[sr-dev] git:master: parser: added instance and reg_id fields to sip_msg_t

admin at sip-router.org admin at sip-router.org
Wed Dec 12 15:34:59 CET 2012


Module: sip-router
Branch: master
Commit: 55e7820686cbfb6392e707e0ee4fae96b22670bb
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=55e7820686cbfb6392e707e0ee4fae96b22670bb

Author: Juha Heinanen <jh at tutpro.com>
Committer: Juha Heinanen <jh at tutpro.com>
Date:   Wed Dec 12 16:06:52 2012 +0200

parser: added instance and reg_id fields to sip_msg_t

- also added set_instance and reset_instance functions

---

 parser/msg_parser.c |   39 +++++++++++++++++++++++++++++++++++++++
 parser/msg_parser.h |    5 +++++
 2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/parser/msg_parser.c b/parser/msg_parser.c
index 7c9c04e..dfed08d 100644
--- a/parser/msg_parser.c
+++ b/parser/msg_parser.c
@@ -820,6 +820,45 @@ void reset_path_vector(struct sip_msg* const msg)
 }
 
 
+int set_instance(struct sip_msg* msg, str* instance)
+{
+	char* ptr;
+
+	if (unlikely(!msg || !instance)) {
+		LM_ERR("invalid instance parameter value\n");
+		return -1;
+	}
+
+	if (unlikely(instance->len == 0)) {
+		reset_instance(msg);
+	} else if (msg->instance.s && (msg->instance.len >= instance->len)) {
+		memcpy(msg->instance.s, instance->s, instance->len);
+		msg->instance.len = instance->len;
+	} else {
+		ptr = (char*)pkg_malloc(instance->len);
+		if (!ptr) {
+			LM_ERR("not enough pkg memory for instance\n");
+			return -1;
+		}
+		memcpy(ptr, instance->s, instance->len);
+		if (msg->instance.s) pkg_free(msg->instance.s);
+		msg->instance.s = ptr;
+		msg->instance.len = instance->len;
+	}
+	return 0;
+}
+
+
+void reset_instance(struct sip_msg* const msg)
+{
+	if(msg->instance.s != 0) {
+		pkg_free(msg->instance.s);
+	}
+	msg->instance.s = 0;
+	msg->instance.len = 0;
+}
+
+
 hdr_field_t* get_hdr(const sip_msg_t* const msg, const enum _hdr_types_t ht)
 {
 	hdr_field_t *hdr;
diff --git a/parser/msg_parser.h b/parser/msg_parser.h
index 1783ee8..79194e3 100644
--- a/parser/msg_parser.h
+++ b/parser/msg_parser.h
@@ -363,6 +363,8 @@ typedef struct sip_msg {
 	struct socket_info* force_send_socket; /* force sending on this socket,
 											  if ser */
 	str path_vec;
+        str instance;
+        unsigned int reg_id;
 } sip_msg_t;
 
 /*! \brief pointer to a fakes message which was never received ;
@@ -447,6 +449,9 @@ int set_path_vector(struct sip_msg* msg, str* path);
 
 void reset_path_vector(struct sip_msg* const msg);
 
+int set_instance(struct sip_msg* msg, str* instance);
+
+void reset_instance(struct sip_msg* const msg);
 
 /** force a specific send socket for forwarding a request.
  * @param msg - sip msg.




More information about the sr-dev mailing list