"Unknown event" error appears in compiled FileZilla

Moderator: Project members

Post Reply
Message
Author
test
150 Opening data channel
Posts: 55
Joined: 2020-03-24 06:36

"Unknown event" error appears in compiled FileZilla

#1 Post by test » 2020-04-14 12:52

Hi!

I am developing a customized FileZilla for Storj RC 1.0.

Before doing this, I created a sample test file for implementing the functionalities of Storj RC1.0 Bucket operations.

And I was successful in implementing all of them.

Now, when I try to integrate that to my customized FileZilla source code files, I get some strange Unknown event error.

My fzstorj.cpp code is as follows:

Code: Select all

#include <stdio.h>
#include <cstdlib>
#include <cstring>

#include <ctime>

#include "events.hpp"

#include <libfilezilla/format.hpp>
#include <libfilezilla/mutex.hpp>

#include "libuplinkc.h"

#include <map>

fz::mutex output_mutex;

void fzprintf(storjEvent event)
{
	fz::scoped_lock l(output_mutex);

	fputc('0' + static_cast<int>(event), stdout);

	fflush(stdout);
}

template<typename ...Args>
void fzprintf(storjEvent event, Args &&... args)
{
	fz::scoped_lock l(output_mutex);

	fputc('0' + static_cast<int>(event), stdout);

	std::string s = fz::sprintf(std::forward<Args>(args)...);
	fwrite(s.c_str(), s.size(), 1, stdout);

	fputc('\n', stdout);
	fflush(stdout);
}

#include "require.h"

bool getLine(std::string & line)
{
	line.clear();
	while (true) {
		int c = fgetc(stdin);
		if (c == -1) {
			return false;
		}
		else if (!c) {
			return line.empty();
		}
		else if (c == '\n') {
			return !line.empty();
		}
		else if (c == '\r') {
			continue;
		}
		else {
			line += static_cast<unsigned char>(c);
		}
	}
}

std::string next_argument(std::string & line)
{
	std::string ret;

	fz::trim(line);

	if (line[0] == '"') {
		size_t pos = 1;
		size_t pos2;
		while ((pos2 = line.find('"', pos)) != std::string::npos && line[pos2 + 1] == '"') {
			ret += line.substr(pos, pos2 - pos + 1);
			pos = pos2 + 2;
		}
		if (pos2 == std::string::npos || (line[pos2 + 1] != ' ' && line[pos2 + 1] != '\0')) {
			line.clear();
			ret.clear();
		}
		ret += line.substr(pos, pos2 - pos);
		line = line.substr(pos2 + 1);
	}
	else {
		size_t pos = line.find(' ');
		if (pos == std::string::npos) {
			ret = line;
			line.clear();
		}
		else {
			ret = line.substr(0, pos);
			line = line.substr(pos + 1);
		}
	}

	fz::trim(line);

	return ret;
}

namespace {
#define DEBUG_MODE false

}

