void spdy_cb_on_ctrl_recv(spdylay_session *session, spdylay_frame_type type, spdylay_frame *frame, void *user_data) { (void)user_data; char **nv; int32_t stream_id; struct Proxy * proxy; switch(type) { case SPDYLAY_SYN_REPLY: nv = frame->syn_reply.nv; stream_id = frame->syn_reply.stream_id; break; case SPDYLAY_RST_STREAM: stream_id = frame->rst_stream.stream_id; break; case SPDYLAY_HEADERS: nv = frame->headers.nv; stream_id = frame->headers.stream_id; break; default: return; break; } proxy = spdylay_session_get_stream_user_data(session, stream_id); if(NULL == proxy) { PRINT_INFO2("received frame type %i for unkonwn stream id %i", type, stream_id); return; //DIE("no proxy obj"); } switch(type) { case SPDYLAY_SYN_REPLY: PRINT_INFO2("received headers for %s", proxy->url); http_create_response(proxy, nv); break; case SPDYLAY_RST_STREAM: PRINT_INFO2("received reset stream for %s", proxy->url); proxy->spdy_error = true; break; case SPDYLAY_HEADERS: PRINT_INFO2("received headers for %s", proxy->url); http_create_response(proxy, nv); break; default: return; break; } glob_opt.spdy_data_received = true; }
void http_command(struct http_channel *c) { const char *command = http_argbyname(c->request, "command"); struct http_response *rs = http_create_response(c); int i; c->response = rs; http_addheader(rs, "Expires", "Thu, 19 Nov 1981 08:52:00 GMT"); http_addheader(rs, "Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); if (!command) { error(rs, PAZPAR2_MISSING_PARAMETER, "command"); return; } for (i = 0; commands[i].name; i++) if (!strcmp(commands[i].name, command)) { (*commands[i].fun)(c); break; } if (!commands[i].name) error(rs, PAZPAR2_MALFORMED_PARAMETER_VALUE, "command"); return; }
struct http_response *http_parse_response_buf(struct http_channel *c, const char *buf, int len) { char tmp[MAX_HTTP_HEADER]; struct http_response *r = http_create_response(c); char *p, *p2; struct http_header **hp = &r->headers; if (len >= MAX_HTTP_HEADER) return 0; memcpy(tmp, buf, len); for (p = tmp; *p && *p != ' '; p++) // Skip HTTP version ; p++; // Response code for (p2 = p; *p2 && *p2 != ' ' && p2 - p < 3; p2++) r->code[p2 - p] = *p2; if (!(p = strstr(tmp, "\r\n"))) return 0; p += 2; while (*p) { if (!(p2 = strstr(p, "\r\n"))) return 0; if (p == p2) // End of headers break; else { struct http_header *h = *hp = nmem_malloc(c->nmem, sizeof(*h)); char *value = strchr(p, ':'); if (!value) return 0; *(value++) = '\0'; h->name = nmem_strdup(c->nmem, p); while (isspace(*(const unsigned char *) value)) value++; if (value >= p2) // Empty header; { h->value = ""; p = p2 + 2; continue; } *p2 = '\0'; h->value = nmem_strdup(c->nmem, value); h->next = 0; hp = &h->next; p = p2 + 2; } } return r; }
static void http_error(struct http_channel *hc, int no, const char *msg) { struct http_response *rs = http_create_response(hc); hc->response = rs; hc->keep_alive = 0; // not keeping this HTTP session alive sprintf(rs->code, "%d", no); rs->msg = nmem_strdup(hc->nmem, msg); rs->payload = nmem_malloc(hc->nmem, 100); yaz_snprintf(rs->payload, 99, "<error>HTTP Error %d: %s</error>\n", no, msg); http_send_response(hc); }