[svn-commits] branch kpfleming/stringfields - r7753 /team/kpfleming/stringfields/channels/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Jan 3 17:36:55 CST 2006


Author: kpfleming
Date: Tue Jan  3 17:36:54 2006
New Revision: 7753

URL: http://svn.digium.com/view/asterisk?rev=7753&view=rev
Log:
initial test version

Modified:
    team/kpfleming/stringfields/channels/chan_sip.c

Modified: team/kpfleming/stringfields/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/stringfields/channels/chan_sip.c?rev=7753&r1=7752&r2=7753&view=diff
==============================================================================
--- team/kpfleming/stringfields/channels/chan_sip.c (original)
+++ team/kpfleming/stringfields/channels/chan_sip.c Tue Jan  3 17:36:54 2006
@@ -86,6 +86,7 @@
 #include "asterisk/dnsmgr.h"
 #include "asterisk/devicestate.h"
 #include "asterisk/linkedlists.h"
+#include "asterisk/stringfields.h"
 
 #ifdef OSP_SUPPORT
 #include "asterisk/astosp.h"
@@ -596,7 +597,9 @@
 static struct sip_pvt {
 	ast_mutex_t lock;			/*!< Channel private lock */
 	int method;				/*!< SIP method of this packet */
-	char callid[80];			/*!< Global CallID */
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(callid);
+	);
 	char randdata[80];			/*!< Random data */
 	struct ast_codec_pref prefs;		/*!< codec prefs */
 	unsigned int ocseq;			/*!< Current outgoing seqno */
@@ -823,6 +826,9 @@
 /*! \brief sip_registry: Registrations with other SIP proxies */
 struct sip_registry {
 	ASTOBJ_COMPONENTS_FULL(struct sip_registry,1,1);
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(callid);
+	);
 	int portno;			/*!<  Optional port override */
 	char username[80];		/*!<  Who we are registering as */
 	char authuser[80];		/*!< Who we *authenticate* as */
@@ -838,7 +844,6 @@
 	struct sip_pvt *call;		/*!< create a sip_pvt structure for each outbound "registration call" in progress */
 	int regstate;			/*!< Registration state (see above) */
 	int callid_valid;		/*!< 0 means we haven't chosen callid for this registry yet. */
-	char callid[80];		/*!< Global CallID for this registry */
 	unsigned int ocseq;		/*!< Sequence number we got to for REGISTERs for this registry */
 	struct sockaddr_in us;		/*!< Who the server thinks we are */
  	
@@ -2173,6 +2178,9 @@
 		p->chanvars = NULL;
 	}
 	ast_mutex_destroy(&p->lock);
+
+	ast_string_field_free_all(p);
+
 	free(p);
 }
 
@@ -2984,24 +2992,46 @@
 	return fr;
 }
 
-/*! \brief  build_callid: Build SIP CALLID header ---*/
-static void build_callid(char *callid, int len, struct in_addr ourip, char *fromdomain)
-{
-	int res;
-	int val;
+/*! \brief  build_callid_pvt: Build SIP Call-ID value for a non-REGISTER transaction ---*/
+static void build_callid_pvt(struct sip_pvt *pvt)
+{
+	int val[4];
 	int x;
 	char iabuf[INET_ADDRSTRLEN];
-	for (x=0; x<4; x++) {
-		val = thread_safe_rand();
-		res = snprintf(callid, len, "%08x", val);
-		len -= res;
-		callid += res;
-	}
-	if (!ast_strlen_zero(fromdomain))
-		snprintf(callid, len, "@%s", fromdomain);
+
+	for (x=0; x<4; x++)
+		val[x] = thread_safe_rand();
+
+	if (ast_strlen_zero(pvt->fromdomain))
+		/* It's not important that we really use our right IP here... */
+		ast_string_field_build(pvt, callid, "%08x%08x%08x%08x@%s",
+				       val[0], val[1], val[2], val[3],
+				       ast_inet_ntoa(iabuf, sizeof(iabuf), pvt->ourip));
 	else
-	/* It's not important that we really use our right IP here... */
-		snprintf(callid, len, "@%s", ast_inet_ntoa(iabuf, sizeof(iabuf), ourip));
+		ast_string_field_build(pvt, callid, "%08x%08x%08x%08x@%s",
+				       val[0], val[1], val[2], val[3],
+				       pvt->fromdomain);
+}
+
+/*! \brief  build_callid_registry: Build SIP Call-ID value for a REGISTER transaction ---*/
+static void build_callid_registry(struct sip_registry *reg, struct in_addr ourip, const char *fromdomain)
+{
+	int val[4];
+	int x;
+	char iabuf[INET_ADDRSTRLEN];
+
+	for (x=0; x<4; x++)
+		val[x] = thread_safe_rand();
+
+	if (ast_strlen_zero(fromdomain))
+		/* It's not important that we really use our right IP here... */
+		ast_string_field_build(reg, callid, "%08x%08x%08x%08x@%s",
+				       val[0], val[1], val[2], val[3],
+				       ast_inet_ntoa(iabuf, sizeof(iabuf), ourip));
+	else
+		ast_string_field_build(reg, callid, "%08x%08x%08x%08x@%s",
+				       val[0], val[1], val[2], val[3],
+				       fromdomain);
 }
 
 static void make_our_tag(char *tagbuf, size_t len)
@@ -3010,7 +3040,8 @@
 }
 
 /*! \brief  sip_alloc: Allocate SIP_PVT structure and set defaults ---*/
