[asterisk-commits] rizzo: branch rizzo/astobj2 r77629 - /team/rizzo/astobj2/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jul 28 04:03:22 CDT 2007


Author: rizzo
Date: Sat Jul 28 04:03:18 2007
New Revision: 77629

URL: http://svn.digium.com/view/asterisk?view=rev&rev=77629
Log:
merge from trunk register= handling

Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=77629&r1=77628&r2=77629
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Sat Jul 28 04:03:18 2007
@@ -962,25 +962,39 @@
 
 /*! \brief Parameters to know status of transfer */
 enum referstatus {
-        REFER_IDLE,                    /*!< No REFER is in progress */
-        REFER_SENT,                    /*!< Sent REFER to transferee */
-        REFER_RECEIVED,                /*!< Received REFER from transferrer */
-        REFER_CONFIRMED,               /*!< Refer confirmed with a 100 TRYING */
-        REFER_ACCEPTED,                /*!< Accepted by transferee */
-        REFER_RINGING,                 /*!< Target Ringing */
-        REFER_200OK,                   /*!< Answered by transfer target */
-        REFER_FAILED,                  /*!< REFER declined - go on */
-        REFER_NOAUTH                   /*!< We had no auth for REFER */
+        REFER_IDLE,		/*!< No REFER is in progress */
+        REFER_SENT,		/*!< Sent REFER to transferee */
+        REFER_RECEIVED,		/*!< Received REFER from transferrer */
+	REFER_CONFIRMED,	/*!< Refer confirmed with a 100 TRYING (unused) */
+        REFER_ACCEPTED,		/*!< Accepted by transferee */
+        REFER_RINGING,		/*!< Target Ringing */
+        REFER_200OK,		/*!< Answered by transfer target */
+        REFER_FAILED,		/*!< REFER declined - go on */
+        REFER_NOAUTH		/*!< We had no auth for REFER */
 };
 
-/*!
- * generic struct to map between strings and integers.
- * Must be terminated by s = NULL;
+/*! \brief generic struct to map between strings and integers.
+ * Fill it with x-s pairs, terminate with an entry with s = NULL;
+ * Then you can call map_x_s(...) to map an integer to a string,
+ * and map_s_x() for the string -> integer mapping.
  */
 struct _map_x_s {
 	int x;
 	const char *s;
 };
+
+static const struct _map_x_s referstatusstrings[] = {
+	{ REFER_IDLE,		"<none>" },
+	{ REFER_SENT,		"Request sent" },
+	{ REFER_RECEIVED,	"Request received" },
+	{ REFER_CONFIRMED,	"Confirmed" },
+	{ REFER_ACCEPTED,	"Accepted" },
+	{ REFER_RINGING,	"Target ringing" },
+	{ REFER_200OK,		"Done" },
+	{ REFER_FAILED,		"Failed" },
+	{ REFER_NOAUTH,		"Failed - auth failure" },
+	{ -1,			NULL} /* terminator */
+} ;
 
 /*! \brief Structure to handle SIP transfers. Dynamically allocated when needed
 	\note OEJ: Should be moved to string fields */
@@ -1004,12 +1018,10 @@
 	enum referstatus status;			/*!< REFER status */
 };
 
-/*!
- * PVT structures are used for each SIP dialog, ie. a call, a registration, a subscribe.
+/*! \brief sip_pvt: structures used for each SIP dialog, ie. a call, a registration, a subscribe.
  * Created and initialized by sip_alloc(), the descriptor goes into the list of
- * descriptors (dialoglist), and there it stays i suppose forever
+ * descriptors (dialoglist).
  */
