php_core_lib.cpp
来自「wxWidgets写的电驴」· C++ 代码 · 共 1,791 行 · 第 1/4 页
CPP
1,791 行
printf("php_native_search_download_cmd: hash=%s category=%d\n", str_link, cat);#endif}/* * 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"); }}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"); }}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"); }}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, "start"); 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, "end"); PHP_VALUE_NODE end = { PHP_VAL_INT, 0 }; if ( si_end ) { end = si_end->var->value; } cast_value_dnum(&end);}/* * Load amule variables into interpreter scope. * "varname" will tell us, what kind of variables need to load: * "downloads", "uploads", "searchresult", "servers", "options" etc */#ifndef PHP_STANDALONE_ENtemplate <class C, class T>void amule_obj_array_create(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; } 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); } }}#elsevoid amule_fake_obj_array_create(int count, char *class_name, PHP_VALUE_NODE *result){ for (int i = 0; i < count; i++) { PHP_VAR_NODE *var = array_push_back(result); var->value.type = PHP_VAL_OBJECT; var->value.obj_val.class_name = class_name; var->value.obj_val.inst_ptr = 0; }}void amule_load_downloads(PHP_VALUE_NODE *result){ amule_fake_obj_array_create(10, "AmuleDownloadFile", result);}void amule_load_servers(PHP_VALUE_NODE *result){ amule_fake_obj_array_create(20, "AmuleServer", result);}void amule_load_shared(PHP_VALUE_NODE *result){ amule_fake_obj_array_create(15, "AmuleSharedFile", result);}void amule_load_search(PHP_VALUE_NODE *result){ amule_fake_obj_array_create(35, "AmuleSearchFile", result);}void amule_load_uploads(PHP_VALUE_NODE *result){ amule_fake_obj_array_create(17, "AmuleUploadFile", result);}void amule_load_stats(){}void amule_load_stats_tree(PHP_VALUE_NODE *){}#endifvoid 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 */#ifndef PHP_STANDALONE_ENvoid 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 { 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 must be out of sync with core if ( !sharedfile ) { SharedFile::GetContainerInstance()->ReQuery(); sharedfile = SharedFile::GetContainerInstance()->GetByID(obj->nHash); } result->str_val = strdup((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 ) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?