/** * Loads an area from XML file. * @param filename of the Area to load. * @param area An optional pointer to the area to load this into, otherwise a new one will be made. * @return Pointer to the loaded Area. */ Area* FileProcessor::loadArea(const string filename, Area* area) { if(!area) { area = new Area(DEFAULT_TAG); } FILE* fp; mxml_node_t *tree, *node; fp = fopen(filename.c_str(), "r"); if(!fp) { return NULL; } tree = mxmlLoadFile(NULL, fp, MXML_TEXT_CALLBACK); fclose(fp); for(node = tree->child; node; node = node->next) { if(node->type == MXML_ELEMENT) { if(strcasecmp(node->value.element.name, "area") == 0) { loadArea_Area(node, area); } } } mxmlDelete(tree); return area; }
/** * Returns the string of the value extracted from the XML value * * @param _xml_value The XML formatted value * * @return The string of the value or NULL if failed */ char* get_value_from_xml_value(char* xml_value) { mxml_node_t *xml; mxml_node_t *node; xml = mxmlLoadString(NULL, xml_value, MXML_TEXT_CALLBACK); if(xml == NULL) { printf("XML value format uncompatible with HomePort\n"); return NULL; } node = mxmlFindElement(xml, xml, "value", NULL, NULL, MXML_DESCEND); if(node == NULL || node-> child == NULL || node->child->value.text.string == NULL) { mxmlDelete(xml); printf("No \"value\" in the XML file\n"); return NULL; } char *return_value = malloc(sizeof(char)*(strlen(node->child->value.text.string)+1)); strcpy(return_value, node->child->value.text.string); mxmlDelete(xml); return return_value; }
void parseEntities(mxml_node_t *entities, struct t_tweet *dest){ mxml_node_t *group = NULL; mxml_node_t *unit = NULL; mxml_node_t *value = NULL; dest->hashtags = NULL; dest->mentions = NULL; group = mxmlFindElement(entities, entities, "user_mentions", NULL, NULL, MXML_DESCEND); if(group && group->child){ for(unit = mxmlFindElement(group, group, "user_mention", NULL, NULL, MXML_DESCEND); unit && unit->child; unit = mxmlFindElement(unit, group, "user_mention", NULL, NULL, MXML_DESCEND)){ dest->mentions = (struct t_mention *)mem2_realloc(dest->mentions, (++(dest->mentions_count))*sizeof(struct t_mention), MEM2_OTHER); value = mxmlFindElement(unit, unit, "screen_name", NULL, NULL, MXML_DESCEND); snprintf(dest->mentions[dest->mentions_count - 1].screenname, 20, "@%s", value->child->value.opaque); value = mxmlFindElement(unit, unit, "id", NULL, NULL, MXML_DESCEND); sscanf(value->child->value.opaque, "%llu", &(dest->mentions[dest->mentions_count - 1].id)); } } group = mxmlFindElement(entities, entities, "hashtags", NULL, NULL, MXML_DESCEND); if(group && group->child){ for(unit = mxmlFindElement(group, group, "hashtag", NULL, NULL, MXML_DESCEND); unit && unit->child; unit = mxmlFindElement(unit, group, "hashtag", NULL, NULL, MXML_DESCEND)){ dest->hashtags = (struct t_hashtag *)mem2_realloc(dest->hashtags, (++(dest->hashtags_count))*sizeof(struct t_hashtag), MEM2_OTHER); value = mxmlFindElement(unit, unit, "text", NULL, NULL, MXML_DESCEND); snprintf(dest->hashtags[dest->hashtags_count - 1].text, 64, "#%s", value->child->value.opaque); } } mxmlDelete(value); mxmlDelete(unit); mxmlDelete(group); }
void CloseXMLDatabase() { /* free memory */ if (xml_loaded) { mxmlDelete(nodedata); mxmlDelete(nodetree); xml_loaded = false; } }
int backup_extract_transfer_complete( mxml_node_t *node, char **msg_out, int *method_id) { mxml_node_t *tree_m, *b, *n; tree_m = mxmlLoadString(NULL, CWMP_TRANSFER_COMPLETE_MESSAGE, MXML_NO_CALLBACK); if (!tree_m) goto error; b = mxmlFindElement(node, node, "command_key", NULL, NULL, MXML_DESCEND); if (!b) goto error; n = mxmlFindElement(tree_m, tree_m, "CommandKey", NULL, NULL, MXML_DESCEND); if (!n) goto error; n = mxmlNewText(n, 0, b->child->value.text.string); if (!n) goto error; b = mxmlFindElement(node, node, "fault_code", NULL, NULL, MXML_DESCEND); if (!b) goto error; n = mxmlFindElement(tree_m, tree_m, "FaultCode", NULL, NULL, MXML_DESCEND); if (!n) goto error; n = mxmlNewText(n, 0, b->child->value.text.string); if (!n) goto error; b = mxmlFindElement(node, node, "fault_string", NULL, NULL, MXML_DESCEND); if (!b) goto error; if (b->child && b->child->type == MXML_TEXT && b->child->value.text.string) { n = mxmlFindElement(tree_m, tree_m, "FaultString", NULL, NULL, MXML_DESCEND); if (!n) goto error; char *c = xml_get_value_with_whitespace(b->child); n = mxmlNewText(n, 0, c); free(c); if (!n) goto error; } b = mxmlFindElement(node, node, "start_time", NULL, NULL, MXML_DESCEND); if (!b) goto error; n = mxmlFindElement(tree_m, tree_m, "StartTime", NULL, NULL, MXML_DESCEND); if (!n) goto error; n = mxmlNewText(n, 0, b->child->value.text.string); if (!n) goto error; b = mxmlFindElement(node, node, "complete_time", NULL, NULL, MXML_DESCEND); if (!b) goto error; n = mxmlFindElement(tree_m, tree_m, "CompleteTime", NULL, NULL, MXML_DESCEND); if (!n) goto error; n = mxmlNewText(n, 0, b->child->value.text.string); if (!n) goto error; b = mxmlFindElement(node, node, "method_id", NULL, NULL, MXML_DESCEND); if (!b) goto error; *method_id = atoi(b->child->value.text.string); *msg_out = mxmlSaveAllocString(tree_m, xml_format_cb); mxmlDelete(tree_m); return 0; error: mxmlDelete(tree_m); return -1; }
struct nftnl_expr *nftnl_mxml_expr_parse(mxml_node_t *node, struct nftnl_parse_err *err, struct nftnl_set_list *set_list) { mxml_node_t *tree; struct nftnl_expr *e; const char *expr_name; char *xml_text; uint32_t set_id; int ret; expr_name = mxmlElementGetAttr(node, "type"); if (expr_name == NULL) { err->node_name = "type"; err->error = NFTNL_PARSE_EMISSINGNODE; goto err; } e = nftnl_expr_alloc(expr_name); if (e == NULL) goto err; xml_text = mxmlSaveAllocString(node, MXML_NO_CALLBACK); if (xml_text == NULL) goto err_expr; tree = mxmlLoadString(NULL, xml_text, MXML_OPAQUE_CALLBACK); xfree(xml_text); if (tree == NULL) goto err_expr; ret = e->ops->xml_parse(e, tree, err); mxmlDelete(tree); if (set_list != NULL && strcmp(expr_name, "lookup") == 0 && nftnl_set_lookup_id(e, set_list, &set_id)) nftnl_expr_set_u32(e, NFTNL_EXPR_LOOKUP_SET_ID, set_id); return ret < 0 ? NULL : e; err_expr: nftnl_expr_free(e); err: mxmlDelete(tree); errno = EINVAL; return NULL; }
void StreamlineSetup::sendCounters() { mxml_node_t *xml; mxml_node_t *counters; xml = mxmlNewXML("1.0"); counters = mxmlNewElement(xml, "counters"); int count = 0; for (Driver *driver = Driver::getHead(); driver != NULL; driver = driver->getNext()) { count += driver->writeCounters(counters); } mxml_node_t *setup = mxmlNewElement(counters, "setup_warnings"); mxmlNewText(setup, 0, logg.getSetup()); if (count == 0) { logg.logError("No counters found, this could be because /dev/gator/events can not be read or because perf is not working correctly"); handleException(); } char* string = mxmlSaveAllocString(xml, mxmlWhitespaceCB); sendString(string, RESPONSE_XML); free(string); mxmlDelete(xml); }
void StreamlineSetup::handleRequest(char* xml) { mxml_node_t *tree, *node; const char * attr = NULL; tree = mxmlLoadString(NULL, xml, MXML_NO_CALLBACK); node = mxmlFindElement(tree, tree, TAG_REQUEST, ATTR_TYPE, NULL, MXML_DESCEND_FIRST); if (node) { attr = mxmlElementGetAttr(node, ATTR_TYPE); } if (attr && strcmp(attr, VALUE_EVENTS) == 0) { sendEvents(); logg.logMessage("Sent events xml response"); } else if (attr && strcmp(attr, VALUE_CONFIGURATION) == 0) { sendConfiguration(); logg.logMessage("Sent configuration xml response"); } else if (attr && strcmp(attr, VALUE_COUNTERS) == 0) { sendCounters(); logg.logMessage("Sent counters xml response"); } else if (attr && strcmp(attr, VALUE_CAPTURED) == 0) { CapturedXML capturedXML; char* capturedText = capturedXML.getXML(false); sendData(capturedText, strlen(capturedText), RESPONSE_XML); free(capturedText); logg.logMessage("Sent captured xml response"); } else if (attr && strcmp(attr, VALUE_DEFAULTS) == 0) { sendDefaults(); logg.logMessage("Sent default configuration xml response"); } else { char error[] = "Unknown request"; sendData(error, strlen(error), RESPONSE_NAK); logg.logMessage("Received unknown request:\n%s", xml); } mxmlDelete(tree); }
int parseUsers(std::string &xmlstr, struct t_user ** dest){ mxml_node_t *xml; mxml_node_t *unit; struct t_user * users = (struct t_user *)mem2_calloc(MAXUNITS, sizeof(struct t_user), MEM2_OTHER); if(!users){ return 0; } size_t pos = 0; while(1){ pos = xmlstr.find("&amp;", pos); if(pos == std::string::npos) break; xmlstr.replace(pos, 9, "&"); } xml = mxmlLoadString(NULL, xmlstr.c_str(), MXML_OPAQUE_CALLBACK); if(!xml){ mem2_free(users, MEM2_OTHER); return 0; } int t=0; for(unit = mxmlFindElement(xml, xml, "user", NULL, NULL, MXML_DESCEND); unit; unit = mxmlFindElement(unit, xml, "user", NULL, NULL, MXML_DESCEND)){ parseUser(unit, &users[t++]); } mxmlDelete(xml); if(t < MAXUNITS){ //Free unused memory users = (struct t_user *)mem2_realloc(users, t*sizeof(struct t_user), MEM2_OTHER); } *dest = users; return t; }
int parseSearch(std::string &xmlstr, struct t_tweet ** dest){ mxml_node_t *xml; mxml_node_t *unit; struct t_tweet * tweets = (struct t_tweet *)mem2_calloc(MAXUNITS, sizeof(struct t_tweet), MEM2_OTHER); if(!tweets){ return 0; } size_t pos = 0; while(1){ pos = xmlstr.find("&amp;", pos); if(pos == std::string::npos) break; xmlstr.replace(pos, 9, "&"); } xml = mxmlLoadString(NULL, xmlstr.c_str(), MXML_OPAQUE_CALLBACK); if(!xml){ mem2_free(tweets, MEM2_OTHER); return 0; } int t=0; for(unit = mxmlFindElement(xml, xml, "entry", NULL, NULL, MXML_DESCEND); unit && t < MAXUNITS; unit = mxmlFindElement(unit, xml, "entry", NULL, NULL, MXML_DESCEND)){ parseSearchEntry(unit, &tweets[t++]); } mxmlDelete(xml); if(t < MAXUNITS){ //Free unused memory tweets = (struct t_tweet *)mem2_realloc(tweets, t*sizeof(struct t_tweet), MEM2_OTHER); } *dest = tweets; return t; }
int xml_del_node(char * area, char *node) { mxml_node_t * xml = xml_root; mxml_node_t * xml_area; mxml_node_t * xml_node; int ret = -1; XML_LOCK(); do { xml_area = mxmlFindElement(xml, xml, area, NULL, NULL, MXML_DESCEND_FIRST);//超找area区域 if (xml_area == NULL) break; xml_node = mxmlFindElement(xml_area, xml, node, NULL, NULL, MXML_DESCEND_FIRST);//查看是否有node节点 if (xml_area == NULL) { //没有此节点 ret = 0; break; } mxmlDelete(xml_node); ret = 0; } while (0); XML_UNLOCK(); }
int command( char *nBI, char *command, char *message, int size) { mxml_node_t *xDoc; mxml_node_t *messageNode; mxml_node_t *innerNode[2]; xDoc = mxmlNewXML("1.0"); messageNode = mxmlNewElement(xDoc, "message"); innerNode[0] = mxmlNewElement(messageNode, "type"); mxmlNewText(innerNode[0], 0, "Command"); innerNode[1] = mxmlNewElement(messageNode, "Command"); mxmlNewText(innerNode[1], 0, command); mxmlSaveString (xDoc, message, size, MXML_NO_CALLBACK); mxmlDelete(xDoc); return 0; }
int logInMessage( char *nBI, char *name, char *hostName, char *message, int size) { mxml_node_t *xDoc; mxml_node_t *messageNode; mxml_node_t *innerNode[4]; xDoc = mxmlNewXML("1.0"); messageNode = mxmlNewElement(xDoc, "message"); innerNode[0] = mxmlNewElement(messageNode, "type"); mxmlNewText(innerNode[0], 0, "Login"); innerNode[1] = mxmlNewElement(messageNode, "nBI"); mxmlNewText(innerNode[1], 0, nBi); innerNode[2] = mxmlNewElement(messageNode, "name"); mxmlNewText(innerNode[2], 0, name); innerNode[3] = mxmlNewElement(messageNode, "hostName"); mxmlNewText(innerNode[3], 0, hostName); mxmlSaveString (xDoc, message, size, MXML_NO_CALLBACK); mxmlDelete(xDoc); return 0; }
int ConfigurationXML::parse(const char* configurationXML) { mxml_node_t *tree, *node; int ret; tree = mxmlLoadString(NULL, configurationXML, MXML_NO_CALLBACK); node = mxmlGetFirstChild(tree); while (node && mxmlGetType(node) != MXML_ELEMENT) node = mxmlWalkNext(node, tree, MXML_NO_DESCEND); ret = configurationsTag(node); node = mxmlGetFirstChild(node); while (node) { if (mxmlGetType(node) != MXML_ELEMENT) { node = mxmlWalkNext(node, tree, MXML_NO_DESCEND); continue; } configurationTag(node); node = mxmlWalkNext(node, tree, MXML_NO_DESCEND); } mxmlDelete(tree); return ret; }
int ConfigurationXML::parse(const char* configurationXML) { mxml_node_t *tree, *node; int ret; // clear counter overflow gSessionData->mCounterOverflow = 0; mIndex = 0; // disable all counters prior to parsing the configuration xml for (int i = 0; i < MAX_PERFORMANCE_COUNTERS; i++) { gSessionData->mCounters[i].setEnabled(false); } tree = mxmlLoadString(NULL, configurationXML, MXML_NO_CALLBACK); node = mxmlGetFirstChild(tree); while (node && mxmlGetType(node) != MXML_ELEMENT) node = mxmlWalkNext(node, tree, MXML_NO_DESCEND); ret = configurationsTag(node); node = mxmlGetFirstChild(node); while (node) { if (mxmlGetType(node) != MXML_ELEMENT) { node = mxmlWalkNext(node, tree, MXML_NO_DESCEND); continue; } configurationTag(node); node = mxmlWalkNext(node, tree, MXML_NO_DESCEND); } mxmlDelete(tree); return ret; }
int LoadSave_loadRocketXML(const text_t* path, TrackData* trackData) { FILE* fp = 0; mxml_node_t* tree = 0; #if defined(_WIN32) if (_wfopen_s(&fp, path, L"r") != 0) return false; #else if (!(fp = fopen(path, "r"))) return false; #endif if (!(tree = mxmlLoadFile(NULL, fp, MXML_TEXT_CALLBACK))) { fclose(fp); return false; } parseXml(tree, trackData); fclose(fp); mxmlDelete(tree); return true; }
/** * @brief Load callback for savegames in XML Format * @param[in] parent XML Node structure, where we get the information from */ qboolean STATS_LoadXML (xmlNode_t *parent) { xmlNode_t * stats; qboolean success = qtrue; stats = XML_GetNode(parent, SAVE_STATS_STATS); if (!stats) { Com_Printf("Did not find stats entry in xml!\n"); return qfalse; } ccs.campaignStats.missions = XML_GetInt(stats, SAVE_STATS_MISSIONS, 0); ccs.campaignStats.missionsWon = XML_GetInt(stats, SAVE_STATS_MISSIONSWON, 0); ccs.campaignStats.missionsLost = XML_GetInt(stats, SAVE_STATS_MISSIONSLOST, 0); ccs.campaignStats.basesBuilt = XML_GetInt(stats, SAVE_STATS_BASESBUILT, 0); ccs.campaignStats.basesAttacked = XML_GetInt(stats, SAVE_STATS_BASESATTACKED, 0); ccs.campaignStats.installationsBuilt = XML_GetInt(stats, SAVE_STATS_INSTALLATIONSBUILT, 0); ccs.campaignStats.interceptions = XML_GetInt(stats, SAVE_STATS_INTERCEPTIONS, 0); ccs.campaignStats.soldiersLost = XML_GetInt(stats, SAVE_STATS_SOLDIERSLOST, 0); ccs.campaignStats.soldiersNew = XML_GetInt(stats, SAVE_STATS_SOLDIERSNEW, 0); ccs.campaignStats.killedAliens = XML_GetInt(stats, SAVE_STATS_KILLEDALIENS, 0); ccs.campaignStats.rescuedCivilians = XML_GetInt(stats, SAVE_STATS_RESCUEDCIVILIANS, 0); ccs.campaignStats.researchedTechnologies = XML_GetInt(stats, SAVE_STATS_RESEARCHEDTECHNOLOGIES, 0); ccs.campaignStats.moneyInterceptions = XML_GetInt(stats, SAVE_STATS_MONEYINTERCEPTIONS, 0); ccs.campaignStats.moneyBases = XML_GetInt(stats, SAVE_STATS_MONEYBASES, 0); ccs.campaignStats.moneyResearch = XML_GetInt(stats, SAVE_STATS_MONEYRESEARCH, 0); ccs.campaignStats.moneyWeapons = XML_GetInt(stats, SAVE_STATS_MONEYWEAPONS, 0); ccs.campaignStats.ufosDetected = XML_GetInt(stats, SAVE_STATS_UFOSDETECTED, 0); ccs.campaignStats.alienBasesBuilt = XML_GetInt(stats, SAVE_STATS_ALIENBASESBUILT, 0); ccs.campaignStats.ufosStored = XML_GetInt(stats, SAVE_STATS_UFOSSTORED, 0); ccs.campaignStats.aircraftHad = XML_GetInt(stats, SAVE_STATS_AIRCRAFTHAD, 0); /* freeing the memory below this node */ mxmlDelete(stats); return success; }
int XMLwrapper::loadXMLfile(const char *filename){ if (tree!=NULL) mxmlDelete(tree); tree=NULL; ZERO(&parentstack,(int)sizeof(parentstack)); ZERO(&values,(int)sizeof(values)); stackpos=0; char *xmldata=doloadfile(filename); if (xmldata==NULL) return(-1);//the file could not be loaded or uncompressed printf("%s\n",xmldata); root=tree=mxmlLoadString(NULL,xmldata,MXML_OPAQUE_CALLBACK); delete []xmldata; if (tree==NULL) return(-2);//this is not XML node=root=mxmlFindElement(tree,tree,"paulstretch-data",NULL,NULL,MXML_DESCEND); if (root==NULL) return(-3);//the XML doesnt embbed required data push(root); values.xml_version.major=str2int(mxmlElementGetAttr(root,"version-major")); values.xml_version.minor=str2int(mxmlElementGetAttr(root,"version-minor")); return(0); };
int oss_list_multipart_uploads_parse_from_body(aos_pool_t *p, aos_list_t *bc, aos_list_t *upload_list, aos_string_t *key_marker, aos_string_t *upload_id_marker, int *truncated) { int res; mxml_node_t *root; const char next_key_marker_xml_path[] = "NextKeyMarker"; const char next_upload_id_marker_xml_path[] = "NextUploadIdMarker"; const char truncated_xml_path[] = "IsTruncated"; const char uploads_xml_path[] = "Upload"; char *next_key_marker; char *next_upload_id_marker; res = get_xmldoc(bc, &root); if (res == AOSE_OK) { next_key_marker = get_xmlnode_value(p, root, next_key_marker_xml_path); if (next_key_marker) { aos_str_set(key_marker, next_key_marker); } next_upload_id_marker = get_xmlnode_value(p, root, next_upload_id_marker_xml_path); if (next_upload_id_marker) { aos_str_set(upload_id_marker, next_upload_id_marker); } *truncated = get_truncated_from_xml(p, root, truncated_xml_path); oss_list_multipart_uploads_contents_parse(p, root, uploads_xml_path, upload_list); mxmlDelete(root); } return res; }
int oss_list_objects_parse_from_body(aos_pool_t *p, aos_list_t *bc, aos_list_t *object_list, aos_list_t *common_prefix_list, aos_string_t *marker, int *truncated) { int res; mxml_node_t *root; const char next_marker_xml_path[] = "NextMarker"; const char truncated_xml_path[] = "IsTruncated"; const char buckets_xml_path[] = "Contents"; const char common_prefix_xml_path[] = "CommonPrefixes"; char* next_marker; res = get_xmldoc(bc, &root); if (res == AOSE_OK) { next_marker = get_xmlnode_value(p, root, next_marker_xml_path); if (next_marker) { aos_str_set(marker, next_marker); } *truncated = get_truncated_from_xml(p, root, truncated_xml_path); oss_list_objects_contents_parse(p, root, buckets_xml_path, object_list); oss_list_objects_common_prefix_parse(p, root, common_prefix_xml_path, common_prefix_list); mxmlDelete(root); } return res; }
int oss_list_parts_parse_from_body(aos_pool_t *p, aos_list_t *bc, aos_list_t *part_list, aos_string_t *partnumber_marker, int *truncated) { int res; mxml_node_t *root; const char next_partnumber_marker_xml_path[] = "NextPartNumberMarker"; const char truncated_xml_path[] = "IsTruncated"; const char parts_xml_path[] = "Part"; char *next_partnumber_marker; res = get_xmldoc(bc, &root); if (res == AOSE_OK) { next_partnumber_marker = get_xmlnode_value(p, root, next_partnumber_marker_xml_path); if (next_partnumber_marker) { aos_str_set(partnumber_marker, next_partnumber_marker); } *truncated = get_truncated_from_xml(p, root, truncated_xml_path); oss_list_parts_contents_parse(p, root, parts_xml_path, part_list); mxmlDelete(root); } return res; }
mxml_node_t *nftnl_mxml_build_tree(const void *data, const char *treename, struct nftnl_parse_err *err, enum nftnl_parse_input input) { mxml_node_t *tree; switch (input) { case NFTNL_PARSE_BUFFER: tree = mxmlLoadString(NULL, data, MXML_OPAQUE_CALLBACK); break; case NFTNL_PARSE_FILE: tree = mxmlLoadFile(NULL, (FILE *)data, MXML_OPAQUE_CALLBACK); break; default: goto err; } if (tree == NULL) { err->error = NFTNL_PARSE_EBADINPUT; goto err; } if (tree->value.opaque != NULL && strcmp(tree->value.opaque, treename) == 0) return tree; err->error = NFTNL_PARSE_EMISSINGNODE; err->node_name = treename; mxmlDelete(tree); err: err->line = 0; err->column = 0; errno = EINVAL; return NULL; }
char* CapturedXML::getXML(bool includeTime) { char* xml_string; mxml_node_t *xml = getTree(includeTime); xml_string = mxmlSaveAllocString(xml, mxmlWhitespaceCB); mxmlDelete(xml); return xml_string; }
/** * Extracts the device XML description given its internal structure * * @param device_to_extract The Device that we want to extract * * @return The XML description of the device or NULL if failed */ char * extract_device_xml(Device *device_to_extract) { if(device_is_in_xml_file (device_to_extract) == HPD_NO) return NULL; mxml_node_t *xml; xml = mxmlNewXML("1.0"); mxml_node_t *new_device; new_device = mxmlNewElement(xml, "device"); if(device_to_extract->description != NULL) mxmlElementSetAttr(new_device, "desc", device_to_extract->description); if(device_to_extract->ID != NULL) mxmlElementSetAttr(new_device, "id", device_to_extract->ID); if(device_to_extract->vendorID != NULL) mxmlElementSetAttr(new_device, "vendorID", device_to_extract->vendorID); if(device_to_extract->productID != NULL) mxmlElementSetAttr(new_device, "productID", device_to_extract->productID); if(device_to_extract->version != NULL) mxmlElementSetAttr(new_device, "version", device_to_extract->version); if(device_to_extract->IP != NULL) mxmlElementSetAttr(new_device, "ip", device_to_extract->IP); if(device_to_extract->port != NULL) mxmlElementSetAttr(new_device, "port", device_to_extract->port); if(device_to_extract->location != NULL) mxmlElementSetAttr(new_device, "location", device_to_extract->location); if(device_to_extract->type != NULL) mxmlElementSetAttr(new_device, "type", device_to_extract->type); char* return_string = mxmlSaveAllocString(xml, MXML_NO_CALLBACK); mxmlDelete(xml); return return_string; }
static int l_mxml_closefile(lua_State *L) { mxml_node_t *tree; tree = l_checkMXML(L, 1); mxmlDelete(tree); }
XmlNode::~XmlNode() { if(_parent == NULL && _data != NULL) { mxmlDelete((mxml_node_t*)_data); _data = NULL; } }
bool UpdateCheck() { bool ret = 0; // we only check for an update if we have internet if(!networkInit) return 0; ShowAction("Checking for updates..."); class twitCurl twitterObj; std::string tmp("392315277"); // @WiiTwiity userid if( twitterObj.userGet(tmp, 1) ){ tmp.clear(); twitterObj.getLastWebResponse(tmp); }else{ CancelAction(); return 0; } mxml_node_t *xml; mxml_node_t *item; xml = mxmlLoadString(NULL, tmp.c_str(), MXML_OPAQUE_CALLBACK); if(!xml){ CancelAction(); return 0; } item = mxmlFindElement(xml, xml, "text", NULL, NULL, MXML_DESCEND); if(item) // Tweet found! { const char * tweet = item->child->value.opaque; int verMajor, verMinor, verPoint; if(sscanf(tweet, "WiiTweet %d.%d.%d released! SHA-1: %s", &verMajor, &verMinor, &verPoint, updateHash) == 4) { int curMajor = APPVERSION[0] - '0'; int curMinor = APPVERSION[2] - '0'; int curPoint = APPVERSION[4] - '0'; // check that the versioning is valid and is a newer version if((verMajor >= 0 && verMajor <= 9 && verMinor >= 0 && verMinor <= 9 && verPoint >= 0 && verPoint <= 9) && (verMajor > curMajor || (verMajor == curMajor && verMinor > curMinor) || (verMajor == curMajor && verMinor == curMinor && verPoint > curPoint))) { snprintf(updateURL, 128, "http://wiitweet.googlecode.com/files/wiitweet%%20%d.%d.%d.zip", verMajor, verMinor, verPoint); ret = 1; } } } mxmlDelete(xml); CancelAction(); return ret; }
bool XMLwrapper::checkfileinformation(char *filename){ stackpos=0; ZERO(&parentstack,(int)sizeof(parentstack)); if (tree!=NULL) mxmlDelete(tree);tree=NULL; char *xmldata=doloadfile(filename); if (xmldata==NULL) return(-1);//the file could not be loaded or uncompressed char *start=strstr(xmldata,"<INFORMATION>"); char *end=strstr(xmldata,"</INFORMATION>"); if ((start==NULL)||(end==NULL)||(start>end)) { delete []xmldata; return(false); }; end+=strlen("</INFORMATION>"); end[0]='\0'; tree=mxmlNewElement(MXML_NO_PARENT,"?xml"); node=root=mxmlLoadString(tree,xmldata,MXML_OPAQUE_CALLBACK); if (root==NULL) { delete []xmldata; mxmlDelete(tree); node=root=tree=NULL; return(false); }; root=mxmlFindElement(tree,tree,"INFORMATION",NULL,NULL,MXML_DESCEND); push(root); if (root==NULL){ delete []xmldata; mxmlDelete(tree); node=root=tree=NULL; return(false); }; exitbranch(); if (tree!=NULL) mxmlDelete(tree); delete []xmldata; node=root=tree=NULL; return(true); };
int node_process(char cmd, mxml_node_t *tree, char *key, char *val, int num) { mxml_node_t *node = NULL; switch (cmd) { case 'a': node = xpath_create(tree, key, num); if(NULL != node) { // although node-text is empty, keep empty mxmlNewText(node, 0, val); } else { eprintf("%s exist\n", key); // return __LINE__; } break; case 'd': node = xpath_find(tree, key, num); if(NULL != node) { mxmlDelete(node); } break; case 'w': node = xpath_find(tree, key, num); if (node == NULL) { eprintf("not found: [%d]%s\n", num, key); return __LINE__; } if (NULL != node->child) { // printf("set\n"); mxmlSetText(node->child, 0, val); // mxmlSetTextf() doesn't work } else { mxmlNewText(node, 0, val); } break; case 'r': node = xpath_find(tree, key, num); if (NULL != node) { // mxml-2.8 vs mxml-2.7 -> (node->child) vs (node->child->value.text.string) // printf("%p\n", (node->child)); if (node->child == NULL) { eprintf("%s __got_empty_text__\n", key); return __LINE__; } else { printf("%d %s %s\n", num, key, trimsps(node->child->value.opaque)); } } else { eprintf("not found: [%d]%s\n", num, key); return __LINE__; } } return 0; }
init_to_server_XML::init_to_server_XML(const string& sessionkey, const vector<string>& ports, const string& minproxy, const string& maxproxy, const string& username, const string& password) { mxml_node_t* xml; mxml_node_t* data; mxml_node_t* node; mxml_node_t* updata; mxml_node_t* lset; mxml_node_t* prange; mxml_node_t* login; /*all of these are not necciary, simply cleaner*/ xml = mxmlNewXML("1.0"); data = mxmlNewElement(xml,"bcmessage"); node = mxmlNewElement(data,"vers"); mxmlNewText(node,0,"1"); node = mxmlNewElement(data,"type"); mxmlNewText(node,0,"1"); node = mxmlNewElement(data,"sessionkey"); node = mxmlNewElement(data,"sessionnumchunks"); mxmlNewText(node,0,"0"); updata = mxmlNewElement(data,"message"); lset = mxmlNewElement(updata,"listenset"); for(unsigned int i = 0; i < ports.size(); i ++) { node = mxmlNewElement(lset,"port"); mxmlNewText(node,0,ports[i].c_str()); } prange = mxmlNewElement(updata,"proxyrange"); node = mxmlNewElement(prange,"min"); mxmlNewText(node,0,minproxy.c_str()); node = mxmlNewElement(prange,"max"); mxmlNewText(node,0,maxproxy.c_str()); login = mxmlNewElement(updata,"login"); node = mxmlNewElement(login,"username"); mxmlNewText(node,0,username.c_str()); node = mxmlNewElement(login,"password"); mxmlNewText(node,0,password.c_str()); char buffer[4096]; /*Should never approach this unless you're being stupid; and at that point, you can seg fault yourself.*/ mxmlSaveString(xml,buffer,4069,NULL); mxmlDelete(xml); initmsg = string(buffer); #ifdef CASCADE_DEBUG cerr << initmsg << endl;; ofstream f("init_to_server.xml"); f << initmsg; f.close(); #endif }