Module: kamailio
Branch: master
Commit: 9328918897d44bec0f0a393af91483c2413a1446
URL:
https://github.com/kamailio/kamailio/commit/9328918897d44bec0f0a393af91483c…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2015-01-07T18:08:35+01:00
core: memset 0 the struct in first line parsing; split type and flags
- initialize to 0 first line struct msg_start_t in parse_first_line()
- split field int type in short type and short flags to be able to store
more info about first line without changes in other places of existing code
- set in flags if the protocol in first line is sip or http - useful to
avoid string comparison whenever needed to get the two very used
protocols
---
Modified: parser/parse_fline.c
Modified: parser/parse_fline.h
---
Diff:
https://github.com/kamailio/kamailio/commit/9328918897d44bec0f0a393af91483c…
Patch:
https://github.com/kamailio/kamailio/commit/9328918897d44bec0f0a393af91483c…
---
diff --git a/parser/parse_fline.c b/parser/parse_fline.c
index dbbe4de..861b5fd 100644
--- a/parser/parse_fline.c
+++ b/parser/parse_fline.c
@@ -45,6 +45,11 @@
#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;
/* grammar:
@@ -56,7 +61,7 @@ int http_reply_parse = 0;
/* parses the first line, returns pointer to next line & fills fl;
also modifies buffer (to avoid extra copy ops) */
-char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
+char* parse_first_line(char* buffer, unsigned int len, struct msg_start* fl)
{
char *tmp;
@@ -77,6 +82,7 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start
* fl)
*/
+ memset(fl, 0, sizeof(struct msg_start));
offset = 0;
end=buffer+len;
/* see if it's a reply (status) */
@@ -97,6 +103,7 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start
* fl)
strncasecmp( tmp+1, SIP_VERSION+1, SIP_VERSION_LEN-1)==0 &&
(*(tmp+SIP_VERSION_LEN)==' ')) {
fl->type=SIP_REPLY;
+ 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 &&
@@ -111,6 +118,7 @@ char* parse_first_line(char* buffer, unsigned int len, struct
msg_start * fl)
* - 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 */;
} else IFISMETHOD( INVITE, 'I' )
@@ -223,6 +231,22 @@ char* parse_first_line(char* buffer, unsigned int len, struct
msg_start * fl)
fl->u.request.version.len=tmp-third;
fl->len=nl-buffer;
+ if (fl->type==SIP_REQUEST) {
+ if(fl->u.request.version.len >= SIP_VERSION_LEN
+ && (fl->u.request.version.s[0]=='S'
+ || fl->u.request.version.s[0]=='s')
+ && !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
+ && (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;
+ }
+ }
+
return nl;
error:
@@ -245,3 +269,12 @@ char* parse_first_line(char* buffer, unsigned int len, struct
msg_start * fl)
nl=eat_line(buffer,len);
return nl;
}
+
+char* parse_fline(char* buffer, char* end, struct msg_start* fl)
+{
+ if(end<=buffer) {
+ /* make it throw error via parse_first_line() for consistency */
+ return parse_first_line(buffer, 0, fl);
+ }
+ return parse_first_line(buffer, (unsigned int)(end-buffer), fl);
+}
diff --git a/parser/parse_fline.h b/parser/parse_fline.h
index 7564b9f..62873f5 100644
--- a/parser/parse_fline.h
+++ b/parser/parse_fline.h
@@ -69,7 +69,8 @@
#define PUBLISH_LEN 7
struct msg_start {
- int type; /*!< Type of the Message - Request/Response */
+ short type; /*!< Type of the message - request/response */
+ short flags; /*!< First line flags */
int len; /*!< length including delimiter */
union {
struct {