parser: added instance and reg_id fields to sip_msg_t
authorJuha Heinanen <jh@tutpro.com>
Wed, 12 Dec 2012 14:06:52 +0000 (16:06 +0200)
committerJuha Heinanen <jh@tutpro.com>
Wed, 12 Dec 2012 14:06:52 +0000 (16:06 +0200)
- also added set_instance and reset_instance functions

parser/msg_parser.c
parser/msg_parser.h

index 7c9c04e..dfed08d 100644 (file)
@@ -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;
index 1783ee8..79194e3 100644 (file)
@@ -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.