/** * \internal * Reads the list of accounts and the list of queue_list returned by the MOAB cluster * "mcredctl" command and places them on \p accounts and \p queue_list, respectively. */ static void server_moab_read_credentials(GString *accounts, GString *queue_list) { GString *cmd_line = NULL; gchar *std_out = NULL; gchar *std_err = NULL; gint exit_status; GdomeDOMImplementation *dom_impl = NULL; GdomeDocument *doc = NULL; GdomeElement *element = NULL; GdomeException exception; GdomeDOMString *attribute_name; cmd_line = g_string_new(""); g_string_printf(cmd_line, "mcredctl -q accessfrom user:%s --format=xml", getenv("USER")); if (g_spawn_command_line_sync(cmd_line->str, &std_out, &std_err, &exit_status, NULL) == FALSE) goto err; if ((dom_impl = gdome_di_mkref()) == NULL) goto err; if ((doc = gdome_di_createDocFromMemory(dom_impl, std_out, GDOME_LOAD_PARSING, &exception)) == NULL) { gdome_di_unref(dom_impl, &exception); goto err; } if ((element = gdome_doc_documentElement(doc, &exception)) == NULL) { gdome_doc_unref(doc, &exception); gdome_di_unref(dom_impl, &exception); goto err; } if ((element = (GdomeElement *) gdome_el_firstChild(element, &exception)) == NULL) { gdome_doc_unref(doc, &exception); gdome_di_unref(dom_impl, &exception); goto err; } attribute_name = gdome_str_mkref("AList"); g_string_assign(accounts, (gdome_el_getAttribute(element, attribute_name, &exception))->str); gdome_str_unref(attribute_name); attribute_name = gdome_str_mkref("CList"); g_string_assign(queue_list, (gdome_el_getAttribute(element, attribute_name, &exception))->str); gdome_str_unref(attribute_name); gdome_doc_unref(doc, &exception); gdome_di_unref(dom_impl, &exception); err: g_string_free(cmd_line, TRUE); g_free(std_out); g_free(std_err); }
/* {{{ flt_xmlarc_cts */ int flt_xmlarc_cts(GdomeDocument *doc,cl_thread_t *thr) { GdomeException e; GdomeNodeList *messages; GdomeNode *msg; GdomeDOMString *message_str = gdome_str_mkref("Message"); /* * We have to create an internal structure from the XML. Trivial * recursive algorithm. */ messages = gdome_doc_getElementsByTagName(doc,message_str,&e); msg = gdome_nl_item(messages,0,&e); thr->messages = cf_alloc(NULL,1,sizeof(*thr->messages),CF_ALLOC_CALLOC); thr->ht = cf_alloc(NULL,1,sizeof(*thr->ht),CF_ALLOC_CALLOC); thr->ht->msg = thr->messages; cf_array_init(&thr->ht->childs,sizeof(*thr->ht),NULL); if(flt_xmlarc_mtt(thr,thr->ht,msg) != 0) return -1; gdome_n_unref(msg,&e); gdome_nl_unref(messages,&e); gdome_str_unref(message_str); return 0; }
/* {{{ flt_xmlarc_hh */ void flt_xmlarc_hh(message_t *p,GdomeNode *n) { GdomeException exc; GdomeNodeList *nl = gdome_n_childNodes(n,&exc); GdomeNode *author = gdome_nl_item(nl,0,&exc); GdomeNode *category = gdome_nl_item(nl,1,&exc); GdomeNode *subject = gdome_nl_item(nl,2,&exc); GdomeNode *date = gdome_nl_item(nl,3,&exc); GdomeDOMString *ls_str = gdome_str_mkref("longSec"); GdomeNamedNodeMap *atts = gdome_n_attributes(date,&exc); GdomeNode *longSec = gdome_nnm_getNamedItem(atts,ls_str,&exc); GdomeDOMString *ls_val = gdome_n_nodeValue(longSec,&exc); GdomeNodeList *a_nl = gdome_n_childNodes(author,&exc); GdomeNode *a_name = gdome_nl_item(a_nl,0,&exc); GdomeNode *a_email = gdome_nl_item(a_nl,1,&exc); GdomeNode *a_hp = gdome_nl_item(a_nl,2,&exc); GdomeNode *a_img = gdome_nl_item(a_nl,3,&exc); p->date = strtol(ls_val->str,NULL,10); flt_xmlarc_snvts(a_name,&p->author); flt_xmlarc_snvts(subject,&p->subject); flt_xmlarc_snvts(category,&p->category); flt_xmlarc_snvts(a_email,&p->email); flt_xmlarc_snvts(a_hp,&p->hp); flt_xmlarc_snvts(a_img,&p->img); gdome_str_unref(ls_val); gdome_n_unref(a_name,&exc); gdome_n_unref(a_email,&exc); gdome_n_unref(a_hp,&exc); gdome_n_unref(a_img,&exc); gdome_n_unref(longSec,&exc); gdome_nl_unref(a_nl,&exc); gdome_str_unref(ls_str); gdome_nnm_unref(atts,&exc); gdome_n_unref(author,&exc); gdome_n_unref(category,&exc); gdome_n_unref(subject,&exc); gdome_n_unref(date,&exc); gdome_nl_unref(nl,&exc); }
/* {{{ flt_xmlarc_mtt */ int flt_xmlarc_mtt(cl_thread_t *thr,hierarchical_node_t *hmsg,GdomeNode *posting) { GdomeException e; GdomeNodeList *childs = gdome_n_childNodes(posting,&e); GdomeNamedNodeMap *atts = gdome_n_attributes(posting,&e); GdomeDOMString *cf_str_id = gdome_str_mkref("id"); GdomeDOMString *cf_str_invi = gdome_str_mkref("invisible"); GdomeNode *invi = gdome_nnm_getNamedItem(atts,cf_str_invi,&e); GdomeNode *id = gdome_nnm_getNamedItem(atts,cf_str_id,&e); GdomeNode *element; GdomeDOMString *name; GdomeDOMString *tmp; hierarchical_node_t h; u_char *ctmp; size_t len,i; thr->msg_len++; if(id) { tmp = gdome_n_nodeValue(id,&e); hmsg->msg->mid = cf_str_to_uint64(tmp->str+1); gdome_str_unref(tmp); } else return -1; if(invi) { tmp = gdome_n_nodeValue(invi,&e); hmsg->msg->invisible = atoi(tmp->str); gdome_str_unref(tmp); } else hmsg->msg->invisible = 0; for(i=0,len=gdome_nl_length(childs,&e);i<len;i++) { element = gdome_nl_item(childs,i,&e); name = gdome_n_nodeName(element,&e); if(cf_strcmp(name->str,"Header") == 0) { flt_xmlarc_hh(hmsg->msg,element); } else if(cf_strcmp(name->str,"MessageContent") == 0) { cf_str_init(&hmsg->msg->content); if((ctmp = xml_get_node_value(element)) != NULL) { hmsg->msg->content.content = ctmp; hmsg->msg->content.reserved = hmsg->msg->content.len = strlen(ctmp); } } else if(cf_strcmp(name->str,"Message") == 0) { h.msg = cf_alloc(NULL,1,sizeof(*h.msg),CF_ALLOC_CALLOC); cf_array_init(&h.childs,sizeof(h),NULL); if(flt_xmlarc_mtt(thr,&h,element) != 0) return -1; cf_array_push(&hmsg->childs,&h); } gdome_str_unref(name); gdome_n_unref(element,&e); } gdome_nl_unref(childs,&e); gdome_nnm_unref(atts,&e); gdome_str_unref(cf_str_id); gdome_str_unref(cf_str_invi); gdome_n_unref(invi,&e); gdome_n_unref(id,&e); return 0; }