[sr-dev] git:master:17be3610: core: add support for parsing http/2 replies parsing

Federico Cabiddu federico.cabiddu at gmail.com
Mon Nov 18 14:09:59 CET 2019


Module: kamailio
Branch: master
Commit: 17be36102e3a1c286c69a5da193dd8405000ab62
URL: https://github.com/kamailio/kamailio/commit/17be36102e3a1c286c69a5da193dd8405000ab62

Author: Federico Cabiddu <federico.cabiddu at gmail.com>
Committer: Federico Cabiddu <federico.cabiddu at gmail.com>
Date: 2019-11-16T16:33:04+01:00

core: add support for parsing http/2 replies parsing

---

Modified: src/core/parser/msg_parser.h
Modified: src/core/parser/parse_fline.c
Modified: src/core/parser/parse_fline.h

---

Diff:  https://github.com/kamailio/kamailio/commit/17be36102e3a1c286c69a5da193dd8405000ab62.diff
Patch: https://github.com/kamailio/kamailio/commit/17be36102e3a1c286c69a5da193dd8405000ab62.patch

---

diff --git a/src/core/parser/msg_parser.h b/src/core/parser/msg_parser.h
index 160a7eb21d..0b0f5044ed 100644
--- a/src/core/parser/msg_parser.h
+++ b/src/core/parser/msg_parser.h
@@ -146,9 +146,12 @@ if (  (*tmp==(firstchar) || *tmp==((firstchar) | 32)) &&                  \
 		SIP_VERSION, SIP_VERSION_LEN))
 
 #define IS_HTTP_REPLY(rpl)                                                \
-	((rpl)->first_line.u.reply.version.len >= HTTP_VERSION_LEN && \
+	(((rpl)->first_line.u.reply.version.len >= HTTP_VERSION_LEN && \
 	!strncasecmp((rpl)->first_line.u.reply.version.s,             \
-		HTTP_VERSION, HTTP_VERSION_LEN))
+		HTTP_VERSION, HTTP_VERSION_LEN)) ||                         \
+	((rpl)->first_line.u.reply.version.len >= HTTP2_VERSION_LEN && \
+	!strncasecmp((rpl)->first_line.u.reply.version.s,             \
+		HTTP2_VERSION, HTTP2_VERSION_LEN)))
 
 #define IS_SIP_REPLY(rpl)                                                \
 	((rpl)->first_line.u.reply.version.len >= SIP_VERSION_LEN && \
diff --git a/src/core/parser/parse_fline.c b/src/core/parser/parse_fline.c
index 6d46f2192a..c535b49a4c 100644
--- a/src/core/parser/parse_fline.c
+++ b/src/core/parser/parse_fline.c
@@ -96,21 +96,28 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start* fl)
 			fl->flags|=FLINE_FLAG_PROTO_SIP;
 			fl->u.reply.version.len=SIP_VERSION_LEN;
 			tmp=buffer+SIP_VERSION_LEN;
-	} else if (http_reply_parse != 0 &&
-		 	(*tmp=='H' || *tmp=='h') &&
+	} else if (http_reply_parse != 0 && (*tmp=='H' || *tmp=='h')) {
 			/* 'HTTP/1.' */
-			strncasecmp( tmp+1, HTTP_VERSION+1, HTTP_VERSION_LEN-1)==0 &&
-			/* [0|1] */
-			((*(tmp+HTTP_VERSION_LEN)=='0') || (*(tmp+HTTP_VERSION_LEN)=='1')) &&
-			(*(tmp+HTTP_VERSION_LEN+1)==' ')  ){ 
-			/* ugly hack to be able to route http replies
-			 * Note: - the http reply must have a via
-			 *       - the message is marked as SIP_REPLY (ugly)
-			 */
-				fl->type=SIP_REPLY;
-				fl->flags|=FLINE_FLAG_PROTO_HTTP;
-				fl->u.reply.version.len=HTTP_VERSION_LEN+1 /*include last digit*/;
-				tmp=buffer+HTTP_VERSION_LEN+1 /* last digit */;
+			if (strncasecmp( tmp+1, HTTP_VERSION+1, HTTP_VERSION_LEN-1)==0 &&
+			  /* [0|1] */
+			  ((*(tmp+HTTP_VERSION_LEN)=='0') || (*(tmp+HTTP_VERSION_LEN)=='1')) &&
+			  (*(tmp+HTTP_VERSION_LEN+1)==' ')  ){ 
+			    /* ugly hack to be able to route http replies
+			    * Note: - the http reply must have a via
+			    *       - the message is marked as SIP_REPLY (ugly)
+			    */
+				  fl->type=SIP_REPLY;
+				  fl->flags|=FLINE_FLAG_PROTO_HTTP;
+				  fl->u.reply.version.len=HTTP_VERSION_LEN+1 /*include last digit*/;
+          tmp=buffer+HTTP_VERSION_LEN+1 /* last digit */;
+			/* 'HTTP/2' */
+			} 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->u.reply.version.len=HTTP2_VERSION_LEN;
+					tmp=buffer+HTTP2_VERSION_LEN;
+			}
 	} else IFISMETHOD( INVITE, 'I' )
 	else IFISMETHOD( CANCEL, 'C')
 	else IFISMETHOD( ACK, 'A' )
diff --git a/src/core/parser/parse_fline.h b/src/core/parser/parse_fline.h
index 2add9b0efb..63f74ececf 100644
--- a/src/core/parser/parse_fline.h
+++ b/src/core/parser/parse_fline.h
@@ -49,6 +49,9 @@
 #define HTTP_VERSION "HTTP/1."
 #define HTTP_VERSION_LEN (sizeof(HTTP_VERSION)-1)
 
+#define HTTP2_VERSION "HTTP/2"
+#define HTTP2_VERSION_LEN (sizeof(HTTP2_VERSION)-1)
+
 #define CANCEL "CANCEL"
 #define ACK    "ACK"
 #define INVITE "INVITE"




More information about the sr-dev mailing list