[SR-Dev] git:master: New element of sip_msg structure with pointer to parsed body
Jan Janak
jan at iptel.org
Tue Mar 24 21:27:21 CET 2009
Module: sip-router
Branch: master
Commit: 5a8977107c9c3f49dedf6de748cef421d755aa8b
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5a8977107c9c3f49dedf6de748cef421d755aa8b
Author: Jan Janak <jan at iptel.org>
Committer: Jan Janak <jan at iptel.org>
Date: Tue Mar 24 20:30:31 2009 +0100
New element of sip_msg structure with pointer to parsed body
This patch adds a new variable (called body) to the sip_msg structure
which can be used to store a pointer to parsed message body. This is
useful for modules that need to parse the SIP message body and would
like to store the result somewhere in the sip_msg structure so that
the body does not get parsed repeatedly.
The pointer is of type msg_body which is a generic structure that
represents parsed body of any type (SDP documents, XML documents, etc.).
This structure contains only two elements, the first element is enum
msg_body_type which designates the type of the parsed body document.
The second element is a pointer to a free function that is called by
the sr core to free all memory associated with the parsed body
structure.
Body parsers do not use the generic structure directly, instead they
are supposed to cast it to some other data structure. The target
structure must, however, retain the first two elements (the type and
the free function pointer) in the same order as the generic structure.
Body parsers provide the value of 'type' and 'free' elements.
The new structure in this commit only supports one body document type
per SIP message. As a possible future extension we could modify the
structure so that multiple such structures can be arranged into a
tree-like structure and then we will have support for multi-part body
documents.
---
parser/msg_parser.c | 1 +
parser/msg_parser.h | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/parser/msg_parser.c b/parser/msg_parser.c
index 74f91f5..bc73fb7 100644
--- a/parser/msg_parser.c
+++ b/parser/msg_parser.c
@@ -694,6 +694,7 @@ void free_sip_msg(struct sip_msg* msg)
if (msg->new_uri.s) { pkg_free(msg->new_uri.s); msg->new_uri.len=0; }
if (msg->dst_uri.s) { pkg_free(msg->dst_uri.s); msg->dst_uri.len=0; }
if (msg->headers) free_hdr_field_lst(msg->headers);
+ if (msg->body && msg->body->free) msg->body->free(&msg->body);
if (msg->add_rm) free_lump_list(msg->add_rm);
if (msg->body_lumps) free_lump_list(msg->body_lumps);
if (msg->reply_lump) free_reply_lump(msg->reply_lump);
diff --git a/parser/msg_parser.h b/parser/msg_parser.h
index af85f21..74754f7 100644
--- a/parser/msg_parser.h
+++ b/parser/msg_parser.h
@@ -200,6 +200,26 @@ struct sip_uri {
#endif
};
+struct msg_body;
+
+typedef void (*free_msg_body_f)(struct msg_body** ptr);
+
+typedef enum msg_body_type {
+ MSG_BODY_UNKNOWN = 0,
+ MSG_BODY_SDP
+} msg_body_type_t;
+
+/* This structure represents a generic SIP message body, regardless of the
+ * body type. Body parsers are supposed to cast this structure to some other
+ * body-type specific structure, but the body type specific structure must
+ * retain msg_body_type variable and a pointer to the free function as the
+ * first two variables within the structure.
+ */
+typedef struct msg_body {
+ msg_body_type_t type;
+ free_msg_body_f free;
+} msg_body_t;
+
typedef struct sip_msg {
unsigned int id; /* message id, unique/process*/
@@ -259,6 +279,8 @@ typedef struct sip_msg {
struct hdr_field* ppi;
struct hdr_field* path;
+ struct msg_body* body;
+
char* eoh; /* pointer to the end of header (if found) or null */
char* unparsed; /* here we stopped parsing*/
More information about the sr-dev
mailing list