Changeset 7f8de6fd1900ed5b0e0bb25a1bc167d8793fa2d7
- Timestamp:
- 09/16/09 14:59:30 (4 years ago)
- git-parent:
- Files:
-
- src/noit_check_rest.c (modified) (5 diffs)
- src/noit_rest.c (modified) (2 diffs)
- src/noit_rest.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/noit_check_rest.c
r25fec2c r7f8de6f 45 45 #include "noit_conf_private.h" 46 46 47 #define FAIL(a) do { error = (a); goto error; } while(0) 47 48 #define UUID_REGEX "[0-9a-fA-F]{4}(?:[0-9a-fA-F]{4}-){4}[0-9a-fA-F]{12}" 48 49 … … 381 382 } 382 383 static int 384 rest_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 448 static int 383 449 rest_set_check(noit_http_rest_closure_t *restc, 384 450 int npats, char **pats) { … … 397 463 398 464 if(npats != 2) goto error; 399 400 #define FAIL(a) do { error = (a); goto error; } while(0)401 465 402 466 if(restc->call_closure == NULL) { … … 476 540 xmlNodePtr a; 477 541 noit_check_t *ocheck; 542 478 543 cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); 479 544 if(cnt != 1) FAIL("internal error, |checkid| > 1"); … … 550 615 rest_set_check 551 616 ) == 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 223 223 primer = "HEAD"; 224 224 break; 225 case NOIT_CONTROL_DELETE: 226 primer = "DELE"; 227 break; 225 228 default: 226 229 goto socket_error; … … 242 245 NOIT_CONTROL_POST, 243 246 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 38 38 #define NOIT_REST_H 39 39 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" */ 43 44 44 45 typedef struct noit_http_rest_closure noit_http_rest_closure_t;
