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 (CECTag::const_iterator it = stats_root->begin(); it != stats_root->end(); it++) { CEC_StatTree_Node_Tag *tag = (CEC_StatTree_Node_Tag*) & *it; if (tag->GetTagName() == EC_TAG_STATTREE_NODE) { ecstats2php(tag, result); } } }
/* * 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); } } }
// Formats a statistics (sub)tree to text wxString StatTree2Text(CEC_StatTree_Node_Tag *tree, int depth) { if (!tree) { return wxEmptyString; } wxString result = wxString(wxChar(' '), depth) + tree->GetDisplayString() + wxT("\n"); for (CECTag::const_iterator it = tree->begin(); it != tree->end(); it++) { CEC_StatTree_Node_Tag *tmp = (CEC_StatTree_Node_Tag*) & *it; if (tmp->GetTagName() == EC_TAG_STATTREE_NODE) { result += StatTree2Text(tmp, depth + 1); } } return result; }