Example #1
0
void amule_search_file_prop_get(void *ptr, char *prop_name, PHP_VALUE_NODE *result)
{
	if ( !ptr ) {
		value_value_free(result);
		return;
	}
	SearchFile *obj = (SearchFile *)ptr;
	if ( strcmp(prop_name, "name") == 0 ) {
		result->type = PHP_VAL_STRING;
		result->str_val = strdup((const char *)unicode2UTF8(obj->sFileName));
	} else if ( strcmp(prop_name, "short_name") == 0 ) {
		result->type = PHP_VAL_STRING;
		wxString short_name(obj->sFileName.Length() > 60 ? (obj->sFileName.Left(60) + (wxT(" ..."))) : obj->sFileName);
		result->str_val = strdup((const char *)unicode2UTF8(short_name));
	} else if ( strcmp(prop_name, "hash") == 0 ) {
		result->type = PHP_VAL_STRING;
		result->str_val = strdup((const char *)unicode2UTF8(obj->sHash));
	} else if ( strcmp(prop_name, "size") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->lFileSize;
	} else if ( strcmp(prop_name, "sources") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->lSourceCount;
	} else if ( strcmp(prop_name, "present") == 0 ) {
		result->type = PHP_VAL_BOOL;
		result->int_val = obj->bPresent;
	} else {
		php_report_error(PHP_ERROR, "'SearchFile' property [%s] is unknown", prop_name);
	}
}
Example #2
0
void amule_server_prop_get(void *ptr, char *prop_name, PHP_VALUE_NODE *result)
{
	if ( !ptr ) {
		value_value_free(result);
		return;
	}
	ServerEntry *obj = (ServerEntry *)ptr;
	if ( strcmp(prop_name, "name") == 0 ) {
		result->type = PHP_VAL_STRING;
		result->str_val = strdup((const char *)unicode2UTF8(obj->sServerName));
	} else if ( strcmp(prop_name, "desc") == 0 ) {
		result->type = PHP_VAL_STRING;
		result->str_val = strdup((const char *)unicode2UTF8(obj->sServerDescription));
	} else if ( strcmp(prop_name, "addr") == 0 ) {
		result->type = PHP_VAL_STRING;
		result->str_val = strdup((const char *)unicode2UTF8(obj->sServerIP));
	} else if ( strcmp(prop_name, "users") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->nServerUsers;
	} else if ( strcmp(prop_name, "ip") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->nServerIP;
	} else if ( strcmp(prop_name, "port") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->nServerPort;
	} else if ( strcmp(prop_name, "maxusers") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->nServerMaxUsers;
	} else if ( strcmp(prop_name, "files") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->nServerFiles;
	} else {
		php_report_error(PHP_ERROR, "'ServerEntry' property [%s] is unknown", prop_name);
	}
}
Example #3
0
/*
 * Amule objects implementations
 */
