Changeset 75ee62d07972a0eb07cde464b4d2244abd0b06ec

Show
Ignore:
Timestamp:
09/21/09 04:07:40 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1253506060 +0000
git-parent:

[37daa37bbc546da8db4d76945b9c4b523e02d77b]

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

programmatic configuration will have to suffice for now, closes #182

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/Makefile.in

    r28b073c r75ee62d  
    4141        noit_capabilities_listener.o noit_xml.o \ 
    4242        noit_jlog_listener.o noit_livestream_listener.o noit_filters.o \ 
    43         noit_http.o noit_rest.o noit_check_rest.o 
     43        noit_http.o noit_rest.o noit_check_rest.o noit_filters_rest.o 
    4444 
    4545STRATCON_OBJS=stratcond.o noit_listener.o \ 
  • src/noit_check_rest.c

    r6f0b2ab r75ee62d  
    4747#define FAIL(a) do { error = (a); goto error; } while(0) 
    4848#define UUID_REGEX "[0-9a-fA-F]{4}(?:[0-9a-fA-F]{4}-){4}[0-9a-fA-F]{12}" 
    49  
    50 struct rest_xml_payload { 
    51   char *buffer; 
    52   int len; 
    53   int allocd; 
    54   int complete; 
    55 }; 
    5649 
    5750static int 
     
    230223  if(doc) xmlFreeDoc(doc); 
    231224  return 0; 
    232 } 
    233  
    234 static void 
    235 rest_xml_payload_free(void *f) { 
    236   struct rest_xml_payload *xmlin = f; 
    237   if(xmlin->buffer) free(xmlin->buffer); 
    238225} 
    239226 
     
    465452  noit_check_t *check; 
    466453  char xpath[1024], *uuid_conf; 
    467   int rv, cnt, error_code = 500
     454  int rv, cnt, error_code = 500, complete = 0, mask = 0
    468455  const char *error = "internal error"; 
    469456  noit_boolean exists = noit_false; 
    470   struct rest_xml_payload *rxc; 
    471457 
    472458  if(npats != 2) goto error; 
    473459 
    474   if(restc->call_closure == NULL) { 
    475     rxc = restc->call_closure = calloc(1, sizeof(*rxc)); 
    476     restc->call_closure_free = rest_xml_payload_free; 
    477   } 
    478   rxc = restc->call_closure; 
    479   while(!rxc->complete) { 
    480     int len, mask; 
    481     if(rxc->len == rxc->allocd) { 
    482       char *b; 
    483       rxc->allocd += 32768; 
    484       b = rxc->buffer ? realloc(rxc->buffer, rxc->allocd) : 
    485                         malloc(rxc->allocd); 
    486       if(!b) FAIL("alloc failed"); 
    487       rxc->buffer = b; 
    488     } 
    489     len = noit_http_session_req_consume(restc->http_ctx, 
    490                                         rxc->buffer + rxc->len, 
    491                                         rxc->allocd - rxc->len, 
    492                                         &mask); 
    493     if(len > 0) rxc->len += len; 
    494     if(len < 0 && errno == EAGAIN) return mask; 
    495     if(rxc->len == restc->http_ctx->req.content_length) rxc->complete = 1; 
    496   } 
    497  
    498   indoc = xmlParseMemory(rxc->buffer, rxc->len); 
     460  indoc = rest_get_xml_upload(restc, &mask, &complete); 
     461  if(!complete) return mask; 
    499462  if(indoc == NULL) FAIL("xml parse error"); 
    500463  if(!validate_check_post(indoc, &attr, &config, &error)) goto error; 
     
    588551  if(pobj) xmlXPathFreeObject(pobj); 
    589552  if(doc) xmlFreeDoc(doc); 
    590   if(indoc) xmlFreeDoc(indoc); 
    591553  restc->fastpath = rest_show_check; 
    592554  return restc->fastpath(restc, restc->nparams, restc->params); 
     
    605567  if(pobj) xmlXPathFreeObject(pobj); 
    606568  if(doc) xmlFreeDoc(doc); 
    607   if(indoc) xmlFreeDoc(indoc); 
    608569  return 0; 
    609570} 
  • src/noit_filters.c

    r37daa37 r75ee62d  
    161161  UNLOCKFS(); 
    162162} 
     163int 
     164noit_filter_exists(const char *name) { 
     165  int removed; 
     166  void *v; 
     167  LOCKFS(); 
     168  removed = noit_hash_retrieve(filtersets, name, strlen(name), &v); 
     169  UNLOCKFS(); 
     170  return removed; 
     171} 
     172int 
     173noit_filter_remove(noit_conf_section_t vnode) { 
     174  int removed; 
     175  xmlNodePtr node = vnode; 
     176  char *name = (char *)node->name; 
     177  LOCKFS(); 
     178  removed = noit_hash_delete(filtersets, name, strlen(name), 
     179                             NULL, filterset_free); 
     180  UNLOCKFS(); 
     181  return removed; 
     182} 
    163183void 
    164184noit_filters_from_conf() { 
     
    392412  if(closure) { 
    393413    int removed; 
    394     LOCKFS(); 
    395     removed = noit_hash_delete(filtersets, argv[0], strlen(argv[0]), 
    396                                NULL, filterset_free); 
    397     UNLOCKFS(); 
     414    removed = noit_filter_remove(fsnode); 
    398415    nc_printf(ncct, "%sremoved filterset '%s'\n", 
    399416              removed ? "" : "failed to ", argv[0]); 
  • src/noit_filters.h

    r88a7178 r75ee62d  
    5151                       metric_t *metric); 
    5252 
     53API_EXPORT(void) 
     54  noit_filter_compile_add(noit_conf_section_t setinfo); 
     55 
     56API_EXPORT(int) 
     57  noit_filter_remove(noit_conf_section_t setinfo); 
     58 
     59API_EXPORT(int) 
     60  noit_filter_exists(const char *name); 
     61 
     62API_EXPORT(void) 
     63  noit_filters_rest_init(); 
     64 
    5365#endif 
  • src/noit_rest.c

    r2082a78 r75ee62d  
    3737 
    3838#include <pcre.h> 
     39#include <errno.h> 
     40 
     41struct rest_xml_payload { 
     42  char *buffer; 
     43  xmlDocPtr indoc; 
     44  int len; 
     45  int allocd; 
     46  int complete; 
     47}; 
    3948 
    4049struct rest_url_dispatcher { 
     
    4655  struct rest_url_dispatcher *next; 
    4756}; 
     57 
    4858struct rule_container { 
    4959  char *base; 
     
    237247} 
    238248 
     249static void 
     250rest_xml_payload_free(void *f) { 
     251  struct rest_xml_payload *xmlin = f; 
     252  if(xmlin->buffer) free(xmlin->buffer); 
     253  if(xmlin->indoc) xmlFreeDoc(xmlin->indoc); 
     254} 
     255 
     256xmlDocPtr 
     257rest_get_xml_upload(noit_http_rest_closure_t *restc, 
     258                    int *mask, int *complete) { 
     259  struct rest_xml_payload *rxc; 
     260  if(restc->call_closure == NULL) { 
     261    rxc = restc->call_closure = calloc(1, sizeof(*rxc)); 
     262    restc->call_closure_free = rest_xml_payload_free; 
     263  } 
     264  rxc = restc->call_closure; 
     265  while(!rxc->complete) { 
     266    int len; 
     267    if(rxc->len == rxc->allocd) { 
     268      char *b; 
     269      rxc->allocd += 32768; 
     270      b = rxc->buffer ? realloc(rxc->buffer, rxc->allocd) : 
     271                        malloc(rxc->allocd); 
     272      if(!b) { 
     273        *complete = 1; 
     274        return NULL; 
     275      } 
     276      rxc->buffer = b; 
     277    } 
     278    len = noit_http_session_req_consume(restc->http_ctx, 
     279                                        rxc->buffer + rxc->len, 
     280                                        rxc->allocd - rxc->len, 
     281                                        mask); 
     282    if(len > 0) rxc->len += len; 
     283    if(len < 0 && errno == EAGAIN) return NULL; 
     284    else if(len < 0) { 
     285      *complete = 1; 
     286      return NULL; 
     287    } 
     288    if(rxc->len == restc->http_ctx->req.content_length) { 
     289      rxc->indoc = xmlParseMemory(rxc->buffer, rxc->len); 
     290      rxc->complete = 1; 
     291    } 
     292  } 
     293 
     294  *complete = 1; 
     295  return rxc->indoc; 
     296} 
    239297void noit_http_rest_init() { 
    240298  eventer_name_callback("http_rest_api/1.0", noit_http_rest_handler); 
  • src/noit_rest.h

    r2082a78 r75ee62d  
    6666                          const char *expression, rest_request_handler f); 
    6767 
     68API_EXPORT(xmlDocPtr) 
     69  rest_get_xml_upload(noit_http_rest_closure_t *restc, 
     70                      int *mask, int *complete) ; 
     71 
    6872#endif 
  • src/noitd.c

    r0256945 r75ee62d  
    185185  noit_http_rest_init(); 
    186186  noit_check_rest_init(); 
     187  noit_filters_rest_init(); 
    187188  noit_livestream_listener_init(); 
    188189