xupl* xupl_parse(xupl *xup) { xupl_*_ = (xupl_*) xup; FILE* in = _->in; off_t buffsize = _->buffsize; unsigned short bit = 0x0001; unsigned short WHITESPACE = bit; unsigned short DOUBLE_STRING = (bit <<= 1); unsigned short SINGLE_STRING = (bit <<= 1); unsigned short STRING = DOUBLE_STRING | SINGLE_STRING; unsigned short LINE_COMMENT = (bit <<= 1); unsigned short MULTI_COMMENT = (bit <<= 1); unsigned short COMMENT = LINE_COMMENT | MULTI_COMMENT; unsigned short _state = 0; const int default_tksize = 12; int tksize = default_tksize + 1; unsigned char *tk = NULL; int tkndx = 0; int chars_read; char* buf = malloc(buffsize + 1); xmlNodePtr xroot = NULL; xmlNodePtr xc = NULL; xmlAttrPtr xprop = NULL; const xmlChar* xuplAttr = (const xmlChar*) "data-xupl"; const xmlChar* xuplClosed = (const xmlChar*) "closed"; xmlDocPtr xdoc = xmlNewDoc((const unsigned char*) "1.1"); //xmlNsPtr xuplNs = xmlNewGlobalNs(xdoc,"http://ns.xupl.org/1.1","xupl"); while ((chars_read = fread(buf, 1, buffsize, in)) > 0) { for (int i = 0; i < chars_read; i++) { const char c = buf[i]; switch (c) { case '\'': case '"': IF(COMMENT) break; IF(STR(c)) { DISABLE(STR(c)); } else if (NOT(STRING)) { ALLOW(STR(c)); break; } case '{': case '}': case ' ': case '\n': case '\r': case '\t': case '\f': case '\v': case ',': case '=': // Comment characters case '*': case '/': case '#': case '!': IF(STRING) break; switch (c) { case ',': case '{': xprop = NULL; } if (tk) { tk[tkndx] = 0; char p = 0; if (tkndx >= 1) p = tk[tkndx - 1]; unsigned char* m = NULL; unsigned int tklen = tkndx + 1; unsigned char* t = tk; IF(COMMENT) { if ('\n' == c && IS(LINE_COMMENT)) { if (tkndx + 1 < tksize) { tk[tkndx++] = ' '; tk[tkndx] = 0; } } else if ('*' == p && '/' == c && IS(MULTI_COMMENT)) { tk[tkndx - 1] = 0; } else break; DISABLE(COMMENT); m = tk + 2; } else if ('/' == p && '*' == c) { ALLOW(MULTI_COMMENT); break; // Single-line comments can be #! #* #/ ## } else if ('#' == p && ('!' == c || '*' == c || '/' == c || '#' == c)) { ALLOW(LINE_COMMENT); break; // If these characters were in the token and not part of a comment, // then continue as if they are normal characters of a token. } else if ('!' == c || '/' == c || '*' == c || '#' == c) break; if (!xc) { if (m) { xroot = xmlNewDocComment(xdoc, m); xmlDocSetRootElement(xdoc, xroot); } else { xc = xmlNewNode(NULL, tk); xmlDocSetRootElement(xdoc, xc); if (!xroot) xroot = xc; } } else if (m) { xmlAddChild(xc, xmlNewComment(m)); } else { char *attr = NULL; xmlAttrPtr closed = xmlHasProp(xc, xuplAttr); switch (tk[0]) { case '\'': case '"': t += 1; xmlAddChild(xc, xmlNewText(t)); break; // TODO make this parameterized, characters and names. case '.': attr = "class"; break; case '#': attr = "id"; break; case '@': attr = "project"; break; case '/': attr = "href"; break; case '[': attr = "data"; break; case '~': attr = "duration"; break; case '=': attr = "location"; break; case '^': attr = "at"; break; case ':': attr = "type"; break; case '!': attr = "priority"; break; default: { regmatch_t pmatch[1]; unsigned int isword = 0 == regexec(&re_word, (char*) tk, 1, pmatch, 0); if (closed) { if (isword) { xc = xmlNewChild(xc, NULL, tk, NULL); } else { xmlAddChild(xc, xmlNewText(tk)); } } else { if (xprop) { xmlNewProp(xc, xprop->name, tk); xmlRemoveProp(xprop); xprop = NULL; } else if (isword) { xprop = xmlNewProp(xc, tk, (unsigned char*) "True"); } else { xprop = xmlNewProp(xc, (unsigned char*) ".fake", tk); } switch (c) { case ',': case '{': xprop = NULL; } } } break; } if (attr) { if (closed) { xmlAddChild(xc, xmlNewText(t)); } else { xmlNewProp(xc, (xmlChar*) attr, t); } } } free(tk); tk = NULL; if (tksize > default_tksize && tkndx < default_tksize) { tksize /= 2; } tkndx = 0; if (m) continue; } default: break; } switch (c) { case '{': xmlNewProp(xc, xuplAttr, xuplClosed); continue; case '}': if (xc) { xmlAttrPtr data = xmlHasProp(xc, xuplAttr); if (data) xmlRemoveProp(data); xc = xc->parent; } continue; default: break; } // Accumulate the tk. if (!tk || tkndx >= tksize) { // If the tk buffer is too small, double it. tk = realloc(tk, tksize *= 2); } tk[tkndx++] = c; }
str* build_dialoginfo(char *state, struct to_body *entity, struct to_body *peer, str *callid, unsigned int initiator, str *localtag, str *remotetag) { xmlDocPtr doc = NULL; xmlNodePtr root_node = NULL; xmlNodePtr dialog_node = NULL; xmlNodePtr state_node = NULL; xmlNodePtr remote_node = NULL; xmlNodePtr local_node = NULL; xmlNodePtr tag_node = NULL; xmlNodePtr id_node = NULL; str *body= NULL; char buf[MAX_URI_SIZE+1]; if (entity->uri.len > MAX_URI_SIZE) { LM_ERR("entity URI '%.*s' too long, maximum=%d\n",entity->uri.len, entity->uri.s, MAX_URI_SIZE); return NULL; } memcpy(buf, entity->uri.s, entity->uri.len); buf[entity->uri.len]= '\0'; /* create the Publish body */ doc = xmlNewDoc(BAD_CAST "1.0"); if(doc==0) return NULL; root_node = xmlNewNode(NULL, BAD_CAST "dialog-info"); if(root_node==0) goto error; xmlDocSetRootElement(doc, root_node); xmlNewProp(root_node, BAD_CAST "xmlns", BAD_CAST "urn:ietf:params:xml:ns:dialog-info"); xmlNewProp(root_node, BAD_CAST "state", BAD_CAST "partial" ); xmlNewProp(root_node, BAD_CAST "entity", BAD_CAST buf); /* version is set by dialoginfo_process_body() */ /* RFC 3245 differs between id and call-id. For example if a call is forked and 2 early dialogs are established, we should send 2 PUBLISH requests, both have the same call-id but different id. Thus, id could be for example derived from the totag. Currently the dialog module does not support multiple dialogs. Thus, it does no make sense to differ here between multiple dialog. Thus, id and call-id will be populated identically */ /* dialog tag */ dialog_node =xmlNewChild(root_node, NULL, BAD_CAST "dialog", NULL) ; if( dialog_node ==NULL) { LM_ERR("while adding child\n"); goto error; } if (callid->len > MAX_URI_SIZE) { LM_ERR("call-id '%.*s' too long, maximum=%d\n", callid->len, callid->s, MAX_URI_SIZE); return NULL; } memcpy(buf, callid->s, callid->len); buf[callid->len]= '\0'; xmlNewProp(dialog_node, BAD_CAST "id", BAD_CAST buf); if (include_callid) { xmlNewProp(dialog_node, BAD_CAST "call-id", BAD_CAST buf); } if (include_tags) { if (localtag && localtag->s) { if (localtag->len > MAX_URI_SIZE) { LM_ERR("localtag '%.*s' too long, maximum=%d\n", localtag->len, localtag->s, MAX_URI_SIZE); return NULL; } memcpy(buf, localtag->s, localtag->len); buf[localtag->len]= '\0'; xmlNewProp(dialog_node, BAD_CAST "local-tag", BAD_CAST buf); } if (remotetag && remotetag->s) { if (remotetag->len > MAX_URI_SIZE) { LM_ERR("remotetag '%.*s' too long, maximum=%d\n", remotetag->len, remotetag->s, MAX_URI_SIZE); return NULL; } memcpy(buf, remotetag->s, remotetag->len); buf[remotetag->len]= '\0'; xmlNewProp(dialog_node, BAD_CAST "remote-tag", BAD_CAST buf); } } if (initiator) { xmlNewProp(dialog_node, BAD_CAST "direction", BAD_CAST "initiator"); }else { xmlNewProp(dialog_node, BAD_CAST "direction", BAD_CAST "recipient"); } /* state tag */ state_node = xmlNewChild(dialog_node, NULL, BAD_CAST "state", BAD_CAST state) ; if( state_node ==NULL) { LM_ERR("while adding child\n"); goto error; } if (include_localremote) { /* remote tag*/ remote_node = xmlNewChild(dialog_node, NULL, BAD_CAST "remote", NULL) ; if( remote_node ==NULL) { LM_ERR("while adding child\n"); goto error; } if (peer->uri.len > MAX_URI_SIZE) { LM_ERR("peer '%.*s' too long, maximum=%d\n", peer->uri.len, peer->uri.s, MAX_URI_SIZE); return NULL; } memcpy(buf, peer->uri.s, peer->uri.len); buf[peer->uri.len]= '\0'; id_node = xmlNewChild(remote_node, NULL, BAD_CAST "identity", BAD_CAST buf) ; if( id_node ==NULL) { LM_ERR("while adding child\n"); goto error; } tag_node = xmlNewChild(remote_node, NULL, BAD_CAST "target", NULL) ; if( tag_node ==NULL) { LM_ERR("while adding child\n"); goto error; } xmlNewProp(tag_node, BAD_CAST "uri", BAD_CAST buf); /* if a display name present - add the display name information */ if(peer->display.s) { if(peer->display.len > MAX_URI_SIZE) { LM_ERR("display '%.*s' too long, maximum=%d\n", peer->display.len, peer->display.s, MAX_URI_SIZE); return NULL; } if(peer->display.s[0] == '"') { memcpy(buf, peer->display.s+1, peer->display.len-2); buf[peer->display.len-2] = '\0'; } else { memcpy(buf, peer->display.s, peer->display.len); buf[peer->display.len] = '\0'; } xmlNewProp(id_node, BAD_CAST "display", BAD_CAST buf); } /* local tag */ local_node = xmlNewChild(dialog_node, NULL, BAD_CAST "local", NULL) ; if( local_node ==NULL) { LM_ERR("while adding child\n"); goto error; } memcpy(buf, entity->uri.s, entity->uri.len); buf[entity->uri.len]= '\0'; id_node = xmlNewChild(local_node, NULL, BAD_CAST "identity", BAD_CAST buf) ; if( id_node ==NULL) { LM_ERR("while adding child\n"); goto error; } tag_node = xmlNewChild(local_node, NULL, BAD_CAST "target", NULL) ; if( tag_node ==NULL) { LM_ERR("while adding child\n"); goto error; } xmlNewProp(tag_node, BAD_CAST "uri", BAD_CAST buf); /* if a display name present - add the display name information */ if(entity->display.s) { if(entity->display.len > MAX_URI_SIZE) { LM_ERR("display '%.*s' too long, maximum=%d\n", entity->display.len, entity->display.s, MAX_URI_SIZE); return NULL; } if(entity->display.s[0] == '"') { memcpy(buf, entity->display.s+1, entity->display.len-2); buf[entity->display.len-2] = '\0'; } else { memcpy(buf, entity->display.s, entity->display.len); buf[entity->display.len] = '\0'; } xmlNewProp(id_node, BAD_CAST "display", BAD_CAST buf); } } /* create the body */ body = (str*)pkg_malloc(sizeof(str)); if(body == NULL) { LM_ERR("while allocating memory\n"); return NULL; } memset(body, 0, sizeof(str)); xmlDocDumpMemory(doc,(unsigned char**)(void*)&body->s,&body->len); LM_DBG("new_body:\n%.*s\n",body->len, body->s); /*free the document */ xmlFreeDoc(doc); xmlCleanupParser(); return body; error: if(body) { if(body->s) xmlFree(body->s); pkg_free(body); } if(doc) xmlFreeDoc(doc); return NULL; }
static xmlNodePtr xml_result(freesasa_node *result, int options) { xmlNodePtr xml_result_node = NULL, xml_structure = NULL, xml_param = NULL; freesasa_node *child = NULL; const freesasa_parameters *parameters; int exclude_type = FREESASA_NODE_NONE; assert(freesasa_node_type(result) == FREESASA_NODE_RESULT); parameters = freesasa_node_result_parameters(result); if (options & FREESASA_OUTPUT_STRUCTURE) exclude_type = FREESASA_NODE_CHAIN; if (options & FREESASA_OUTPUT_CHAIN) exclude_type = FREESASA_NODE_RESIDUE; if (options & FREESASA_OUTPUT_RESIDUE) exclude_type = FREESASA_NODE_ATOM; xml_result_node = xmlNewNode(NULL, BAD_CAST "result"); if (xml_result_node == NULL) { fail_msg(""); return NULL; } xml_param = parameters2xml(parameters); if (xml_param == NULL) { fail_msg(""); goto cleanup; } if (xmlAddChild(xml_result_node, xml_param) == NULL) { fail_msg(""); xmlFreeNode(xml_param); goto cleanup; } if (xmlNewProp(xml_result_node, BAD_CAST "classifier", BAD_CAST freesasa_node_classified_by(result)) == NULL) { fail_msg(""); goto cleanup; } if (xmlNewProp(xml_result_node, BAD_CAST "input", BAD_CAST freesasa_node_name(result)) == NULL) { fail_msg(""); goto cleanup; } child = freesasa_node_children(result); assert(child); while(child) { if (node2xml(&xml_structure, child, exclude_type, options) == FREESASA_FAIL) { fail_msg(""); goto cleanup; } if (xmlAddChild(xml_result_node, xml_structure) == NULL) { fail_msg(""); goto cleanup; } child = freesasa_node_next(child); }; return xml_result_node; cleanup: xmlFreeNode(xml_structure); xmlFreeNode(xml_result_node); return NULL; }
int main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char** argv) { xmlDocPtr doc; xmlNodePtr node; gchar *fname; xmlNodePtr out_top_node; xmlBufferPtr buf; fname = g_build_filename (ROOT_DIR, "libgda", FILE_NAME, NULL); if (! g_file_test (fname, G_FILE_TEST_EXISTS)) { g_free (fname); fname = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, FILE_NAME, NULL); if (! g_file_test (fname, G_FILE_TEST_EXISTS)) { g_print ("Could not find '%s'.\n", FILE_NAME); exit (1); } } doc = xmlParseFile (fname); if (!doc) { g_print ("Missing or malformed file '%s', check your installation", fname); g_free (fname); exit (1); } node = xmlDocGetRootElement (doc); g_free (fname); if (strcmp ((gchar *) node->name, "schema")) { g_print ("Root node should be <schema>, got <%s>\n", (gchar *) node->name); xmlFreeDoc (doc); exit (1); } out_top_node = xmlNewNode (NULL, BAD_CAST "sect2"); xmlAddChild (out_top_node, xmlNewComment (BAD_CAST "File generated by the tools/information-schema-doc program from the\n" "libgda/information-schema.xml file,\ndo not modify")); xmlNewChild (out_top_node, NULL, BAD_CAST "title", BAD_CAST "Individual table description"); xmlNewChild (out_top_node, NULL, BAD_CAST "para", BAD_CAST "This section individually describes each table."); for (node = node->children; node; node = node->next) { if (!strcmp ((gchar *) node->name, "table")) { xmlNodePtr snode, child, table, row, ref = NULL; xmlChar *prop; snode = xmlNewChild (out_top_node, NULL, BAD_CAST "sect3", NULL); prop = xmlGetProp (node, BAD_CAST "name"); if (prop) { gchar *str; str = g_strdup_printf ("is:%s", (gchar *) prop); xmlSetProp (snode, BAD_CAST "id", BAD_CAST str); g_free (str); str = g_strdup_printf ("%s table", (gchar *) prop); xmlNewTextChild (snode, NULL, BAD_CAST "title", BAD_CAST str); g_free (str); xmlFree (prop); } else xmlNewChild (snode, NULL, BAD_CAST "title", BAD_CAST "FIXME: table not named"); prop = xmlGetProp (node, BAD_CAST "descr"); if (prop) { xmlNewTextChild (snode, NULL, BAD_CAST "para", prop); xmlFree (prop); } table = xmlNewChild (snode, NULL, BAD_CAST "para", BAD_CAST "The following table describes the columns:"); table = xmlNewChild (table, NULL, BAD_CAST "informaltable", NULL); xmlSetProp (table, BAD_CAST "frame", BAD_CAST "all"); table = xmlNewChild (table, NULL, BAD_CAST "tgroup", NULL); xmlSetProp (table, BAD_CAST "cols", BAD_CAST "5"); xmlSetProp (table, BAD_CAST "colsep", BAD_CAST "1"); xmlSetProp (table, BAD_CAST "rowsep", BAD_CAST "1"); xmlSetProp (table, BAD_CAST "align", BAD_CAST "justify"); child = xmlNewChild (table, NULL, BAD_CAST "thead", NULL); row = xmlNewChild (child, NULL, BAD_CAST "row", NULL); xmlNewChild (row, NULL, BAD_CAST "entry", BAD_CAST "Column name"); xmlNewChild (row, NULL, BAD_CAST "entry", BAD_CAST "Type"); xmlNewChild (row, NULL, BAD_CAST "entry", BAD_CAST "Key"); xmlNewChild (row, NULL, BAD_CAST "entry", BAD_CAST "Can be NULL"); xmlNewChild (row, NULL, BAD_CAST "entry", BAD_CAST "description"); table = xmlNewChild (table, NULL, BAD_CAST "tbody", NULL); for (child = node->children; child; child = child->next) { if (!strcmp ((gchar *) child->name, "column")) { row = xmlNewChild (table, NULL, BAD_CAST "row", NULL); prop = xmlGetProp (child, BAD_CAST "name"); xmlNewChild (row, NULL, BAD_CAST "entry", prop ? prop : BAD_CAST "FIXME"); if (prop) xmlFree (prop); prop = xmlGetProp (child, BAD_CAST "type"); xmlNewChild (row, NULL, BAD_CAST "entry", prop ? prop : BAD_CAST "string"); if (prop) xmlFree (prop); prop = xmlGetProp (child, BAD_CAST "pkey"); xmlNewChild (row, NULL, BAD_CAST "entry", prop && ((*prop == 't') || (*prop == 'T')) ? BAD_CAST "Yes" : BAD_CAST ""); if (prop) xmlFree (prop); prop = xmlGetProp (child, BAD_CAST "nullok"); xmlNewChild (row, NULL, BAD_CAST "entry", prop && ((*prop == 't') || (*prop == 'T')) ? BAD_CAST "Yes" : BAD_CAST "No"); if (prop) xmlFree (prop); prop = xmlGetProp (child, BAD_CAST "descr"); xmlNewTextChild (row, NULL, BAD_CAST "entry", prop ? prop : BAD_CAST ""); if (prop) xmlFree (prop); } else if (!strcmp ((gchar *) child->name, "fkey")) { xmlNodePtr fkey; if (!ref) { ref = xmlNewChild (snode, NULL, BAD_CAST "para", NULL); ref = xmlNewChild (ref, NULL, BAD_CAST "itemizedlist", NULL); } fkey = xmlNewChild (ref, NULL, BAD_CAST "listitem", NULL); prop = xmlGetProp (child, BAD_CAST "ref_table"); if (prop) { gchar *str; GString *fk_str = NULL, *ref_pk_str = NULL; xmlNodePtr subnode, link; fkey = xmlNewChild (fkey, NULL, BAD_CAST "para", NULL); for (subnode = child->children; subnode; subnode = subnode->next) { xmlChar *column, *ref_column; if (strcmp ((gchar *) subnode->name, "part")) continue; column = xmlGetProp (subnode, BAD_CAST "column"); if (!column) continue; if (!fk_str) { fk_str = g_string_new ("("); ref_pk_str = g_string_new ("("); } else { g_string_append (fk_str, ", "); g_string_append (ref_pk_str, ", "); } g_string_append (fk_str, (gchar *) column); ref_column = xmlGetProp (subnode, BAD_CAST "ref_column"); if (ref_column) { g_string_append (ref_pk_str, (gchar *) ref_column); xmlFree (ref_column); } else g_string_append (ref_pk_str, (gchar *) column); xmlFree (column); } if (fk_str) { g_string_append (fk_str, ") "); g_string_append (ref_pk_str, ") "); } if (fk_str) { xmlNodeAddContent (fkey, BAD_CAST fk_str->str); g_string_free (fk_str, TRUE); } xmlNodeAddContent (fkey, BAD_CAST "references "); link = xmlNewTextChild (fkey, NULL, BAD_CAST "link", prop); str = g_strdup_printf ("is:%s", prop); xmlSetProp (link, BAD_CAST "linkend", BAD_CAST str); g_free (str); if (ref_pk_str) { xmlNodeAddContent (fkey, BAD_CAST ref_pk_str->str); g_string_free (ref_pk_str, TRUE); } if (prop) xmlFree (prop); } else fkey = xmlNewChild (ref, NULL, BAD_CAST "para", BAD_CAST "FIXME"); } } } else if (!strcmp ((gchar *) node->name, "view")) { xmlNodePtr snode, child, para; xmlChar *prop; snode = xmlNewChild (out_top_node, NULL, BAD_CAST "sect3", NULL); prop = xmlGetProp (node, BAD_CAST "name"); if (prop) { gchar *str; str = g_strdup_printf ("is:%s", (gchar *) prop); xmlSetProp (snode, BAD_CAST "id", BAD_CAST str); g_free (str); str = g_strdup_printf ("%s view", (gchar *) prop); xmlNewTextChild (snode, NULL, BAD_CAST "title", BAD_CAST str); g_free (str); xmlFree (prop); } else xmlNewChild (snode, NULL, BAD_CAST "title", BAD_CAST "FIXME: view not named"); prop = xmlGetProp (node, BAD_CAST "descr"); if (prop) { xmlNewTextChild (snode, NULL, BAD_CAST "para", prop); xmlFree (prop); } for (child = node->children; child; child = child->next) { if (!strcmp ((gchar *) child->name, "definition")) { xmlChar *def; def = xmlNodeGetContent (child); para = xmlNewChild (snode, NULL, BAD_CAST "para", BAD_CAST "Definition is:"); para = xmlNewTextChild (para, NULL, BAD_CAST "programlisting", def); xmlSetProp (para, BAD_CAST "width", BAD_CAST "80"); xmlFree (def); break; } } } } xmlFreeDoc (doc); buf = xmlBufferCreate(); xmlNodeDump (buf, NULL, out_top_node, 0, 1); if (! g_file_set_contents (OUT_FILE, (gchar*) xmlBufferContent (buf), -1, NULL)) g_print ("Could not write output file '%s'\n", OUT_FILE); else g_print ("Doc. written to '%s'\n", OUT_FILE); xmlBufferFree (buf); return 0; }
HRESULT CTSExecutorLIB::GetConfigurationData(xmlNodePtr pxmlNodePtr) { const char* omcVarChar ; //<Test_Suite_Name /> omcVarChar = m_omstrTestSuiteName.GetBuffer(MAX_PATH); xmlNodePtr pTSName = xmlNewChild(pxmlNodePtr, NULL, BAD_CAST DEF_TS_NAME, BAD_CAST omcVarChar); xmlAddChild(pxmlNodePtr, pTSName); // <IsEnable /> CString csIsEnabled; csIsEnabled.Format("%d", m_bTestSuiteStatus); omcVarChar = csIsEnabled; xmlNodePtr pIsEnabled = xmlNewChild(pxmlNodePtr, NULL, BAD_CAST DEF_IS_ENABLE, BAD_CAST omcVarChar); xmlAddChild(pxmlNodePtr, pIsEnabled); INT nFileCount = (INT)m_ouTestSetupEntityList.GetCount(); for(int iCnt = 0; iCnt < nFileCount; iCnt++) { //<TEST_SUITE> xmlNodePtr pTestSuite = xmlNewNode(NULL, BAD_CAST DEF_TEST_SUITE); xmlAddChild(pxmlNodePtr, pTestSuite); //<Test_Suite_Name /> POSITION pos = m_ouTestSetupEntityList.FindIndex(iCnt); CTestSetupEntity& ouTestSetupEntity = m_ouTestSetupEntityList.GetAt(pos); string omPath, omStrConfigFolder; char configPath[MAX_PATH]; AfxGetMainWnd()->SendMessage(MSG_GET_CONFIGPATH, (WPARAM)configPath, 0); CUtilFunctions::nGetBaseFolder(configPath, omStrConfigFolder ); CUtilFunctions::MakeRelativePath(omStrConfigFolder.c_str(), (char*)ouTestSetupEntity.m_omstrCurrentTSFile.GetBuffer(MAX_PATH), omPath); omcVarChar = omPath.c_str(); xmlNodePtr pFilePath = xmlNewChild(pTestSuite, NULL, BAD_CAST DEF_FILE_PATH, BAD_CAST omcVarChar); xmlAddChild(pTestSuite, pFilePath); //<IsEnable /> CString csIsEnabled; csIsEnabled.Format("%d", ouTestSetupEntity.bGetEnableStatus()); omcVarChar = csIsEnabled; xmlNodePtr pIsEnabled = xmlNewChild(pTestSuite, NULL, BAD_CAST DEF_IS_ENABLE, BAD_CAST omcVarChar); xmlAddChild(pTestSuite, pIsEnabled); //<Testcases_Selected> xmlNodePtr pTestCasesSel = xmlNewNode(NULL, BAD_CAST DEF_TEST_CASES_SEL); xmlAddChild(pTestSuite, pTestCasesSel); // <Index>1</Index> CString csIndex; bool bStatus; UINT unCount; ouTestSetupEntity.GetSubEntryCount(unCount); for(UINT j=0; j<unCount; j++) { CBaseEntityTA* pTCEntity; ouTestSetupEntity.GetSubEntityObj(j, &pTCEntity); bStatus = FALSE; if(pTCEntity != NULL) { bStatus = pTCEntity->bGetEnableStatus(); } if( bStatus == true ) { csIndex.Format("%d", j); omcVarChar = csIndex; xmlNodePtr pIndex = xmlNewChild(pTestCasesSel, NULL, BAD_CAST DEF_INDEX, BAD_CAST omcVarChar); xmlAddChild(pTestCasesSel, pIndex); } } } return true; }
static int noit_console_rule_configure(noit_console_closure_t ncct, int argc, char **argv, noit_console_state_t *state, void *closure) { xmlNodePtr fsnode = NULL; noit_conf_t_userdata_t *info; char xpath[1024]; info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); snprintf(xpath, sizeof(xpath), "/%s", info->path); fsnode = noit_conf_get_section(NULL, xpath); if(!fsnode) { nc_printf(ncct, "internal error"); return -1; } if(closure) { int rulenum; xmlNodePtr byebye; /* removing a rule */ if(argc != 1) { nc_printf(ncct, "requires one argument\n"); return -1; } rulenum = atoi(argv[0]); snprintf(xpath, sizeof(xpath), "rule[%d]", rulenum); byebye = noit_conf_get_section(fsnode, xpath); if(!byebye) { nc_printf(ncct, "cannot find rule\n"); return -1; } xmlUnlinkNode(byebye); xmlFreeNode(byebye); nc_printf(ncct, "removed\n"); } else { xmlNodePtr (*add_func)(xmlNodePtr, xmlNodePtr); xmlNodePtr add_arg, new_rule; int i, needs_type = 1; if(argc < 1 || argc % 2) { nc_printf(ncct, "even number of arguments required\n"); return -1; } if(!strcmp(argv[0], "before") || !strcmp(argv[0], "after")) { int rulenum = atoi(argv[1]); snprintf(xpath, sizeof(xpath), "rule[%d]", rulenum); add_arg = noit_conf_get_section(fsnode, xpath); if(!add_arg) { nc_printf(ncct, "%s rule not found\n", xpath); return -1; } if(*argv[0] == 'b') add_func = xmlAddPrevSibling; else add_func = xmlAddNextSibling; argc -= 2; argv += 2; } else { add_func = xmlAddChild; add_arg = fsnode; } for(i=0;i<argc;i+=2) { if(!strcmp(argv[i], "type")) needs_type = 0; else if(strcmp(argv[i], "target") && strcmp(argv[i], "module") && strcmp(argv[i], "name") && strcmp(argv[i], "metric")) { nc_printf(ncct, "unknown attribute '%s'\n", argv[i]); return -1; } } if(needs_type) { nc_printf(ncct, "type <allow|deny> is required\n"); return -1; } new_rule = xmlNewNode(NULL, (xmlChar *)"rule"); for(i=0;i<argc;i+=2) xmlSetProp(new_rule, (xmlChar *)argv[i], (xmlChar *)argv[i+1]); add_func(add_arg, new_rule); noit_filter_compile_add((noit_conf_section_t *)fsnode); } return 0; }
static xmlNodePtr msWFSDumpLayer11(mapObj *map, layerObj *lp, xmlNsPtr psNsOws) { rectObj ext; xmlNodePtr psRootNode, psNode; const char *value = NULL; const char *encoding = NULL; char *encoded=NULL; char *valueToFree; char **tokens; int n=0,i=0; encoding = msOWSLookupMetadata(&(map->web.metadata), "FO", "encoding"); if (!encoding) encoding = "ISO-8859-1"; psRootNode = xmlNewNode(NULL, BAD_CAST "FeatureType"); /* add namespace to layer name */ value = msOWSLookupMetadata(&(map->web.metadata), "FO", "namespace_prefix"); if(value) { n = strlen(value)+strlen(lp->name)+1+1; valueToFree = (char *) msSmallMalloc(sizeof(char*)*n); snprintf(valueToFree, n, "%s%s%s", (value ? value : ""), (value ? ":" : ""), lp->name); /*if there is an encoding using it on some of the items*/ psNode = msOWSCommonxmlNewChildEncoded(psRootNode, NULL, "Name", valueToFree, encoding); msFree(valueToFree); } else { psNode = msOWSCommonxmlNewChildEncoded(psRootNode, NULL, "Name", lp->name, encoding); } if (lp->name && strlen(lp->name) > 0 && (msIsXMLTagValid(lp->name) == MS_FALSE || isdigit(lp->name[0]))) xmlAddSibling(psNode, xmlNewComment(BAD_CAST "WARNING: The layer name '%s' might contain spaces or " "invalid characters or may start with a number. This could lead to potential problems")); value = msOWSLookupMetadata(&(lp->metadata), "FO", "title"); if (!value) value =(const char*)lp->name; psNode = msOWSCommonxmlNewChildEncoded(psRootNode, NULL, "Title", value, encoding); value = msOWSLookupMetadata(&(lp->metadata), "FO", "abstract"); if (value) psNode = msOWSCommonxmlNewChildEncoded(psRootNode, NULL, "Abstract", value, encoding); value = msOWSLookupMetadata(&(lp->metadata), "FO", "keywordlist"); if (value) { encoded = msGetEncodedString(value, encoding); msLibXml2GenerateList( xmlNewChild(psRootNode, psNsOws, BAD_CAST "Keywords", NULL), NULL, "Keyword", encoded, ',' ); msFree(encoded); } /*support DefaultSRS and OtherSRS*/ valueToFree = msOWSGetProjURN(&(map->projection),&(map->web.metadata),"FO",MS_FALSE); if (!valueToFree) valueToFree = msOWSGetProjURN(&(lp->projection), &(lp->metadata), "FO", MS_FALSE); if (valueToFree) { tokens = msStringSplit(valueToFree, ' ', &n); if (tokens && n > 0) { psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "DefaultSRS", BAD_CAST tokens[0]); for (i=1; i<n; i++) psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "OtherSRS", BAD_CAST tokens[i]); msFreeCharArray(tokens, n); } } else xmlAddSibling(psNode, xmlNewComment(BAD_CAST "WARNING: Mandatory mapfile parameter: (at least one of) MAP.PROJECTION, LAYER.PROJECTION or wfs/ows_srs metadata was missing in this context.")); free(valueToFree); valueToFree = NULL; /*TODO: adevertize only gml3?*/ psNode = xmlNewNode(NULL, BAD_CAST "OutputFormats"); xmlAddChild(psRootNode, psNode); { char *formats_list = msWFSGetOutputFormatList( map, lp, "1.1.0" ); int iformat, n; char **tokens; n = 0; tokens = msStringSplit(formats_list, ',', &n); for( iformat = 0; iformat < n; iformat++ ) xmlNewChild(psNode, NULL, BAD_CAST "Format", BAD_CAST tokens[iformat] ); msFree( formats_list ); msFreeCharArray( tokens, n ); } /*bbox*/ if (msOWSGetLayerExtent(map, lp, "FO", &ext) == MS_SUCCESS) { /*convert to latlong*/ if (lp->projection.numargs > 0) msOWSProjectToWGS84(&lp->projection, &ext); else msOWSProjectToWGS84(&map->projection, &ext); xmlAddChild(psRootNode, msOWSCommonWGS84BoundingBox( psNsOws, 2, ext.minx, ext.miny, ext.maxx, ext.maxy)); } else { xmlNewChild(psRootNode, psNsOws, BAD_CAST "WGS84BoundingBox", NULL); xmlAddSibling(psNode, xmlNewComment(BAD_CAST "WARNING: Optional WGS84BoundingBox could not be established for this layer. Consider setting the EXTENT in the LAYER object, or wfs_extent metadata. Also check that your data exists in the DATA statement")); } value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_href"); if (value) { psNode = xmlNewChild(psRootNode, NULL, BAD_CAST "MetadataURL", BAD_CAST value); value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_format"); if (!value) value = msStrdup("text/html"); /* default */ xmlNewProp(psNode, BAD_CAST "format", BAD_CAST value); value = msOWSLookupMetadata(&(lp->metadata), "FO", "metadataurl_type"); if (!value) value = msStrdup("FGDC"); /* default */ xmlNewProp(psNode, BAD_CAST "type", BAD_CAST value); } return psRootNode; }
str* build_pidf(ucontact_t* c) { xmlDocPtr doc = NULL; xmlNodePtr root_node = NULL; xmlNodePtr tuple_node = NULL; xmlNodePtr status_node = NULL; xmlNodePtr basic_node = NULL; str *body= NULL; str pres_uri= {NULL, 0}; char buf[BUF_LEN]; char* at= NULL; if(c->expires< (int)time(NULL)) { LM_DBG("found expired \n\n"); return NULL; } pres_uri.s = buf; if(pres_prefix.s) { memcpy(pres_uri.s, pres_prefix.s, pres_prefix.len); pres_uri.len+= pres_prefix.len; memcpy(pres_uri.s+ pres_uri.len, ":", 1); pres_uri.len+= 1; } if(pres_uri.len + c->aor->len+ 1 > BUF_LEN) { LM_ERR("buffer size overflown\n"); return NULL; } memcpy(pres_uri.s+ pres_uri.len, c->aor->s, c->aor->len); pres_uri.len+= c->aor->len; at = memchr(c->aor->s, '@', c->aor->len); if(!at) { if(pres_uri.len + 2 + default_domain.len > BUF_LEN) { LM_ERR("buffer size overflown\n"); return NULL; } pres_uri.s[pres_uri.len++]= '@'; memcpy(pres_uri.s+ pres_uri.len, default_domain.s, default_domain.len); pres_uri.len+= default_domain.len; } pres_uri.s[pres_uri.len]= '\0'; /* create the Publish body */ doc = xmlNewDoc(BAD_CAST "1.0"); if(doc==0) return NULL; root_node = xmlNewNode(NULL, BAD_CAST "presence"); if(root_node==0) goto error; xmlDocSetRootElement(doc, root_node); xmlNewProp(root_node, BAD_CAST "xmlns", BAD_CAST "urn:ietf:params:xml:ns:pidf"); xmlNewProp(root_node, BAD_CAST "xmlns:dm", BAD_CAST "urn:ietf:params:xml:ns:pidf:data-model"); xmlNewProp(root_node, BAD_CAST "xmlns:rpid", BAD_CAST "urn:ietf:params:xml:ns:pidf:rpid" ); xmlNewProp(root_node, BAD_CAST "xmlns:c", BAD_CAST "urn:ietf:params:xml:ns:pidf:cipid"); xmlNewProp(root_node, BAD_CAST "entity", BAD_CAST pres_uri.s); tuple_node =xmlNewChild(root_node, NULL, BAD_CAST "tuple", NULL) ; if( tuple_node ==NULL) { LM_ERR("while adding child\n"); goto error; } status_node = xmlNewChild(tuple_node, NULL, BAD_CAST "status", NULL) ; if( status_node ==NULL) { LM_ERR("while adding child\n"); goto error; } basic_node = xmlNewChild(status_node, NULL, BAD_CAST "basic", BAD_CAST "open") ; if( basic_node ==NULL) { LM_ERR("while adding child\n"); goto error; } body = (str*)pkg_malloc(sizeof(str)); if(body == NULL) { LM_ERR("while allocating memory\n"); return NULL; } memset(body, 0, sizeof(str)); xmlDocDumpFormatMemory(doc,(unsigned char**)(void*)&body->s,&body->len,1); LM_DBG("new_body:\n%.*s\n",body->len, body->s); /*free the document */ xmlFreeDoc(doc); xmlCleanupParser(); return body; error: if(body) { if(body->s) xmlFree(body->s); pkg_free(body); } if(doc) xmlFreeDoc(doc); return NULL; }
xmlDoc *marcmap_apply(struct marcmap *marcmap, xmlDoc *xml_in) { char mergekey[1024]; char medium[32]; char *s; NMEM nmem; xmlNsPtr ns_pz; xmlDocPtr xml_out; xmlNodePtr xml_out_root; xmlNodePtr rec_node; xmlNodePtr meta_node; struct marchash *marchash; struct marcfield *field; struct marcsubfield *subfield; struct marcmap *mmcur; xml_out = xmlNewDoc(BAD_CAST "1.0"); xml_out->encoding = xmlCharStrdup("UTF-8"); xml_out_root = xmlNewNode(NULL, BAD_CAST "record"); xmlDocSetRootElement(xml_out, xml_out_root); ns_pz = xmlNewNs(xml_out_root, BAD_CAST "http://www.indexdata.com/pazpar2/1.0", BAD_CAST "pz"); xmlSetNs(xml_out_root, ns_pz); nmem = nmem_create(); rec_node = xmlDocGetRootElement(xml_in); marchash = marchash_create(nmem); marchash_ingest_marcxml(marchash, rec_node); mmcur = marcmap; while (mmcur != NULL) { field = 0; while ((field = marchash_get_field(marchash, mmcur->field, field)) != 0) { // field value if ((mmcur->subfield == '$') && (s = field->val)) { meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST s); xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz); } // catenate all subfields else if ((mmcur->subfield == '*') && (s = marchash_catenate_subfields(field, " ", nmem))) { meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST s); xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz); } // subfield value else if (mmcur->subfield) { subfield = 0; while ((subfield = marchash_get_subfield(mmcur->subfield, field, subfield)) != 0) { if ((s = subfield->val) != 0) { meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST s); xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz); } } } } mmcur = mmcur->next; } // hard coded mappings // medium if ((field = marchash_get_field(marchash, "245", NULL)) && (subfield = marchash_get_subfield('h', field, NULL))) { strncpy(medium, subfield->val, 32); } else if ((field = marchash_get_field(marchash, "900", NULL)) && (subfield = marchash_get_subfield('a', field, NULL))) strcpy(medium, "electronic resource"); else if ((field = marchash_get_field(marchash, "900", NULL)) && (subfield = marchash_get_subfield('b', field, NULL))) strcpy(medium, "electronic resource"); else if ((field = marchash_get_field(marchash, "773", NULL)) && (subfield = marchash_get_subfield('t', field, NULL))) strcpy(medium, "article"); else strcpy(medium, "book"); meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST medium); xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST "medium"); // merge key memset(mergekey, 0, 1024); strcpy(mergekey, "title "); if ((field = marchash_get_field(marchash, "245", NULL)) && (subfield = marchash_get_subfield('a', field, NULL))) strncat(mergekey, subfield->val, 1023 - strlen(mergekey)); strncat(mergekey, " author ", 1023 - strlen(mergekey)); if ((field = marchash_get_field(marchash, "100", NULL)) && (subfield = marchash_get_subfield('a', field, NULL))) strncat(mergekey, subfield->val, 1023 - strlen(mergekey)); strncat(mergekey, " medium ", 1023 - strlen(mergekey)); strncat(mergekey, medium, 1023 - strlen(mergekey)); // xmlSetProp(xml_out_root, BAD_CAST "mergekey", BAD_CAST mergekey); nmem_destroy(nmem); return xml_out; }
void mate_wp_xml_save_list (AppearanceData *data) { xmlDoc * wplist; xmlNode * root, * wallpaper, * item; GSList * list = NULL; gchar * wpfile; g_hash_table_foreach (data->wp_hash, (GHFunc) mate_wp_list_flatten, &list); g_hash_table_destroy (data->wp_hash); list = g_slist_reverse (list); wpfile = g_build_filename (g_get_home_dir (), "/.mate2", "backgrounds.xml", NULL); xmlKeepBlanksDefault (0); wplist = xmlNewDoc ((xmlChar *)"1.0"); xmlCreateIntSubset (wplist, (xmlChar *)"wallpapers", NULL, (xmlChar *)"mate-wp-list.dtd"); root = xmlNewNode (NULL, (xmlChar *)"wallpapers"); xmlDocSetRootElement (wplist, root); while (list != NULL) { MateWPItem * wpitem = list->data; const char * none = "(none)"; gchar * filename; const gchar * scale, * shade; gchar * pcolor, * scolor; if (!strcmp (wpitem->filename, none) || (g_utf8_validate (wpitem->filename, -1, NULL) && g_file_test (wpitem->filename, G_FILE_TEST_EXISTS))) filename = g_strdup (wpitem->filename); else filename = g_filename_to_utf8 (wpitem->filename, -1, NULL, NULL, NULL); pcolor = gdk_color_to_string (wpitem->pcolor); scolor = gdk_color_to_string (wpitem->scolor); scale = wp_item_option_to_string (wpitem->options); shade = wp_item_shading_to_string (wpitem->shade_type); wallpaper = xmlNewChild (root, NULL, (xmlChar *)"wallpaper", NULL); mate_wp_xml_set_bool (wallpaper, (xmlChar *)"deleted", wpitem->deleted); item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"name", (xmlChar *)wpitem->name); item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"filename", (xmlChar *)filename); item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"options", (xmlChar *)scale); item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"shade_type", (xmlChar *)shade); item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"pcolor", (xmlChar *)pcolor); item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"scolor", (xmlChar *)scolor); g_free (pcolor); g_free (scolor); g_free (filename); list = g_slist_delete_link (list, list); mate_wp_item_free (wpitem); } xmlSaveFormatFile (wpfile, wplist, 1); xmlFreeDoc (wplist); g_free (wpfile); }
static gboolean status_presets_file_save (void) { xmlDocPtr doc; xmlNodePtr root; GList *l; gchar *dir; gchar *file; gint count[TP_NUM_CONNECTION_PRESENCE_TYPES]; gint i; for (i = 0; i < TP_NUM_CONNECTION_PRESENCE_TYPES; i++) { count[i] = 0; } dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL); g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR); file = g_build_filename (dir, STATUS_PRESETS_XML_FILENAME, NULL); g_free (dir); doc = xmlNewDoc ((const xmlChar *) "1.0"); root = xmlNewNode (NULL, (const xmlChar *) "presets"); xmlDocSetRootElement (doc, root); if (default_preset) { xmlNodePtr subnode; xmlChar *state; state = (xmlChar *) empathy_presence_to_str (default_preset->state); subnode = xmlNewTextChild (root, NULL, (const xmlChar *) "default", (const xmlChar *) default_preset->status); xmlNewProp (subnode, (const xmlChar *) "presence", state); } for (l = presets; l; l = l->next) { StatusPreset *sp; xmlNodePtr subnode; xmlChar *state; sp = l->data; state = (xmlChar *) empathy_presence_to_str (sp->state); count[sp->state]++; if (count[sp->state] > STATUS_PRESETS_MAX_EACH) { continue; } subnode = xmlNewTextChild (root, NULL, (const xmlChar *) "status", (const xmlChar *) sp->status); xmlNewProp (subnode, (const xmlChar *) "presence", state); } /* Make sure the XML is indented properly */ xmlIndentTreeOutput = 1; DEBUG ("Saving file:'%s'", file); xmlSaveFormatFileEnc (file, doc, "utf-8", 1); xmlFreeDoc (doc); g_free (file); return TRUE; }
int DEFAULT_CC send_logoff(int client, int session_id) { struct session_item* sess; xmlNodePtr node, node2; xmlDocPtr doc; xmlChar* version; xmlChar* response; xmlChar* session; xmlChar* username; xmlChar* username_value; xmlChar* id; xmlChar* id_value; xmlChar* status; xmlChar* status_value; char prop[128]; int display; if (session_id == 0) { log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[send_logoff]: " "%i is not a valid session id", session_id); return 1; } log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[send_logoff]: " "request session %i logoff", session_id); lock_chain_acquire(); sess = session_get_by_display(session_id); lock_chain_release(); if( sess == NULL) { log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[send_logoff]: " "The session %i did not exist", session_id); xml_send_error(client, "the session id of the request did not exist"); return 1; } session_update_status_by_user(sess->name, SESMAN_SESSION_STATUS_TO_DESTROY); version = xmlCharStrdup("1.0"); doc = xmlNewDoc(version); if (doc == NULL) { log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[send_logoff]: " "Unable to create the document"); g_free(sess); xmlFree(version); xmlFreeDoc(doc); return 1; } doc->encoding = xmlCharStrdup("UTF-8"); response = xmlCharStrdup("response"); session = xmlCharStrdup("session"); node = xmlNewNode(NULL, response); node2 = xmlNewNode(NULL, session); sprintf(prop, "%i", display); id = xmlCharStrdup("id"); id_value = xmlCharStrdup(prop); username = xmlCharStrdup("username"); username_value = xmlCharStrdup(sess->name); status = xmlCharStrdup("status"); status_value = xmlCharStrdup("CLOSED"); xmlSetProp(node2, id, id_value); xmlSetProp(node2, username, username_value); xmlSetProp(node2, status, status_value); xmlAddChild(node, node2); xmlDocSetRootElement(doc, node); xml_send_info(client, doc); xmlFreeDoc(doc); xmlFree(version); xmlFree(response); xmlFree(session); xmlFree(username); xmlFree(username_value); xmlFree(id); xmlFree(id_value); xmlFree(status); xmlFree(status_value); g_free(sess); return 0; }
int DEFAULT_CC send_session(int client, int session_id, char* user) { struct session_item* sess = NULL; xmlNodePtr node, node2; xmlDocPtr doc; xmlChar* version; xmlChar* response; xmlChar* session; xmlChar* id; xmlChar* id_value; xmlChar* username; xmlChar* username_value; xmlChar* status; xmlChar* status_value; log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_session]: " "request for session\n"); lock_chain_acquire(); if (user == NULL || user[0] == '\0') { sess = session_get_by_display(session_id); } else { sess = session_get_bydata(user); } lock_chain_release(); if( sess == NULL && session_id != 0) { log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[send_session]: " "the session %i did not exist",session_id); sess = g_malloc(sizeof(struct session_item), 1); sess->display = session_id; sess->status = SESMAN_SESSION_STATUS_UNKNOWN; g_snprintf(sess->name, sizeof(sess->name), "UNKNOW"); } version = xmlCharStrdup("1.0"); doc = xmlNewDoc(version); if (doc == NULL) { log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_session]: " "Unable to create the document"); if (sess != NULL) { g_free(sess); } return 1; } doc->encoding = xmlCharStrdup("UTF-8"); response = xmlCharStrdup("response"); session = xmlCharStrdup("session"); node = xmlNewNode(NULL, response); node2 = xmlNewNode(NULL, session); if (sess != NULL) { char prop[128] = {0}; g_sprintf(prop, "%i", sess->display); id = xmlCharStrdup("id"); id_value = xmlCharStrdup(prop); username = xmlCharStrdup("username"); username_value = xmlCharStrdup(sess->name); status = xmlCharStrdup("status"); status_value = xmlCharStrdup(session_get_status_string(sess->status)); xmlSetProp(node2, id, id_value); xmlSetProp(node2, username, username_value); xmlSetProp(node2, status, status_value ); xmlAddChild(node, node2); } xmlDocSetRootElement(doc, node); xml_send_info(client, doc); xmlFree(response); xmlFree(session); xmlFree(version); xmlFreeDoc(doc); if (sess != NULL) { xmlFree(id); xmlFree(id_value); xmlFree(username); xmlFree(username_value); xmlFree(status); xmlFree(status_value); g_free(sess); } return 0; }
int DEFAULT_CC send_sessions(int client) { struct session_item* sess; xmlNodePtr node, node2, node3; xmlDocPtr doc; int count, i; xmlChar* version; xmlChar* encoding; xmlChar* s_node; xmlChar* s_node2; log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_sessions]: " "request for sessions list"); lock_chain_acquire(); sess = (struct session_item*)session_list_session(&count); lock_chain_release(); log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_sessions]: " "%i count sessions",count); version = xmlCharStrdup("1.0"); doc = xmlNewDoc(version); if (doc ==NULL) { log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_sessions]: " "Unable to create the document"); return 1; } doc->encoding = xmlCharStrdup("UTF-8"); s_node = xmlCharStrdup("response"); node = xmlNewNode(NULL, s_node); s_node2 = xmlCharStrdup("sessions"); node2 = xmlNewNode(NULL, s_node2); xmlAddChild(node, node2); char prop[128]; for ( i=0 ; i<count ; i++) { g_sprintf(prop, "%i", sess[i].display); xmlChar* s_session = xmlCharStrdup("session"); xmlChar* s_id = xmlCharStrdup("id"); xmlChar* s_id_value = xmlCharStrdup(prop); xmlChar* s_username = xmlCharStrdup("username"); xmlChar* s_username_value = xmlCharStrdup(sess[i].name); xmlChar* s_status = xmlCharStrdup("status"); xmlChar* s_status_value = xmlCharStrdup(session_get_status_string(sess[i].status)); node3 = xmlNewNode(NULL, s_session); xmlSetProp(node3, s_id, s_id_value ); xmlSetProp(node3, s_username, s_username_value); xmlSetProp(node3, s_status, s_status_value ); xmlAddChild(node2, node3); xmlFree(s_session); xmlFree(s_id); xmlFree(s_id_value); xmlFree(s_username); xmlFree(s_username_value); xmlFree(s_status); xmlFree(s_status_value); } xmlAddChild(node, node2); xmlDocSetRootElement(doc, node); xml_send_info(client, doc); xmlFree(version); xmlFree(s_node); xmlFree(s_node2); g_free(sess); xmlFreeDoc(doc); return 0; }
/* * Create xml content for the gallery ready to be written to disk. */ guchar * xml_gal_write(struct data *data, gsize *len) { xmlDocPtr doc; xmlNodePtr gallery, settings, pages, page, page_settings; xmlChar *xmlbuff; gchar tmp_setting[256]; int bufsize; GSList *list; g_assert(data != NULL); g_assert(len != NULL); g_debug("in xml_gal_write"); /* CHECKME: extra block to help emacs with indenting.. */ { LIBXML_TEST_VERSION } /* create new xml with pwgallery as the root element */ doc = xmlNewDoc(BAD_CAST "1.0"); gallery = xmlNewNode(NULL, BAD_CAST "pwgallery"); xmlDocSetRootElement(doc, gallery); /* add settings node under pwgallery node */ settings = xmlNewNode(NULL, BAD_CAST "settings"); xmlAddChild(gallery, settings); /* add settings under the settings node */ xmlNewChild(settings, NULL, BAD_CAST "version", BAD_CAST VERSION); xmlNewTextChild(settings, NULL, BAD_CAST "name", BAD_CAST data->gal->name); xmlNewTextChild(settings, NULL, BAD_CAST "dir_name", BAD_CAST data->gal->dir_name); xmlNewTextChild(settings, NULL, BAD_CAST "desc", BAD_CAST data->gal->desc); xmlNewChild(settings, NULL, BAD_CAST "output_dir", BAD_CAST data->gal->base_dir); xmlNewChild(settings, NULL, BAD_CAST "page_gen_prog", BAD_CAST data->gal->page_gen_prog); xmlNewChild(settings, NULL, BAD_CAST "templ_index", BAD_CAST data->gal->templ_index); xmlNewChild(settings, NULL, BAD_CAST "templ_indeximg", BAD_CAST data->gal->templ_indeximg); xmlNewChild(settings, NULL, BAD_CAST "templ_indexgen", BAD_CAST data->gal->templ_indexgen); xmlNewChild(settings, NULL, BAD_CAST "templ_image", BAD_CAST data->gal->templ_image); xmlNewChild(settings, NULL, BAD_CAST "templ_gen", BAD_CAST data->gal->templ_gen); g_snprintf(tmp_setting, 256, "%d", data->gal->page_gen); xmlNewChild(settings, NULL, BAD_CAST "page_gen", BAD_CAST tmp_setting); g_snprintf(tmp_setting, 256, "%d", data->gal->thumb_w); xmlNewChild(settings, NULL, BAD_CAST "thumb_w", BAD_CAST tmp_setting); g_snprintf(tmp_setting, 256, "%d", data->gal->image_h); xmlNewChild(settings, NULL, BAD_CAST "image_h", BAD_CAST tmp_setting); g_snprintf(tmp_setting, 256, "%d", data->gal->image_h2); xmlNewChild(settings, NULL, BAD_CAST "image_h2", BAD_CAST tmp_setting); g_snprintf(tmp_setting, 256, "%d", data->gal->image_h3); xmlNewChild(settings, NULL, BAD_CAST "image_h3", BAD_CAST tmp_setting); g_snprintf(tmp_setting, 256, "%d", data->gal->image_h4); xmlNewChild(settings, NULL, BAD_CAST "image_h4", BAD_CAST tmp_setting); xmlNewChild(settings, NULL, BAD_CAST "edited", BAD_CAST (data->gal->edited ? "true" : "false")); xmlNewChild(settings, NULL, BAD_CAST "remove_exif", BAD_CAST (data->gal->remove_exif ? "true" : "false")); xmlNewChild(settings, NULL, BAD_CAST "rename", BAD_CAST (data->gal->rename ? "true" : "false")); /* add pages node under pwgallery node */ pages = xmlNewNode(NULL, BAD_CAST "pages"); xmlAddChild(gallery, pages); /* add pages (images/generic) under the pages node */ list = data->gal->images; while(list != NULL) { struct image *img = list->data; /* FIXME: how to support generic pages here? */ page = xmlNewNode(NULL, BAD_CAST "image"); xmlAddChild(pages, page); /* add page settings node under page node */ page_settings = xmlNewNode(NULL, BAD_CAST "settings"); xmlAddChild(page, page_settings); /* add page settings under the page settings node */ xmlNewTextChild(page_settings, NULL, BAD_CAST "text", BAD_CAST img->text); xmlNewTextChild(page_settings, NULL, BAD_CAST "uri", BAD_CAST img->uri); g_snprintf(tmp_setting, 256, "%f", img->gamma); xmlNewChild(page_settings, NULL, BAD_CAST "gamma", BAD_CAST tmp_setting); g_snprintf(tmp_setting, 256, "%d", img->rotate); xmlNewChild(page_settings, NULL, BAD_CAST "rotate", BAD_CAST tmp_setting); g_snprintf(tmp_setting, 256, "%d", img->image_h); xmlNewChild(page_settings, NULL, BAD_CAST "image_h", BAD_CAST tmp_setting); g_snprintf(tmp_setting, 256, "%s", img->nomodify == TRUE ? "true" : "false"); xmlNewChild(page_settings, NULL, BAD_CAST "nomodify", BAD_CAST tmp_setting); list = list->next; } /* dump xml to a buffer */ xmlDocDumpFormatMemory(doc, &xmlbuff, &bufsize, 1); *len = (gsize)bufsize; xmlFreeDoc(doc); xmlCleanupParser(); return (guchar *)xmlbuff; }
xmlNode *oval_definition_model_to_dom(struct oval_definition_model *definition_model, xmlDocPtr doc, xmlNode * parent) { xmlNodePtr root_node = NULL; if (parent) { /* result file */ root_node = xmlNewTextChild(parent, NULL, BAD_CAST OVAL_ROOT_ELM_DEFINITIONS, NULL); } else { /* definitions file, we are the root */ root_node = xmlNewNode(NULL, BAD_CAST OVAL_ROOT_ELM_DEFINITIONS); xmlDocSetRootElement(doc, root_node); } xmlNewNsProp(root_node, lookup_xsi_ns(doc), BAD_CAST "schemaLocation", BAD_CAST definition_model->schema); xmlNs *ns_common = xmlNewNs(root_node, OVAL_COMMON_NAMESPACE, BAD_CAST "oval"); xmlNs *ns_unix = xmlNewNs(root_node, OVAL_DEFINITIONS_UNIX_NS, BAD_CAST "unix-def"); xmlNs *ns_ind = xmlNewNs(root_node, OVAL_DEFINITIONS_IND_NS, BAD_CAST "ind-def"); xmlNs *ns_lin = xmlNewNs(root_node, OVAL_DEFINITIONS_LIN_NS, BAD_CAST "lin-def"); xmlNs *ns_defntns = xmlNewNs(root_node, OVAL_DEFINITIONS_NAMESPACE, NULL); xmlSetNs(root_node, ns_common); xmlSetNs(root_node, ns_unix); xmlSetNs(root_node, ns_ind); xmlSetNs(root_node, ns_lin); xmlSetNs(root_node, ns_defntns); /* Always report the generator */ oval_generator_to_dom(definition_model->generator, doc, root_node); /* Report definitions */ struct oval_definition_iterator *definitions = oval_definition_model_get_definitions(definition_model); if (oval_definition_iterator_has_more(definitions)) { xmlNode *definitions_node = NULL; while(oval_definition_iterator_has_more(definitions)) { struct oval_definition *definition = oval_definition_iterator_next(definitions); if (definitions_node == NULL) { definitions_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "definitions", NULL); } oval_definition_to_dom(definition, doc, definitions_node); } } oval_definition_iterator_free(definitions); /* Report tests */ struct oval_test_iterator *tests = oval_definition_model_get_tests(definition_model); if (oval_test_iterator_has_more(tests)) { xmlNode *tests_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "tests", NULL); while (oval_test_iterator_has_more(tests)) { struct oval_test *test = oval_test_iterator_next(tests); oval_test_to_dom(test, doc, tests_node); } } oval_test_iterator_free(tests); /* Report objects */ struct oval_object_iterator *objects = oval_definition_model_get_objects(definition_model); if (oval_object_iterator_has_more(objects)) { xmlNode *objects_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "objects", NULL); while(oval_object_iterator_has_more(objects)) { struct oval_object *object = oval_object_iterator_next(objects); if (oval_object_get_base_obj(object)) /* Skip internal objects */ continue; oval_object_to_dom(object, doc, objects_node); } } oval_object_iterator_free(objects); /* Report states */ struct oval_state_iterator *states = oval_definition_model_get_states(definition_model); if (oval_state_iterator_has_more(states)) { xmlNode *states_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "states", NULL); while (oval_state_iterator_has_more(states)) { struct oval_state *state = oval_state_iterator_next(states); oval_state_to_dom(state, doc, states_node); } } oval_state_iterator_free(states); /* Report variables */ struct oval_variable_iterator *variables = oval_definition_model_get_variables(definition_model); if (oval_variable_iterator_has_more(variables)) { xmlNode *variables_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "variables", NULL); while (oval_variable_iterator_has_more(variables)) { struct oval_variable *variable = oval_variable_iterator_next(variables); oval_variable_to_dom(variable, doc, variables_node); } } oval_variable_iterator_free(variables); return root_node; }
/** * \brief Serializes an array of \c LALInferenceVariables into a VOTable XML %node * * This function takes a \c LALInferenceVariables structure and serializes it into a VOTable * \c RESOURCE %node identified by the given name. The returned \c xmlNode can then be * embedded into an existing %node hierarchy or turned into a full VOTable document. * A VOTable Table element is returned, with fixed variables as PARAMs and the varying ones as FIELDs. * * \param varsArray [in] Pointer to an array of \c LALInferenceVariables structures to be serialized * \param N [in] Number of items in the array * \param tablename UNDOCUMENTED * * \return A pointer to a \c xmlNode that holds the VOTable fragment that represents * the \c LALInferenceVariables array. * In case of an error, a null-pointer is returned.\n * \b Important: the caller is responsible to free the allocated memory (when the * fragment isn't needed anymore) using \c xmlFreeNode. Alternatively, \c xmlFreeDoc * can be used later on when the returned fragment has been embedded in a XML document. * * \sa XLALCreateVOTParamNode * \sa XLALCreateVOTResourceNode * * \author John Veitch * */ xmlNodePtr XLALInferenceVariablesArray2VOTTable(LALInferenceVariables * const *const varsArray, UINT4 N, const char *tablename) { xmlNodePtr fieldNodeList=NULL; xmlNodePtr paramNodeList=NULL; xmlNodePtr xmlTABLEDATAnode=NULL; xmlNodePtr VOTtableNode=NULL; xmlNodePtr tmpNode=NULL; xmlNodePtr field_ptr,param_ptr; LALInferenceVariableItem *varitem=NULL; UINT4 Nfields=0; UINT4 bufsize=1024; int err; /* Sanity check input */ if(!varsArray) { XLALPrintError("Received null varsArray pointer"); XLAL_ERROR_NULL(XLAL_EFAULT); } if(N==0) return(NULL); field_ptr=fieldNodeList; param_ptr=paramNodeList; char *field_names[varsArray[0]->dimension]; /* Build a list of PARAM and FIELD elements */ for(varitem=varsArray[0]->head;varitem;varitem=varitem->next) { tmpNode=NULL; switch(varitem->vary){ case LALINFERENCE_PARAM_LINEAR: case LALINFERENCE_PARAM_CIRCULAR: case LALINFERENCE_PARAM_OUTPUT: { tmpNode=LALInferenceVariableItem2VOTFieldNode(varitem); if(!tmpNode) { XLALPrintWarning ("%s: xmlAddNextSibling() failed to add field node for %s.\n", __func__, varitem->name ); //XLAL_ERROR_NULL(XLAL_EFAILED); continue; } if(field_ptr) field_ptr=xmlAddNextSibling(field_ptr,tmpNode); else {field_ptr=tmpNode; fieldNodeList=field_ptr;} field_names[Nfields]=varitem->name; Nfields++; break; } case LALINFERENCE_PARAM_FIXED: { tmpNode=LALInferenceVariableItem2VOTParamNode(varitem); if(!tmpNode) { XLALPrintWarning ("%s: xmlAddNextSibling() failed to add param node for %s.\n", __func__, varitem->name ); //XLAL_ERROR_NULL(XLAL_EFAILED); continue; } if(param_ptr) param_ptr=xmlAddNextSibling(param_ptr,tmpNode); else {param_ptr=tmpNode; paramNodeList=param_ptr;} break; } default: { XLALPrintWarning("Unknown param vary type"); } } } if(Nfields>0) { UINT4 row,col; /* create TABLEDATA node */ if ( ( xmlTABLEDATAnode = xmlNewNode ( NULL, CAST_CONST_XMLCHAR("TABLEDATA") ))== NULL ) { XLALPrintError ("%s: xmlNewNode() failed to create 'TABLEDATA' node.\n", __func__ ); err = XLAL_ENOMEM; goto failed; } /* ---------- loop over data-arrays and generate each table-row */ for ( row = 0; row < N; row ++ ) { /* create TR node */ xmlNodePtr xmlThisRowNode = NULL; if ( (xmlThisRowNode = xmlNewNode ( NULL, CAST_CONST_XMLCHAR("TR") )) == NULL ) { XLALPrintError ("%s: xmlNewNode() failed to create new 'TR' node.\n", __func__ ); err = XLAL_EFAILED; goto failed; } if ( xmlAddChild(xmlTABLEDATAnode, xmlThisRowNode ) == NULL ) { XLALPrintError ("%s: failed to insert 'TR' node into 'TABLEDATA' node.\n", __func__ ); err = XLAL_EFAILED; goto failed; } /* ----- loop over columns and generate each table element */ for ( col = 0; col < Nfields; col ++ ) { /* create TD node */ xmlNodePtr xmlThisEntryNode = NULL; if ( (xmlThisEntryNode = xmlNewNode ( NULL, CAST_CONST_XMLCHAR("TD") )) == NULL ) { XLALPrintError ("%s: xmlNewNode() failed to create new 'TD' node.\n", __func__ ); err = XLAL_EFAILED; goto failed; } if ( xmlAddChild(xmlThisRowNode, xmlThisEntryNode ) == NULL ) { XLALPrintError ("%s: failed to insert 'TD' node into 'TR' node.\n", __func__ ); err = XLAL_EFAILED; goto failed; } char *valuestr=XLALCalloc(bufsize,sizeof(char)); varitem = LALInferenceGetItem(varsArray[row],field_names[col]); UINT4 required_size=LALInferencePrintNVariableItem(valuestr,bufsize,varitem); if(required_size>bufsize) { bufsize=required_size; valuestr=XLALRealloc(valuestr,required_size*sizeof(char)); required_size=LALInferencePrintNVariableItem(valuestr,bufsize,varitem); } xmlNodePtr xmlTextNode= xmlNewText (CAST_CONST_XMLCHAR(valuestr) ); if ( xmlTextNode == NULL ) { XLALPrintError("%s: xmlNewText() failed to turn text '%s' into node\n", __func__, valuestr ); err = XLAL_EFAILED; XLALFree(valuestr); goto failed; } if ( xmlAddChild(xmlThisEntryNode, xmlTextNode ) == NULL ) { XLALPrintError ("%s: failed to insert text-node node into 'TD' node.\n", __func__ ); err = XLAL_EFAILED; XLALFree(valuestr); goto failed; } XLALFree(valuestr); } /* for col < numFields */ } /* for row < numRows */ } /* Create a TABLE from the FIELDs, PARAMs, and TABLEDATA nodes */ VOTtableNode= XLALCreateVOTTableNode (tablename, fieldNodeList, paramNodeList, xmlTABLEDATAnode ); return(VOTtableNode); failed: XLAL_ERROR_NULL ( err ); return(NULL); }
static gboolean create_program_list(IRAPISession *session, GList **list, SynceAppManBusyFunc busy_func, gpointer busy_data, GError **error) { GList *prog_list = NULL; xmlDocPtr doc = NULL; xmlDocPtr reply_doc = NULL; xmlNodePtr parent = NULL; xmlNodePtr root_node = NULL, node = NULL, reply_node = NULL; xmlChar *doc_string = NULL; gint doc_size; LPWSTR config_w = NULL; LPWSTR reply_w = NULL; HRESULT result; gchar *reply = NULL; gchar *prop = NULL; doc = xmlNewDoc((xmlChar *)"1.0"); root_node = xmlNewNode(NULL, (xmlChar *)"wap-provisioningdoc"); xmlDocSetRootElement(doc, root_node); parent = root_node; node = xmlNewNode(NULL, (xmlChar *)"characteristic-query"); xmlNewProp(node, (xmlChar *)"recursive", (xmlChar *)"false"); xmlNewProp(node, (xmlChar *)"type", (xmlChar *)"UnInstall"); xmlAddChild(parent, node); xmlDocDumpMemoryEnc(doc, &doc_string, &doc_size, "utf-8"); g_debug("%s: CeProcessConfig request is \n%s", G_STRFUNC, doc_string); config_w = wstr_from_utf8((char *)doc_string); xmlFree(doc_string); xmlFreeDoc(doc); result = IRAPISession_CeProcessConfig(session, config_w, CONFIG_PROCESS_DOCUMENT, &reply_w); wstr_free_string(config_w); if (result != 0) { g_set_error(error, SYNCE_APP_MAN_ERROR, SYNCE_APP_MAN_ERROR_RAPI, _("Unable to obtain application list: %s"), synce_strerror(result)); return FALSE; } reply = wstr_to_utf8(reply_w); wstr_free_string(reply_w); reply_doc = xmlReadMemory(reply, strlen(reply), "reply.xml", NULL, 0); xmlDocDumpMemoryEnc(reply_doc, &doc_string, &doc_size, "utf-8"); g_debug("%s: CeProcessConfig response is \n%s", G_STRFUNC, doc_string); xmlFree(doc_string); reply_node = NULL; node = xmlDocGetRootElement(reply_doc); node = node->children; while(node) { if (node->type == XML_ELEMENT_NODE) { reply_node = node; } node = node->next; } if (!reply_node) { xmlFreeDoc(reply_doc); g_set_error(error, SYNCE_APP_MAN_ERROR, SYNCE_APP_MAN_ERROR_RAPI, _("Unable to obtain application list: Unexpected reply XML structure")); return FALSE; } node = reply_node->children; while (node) { prop = (gchar *)xmlGetProp(node, (xmlChar *)"type"); g_strstrip(prop); prog_list = g_list_append(prog_list, prop); node = node->next; } xmlFreeDoc(reply_doc); *list = prog_list; return TRUE; }
static int noit_console_filter_configure(noit_console_closure_t ncct, int argc, char **argv, noit_console_state_t *state, void *closure) { xmlNodePtr parent, fsnode = NULL; int rv = -1; noit_conf_t_userdata_t *info; char xpath[1024]; info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); if(!info) { nc_printf(ncct, "internal error\n"); goto cleanup; } if(strncmp(info->path, "/filtersets/", strlen("/filtersets/")) && strcmp(info->path, "/filtersets")) { nc_printf(ncct, "filterset only allows inside /filtersets (not %s)\n", info->path); goto cleanup; } if(argc != 1) { nc_printf(ncct, "filterset requires one argument\n"); goto cleanup; } snprintf(xpath, sizeof(xpath), "/%s", info->path); parent = noit_conf_get_section(NULL, xpath); if(!parent) { nc_printf(ncct, "internal error, can't final current working path\n"); goto cleanup; } snprintf(xpath, sizeof(xpath), "filterset[@name=\"%s\"]", argv[0]); fsnode = noit_conf_get_section(parent, xpath); if(closure) { int removed; removed = noit_filter_remove(fsnode); nc_printf(ncct, "%sremoved filterset '%s'\n", removed ? "" : "failed to ", argv[0]); if(removed) { xmlUnlinkNode(fsnode); xmlFreeNode(fsnode); } rv = !removed; goto cleanup; } if(!fsnode) { void *vfs; nc_printf(ncct, "Cannot find filterset '%s'\n", argv[0]); LOCKFS(); if(noit_hash_retrieve(filtersets, argv[0], strlen(argv[0]), &vfs)) { UNLOCKFS(); nc_printf(ncct, "filter of the same name already exists\n"); goto cleanup; } UNLOCKFS(); /* Fine the parent path */ fsnode = xmlNewNode(NULL, (xmlChar *)"filterset"); xmlSetProp(fsnode, (xmlChar *)"name", (xmlChar *)argv[0]); xmlAddChild(parent, fsnode); nc_printf(ncct, "created new filterset\n"); } if(info) { char *xmlpath = NULL; if(info->path) free(info->path); xmlpath = (char *)xmlGetNodePath(fsnode); info->path = strdup(xmlpath + strlen("/noit")); free(xmlpath); strlcpy(info->filter_name, argv[0], sizeof(info->filter_name)); if(state) { noit_console_state_push_state(ncct, state); noit_console_state_init(ncct); } } cleanup: return rv; }
/* * \fn hip_xmlrpc_getput() * * \param mode determines get or put, app, retry on/off * If retry is off only one attempt should be made, * on means the connect() should keep retrying * \param app string to use in the XML RPC application field * \param server server address and port to connect to * \param key DHT key used for get or put * \param key_len length of DHT key in bytes * \param value DHT value used for put, ptr for storing value for get * \param value_len ptr to length of value buffer, length of get is returned * \param secret secret value used to make put removable * \param secret_len length of secret value * \param ttl time to live in seconds * * \brief Perform the XML RPC GET, PUT, and RM operations. */ int hip_xmlrpc_getput(int mode, char *app, struct sockaddr *server, char *key, int key_len, char *value, int *value_len, char *secret, int secret_len, int ttl) { xmlDocPtr doc = NULL; xmlNodePtr root_node = NULL, node; int len = 0, s, retval = 0; char buff[2048], oper[14]; unsigned char key64[2 * DHT_KEY_SIZE], val64[2 * DHT_VAL_SIZE]; unsigned char tmp[2 * DHT_VAL_SIZE], *xmlbuff = NULL; fd_set read_fdset; struct timeval timeout, now; char *p; unsigned int retry_attempts = 0; struct sockaddr_in src_addr; struct dht_val *dv, rm; SHA_CTX c; __u8 secret_hash[SHA_DIGEST_LENGTH], value_hash[SHA_DIGEST_LENGTH]; int rm_ttl = 0, value_hash_len; int retry = ((mode & 0x00F0) == XMLRPC_MODE_RETRY_ON); if ((key_len > (2 * DHT_KEY_SIZE)) || (*value_len > (2 * DHT_VAL_SIZE))) { return(-1); } /* * support for removable puts */ memset(&rm, 0, sizeof(struct dht_val)); if ((mode & 0x000F) == XMLRPC_MODE_PUT) { /* * produce hashes of the secret and the value, for later removal */ SHA1_Init(&c); SHA1_Update(&c, value, *value_len); SHA1_Final(value_hash, &c); SHA1_Init(&c); SHA1_Update(&c, secret, secret_len); SHA1_Final(secret_hash, &c); /* * check if we already published a record with this key; record * this new secret value and value_hash */ pthread_mutex_lock(&dht_vals_lock); gettimeofday(&now, NULL); dv = lookup_dht_val(key); if (dv) { /* save old secret so we can remove it later below */ memcpy(&rm, &dv, sizeof(struct dht_val)); /* any time left for removing the old record? */ rm_ttl = TDIFF(rm.expire_time, now); } else { dv = insert_dht_val(key); } strncpy(dv->app, app, sizeof(dv->app)); dv->value_hash_len = SHA_DIGEST_LENGTH; memcpy(dv->value_hash, value_hash, SHA_DIGEST_LENGTH); dv->secret_len = secret_len; memcpy(dv->secret, secret, secret_len); dv->expire_time.tv_usec = now.tv_usec; dv->expire_time.tv_sec = now.tv_sec + ttl; pthread_mutex_unlock(&dht_vals_lock); } switch (mode & 0x000F) { case XMLRPC_MODE_PUT: sprintf(oper, "put_removable"); break; case XMLRPC_MODE_GET: sprintf(oper, "get"); break; case XMLRPC_MODE_RM: sprintf(oper, "rm"); break; default: log_(WARN, "Invalid XMLRPC mode given to DHT.\n"); return(-1); } /* * create a new XML document */ doc = xmlNewDoc(BAD_CAST "1.0"); root_node = xmlNewNode(NULL, BAD_CAST "methodCall"); xmlDocSetRootElement(doc, root_node); node = xmlNewChild(root_node, NULL, BAD_CAST "methodName", BAD_CAST oper); node = xmlNewChild(root_node, NULL, BAD_CAST "params", NULL); memset(tmp, 0, sizeof(tmp)); memcpy(tmp, key, key_len); EVP_EncodeBlock(key64, tmp, key_len); xml_new_param(node, "base64", (char *)key64); /* key */ /* log_(NORM, "Doing %s using key(%d)=", * ((mode & 0x000F)==XMLRPC_MODE_PUT) ? "PUT":"GET", key_len); * print_hex(key, key_len); * log_(NORM, " [%s]\n", key64); // */ switch (mode & 0x000F) { case XMLRPC_MODE_PUT: memset(tmp, 0, sizeof(tmp)); memcpy(tmp, value, *value_len); EVP_EncodeBlock(val64, tmp, *value_len); xml_new_param(node, "base64", (char *)val64); /* value */ xml_new_param(node, "string", "SHA"); /* hash type */ memset(tmp, 0, sizeof(tmp)); memcpy(tmp, secret_hash, SHA_DIGEST_LENGTH); EVP_EncodeBlock(val64, tmp, SHA_DIGEST_LENGTH); xml_new_param(node, "base64", (char *)val64); /* secret_hash */ sprintf((char *)tmp, "%d", ttl); xml_new_param(node, "int", (char *)tmp); /* lifetime */ break; case XMLRPC_MODE_GET: xml_new_param(node, "int", "10"); /* maxvals */ xml_new_param(node, "base64", ""); /* placemark */ memset(value, 0, *value_len); break; case XMLRPC_MODE_RM: memset(tmp, 0, sizeof(tmp)); memcpy(tmp, value_hash, SHA_DIGEST_LENGTH); EVP_EncodeBlock(val64, tmp, SHA_DIGEST_LENGTH); xml_new_param(node, "base64", (char *)val64); /* value_hash */ xml_new_param(node, "string", "SHA"); /* hash type */ memset(tmp, 0, sizeof(tmp)); memcpy(tmp, secret, secret_len); EVP_EncodeBlock(val64, tmp, secret_len); xml_new_param(node, "base64", (char *)val64); /* secret */ sprintf((char *)tmp, "%d", ttl); xml_new_param(node, "int", (char *)tmp); /* lifetime */ } xml_new_param(node, "string", app); /* app */ xmlDocDumpFormatMemory(doc, &xmlbuff, &len, 0); /* * Build an HTTP POST and transmit to server */ memset(buff, 0, sizeof(buff)); build_http_post_header(buff, len, server); /* len is XML length above */ memcpy(&buff[strlen(buff)], xmlbuff, len); xmlFree(xmlbuff); len = strlen(buff) + 1; connect_retry: /* Connect and send the XML RPC */ if ((s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { log_(WARN, "DHT connect - socket error: %s\n", strerror(errno)); retval = -1; goto putget_exit; } /* Use the preferred address as source */ memset(&src_addr, 0, sizeof(src_addr)); src_addr.sin_family = AF_INET; src_addr.sin_addr.s_addr = get_preferred_addr(); if (!src_addr.sin_addr.s_addr) { log_(NORM, "No preferred address, deferring DHT!\n"); return(-1); } log_(NORM, "Using source address of %s for DHT %s.\n", logaddr(SA(&src_addr)), oper); fflush(stdout); if (bind(s, SA(&src_addr), SALEN(&src_addr)) < 0) { log_(WARN, "DHT connect - bind error: %s\n", strerror(errno)); } if (g_state != 0) { return(-1); } if (retry && (retry_attempts > 0)) { /* quit after a certain number of retries */ if (retry_attempts >= HCNF.max_retries) { retval = -2; goto putget_exit; } /* wait packet_timeout seconds before retrying */ hip_sleep(HCNF.packet_timeout); } retry_attempts++; if (connect(s, server, SALEN(server)) < 0) { log_(WARN, "DHT server connect error: %s\n", strerror(errno)); closesocket(s); #ifdef __WIN32__ errno = WSAGetLastError(); if (retry && ((errno == WSAETIMEDOUT) || (errno == WSAENETUNREACH))) { goto connect_retry; } #else if (retry && ((errno == ETIMEDOUT) || (errno == EHOSTUNREACH))) { goto connect_retry; } #endif retval = -3; goto putget_exit; } if (send(s, buff, len, 0) != len) { log_(WARN, "DHT sent incorrect number of bytes\n"); retval = -4; goto putget_exit; } xmlFreeDoc(doc); doc = NULL; /* * Receive XML RPC response from server */ FD_ZERO(&read_fdset); FD_SET((unsigned int)s, &read_fdset); /* use longer timeout when retry==TRUE, because we have own thread */ if (retry) { timeout.tv_sec = 3; timeout.tv_usec = 0; } else { timeout.tv_sec = 0; timeout.tv_usec = 300000; /* 300ms */ } if (select(s + 1, &read_fdset, NULL, NULL, &timeout) < 0) { log_(WARN, "DHT select error: %s\n", strerror(errno)); retval = -5; goto putget_exit; } else if (FD_ISSET(s, &read_fdset)) { if ((len = recv(s, buff, sizeof(buff) - 1, 0)) <= 0) { log_(WARN, "DHT error receiving from server: %s\n", strerror(errno)); retval = -6; goto putget_exit; } if (strncmp(buff, "HTTP", 4) != 0) { return(-7); } if ((p = strstr(buff, "Content-Length: ")) == NULL) { return(-8); } else /* advance ptr to Content-Length */ { p += 16; } sscanf(p, "%d", &len); p = strchr(p, '\n') + 3; /* advance to end of line */ retval = hip_xmlrpc_parse_response(mode, p, len, value, value_len); log_(NORM, "DHT server responded with return code %d (%s).\n", retval, hip_xmlrpc_resp_to_str(retval)); } else { /* select timeout */ if (retry) /* XXX testme: retry select instead? */ { goto connect_retry; } retval = -9; } putget_exit: #ifdef __WIN32__ closesocket(s); #else close(s); #endif if (doc != NULL) { xmlFreeDoc(doc); } if (rm_ttl > 0) { value_hash_len = sizeof(rm.value_hash); hip_xmlrpc_getput(((mode & 0x00F0) | XMLRPC_MODE_RM), app, server, key, key_len, (char *)rm.value_hash, &value_hash_len, (char *)rm.secret, secret_len, rm_ttl); } return(retval); }
int msWFSGetCapabilities11(mapObj *map, wfsParamsObj *params, cgiRequestObj *req, owsRequestObj *ows_request) { xmlDocPtr psDoc = NULL; /* document pointer */ xmlNodePtr psRootNode, psMainNode, psNode, psFtNode; const char *updatesequence=NULL; xmlNsPtr psNsOws, psNsXLink, psNsOgc; char *schemalocation = NULL; char *xsi_schemaLocation = NULL; const char *user_namespace_prefix = NULL; const char *user_namespace_uri = NULL; gmlNamespaceListObj *namespaceList=NULL; /* for external application schema support */ char *script_url=NULL, *formats_list; const char *value = NULL; const char *encoding; xmlChar *buffer = NULL; int size = 0, i; msIOContext *context = NULL; int ows_version = OWS_1_0_0; /* -------------------------------------------------------------------- */ /* Handle updatesequence */ /* -------------------------------------------------------------------- */ updatesequence = msOWSLookupMetadata(&(map->web.metadata), "FO", "updatesequence"); encoding = msOWSLookupMetadata(&(map->web.metadata), "FO", "encoding"); if (params->pszUpdateSequence != NULL) { i = msOWSNegotiateUpdateSequence(params->pszUpdateSequence, updatesequence); if (i == 0) { /* current */ msSetError(MS_WFSERR, "UPDATESEQUENCE parameter (%s) is equal to server (%s)", "msWFSGetCapabilities11()", params->pszUpdateSequence, updatesequence); return msWFSException11(map, "updatesequence", "CurrentUpdateSequence", params->pszVersion); } if (i > 0) { /* invalid */ msSetError(MS_WFSERR, "UPDATESEQUENCE parameter (%s) is higher than server (%s)", "msWFSGetCapabilities11()", params->pszUpdateSequence, updatesequence); return msWFSException11(map, "updatesequence", "InvalidUpdateSequence", params->pszVersion); } } /* -------------------------------------------------------------------- */ /* Create document. */ /* -------------------------------------------------------------------- */ psDoc = xmlNewDoc(BAD_CAST "1.0"); psRootNode = xmlNewNode(NULL, BAD_CAST "WFS_Capabilities"); xmlDocSetRootElement(psDoc, psRootNode); /* -------------------------------------------------------------------- */ /* Name spaces */ /* -------------------------------------------------------------------- */ /*default name space*/ xmlNewProp(psRootNode, BAD_CAST "xmlns", BAD_CAST "http://www.opengis.net/wfs"); xmlSetNs(psRootNode, xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/gml", BAD_CAST "gml")); xmlSetNs(psRootNode, xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/wfs", BAD_CAST "wfs")); psNsOws = xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_OWS_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_OWS_NAMESPACE_PREFIX); psNsXLink = xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_W3C_XLINK_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_W3C_XLINK_NAMESPACE_PREFIX); xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_W3C_XSI_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_W3C_XSI_NAMESPACE_PREFIX); xmlNewNs(psRootNode, BAD_CAST MS_OWSCOMMON_OGC_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_OGC_NAMESPACE_PREFIX ); value = msOWSLookupMetadata(&(map->web.metadata), "FO", "namespace_uri"); if(value) user_namespace_uri = value; value = msOWSLookupMetadata(&(map->web.metadata), "FO", "namespace_prefix"); if(value) user_namespace_prefix = value; if(user_namespace_prefix != NULL && msIsXMLTagValid(user_namespace_prefix) == MS_FALSE) msIO_printf("<!-- WARNING: The value '%s' is not valid XML namespace. -->\n", user_namespace_prefix); else xmlNewNs(psRootNode, BAD_CAST user_namespace_uri, BAD_CAST user_namespace_prefix); /* any additional namespaces */ namespaceList = msGMLGetNamespaces(&(map->web), "G"); for(i=0; i<namespaceList->numnamespaces; i++) { if(namespaceList->namespaces[i].uri) { xmlNewNs(psRootNode, BAD_CAST namespaceList->namespaces[i].uri, BAD_CAST namespaceList->namespaces[i].prefix); } } msGMLFreeNamespaces(namespaceList); xmlNewProp(psRootNode, BAD_CAST "version", BAD_CAST params->pszVersion ); updatesequence = msOWSLookupMetadata(&(map->web.metadata), "FO", "updatesequence"); if (updatesequence) xmlNewProp(psRootNode, BAD_CAST "updateSequence", BAD_CAST updatesequence); /*schema*/ schemalocation = msEncodeHTMLEntities( msOWSGetSchemasLocation(map) ); xsi_schemaLocation = msStrdup("http://www.opengis.net/wfs"); xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, " "); xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, schemalocation); xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, "/wfs/1.1.0/wfs.xsd"); xmlNewNsProp(psRootNode, NULL, BAD_CAST "xsi:schemaLocation", BAD_CAST xsi_schemaLocation); /* -------------------------------------------------------------------- */ /* Service metadata. */ /* -------------------------------------------------------------------- */ xmlAddChild(psRootNode, msOWSCommonServiceIdentification(psNsOws, map, "OGC WFS", params->pszVersion, "FO")); /*service provider*/ xmlAddChild(psRootNode, msOWSCommonServiceProvider( psNsOws, psNsXLink, map, "FO")); /*operation metadata */ if ((script_url=msOWSGetOnlineResource(map, "FO", "onlineresource", req)) == NULL) { msSetError(MS_WFSERR, "Server URL not found", "msWFSGetCapabilities11()"); return msWFSException11(map, "mapserv", "NoApplicableCode", params->pszVersion); } /* -------------------------------------------------------------------- */ /* Operations metadata. */ /* -------------------------------------------------------------------- */ psMainNode= xmlAddChild(psRootNode,msOWSCommonOperationsMetadata(psNsOws)); /* -------------------------------------------------------------------- */ /* GetCapabilities */ /* -------------------------------------------------------------------- */ psNode = xmlAddChild(psMainNode, msOWSCommonOperationsMetadataOperation(psNsOws,psNsXLink,"GetCapabilities", OWS_METHOD_GETPOST, script_url)); xmlAddChild(psMainNode, psNode); xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType( ows_version, psNsOws, "Parameter", "service", "WFS")); /*accept version*/ xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, "Parameter", "AcceptVersions", "1.0.0,1.1.0")); /*format*/ xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, "Parameter", "AcceptFormats", "text/xml")); /* -------------------------------------------------------------------- */ /* DescribeFeatureType */ /* -------------------------------------------------------------------- */ if (msOWSRequestIsEnabled(map, NULL, "F", "DescribeFeatureType", MS_TRUE)) { psNode = xmlAddChild(psMainNode, msOWSCommonOperationsMetadataOperation(psNsOws,psNsXLink,"DescribeFeatureType", OWS_METHOD_GETPOST, script_url)); xmlAddChild(psMainNode, psNode); /*output format*/ xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, "Parameter", "outputFormat", "XMLSCHEMA,text/xml; subtype=gml/2.1.2,text/xml; subtype=gml/3.1.1")); } /* -------------------------------------------------------------------- */ /* GetFeature */ /* -------------------------------------------------------------------- */ if (msOWSRequestIsEnabled(map, NULL, "F", "GetFeature", MS_TRUE)) { psNode = xmlAddChild(psMainNode, msOWSCommonOperationsMetadataOperation(psNsOws,psNsXLink,"GetFeature", OWS_METHOD_GETPOST, script_url)); xmlAddChild(psMainNode, psNode); xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, "Parameter", "resultType", "results,hits")); formats_list = msWFSGetOutputFormatList( map, NULL, "1.1.0" ); xmlAddChild(psNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, "Parameter", "outputFormat", formats_list)); msFree( formats_list ); value = msOWSLookupMetadata(&(map->web.metadata), "FO", "maxfeatures"); if (value) { xmlAddChild(psMainNode, msOWSCommonOperationsMetadataDomainType(ows_version, psNsOws, "Constraint", "DefaultMaxFeatures", (char *)value)); } } /* -------------------------------------------------------------------- */ /* FeatureTypeList */ /* -------------------------------------------------------------------- */ psFtNode = xmlNewNode(NULL, BAD_CAST "FeatureTypeList"); xmlAddChild(psRootNode, psFtNode); psNode = xmlNewChild(psFtNode, NULL, BAD_CAST "Operations", NULL); xmlNewChild(psNode, NULL, BAD_CAST "Operation", BAD_CAST "Query"); for(i=0; i<map->numlayers; i++) { layerObj *lp; lp = GET_LAYER(map, i); if (!msIntegerInArray(lp->index, ows_request->enabled_layers, ows_request->numlayers)) continue; /* List only vector layers in which DUMP=TRUE */ if (msWFSIsLayerSupported(lp)) xmlAddChild(psFtNode, msWFSDumpLayer11(map, lp, psNsOws)); } /* -------------------------------------------------------------------- */ /* Filter capabilities. */ /* -------------------------------------------------------------------- */ psNsOgc = xmlNewNs(NULL, BAD_CAST MS_OWSCOMMON_OGC_NAMESPACE_URI, BAD_CAST MS_OWSCOMMON_OGC_NAMESPACE_PREFIX); xmlAddChild(psRootNode, FLTGetCapabilities(psNsOgc, psNsOgc, MS_FALSE)); /* -------------------------------------------------------------------- */ /* Write out the document. */ /* -------------------------------------------------------------------- */ if( msIO_needBinaryStdout() == MS_FAILURE ) return MS_FAILURE; if (encoding) msIO_setHeader("Content-Type","text/xml; charset=%s", encoding); else msIO_setHeader("Content-Type","text/xml"); msIO_sendHeaders(); context = msIO_getHandler(stdout); xmlDocDumpFormatMemoryEnc(psDoc, &buffer, &size, (encoding ? encoding : "ISO-8859-1"), 1); msIO_contextWrite(context, buffer, size); xmlFree(buffer); /*free buffer and the document */ /*xmlFree(buffer);*/ xmlFreeDoc(psDoc); xmlFreeNs(psNsOgc); free(script_url); free(xsi_schemaLocation); free(schemalocation); xmlCleanupParser(); return(MS_SUCCESS); }
int ExporterVTK<MeshType,N>::writeTimePVD(std::string xmlFilename, double timestep, std::string dataFilename, int partNo) const { /* <!-- Sample xml code for PVD format --> <?xml version="1.0"?> <VTKFile type="Collection" version="0.1"> <Collection> <DataSet timestep="0" group="" part="0" file="ts_0.vtm"/> <DataSet timestep="0.5" group="" part="0" file="ts_1.vtm"/> </Collection> </VTKFile> */ int retcode = 0; xmlDocPtr doc = NULL; xmlNodePtr root = NULL, node1 = NULL, node2 = NULL; std::ostringstream oss; /* only do this on the master rank */ if(this->worldComm().isMasterRank()) { /* First Step: Find the Collection node */ /* Either in a newly created file or in an existing file */ /* check if the time file already exists */ /* if so we update its data by adding a new DataSet node */ if(boost::filesystem::exists(xmlFilename)) { doc = xmlReadFile(xmlFilename.c_str(), NULL, 0); if (doc == NULL) { //std::cerr << "Failed to parse %s" << std::endl; return 1; } root = xmlDocGetRootElement(doc); /* check that we have VTKFile as a first entry */ if(xmlStrncmp(root->name, BAD_CAST "VTKFile", 7) == 0 && root->children != NULL) { /* get first child */ node1 = root->children; if(xmlStrncmp(node1->name, BAD_CAST "Collection", 10) != 0) { node1 = NULL; retcode = 1; } } /* mark this as an error */ else { retcode = 1; } } /* if the file does not already exists we create it */ else { /* create a new document */ doc = xmlNewDoc(BAD_CAST "1.0"); root = xmlNewNode(NULL, BAD_CAST "VTKFile"); xmlSetProp(root, BAD_CAST "type", BAD_CAST "Collection"); xmlSetProp(root, BAD_CAST "version", BAD_CAST "0.1"); xmlDocSetRootElement(doc, root); node1 = xmlNewNode(NULL, BAD_CAST "Collection"); xmlAddChild(root, node1); } /* Second step */ /* Create a new dataset entry to add to the Collection node */ if(node1) { node2 = xmlNewNode(NULL, BAD_CAST "DataSet"); xmlAddChild(node1, node2); oss.str(""); oss << timestep; xmlSetProp(node2, BAD_CAST "timestep", BAD_CAST oss.str().c_str()); xmlSetProp(node2, BAD_CAST "group", BAD_CAST ""); oss.str(""); oss << partNo; xmlSetProp(node2, BAD_CAST "part", BAD_CAST oss.str().c_str()); xmlSetProp(node2, BAD_CAST "file", BAD_CAST dataFilename.c_str()); /* xmlChar * mem = NULL; int size = 0; xmlDocDumpFormatMemory(doc, &mem, &size, 1); std::cout << mem << std::endl; xmlFree(mem); */ //std::cout << "Writing file " << xmlFilename << std::endl; FILE * f = fopen(xmlFilename.c_str(), "w"); xmlDocDump(f, doc); fclose(f); } xmlFreeDoc(doc); } return retcode; }
xmlNodePtr dns_getconfig(xmlNsPtr ns, char** msg) { int i, done; char* path, *content = NULL; const char* value; xmlNodePtr dns_node, server, aux_node; assert(sysaugeas); /* dns-resolver */ dns_node = xmlNewNode(ns, BAD_CAST "dns-resolver"); /* dns-resolver/search[] */ for (i = 1, done = 0; !done; i++) { path = NULL; asprintf(&path, "/files/"AUGEAS_DNS_CONF"/search/domain[%d]", i); switch (aug_match(sysaugeas, path, NULL)) { case -1: asprintf(msg, "Augeas match for \"%s\" failed: %s", path, aug_error_message(sysaugeas)); free(path); xmlFreeNode(dns_node); return (NULL); case 0: /* index out of bounds, continue with next server type */ free(path); done = 1; break; default: /* 1 */ /* dns-resolver/search */ aug_get(sysaugeas, path, &value); xmlNewChild(dns_node, dns_node->ns, BAD_CAST "search", BAD_CAST value); free(path); path = NULL; break; } } /* dns-resolver/server[] */ for (i = 1, done = 0; !done; i++) { path = NULL; asprintf(&path, "/files/"AUGEAS_DNS_CONF"/nameserver[%d]", i); switch (aug_match(sysaugeas, path, NULL)) { case -1: asprintf(msg, "Augeas match for \"%s\" failed: %s", path, aug_error_message(sysaugeas)); free(path); xmlFreeNode(dns_node); return (NULL); case 0: /* index out of bounds, continue with next server type */ free(path); done = 1; break; default: /* 1 */ /* dns-resolver/server */ server = xmlNewChild(dns_node, dns_node->ns, BAD_CAST "server", NULL); /* dns-resolver/server/name */ asprintf(&content, "nameserver-%d", i); xmlNewChild(server, server->ns, BAD_CAST "name", BAD_CAST content); free(content); /* dns-resolver/server/udp-and-tcp/address */ aug_get(sysaugeas, path, &value); aux_node = xmlNewChild(server, server->ns, BAD_CAST "udp-and-tcp", NULL); xmlNewChild(aux_node, aux_node->ns, BAD_CAST "address", BAD_CAST value); free(path); /* port specification is not supported by Linux dns resolver implementation */ break; } } /* dns-resolver/options */ switch (aug_match(sysaugeas, "/files/"AUGEAS_DNS_CONF"/options", NULL)) { case -1: asprintf(msg, "Augeas match for \"%s\" failed: %s", path, aug_error_message(sysaugeas)); free(path); xmlFreeNode(dns_node); return (NULL); case 0: /* No options specified */ break; default: /* 1 */ aux_node = xmlNewChild(dns_node, dns_node->ns, BAD_CAST "options", NULL); /* dns-resolver/options/timeout */ value = NULL; aug_get(sysaugeas, "/files/"AUGEAS_DNS_CONF"/options/timeout", &value); if (value != NULL) { xmlNewChild(aux_node, aux_node->ns, BAD_CAST "timeout", BAD_CAST value); } /* dns-resolver/options/attempts */ value = NULL; aug_get(sysaugeas, "/files/"AUGEAS_DNS_CONF"/options/attempts", &value); if (value != NULL) { xmlNewChild(aux_node, aux_node->ns, BAD_CAST "attempts", BAD_CAST value); } break; } return (dns_node); }
char *uwsgi_format_airbrake_backtrace(struct uwsgi_thread *ut) { struct uwsgi_airbrake_config *uacc = (struct uwsgi_airbrake_config *) ut->data; xmlChar *xmlbuff; int buffersize; xmlDocPtr doc = NULL; xmlNodePtr notice_node = NULL, node = NULL, line_node = NULL, errnode = NULL; char *msg = NULL; doc = xmlNewDoc(BAD_CAST "1.0"); notice_node = xmlNewNode(NULL, BAD_CAST "notice"); xmlNewProp(notice_node, BAD_CAST "version", BAD_CAST "2.3"); xmlDocSetRootElement(doc, notice_node); xmlNewChild(notice_node, NULL, BAD_CAST "api-key", BAD_CAST uacc->apikey); node = xmlNewChild(notice_node, NULL, BAD_CAST "notifier", NULL); xmlNewChild(node, NULL, BAD_CAST "name", BAD_CAST "uWSGI"); xmlNewChild(node, NULL, BAD_CAST "version", BAD_CAST UWSGI_VERSION); xmlNewChild(node, NULL, BAD_CAST "url", BAD_CAST "https://github.com/unbit/uwsgi"); // request env node = xmlNewChild(notice_node, NULL, BAD_CAST "request", NULL); node = xmlNewChild(node, NULL, BAD_CAST "cgi-data", NULL); line_node = xmlNewChild(node, NULL, BAD_CAST "var", BAD_CAST UWSGI_VERSION); xmlNewProp(line_node, BAD_CAST "key", BAD_CAST "uwsgi_version"); line_node = xmlNewChild(node, NULL, BAD_CAST "var", BAD_CAST __VERSION__); xmlNewProp(line_node, BAD_CAST "key", BAD_CAST "compiled_with_version"); struct utsname uuts; #ifdef __sun__ if (uname(&uuts) < 0) { #else if (uname(&uuts)) { #endif uwsgi_error("uname()"); } else { line_node = xmlNewChild(node, NULL, BAD_CAST "var", BAD_CAST uuts.sysname); xmlNewProp(line_node, BAD_CAST "key", BAD_CAST "os_sysname"); char *os_version = uwsgi_concat3(uuts.release, "-", uuts.version); line_node = xmlNewChild(node, NULL, BAD_CAST "var", BAD_CAST os_version); xmlNewProp(line_node, BAD_CAST "key", BAD_CAST "os_version"); free(os_version); line_node = xmlNewChild(node, NULL, BAD_CAST "var", BAD_CAST uuts.machine); xmlNewProp(line_node, BAD_CAST "key", BAD_CAST "machine"); line_node = xmlNewChild(node, NULL, BAD_CAST "var", BAD_CAST uuts.nodename); xmlNewProp(line_node, BAD_CAST "key", BAD_CAST "nodename"); } // end request env node = xmlNewChild(notice_node, NULL, BAD_CAST "server-environment", NULL); xmlNewChild(node, NULL, BAD_CAST "app-version", BAD_CAST UWSGI_VERSION); if (uacc->env) { xmlNewChild(node, NULL, BAD_CAST "environment-name", BAD_CAST uacc->env); } else { xmlNewChild(node, NULL, BAD_CAST "environment-name", BAD_CAST UWSGI_VERSION); } errnode = xmlNewChild(notice_node, NULL, BAD_CAST "error", NULL); xmlNewChild(errnode, NULL, BAD_CAST "class", BAD_CAST "RuntimeError"); node = xmlNewChild(errnode, NULL, BAD_CAST "backtrace", NULL); char *ctx = NULL; char *text = uwsgi_str(ut->buf); char *p = strtok_r(text, "\n", &ctx); while (p) { // skip log messages if (!uwsgi_startswith(p, "***", 3)) goto next; // backtrace line looks like this: uwsgi(simple_loop_run+0xc5) [0x451555] // we take binary/lib as filename // and extract method name from remaining string char *n = strchr(p, '('); if (n) { *n = 0; char *pls = strchr(n+1, '+'); if (pls) { *pls = 0; } if (!strcmp("uwsgi_backtrace", n+1) || !strcmp("what_i_am_doing", n+1)) { goto next; } else if (!strcmp("uwsgi_fpe", n+1)) { msg = uwsgi_concat4("uWSGI FPE at ", n+1, " in ", p); goto next; } if (!msg) { if (strlen(n+1)) { msg = uwsgi_concat4("uWSGI segfault at ", n+1, " in ", p); } else { // method name might be missing msg = uwsgi_concat2("uWSGI segfault in ", p); } } // skip empty lines if (!p) goto next; line_node = xmlNewChild(node, NULL, BAD_CAST "line", NULL); if ((n+1)[0] == ')') { xmlNewProp(line_node, BAD_CAST "method", BAD_CAST "()"); } else { xmlNewProp(line_node, BAD_CAST "method", BAD_CAST n+1); } xmlNewProp(line_node, BAD_CAST "file", BAD_CAST p); //xmlNewProp(line_node, BAD_CAST "number", BAD_CAST "0"); } next: p = strtok_r(NULL, "\n", &ctx); } xmlNewChild(errnode, NULL, BAD_CAST "message", BAD_CAST msg); xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); xmlFreeDoc(doc); xmlCleanupParser(); xmlMemoryDump(); free(msg); free(text); return (char *) xmlbuff; } static void uwsgi_airbrake_loop(struct uwsgi_thread *ut) { int interesting_fd; ut->buf = uwsgi_malloc(uwsgi.log_master_bufsize); CURL *curl = curl_easy_init(); // ARGH !!! if (!curl) return; curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); curl_easy_setopt(curl, CURLOPT_TIMEOUT, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL); curl_easy_setopt(curl, CURLOPT_READDATA, ut); curl_easy_setopt(curl, CURLOPT_POST, 1L); struct curl_slist *expect = NULL; expect = curl_slist_append(expect, "Expect:"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, expect); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); struct uwsgi_airbrake_config *uacc = (struct uwsgi_airbrake_config *) ut->data; char *opts = uwsgi_str(uacc->arg); // fill curl options char *ctx = NULL; char *p = strtok_r(opts, ";", &ctx); while(p) { uwsgi_airbrake_setopt(curl, uwsgi_str(p), uacc); p = strtok_r(NULL, ";", &ctx); } for(;;) { int ret = event_queue_wait(ut->queue, -1, &interesting_fd); if (ret < 0) return; if (ret == 0) continue; if (interesting_fd != ut->pipe[1]) continue; ssize_t rlen = read(ut->pipe[1], ut->buf, uwsgi.log_master_bufsize); if (rlen <= 0) continue; ut->pos = 0; ut->len = (size_t) rlen; ut->custom0 = 0; char *notice = uwsgi_format_airbrake_backtrace(ut); curl_slist_append(expect, "Accept: */*"); curl_slist_append(expect, "Content-Type: text/xml; charset=utf-8"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, expect); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, notice); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(notice)); curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) ut->len); CURLcode res = curl_easy_perform(curl); if (res != CURLE_OK) { uwsgi_log_alarm("-curl] curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } free(notice); } }
xmlNodePtr xccdf_tailoring_to_dom(struct xccdf_tailoring *tailoring, xmlDocPtr doc, xmlNodePtr parent, const struct xccdf_version_info *version_info) { xmlNs *ns_xccdf = xmlSearchNsByHref(doc, parent, BAD_CAST xccdf_version_info_get_namespace_uri(version_info)); xmlNs *ns_tailoring = NULL; xmlNode *tailoring_node = xmlNewNode(ns_xccdf, BAD_CAST "Tailoring"); const char *xccdf_version = xccdf_version_info_get_version(version_info); #ifdef __USE_GNU if (strverscmp(xccdf_version, "1.1") >= 0 && strverscmp(xccdf_version, "1.2") < 0) { #else if (strcmp(xccdf_version, "1.1") >= 0 && strcmp(xccdf_version, "1.2") < 0) { #endif // XCCDF 1.1 does not support Tailoring! // However we will allow Tailoring export if it is done to an external // file. The namespace will be our custom xccdf-1.1-tailoring extension // namespace. if (parent != NULL) { oscap_seterr(OSCAP_EFAMILY_XML, "XCCDF 1.1 does not support embedded Tailoring elements!"); xmlFreeNode(tailoring_node); return NULL; } ns_tailoring = xmlNewNs(tailoring_node, BAD_CAST "http://open-scap.org/page/Xccdf-1.1-tailoring", BAD_CAST "cdf-11-tailoring" ); } #ifdef __USE_GNU else if (strverscmp(xccdf_version, "1.1") < 0) { #else else if (strcmp(xccdf_version, "1.1") < 0) { #endif oscap_seterr(OSCAP_EFAMILY_XML, "XCCDF Tailoring isn't supported in XCCDF version '%s'," "nor does openscap have a custom extension for this scenario. " "XCCDF Tailoring requires XCCDF 1.1 and higher, 1.2 is recommended."); xmlFreeNode(tailoring_node); return NULL; } if (!ns_xccdf) { // In cases where tailoring ends up being the root node we have to create // a namespace at the node itself. ns_xccdf = xmlNewNs(tailoring_node, BAD_CAST xccdf_version_info_get_namespace_uri(version_info), BAD_CAST "xccdf"); } if (!ns_tailoring) ns_tailoring = ns_xccdf; // We intentionally set the wrong namespace here since children of tailoring // will reuse it and we want them to have the xccdf namespace, the namespace // is set to the proper namespace before returning the tailoring. xmlSetNs(tailoring_node, ns_xccdf); if (parent) xmlAddChild(parent, tailoring_node); else xmlDocSetRootElement(doc, tailoring_node); if (tailoring->id) { xmlNewProp(tailoring_node, BAD_CAST "id", BAD_CAST tailoring->id); } if (tailoring->benchmark_ref || tailoring->benchmark_ref_version) { xmlNodePtr benchmark_ref_node = xmlNewChild(tailoring_node, ns_tailoring, BAD_CAST "benchmark", NULL); if (tailoring->benchmark_ref) xmlNewProp(benchmark_ref_node, BAD_CAST "href", BAD_CAST tailoring->benchmark_ref); if (tailoring->benchmark_ref_version) xmlNewProp(benchmark_ref_node, BAD_CAST "version", BAD_CAST tailoring->benchmark_ref_version); } struct xccdf_status_iterator *statuses = xccdf_tailoring_get_statuses(tailoring); while (xccdf_status_iterator_has_more(statuses)) { struct xccdf_status *status = xccdf_status_iterator_next(statuses); xccdf_status_to_dom(status, doc, tailoring_node, version_info); } xccdf_status_iterator_free(statuses); struct oscap_reference_iterator *dc_statuses = xccdf_tailoring_get_dc_statuses(tailoring); while (oscap_reference_iterator_has_more(dc_statuses)) { struct oscap_reference *ref = oscap_reference_iterator_next(dc_statuses); oscap_reference_to_dom(ref, tailoring_node, doc, "dc-status"); } oscap_reference_iterator_free(dc_statuses); /* version and attributes */ const char *version = xccdf_tailoring_get_version(tailoring); if (version) { xmlNode* version_node = xmlNewTextChild(tailoring_node, ns_tailoring, BAD_CAST "version", BAD_CAST version); const char *version_update = xccdf_tailoring_get_version_update(tailoring); if (version_update) xmlNewProp(version_node, BAD_CAST "update", BAD_CAST version_update); const char *version_time = xccdf_tailoring_get_version_time(tailoring); if (version_time) xmlNewProp(version_node, BAD_CAST "time", BAD_CAST version_time); } struct oscap_string_iterator* metadata = xccdf_tailoring_get_metadata(tailoring); while (oscap_string_iterator_has_more(metadata)) { const char* meta = oscap_string_iterator_next(metadata); oscap_xmlstr_to_dom(tailoring_node, "metadata", meta); } oscap_string_iterator_free(metadata); struct xccdf_profile_iterator *profiles = xccdf_tailoring_get_profiles(tailoring); while (xccdf_profile_iterator_has_more(profiles)) { struct xccdf_profile *profile = xccdf_profile_iterator_next(profiles); xccdf_item_to_dom(XITEM(profile), doc, tailoring_node); } xccdf_profile_iterator_free(profiles); xmlSetNs(tailoring_node, ns_tailoring); return tailoring_node; } int xccdf_tailoring_export(struct xccdf_tailoring *tailoring, const char *file, const struct xccdf_version_info *version_info) { __attribute__nonnull__(file); LIBXML_TEST_VERSION; xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); if (doc == NULL) { oscap_setxmlerr(xmlGetLastError()); return -1; } xccdf_tailoring_to_dom(tailoring, doc, NULL, version_info); return oscap_xml_save_filename(file, doc); } const char *xccdf_tailoring_get_id(const struct xccdf_tailoring *tailoring) { return tailoring->id; } const char *xccdf_tailoring_get_version(const struct xccdf_tailoring *tailoring) { return tailoring->version; } const char *xccdf_tailoring_get_version_update(const struct xccdf_tailoring *tailoring) { return tailoring->version_update; } const char *xccdf_tailoring_get_version_time(const struct xccdf_tailoring *tailoring) { return tailoring->version_time; } const char *xccdf_tailoring_get_benchmark_ref(const struct xccdf_tailoring *tailoring) { return tailoring->benchmark_ref; } const char *xccdf_tailoring_get_benchmark_ref_version(const struct xccdf_tailoring *tailoring) { return tailoring->benchmark_ref_version; } bool xccdf_tailoring_set_id(struct xccdf_tailoring *tailoring, const char* newval) { if (tailoring->id) oscap_free(tailoring->id); tailoring->id = oscap_strdup(newval); return true; } bool xccdf_tailoring_set_version(struct xccdf_tailoring *tailoring, const char *newval) { if (tailoring->version) oscap_free(tailoring->version); tailoring->version = oscap_strdup(newval); return true; } bool xccdf_tailoring_set_version_update(struct xccdf_tailoring *tailoring, const char *newval) { if (tailoring->version_update) oscap_free(tailoring->version_update); tailoring->version_update = oscap_strdup(newval); return true; } bool xccdf_tailoring_set_version_time(struct xccdf_tailoring *tailoring, const char *newval) { if (tailoring->version_time) oscap_free(tailoring->version_time); tailoring->version_time = oscap_strdup(newval); return true; } bool xccdf_tailoring_set_benchmark_ref(struct xccdf_tailoring *tailoring, const char *newval) { if (tailoring->benchmark_ref) oscap_free(tailoring->benchmark_ref); tailoring->benchmark_ref = oscap_strdup(newval); return true; } bool xccdf_tailoring_set_benchmark_ref_version(struct xccdf_tailoring *tailoring, const char *newval) { if (tailoring->benchmark_ref_version) oscap_free(tailoring->benchmark_ref_version); tailoring->benchmark_ref_version = oscap_strdup(newval); return true; } struct oscap_string_iterator *xccdf_tailoring_get_metadata(const struct xccdf_tailoring *tailoring) { return (struct oscap_string_iterator*) oscap_iterator_new(tailoring->metadata); } struct xccdf_profile_iterator *xccdf_tailoring_get_profiles(const struct xccdf_tailoring *tailoring) { return (struct xccdf_profile_iterator*) oscap_iterator_new(tailoring->profiles); } struct xccdf_status_iterator *xccdf_tailoring_get_statuses(const struct xccdf_tailoring *tailoring) { return (struct xccdf_status_iterator*) oscap_iterator_new(tailoring->statuses); } struct oscap_reference_iterator *xccdf_tailoring_get_dc_statuses(const struct xccdf_tailoring *tailoring) { return (struct oscap_reference_iterator*) oscap_iterator_new(tailoring->dc_statuses); } struct xccdf_profile * xccdf_tailoring_get_profile_by_id(const struct xccdf_tailoring *tailoring, const char *profile_id) { struct xccdf_profile_iterator *profit = xccdf_tailoring_get_profiles(tailoring); while (xccdf_profile_iterator_has_more(profit)) { struct xccdf_profile *profile = xccdf_profile_iterator_next(profit); if (profile == NULL) { assert(profile != NULL); continue; } if (oscap_streq(xccdf_profile_get_id(profile), profile_id)) { xccdf_profile_iterator_free(profit); return profile; } } xccdf_profile_iterator_free(profit); return NULL; }
int EBC_Provider_MkEuZipDoc_A004(AB_PROVIDER *pro, AB_USER *u, const char *requestType, const uint8_t *pMsg, uint32_t lMsg, GWEN_BUFFER *sbuf) { int rv; xmlDocPtr doc; xmlNodePtr root_node; xmlNodePtr node; xmlNsPtr ns; GWEN_BUFFER *tbuf; GWEN_BUFFER *bbuf; tbuf=GWEN_Buffer_new(0, 256, 0, 1); rv=EBC_Provider_EuSign_A004(pro, u, requestType, pMsg, lMsg, tbuf); if (rv) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(tbuf); return rv; } bbuf=GWEN_Buffer_new(0, (GWEN_Buffer_GetUsedBytes(tbuf)*3)/2, 0, 1); rv=GWEN_Base64_Encode((const uint8_t*)GWEN_Buffer_GetStart(tbuf), GWEN_Buffer_GetUsedBytes(tbuf), bbuf, 0); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(bbuf); GWEN_Buffer_free(tbuf); return rv; } GWEN_Buffer_free(tbuf); doc=xmlNewDoc(BAD_CAST "1.0"); root_node=xmlNewNode(NULL, BAD_CAST "UserSignatureData"); xmlDocSetRootElement(doc, root_node); ns=xmlNewNs(root_node, BAD_CAST "http://www.ebics.org/H002", NULL); assert(ns); ns=xmlNewNs(root_node, BAD_CAST "http://www.w3.org/2001/XMLSchema-instance", BAD_CAST "xsi"); xmlNewNsProp(root_node, ns, BAD_CAST "schemaLocation", /* xsi:schemaLocation */ BAD_CAST "http://www.ebics.org/H002 " "http://www.ebics.org/H002/ebics_orders.xsd"); node=xmlNewTextChild(root_node, NULL, BAD_CAST "OrderSignature", BAD_CAST GWEN_Buffer_GetStart(bbuf)); GWEN_Buffer_free(bbuf); xmlNewProp(node, BAD_CAST "PartnerID", BAD_CAST AB_User_GetCustomerId(u)); rv=EB_Xml_CompressDoc(doc, sbuf); if (rv<0) { DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv); xmlFreeDoc(doc); return rv; } xmlFreeDoc(doc); return 0; }
static xmlNodePtr residue2xml(const freesasa_node *node, int options) { xmlNodePtr xml_node = NULL, xml_area = NULL, xml_relarea = NULL; const char *name, *number; const freesasa_nodearea *abs, *reference; char *trim_number, *trim_name; freesasa_nodearea rel; assert(node); name = freesasa_node_name(node); number = freesasa_node_residue_number(node); abs = freesasa_node_area(node); reference = freesasa_node_residue_reference(node); trim_number = malloc(strlen(number) + 1); trim_name = malloc(strlen(name) + 1); if (!trim_number || ! trim_name) { mem_fail(); goto cleanup; } sscanf(number, "%s", trim_number); sscanf(name, "%s", trim_name); xml_node = xmlNewNode(NULL, BAD_CAST "residue"); if (xml_node == NULL) { fail_msg(""); return NULL; } if (xmlNewProp(xml_node, BAD_CAST "name", BAD_CAST trim_name) == NULL || xmlNewProp(xml_node, BAD_CAST "number", BAD_CAST trim_number) == NULL) { fail_msg(""); goto cleanup; } xml_area = nodearea2xml(abs, "area"); if (xml_area == NULL) { fail_msg(""); goto cleanup; } if (xmlAddChild(xml_node, xml_area) == NULL) { xmlFreeNode(xml_area); fail_msg(""); goto cleanup; } if ((reference != NULL) && !(options & FREESASA_OUTPUT_SKIP_REL)) { freesasa_residue_rel_nodearea(&rel, abs, reference); xml_relarea = nodearea2xml(&rel, "relativeArea"); if (xml_relarea == NULL) { fail_msg(""); goto cleanup; } if (xmlAddChild(xml_node, xml_relarea) == NULL) { xmlFreeNode(xml_relarea); fail_msg(""); goto cleanup; } } free(trim_name); free(trim_number); return xml_node; cleanup: free(trim_name); free(trim_number); xmlFreeNode(xml_node); return NULL; }
xmlNode* CXBindingsObjectHandler::DoWriteResource() { CXBindingsObject* object = dynamic_cast<CXBindingsObject*>(m_instance); xmlNode* node = xmlNewNode( NULL , (const xmlChar*) "object" ); xmlNewProp( node , (const xmlChar*) "type" , cxxU2C( object->GetName() ) ); CXBindingsArrayGrammarChild& childs = object->GetChilds(); for( unsigned int i = 0; i < childs.size() ; ++i ) { xmlNode* child = CXBindingsXmlReader::Get()->WriteResource( &(childs[i]) ); if( child != NULL ) xmlAddChild( node , child ); } CXBindingsArrayGrammarRule& rules = object->GetRules(); for( unsigned int i = 0; i < rules.size() ; ++i ) { xmlNode* childnode = CXBindingsXmlReader::Get()->WriteResource( &(rules[i]) ); if( childnode != NULL ) xmlAddChild( node , childnode ); } CXBindingsArrayGrammarProperty& properties = object->GetProperties(); for( unsigned int i = 0; i < properties.size() ; ++i ) { xmlNode* childnode = CXBindingsXmlReader::Get()->WriteResource( &(properties[i]) ); if( childnode != NULL ) xmlAddChild( node , childnode ); } CXBindingsArrayGrammarForEachChild& childRules = object->GetChildRules(); for( unsigned int i = 0; i < childRules.size() ; ++i ) { xmlNode* childnode = CXBindingsXmlReader::Get()->WriteResource( &(childRules[i]) ); if( childnode != NULL ) xmlAddChild( node , childnode ); } CXBindingsArrayGrammarCategory& categories = object->GetCategories(); for( unsigned int i = 0; i < categories.size() ; ++i ) { xmlNode* childnode = CXBindingsXmlReader::Get()->WriteResource( &(categories[i]) ); if( childnode != NULL ) xmlAddChild( node , childnode ); } CXBindingsArrayGrammarChildContainer& childcontainers = object->GetChildContainers(); for( unsigned int i = 0; i < childcontainers.size() ; ++i ) { xmlNode* childnode = CXBindingsXmlReader::Get()->WriteResource( &(childcontainers[i]) ); if( childnode != NULL ) xmlAddChild( node , childnode ); } CXBindingsArrayGrammarInherits& inherits = object->GetModels(); for( unsigned int i = 0; i < inherits.size() ; ++i ) { xmlNode* childnode = CXBindingsXmlReader::Get()->WriteResource( &(inherits[i]) ); if( childnode != NULL ) xmlAddChild( node , childnode ); } return node; }
int freesasa_write_xml(FILE *output, freesasa_node *root, int options) { freesasa_node *child = NULL; xmlDocPtr doc = NULL; xmlNodePtr xml_root = NULL, xml_result_node = NULL; xmlNsPtr ns = NULL; xmlBufferPtr buf = NULL; xmlTextWriterPtr writer = NULL; int ret = FREESASA_FAIL; assert(freesasa_node_type(root) == FREESASA_NODE_ROOT); doc = xmlNewDoc(BAD_CAST "1.0"); if (doc == NULL) { fail_msg(""); goto cleanup; } xml_root = xmlNewNode(NULL, BAD_CAST "results"); if (xml_root == NULL) { fail_msg(""); goto cleanup; } ns = xmlNewNs(xml_root, BAD_CAST FREESASA_XMLNS, NULL); if (ns == NULL) { fail_msg(""); xmlFreeNode(xml_root); goto cleanup; } xmlDocSetRootElement(doc, xml_root); /* global attributes */ if (xmlNewProp(xml_root, BAD_CAST "source", BAD_CAST freesasa_string) == NULL) { fail_msg(""); goto cleanup; } if (xmlNewProp(xml_root, BAD_CAST "lengthUnit", BAD_CAST "Ångström") == NULL) { fail_msg(""); goto cleanup; } child = freesasa_node_children(root); while (child) { xml_result_node = xml_result(child, options); if (xml_result_node == NULL) { fail_msg(""); goto cleanup; } if (xmlAddChild(xml_root, xml_result_node) == NULL) { fail_msg(""); xmlFreeNode(xml_result_node); goto cleanup; } child = freesasa_node_next(child); } buf = xmlBufferCreate(); if (buf == NULL) { fail_msg(""); goto cleanup; } writer = xmlNewTextWriterMemory(buf, 0); if (writer == NULL) { xmlBufferFree(buf); fail_msg(""); goto cleanup; } if (xmlTextWriterStartDocument(writer, XML_DEFAULT_VERSION, xmlGetCharEncodingName(XML_CHAR_ENCODING_UTF8), NULL) == -1) { fail_msg(""); goto cleanup; } if (xmlTextWriterFlush(writer) == -1) { fail_msg(""); goto cleanup; } if (xmlNodeDump(buf, doc, xml_root, 0, 1) == 0) { fail_msg(""); goto cleanup; } if (xmlTextWriterEndDocument(writer) == -1) { fail_msg(""); goto cleanup; } fprintf(output, "%s", (const char*) buf->content); fflush(output); if (ferror(output)) { fail_msg(strerror(errno)); goto cleanup; } ret = FREESASA_SUCCESS; cleanup: xmlFreeDoc(doc); xmlFreeTextWriter(writer); return ret; }
//mod xml node int mod_eag_node(char * fpath,char * node_name,char *attribute,char *ruler,char * content,char *newc) { xmlDocPtr pdoc = NULL; xmlNodePtr pcurnode = NULL; xmlNodePtr design_node = NULL; pdoc = xmlReadFile(fpath,"utf-8",256); if(NULL == pdoc) { return 1; } int if_second_flag=0,if_second_null=0; pcurnode = xmlDocGetRootElement(pdoc); pcurnode = pcurnode->xmlChildrenNode; while (NULL != pcurnode) { if (!xmlStrcmp(pcurnode->name, BAD_CAST node_name)) { xmlChar* szAttr = xmlGetProp(pcurnode,BAD_CAST attribute); if(!xmlStrcmp(szAttr,BAD_CAST ruler)) { xmlNodePtr childPtr = pcurnode; childPtr=childPtr->children; while(childPtr !=NULL) { if_second_null=1; if ((!xmlStrcmp(childPtr->name, BAD_CAST content))) { xmlNodeSetContent(childPtr, BAD_CAST newc); if_second_flag=0; break; } else { if_second_flag=1; design_node=pcurnode; } childPtr = childPtr->next; } if(if_second_null == 0) { if_second_flag=1; design_node=pcurnode; } } xmlFree(szAttr); } pcurnode = pcurnode->next; } if(if_second_flag==1) { xmlNodePtr node = xmlNewNode(NULL,BAD_CAST content); xmlAddChild(design_node,node); xmlNodePtr content1 = xmlNewText(BAD_CAST newc); xmlAddChild(node,content1); design_node=NULL; } xmlSaveFile(fpath,pdoc); return if_second_flag; }