void amule_download_file_prop_get(void *ptr, char *prop_name, PHP_VALUE_NODE *result)
{
	if ( !ptr ) {
		value_value_free(result);
		return;
	}
	DownloadFile *obj = (DownloadFile *)ptr;
	result->type = PHP_VAL_INT;
	if ( strcmp(prop_name, "name") == 0 ) {
		result->type = PHP_VAL_STRING;
		result->str_val = strdup((const char *)unicode2UTF8(obj->sFileName));
	} else if ( strcmp(prop_name, "short_name") == 0 ) {
		result->type = PHP_VAL_STRING;
		wxString short_name(obj->sFileName.Length() > 60 ? (obj->sFileName.Left(60) + (wxT(" ..."))) : obj->sFileName);
		result->str_val = strdup((const char *)unicode2UTF8(short_name));
	} else if ( strcmp(prop_name, "hash") == 0 ) {
		result->type = PHP_VAL_STRING;
		result->str_val = strdup((const char *)unicode2UTF8(obj->sFileHash));
	} else if ( strcmp(prop_name, "progress") == 0 ) {
		result->type = PHP_VAL_STRING;
		result->str_val = strdup((const char *)unicode2UTF8(obj->m_Image->GetHTML()));
	} else if ( strcmp(prop_name, "link") == 0 ) {
		result->type = PHP_VAL_STRING;
		result->str_val = strdup((const char *)unicode2UTF8(obj->sED2kLink));
	} else if ( strcmp(prop_name, "category") == 0 ) {
		result->int_val = obj->nCat;
	} else if ( strcmp(prop_name, "status") == 0 ) {
		result->int_val = obj->nFileStatus;
	} else if ( strcmp(prop_name, "size") == 0 ) {
		result->int_val = obj->lFileSize;
	} else if ( strcmp(prop_name, "size_done") == 0 ) {
		result->int_val = obj->lFileCompleted;
	} else if ( strcmp(prop_name, "size_xfer") == 0 ) {
		result->int_val = obj->lFileTransferred;
	} else if ( strcmp(prop_name, "speed") == 0 ) {
		result->int_val = obj->lFileSpeed;
	} else if ( strcmp(prop_name, "src_count") == 0 ) {
		result->int_val = obj->lSourceCount;
	} else if ( strcmp(prop_name, "src_count_not_curr") == 0 ) {
		result->int_val = obj->lNotCurrentSourceCount;
	} else if ( strcmp(prop_name, "src_count_a4af") == 0 ) {
		result->int_val = obj->lSourceCountA4AF;
	} else if ( strcmp(prop_name, "src_count_xfer") == 0 ) {
		result->int_val = obj->lTransferringSourceCount;
	} else if ( strcmp(prop_name, "prio") == 0 ) {
		result->int_val = obj->lFilePrio;
	} else if ( strcmp(prop_name, "prio_auto") == 0 ) {
		result->int_val = obj->bFileAutoPriority;
	} else if ( strcmp(prop_name, "last_seen_complete") == 0 ) {
		result->int_val = obj->wxtLastSeenComplete.GetTicks();
	} else {
		php_report_error(PHP_ERROR, "'DownloadFile' property [%s] is unknown", prop_name);
	}
}
Example #4
0
void amule_shared_file_prop_get(void *ptr, char *prop_name, PHP_VALUE_NODE *result)
{
	if ( !ptr ) {
		value_value_free(result);
		return;
	}
	SharedFile *obj = (SharedFile *)ptr;
	if ( strcmp(prop_name, "name") == 0 ) {
		result->type = PHP_VAL_STRING;
		result->str_val = strdup((const char *)unicode2UTF8(obj->sFileName));
	} else if ( strcmp(prop_name, "short_name") == 0 ) {
		result->type = PHP_VAL_STRING;
		wxString short_name(obj->sFileName.Length() > 60 ? (obj->sFileName.Left(60) + (wxT(" ..."))) : obj->sFileName);
		result->str_val = strdup((const char *)unicode2UTF8(short_name));
	} else if ( strcmp(prop_name, "hash") == 0 ) {
		result->type = PHP_VAL_STRING;
		result->str_val = strdup((const char *)unicode2UTF8(obj->sFileHash));
	} else if ( strcmp(prop_name, "size") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->lFileSize;
	} else if ( strcmp(prop_name, "link") == 0 ) {
		result->type = PHP_VAL_STRING;
		result->str_val = strdup(unicode2UTF8(obj->sED2kLink));
	} else if ( strcmp(prop_name, "xfer") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->nFileTransferred;
	} else if ( strcmp(prop_name, "xfer_all") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->nFileAllTimeTransferred;
	} else if ( strcmp(prop_name, "req") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->nFileRequests;
	} else if ( strcmp(prop_name, "req_all") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->nFileAllTimeRequests;
	} else if ( strcmp(prop_name, "accept") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->nFileAccepts;
	} else if ( strcmp(prop_name, "accept_all") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->nFileAllTimeAccepts;
	} else if ( strcmp(prop_name, "prio") == 0 ) {
		result->type = PHP_VAL_INT;
		result->int_val = obj->nFilePriority;
	} else if ( strcmp(prop_name, "prio_auto") == 0 ) {
		result->type = PHP_VAL_BOOL;
		result->int_val = obj->bFileAutoPriority;
	} else {
		php_report_error(PHP_ERROR, "'SharedFile' property [%s] is unknown", prop_name);
	}
}
Example #5
0
/*
 * Request contents of server info
 */
