Changeset d9050a442ce49ffad4040ba933511197fe71390f

Show
Ignore:
Timestamp:
01/08/10 20:04:49 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1262981089 +0000
git-parent:

[57156325b280cf0021706459de269ef44b89d8cc]

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

this will break realtime streaming.... need to fix the javascript in the web ui now, refs #229

Files:

Legend:

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

    r4790fc8 rd9050a4  
    5151static const char _hexchars[16] = 
    5252  {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; 
     53static void inplace_urldecode(char *c) { 
     54  char *o = c; 
     55  while(*c) { 
     56    if(*c == '%') { 
     57      int i, ord = 0; 
     58      for(i = 0; i < 2; i++) { 
     59        if(c[i] >= '0' && c[i] <= '9') ord = (ord << 4) | (c[i] - '0'); 
     60        else if (c[i] >= 'a' && c[i] <= 'f') ord = (ord << 4) | (c[i] - 'a'); 
     61        else if (c[i] >= 'A' && c[i] <= 'F') ord = (ord << 4) | (c[i] - 'A'); 
     62        else break; 
     63      } 
     64      if(i==2) { 
     65        *((unsigned char *)o++) = ord; 
     66        c+=3; 
     67        continue; 
     68      } 
     69    } 
     70    *o++ = *c++; 
     71  } 
     72  *o = '\0'; 
     73} 
    5374 
    5475struct bchain *bchain_alloc(size_t size) { 
     
    390411  return noit_true; 
    391412} 
     413void 
     414noit_http_process_querystring(noit_http_request *req) { 
     415  char *cp, *copy, *interest, *brk; 
     416  cp = strchr(req->uri_str, '?'); 
     417  if(!cp) return; 
     418  *cp++ = '\0'; 
     419  for (interest = strtok_r(cp, "&", &brk); 
     420       interest; 
     421       interest = strtok_r(NULL, "&", &brk)) { 
     422    char *eq; 
     423    eq = strchr(interest, '='); 
     424    if(!eq) { 
     425      inplace_urldecode(interest); 
     426      noit_hash_store(&req->querystring, interest, strlen(interest), NULL); 
     427    } 
     428    else { 
     429      *eq++ = '\0'; 
     430      inplace_urldecode(interest); 
     431      inplace_urldecode(eq); 
     432      noit_hash_store(&req->querystring, interest, strlen(interest), eq); 
     433    } 
     434  } 
     435} 
    392436static noit_boolean 
    393437noit_http_request_finalize_payload(noit_http_request *req, noit_boolean *err) { 
     
    480524void 
    481525noit_http_request_release(noit_http_session_ctx *ctx) { 
     526  noit_hash_destroy(&ctx->req.querystring, NULL, NULL); 
    482527  noit_hash_destroy(&ctx->req.headers, NULL, NULL); 
    483528  /* If we expected a payload, we expect a trailing \r\n */ 
  • src/noit_http.h

    r0256945 rd9050a4  
    9090  char *uri_str; 
    9191  char *protocol_str; 
     92  noit_hash_table querystring; 
    9293  u_int32_t opts; 
    9394  noit_http_method method; 
     
    133134API_EXPORT(void) 
    134135  noit_http_session_ctx_release(noit_http_session_ctx *); 
     136API_EXPORT(void) 
     137  noit_http_process_querystring(noit_http_request *); 
    135138 
    136139API_EXPORT(int) 
  • src/stratcon_datastore.c

    raaa42af rd9050a4  
    406406} execute_outcome_t; 
    407407 
    408 static char * 
    409 __noit__strndup(const char *src, int len) { 
    410   int slen; 
    411   char *dst; 
    412   for(slen = 0; slen < len; slen++) 
    413     if(src[slen] == '\0') break; 
    414   dst = malloc(slen + 1); 
    415   memcpy(dst, src, slen); 
    416   dst[slen] = '\0'; 
    417   return dst; 
    418 } 
    419408#define DECLARE_PARAM_STR(str, len) do { \ 
    420   d->paramValues[d->nparams] = __noit__strndup(str, len); \ 
     409  d->paramValues[d->nparams] = noit__strndup(str, len); \ 
    421410  d->paramLengths[d->nparams] = len; \ 
    422411  d->paramFormats[d->nparams] = 0; \ 
  • src/stratcon_realtime_http.c

    r47a77d0 rd9050a4  
    3636#include "utils/noit_hash.h" 
    3737#include "utils/noit_log.h" 
     38#include "utils/noit_str.h" 
    3839#include "jlog/jlog.h" 
    3940#include "noit_jlog_listener.h" 
     
    110111  char *scp, *ecp, *token; 
    111112  int len; 
     113  void *vcb; 
     114  const char *v, *cb = NULL; 
     115  noit_hash_table json = NOIT_HASH_EMPTY; 
     116 
     117  if(noit_hash_retrieve(&ctx->req.querystring, "cb", strlen("cb"), &vcb)) 
     118    cb = vcb; 
     119  for(v = cb; v && *v; v++) 
     120    if(!((*v >= '0' && *v <= '9') || 
     121         (*v >= 'a' && *v <= 'z') || 
     122         (*v >= 'A' && *v <= 'Z') || 
     123         (*v == '_'))) { 
     124      cb = NULL; 
     125      break; 
     126    } 
     127  if(!cb) cb = "window.parent.plot_iframe_data"; 
    112128 
    113129#define BAIL_HTTP_WRITE do { \ 
     130  noit_hash_destroy(&json, NULL, free); \ 
    114131  noitL(noit_error, "javascript emit failed: %s:%s:%d\n", \ 
    115132        __FILE__, __FUNCTION__, __LINE__); \ 
     
    138155  PROCESS_NEXT_FIELD(token,len); /* Skip the leader */ 
    139156  if(buff[0] == 'M') { 
    140     snprintf(buffer, sizeof(buffer), "<script>window.parent.plot_iframe_data('"); 
    141     if(noit_http_response_append(ctx, buffer, strlen(buffer)) == noit_false) BAIL_HTTP_WRITE; 
    142  
     157    noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 
     158    const char *key; 
     159    int klen, i=0; 
     160    void *vval; 
     161 
     162#define ra_write(a,b) if(noit_http_response_append(ctx, a, b) == noit_false) BAIL_HTTP_WRITE 
     163 
     164    snprintf(buffer, sizeof(buffer), "<script>%s({", cb); 
     165    ra_write(buffer, strlen(buffer)); 
     166 
     167    while(noit_hash_next(&ctx->req.querystring, &iter, &key, &klen, &vval)) { 
     168      if(!strcmp(key, "cb")) continue; 
     169      noit_hash_store(&json, key, klen, strdup(vval ?(char *)vval : "true")); 
     170    } 
    143171    /* Time */ 
     172    noit_hash_store(&json, "type", 4, strdup("M")); 
    144173    PROCESS_NEXT_FIELD(token,len); 
    145     if(noit_http_response_append(ctx, token, len) == noit_false) BAIL_HTTP_WRITE; 
    146  
    147     snprintf(buffer, sizeof(buffer), "', '"); 
    148     if(noit_http_response_append(ctx, buffer, strlen(buffer)) == noit_false) BAIL_HTTP_WRITE; 
    149  
     174    noit_hash_store(&json, "time", 4, noit__strndup(token, len)); 
    150175    /* UUID */ 
    151176    PROCESS_NEXT_FIELD(token,len); 
    152     if(noit_http_response_append(ctx, token, len) == noit_false) BAIL_HTTP_WRITE; 
    153  
    154     snprintf(buffer, sizeof(buffer), "', '"); 
    155     if(noit_http_response_append(ctx, buffer, strlen(buffer)) == noit_false) BAIL_HTTP_WRITE; 
    156  
     177    noit_hash_store(&json, "id", 2, noit__strndup(token, len)); 
    157178    /* name */ 
    158179    PROCESS_NEXT_FIELD(token,len); 
    159     if(noit_http_response_append(ctx, token, len) == noit_false) BAIL_HTTP_WRITE; 
    160  
    161     snprintf(buffer, sizeof(buffer), "', '"); 
    162     if(noit_http_response_append(ctx, buffer, strlen(buffer)) == noit_false) BAIL_HTTP_WRITE; 
    163  
    164     PROCESS_NEXT_FIELD(token,len); /* skip type */ 
     180    noit_hash_store(&json, "metric_name", 11, noit__strndup(token, len)); 
     181    /* type */ 
     182    PROCESS_NEXT_FIELD(token,len); 
     183    noit_hash_store(&json, "metric_type", 11, noit__strndup(token, len)); 
     184    /* value */ 
    165185    PROCESS_LAST_FIELD(token,len); /* value */ 
    166     if(noit_http_response_append(ctx, token, len) == noit_false) BAIL_HTTP_WRITE; 
    167  
    168     snprintf(buffer, sizeof(buffer), "');</script>\n"); 
    169     if(noit_http_response_append(ctx, buffer, strlen(buffer)) == noit_false) BAIL_HTTP_WRITE; 
     186    noit_hash_store(&json, "value", 5, noit__strndup(token, len)); 
     187 
     188    memset(&iter, 0, sizeof(iter)); 
     189    while(noit_hash_next(&json, &iter, &key, &klen, &vval)) { 
     190      if(i++) ra_write(",", 1); 
     191      ra_write("'", 1); 
     192      ra_write(key, klen); 
     193      ra_write("':'", 3); 
     194      ra_write((char *)vval, strlen((char *)vval)); 
     195      ra_write("'", 1); 
     196    } 
     197    snprintf(buffer, sizeof(buffer), "});</script>\n"); 
     198    ra_write(buffer, strlen(buffer)); 
    170199 
    171200    if(noit_http_response_flush(ctx, noit_false) == noit_false) BAIL_HTTP_WRITE; 
    172201  } 
    173202 
     203  noit_hash_destroy(&json, NULL, free); 
    174204  return 0; 
    175205 
    176206 bad_row: 
    177207  BAIL_HTTP_WRITE; 
    178   if(0) { 
    179     noit_http_response_end(ctx); 
    180     clear_realtime_context(ctx->dispatcher_closure); 
    181     if(ctx->conn.e) eventer_trigger(ctx->conn.e, EVENTER_WRITE); 
    182     return 0; 
    183   } 
    184208} 
    185209int 
     
    468492  noit_http_rest_closure_free(restc); 
    469493 
     494  noit_http_process_querystring(&ctx->req); 
    470495  /* Rewire the http context */ 
    471496  ctx->conn.e->callback = stratcon_realtime_http_handler; 
  • src/utils/noit_str.c

    rb0c153f rd9050a4  
    6969  return NULL; 
    7070} 
     71 
     72char * 
     73noit__strndup(const char *src, int len) { 
     74  int slen; 
     75  char *dst; 
     76  for(slen = 0; slen < len; slen++) 
     77    if(src[slen] == '\0') break; 
     78  dst = malloc(slen + 1); 
     79  memcpy(dst, src, slen); 
     80  dst[slen] = '\0'; 
     81  return dst; 
     82} 
     83 
    7184#endif 
    7285 
  • src/utils/noit_str.h

    rb0c153f rd9050a4  
    4040#endif 
    4141 
     42API_EXPORT(char *) noit__strndup(const char *src, int len); 
     43 
    4244#endif