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; }
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"); } }
/* * 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); } }
/* * 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); } } }
void load_session_vars(const char *target, std::map<std::string, std::string> &varmap) { PHP_EXP_NODE *sess_vars_exp_node = get_var_node(target); PHP_VAR_NODE *sess_vars = sess_vars_exp_node->var_si_node->var; // i'm not building exp tree, node not needed delete sess_vars_exp_node; cast_value_array(&sess_vars->value); for(std::map<std::string, std::string>::iterator i = varmap.begin(); i != varmap.end(); i++) { PHP_VAR_NODE *curr_var = array_get_by_str_key(&sess_vars->value, i->first); PHP_VALUE_NODE val; val.type = PHP_VAL_STRING; val.str_val = const_cast<char *>(i->second.c_str()); value_value_assign(&curr_var->value, &val); } }
/* * 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; }
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)); } }