Changeset 03fe9a7330858471b035c426bdbb9f74fdcd0d58

Show
Ignore:
Timestamp:
03/28/12 20:59:02 (2 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1332968342 +0000
git-parent:

[d5db0b89dd6ef5ab8baaa06225cd92898bd0dcea]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1332968342 +0000
Message:

more subtle magic around transitioning namespaces from submissions into the master config

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_check_rest.c

    r2a06f12 r03fe9a7  
    216216  mod_cnt = noit_check_registered_module_cnt(); 
    217217  for(mod=0; mod<mod_cnt; mod++) { 
     218    noit_conf_section_t toplevel; 
     219    xmlNodePtr nodeptr; 
    218220    xmlNsPtr ns; 
    219221    const char *nsname; 
    220222    char buff[256]; 
     223    toplevel = noit_conf_get_section(NULL, "/*"); 
    221224    nsname = noit_check_registered_module(mod); 
     225  
     226    nodeptr = (xmlNodePtr)toplevel;  
    222227    snprintf(buff, sizeof(buff), "noit://module/%s", nsname); 
    223     ns = xmlNewNs(config, (xmlChar *)buff, (xmlChar *)nsname); 
    224     configh = noit_conf_get_namespaced_hash(node, "config", nsname); 
    225     if(configh) { 
    226       memset(&iter, 0, sizeof(iter)); 
    227       while(noit_hash_next(configh, &iter, &k, &klen, &data)) { 
    228         NS_NODE_CONTENT(config, ns, "value", data, 
    229           xmlSetProp(tmp, (xmlChar *)"name", (xmlChar *)k); 
    230         ); 
     228    ns = xmlSearchNs(nodeptr->doc, nodeptr, (xmlChar *)nsname); 
     229    if(ns) { 
     230      configh = noit_conf_get_namespaced_hash(node, "config", nsname); 
     231      if(configh) { 
     232        memset(&iter, 0, sizeof(iter)); 
     233        while(noit_hash_next(configh, &iter, &k, &klen, &data)) { 
     234          NS_NODE_CONTENT(config, ns, "value", data, 
     235            xmlSetProp(tmp, (xmlChar *)"name", (xmlChar *)k); 
     236          ); 
     237        } 
     238        noit_hash_destroy(configh, free, free); 
     239        free(configh); 
    231240      } 
    232       noit_hash_destroy(configh, free, free); 
    233       free(configh); 
    234241    } 
    235242  } 
     
    381388} 
    382389static void 
    383 configure_xml_check(xmlNodePtr check, xmlNodePtr a, xmlNodePtr c) { 
     390configure_xml_check(xmlNodePtr parent, xmlNodePtr check, xmlNodePtr a, xmlNodePtr c) { 
    384391  xmlNodePtr n, config, oldconfig; 
    385392  for(n = a->children; n; n = n->next) { 
     
    413420      xmlChar *v = xmlNodeGetContent(n); 
    414421      if(n->ns) { 
    415         targetns = xmlSearchNs(check->doc, config, n->ns->prefix); 
     422        targetns = xmlSearchNs(parent->doc, xmlDocGetRootElement(parent->doc), 
     423                               n->ns->prefix); 
     424noitL(noit_error,"Setting a config value in a namespace (%p)\n", targetns); 
    416425        if(!targetns) targetns = xmlNewNs(config, n->ns->href, n->ns->prefix); 
    417426      } 
     
    586595      newcheck = xmlNewNode(NULL, (xmlChar *)"check"); 
    587596      xmlSetProp(newcheck, (xmlChar *)"uuid", (xmlChar *)pats[1]); 
    588       configure_xml_check(newcheck, attr, config); 
    589597      parent = make_conf_path(pats[0]); 
    590598      if(!parent) FAIL("invalid path"); 
     599      configure_xml_check(parent, newcheck, attr, config); 
    591600      xmlAddChild(parent, newcheck); 
    592601      CONF_DIRTY(newcheck); 
     
    622631    if(ocheck && ocheck != check) FAIL("new target`name would collide"); 
    623632    if(module_change) FAIL("cannot change module"); 
    624     configure_xml_check(node, attr, config); 
    625633    parent = make_conf_path(pats[0]); 
    626634    if(!parent) FAIL("invalid path"); 
     635    configure_xml_check(parent, node, attr, config); 
    627636    xmlUnlinkNode(node); 
    628637    xmlAddChild(parent, node);