示例#1
0
/*
 * Download ed2k link. Params: link, category (default=0)
 */
void php_native_ed2k_download_cmd(PHP_VALUE_NODE *result)
{
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	if ( !si || (si->var->value.type != PHP_VAL_STRING)) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 1 (file link)");
		return;
	}
	char *str_link = si->var->value.str_val;
	
	si = get_scope_item(g_current_scope, "__param_1");
	if ( !si || (si->var->value.type != PHP_VAL_STRING)) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 2 (category)");
		return;
	}

	cast_value_dnum(&si->var->value);
	int cat = si->var->value.int_val;

	bool cmd_result = CPhPLibContext::g_curr_context->WebServer()->Send_DownloadEd2k_Cmd(
		wxString(char2unicode(str_link)), cat);
	if ( result ) {
		cast_value_bool(result);
		result->int_val = cmd_result;
	}
}
示例#2
0
void php_native_substr(PHP_VALUE_NODE * /*result*/)
{
	PHP_SCOPE_ITEM *si_str = get_scope_item(g_current_scope, "__param_0");
	PHP_VALUE_NODE *str = &si_str->var->value;
	if ( si_str ) {
		cast_value_str(str);
	} else {
		php_report_error(PHP_ERROR, "Invalid or missing argument 'str' for 'substr'");
		return;
	}
	PHP_SCOPE_ITEM *si_start = get_scope_item(g_current_scope, "__param_1");
	PHP_VALUE_NODE *start = &si_start->var->value;
	if ( si_start ) {
		cast_value_dnum(start);
	} else {
		php_report_error(PHP_ERROR, "Invalid or missing argument 'start' for 'substr'");
		return;
	}
	// 3-rd is optional
	PHP_SCOPE_ITEM *si_end = get_scope_item(g_current_scope, "__param_2");
	PHP_VALUE_NODE end = { PHP_VAL_INT, { 0 } };
	if ( si_end ) {
		end = si_end->var->value;
	}
	cast_value_dnum(&end);


}
示例#3
0
void php_native_load_amule_vars(PHP_VALUE_NODE *result)
{
	PHP_SCOPE_ITEM *si_str = get_scope_item(g_current_scope, "__param_0");
	if ( !si_str  ) {
		php_report_error(PHP_ERROR, "Missing argument 'varname' for 'load_amule_vars'");
		return;
	}
	PHP_VALUE_NODE *str = &si_str->var->value;
	if ( str->type != PHP_VAL_STRING ) {
		php_report_error(PHP_ERROR, "Argument 'varname' for 'load_amule_vars' must be string");
		return;
	}
	char *varname = str->str_val;
	if ( result ) {
		cast_value_array(result);
	}
	if ( strcmp(varname, "downloads") == 0 ) {
		amule_load_downloads(result);
	} else if ( strcmp(varname, "uploads") == 0 ) {
		amule_load_uploads(result);
	} else if ( strcmp(varname, "shared") == 0 ) {
		amule_load_shared(result);
	} else if ( strcmp(varname, "searchresult") == 0 ) {
		amule_load_search(result);
	} else if ( strcmp(varname, "servers") == 0 ) {
		amule_load_servers(result);
	} else if ( strcmp(varname, "stats_graph") == 0 ) {
		amule_load_stats();
	} else if ( strcmp(varname, "stats_tree") == 0 ) {
		amule_load_stats_tree(result);
	} else {
		value_value_free(result);
		php_report_error(PHP_ERROR, "This type of amule variable is unknown");
	}
}
示例#4
0
/*
 * 
 * Usage: php_native_download_file_cmd($file_hash, "command", $optional_arg)
 * 
 */
