Changeset a0606963803036aef4ac06ee4058ec140ad0176c

Show
Ignore:
Timestamp:
10/02/09 14:20:47 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1254493247 +0000
git-parent:

[fc257c3a0ca0ba485d58c775959836e7fdc50721]

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

adding and removing noits to a stratcond via REST, refs #171

Files:

Legend:

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

    rfc257c3 ra060696  
    875875  xmlSetProp(newnoit, (xmlChar *)"port", (xmlChar *)port_str); 
    876876  xmlAddChild(parent, newnoit); 
    877   noit_conf_mark_changed(); 
    878877  stratcon_streamer_connection(NULL, target, 
    879878                               stratcon_jlog_recv_handler, 
     
    909908  } 
    910909  free(noit_configs); 
    911   noit_conf_mark_changed(); 
    912910 
    913911  pthread_mutex_lock(&noits_lock); 
     
    928926  free(ctx); 
    929927  return n; 
     928} 
     929static int 
     930rest_set_noit(noit_http_rest_closure_t *restc, 
     931              int npats, char **pats) { 
     932  noit_http_session_ctx *ctx = restc->http_ctx; 
     933  unsigned short port = 43191; 
     934  if(npats < 1 || npats > 2) 
     935    noit_http_response_server_error(ctx, "text/xml"); 
     936  if(npats == 2) port = atoi(pats[1]); 
     937  if(stratcon_add_noit(pats[0], port)) 
     938    noit_http_response_ok(ctx, "text/xml"); 
     939  else 
     940    noit_http_response_standard(ctx, 409, "EXISTS", "text/xml"); 
     941  if(noit_conf_write_file(NULL) != 0) 
     942    noitL(noit_error, "local config write failed\n"); 
     943  noit_conf_mark_changed(); 
     944  noit_http_response_end(ctx); 
     945  return 0; 
     946} 
     947static int 
     948rest_delete_noit(noit_http_rest_closure_t *restc, 
     949                 int npats, char **pats) { 
     950  noit_http_session_ctx *ctx = restc->http_ctx; 
     951  unsigned short port = 43191; 
     952  if(npats < 1 || npats > 2) 
     953    noit_http_response_server_error(ctx, "text/xml"); 
     954  if(npats == 2) port = atoi(pats[1]); 
     955  if(stratcon_remove_noit(pats[0], port)) 
     956    noit_http_response_ok(ctx, "text/xml"); 
     957  else 
     958    noit_http_response_not_found(ctx, "text/xml"); 
     959  if(noit_conf_write_file(NULL) != 0) 
     960    noitL(noit_error, "local config write failed\n"); 
     961  noit_conf_mark_changed(); 
     962  noit_http_response_end(ctx); 
     963  return 0; 
    930964} 
    931965static int 
     
    9851019    NCSCMD("noits", stratcon_console_show_noits, NULL, NULL, NULL)); 
    9861020} 
    987  
    9881021 
    9891022void 
     
    10041037             noit_http_rest_client_cert_auth 
    10051038  ) == 0); 
    1006 
    1007  
     1039  assert(noit_http_rest_register_auth( 
     1040    "PUT", "/noits/", "^set/([^/:]+)$", rest_set_noit, 
     1041             noit_http_rest_client_cert_auth 
     1042  ) == 0); 
     1043  assert(noit_http_rest_register_auth( 
     1044    "PUT", "/noits/", "^set/([^/:]+):(\\d+)$", rest_set_noit, 
     1045             noit_http_rest_client_cert_auth 
     1046  ) == 0); 
     1047  assert(noit_http_rest_register_auth( 
     1048    "DELETE", "/noits/", "^delete/([^/:]+)$", rest_delete_noit, 
     1049             noit_http_rest_client_cert_auth 
     1050  ) == 0); 
     1051  assert(noit_http_rest_register_auth( 
     1052    "DELETE", "/noits/", "^delete/([^/:]+):(\\d+)$", rest_delete_noit, 
     1053             noit_http_rest_client_cert_auth 
     1054  ) == 0); 
     1055
     1056