-
 struct sip_pvt {
 #ifndef USE_AO2
 	struct sip_pvt *next;			/*!< Next dialog in chain */
@@ -1801,28 +1813,31 @@
 	.description = "Session Initiation Protocol (SIP)",
 	.capabilities = ((AST_FORMAT_MAX_AUDIO << 1) - 1),
 	.properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER,
-	.requester = sip_request_call,	/* called with chan unlocked */
-	.devicestate = sip_devicestate,	/* called with chan unlocked (not chan-specific) */
-	.call = sip_call,		/* called with chan locked */
-	.hangup = sip_hangup,		/* called with chan locked */
-	.answer = sip_answer,		/* called with chan locked */
-	.read = sip_read,		/* called with chan locked */
-	.write = sip_write,		/* called with chan locked */
-	.write_video = sip_write,		/* called with chan locked */
-	.write_text = sip_write,	/* XXX */
-	.indicate = sip_indicate,	/* called with chan locked */
-	.transfer = sip_transfer,		/* called with chan locked */
-	.fixup = sip_fixup,		/* called with chan locked */
+	.requester = sip_request_call,
+	.devicestate = sip_devicestate,
+	.call = sip_call,
+	.hangup = sip_hangup,
+	.answer = sip_answer,
+	.read = sip_read,
+	.write = sip_write,
+	.write_video = sip_write,
+	.write_text = sip_write,
+	.indicate = sip_indicate,
+	.transfer = sip_transfer,
+	.fixup = sip_fixup,
 	.send_digit_end = sip_senddigit_end,
-	.bridge = ast_rtp_bridge,	/* XXX chan unlocked ? */
+	.bridge = ast_rtp_bridge,
 	.early_bridge = ast_rtp_early_bridge,
-	.send_text = sip_sendtext,	/* called with chan locked */
+	.send_text = sip_sendtext,
+	.func_channel_read = acf_channel_read,
 };
 
 /* wrapper macro to tell whether t points to one of the sip_tech descriptors */
 #define IS_SIP_TECH(t)	((t) == &sip_tech || (t) == &sip_tech_info)
 
-/*! \begin map from an integer value to a string */
+/*! \begin map from an integer value to a string.
+ * If no match is found, return errorstring
+ */
 static const char *map_x_s(const struct _map_x_s *table, int x, const char *errorstring)
 {
 	const struct _map_x_s *cur;
@@ -1833,7 +1848,9 @@
 	return errorstring;
 }
 
-/*! \begin map from a string to an integer value */
+/*! \begin map from a string to an integer value, case insensitive.
+ * If no match is found, return errorvalue.
+ */
 static int map_s_x(const struct _map_x_s *table, const char *s, int errorvalue)
 {
 	const struct _map_x_s *cur;
@@ -1973,17 +1990,6 @@
 static void append_history_full(struct sip_pvt *p, const char *fmt, ...)
 	__attribute__ ((format (printf, 2, 3)));
  
-static const struct _map_x_s referstatusstrings[] = {
-	{ REFER_IDLE,		"<none>" },
-	{ REFER_SENT,		"Request sent" },
-	{ REFER_RECEIVED,	"Request received" },
-	{ REFER_ACCEPTED,	"Accepted" },
-	{ REFER_RINGING,	"Target ringing" },
-	{ REFER_200OK,		"Done" },
-	{ REFER_FAILED,		"Failed" },
-	{ REFER_NOAUTH,		"Failed - auth failure" },
-	{ -1,			NULL} /* terminator */
-} ;
 
 /*! \brief Convert transfer status to string */
 static const char *referstatus2str(enum referstatus rstatus)
@@ -8306,9 +8312,10 @@
 	else if (!ast_strlen_zero(r->nonce)) {
 		char digest[1024];
 
-		/* We have auth data to reuse, build a digest header!
-		 * Actually this doesn't seem terribly useful, as some parties usually
-		 * do not like the old nonce (for good reasons) and challenge us again.
+		/* We have auth data to reuse, build a digest header.
+		 * Note, this is not always useful because some parties do not
+		 * like nonces to be reused (for good reasons!) so they will
+		 * challenge us anyways.
 		 */
 		if (sipdebug)
 			ast_debug(1, "   >>> Re-using Auth data for %s@%s\n", r->username, r->hostname);
@@ -9154,6 +9161,7 @@
 
 	/* If they put someone on hold, increment the value... otherwise decrement it */
 	ast_atomic_fetchadd_int(&peer->onHold, (hold ? +1 : -1) );
+
 	/* Request device state update */
 	ast_device_state_changed("SIP/%s", peer->name);
 
@@ -9176,6 +9184,8 @@
 static int cb_extensionstate(char *context, char* exten, int state, void *data)
 {
 	struct sip_pvt *p = data;
+
+	sip_pvt_lock(p);
 
 	switch(state) {
 	case AST_EXTENSION_DEACTIVATED:	/* Retry after a while */
@@ -9195,8 +9205,10 @@
 	if (p->subscribed != NONE)	/* Only send state NOTIFY if we know the format */
 		transmit_state_notify(p, state, 1, FALSE);
 
-	if (option_verbose > 1)
-		ast_verbose(VERBOSE_PREFIX_1 "Extension Changed %s new state %s for Notify User %s\n", exten, ast_extension_state2str(state), p->username);
+	ast_verb(1, "Extension Changed %s new state %s for Notify User %s\n", exten, ast_extension_state2str(state), p->username);
+
+	sip_pvt_unlock(p);
+
 	return 0;
 }
 
@@ -9901,8 +9913,13 @@
 
 /*! \brief check received= and rport= in a SIP response.
  * If we get a response with received= and/or rport= in the Via:
- * line, we can use them as 'ourip' (see RFC 3581 for rport,
- * and RFC 3261 for received (?)
+ * line, use them as 'p->ourip' (see RFC 3581 for rport,
+ * and RFC 3261 for received).
+ * Using these two fields SIP can produce the correct
+ * address and port in the SIP headers without the need for STUN.
+ * The address part is also reused for the media sessions.
+ * Note that ast_sip_ouraddrfor() still rewrites p->ourip
+ * if you specify externip/seternaddr/stunaddr.
  */
 static void check_via_response(struct sip_pvt *p, struct sip_request *req)
 {
@@ -9917,21 +9934,18 @@
 		*opts = '\0';
 
 	/* parse all relevant options */
-	ast_log(LOG_WARNING, "doing Via: %s\n", via);
 	opts = strchr(via, ';');
 	if (!opts)
-		return;	/* no options to parse */
+		return; /* no options to parse */
 	*opts++ = '\0';
 	while ( (cur = strsep(&opts, ";")) ) {
 		if (!strncmp(cur, "rport=", 6)) {
 			int port = strtol(cur+6, NULL, 10);
-			ast_log(LOG_WARNING, "found rport: %s\n", cur);
-			/* XXX error checking */
+			/* XXX add error checking */
 			p->ourip.sin_port = ntohs(port);
 		} else if (!strncmp(cur, "received=", 9)) {
-			ast_log(LOG_WARNING, "found received: %s\n", cur);
 			if (ast_parse_arg(cur+9, PARSE_INADDR, &p->ourip))
-				;	/* XXX error checking */
+				;       /* XXX add error checking */
 		}
 	}
 }
@@ -11741,6 +11755,7 @@
 );
 		arg->numchans++;
 	}
+
 	return 0;	/* don't care, we scan all channels */
 }
 
