| | 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 |
|---|