diff options
| author | 李佳 <[email protected]> | 2024-04-10 13:51:41 +0000 |
|---|---|---|
| committer | 李佳 <[email protected]> | 2024-04-10 13:51:41 +0000 |
| commit | 8be661adc385b843ca36769f71d43549848e4c7d (patch) | |
| tree | 8fcfbcb35c10d884b2f38810759dcee094684f29 /src | |
| parent | c00538d6a95fced820e23c11cf238bef7bfe7fbb (diff) | |
| parent | 600e7eba3f0a3ffc6002d5278903892843d735a9 (diff) | |
Merge branch 'get-transaction-seq' into 'develop'
add http_message_get_transaction_seq() API; add base64 encode format for...
See merge request stellar/http_decoder!2
Diffstat (limited to 'src')
| -rw-r--r-- | src/http_decoder.c | 21 | ||||
| -rw-r--r-- | src/http_decoder_half.c | 42 | ||||
| -rw-r--r-- | src/http_decoder_half.h | 1 |
3 files changed, 55 insertions, 9 deletions
diff --git a/src/http_decoder.c b/src/http_decoder.c index 68f7c58..43eb8bf 100644 --- a/src/http_decoder.c +++ b/src/http_decoder.c @@ -855,4 +855,25 @@ int http_message_get_url(struct http_message *msg, struct hstring *url) msg->ref_queue->array[msg->queue_index].req_data; return http_half_data_get_url(req_data, url); +} + +int http_message_get_transaction_seq(struct http_message *msg) +{ + if (NULL == msg) + { + return -1; + } + assert(msg->ref_queue); + assert(msg->queue_index < HD_RESULT_QUEUE_LEN); + struct http_decoder_half_data *hf_data; + if (HTTP_MESSAGE_REQ_LINE == msg->type || HTTP_MESSAGE_REQ_HEADER == msg->type || HTTP_MESSAGE_REQ_BODY == msg->type) + { + hf_data = msg->ref_queue->array[msg->queue_index].req_data; + } + else + { + hf_data = msg->ref_queue->array[msg->queue_index].res_data; + } + return http_half_data_get_transaction_seq(hf_data); + ; }
\ No newline at end of file diff --git a/src/http_decoder_half.c b/src/http_decoder_half.c index 56a7838..5772a54 100644 --- a/src/http_decoder_half.c +++ b/src/http_decoder_half.c @@ -37,6 +37,7 @@ struct http_decoder_half_data { int joint_url_complete; struct hstring joint_url; // http://<host>[:<port>]/<path>?<searchpart> + long long transaction_index; }; struct http_decoder_half { @@ -54,6 +55,7 @@ struct http_decoder_half { long long trans_counter; long long err_counter; + long long transaction_seq; }; // #define HTTP_DECODER_DEBUG @@ -126,7 +128,7 @@ static int on_message_begin(llhttp_t *http) half->http_ev_cb(half->event, &half->ref_data, half->http_ev_ctx); half->trans_counter++; - + half->ref_data->transaction_index = half->transaction_seq++; return 0; } @@ -228,11 +230,21 @@ static int on_uri(llhttp_t *http, const char *at, size_t length) static void http_decoder_cached_portion_url(struct http_decoder_half *half, const struct hstring *uri_result) { struct http_decoder_half_data *ref_data = half->ref_data; + int uri_skip_len = 0; - ref_data->joint_url.str_len = uri_result->str_len; - ref_data->joint_url.str = MEMPOOL_CALLOC(half->http_ev_ctx->ref_mempool, char, uri_result->str_len); - // ref_data->joint_url.str = (char *)malloc(uri_result->str_len); - memcpy(ref_data->joint_url.str, uri_result->str, uri_result->str_len); + if ((uri_result->str_len) > 7 && (strncasecmp("http://", uri_result->str, 7) == 0)) // absolute URI + { + uri_skip_len = strlen("http://"); + ref_data->joint_url_complete = 1; + } + else + { + ref_data->joint_url_complete = 0; + } + + ref_data->joint_url.str_len = uri_result->str_len - uri_skip_len; + ref_data->joint_url.str = MEMPOOL_CALLOC(half->http_ev_ctx->ref_mempool, char, ref_data->joint_url.str_len); + memcpy(ref_data->joint_url.str, uri_result->str+uri_skip_len, ref_data->joint_url.str_len); } /* Information-only callbacks, return value is ignored */ @@ -963,15 +975,22 @@ static void using_session_addr_as_host(struct session *ref_session, void http_decoder_join_url(struct http_decoder_half_data *hfdata, nmx_pool_t *mempool, const struct http_header *host_hdr) { - //int url_cache_str_len = strlen("http://") + host_hdr->val.str_len + hfdata->joint_url.str_len; - int url_cache_str_len = host_hdr->val.str_len + hfdata->joint_url.str_len; + int append_slash_len = 0; + if('/' != hfdata->joint_url.str[0]) + { + append_slash_len = 1; + } + int url_cache_str_len = host_hdr->val.str_len + hfdata->joint_url.str_len + append_slash_len; char *url_cache_str = MEMPOOL_CALLOC(mempool, char, url_cache_str_len); char *ptr = url_cache_str; - //memcpy(ptr, "http://", strlen("http://")); - //ptr += strlen("http://"); memcpy(ptr, host_hdr->val.str, host_hdr->val.str_len); ptr += host_hdr->val.str_len; + if(append_slash_len) + { + *ptr = '/'; + ptr++; + } memcpy(ptr, hfdata->joint_url.str, hfdata->joint_url.str_len); MEMPOOL_FREE(mempool, hfdata->joint_url.str); // free the cached uri buffer @@ -1031,4 +1050,9 @@ int http_half_data_get_url(struct http_decoder_half_data *res_data, struct hstri url->str_len = res_data->joint_url.str_len; return 0; +} + +int http_half_data_get_transaction_seq(struct http_decoder_half_data *hf_data) +{ + return hf_data->transaction_index; }
\ No newline at end of file diff --git a/src/http_decoder_half.h b/src/http_decoder_half.h index 0fcd0b6..ebe7e00 100644 --- a/src/http_decoder_half.h +++ b/src/http_decoder_half.h @@ -111,6 +111,7 @@ int http_decoder_join_url_finally(struct http_event_context *ev_ctx, struct http_decoder_half_data *hfdata, nmx_pool_t *mempool); int http_half_data_get_url(struct http_decoder_half_data *res_data, struct hstring *url); +int http_half_data_get_transaction_seq(struct http_decoder_half_data *hf_data); #ifdef __cplusplus } |