void php_native_download_file_cmd(PHP_VALUE_NODE *)
{
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	if ( !si || (si->var->value.type != PHP_VAL_STRING)) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 1");
		return;
	}
	char *str_hash = si->var->value.str_val;
	
	si = get_scope_item(g_current_scope, "__param_1");
	if ( !si || (si->var->value.type != PHP_VAL_STRING)) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 2");
		return;
	}
	char *cmd_name = si->var->value.str_val;
	si = get_scope_item(g_current_scope, "__param_2");
	PHP_VAR_NODE *opt_param = si ? si->var : 0;

	if ( (!strcmp(cmd_name, "prio") || !strcmp(cmd_name, "setcat")) && !opt_param ) {
		php_report_error(PHP_ERROR, "Commands 'prio' and 'setcat' needs 3-rd argument");
		return;
	}
		
	CPhPLibContext::g_curr_context->WebServer()->Send_DownloadFile_Cmd(wxString(char2unicode(str_hash)),
		wxString(char2unicode(cmd_name)),
		opt_param ? opt_param->value.int_val : 0);
}
示例#5
0
/*
 * Usage amule_add_server_cmd($server_addr, $server_port, $server_name);
 */
void php_native_add_server_cmd(PHP_VALUE_NODE *)
{
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	if ( !si || (si->var->value.type != PHP_VAL_STRING) ) {
		php_report_error(PHP_ERROR, "Missing or bad argument 1: $server_addr");
		return;
	}
	char *addr = si->var->value.str_val;
	
	si = get_scope_item(g_current_scope, "__param_1");
	if ( !si ) {
		php_report_error(PHP_ERROR, "Missing argument 2: $server_port");
		return;
	}
	cast_value_dnum(&si->var->value);
	int port = si->var->value.int_val;

	si = get_scope_item(g_current_scope, "__param_2");
	if ( !si || (si->var->value.type != PHP_VAL_STRING) ) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 3: $server_name");
		return;
	}
	char *name = si->var->value.str_val;

	CPhPLibContext::g_curr_context->WebServer()->Send_AddServer_Cmd(wxString(char2unicode(addr)),
		wxString::Format(wxT("%d"), port), wxString(char2unicode(name)));
}
示例#6
0
/*
 * Usage amule_server_cmd($server_ip, $server_port, "command");
 */
void php_native_server_cmd(PHP_VALUE_NODE *)
{
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	if ( !si ) {
		php_report_error(PHP_ERROR, "Missing argument 1: $server_ip");
		return;
	}
	cast_value_dnum(&si->var->value);
	uint32_t ip = si->var->value.int_val;

	si = get_scope_item(g_current_scope, "__param_1");
	if ( !si ) {
		php_report_error(PHP_ERROR, "Missing argument 2: $server_port");
		return;
	}
	cast_value_dnum(&si->var->value);
	int port = si->var->value.int_val;

	si = get_scope_item(g_current_scope, "__param_2");
	if ( !si || (si->var->value.type != PHP_VAL_STRING)) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 3: $command");
		return;
	}
	char *cmd = si->var->value.str_val;

	CPhPLibContext::g_curr_context->WebServer()->Send_Server_Cmd(ip, port, wxString(char2unicode(cmd)));
}
示例#7
0
void php_native_usort(PHP_VALUE_NODE *)
{
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	if ( !si || (si->var->value.type != PHP_VAL_ARRAY)) {
		php_report_error(PHP_ERROR, "Invalid or missing argument (array)");
		return;
	}
	PHP_VAR_NODE *array = si->var;
	si = get_scope_item(g_current_scope, "__param_1");
	if ( !si || (si->var->value.type != PHP_VAL_STRING)) {
		php_report_error(PHP_ERROR, "Invalid or missing argument (func name)");
		return;
	}
	char *cmp_func_name = si->var->value.str_val;
	si = get_scope_item(g_global_scope, cmp_func_name);
	if ( !si || (si->type != PHP_SCOPE_FUNC)) {
		php_report_error(PHP_ERROR, "Compare function [%s] not found", cmp_func_name);
		return;
	}
	PHP_SYN_FUNC_DECL_NODE *func_decl = si->func->func_decl;

	//
	// usort invalidates keys, and sorts values
	//
	PHP_ARRAY_TYPE *arr_obj = (PHP_ARRAY_TYPE *)array->value.ptr_val;
	//
	// create vector of values
	//
	if ( arr_obj->array.size() == 0 ) {
		php_report_error(PHP_WARNING, "Sorting array of size 0");
		return;
	}

	std::list<SortElem> sort_list;
	for(PHP_ARRAY_ITER_TYPE i = arr_obj->array.begin(); i != arr_obj->array.end(); i++) {
		sort_list.push_back(SortElem(i->second));
	}
	SortElem::callback = func_decl;
	sort_list.sort();

	arr_obj->array.clear();
	arr_obj->sorted_keys.clear();
	unsigned int key = 0;
	for(std::list<SortElem>::iterator i = sort_list.begin(); i != sort_list.end(); i++) {
		array_add_to_int_key(&array->value, key++, i->obj);
	}

}
示例#8
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);
	}
}
示例#9
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);
	}
}
示例#10
0
void php_native_var_dump(PHP_VALUE_NODE *)
{
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	if ( si ) {
		assert((si->type == PHP_SCOPE_VAR)||(si->type == PHP_SCOPE_PARAM));
		php_var_dump(&si->var->value, 0, 0);
	} else {
		php_report_error(PHP_ERROR, "Invalid or missing argument");
	}
}
示例#11
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);
	}
}
示例#12
0
/*
 * Download 1 of search results. Params: hash, category (default=0)
 */
