Changeset d9050a442ce49ffad4040ba933511197fe71390f
- Timestamp:
- 01/08/10 20:04:49
(3 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
| r4790fc8 |
rd9050a4 |
|
| 51 | 51 | static const char _hexchars[16] = |
|---|
| 52 | 52 | {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; |
|---|
| | 53 | static 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 | } |
|---|
| 53 | 74 | |
|---|
| 54 | 75 | struct bchain *bchain_alloc(size_t size) { |
|---|
| … | … | |
| 390 | 411 | return noit_true; |
|---|
| 391 | 412 | } |
|---|
| | 413 | void |
|---|
| | 414 | noit_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 | } |
|---|
| 392 | 436 | static noit_boolean |
|---|
| 393 | 437 | noit_http_request_finalize_payload(noit_http_request *req, noit_boolean *err) { |
|---|
| … | … | |
| 480 | 524 | void |
|---|
| 481 | 525 | noit_http_request_release(noit_http_session_ctx *ctx) { |
|---|
| | 526 | noit_hash_destroy(&ctx->req.querystring, NULL, NULL); |
|---|
| 482 | 527 | noit_hash_destroy(&ctx->req.headers, NULL, NULL); |
|---|
| 483 | 528 | /* If we expected a payload, we expect a trailing \r\n */ |
|---|
| r0256945 |
rd9050a4 |
|
| 90 | 90 | char *uri_str; |
|---|
| 91 | 91 | char *protocol_str; |
|---|
| | 92 | noit_hash_table querystring; |
|---|
| 92 | 93 | u_int32_t opts; |
|---|
| 93 | 94 | noit_http_method method; |
|---|
| … | … | |
| 133 | 134 | API_EXPORT(void) |
|---|
| 134 | 135 | noit_http_session_ctx_release(noit_http_session_ctx *); |
|---|
| | 136 | API_EXPORT(void) |
|---|
| | 137 | noit_http_process_querystring(noit_http_request *); |
|---|
| 135 | 138 | |
|---|
| 136 | 139 | API_EXPORT(int) |
|---|
| raaa42af |
rd9050a4 |
|
| 406 | 406 | } execute_outcome_t; |
|---|
| 407 | 407 | |
|---|
| 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 | | } |
|---|
| 419 | 408 | #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); \ |
|---|
| 421 | 410 | d->paramLengths[d->nparams] = len; \ |
|---|
| 422 | 411 | d->paramFormats[d->nparams] = 0; \ |
|---|
| r47a77d0 |
rd9050a4 |
|
| 36 | 36 | #include "utils/noit_hash.h" |
|---|
| 37 | 37 | #include "utils/noit_log.h" |
|---|
| | 38 | #include "utils/noit_str.h" |
|---|
| 38 | 39 | #include "jlog/jlog.h" |
|---|
| 39 | 40 | #include "noit_jlog_listener.h" |
|---|
| … | … | |
| 110 | 111 | char *scp, *ecp, *token; |
|---|
| 111 | 112 | 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"; |
|---|
| 112 | 128 | |
|---|
| 113 | 129 | #define BAIL_HTTP_WRITE do { \ |
|---|
| | 130 | noit_hash_destroy(&json, NULL, free); \ |
|---|
| 114 | 131 | noitL(noit_error, "javascript emit failed: %s:%s:%d\n", \ |
|---|
| 115 | 132 | __FILE__, __FUNCTION__, __LINE__); \ |
|---|
| … | … | |
| 138 | 155 | PROCESS_NEXT_FIELD(token,len); /* Skip the leader */ |
|---|
| 139 | 156 | 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 | } |
|---|
| 143 | 171 | /* Time */ |
|---|
| | 172 | noit_hash_store(&json, "type", 4, strdup("M")); |
|---|
| 144 | 173 | 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)); |
|---|
| 150 | 175 | /* UUID */ |
|---|
| 151 | 176 | 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)); |
|---|
| 157 | 178 | /* name */ |
|---|
| 158 | 179 | 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 */ |
|---|
| 165 | 185 | 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)); |
|---|
| 170 | 199 | |
|---|
| 171 | 200 | if(noit_http_response_flush(ctx, noit_false) == noit_false) BAIL_HTTP_WRITE; |
|---|
| 172 | 201 | } |
|---|
| 173 | 202 | |
|---|
| | 203 | noit_hash_destroy(&json, NULL, free); |
|---|
| 174 | 204 | return 0; |
|---|
| 175 | 205 | |
|---|
| 176 | 206 | bad_row: |
|---|
| 177 | 207 | 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 | | } |
|---|
| 184 | 208 | } |
|---|
| 185 | 209 | int |
|---|
| … | … | |
| 468 | 492 | noit_http_rest_closure_free(restc); |
|---|
| 469 | 493 | |
|---|
| | 494 | noit_http_process_querystring(&ctx->req); |
|---|
| 470 | 495 | /* Rewire the http context */ |
|---|
| 471 | 496 | ctx->conn.e->callback = stratcon_realtime_http_handler; |
|---|
| rb0c153f |
rd9050a4 |
|
| 69 | 69 | return NULL; |
|---|
| 70 | 70 | } |
|---|
| | 71 | |
|---|
| | 72 | char * |
|---|
| | 73 | noit__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 | |
|---|
| 71 | 84 | #endif |
|---|
| 72 | 85 | |
|---|
| rb0c153f |
rd9050a4 |
|
| 40 | 40 | #endif |
|---|
| 41 | 41 | |
|---|
| | 42 | API_EXPORT(char *) noit__strndup(const char *src, int len); |
|---|
| | 43 | |
|---|
| 42 | 44 | #endif |
|---|