Show
Ignore:
Timestamp:
09/16/09 14:59:30 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1253113170 +0000
git-parent:

[25fec2caf0dfcfa3c997f8f87f6c42d4e176cea0]

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

support check deletes, refs #171

Files:

Legend:

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

    r25fec2c r7f8de6f  
    4545#include "noit_conf_private.h" 
    4646 
     47#define FAIL(a) do { error = (a); goto error; } while(0) 
    4748#define UUID_REGEX "[0-9a-fA-F]{4}(?:[0-9a-fA-F]{4}-){4}[0-9a-fA-F]{12}" 
    4849 
     
    381382} 
    382383static int 
     384rest_delete_check(noit_http_rest_closure_t *restc, 
     385                  int npats, char **pats) { 
     386  noit_http_session_ctx *ctx = restc->http_ctx; 
     387  xmlXPathObjectPtr pobj = NULL; 
     388  xmlXPathContextPtr xpath_ctxt = NULL; 
     389  xmlNodePtr node; 
     390  uuid_t checkid; 
     391  noit_check_t *check; 
     392  const char *error; 
     393  char xpath[1024], *uuid_conf; 
     394  int rv, cnt; 
     395  noit_boolean exists = noit_false; 
     396 
     397  if(npats != 2) goto error; 
     398 
     399  if(uuid_parse(pats[1], checkid)) goto error; 
     400  check = noit_poller_lookup(checkid); 
     401  if(check) 
     402    exists = noit_true; 
     403 
     404  rv = noit_check_xpath(xpath, sizeof(xpath), pats[0], pats[1]); 
     405  if(rv == 0) FAIL("uuid not valid"); 
     406  if(rv < 0) FAIL("Tricky McTrickster... No"); 
     407 
     408  noit_conf_xml_xpath(NULL, &xpath_ctxt); 
     409  pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); 
     410  if(!pobj || pobj->type != XPATH_NODESET || 
     411     xmlXPathNodeSetIsEmpty(pobj->nodesetval)) { 
     412    if(exists) FAIL("uuid not yours"); 
     413    goto not_found; 
     414  } 
     415  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); 
     416  if(cnt != 1) FAIL("internal error, |checkid| > 1"); 
     417  node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0); 
     418  uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid"); 
     419  if(!uuid_conf || strcasecmp(uuid_conf, pats[1])) 
     420    FAIL("internal error uuid"); 
     421 
     422  /* delete this here */ 
     423  noit_poller_deschedule(check->checkid); 
     424  xmlUnlinkNode(node); 
     425  xmlFreeNode(node); 
     426  if(noit_conf_write_file(NULL) != 0) 
     427    noitL(noit_error, "local config write failed\n"); 
     428  noit_conf_mark_changed(); 
     429  noit_http_response_ok(ctx, "text/html"); 
     430  noit_http_response_end(ctx); 
     431  goto cleanup; 
     432 
     433 not_found: 
     434  noit_http_response_not_found(ctx, "text/html"); 
     435  noit_http_response_end(ctx); 
     436  goto cleanup; 
     437 
     438 error: 
     439  noit_http_response_server_error(ctx, "text/html"); 
     440  noit_http_response_end(ctx); 
     441  goto cleanup; 
     442 
     443 cleanup: 
     444  if(pobj) xmlXPathFreeObject(pobj); 
     445  return 0; 
     446} 
     447 
     448static int 
    383449rest_set_check(noit_http_rest_closure_t *restc, 
    384450               int npats, char **pats) { 
     
    397463 
    398464  if(npats != 2) goto error; 
    399  
    400 #define FAIL(a) do { error = (a); goto error; } while(0) 
    401465 
    402466  if(restc->call_closure == NULL) { 
     
    476540    xmlNodePtr a; 
    477541    noit_check_t *ocheck; 
     542 
    478543    cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); 
    479544    if(cnt != 1) FAIL("internal error, |checkid| > 1"); 
     
    550615    rest_set_check 
    551616  ) == 0); 
    552 
    553  
     617  assert(noit_http_rest_register( 
     618    "DELETE", 
     619    "/checks/", 
     620    "^delete(/.*)(?<=/)(" UUID_REGEX ")$", 
     621    rest_delete_check 
     622  ) == 0); 
     623
     624 
  • src/noit_rest.c

    r914f047 r7f8de6f  
    223223        primer = "HEAD"; 
    224224        break; 
     225      case NOIT_CONTROL_DELETE: 
     226        primer = "DELE"; 
     227        break; 
    225228      default: 
    226229        goto socket_error; 
     
    242245                                 NOIT_CONTROL_POST, 
    243246                                 noit_http_rest_handler); 
    244 
    245  
     247  noit_control_dispatch_delegate(noit_control_dispatch, 
     248                                 NOIT_CONTROL_DELETE, 
     249                                 noit_http_rest_handler); 
     250
     251 
  • src/noit_rest.h

    r914f047 r7f8de6f  
    3838#define NOIT_REST_H 
    3939 
    40 #define NOIT_CONTROL_GET  0x47455420 
    41 #define NOIT_CONTROL_HEAD 0x48454144 
    42 #define NOIT_CONTROL_POST 0x504f5354 
     40#define NOIT_CONTROL_GET    0x47455420 /* "GET " */ 
     41#define NOIT_CONTROL_HEAD   0x48454144 /* "HEAD" */ 
     42#define NOIT_CONTROL_POST   0x504f5354 /* "POST" */ 
     43#define NOIT_CONTROL_DELETE 0x44454c45 /* "DELE" */ 
    4344 
    4445typedef struct noit_http_rest_closure noit_http_rest_closure_t;