/**@ingroup thttp_message_group */ int thttp_message_add_header(thttp_message_t *self, const thttp_header_t *hdr) { #define ADD_HEADER(type, field) \ case thttp_htype_##type: \ { \ if(!self->field) \ { \ self->field = (thttp_header_##type##_t*)header; \ return 0; \ } \ break; \ } if(self && hdr) { thttp_header_t *header = tsk_object_ref((void*)hdr); switch(header->type) { ADD_HEADER(Content_Type, Content_Type); ADD_HEADER(Content_Length, Content_Length); default: break; } tsk_list_push_back_data(self->headers, (void**)&header); return 0; } return -1; }
void SystemsSettingsEditor::InitializeProperties() { QtPropertyItem *header = NULL; ADD_HEADER("Collision system settings:"); collisionSysDrawStateMap[ST_COLL_DRAW_NOTHING_NAME] = std::make_pair<DAVA::uint32,bool>(ST_COLL_DRAW_NOTHING, false); collisionSysDrawStateMap[ST_COLL_DRAW_OBJECTS_NAME] = std::make_pair<DAVA::uint32,bool>(ST_COLL_DRAW_OBJECTS, false); collisionSysDrawStateMap[ST_COLL_DRAW_OBJECTS_SELECTED_NAME]= std::make_pair<DAVA::uint32,bool>(ST_COLL_DRAW_OBJECTS_SELECTED, false); collisionSysDrawStateMap[ST_COLL_DRAW_OBJECTS_RAYTEST_NAME] = std::make_pair<DAVA::uint32,bool>(ST_COLL_DRAW_OBJECTS_RAYTEST, false); collisionSysDrawStateMap[ST_COLL_DRAW_LAND_NAME] = std::make_pair<DAVA::uint32,bool>(ST_COLL_DRAW_LAND, false); collisionSysDrawStateMap[ST_COLL_DRAW_LAND_RAYTEST_NAME] = std::make_pair<DAVA::uint32,bool>(ST_COLL_DRAW_LAND_RAYTEST, false); collisionSysDrawStateMap[ST_COLL_DRAW_LAND_COLLISION_NAME] = std::make_pair<DAVA::uint32,bool>(ST_COLL_DRAW_LAND_COLLISION, false); collisionSysDrawStateMap[ST_COLL_DRAW_ALL_NAME] = std::make_pair<DAVA::uint32,bool>(ST_COLL_DRAW_ALL, false); int debugDrawFlags = sceneEditor->collisionSystem->GetDebugDrawFlags(); InitMapWithFlag(&collisionSysDrawStateMap, debugDrawFlags); INIT_PROPERTY_WITH_BTN(collSysDrawMode, collSysDrawModeBtn, debugDrawFlags, "Collision draw mode", HandleCollisionDrawMode(QtPropertyData::ValueChangeReason),collisionSysDrawStateMap); ADD_HEADER("Selection system settings:"); selectionSysDrawStateMap[ST_SELDRAW_NOTHING_NAME] = std::make_pair<DAVA::uint32,bool>(ST_SELDRAW_NOTHING, false); selectionSysDrawStateMap[ST_SELDRAW_DRAW_SHAPE_NAME] = std::make_pair<DAVA::uint32,bool>(ST_SELDRAW_DRAW_SHAPE, false); selectionSysDrawStateMap[ST_SELDRAW_DRAW_CORNERS_NAME] = std::make_pair<DAVA::uint32,bool>(ST_SELDRAW_DRAW_CORNERS, false); selectionSysDrawStateMap[ST_SELDRAW_FILL_SHAPE_NAME] = std::make_pair<DAVA::uint32,bool>(ST_SELDRAW_FILL_SHAPE, false); selectionSysDrawStateMap[ST_SELDRAW_NO_DEEP_TEST_NAME] = std::make_pair<DAVA::uint32,bool>(ST_SELDRAW_NO_DEEP_TEST, false); selectionSysDrawStateMap[ST_SELDRAW_ALL_NAME] = std::make_pair<DAVA::uint32,bool>(ST_SELDRAW_ALL, false); InitMapWithFlag(&selectionSysDrawStateMap, sceneEditor->selectionSystem->GetDrawMode()); INIT_PROPERTY_WITH_BTN(selectionDrawMode, selectionDrawModeBtn, sceneEditor->selectionSystem->GetDrawMode(), "Draw mode", HandleSelectionDrawMode(QtPropertyData::ValueChangeReason),selectionSysDrawStateMap); ADD_HEADER("Grid system settings:"); INIT_PROPERTY(gridMax, sceneEditor->gridSystem->GetGridMax(), "Grid Max", HandleGridMax(QtPropertyData::ValueChangeReason)); INIT_PROPERTY(gridStep, sceneEditor->gridSystem->GetGridStep(), "Grid Step", HandleGridStep(QtPropertyData::ValueChangeReason)); }
static string createRequestHeaders(const char *uri = "/foo/new") { string headers; #define ADD_HEADER(name, value) \ headers.append(name); \ headers.append(1, '\0'); \ headers.append(value); \ headers.append(1, '\0') ADD_HEADER("HTTP_HOST", "www.test.com"); ADD_HEADER("QUERY_STRING", ""); ADD_HEADER("REQUEST_URI", uri); ADD_HEADER("REQUEST_METHOD", "GET"); ADD_HEADER("REMOTE_ADDR", "localhost"); return headers; }
void optionally_add_header(HMAC_CTX *ctx, struct http_txn *txn, const char* header_name, int header_len) { struct hdr_ctx hdr_ctx = {.idx = 0}; char *begin = NULL; char *end = NULL; if(http_find_header2(header_name, header_len, txn->req.sol, &txn->hdr_idx, &hdr_ctx)) { begin = hdr_ctx.line + hdr_ctx.val; end = begin + hdr_ctx.vlen; } // For Date, haproxy does a silly thing where it considers the ',' to be a field separator while(http_find_header2(header_name, header_len, txn->req.sol, &txn->hdr_idx, &hdr_ctx)) { end = hdr_ctx.line + hdr_ctx.val + hdr_ctx.vlen; } if(begin) { HMAC_Update(ctx, (unsigned char*)begin, end - begin); } HMAC_Update(ctx, (unsigned const char*)"\n", 1); } void make_aws_signature(char *retval, const char *key, int key_len, struct http_txn *txn) { struct http_msg *msg = &txn->req; static int loaded_engines = 0; if(!loaded_engines) { ENGINE_load_builtin_engines(); ENGINE_register_all_complete(); loaded_engines = 1; } static unsigned char raw_sig[SIG_SIZE]; HMAC_CTX ctx; HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, key, key_len, EVP_sha1(), NULL); HMAC_Update(&ctx, (unsigned char*)msg->sol + msg->som, msg->sl.rq.m_l); HMAC_Update(&ctx, (unsigned const char*)"\n", 1); ADD_HEADER(&ctx, txn, "Content-MD5"); ADD_HEADER(&ctx, txn, "Content-Type"); ADD_HEADER(&ctx, txn, "Date"); void *header_sorter = HeaderSorter_new("x-amz-"); for_each_header(txn, header_sorter, &HeaderSorter_add); HeaderSorter_update(header_sorter, &ctx); HeaderSorter_delete(header_sorter); header_sorter = NULL; char *rel_uri = http_get_path(txn); char *uri_end = msg->sol + msg->sl.rq.u + txn->req.sl.rq.u_l; CanonicalizeResource(&ctx, rel_uri, uri_end - rel_uri); unsigned int sig_len = sizeof(raw_sig); HMAC_Final(&ctx, raw_sig, &sig_len); HMAC_CTX_cleanup(&ctx); BIO *mem_output_stream, *b64_filter; BUF_MEM *output_buffer; b64_filter = BIO_new(BIO_f_base64()); mem_output_stream = BIO_new(BIO_s_mem()); b64_filter = BIO_push(b64_filter, mem_output_stream); BIO_write(b64_filter, raw_sig, sig_len); (void) BIO_flush(b64_filter); BIO_get_mem_ptr(b64_filter, &output_buffer); memcpy(retval, output_buffer->data, output_buffer->length-1); BIO_free_all(b64_filter); } int s3_resign(struct session *s, struct buffer *req, struct proxy *px) { // TODO: Enable support for query string signatures? static struct hdr_exp *exp = NULL; if(!exp) { exp = calloc(1, sizeof(struct hdr_exp)); exp->preg = calloc(1, sizeof(regex_t)); exp->replace = strdup(px->s3_auth_header); exp->action = ACT_REPLACE; regcomp((regex_t*)exp->preg, "^Authorization:.*$", REG_EXTENDED | REG_ICASE); } if(!px->s3_auth_header || !px->s3_key) { printf("In s3_resign but have null config fields?"); return 0; } struct http_txn *txn = &s->txn; struct hdr_ctx authorization_header = {.idx = 0}; int ret = http_find_header2("Authorization", 13, txn->req.sol, &txn->hdr_idx, &authorization_header); if(!ret) { printf("No Authorization, so pass through unsigned."); return 0; } // Using exp->replace is only OK because haproxy is single-threaded, so the buffer // will only serve 1 request at a time. make_aws_signature((char*)exp->replace + px->s3_auth_header_colon, px->s3_key, px->s3_key_len, txn); apply_filter_to_req_headers(s, req, exp); return 0; }