void php_get_serverinfo(PHP_VALUE_NODE *result)
{
	value_value_free(result);
	
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	bool rst;
	if ( !si ) {
		rst = false;
	} else {
		cast_value_dnum(&si->var->value);
		rst = si->var->value.int_val != 0;
	}

	if ( rst ) {
		CECPacket req(EC_OP_CLEAR_SERVERINFO);
		CPhPLibContext::g_curr_context->WebServer()->Send_Discard_V2_Request(&req);
	}
	CECPacket req(EC_OP_GET_SERVERINFO);
	const CECPacket *response = CPhPLibContext::g_curr_context->WebServer()->webInterface->SendRecvMsg_v2(&req);
	if (response) {
		wxString serverInfoString(_SpecialChars(response->GetFirstTagSafe()->GetStringData()));
		delete response;
		result->type = PHP_VAL_STRING;
		result->str_val = strdup((const char *)unicode2UTF8(serverInfoString));
	}
}
Example #6
0
void php_get_amule_categories(PHP_VALUE_NODE *result)
{
	cast_value_array(result);

	CECPacket req(EC_OP_GET_PREFERENCES);
	req.AddTag(CECTag(EC_TAG_SELECT_PREFS, (uint32)EC_PREFS_CATEGORIES));
	const CECPacket *reply = CPhPLibContext::g_curr_context->WebServer()->webInterface->SendRecvMsg_v2(&req);
	if ( !reply ) {
		return ;
	}
	const CECTag *cats_tag = reply->GetFirstTagSafe();
	if (cats_tag->HasChildTags()) {
		int i = 0;
		for (CECTag::const_iterator it = cats_tag->begin(); it != cats_tag->end(); it++) {
			const CECTag *categoryTitle = it->GetTagByName(EC_TAG_CATEGORY_TITLE);
			PHP_VAR_NODE *cat = array_get_by_int_key(result, i++);
			value_value_free(&cat->value);
			cat->value.type = PHP_VAL_STRING;
			cat->value.str_val = strdup(unicode2UTF8(categoryTitle->GetStringData()));
		}
	} else {
		PHP_VAR_NODE *cat = array_get_by_int_key(result, 0);
		value_value_free(&cat->value);
		cat->value.type = PHP_VAL_STRING;
		cat->value.str_val = strdup("all");
	}
	delete reply;
}
Example #7
0
void CECTag::SetStringData(const wxString& s)
{
	if (IsString()) {
		delete [] m_tagData;
		ConstructStringTag(m_tagName, (const char*)unicode2UTF8(s));
	}
}
Example #8
0
void amule_upload_file_prop_get(void *ptr, char *prop_name, PHP_VALUE_NODE *result)
{
	if ( !ptr ) {
		value_value_free(result);
		return;
	}
	UploadFile *obj = (UploadFile *)ptr;
	result->type = PHP_VAL_INT;
	if ( strcmp(prop_name, "name") == 0 ) {
		result->type = PHP_VAL_STRING;
		SharedFile *sharedfile = SharedFile::GetContainerInstance()->GetByID(obj->nUploadFile);
		// uploading file we don't share ?! We are either out of sync with core or a shared file has been removed while uploading it
		if ( !sharedfile ) {
			SharedFile::GetContainerInstance()->ReQuery();
			sharedfile = SharedFile::GetContainerInstance()->GetByID(obj->nUploadFile);
		}
		result->str_val = strdup(sharedfile ? (const char *)unicode2UTF8(sharedfile->sFileName) : "???");
	} else if ( strcmp(prop_name, "short_name") == 0 ) {
		result->type = PHP_VAL_STRING;
		SharedFile *sharedfile = SharedFile::GetContainerInstance()->GetByID(obj->nUploadFile);
		if ( !sharedfile ) {
			SharedFile::GetContainerInstance()->ReQuery();
			sharedfile = SharedFile::GetContainerInstance()->GetByID(obj->nUploadFile);
		}
		wxString short_name;
		if (sharedfile) {
			short_name = sharedfile->sFileName.Length() > 60 ? (sharedfile->sFileName.Left(60) + (wxT(" ..."))) : sharedfile->sFileName;
		} else {
			short_name = wxT("???");
		}
		result->str_val = strdup((const char *)unicode2UTF8(short_name));
	} else if ( strcmp(prop_name, "user_name") == 0 ) {
		result->type = PHP_VAL_STRING;
		result->str_val = strdup((const char *)unicode2UTF8(obj->sUserName));
	} else if ( strcmp(prop_name, "xfer_up") == 0 ) {
		result->int_val = obj->nTransferredUp;
	} else if ( strcmp(prop_name, "xfer_down") == 0 ) {
		result->int_val = obj->nTransferredDown;
	} else if ( strcmp(prop_name, "xfer_speed") == 0 ) {
		result->int_val = obj->nSpeed;
	} else {
		php_report_error(PHP_ERROR, "'UploadFile' property [%s] is unknown", prop_name);
	}
}
Example #9
0
/*
 * Convert CEC_StatTree_Node_Tag into php associative array
 * 
 * Since data structure is recoursive - we need helper function
 * to perform conversion
 */
