//handles /ai?... void handle_request_ai(struct evhttp_request *req, void *arg){ global_data * global = (global_data *) arg; global->stats.requests++; request_t * aireq = new request_t(); const char * ptr; struct evkeyvalq options; evhttp_parse_query(req->uri, &options); int depth = 2; Board board = Board(true); //start with an empty board, replacing it below if a one is supplied if((ptr = evhttp_find_header(&options, "l"))) depth = atoi(ptr); if(depth < 0) depth = 0; if(depth > 4) depth = 4; if((ptr = evhttp_find_header(&options, "m")) && strlen(ptr) == 36) board = Board(ptr); aireq->req = req; aireq->boardstart = board; aireq->player = new PlayerNegamax3(depth); global->request->push(aireq); evhttp_clear_headers(&options); }
static void filter_query_into(struct evbuffer *buf, const char *full_url) { struct evkeyvalq params; const char *val; /* FIXME: Remember that passthrough thing we do if * there's _any_ alt=... format specifier? Yeah, that one. * Great idea. Now we get to jump through hoops dropping it from * the next/previous links. * * Just go make passthrough an explicit url parameter, and teach * /list how to deal with alt=atom, so we don't have to do this. */ memset(¶ms, 0, sizeof(params)); if (evhttp_parse_query_str(full_url, ¶ms) == -1) { /* Bad idea, we're kind of committed to this :( */ return; } /* If we'd dig into the internals we could just iterate the parameters * and skip alt=... As it is, we'll just pick start-index and * max-results. Those are the only ones /list? will pass to Google * anyway */ if ((val = evhttp_find_header(¶ms, "start-index")) != NULL) { evbuffer_add_printf(buf, "start-index=%s&", val); } if ((val = evhttp_find_header(¶ms, "max-results")) != NULL) { evbuffer_add_printf(buf, "max-results=%s&", val); } evhttp_clear_headers(¶ms); }
void http_request_empty_done(struct evhttp_request *req, void *arg) { if (req->response_code != HTTP_OK) { fprintf(stderr, "FAILED\n"); exit(1); } if (evhttp_find_header(req->input_headers, "Date") == NULL) { fprintf(stderr, "FAILED\n"); exit(1); } if (evhttp_find_header(req->input_headers, "Content-Length") == NULL) { fprintf(stderr, "FAILED\n"); exit(1); } if (strcmp(evhttp_find_header(req->input_headers, "Content-Length"), "0")) { fprintf(stderr, "FAILED\n"); exit(1); } if (EVBUFFER_LENGTH(req->input_buffer) != 0) { fprintf(stderr, "FAILED\n"); exit(1); } test_ok = 1; event_loopexit(NULL); }
void web_pipeline_create(struct evhttp_request *req, void *arg) { moModule *module; struct evkeyvalq headers; const char *uri; uri = evhttp_request_uri(req); if ( uri == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "unable to retreive uri"); } evhttp_parse_query(uri, &headers); if ( evhttp_find_header(&headers, "objectname") == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "missing objectname"); } module = moFactory::getInstance()->create(evhttp_find_header(&headers, "objectname")); if ( module == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "invalid objectname"); } pipeline->addElement(module); evhttp_clear_headers(&headers); web_message(req, module->property("id").asString().c_str()); }
void http_basic_cb(struct evhttp_request *req, void *arg) { struct evbuffer *evb = evbuffer_new(); int empty = evhttp_find_header(req->input_headers, "Empty") != NULL; event_debug(("%s: called\n", __func__)); evbuffer_add_printf(evb, "This is funny"); /* For multi-line headers test */ { const char *multi = evhttp_find_header(req->input_headers,"X-multi"); if (multi) { if (strcmp("END", multi + strlen(multi) - 3) == 0) test_ok++; if (evhttp_find_header(req->input_headers, "X-Last")) test_ok++; } } /* injecting a bad content-length */ if (evhttp_find_header(req->input_headers, "X-Negative")) evhttp_add_header(req->output_headers, "Content-Length", "-100"); /* allow sending of an empty reply */ evhttp_send_reply(req, HTTP_OK, "Everything is fine", !empty ? evb : NULL); evbuffer_free(evb); }
/* Will always return -1 to make evhttp close the connection - we only need the http headers */ static int scan_icy_header_cb(struct evhttp_request *req, void *arg) { struct media_file_info *mfi; const char *ptr; mfi = (struct media_file_info *)arg; if ( (ptr = evhttp_find_header(req->input_headers, "icy-name")) ) { mfi->title = strdup(ptr); mfi->artist = strdup(ptr); DPRINTF(E_DBG, L_SCAN, "Found ICY metadata, name (title/artist) is %s\n", mfi->title); } if ( (ptr = evhttp_find_header(req->input_headers, "icy-description")) ) { mfi->album = strdup(ptr); DPRINTF(E_DBG, L_SCAN, "Found ICY metadata, description (album) is %s\n", mfi->album); } if ( (ptr = evhttp_find_header(req->input_headers, "icy-genre")) ) { mfi->genre = strdup(ptr); DPRINTF(E_DBG, L_SCAN, "Found ICY metadata, genre is %s\n", mfi->genre); } status = ICY_DONE; return -1; }
void web_pipeline_get(struct evhttp_request *req, void *arg) { moModule *module; struct evkeyvalq headers; const char *uri; uri = evhttp_request_uri(req); evhttp_parse_query(uri, &headers); if ( evhttp_find_header(&headers, "objectname") == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "missing objectname"); } if ( evhttp_find_header(&headers, "name") == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "missing name"); } module = module_search(evhttp_find_header(&headers, "objectname"), pipeline); if ( module == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "object not found"); } web_message(req, module->property(evhttp_find_header(&headers, "name")).asString().c_str()); evhttp_clear_headers(&headers); }
void get_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx) { const char *value, *name; char *uri, *json, *hash, *key; struct evkeyvalq args; struct json_object *jsobj, *jsobj2, *jsobj3; TCMAP *cols; if (rdb == NULL) { evhttp_send_error(req, 503, "database not connected"); return; } uri = evhttp_decode_uri(req->uri); evhttp_parse_query(uri, &args); free(uri); hash = (char *)evhttp_find_header(&args, "hash"); key = (char *)evhttp_find_header(&args, "key"); if (hash == NULL) { evhttp_send_error(req, 400, "hash is required"); evhttp_clear_headers(&args); return; } jsobj = json_object_new_object(); jsobj2 = json_object_new_object(); cols = tcrdbtblget(rdb, hash, sizeof(hash)); if (cols) { tcmapiterinit(cols); jsobj3 = json_object_new_object(); if (key) { value = tcmapget2(cols, key); if (!value) { value = ""; } json_object_object_add(jsobj2, key, json_object_new_string(value)); } else { while ((name = tcmapiternext2(cols)) != NULL) { json_object_object_add(jsobj2, name, json_object_new_string(tcmapget2(cols, name))); } } json_object_object_add(jsobj, "status", json_object_new_string("ok")); json_object_object_add(jsobj, "results", jsobj2); tcmapdel(cols); } else { json_object_object_add(jsobj, "status", json_object_new_string("error")); } finalize_json(req, evb, &args, jsobj); }
void web_pipeline_remove(struct evhttp_request *req, void *arg) { moModule *module; moDataStream *ds; struct evkeyvalq headers; const char *uri; uri = evhttp_request_uri(req); if ( uri == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "unable to retreive uri"); } evhttp_parse_query(uri, &headers); if ( evhttp_find_header(&headers, "objectname") == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "missing objectname"); } module = pipeline->getModuleById(evhttp_find_header(&headers, "objectname")); if ( module == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "object not found"); } pipeline->stop(); module->stop(); // disconnect inputs if ( module->getInputCount() ) { for ( int i = 0; i < module->getInputCount(); i++ ) { ds = module->getInput(i); if ( ds == NULL ) continue; ds->removeObserver(module); } } // disconnect output if ( module->getOutputCount() ) { for ( int i = 0; i < module->getOutputCount(); i++ ) { ds = module->getOutput(i); if ( ds == NULL ) continue; ds->removeObservers(); } } // remove element from pipeline pipeline->removeElement(module); delete module; web_message(req, "ok"); evhttp_clear_headers(&headers); }
int get_int(const char *name, int def){ if(_has_post){ const char *val = evhttp_find_header(&_post, name); if(val){ return atoi(val); } } const char *val = evhttp_find_header(&_get, name); return val? atoi(val) : def; }
const char* get_str(const char *name, const char *def){ if(_has_post){ const char *val = evhttp_find_header(&_post, name); if(val){ return val; } } const char *val = evhttp_find_header(&_get, name); return val? val : def; }
void put_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx) { char *uri, *id, *data, *json, *key, *value; double lat, lng; int x, y; char buf[16]; struct evkeyvalq args; struct json_object *jsobj; TCMAP *cols; if (rdb == NULL) { evhttp_send_error(req, 503, "database not connected"); return; } uri = evhttp_decode_uri(req->uri); evhttp_parse_query(uri, &args); free(uri); argtof(&args, "lat", &lat, 0); argtof(&args, "lng", &lng, 0); id = (char *)evhttp_find_header(&args, "id"); data = (char *)evhttp_find_header(&args, "data"); if (id == NULL) { evhttp_send_error(req, 400, "id is required"); evhttp_clear_headers(&args); return; } x = (lat * 10000) + 1800000; y = (lng * 10000) + 1800000; cols = tcmapnew(); tcmapput2(cols, "data", data); sprintf(buf, "%d", x); tcmapput2(cols, "x", buf); sprintf(buf, "%d", y); tcmapput2(cols, "y", buf); sprintf(buf, "%f", lat); tcmapput2(cols, "lat", buf); sprintf(buf, "%f", lng); tcmapput2(cols, "lng", buf); jsobj = json_object_new_object(); if (tcrdbtblput(rdb, id, strlen(id), cols)) { json_object_object_add(jsobj, "status", json_object_new_string("ok")); } else { db_status = tcrdbecode(rdb); db_error_to_json(db_status, jsobj); } tcmapdel(cols); finalize_json(req, evb, &args, jsobj); }
void upnpc_event_conn_req(struct evhttp_request * req, void * data) { size_t len; char * xml_data; struct evbuffer * input_buffer; struct evkeyvalq * headers; const char * sid; const char * nts; const char * nt; const char * seq; struct NameValueParserData parsed_data; struct NameValue * nv; upnpc_device_t * d = (upnpc_device_t *)data; debug_printf("%s(%p, %p)\n", __func__, req, d); headers = evhttp_request_get_input_headers(req); input_buffer = evhttp_request_get_input_buffer(req); len = evbuffer_get_length(input_buffer); sid = evhttp_find_header(headers, "sid"); nts = evhttp_find_header(headers, "nts"); nt = evhttp_find_header(headers, "nt"); seq = evhttp_find_header(headers, "seq"); if(len == 0 || nts == NULL || nt == NULL) { /* 400 Bad request : * The NT or NTS header field is missing * or the request is malformed. */ evhttp_send_reply(req, 400, "Bad Request", NULL); return; } debug_printf("SID=%s NTS=%s SEQ=%s\n", sid, nts, seq); if(sid == NULL || 0 != strcmp(sid, d->event_conn_sid) || 0 != strcmp(nt, "upnp:event") || 0 != strcmp(nts, "upnp:propchange")) { /* 412 Precondition Failed : * An SID does not correspond to a known, un-expired subscription * or the NT header field does not equal upnp:event * or the NTS header field does not equal upnp:propchange * or the SID header field is missing or empty. */ evhttp_send_reply(req, 412, "Precondition Failed", NULL); return; } xml_data = (char *)evbuffer_pullup(input_buffer, len); /*debug_printf("%.*s\n", len, xml_data);*/ ParseNameValue(xml_data, len, &parsed_data); for(nv = parsed_data.l_head; nv != NULL; nv = nv->l_next) { if(d->parent->value_changed_cb) { d->parent->value_changed_cb(d->parent, d, d->parent->cb_data, d->conn_service_type, nv->name, nv->value); } else { debug_printf("%s=%s\n", nv->name, nv->value); } } ClearNameValueList(&parsed_data); /* response : 200 OK */ evhttp_send_reply(req, 200, "OK", NULL); }
/** Return true if the list of headers in 'headers', intepreted with respect * to flags, means that we should send a "connection: close" when the request * is done. */ static int evhttp_is_connection_close(int flags, struct evkeyvalq* headers) { if (flags & EVHTTP_PROXY_REQUEST) { /* proxy connection */ const char *connection = evhttp_find_header(headers, "Proxy-Connection"); return (connection == NULL || evutil_ascii_strcasecmp(connection, "keep-alive") != 0); } else { const char *connection = evhttp_find_header(headers, "Connection"); return (connection != NULL && evutil_ascii_strcasecmp(connection, "close") == 0); } }
void web_pipeline_connect(struct evhttp_request *req, void *arg) { moModule *in, *out; int inidx = 0, outidx = 0; struct evkeyvalq headers; const char *uri; uri = evhttp_request_uri(req); if ( uri == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "unable to retreive uri"); } evhttp_parse_query(uri, &headers); if ( evhttp_find_header(&headers, "out") == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "missing out"); } if ( evhttp_find_header(&headers, "in") == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "missing in"); } if ( evhttp_find_header(&headers, "outidx") != NULL ) outidx = atoi(evhttp_find_header(&headers, "outidx")); if ( evhttp_find_header(&headers, "inidx") != NULL ) inidx = atoi(evhttp_find_header(&headers, "inidx")); in = pipeline->getModuleById(evhttp_find_header(&headers, "in")); out = pipeline->getModuleById(evhttp_find_header(&headers, "out")); if ( in == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "in object not found"); } if ( out == NULL && strcmp(evhttp_find_header(&headers, "out"), "NULL") != 0 ) { evhttp_clear_headers(&headers); return web_error(req, "out object not found"); } if ( strcmp(evhttp_find_header(&headers, "out"), "NULL") == 0 ) in->setInput(NULL, inidx); else in->setInput(out->getOutput(outidx), inidx); evhttp_clear_headers(&headers); web_message(req, "ok"); }
static void put_playlist_remove_tracks(sp_playlist *playlist, struct evhttp_request *request, void *userdata) { // sp_session *session = userdata; const char *uri = evhttp_request_get_uri(request); struct evkeyvalq query_fields; evhttp_parse_query(uri, &query_fields); // Parse index const char *index_field = evhttp_find_header(&query_fields, "index"); int index; if (index_field == NULL || sscanf(index_field, "%d", &index) <= 0 || index < 0) { send_error(request, HTTP_BADREQUEST, "Bad parameter: index must be numeric"); return; } const char *count_field = evhttp_find_header(&query_fields, "count"); int count; if (count_field == NULL || sscanf(count_field, "%d", &count) <= 0 || count < 1) { send_error(request, HTTP_BADREQUEST, "Bad parameter: count must be numeric and positive"); return; } int *tracks = calloc(count, sizeof(int)); for (int i = 0; i < count; i++) tracks[i] = index + i; struct playlist_handler *handler = register_playlist_callbacks( playlist, request, &get_playlist, &playlist_update_in_progress_callbacks, NULL); sp_error remove_tracks_error = sp_playlist_remove_tracks(playlist, tracks, count); if (remove_tracks_error != SP_ERROR_OK) { sp_playlist_remove_callbacks(playlist, handler->playlist_callbacks, handler); free(handler); send_error_sp(request, HTTP_BADREQUEST, remove_tracks_error); } free(tracks); }
static void httpd_handler(struct evhttp_request *req, void *arg) { struct evbuffer *buf; buf = evbuffer_new(); //get http request url char *decode_uri = strdup((char*) evhttp_request_uri(req)); struct evkeyvalq httpd_query; evhttp_parse_query(decode_uri, &httpd_query); free(decode_uri); //recive http params const char *start = evhttp_find_header(&httpd_query, "start"); const char *httpd_charset = evhttp_find_header(&httpd_query, "charset"); //send http header charset if (httpd_charset != NULL && strlen(httpd_charset) <= 40) { char content_type[64] = { 0 }; sprintf(content_type, "text/plain; charset=%s", httpd_charset); evhttp_add_header(req->output_headers, "Content-Type", content_type); } else { evhttp_add_header(req->output_headers, "Content-Type", "text/plain"); } evhttp_add_header(req->output_headers, "Connection", "keep-alive"); evhttp_add_header(req->output_headers, "Cache-Control", "no-cache"); evbuffer_add_printf(buf, "%s\n", "HTTRACK_OK"); char start_t[255] = {0x00}; sprintf(start_t, "%s", start); if (strcmp(start_t, "1") == 0) { struct hts_proj proj; proj.depth = 5; proj.priority = PRIORITY_ONLY_HTML; proj.action = ACTION_ONLY_FILES; sprintf(proj.name, "%s", "dianying.yisou.com"); sprintf(proj.urls, "%s", "http://dianying.yisou.com/"); new_dl_thread(); } //send content to client evhttp_send_reply(req, HTTP_OK, "OK", buf); //free buf evhttp_clear_headers(&httpd_query); evbuffer_free(buf); }
static int get_query_params(struct evhttp_request *req, struct evkeyvalq *query, struct query_params *qp) { const char *param; int ret; qp->offset = 0; param = evhttp_find_header(query, "offset"); if (param) { ret = safe_atoi32(param, &qp->offset); if (ret < 0) { rsp_send_error(req, "Invalid offset"); return -1; } } qp->limit = 0; param = evhttp_find_header(query, "limit"); if (param) { ret = safe_atoi32(param, &qp->limit); if (ret < 0) { rsp_send_error(req, "Invalid limit"); return -1; } } if (qp->offset || qp->limit) qp->idx_type = I_SUB; else qp->idx_type = I_NONE; qp->sort = S_NONE; param = evhttp_find_header(query, "query"); if (param) { DPRINTF(E_DBG, L_RSP, "RSP browse query filter: %s\n", param); qp->filter = rsp_query_parse_sql(param); if (!qp->filter) DPRINTF(E_LOG, L_RSP, "Ignoring improper RSP query\n"); } return 0; }
void LibEventTransport::sendImpl(const void *data, int size, int code, bool chunked) { assert(data); assert(!m_sendEnded); assert(!m_sendStarted || chunked); if (chunked) { assert(m_method != HEAD); evbuffer *chunk = evbuffer_new(); evbuffer_add(chunk, data, size); /* * Chunked replies are sent async, so there is no way to know the * time it took to flush the response, but tracking the bytes sent is * very useful. */ onChunkedProgress(size); m_server->onChunkedResponse(m_workerId, m_request, code, chunk, !m_sendStarted); } else { if (m_method != HEAD) { evbuffer_add(m_request->output_buffer, data, size); } else if (!evhttp_find_header(m_request->output_headers, "Content-Length")) { char buf[11]; snprintf(buf, sizeof(buf), "%d", size); addHeaderImpl("Content-Length", buf); } m_server->onResponse(m_workerId, m_request, code, this); m_sendEnded = true; } m_sendStarted = true; }
int source_callback_helper(struct evhttp_request *req, void *arg){ if ((size_t)BOUNDARY_LENGTH > EVBUFFER_LENGTH(req->input_buffer)){ return 0; } if (DEBUG) fprintf(stdout, "source_callback\n"); // enum message_read_status done; evhttp_clear_headers(req->input_headers); evhttp_parse_headers(req, req->input_buffer); char *content_len; content_len = (char *) evhttp_find_header(req->input_headers, "Content-Length"); if (!content_len){return 0; // drain buffer? // exit? } int len = atoi(content_len); size_t len_size; len_size = (size_t)len; if (DEBUG) fprintf(stdout, "received content_length:%d buffer has:%d\n", (int)len, (int)EVBUFFER_LENGTH(req->input_buffer)); struct global_data *client_data = (struct global_data *)arg; char *data = calloc(len, sizeof(char *)); evbuffer_remove(req->input_buffer, data, len); if (DEBUG)fprintf(stdout, "data has %d bytes\n", (int)strlen(data)); if (DEBUG)fprintf(stdout, "data=%s\n", data); (*client_data->cb)(data, client_data->cbarg); free(data); // empty buffer // -- if ((size_t)BOUNDARY_LENGTH <= EVBUFFER_LENGTH(req->input_buffer) ){ evbuffer_drain(req->input_buffer, (size_t)BOUNDARY_LENGTH); } return 1; }
void http_postrequest_done(struct evhttp_request *req, void *arg) { const char *what = "This is funny"; if (req == NULL) { fprintf(stderr, "FAILED (timeout)\n"); exit(1); } if (req->response_code != HTTP_OK) { fprintf(stderr, "FAILED (response code)\n"); exit(1); } if (evhttp_find_header(req->input_headers, "Content-Type") == NULL) { fprintf(stderr, "FAILED (content type)\n"); exit(1); } if (EVBUFFER_LENGTH(req->input_buffer) != strlen(what)) { fprintf(stderr, "FAILED (length %zu vs %zu)\n", EVBUFFER_LENGTH(req->input_buffer), strlen(what)); exit(1); } if (memcmp(EVBUFFER_DATA(req->input_buffer), what, strlen(what)) != 0) { fprintf(stderr, "FAILED (data)\n"); exit(1); } test_ok = 1; event_loopexit(NULL); }
/* Callback used for the /dump URI, and for every non-GET request: * dumps all information to stdout and gives back a trivial 200 ok */ static void fetch_request_cb(struct evhttp_request *req, void *arg) { struct evkeyvalq args; const char *uri = evhttp_request_get_uri(req); evhttp_parse_query(uri, &args); char* url = (char *)evhttp_find_header(&args, "url"); struct evbuffer *evb = NULL; if (url && strlen(url) > 0) { CURL *curl; CURLcode res; curl = curl_easy_init(); if (curl) { evb = evbuffer_new(); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, evb); res = curl_easy_perform(curl); curl_easy_cleanup(curl); // this should probably use the curlcode status evhttp_send_reply(req, 200, "OK", evb); evbuffer_free(evb); } } else { evhttp_send_reply(req, 500, "MEH", NULL); } }
/* Return true iff 'headers' contains 'Connection: keep-alive' */ static int evhttp_is_connection_keepalive(struct evkeyvalq* headers) { const char *connection = evhttp_find_header(headers, "Connection"); return (connection != NULL && evutil_ascii_strncasecmp(connection, "keep-alive", 10) == 0); }
/** * * @param *request the opaque data structure containing the request infos * @param *privParams global parameters set when the callback was associated * @return nothing */ void testing (struct evhttp_request *request, void *privParams) { struct evbuffer *buffer; struct evkeyvalq headers; const char *q; // Parse the query for later lookups evhttp_parse_query (evhttp_request_get_uri (request), &headers); // lookup the 'q' GET parameter q = evhttp_find_header (&headers, "q"); // Create an answer buffer where the data to send back to the browser will be appened buffer = evbuffer_new (); evbuffer_add (buffer, "coucou !", 8); evbuffer_add_printf (buffer, "%s", q); // Add a HTTP header, an application/json for the content type here evhttp_add_header (evhttp_request_get_output_headers (request), "Content-Type", "text/plain"); // Tell we're done and data should be sent back evhttp_send_reply(request, HTTP_OK, "OK", buffer); // Free up stuff evhttp_clear_headers (&headers); evbuffer_free (buffer); return; }
static struct metric_history * http_find_metrics_from_query(struct metrics *m, const char *query) { struct metric_history *mh = NULL; struct evkeyvalq params; const char *metric_name; if (query) { memset(¶ms, 0, sizeof(params)); if (evhttp_parse_query_str(query, ¶ms) == 0) { metric_name = evhttp_find_header(¶ms,"series"); if (metric_name != NULL) { printf("query is for %s\n", metric_name); mh = metrics_find_metric(m,metric_name); } } evhttp_clear_headers(¶ms); } return mh; }
static void http_set_headers(struct evhttp_request *req, struct server_socket *sock, bool longpoll) { evhttp_clear_headers(req->output_headers); /* Add header to debug load balancing */ if (srv.ourhost) evhttp_add_header(req->output_headers, "X-Server", srv.ourhost); /* copy X-Forwarded-For header to remote_host, if a trusted proxy provides it */ if (sock->cfg->proxy && !strcmp(req->remote_host, sock->cfg->proxy)) { const char *hdr; hdr = evhttp_find_header(req->input_headers, "X-Forwarded-For"); if (hdr) { free(req->remote_host); req->remote_host = strdup(hdr); } } evhttp_add_header(req->output_headers, "Content-Type", "application/json"); if (!longpoll && !srv.disable_lp) evhttp_add_header(req->output_headers, "X-Long-Polling", "/LP"); if (!srv.disable_roll_ntime) evhttp_add_header(req->output_headers, "X-Roll-NTime", "Y"); }
static void upnpc_subscribe_response(struct evhttp_request * req, void * pvoid) { size_t len; unsigned char * data; struct evbuffer * input_buffer; upnpc_device_t * d = (upnpc_device_t *)pvoid; if(req == NULL) { debug_printf("%s(%p, %p) NULL argument !\n", __func__, req, pvoid); return; } input_buffer = evhttp_request_get_input_buffer(req); len = evbuffer_get_length(input_buffer); data = evbuffer_pullup(input_buffer, len); debug_printf("%s %d (%d bytes)\n", __func__, evhttp_request_get_response_code(req), (int)len); d->state &= ~UPNPC_DEVICE_SOAP_REQ; if(evhttp_request_get_response_code(req) != HTTP_OK) { /* TODO ERROR */ } else { const char * sid; struct evkeyvalq * headers = evhttp_request_get_input_headers(req); sid = evhttp_find_header(headers, "sid"); debug_printf("SID=%s\n", sid); if(sid) { if(d->event_conn_sid) free(d->event_conn_sid); d->event_conn_sid = strdup(sid); } } }
static void http_chunked_request_done(struct evhttp_request *req, void *arg) { if (req->response_code != HTTP_OK) { fprintf(stderr, "FAILED\n"); exit(1); } if (evhttp_find_header(req->input_headers, "Transfer-Encoding") == NULL) { fprintf(stderr, "FAILED\n"); exit(1); } if (EVBUFFER_LENGTH(req->input_buffer) != 13 + 18 + 8) { fprintf(stderr, "FAILED\n"); exit(1); } if (strncmp((char *)EVBUFFER_DATA(req->input_buffer), "This is funnybut not hilarious.bwv 1052", 13 + 18 + 8)) { fprintf(stderr, "FAILED\n"); exit(1); } test_ok = 1; event_loopexit(NULL); }
static void http_readcb(struct bufferevent *bev, void *arg) { const char *what = "This is funny"; event_debug(("%s: %s\n", __func__, EVBUFFER_DATA(bev->input))); if (evbuffer_find(bev->input, (const unsigned char*) what, strlen(what)) != NULL) { struct evhttp_request *req = evhttp_request_new(NULL, NULL); enum message_read_status done; req->kind = EVHTTP_RESPONSE; done = evhttp_parse_firstline(req, bev->input); if (done != ALL_DATA_READ) goto out; done = evhttp_parse_headers(req, bev->input); if (done != ALL_DATA_READ) goto out; if (done == 1 && evhttp_find_header(req->input_headers, "Content-Type") != NULL) test_ok++; out: evhttp_request_free(req); bufferevent_disable(bev, EV_READ); if (base) event_base_loopexit(base, NULL); else event_loopexit(NULL); } }
void del_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx) { char *uri, *json, *id; struct evkeyvalq args; struct json_object *jsobj; if (rdb == NULL) { evhttp_send_error(req, 503, "database not connected"); return; } uri = evhttp_decode_uri(req->uri); evhttp_parse_query(uri, &args); free(uri); id = (char *)evhttp_find_header(&args, "id"); if (id == NULL) { evhttp_send_error(req, 400, "id is required"); evhttp_clear_headers(&args); return; } jsobj = json_object_new_object(); if (tcrdbtblout(rdb, id, sizeof(id))) { json_object_object_add(jsobj, "status", json_object_new_string("ok")); } else { db_status = tcrdbecode(rdb); db_error_to_json(db_status, jsobj); } finalize_json(req, evb, &args, jsobj); }