Show
Ignore:
Timestamp:
05/04/09 18:08:20 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1241460500 +0000
git-parent:

[e7ae97b8a3932bf5cb12dbfe71a21caa328d49af]

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

Fixed up and working. Tested with:

(perl -e '$| = 0; print pack("N", 0xca4aca4a);'; sleep 1) | openssl s_client -connect localhost:34332
Files:

Legend:

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

    rd074a94 rdb9d1c2  
    1818#include <errno.h> 
    1919 
     20#include <libxml/xmlsave.h> 
    2021#include <libxml/tree.h> 
    2122 
     
    2829void 
    2930noit_capabilities_listener_init() { 
    30   eventer_name_callback("capabilities_transit", noit_capabilities_handler); 
     31  eventer_name_callback("capabilities_transit/1.0", noit_capabilities_handler); 
    3132  noit_control_dispatch_delegate(noit_control_dispatch, 
    3233                                 NOIT_CAPABILITIES_SERVICE, 
     
    5758  if(!ac->service_ctx) { 
    5859    char vbuff[128]; 
     60    noit_hash_table *lc; 
     61    noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 
     62    const char *k; 
     63    int klen; 
     64    void *data; 
     65 
    5966    xmlDocPtr xmldoc; 
    60     xmlNodePtr head; 
    61     xmlOutputBufferPtr out; 
     67    xmlNodePtr root, cmds; 
    6268    xmlBufferPtr xmlbuffer; 
     69    xmlSaveCtxtPtr savectx; 
    6370 
    6471    cl = ac->service_ctx = calloc(1, sizeof(*cl)); 
     
    6875    /* Create an XML Document */ 
    6976    xmldoc = xmlNewDoc((xmlChar *)"1.0"); 
    70     head = xmlNewDocNode(xmldoc, NULL, (xmlChar *)"noitd_capabilities", NULL); 
     77    root = xmlNewDocNode(xmldoc, NULL, (xmlChar *)"noitd_capabilities", NULL); 
     78    xmlDocSetRootElement(xmldoc, root); 
    7179 
    7280    /* Fill in the document */ 
    73     xmlNewTextChild(head, NULL, (xmlChar *)"version", (xmlChar *)vbuff); 
     81    xmlNewTextChild(root, NULL, (xmlChar *)"version", (xmlChar *)vbuff); 
     82 
     83    cmds = xmlNewNode(NULL, (xmlChar *)"services"); 
     84    xmlAddChild(root, cmds); 
     85    lc = noit_listener_commands(); 
     86    while(noit_hash_next(lc, &iter, &k, &klen, &data)) { 
     87      xmlNodePtr cnode; 
     88      char hexcode[10]; 
     89      const char *name; 
     90      eventer_func_t *f = (eventer_func_t *)k; 
     91      noit_hash_table *sc = (noit_hash_table *)data; 
     92      noit_hash_iter sc_iter = NOIT_HASH_ITER_ZERO; 
     93      const char *sc_k; 
     94      int sc_klen; 
     95      void *sc_data; 
     96 
     97      name = eventer_name_for_callback(*f); 
     98      cnode = xmlNewNode(NULL, (xmlChar *)"service"); 
     99      xmlSetProp(cnode, (xmlChar *)"name", name ? (xmlChar *)name : NULL); 
     100      if(*f == ac->dispatch) 
     101        xmlSetProp(cnode, (xmlChar *)"connected", (xmlChar *)"true"); 
     102      xmlAddChild(cmds, cnode); 
     103      while(noit_hash_next(sc, &sc_iter, &sc_k, &sc_klen, &sc_data)) { 
     104        xmlNodePtr scnode; 
     105        eventer_func_t *f = (eventer_func_t *)sc_data; 
     106 
     107        snprintf(hexcode, sizeof(hexcode), "0x%08x", *((u_int32_t *)sc_k)); 
     108        name = eventer_name_for_callback(*f); 
     109        scnode = xmlNewNode(NULL, (xmlChar *)"command"); 
     110        xmlSetProp(scnode, (xmlChar *)"name", name ? (xmlChar *)name : NULL); 
     111        xmlSetProp(scnode, (xmlChar *)"code", (xmlChar *)hexcode); 
     112        xmlAddChild(cnode, scnode); 
     113      } 
     114    } 
    74115 
    75116    /* Write it out to a buffer and copy it for writing */ 
    76117    xmlbuffer = xmlBufferCreate(); 
    77     out = xmlOutputBufferCreateBuffer(xmlbuffer, NULL); 
    78     xmlOutputBufferFlush(out); 
    79     xmlOutputBufferClose(out); 
     118    savectx = xmlSaveToBuffer(xmlbuffer, "utf8", 1); 
     119    xmlSaveDoc(savectx, xmldoc); 
     120    xmlSaveClose(savectx); 
    80121    cl->buff = strdup((const char *)xmlBufferContent(xmlbuffer)); 
    81122    cl->towrite = xmlBufferLength(xmlbuffer);