void ecstats2php(CEC_StatTree_Node_Tag *root, PHP_VALUE_NODE *result)
{
	cast_value_array(result);
	std::string key(unicode2UTF8(root->GetDisplayString()));
	PHP_VAR_NODE *v_key = array_get_by_str_key(result, key);
	for (CECTag::const_iterator it = root->begin(); it != root->end(); it++) {
		CEC_StatTree_Node_Tag *tag = (CEC_StatTree_Node_Tag*) & *it;
		if (tag->GetTagName() == EC_TAG_STATTREE_NODE) {
			ecstats2php(tag, &v_key->value);
		}
	}

}
Example #10
0
/*
 * Return hash of amule options.
 *  Key: option name
 *  Value: option value (string)
 */
void php_get_amule_options(PHP_VALUE_NODE *result)
{
	cast_value_array(result);

	CECPacket req(EC_OP_GET_PREFERENCES);
	req.AddTag(CECTag(EC_TAG_SELECT_PREFS, (uint32)0xffffffff));
	const CECPacket *reply = CPhPLibContext::g_curr_context->WebServer()->webInterface->SendRecvMsg_v2(&req);
	if ( !reply || !reply->HasChildTags()) {
		return ;
	}
	const CECTag *cattag = 0;
	PHP_VALUE_NODE intval;
	intval.type = PHP_VAL_INT;
    if ((cattag = reply->GetTagByName(EC_TAG_PREFS_GENERAL)) != 0) {
		PHP_VAR_NODE *key = array_get_by_str_key(result, "nick");
		value_value_free(&key->value);
		key->value.type = PHP_VAL_STRING;
		key->value.str_val = strdup(unicode2UTF8(cattag->GetTagByNameSafe(EC_TAG_USER_NICK)->GetStringData()));
	}

	if ((cattag = reply->GetTagByName(EC_TAG_PREFS_CONNECTIONS)) != 0) {
		PHP_VAR_NODE *cat = array_get_by_str_key(result, "connection");
		cast_value_array(&cat->value);
		
		ec_tag_2_php(cattag, g_connection_opt_defs, cat);
	}
	if ((cattag = reply->GetTagByName(EC_TAG_PREFS_FILES)) != 0) {
		PHP_VAR_NODE *cat = array_get_by_str_key(result, "files");
		cast_value_array(&cat->value);

		ec_tag_2_php(cattag, g_file_opt_defs, cat);
	}

	if ((cattag = reply->GetTagByName(EC_TAG_PREFS_REMOTECTRL)) != 0) {
		PHP_VAR_NODE *cat = array_get_by_str_key(result, "webserver");
		cast_value_array(&cat->value);

		ec_tag_2_php(cattag, g_webserver_opt_defs, cat);
	}

	if ((cattag = reply->GetTagByName(EC_TAG_PREFS_CORETWEAKS)) != 0) {
		PHP_VAR_NODE *cat = array_get_by_str_key(result, "coretweaks");
		cast_value_array(&cat->value);

		ec_tag_2_php(cattag, g_coretweak_opt_defs, cat);
	}
}
Example #11
0
void CFileDataIO::WriteString(const wxString& str, EUtf8Str eEncode, uint8 SizeLen)
{
	switch (eEncode) {
		case utf8strRaw:
		case utf8strOptBOM: {
			Unicode2CharBuf s(unicode2UTF8(str));
			if (s) {
				WriteStringCore(s, eEncode, SizeLen);
				break;
			}
		}
		default: {
			// Non UTF-8 strings are saved as Latin-1
			wxCharBuffer s1 = wxConvISO8859_1.cWC2MB(str);
			WriteStringCore(s1, utf8strNone, SizeLen);			
		}
	}
}
Example #12
0
/*
 * Query amule status. Return hash containing stats values
 */