int main()
{
	fzprintf(storjEvent::Reply, "fzStorj started, protocol_version=%d", FZSTORJ_PROTOCOL_VERSION);

	std::string ls_satelliteURL;
	std::string ls_apiKey;
	std::string ls_encryptionPassPhrase;
	
	char* lpc_error = "";

	int ret = 0;
	while (true) {
		std::string command;
		if (!getLine(command)) {
			ret = 1;
			break;
		}

		if (command.empty()) {
			break;
		}

		std::size_t pos = command.find(' ');
		std::string arg;
		if (pos != std::string::npos) {
			arg = command.substr(pos + 1);
			command = command.substr(0, pos);
		}

		if (command == "host") {
			ls_satelliteURL = arg;
			fzprintf(storjEvent::Done);
		}
		else if (command == "user") {
			ls_apiKey = arg;
			//
			fzprintf(storjEvent::Done);
		}
		else if (command == "pass") {
			ls_encryptionPassPhrase = arg;
			fzprintf(storjEvent::Done);
		}
		else if (command == "genkey") {
			fzprintf(storjEvent::Done, "");
		}
		else if (command == "key" || command == "validatekey") {
			if (command == "key") {
				fzprintf(storjEvent::Done);
			}
			else {
				fzprintf(storjEvent::Done, "");
			}
		}
		else if (command == "timeout") {
			// timeout = fz::to_integral<uint64_t>(arg);
			fzprintf(storjEvent::Done);
		}
		else if (command == "proxy") {
			fzprintf(storjEvent::Done);
		}
		else if (command == "list-buckets") {
			char *satellite_addr = "..........";
			char *api_key = "................";
			char *passphrase = "..............";
			
			fzprintf(storjEvent::Status, "passphrase = %s", passphrase);
			
			AccessResult access_result = request_access_with_passphrase(satellite_addr, api_key, passphrase);
			if (access_result.error) {
				fzprintf(storjEvent::Error, "failed to parse access: %s\n", access_result.error->message);
				free_access_result(access_result);
			}
			else {
				fzprintf(storjEvent::Status, "1)Access obtained");
			}
	
			ProjectResult project_result = open_project(access_result.access);
			if (project_result.error) {
				fzprintf(storjEvent::Error, "failed to open project: %s\n", project_result.error->message);
				free_project_result(project_result);
			}
			else {
				fzprintf(storjEvent::Status, "2)Project handle obtained");
			}
			fzprintf(storjEvent::Status, "# listing buckets\n");
		
			BucketIterator *it = list_buckets(project_result.project, NULL);

			int count = 0;
			while (bucket_iterator_next(it)) {
				Bucket *bucket = bucket_iterator_item(it);
				fzprintf(storjEvent::Status, "bucket %s", bucket->name);
				free_bucket(bucket);
				count++;
			}
			Error *err = bucket_iterator_err(it);
			if (err) {
				fzprintf(storjEvent::Error, "bucket listing failed: %s", err->message);
				free_error(err);
				free_bucket_iterator(it);
			}
			else {
				fzprintf(storjEvent::Status, "No error in bucket listing ");
			}
			free_bucket_iterator(it);	
			
			fzprintf(storjEvent::Done);
		}
		else if (command == "list") {
		}
		else if (command == "get") {
		}
		else if (command == "put") {
		}
		else if (command == "rm") {
		}
		else if (command == "mkbucket") {
		}
		else if (command == "rmbucket") {
		}
		else {
			fzprintf(storjEvent::Error, "No such command: %s", command);
		}

	}

	return ret;
}

The output I get in the message bar after compiling using make, then installing using NSIS3 and then running Filezilla.exe is:

Code: Select all

Status:	Connecting to (My storj satellite URL)...
Status:	Retrieving directory listing...
Status:	passphrase = (Same as the passphrase value taken by me)
Status:	1)Access obtained
Status:	2)Project handle obtained
Status:	# listing buckets
Error:	Unknown eventType 221
Error:	Failed to retrieve directory listing
Status:	Disconnected from server
Status:	Connecting to (My storj satellite URL)...
Status:	Retrieving directory listing...
Status:	passphrase = (Same as the passphrase value taken by me)
Status:	1)Access obtained
Status:	2)Project handle obtained
Status:	# listing buckets
Error:	Unknown eventType 221
Error:	Failed to retrieve directory listing
I know that my hardcoding approach is not a nice one. I actually plan to remove that after testing my code.

Kindly help!

Thanks

User avatar
botg
Site Admin
Posts: 35491
Joined: 2004-02-23 20:49
First name: Tim
Last name: Kosse

Re: "Unknown event" error appears in compiled FileZilla

#2 Post by botg » 2020-04-14 13:30

You cannot include line breaks in status messages.

test
150 Opening data channel
Posts: 55
Joined: 2020-03-24 06:36

Re: "Unknown event" error appears in compiled FileZilla

#3 Post by test » 2020-04-14 14:49

Thanks :D It worked

Man, you are genius! :)

Post Reply