void php_native_search_download_cmd(PHP_VALUE_NODE *)
{
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	if ( !si || (si->var->value.type != PHP_VAL_STRING)) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 1 (file hash)");
		return;
	}
	char *str_hash = si->var->value.str_val;
	
	si = get_scope_item(g_current_scope, "__param_1");
	if ( !si || (si->var->value.type != PHP_VAL_STRING)) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 2 (category)");
		return;
	}

	cast_value_dnum(&si->var->value);
	int cat = si->var->value.int_val;

	CPhPLibContext::g_curr_context->WebServer()->Send_DownloadSearchFile_Cmd(
		wxString(char2unicode(str_hash)), cat);
}
示例#13
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);
	}
}
示例#14
0
void php_native_isset(PHP_VALUE_NODE *result)
{
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	if ( si ) {
		PHP_VALUE_NODE *param = &si->var->value;
		cast_value_str(param);
		if ( result ) {
			cast_value_bool(result);
			result->int_val = (si->var->value.type == PHP_VAL_NONE) ? 0 : 1;
		}
	} else {
		php_report_error(PHP_ERROR, "Invalid or missing argument");
	}
}
示例#15
0
/*
 * String functions
 */
void php_native_strlen(PHP_VALUE_NODE *result)
{
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	if ( si ) {
		PHP_VALUE_NODE *param = &si->var->value;
		cast_value_str(param);
		if ( result ) {
			cast_value_dnum(result);
			result->int_val = strlen(param->str_val);
		}
	} else {
		php_report_error(PHP_ERROR, "Invalid or missing argument");
	}
}
示例#16
0
/*
 * Usage amule_kad_connect($bootstrap_ip, $bootstrap_port)
 */