@@ -14126,31 +14141,27 @@
 	}
 	ast_channel_unlock(transferer);
 	if (!transferer || !transferee) {
-		if (!transferer)
+		if (!transferer) {
 			ast_debug(1, "No transferer channel, giving up parking\n");
-		if (!transferee)
+		}
+		if (!transferee) {
 			ast_debug(1, "No transferee channel, giving up parking\n");
+		}
 		return -1;
 	}
 	if ((d = ast_calloc(1, sizeof(*d)))) {
-		pthread_attr_t attr;
-
-  		pthread_attr_init(&attr);
-		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-  	 
+
 		/* Save original request for followup */
 		copy_request(&d->req, req);
 		d->chan1 = transferee;	/* Transferee */
 		d->chan2 = transferer;	/* Transferer */
 		d->seqno = seqno;
-		if (ast_pthread_create_background(&th, &attr, sip_park_thread, d) < 0) {
+		if (ast_pthread_create_detached_background(&th, NULL, sip_park_thread, d) < 0) {
 			/* Could not start thread */
 			ast_free(d);	/* We don't need it anymore. If thread is created, d will be free'd
 					   by sip_park_thread() */
-			pthread_attr_destroy(&attr);
 			return 0;
 		}
-		pthread_attr_destroy(&attr);
 	} 
 	return -1;
 }
@@ -16522,9 +16533,11 @@
 	}
 
 	/*! \todo Check video RTP keepalives
+
 	       Do we need to move the lastrtptx to the RTP structure to have one for audio and one
 	       for video? It really does belong to the RTP structure.
   	 */
+
 	/* XXX probably wrong check if rtptimeout == 0 */
 	/* Check AUDIO RTP timers */
 	if (! (dialog->lastrtprx && (ast_rtp_get_rtptimeout(dialog->rtp) || ast_rtp_get_rtpholdtimeout(dialog->rtp)) &&
@@ -16650,9 +16663,9 @@
 		}
 		ast_mutex_unlock(&monlock);
 	}
+
 	/* Never reached */
 	return NULL;
-	
 }
 
 /*! \brief Start the channel monitor thread */
@@ -17871,6 +17884,7 @@
 #if 0 /* XXX fixme */
 		M_F("outboundproxy", {
 			char *name, *port = NULL, *force;
+
 			name = ast_strdupa(v->value);
 			/* XXX use strsep here */
 			if ((port = strchr(name, ':'))) {
@@ -18386,6 +18400,7 @@
 
 	return res;
 }
+
 /*! \brief Set the RTP peer for this call */
 static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active)
 {




More information about the asterisk-commits mailing list