Module: kamailio Branch: master Commit: bb1a7d9a70501ddb89073564ec49d343a75faa27 URL: https://github.com/kamailio/kamailio/commit/bb1a7d9a70501ddb89073564ec49d343...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2020-10-11T12:48:28+02:00
core: parse first line - detect http/2 also for requests
- it was done for replies - set additional flag to differentiate on http/2 version
---
Modified: src/core/parser/parse_fline.c Modified: src/core/parser/parse_fline.h
---
Diff: https://github.com/kamailio/kamailio/commit/bb1a7d9a70501ddb89073564ec49d343... Patch: https://github.com/kamailio/kamailio/commit/bb1a7d9a70501ddb89073564ec49d343...
---
diff --git a/src/core/parser/parse_fline.c b/src/core/parser/parse_fline.c index dac891fad7..43afd723d8 100644 --- a/src/core/parser/parse_fline.c +++ b/src/core/parser/parse_fline.c @@ -35,10 +35,6 @@ #include "../mem/mem.h" #include "../ut.h"
-/* flags for first line - * - stored on a short field (16 flags) */ -#define FLINE_FLAG_PROTO_SIP (1<<0) -#define FLINE_FLAG_PROTO_HTTP (1<<1)
int http_reply_parse = 0;
@@ -110,7 +106,7 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start* fl) } else if (strncasecmp( tmp+1, &HTTP2_VERSION[1], HTTP2_VERSION_LEN-1)==0 && (*(tmp+HTTP2_VERSION_LEN)==' ')) { fl->type=SIP_REPLY; - fl->flags|=FLINE_FLAG_PROTO_HTTP; + fl->flags|=(FLINE_FLAG_PROTO_HTTP | FLINE_FLAG_PROTO_HTTP2); fl->u.reply.version.len=HTTP2_VERSION_LEN; tmp=buffer+HTTP2_VERSION_LEN; } @@ -235,15 +231,24 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start* fl) && !strncasecmp(fl->u.request.version.s+1, &SIP_VERSION[1], SIP_VERSION_LEN-1)) { fl->flags|=FLINE_FLAG_PROTO_SIP; - } else if(fl->u.request.version.len >= HTTP_VERSION_LEN + } else if(fl->u.request.version.len >= 4 && (fl->u.request.version.s[0]=='H' - || fl->u.request.version.s[0]=='h') - && !strncasecmp(fl->u.request.version.s+1, - &HTTP_VERSION[1], HTTP_VERSION_LEN-1)) { - fl->flags|=FLINE_FLAG_PROTO_HTTP; + || fl->u.request.version.s[0]=='h')) { + if(fl->u.request.version.len >= HTTP_VERSION_LEN + && !strncasecmp(fl->u.request.version.s+1, + &HTTP_VERSION[1], HTTP_VERSION_LEN-1)) { + fl->flags|=FLINE_FLAG_PROTO_HTTP; + } else if(fl->u.request.version.len >= HTTP2_VERSION_LEN + && !strncasecmp(fl->u.request.version.s+1, + &HTTP2_VERSION[1], HTTP2_VERSION_LEN-1)) { + fl->flags|=(FLINE_FLAG_PROTO_HTTP | FLINE_FLAG_PROTO_HTTP2); + } } }
+ LM_DBG("first line type %d (%s) flags %d\n", (int)fl->type, + (fl->type==SIP_REPLY)?"reply(status)":"request", (int)fl->flags); + return nl;
error: diff --git a/src/core/parser/parse_fline.h b/src/core/parser/parse_fline.h index 63f74ececf..d65b04bdbb 100644 --- a/src/core/parser/parse_fline.h +++ b/src/core/parser/parse_fline.h @@ -34,14 +34,24 @@
#include "../str.h"
+ +/* Invalid message */ +#define SIP_INVALID 0 +#define MSG_INVALID 0 + /* Message is request */ #define SIP_REQUEST 1 +#define MSG_REQUEST 1
/* Message is reply */ #define SIP_REPLY 2 +#define MSG_REPLY 2
-/* Invalid message */ -#define SIP_INVALID 0 +/* flags for first line + * - stored on a short field (16 flags) */ +#define FLINE_FLAG_PROTO_SIP (1<<0) /* sip 2.0 protocol */ +#define FLINE_FLAG_PROTO_HTTP (1<<1) /* any http protocol */ +#define FLINE_FLAG_PROTO_HTTP2 (1<<2) /* additional for http 2 */
#define SIP_VERSION "SIP/2.0" #define SIP_VERSION_LEN 7 @@ -85,7 +95,7 @@ typedef struct msg_start { str method; /*!< Method string */ str uri; /*!< Request URI */ str version; /*!< SIP version */ - int method_value; + int method_value; /*!< Method id value */ } request; struct { str version; /*!< SIP version */