Przeglądaj źródła

core: added ruid to msg and branch structures

Peter Dunkley 12 lat temu
rodzic
commit
e3ba8f38f7
5 zmienionych plików z 72 dodań i 4 usunięć
  1. 2 0
      config.h
  2. 18 1
      dset.c
  3. 8 3
      dset.h
  4. 39 0
      parser/msg_parser.c
  5. 5 0
      parser/msg_parser.h

+ 2 - 0
config.h

@@ -75,6 +75,8 @@
 
 #define MAX_INSTANCE_SIZE 256 		/*!< Maximum length of +sip.instance contact header param value buffer */
 
+#define MAX_RUID_SIZE 65		/*!< Maximum length of ruid for location records */
+
 #define MY_VIA "Via: SIP/2.0/UDP "
 #define MY_VIA_LEN (sizeof(MY_VIA) - 1)
 

+ 18 - 1
dset.c

@@ -297,7 +297,8 @@ void clear_branches(void)
 int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path,
 		  qvalue_t q, unsigned int flags,
 		  struct socket_info* force_socket,
-		  str* instance, unsigned int reg_id)
+		  str* instance, unsigned int reg_id,
+		  str* ruid)
 {
 	str luri;
 
@@ -381,6 +382,22 @@ int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path,
 	/* copy reg_id */
 	branches[nr_branches].reg_id = reg_id;
 
+	/* copy ruid string */
+	if (unlikely(ruid && ruid->len && ruid->s)) {
+		if (unlikely(ruid->len > MAX_RUID_SIZE - 1)) {
+			LOG(L_ERR, "too long ruid: %.*s\n",
+			    ruid->len, ruid->s);
+			return -1;
+		}
+		memcpy(branches[nr_branches].ruid, ruid->s,
+		       ruid->len);
+		branches[nr_branches].ruid[ruid->len] = 0;
+		branches[nr_branches].ruid_len = ruid->len;
+	} else {
+		branches[nr_branches].ruid[0] = '\0';
+		branches[nr_branches].ruid_len = 0;
+	}
+
 	nr_branches++;
 	return 1;
 }

+ 8 - 3
dset.h

@@ -66,6 +66,10 @@ struct branch
     /* reg-id contact header param value */
     unsigned int reg_id;
 
+    /* ruid value from usrloc */
+    char ruid[MAX_RUID_SIZE];
+    unsigned int ruid_len;
+
     /* Branch flags */
     flag_t flags;
 };
@@ -88,11 +92,12 @@ int drop_sip_branch(int idx);
 int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path,
 		  qvalue_t q, unsigned int flags,
 		  struct socket_info* force_socket,
-		  str* instance, unsigned int reg_id);
+		  str* instance, unsigned int reg_id,
+		  str* ruid);
 
 /*! \brief kamailio compatible version */
 #define km_append_branch(msg, uri, dst_uri, path, q, flags, force_socket) \
-    append_branch(msg, uri, dst_uri, path, q, flags, force_socket, 0, 0)
+    append_branch(msg, uri, dst_uri, path, q, flags, force_socket, 0, 0, 0)
 
 /*! \brief ser compatible append_branch version.
  *  append_branch version compatible with ser: no path or branch flags support
@@ -109,7 +114,7 @@ static inline int ser_append_branch(struct sip_msg* msg,
     s_uri.len=uri_len;
     s_dst_uri.s=dst_uri;
     s_dst_uri.len=dst_uri_len;
-    return append_branch(msg, &s_uri, &s_dst_uri, 0, q, 0, force_socket, 0, 0);
+    return append_branch(msg, &s_uri, &s_dst_uri, 0, q, 0, force_socket, 0, 0, 0);
 }
 
 

+ 39 - 0
parser/msg_parser.c

@@ -859,6 +859,45 @@ void reset_instance(struct sip_msg* const msg)
 }
 
 
+int set_ruid(struct sip_msg* msg, str* ruid)
+{
+	char* ptr;
+
+	if (unlikely(!msg || !ruid)) {
+		LM_ERR("invalid ruid parameter value\n");
+		return -1;
+	}
+
+	if (unlikely(ruid->len == 0)) {
+		reset_ruid(msg);
+	} else if (msg->ruid.s && (msg->ruid.len >= ruid->len)) {
+		memcpy(msg->ruid.s, ruid->s, ruid->len);
+		msg->ruid.len = ruid->len;
+	} else {
+		ptr = (char*)pkg_malloc(ruid->len);
+		if (!ptr) {
+			LM_ERR("not enough pkg memory for ruid\n");
+			return -1;
+		}
+		memcpy(ptr, ruid->s, ruid->len);
+		if (msg->ruid.s) pkg_free(msg->ruid.s);
+		msg->ruid.s = ptr;
+		msg->ruid.len = ruid->len;
+	}
+	return 0;
+}
+
+
+void reset_ruid(struct sip_msg* const msg)
+{
+	if(msg->ruid.s != 0) {
+		pkg_free(msg->ruid.s);
+	}
+	msg->ruid.s = 0;
+	msg->ruid.len = 0;
+}
+
+
 hdr_field_t* get_hdr(const sip_msg_t* const msg, const enum _hdr_types_t ht)
 {
 	hdr_field_t *hdr;

+ 5 - 0
parser/msg_parser.h

@@ -365,6 +365,7 @@ typedef struct sip_msg {
 	str path_vec;
         str instance;
         unsigned int reg_id;
+	str ruid;
 } sip_msg_t;
 
 /*! \brief pointer to a fakes message which was never received ;
@@ -453,6 +454,10 @@ int set_instance(struct sip_msg* msg, str* instance);
 
 void reset_instance(struct sip_msg* const msg);
 
+int set_ruid(struct sip_msg* msg, str* ruid);
+
+void reset_ruid(struct sip_msg* const msg);
+
 /** force a specific send socket for forwarding a request.
  * @param msg - sip msg.
  * @param fsocket - forced socket, pointer to struct socket_info, can be 0 (in