Module: kamailio
Branch: master
Commit: f1baf7dd48c4ccb8d2d0ab0b24547f2793bb8588
URL:
https://github.com/kamailio/kamailio/commit/f1baf7dd48c4ccb8d2d0ab0b24547f2…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2024-05-02T10:15:48+02:00
nghttp2: set the data field for event route
- reset ctx fields when nothing was set from session/stream
---
Modified: src/modules/nghttp2/nghttp2_server.c
Modified: src/modules/nghttp2/nghttp2_server.h
---
Diff:
https://github.com/kamailio/kamailio/commit/f1baf7dd48c4ccb8d2d0ab0b24547f2…
Patch:
https://github.com/kamailio/kamailio/commit/f1baf7dd48c4ccb8d2d0ab0b24547f2…
---
diff --git a/src/modules/nghttp2/nghttp2_server.c b/src/modules/nghttp2/nghttp2_server.c
index d8c23220a13..6f5faf02ad6 100644
--- a/src/modules/nghttp2/nghttp2_server.c
+++ b/src/modules/nghttp2/nghttp2_server.c
@@ -518,11 +518,25 @@ static int on_request_recv(nghttp2_session *session,
if(stream_data->request_method) {
_ksr_nghttp2_ctx.method.s = stream_data->request_method;
_ksr_nghttp2_ctx.method.len = strlen(_ksr_nghttp2_ctx.method.s);
+ } else {
+ _ksr_nghttp2_ctx.method.s = NULL;
+ _ksr_nghttp2_ctx.method.len = 0;
}
if(session_data->client_addr) {
_ksr_nghttp2_ctx.srcip.s = session_data->client_addr;
_ksr_nghttp2_ctx.srcip.len = strlen(_ksr_nghttp2_ctx.srcip.s);
+ } else {
+ _ksr_nghttp2_ctx.srcip.s = NULL;
+ _ksr_nghttp2_ctx.srcip.len = 0;
+ }
+
+ if(stream_data->request_data.len > 0) {
+ _ksr_nghttp2_ctx.data.s = stream_data->request_data.s;
+ _ksr_nghttp2_ctx.data.len = stream_data->request_data.len;
+ } else {
+ _ksr_nghttp2_ctx.data.s = NULL;
+ _ksr_nghttp2_ctx.data.len = 0;
}
ksr_event_route();
@@ -567,16 +581,26 @@ static int on_frame_recv_callback(
static int on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags,
int32_t stream_id, const uint8_t *data, size_t len, void *user_data)
{
- struct Request *req;
+ http2_stream_data *stream_data;
(void)flags;
- (void)user_data;
- req = nghttp2_session_get_stream_user_data(session, stream_id);
- if(req) {
+ stream_data = nghttp2_session_get_stream_user_data(session, stream_id);
+
+ if(stream_data) {
LM_DBG("---------------------------- (DATA chunk) [%lu bytes]\n",
(unsigned long int)len);
LM_DBG("[[%.*s]]", (int)len, (char *)data);
- LM_DBG("----------------------------\n");
+ LM_DBG("\n----------------------------\n");
+ stream_data->request_data.s = realloc(stream_data->request_data.s,
+ len + stream_data->request_data.len + 1);
+ if(stream_data->request_data.s == NULL) {
+ LM_ERR("failed to allocate system memory\n");
+ return 0;
+ }
+ memcpy(stream_data->request_data.s + stream_data->request_data.len,
+ data, len);
+ stream_data->request_data.len += len;
+ stream_data->request_data.s[stream_data->request_data.len] = '\0';
}
return 0;
}
diff --git a/src/modules/nghttp2/nghttp2_server.h b/src/modules/nghttp2/nghttp2_server.h
index ac69a147313..63650db53af 100644
--- a/src/modules/nghttp2/nghttp2_server.h
+++ b/src/modules/nghttp2/nghttp2_server.h
@@ -80,6 +80,7 @@ typedef struct http2_stream_data
char *request_pathfull;
char *request_method;
http2_msghdr_t *hdrlist;
+ str request_data;
int32_t stream_id;
int fd;
} http2_stream_data;