void php_native_kad_connect(PHP_VALUE_NODE *)
{
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	if ( !si ) {
		php_report_error(PHP_ERROR, "Missing or bad argument 1: $bootstrap_ip_addr");
		return;
	}
	cast_value_dnum(&si->var->value);
	unsigned int ipaddr = si->var->value.int_val;

	si = get_scope_item(g_current_scope, "__param_1");
	if ( !si ) {
		php_report_error(PHP_ERROR, "Missing or bad argument 2: $bootstrap_ip_port");
		return;
	}
	cast_value_dnum(&si->var->value);
	unsigned int ipport = si->var->value.int_val;

	CECPacket req(EC_OP_KAD_BOOTSTRAP_FROM_IP);
	req.AddTag(CECTag(EC_TAG_BOOTSTRAP_IP, ipaddr));
	req.AddTag(CECTag(EC_TAG_BOOTSTRAP_PORT, ipport));
	CPhPLibContext::g_curr_context->WebServer()->Send_Discard_V2_Request(&req);
}
示例#17
0
void php_native_count(PHP_VALUE_NODE *result)
{
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	if ( si ) {
		PHP_VALUE_NODE *param = &si->var->value;
		if ( result ) {
			cast_value_dnum(result);
			if ( (si->var->value.type == PHP_VAL_NONE) || (si->var->value.type != PHP_VAL_ARRAY) ) {
				result->int_val = 0;
			} else {
				result->int_val = array_get_size(param);
			}
		}
	} else {
		php_report_error(PHP_ERROR, "Invalid or missing argument");
	}
}
示例#18
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);
	}
}
示例#19
0
/*
 * Set amule options from given array. Argument looks like "amule_get_options" result
 */
void php_set_amule_options(PHP_VALUE_NODE *)
{
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	if ( !si || (si->var->value.type != PHP_VAL_ARRAY)) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 1 (options array)");
		return;
	}

	CECPacket req(EC_OP_SET_PREFERENCES);
	PHP_VAR_NODE *opt_group_array = 0;

	// files
	opt_group_array = array_get_by_str_key(&si->var->value, "files");
	if ( opt_group_array->value.type == PHP_VAL_ARRAY ) {
		CECEmptyTag filePrefs(EC_TAG_PREFS_FILES);
		php_2_ec_tag(&filePrefs, g_file_opt_defs, &opt_group_array->value);
		req.AddTag(filePrefs);
	}
	// connection
	opt_group_array = array_get_by_str_key(&si->var->value, "connection");
	if ( opt_group_array->value.type == PHP_VAL_ARRAY ) {
		CECEmptyTag connPrefs(EC_TAG_PREFS_CONNECTIONS);
		php_2_ec_tag(&connPrefs, g_connection_opt_defs, &opt_group_array->value);
		req.AddTag(connPrefs);
	}
	// webserver
	opt_group_array = array_get_by_str_key(&si->var->value, "webserver");
	if ( opt_group_array->value.type == PHP_VAL_ARRAY ) {
		CECEmptyTag webPrefs(EC_TAG_PREFS_REMOTECTRL);
		php_2_ec_tag(&webPrefs, g_webserver_opt_defs, &opt_group_array->value);
		req.AddTag(webPrefs);
		// also apply settings localy
		PHP_VAR_NODE *pref = array_get_by_str_key(&opt_group_array->value, "use_gzip");
		cast_value_dnum(&pref->value);
		CPhPLibContext::g_curr_context->WebServer()->webInterface->m_UseGzip = pref->value.int_val != 0;
		pref = array_get_by_str_key(&opt_group_array->value, "autorefresh_time");
		cast_value_dnum(&pref->value);
		CPhPLibContext::g_curr_context->WebServer()->webInterface->m_PageRefresh = pref->value.int_val;
	}
	CPhPLibContext::g_curr_context->WebServer()->Send_Discard_V2_Request(&req);
}
示例#20
0
void php_native_split(PHP_VALUE_NODE *result)
{
	if ( result ) {
		cast_value_array(result);
	} else {
		return;
	}
	PHP_VALUE_NODE *pattern, *string_to_split, *split_limit;
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	if ( si ) {
		pattern = &si->var->value;
		cast_value_str(pattern);
	} else {
		php_report_error(PHP_ERROR, "Invalid or missing argument: pattern");
		return;
	}
	si = get_scope_item(g_current_scope, "__param_1");
	if ( si ) {
		string_to_split = &si->var->value;
		cast_value_str(string_to_split);
	} else {
		php_report_error(PHP_ERROR, "Invalid or missing argument: string");
		return;
	}
	si = get_scope_item(g_current_scope, "__param_2");
	if ( si ) {
		split_limit = &si->var->value;
		cast_value_dnum(split_limit);
	} else {
		php_report_error(PHP_ERROR, "Invalid or missing argument: string");
		return;
	}
#ifdef PHP_STANDALONE_EN
	regex_t preg;
	char error_buff[256];
	int reg_result = regcomp(&preg, pattern->str_val, REG_EXTENDED);
	if ( reg_result ) {
		regerror(reg_result, &preg, error_buff, sizeof(error_buff));
		php_report_error(PHP_ERROR, "Failed in regcomp: %s", error_buff);
#else
	wxRegEx preg;
	if (!preg.Compile(wxString(char2unicode(pattern->str_val)), wxRE_EXTENDED)) {
		php_report_error(PHP_ERROR, "Failed in Compile of: %s", pattern->str_val);
#endif
		return;
	}

#ifdef PHP_STANDALONE_EN
	size_t nmatch = strlen(string_to_split->str_val);
	regmatch_t *pmatch = new regmatch_t[nmatch];
#endif
	char *str_2_match = string_to_split->str_val;
	char *tmp_buff = new char[strlen(string_to_split->str_val)+1];

	while ( 1 ) {
//		printf("matching: %s\n", str_2_match);
#ifdef PHP_STANDALONE_EN
		reg_result = regexec(&preg, str_2_match, nmatch, pmatch, 0);
		if ( reg_result ) {
#else
		if (!preg.Matches(wxString(char2unicode(str_2_match)))) {
#endif
			// no match
			break;
		}
#ifndef PHP_STANDALONE_EN
		// get matching position
		size_t start, len;
		if (!preg.GetMatch(&start, &len)) {
			break;	// shouldn't happen
		}
#endif
		/*
		 * I will use only first match, since I don't see any sense to have more
		 * then 1 match in split() call
		 */
#ifdef PHP_STANDALONE_EN
		for(int i = 0; i < pmatch[0].rm_so; i++) {
#else
		for(size_t i = 0; i < start; i++) {
#endif
			tmp_buff[i] = str_2_match[i];
		}
#ifdef PHP_STANDALONE_EN
		tmp_buff[pmatch[0].rm_so] = 0;
#else
		tmp_buff[start] = 0;
#endif
//		printf("Match added [%s]\n", tmp_buff);

		PHP_VAR_NODE *match_val = array_push_back(result);
		match_val->value.type = PHP_VAL_STRING;
		match_val->value.str_val = strdup(tmp_buff);

#ifdef PHP_STANDALONE_EN
		str_2_match += pmatch[0].rm_eo;
#else
		str_2_match += start + len;
#endif
	}

	PHP_VAR_NODE *match_val = array_push_back(result);
	match_val->value.type = PHP_VAL_STRING;
	match_val->value.str_val = strdup(str_2_match);

	delete [] tmp_buff;
#ifdef PHP_STANDALONE_EN
	delete [] pmatch;
	regfree(&preg);
#endif
}

#ifdef ENABLE_NLS

void php_native_gettext(PHP_VALUE_NODE *result)
{
	PHP_SCOPE_ITEM *si_str = get_scope_item(g_current_scope, "__param_0");
	PHP_VALUE_NODE *str = &si_str->var->value;
	if ( si_str ) {
		cast_value_str(str);
	} else {
		php_report_error(PHP_ERROR, "Invalid or missing argument 'msgid' for 'gettext'");
		return;
	}
	if ( result ) {
		cast_value_dnum(result);
		result->type = PHP_VAL_STRING;
		result->str_val = strdup(gettext(str->str_val));
	}
}

void php_native_gettext_noop(PHP_VALUE_NODE *result)
{
	PHP_SCOPE_ITEM *si_str = get_scope_item(g_current_scope, "__param_0");
	PHP_VALUE_NODE *str = &si_str->var->value;
	if ( si_str ) {
		cast_value_str(str);
	} else {
		php_report_error(PHP_ERROR, "Invalid or missing argument 'msgid' for 'gettext_noop'");
		return;
	}
	if ( result ) {
		cast_value_dnum(result);
		result->type = PHP_VAL_STRING;
		result->str_val = strdup(str->str_val);
	}
}

void php_native_ngettext(PHP_VALUE_NODE *result)
{
	PHP_SCOPE_ITEM *si_msgid = get_scope_item(g_current_scope, "__param_0");
	PHP_VALUE_NODE *msgid = &si_msgid->var->value;
	if ( si_msgid ) {
		cast_value_str(msgid);
	} else {
		php_report_error(PHP_ERROR, "Invalid or missing argument 'msgid' for 'ngettext'");
		return;
	}
	PHP_SCOPE_ITEM *si_msgid_plural = get_scope_item(g_current_scope, "__param_1");
	PHP_VALUE_NODE *msgid_plural = &si_msgid_plural->var->value;
	if ( si_msgid_plural ) {
		cast_value_str(msgid_plural);
	} else {
		php_report_error(PHP_ERROR, "Invalid or missing argument 'msgid_plural' for 'ngettext'");
		return;
	}
	PHP_SCOPE_ITEM *si_count = get_scope_item(g_current_scope, "__param_2");
	PHP_VALUE_NODE *count = &si_count->var->value;
	if ( si_count ) {
		cast_value_dnum(count);
	} else {
		php_report_error(PHP_ERROR, "Invalid or missing argument 'count' for 'ngettext'");
		return;
	}
	if ( result ) {
		cast_value_dnum(result);
		result->type = PHP_VAL_STRING;
		result->str_val = strdup(ngettext(msgid->str_val, msgid_plural->str_val, count->int_val));
	}
}
示例#21
0
void php_native_search_start_cmd(PHP_VALUE_NODE *)
{
	PHP_SCOPE_ITEM *si = get_scope_item(g_current_scope, "__param_0");
	if ( !si || (si->var->value.type != PHP_VAL_STRING)) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 1 (search term)");
		return;
	}
	char *search = si->var->value.str_val;

	if ( !(si = get_scope_item(g_current_scope, "__param_1")) || (si->var->value.type != PHP_VAL_STRING)) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 2 (file extension)");
		return;
	}
	char *ext = si->var->value.str_val;

	if ( !(si = get_scope_item(g_current_scope, "__param_2")) || (si->var->value.type != PHP_VAL_STRING)) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 3 (file type)");
		return;
	}
	char *type = si->var->value.str_val;

	if ( !(si = get_scope_item(g_current_scope, "__param_3")) ) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 4 (search type)");
		return;
	}
	cast_value_dnum(&si->var->value);

	EC_SEARCH_TYPE search_type;
	switch(si->var->value.int_val) {
		case 0: search_type = EC_SEARCH_LOCAL; break;
		case 1: search_type = EC_SEARCH_GLOBAL; break;
		case 2: search_type = EC_SEARCH_KAD; break;
		default: 
			php_report_error(PHP_ERROR, "Invalid search type %"PRIu64, si->var->value.int_val);
			return;
	}

	if ( !(si = get_scope_item(g_current_scope, "__param_4")) ) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 5 (availability)");
		return;
	}
	cast_value_dnum(&si->var->value);
	int avail = si->var->value.int_val;

	if ( !(si = get_scope_item(g_current_scope, "__param_5")) ) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 6 (min size)");
		return;
	}
	cast_value_dnum(&si->var->value);
	int min_size = si->var->value.int_val;

	if ( !(si = get_scope_item(g_current_scope, "__param_6")) ) {
		php_report_error(PHP_ERROR, "Invalid or missing argument 7 (max size)");
		return;
	}
	cast_value_dnum(&si->var->value);
	int max_size = si->var->value.int_val;


	CPhPLibContext::g_curr_context->WebServer()->Send_Search_Cmd(
		wxString(char2unicode(search)), wxString(char2unicode(ext)), wxString(char2unicode(type)),
		search_type, avail, min_size, max_size);
}