void php_get_amule_stats(PHP_VALUE_NODE *result)
{
	CECPacket stat_req(EC_OP_STAT_REQ, EC_DETAIL_FULL);
	const CECPacket *stats = CPhPLibContext::g_curr_context->WebServer()->webInterface->SendRecvMsg_v2(&stat_req);
	if (!stats) {
		return ;
	}
	CEC_ConnState_Tag *tag = (CEC_ConnState_Tag *)stats->GetTagByName(EC_TAG_CONNSTATE);
	if (!tag) {
		return ;
	}
	
	cast_value_array(result);
	PHP_VAR_NODE *id = array_get_by_str_key(result, "id");
	cast_value_dnum(&id->value);
	id->value.int_val = tag->GetEd2kId();
	const CECTag *server = tag->GetTagByName(EC_TAG_SERVER);
	if ( server ) {
		PHP_VAR_NODE *srv_ip = array_get_by_str_key(result, "serv_addr");
		value_value_free(&srv_ip->value);
		srv_ip->value.type = PHP_VAL_STRING;
		srv_ip->value.str_val =strdup(unicode2UTF8(server->GetIPv4Data().StringIP()));

		const CECTag *sname = server->GetTagByName(EC_TAG_SERVER_NAME);
		if ( sname ) {
			PHP_VAR_NODE *srv_name = array_get_by_str_key(result, "serv_name");
			value_value_free(&srv_name->value);
			srv_name->value.type = PHP_VAL_STRING;
			srv_name->value.str_val = strdup(unicode2UTF8(sname->GetStringData()));
		}
		
		const CECTag *susers = server->GetTagByName(EC_TAG_SERVER_USERS);
		if ( susers ) {
			PHP_VAR_NODE *srv_users = array_get_by_str_key(result, "serv_users");
			value_value_free(&srv_users->value);
			srv_users->value.type = PHP_VAL_INT;
			srv_users->value.int_val = susers->GetInt();
		}
			
	}
	// kademlia
	PHP_VAR_NODE *kad = array_get_by_str_key(result, "kad_connected");
	value_value_free(&kad->value);
	kad->value.type = PHP_VAL_BOOL;
	if ( tag->IsConnectedKademlia() ) {
		kad->value.int_val = 1;
		PHP_VAR_NODE *kad_fwl = array_get_by_str_key(result, "kad_firewalled");
		kad_fwl->value.type = PHP_VAL_BOOL;
		kad_fwl->value.int_val = tag->IsKadFirewalled();
	} else {
		kad->value.int_val = 0;
	}
	// traffic stats
	PHP_VAR_NODE *speed;
	speed = array_get_by_str_key(result, "speed_up");
	value_value_free(&speed->value);
	speed->value.type = PHP_VAL_INT;
	speed->value.int_val = stats->GetTagByName(EC_TAG_STATS_UL_SPEED)->GetInt();
	
	speed = array_get_by_str_key(result, "speed_down");
	value_value_free(&speed->value);
	speed->value.type = PHP_VAL_INT;
	speed->value.int_val = stats->GetTagByName(EC_TAG_STATS_DL_SPEED)->GetInt();

	speed = array_get_by_str_key(result, "speed_limit_up");
	value_value_free(&speed->value);
	speed->value.type = PHP_VAL_INT;
	speed->value.int_val = stats->GetTagByName(EC_TAG_STATS_UL_SPEED_LIMIT)->GetInt();
	
	speed = array_get_by_str_key(result, "speed_limit_down");
	value_value_free(&speed->value);
	speed->value.type = PHP_VAL_INT;
	speed->value.int_val = stats->GetTagByName(EC_TAG_STATS_DL_SPEED_LIMIT)->GetInt();

	delete stats;
}
Example #13
0
CECTag::CECTag(ec_tagname_t name, const wxChar* data)
{
	ConstructStringTag(name, (const char*)unicode2UTF8(data));
}
Example #14
0
bool CFile::Open(const wxString& fileName, OpenMode mode, int accessMode)
{
	MULE_VALIDATE_PARAMS(!fileName.IsEmpty(), wxT("CFile: Cannot open, empty path."));

#ifdef __linux__
	int flags = O_BINARY | O_LARGEFILE;
#else
	int flags = O_BINARY;
#endif

	switch ( mode ) {
		case read:
			flags |= O_RDONLY;
			break;
	
		case write_append:
			if (CheckFileExists(fileName))
			{
				flags |= O_WRONLY | O_APPEND;
				break;
			}
			//else: fall through as write_append is the same as write if the
			//      file doesn't exist
	
		case write:
			flags |= O_WRONLY | O_CREAT | O_TRUNC;
			break;
	
		case write_excl:
			flags |= O_WRONLY | O_CREAT | O_EXCL;
			break;

		case read_write:
			flags |= O_RDWR;
        	break;
	}

	if (IsOpened()) {
		Close();	
	}

	
	// When opening files, we will always first try to create an ANSI file name,
	// even if that means an extended ANSI file name. Only if it is not possible
	// to do that, we fall back to  UTF-8 file names. This is unicode safe and is
	// the only way to guarantee that we can open any file in the file system,
	// even if it is not an UTF-8 valid sequence.
	//
	
	
	// Test if it is possible to use an ANSI name
	Unicode2CharBuf tmpFileName = unicode2char(fileName);
	if (tmpFileName) {
		// Use an ANSI name
		m_fd = open(tmpFileName, flags, accessMode);
	} 
	
	if (m_fd == fd_invalid) { // Wrong conversion or can't open.
		// Try an UTF-8 name
		m_fd = open(unicode2UTF8(fileName), flags, accessMode);
	}
	
	m_filePath = fileName;

	SYSCALL_CHECK(m_fd != fd_invalid, wxT("opening file"));	
      
    return IsOpened();
}