📄 php_amule_lib.cpp
字号:
} wxASSERT(val != -1); //printf("OPT_DEBUG: %s of size %d -> %d\n", def->php_name, def->opsize, val); set_array_int_val(&catvar->value, def->php_name, val); }}/* * 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->GetTagCount()) { 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); }}bool php_2_ec_tag(CECTag *cattag, PHP_2_EC_OPT_DEF *opts, PHP_VALUE_NODE *catvar){ for(PHP_2_EC_OPT_DEF *def = opts; def->php_name; def++) { PHP_VAR_NODE *opt_var = array_get_by_str_key(catvar, def->php_name); if ( opt_var->value.type == PHP_VAL_NONE ) { continue; } cast_value_dnum(&opt_var->value); switch(def->opsize) { case 0: // always transmit ! case 1: cattag->AddTag(CECTag(def->tagname ,(uint8)opt_var->value.int_val)); break; case 2: cattag->AddTag(CECTag(def->tagname ,(uint16)opt_var->value.int_val)); break; case 4: cattag->AddTag(CECTag(def->tagname ,(uint32)opt_var->value.int_val)); break; default: return false; } } return true;}/* * 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);}/* * 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);}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);}/* * Request contents of log */void php_get_log(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_RESET_LOG); CPhPLibContext::g_curr_context->WebServer()->Send_Discard_V2_Request(&req); } CECPacket req(EC_OP_GET_LOG); const CECPacket *response = CPhPLibContext::g_curr_context->WebServer()->webInterface->SendRecvMsg_v2(&req); if (response) { wxString serverInfoString(_SpecialChars(response->GetTagByIndexSafe(0)->GetStringData())); delete response; result->type = PHP_VAL_STRING; result->str_val = strdup((const char *)unicode2UTF8(serverInfoString)); }}/* * 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->GetTagByIndexSafe(0)->GetStringData())); delete response; result->type = PHP_VAL_STRING; result->str_val = strdup((const char *)unicode2UTF8(serverInfoString)); }}/* * 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; }}/* * Load amule variables into interpreter scope. * "varname" will tell us, what kind of variables need to load: * "downloads", "uploads", "searchresult", "servers", "options" etc */template <class C, class T>void amule_obj_array_create(const char *class_name, PHP_VALUE_NODE *result){ if ( !result ) { return; } C *container = T::GetContainerInstance(); container->ReQuery(); typename std::list<T>::const_iterator it = container->GetBeginIterator(); while ( it != container->GetEndIterator()) { PHP_VAR_NODE *var = array_push_back(result); var->value.type = PHP_VAL_OBJECT; var->value.obj_val.class_name = class_name; const T *cur_item = &(*it); var->value.obj_val.inst_ptr = (void *)cur_item; it++; }}void amule_load_downloads(PHP_VALUE_NODE *result){ amule_obj_array_create<DownloadFileInfo, DownloadFile>("AmuleDownloadFile", result);}void amule_load_servers(PHP_VALUE_NODE *result){ amule_obj_array_create<ServersInfo, ServerEntry>("AmuleServer", result);}void amule_load_shared(PHP_VALUE_NODE *result){ amule_obj_array_create<SharedFileInfo, SharedFile>("AmuleSharedFile", result);}void amule_load_search(PHP_VALUE_NODE *result){ amule_obj_array_create<SearchInfo, SearchFile>("AmuleSearchFile", result);}void amule_load_uploads(PHP_VALUE_NODE *result){ amule_obj_array_create<UploadsInfo, UploadFile>("AmuleUploadFile", result);}void amule_load_stats(){ CPhPLibContext::g_curr_context->WebServer()->Reload_Stats();}/* * 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 (int i = 0; i < root->GetTagCount(); i++) { CEC_StatTree_Node_Tag *tag = (CEC_StatTree_Node_Tag*)root->GetTagByIndex(i); if (tag->GetTagName() == EC_TAG_STATTREE_NODE) { ecstats2php(tag, &v_key->value); } }}void amule_load_stats_tree(PHP_VALUE_NODE *result){ if ( !result ) { return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -