📄 php_amule_lib.cpp
字号:
} value_value_free(result); CECPacket req(EC_OP_GET_STATSTREE, EC_DETAIL_WEB); const CECPacket *response = CPhPLibContext::g_curr_context->WebServer()->webInterface->SendRecvMsg_v2(&req); if ( !response ) { return; } const CECTag *server_ver = response->GetTagByName(EC_TAG_SERVER_VERSION); const CECTag *user_nick = response->GetTagByName(EC_TAG_USER_NICK); if ( !server_ver || !user_nick ) { delete response; return; } CEC_StatTree_Node_Tag *stats_root = (CEC_StatTree_Node_Tag *)response->GetTagByName(EC_TAG_STATTREE_NODE); //ecstats2php(stats_root, result); for (int i = 0; i < stats_root->GetTagCount(); i++) { CEC_StatTree_Node_Tag *tag = (CEC_StatTree_Node_Tag*)stats_root->GetTagByIndex(i); if (tag->GetTagName() == EC_TAG_STATTREE_NODE) { ecstats2php(tag, result); } }}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"); }}/* * 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); }}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->nHash); // 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->nHash); } 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->nHash); if ( !sharedfile ) { SharedFile::GetContainerInstance()->ReQuery(); sharedfile = SharedFile::GetContainerInstance()->GetByID(obj->nHash); } wxString short_name(sharedfile->sFileName.Length() > 60 ? (sharedfile->sFileName.Left(60) + (wxT(" ..."))) : sharedfile->sFileName); 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); }}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); }}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); }}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); }}void amule_version(PHP_VALUE_NODE *val){ if ( !val ) { return; } value_value_free(val); val->type = PHP_VAL_STRING; val->str_val = strdup(PACKAGE_VERSION);}PHP_BLTIN_FUNC_DEF amule_lib_funcs[] = { { "amule_load_vars", 1, php_native_load_amule_vars, }, { "amule_get_stats", 0, php_get_amule_stats, }, { "amule_get_categories", 0, php_get_amule_categories, }, { "amule_get_options", 0, php_get_amule_options, }, { "amule_set_options", 1, php_set_amule_options, }, { "amule_do_server_cmd", 3, php_native_server_cmd, }, { "amule_do_add_server_cmd", 3, php_native_add_server_cmd, }, { "amule_do_download_cmd", 3, php_native_download_file_cmd, }, { "amule_do_shared_cmd", 3, php_native_shared_file_cmd, }, { "amule_do_reload_shared_cmd", 0, php_native_reload_shared_file_cmd, }, { "amule_do_search_download_cmd", 2, php_native_search_download_cmd, }, { "amule_do_search_start_cmd", 7, php_native_search_start_cmd, }, { "amule_do_ed2k_download_cmd", 2, php_native_ed2k_download_cmd, }, { "amule_get_log", 1, php_get_log, }, { "amule_get_serverinfo", 1, php_get_serverinfo, }, { "amule_get_version", 0, amule_version, }, { 0, 0, 0, },};void php_init_amule_lib(){ // load function definitions PHP_BLTIN_FUNC_DEF *curr_def = amule_lib_funcs; while ( curr_def->name ) { php_add_native_func(curr_def); curr_def++; } // load object definitions php_add_native_class("AmuleDownloadFile", amule_download_file_prop_get); php_add_native_class("AmuleUploadFile", amule_upload_file_prop_get); php_add_native_class("AmuleServer", amule_server_prop_get); php_add_native_class("AmuleSharedFile", amule_shared_file_prop_get); php_add_native_class("AmuleSearchFile", amule_search_file_prop_get);}// File_checked_for_headers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -