[asterisk-commits] bbryant: branch bbryant/sip-tcptls r73469 - /team/bbryant/sip-tcptls/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jul 5 14:26:13 CDT 2007


Author: bbryant
Date: Thu Jul  5 14:26:12 2007
New Revision: 73469

URL: http://svn.digium.com/view/asterisk?view=rev&rev=73469
Log:
Saved socket information on peer structure after registration

Modified:
    team/bbryant/sip-tcptls/channels/chan_sip.c

Modified: team/bbryant/sip-tcptls/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/bbryant/sip-tcptls/channels/chan_sip.c?view=diff&rev=73469&r1=73468&r2=73469
==============================================================================
--- team/bbryant/sip-tcptls/channels/chan_sip.c (original)
+++ team/bbryant/sip-tcptls/channels/chan_sip.c Thu Jul  5 14:26:12 2007
@@ -641,6 +641,7 @@
 };
 
 struct sip_socket {
+	ast_mutex_t *lock;
 	enum sip_transport type;
 	int fd;
 	short port;
@@ -1145,7 +1146,7 @@
 struct sip_peer {
 	ASTOBJ_COMPONENTS(struct sip_peer);	/*!< name, refcount, objflags,  object pointers */
 					/*!< peer->name is the unique name of this object */
-	enum sip_transport transport;
+	struct sip_socket socket;
 	char secret[80];		/*!< Password */
 	char md5secret[80];		/*!< Password in MD5 */
 	struct sip_auth *auth;		/*!< Realm authentication list */
@@ -1752,32 +1753,31 @@
 	char buf[1024];
 	struct sip_request req = { 0, }, reqcpy = { 0, };
 
+	req.socket.lock = ast_calloc(1, sizeof(*req.socket.lock));
+
+	if (!req.socket.lock)
+		goto cleanup;
+
+	ast_mutex_init(req.socket.lock);
+
 	for (;;) {
 		bzero(req.data, sizeof(req.data));
 		req.len = 0;
 
 		while (req.len < 4 || strncmp((char *)&req.data + req.len - 4, "\r\n\r\n", 4)) {
-			if (!fgets(buf, sizeof(buf), ser->f)) {
-				if (pvt)
-					pvt->socket.ser = NULL;
-				return NULL;
-			}
+			if (!fgets(buf, sizeof(buf), ser->f))
+				goto cleanup;
 
 			strncat(req.data, buf, sizeof(req.data) - req.len);
 			req.len = strlen(req.data);
 		}
 
-		memcpy(&reqcpy, &req, sizeof(req));
-
-		parse_request(&reqcpy);
+		parse_copy(&reqcpy, &req);
 
 		if (sscanf(get_header(&reqcpy, "Content-Length"), "%d", &cl)) {
 			while (cl > 0) {
-				if (!fread(buf, (cl < sizeof(buf)) ? cl : sizeof(buf), 1, ser->f)) {
-					if (pvt)
-						pvt->socket.ser = NULL;
-					return NULL;
-				}
+				if (!fread(buf, (cl < sizeof(buf)) ? cl : sizeof(buf), 1, ser->f))
+					goto cleanup;
 
 				cl -= strlen(buf);
 				strncat(req.data, buf, sizeof(req.data) - req.len);
@@ -1798,6 +1798,15 @@
 		req.socket.ser = ser;
 
 		handle_request_do(&req, &ser->requestor);
+	}
+
+cleanup:
+	ast_free(ser);
+	ast_free(req.socket.lock);
+
+	if (pvt) {
+		ast_debug(3, "Destroying sip session '%s', %s.", pvt->callid, strerror(errno));
+		sip_destroy(pvt);
 	}
 
 	return NULL;
@@ -2062,7 +2071,13 @@
 	if (p->socket.fd == -1)
 		return XMIT_ERROR;
 
+	if (p->socket.lock)
+		ast_mutex_lock(p->socket.lock);
+
 	res = sendto(p->socket.fd, data, len, 0, (const struct sockaddr *)dst, sizeof(struct sockaddr_in));
+
+	if (p->socket.lock)
+		ast_mutex_unlock(p->socket.lock);
 
 	if (res == -1) {
 		switch (errno) {
@@ -3110,7 +3125,8 @@
  */
 static int create_addr_from_peer(struct sip_pvt *dialog, struct sip_peer *peer)
 {
-	dialog->socket.type = peer->transport;
+	dialog->socket = peer->socket;
+
 	if ((peer->addr.sin_addr.s_addr || peer->defaddr.sin_addr.s_addr) &&
 	    (!peer->maxms || ((peer->lastms >= 0)  && (peer->lastms <= peer->maxms)))) {
 		dialog->sa = (peer->addr.sin_addr.s_addr) ? peer->addr : peer->defaddr;
@@ -3434,9 +3450,6 @@
 		update_call_counter(p, DEC_CALL_LIMIT);
 		ast_debug(2, "This call did not properly clean up call limits. Call ID %s\n", p->callid);
 	}
-
-	if (p->socket.ser)
-		ast_free(p->socket.ser);
 
 	/* Remove link from peer to subscription of MWI */
 	if (p->relatedpeer && p->relatedpeer->mwipvt) 
@@ -8654,6 +8667,8 @@
 		   with */
 		peer->addr = pvt->recv;
 	}
+
+	peer->socket = req->socket;
 
 	/* Save SIP options profile */
 	peer->sipoptions = pvt->sipoptions;
@@ -15997,6 +16012,7 @@
 	req.socket.type = SIP_TRANSPORT_UDP;
 	req.socket.ser	= NULL;
 	req.socket.port = ourport;
+	req.socket.lock = NULL;
 
 	handle_request_do(&req, &sin);
 
@@ -17167,9 +17183,9 @@
 			continue;
 		if (!strcasecmp(v->name, "transport")) {
 			if (!strcasecmp(v->value, "tcp")) {
-				peer->transport = SIP_TRANSPORT_TCP;
+				peer->socket.type = SIP_TRANSPORT_TCP;
 			} else if (!strcasecmp(v->value, "tls")) {
-				peer->transport = SIP_TRANSPORT_TLS;
+				peer->socket.type = SIP_TRANSPORT_TLS;
 			}
 		} else if (realtime && !strcasecmp(v->name, "regseconds")) {
 			ast_get_time_t(v->value, &regseconds, 0, NULL);
@@ -17346,8 +17362,8 @@
 	if (srvlookup) {
 		if (ast_get_ip_or_srv(&peer->addr, srvlookup, 
 								global_srvlookup ?  
-									((peer->transport & SIP_TRANSPORT_UDP) ? "_sip._udp" :
-									 (peer->transport & SIP_TRANSPORT_TCP) ? "_sip._tcp" :
+									((peer->socket.type & SIP_TRANSPORT_UDP) ? "_sip._udp" :
+									 (peer->socket.type & SIP_TRANSPORT_TCP) ? "_sip._tcp" :
 									 "_sip._tls")
 									: NULL)) {
 			unref_peer(peer);




More information about the asterisk-commits mailing list