-static struct sip_pvt *sip_alloc(char *callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method)
+static struct sip_pvt *sip_alloc(ast_string_field callid, struct sockaddr_in *sin,
+				 int useglobal_nat, const int intended_method)
 {
 	struct sip_pvt *p;
 
@@ -3080,9 +3111,9 @@
 		ast_copy_string(p->fromdomain, default_fromdomain, sizeof(p->fromdomain));
 	build_via(p, p->via, sizeof(p->via));
 	if (!callid)
-		build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain);
+		build_callid_pvt(p);
 	else
-		ast_copy_string(p->callid, callid, sizeof(p->callid));
+		ast_string_field_set(p, callid, callid);
 	ast_copy_flags(p, &global_flags, SIP_FLAGS_TO_COPY);
 	/* Assign default music on hold class */
 	strcpy(p->musicclass, global_musicclass);
@@ -5310,7 +5341,7 @@
 	} else {
 		/* Build callid for registration if we haven't registered before */
 		if (!r->callid_valid) {
-			build_callid(r->callid, sizeof(r->callid), __ourip, default_fromdomain);
+			build_callid_registry(r, __ourip, default_fromdomain);
 			r->callid_valid = 1;
 		}
 		/* Allocate SIP packet for registration */
@@ -5338,7 +5369,7 @@
 			return 0;
 		}
 		/* Copy back Call-ID in case create_addr changed it */
-		ast_copy_string(r->callid, p->callid, sizeof(r->callid));
+		ast_string_field_set(r, callid, p->callid);
 		if (r->portno)
 			p->sa.sin_port = htons(r->portno);
 		ast_set_flag(p, SIP_OUTGOING);	/* Registration is outgoing call */
@@ -8772,7 +8803,7 @@
 		if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip))
 			memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
 		build_via(p, p->via, sizeof(p->via));
-		build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain);
+		build_callid_pvt(p);
 		ast_cli(fd, "Sending NOTIFY of type '%s' to '%s'\n", argv[2], argv[i]);
 		transmit_sip_request(p, &req);
 		sip_scheddestroy(p, 15000);
@@ -11151,7 +11182,7 @@
 	if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip))
 		memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
 	build_via(p, p->via, sizeof(p->via));
-	build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain);
+	build_callid_pvt(p);
 	/* Send MWI */
 	ast_set_flag(p, SIP_OUTGOING);
 	transmit_notify_with_mwi(p, newmsgs, oldmsgs, peer->vmexten);
@@ -11386,7 +11417,7 @@
 	if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip))
 		memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
 	build_via(p, p->via, sizeof(p->via));
-	build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain);
+	build_callid_pvt(p);
 
 	if (peer->pokeexpire > -1)
 		ast_sched_del(sched, peer->pokeexpire);
@@ -11527,7 +11558,7 @@
 	if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip))
 		memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
 	build_via(p, p->via, sizeof(p->via));
-	build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain);
+	build_callid_pvt(p);
 	
 	/* We have an extension to call, don't use the full contact here */
 	/* This to enable dialling registered peers with extension dialling,



More information about the svn-commits mailing list