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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jun 30 17:14:23 CDT 2007


Author: rizzo
Date: Sat Jun 30 17:14:23 2007
New Revision: 72801

URL: http://svn.digium.com/view/asterisk?view=rev&rev=72801
Log:
merge from trunk up to svn 62457 (with local modifications e.g.
config file parsing and the handling of the listening socket).

This now compiles.

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=72801&r1=72800&r2=72801
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Sat Jun 30 17:14:23 2007
@@ -137,12 +137,14 @@
 #include "asterisk/linkedlists.h"
 #include "asterisk/stringfields.h"
 #include "asterisk/monitor.h"
+#include "asterisk/netsock.h"
 #include "asterisk/localtime.h"
 #include "asterisk/abstract_jb.h"
 #include "asterisk/compiler.h"
 #include "asterisk/threadstorage.h"
 #include "asterisk/translate.h"
 #include "asterisk/version.h"
+#include "asterisk/event.h"
 
 #ifndef FALSE
 #define FALSE    0
@@ -479,7 +481,6 @@
 #define DEFAULT_VMEXTEN 	"asterisk"
 #define DEFAULT_CALLERID 	"asterisk"
 #define DEFAULT_NOTIFYMIME 	"application/simple-message-summary"
-#define DEFAULT_MWITIME 	10
 #define DEFAULT_ALLOWGUEST	TRUE
 #define DEFAULT_SRVLOOKUP	FALSE		/*!< Recommended setting is ON */
 #define DEFAULT_COMPACTHEADERS	FALSE
@@ -487,6 +488,10 @@
 #define DEFAULT_TOS_AUDIO       0               /*!< Audio packets should be marked as DSCP EF (Expedited Forwarding), but the default is 0 to be compatible with previous versions. */
 #define DEFAULT_TOS_VIDEO       0               /*!< Video packets should be marked as DSCP AF41, but the default is 0 to be compatible with previous versions. */
 #define DEFAULT_TOS_TEXT        0               /*!< Text packets should be marked as XXXX XXXX, but the default is 0 to be compatible with previous versions. */
+#define DEFAULT_COS_SIP         4
+#define DEFAULT_COS_AUDIO       5
+#define DEFAULT_COS_VIDEO       6
+#define DEFAULT_COS_TEXT        0
 #define DEFAULT_ALLOW_EXT_DOM	TRUE
 #define DEFAULT_REALM		"asterisk"
 #define DEFAULT_NOTIFYRINGING	TRUE
@@ -551,11 +556,14 @@
 static int global_allowguest;		/*!< allow unauthenticated users/peers to connect? */
 static int global_allowsubscribe;	/*!< Flag for disabling ALL subscriptions, this is FALSE only if all peers are FALSE 
 					    the global setting is in globals_flags[1] */
-static int global_mwitime;		/*!< Time between MWI checks for peers */
 static unsigned int global_tos_sip;		/*!< IP type of service for SIP packets */
 static unsigned int global_tos_audio;		/*!< IP type of service for audio RTP packets */
 static unsigned int global_tos_video;		/*!< IP type of service for video RTP packets */
 static unsigned int global_tos_text;            /*!< IP type of service for text RTP packets */
+static unsigned int global_cos_sip;		/*!< 802.1p class of service for SIP packets */
+static unsigned int global_cos_audio;		/*!< 802.1p class of service for audio RTP packets */
+static unsigned int global_cos_video;		/*!< 802.1p class of service for video RTP packets */
+static unsigned int global_cos_text;		/*!< 802.1p class of service for text RTP packets */
 static int compactheaders;		/*!< send compact sip headers */
 static int recordhistory;		/*!< Record SIP history. Off by default */
 static int dumphistory;			/*!< Dump history to verbose before destroying SIP dialog */
@@ -1225,7 +1233,6 @@
 	char mailbox[AST_MAX_EXTENSION]; /*!< Mailbox setting for MWI checks */
 	char register_from_hdr[256];	/*!<  'From' header received in REGISTER */
 	int lastmsgssent;
-	time_t	lastmsgcheck;		/*!<  Last time we checked for MWI */
 	int expire;			/*!<  When to expire this peer registration */
 	int rtptimeout;			/*!<  RTP timeout */
 	int rtpholdtimeout;		/*!<  RTP Hold Timeout */
@@ -1242,6 +1249,7 @@
 	struct sockaddr_in defaddr;	/*!<  Default IP address, used until registration */
 	struct sip_pvt *mwipvt;		/*!<  Subscription for MWI */
 	int lastmsg;
+	struct ast_event_sub *mwi_event_sub; /*!< The MWI event subscription */
 };
 
 
@@ -1441,8 +1449,7 @@
 static void copy_request(struct sip_request *dst, const struct sip_request *src);
 static void receive_message(struct sip_pvt *p, struct sip_request *req);
 static void parse_moved_contact(struct sip_pvt *p, struct sip_request *req);
-static int sip_send_mwi_to_peer(struct sip_peer *peer);
-static int does_peer_need_mwi(struct sip_peer *peer);
+static int sip_send_mwi_to_peer(struct sip_peer *peer, const struct ast_event *event, int cache_only);
 
 /*--- Dialog management */
 static struct sip_pvt *sip_alloc(ast_string_field callid, struct sockaddr_in *sin,
@@ -1511,20 +1518,20 @@
 static int expire_register(void *data);
 static void *do_monitor(void *data);
 static int restart_monitor(void);
-static int sip_send_mwi_to_peer(struct sip_peer *peer);
 static int sip_addrcmp(char *name, struct sockaddr_in *sin);	/* Support for peer matching */
 static int sip_refer_allocate(struct sip_pvt *p);
 static void sip_refer_destroy(struct sip_pvt *p);
 static void ast_quiet_chan(struct ast_channel *chan);
 static int attempt_transfer(struct sip_dual *transferer, struct sip_dual *target);
 
-/*--- Device monitoring and Device/extension state handling */
+/*--- Device monitoring and Device/extension state/event handling */
 static int cb_extensionstate(char *context, char* exten, int state, void *data);
 static int sip_devicestate(void *data);
 static int sip_poke_noanswer(void *data);
 static int sip_poke_peer(struct sip_peer *peer);
 static void sip_poke_all_peers(void);
 static void sip_peer_hold(struct sip_pvt *p, int hold);
+static void mwi_event_cb(const struct ast_event *, void *);
 
 /*--- Applications, functions, CLI and manager command helpers */
 static const char *sip_nat_mode(const struct sip_pvt *p);
@@ -1555,7 +1562,9 @@
 static const struct cfsubscription_types *find_subscription_type(enum subscriptiontype subtype);
 static char *complete_sipch(const char *line, const char *word, int pos, int state);
 static char *complete_sip_peer(const char *word, int state, int flags2);
+static char *complete_sip_registered_peer(const char *word, int state, int flags2);
 static char *complete_sip_show_peer(const char *line, const char *word, int pos, int state);
+static char *complete_sip_unregister(const char *line, const char *word, int pos, int state);
 static char *complete_sip_user(const char *word, int state, int flags2);
 static char *complete_sip_show_user(const char *line, const char *word, int pos, int state);
 static char *complete_sipnotify(const char *line, const char *word, int pos, int state);
@@ -2874,6 +2883,11 @@
 
 	if (peer->mwipvt) 	/* We have an active subscription, delete it */
 		peer->mwipvt = sip_destroy(peer->mwipvt);
+
+	if (peer->mwi_event_sub) {
+		ast_event_unsubscribe(peer->mwi_event_sub);
+		peer->mwi_event_sub = NULL;
+	}
 
 	if (peer->chanvars) {
 		ast_variables_destroy(peer->chanvars);
@@ -4912,14 +4926,14 @@
 				ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT) ? "and text " : "", strerror(errno));
 			return __sip_destroy(p);
 		}
+		ast_rtp_setqos(p->rtp, global_tos_audio, global_cos_audio);
 		ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
 		ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
-		ast_rtp_settos(p->rtp, global_tos_audio);
 		ast_rtp_set_rtptimeout(p->rtp, global_rtptimeout);
 		ast_rtp_set_rtpholdtimeout(p->rtp, global_rtpholdtimeout);
 		ast_rtp_set_rtpkeepalive(p->rtp, global_rtpkeepalive);
 		if (p->vrtp) {
-			ast_rtp_settos(p->vrtp, global_tos_video);
+			ast_rtp_setqos(p->vrtp, global_tos_video, global_cos_video);
 			ast_rtp_setdtmf(p->vrtp, 0);
 			ast_rtp_setdtmfcompensate(p->vrtp, 0);
 			ast_rtp_set_rtptimeout(p->vrtp, global_rtptimeout);
@@ -4927,12 +4941,12 @@
 			ast_rtp_set_rtpkeepalive(p->vrtp, global_rtpkeepalive);
 		}
 		if (p->trtp) {
-			ast_rtp_settos(p->trtp, global_tos_text);
+			ast_rtp_setqos(p->trtp, global_tos_text, global_cos_text);
 			ast_rtp_setdtmf(p->trtp, 0);
 			ast_rtp_setdtmfcompensate(p->trtp, 0);
 		}
 		if (p->udptl)
-			ast_udptl_settos(p->udptl, global_tos_audio);
+			ast_udptl_setqos(p->udptl, global_tos_audio, global_cos_audio);
 		p->maxcallbitrate = default_maxcallbitrate;
 		ast_mark(prof_rtp, 0);
 	}
@@ -9091,6 +9105,16 @@
 	return;
 }
 
+/*! \brief Receive MWI events that we have subscribed to */
+static void mwi_event_cb(const struct ast_event *event, void *userdata)
+{
+	struct sip_peer *peer = userdata;
+
+	ASTOBJ_RDLOCK(peer);
+	sip_send_mwi_to_peer(peer, event, 0);
+	ASTOBJ_UNLOCK(peer);
+}
+
 /*! \brief Callback for the devicestate notification (SUBSCRIBE) support subsystem
 \note	If you add an "hint" priority to the extension in the dial plan,
 	you will get notifications on device state changes */
@@ -9218,7 +9242,7 @@
 			if (!(res = check_auth(p, req, peer->name, peer->secret, peer->md5secret, SIP_REGISTER, uri, XMIT_UNRELIABLE, req_ignore(req)))) {
 				sip_cancel_destroy(p);
 
-				/* We have a succesful registration attemp with proper authentication,
+				/* We have a succesful registration attempt with proper authentication,
 				   now, update the peer */
 				switch (parse_register_contact(p, peer, req)) {
 				case PARSE_REGISTER_FAILED:
@@ -11366,7 +11390,10 @@
 #undef FORMAT2
 }
 
-/*! \brief Unregister (force expiration) a SIP peer in the registry via CLI */
+/*! \brief Unregister (force expiration) a SIP peer in the registry via CLI 
+	\note This function does not tell the SIP device what's going on,
+	so use it with great care.
+*/
 static int sip_unregister(int fd, int argc, char *argv[])
 {
 	struct sip_peer *peer;
@@ -11379,7 +11406,7 @@
 		expire_register(peer);
 		ast_cli(fd, "Unregistered peer \'%s\'\n\n", argv[2]);
 	} else {
-		ast_cli(fd, "Attempted to unregister an unknown peer \'%s\' via CLI\n", argv[2]);
+		ast_cli(fd, "Peer unknown: \'%s\'. Not unregistered.\n", argv[2]);
 	}
 	
 	return 0;
@@ -11420,7 +11447,6 @@
 	ast_cli(fd, "  Call limit peers only:  %s\n", global_limitonpeers ? "Yes" : "No");
 	ast_cli(fd, "  Direct RTP setup:       %s\n", global_directrtpsetup ? "Yes" : "No");
 	ast_cli(fd, "  User Agent:             %s\n", global_useragent);
-	ast_cli(fd, "  MWI checking interval:  %d secs\n", global_mwitime);
 	ast_cli(fd, "  Reg. context:           %s\n", S_OR(global_regcontext, "(not set)"));
 	ast_cli(fd, "  Caller ID:              %s\n", default_callerid);
 	ast_cli(fd, "  From: Domain:           %s\n", default_fromdomain);
@@ -11430,6 +11456,11 @@
 	ast_cli(fd, "  IP ToS RTP audio:       %s\n", ast_tos2str(global_tos_audio));
 	ast_cli(fd, "  IP ToS RTP video:       %s\n", ast_tos2str(global_tos_video));
 	ast_cli(fd, "  IP ToS RTP text:        %s\n", ast_tos2str(global_tos_text));
+	ast_cli(fd, "  802.1p CoS SIP:         %d\n", global_cos_sip);
+	ast_cli(fd, "  802.1p CoS RTP audio:   %d\n", global_cos_audio);
+	ast_cli(fd, "  802.1p CoS RTP video:   %d\n", global_cos_video);
+	ast_cli(fd, "  802.1p CoS RTP text:    %d\n", global_cos_text);
+
 	ast_cli(fd, "  T38 fax pt UDPTL:       %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT_UDPTL) ? "Yes" : "No");
 #ifdef WHEN_WE_HAVE_T38_FOR_OTHER_TRANSPORTS
 	ast_cli(fd, "  T38 fax pt RTP:         %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT_RTP) ? "Yes" : "No");
@@ -11669,6 +11700,24 @@
 	return result;
 }
 
+/*! \brief Do completion on registered peer name */
+static char *complete_sip_registered_peer(const char *word, int state, int flags2)
+{
+	char *result = NULL;
+	int wordlen = strlen(word);
+	int which = 0;
+
+	ASTOBJ_CONTAINER_TRAVERSE(&peerl, !result, do {
+		ASTOBJ_WRLOCK(iterator);
+		if (!strncasecmp(word, iterator->name, wordlen) &&
+			(!flags2 || ast_test_flag(&iterator->flags[1], flags2)) &&
+				++which > state && iterator->expire > 0)
+			result = ast_strdup(iterator->name);
+		ASTOBJ_UNLOCK(iterator);
+	} while(0) );
+	return result;
+}
+
 /*! \brief Support routine for 'sip show peer' CLI */
 static char *complete_sip_show_peer(const char *line, const char *word, int pos, int state)
 {
@@ -11703,6 +11752,15 @@
 {
 	if (pos == 3)
 		return complete_sip_user(word, state, 0);
+
+	return NULL;
+}
+
+/*! \brief Support routine for 'sip unregister' CLI */
+static char *complete_sip_unregister(const char *line, const char *word, int pos, int state)
+{
+	if (pos == 2)
+		return complete_sip_registered_peer(word, state, 0);
 
 	return NULL;
 }
@@ -15384,8 +15442,8 @@
 		return 0;
 	}
 
-	if (strcasecmp(args.param, "rtpqos"))
-		return 0;
+	if (ast_strlen_zero(args.param) || strcasecmp(args.param, "rtpqos"))
+		return -1;
 
 	memset(buf, 0, buflen);
 	memset(&qos, 0, sizeof(qos));
@@ -15397,6 +15455,9 @@
 	} else if (strcasecmp(args.type, "TEXT") == 0) {
 		all = ast_rtp_get_quality(p->trtp, &qos);
 	}
+
+	if (ast_strlen_zero(args.field))
+		return -1;
 
 	if (strcasecmp(args.field, "local_ssrc") == 0)
 		snprintf(buf, buflen, "%u", qos.local_ssrc);
@@ -15704,6 +15765,11 @@
 		}
 
 		p->subscribed = MWI_NOTIFICATION;
+		if (ast_test_flag(&authpeer->flags[1], SIP_PAGE2_SUBSCRIBEMWIONLY)) {
+			authpeer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, authpeer,
+				AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, authpeer->mailbox,
+				AST_EVENT_IE_END);
+		}
 		if (authpeer->mwipvt) {
 			/* We only allow one subscription per peer */
 			if (authpeer->mwipvt != p)	/* Destroy old PVT if this is a new one */
@@ -15753,7 +15819,7 @@
 			transmit_response(p, "200 OK", req);
 			if (p->relatedpeer) {	/* Send first notification */
 				ASTOBJ_WRLOCK(p->relatedpeer);
-				sip_send_mwi_to_peer(p->relatedpeer);
+				sip_send_mwi_to_peer(p->relatedpeer, NULL, 0);
 				ASTOBJ_UNLOCK(p->relatedpeer);
 			}
 		} else {
@@ -16243,24 +16309,34 @@
 }
 
 /*! \brief Send message waiting indication to alert peer that they've got voicemail */
-static int sip_send_mwi_to_peer(struct sip_peer *peer)
+static int sip_send_mwi_to_peer(struct sip_peer *peer, const struct ast_event *event, int cache_only)
 {
 	/* Called with peerl lock, but releases it */
 	struct sip_pvt *p;
-	int newmsgs, oldmsgs;
-
-	/* Check for messages */
-	ast_app_inboxcount(peer->mailbox, &newmsgs, &oldmsgs);
-	
-	peer->lastmsgcheck = time(NULL);
-	
-	/* Return now if it's the same thing we told them last time */
-	if (((newmsgs > 0x7fff ? 0x7fff0000 : (newmsgs << 16)) | (oldmsgs > 0xffff ? 0xffff : oldmsgs)) == peer->lastmsgssent) {
+	int newmsgs = 0, oldmsgs = 0;
+	struct ast_event *cache_event = NULL;
+
+	if (ast_test_flag((&peer->flags[1]), SIP_PAGE2_SUBSCRIBEMWIONLY) && !peer->mwipvt)
 		return 0;
-	}
-	
-	
-	peer->lastmsgssent = ((newmsgs > 0x7fff ? 0x7fff0000 : (newmsgs << 16)) | (oldmsgs > 0xffff ? 0xffff : oldmsgs));
+
+	if (!event) {
+		/* Check the event cache for the mailbox info */
+		event = cache_event = ast_event_get_cached(AST_EVENT_MWI,
+			AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, peer->mailbox,
+			AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
+			AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
+			AST_EVENT_IE_END);
+	}
+
+	if (event) {
+		newmsgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
+		oldmsgs = ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS);
+		if (cache_event)
+			ast_event_destroy(cache_event);
+	} else if (cache_only) {
+		return 0;
+	} else /* Fall back to manually checking the mailbox */
+		ast_app_inboxcount(peer->mailbox, &newmsgs, &oldmsgs);
 
 	if (peer->mwipvt) {
 		/* Base message on subscription */
@@ -16282,30 +16358,13 @@
 		/* Destroy this session after 32 secs */
 		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
 	}
+
 	/* Send MWI */
 	ast_set_flag(&p->flags[0], SIP_OUTGOING);
 	transmit_notify_with_mwi(p, newmsgs, oldmsgs, peer->vmexten);
 	pvt_unref(p);
 	return 0;
 }
-
-/*! \brief Check whether peer needs a new MWI notification check */
-static int does_peer_need_mwi(struct sip_peer *peer)
-{
-	time_t t = time(NULL);
-
-	if (ast_test_flag(&peer->flags[1], SIP_PAGE2_SUBSCRIBEMWIONLY) &&
-	    !peer->mwipvt) {	/* We don't have a subscription */
-		peer->lastmsgcheck = t;	/* Reset timer */
-		return FALSE;
-	}
-
-	if (!ast_strlen_zero(peer->mailbox) && (t - peer->lastmsgcheck) > global_mwitime)
-		return TRUE;
-
-	return FALSE;
-}
-
 
 /*!
  * helper function for the monitoring thread.
@@ -16386,10 +16445,6 @@
 static void *do_monitor(void *data)
 {
 	int res;
-	struct sip_peer *peer = NULL;
-	int fastrestart = FALSE;
-	int lastpeernum = -1;
-	int curpeernum;
 	int reloading;
 
 	/* From here on out, we die whenever asked */
@@ -16405,11 +16460,7 @@
 			sip_do_reload(sip_reloadreason);
 		}
 		/* Check for dialogs needing to be killed */
-		/* don't scan the dialogs list if it hasn't been a reasonable period
-		   of time since the last time we did it (when MWI is being sent, we can
-		   get back to this point every millisecond or less)
-		*/
-		if (!fastrestart) {
+		{	
 			struct sip_pvt *cur, *prev = NULL;
 			time_t t = time(NULL);
 #ifdef USE_AO2
@@ -16459,9 +16510,6 @@
 		res = ast_sched_wait(sched);
 		if ((res < 0) || (res > 1000))
 			res = 1000;
-		/* If we might need to send more mailboxes, don't wait long at all.*/
-		if (fastrestart)
-			res = 1;
 		res = ast_io_wait(io, res);
 		if (option_debug && res > 20)
 			ast_log(LOG_DEBUG, "chan_sip: ast_io_wait ran %d all at once\n", res);
@@ -16470,31 +16518,6 @@
 			res = ast_sched_runq(sched);
 			if (option_debug && res >= 20)
 				ast_log(LOG_DEBUG, "chan_sip: ast_sched_runq ran %d all at once\n", res);
-		}
-
-		/* Send MWI notifications to peers - static and cached realtime peers */
-		fastrestart = FALSE;
-		curpeernum = 0;
-		peer = NULL;
-		/* Find next peer that needs mwi */
-		ASTOBJ_CONTAINER_TRAVERSE(&peerl, !peer, do {
-			if ((curpeernum > lastpeernum) && does_peer_need_mwi(iterator)) {
-				fastrestart = TRUE;
-				lastpeernum = curpeernum;
-				peer = ASTOBJ_REF(iterator);
-			};
-			curpeernum++;
-		} while (0)
-		);
-		/* Send MWI to the peer */
-		if (peer) {
-			ASTOBJ_WRLOCK(peer);
-			sip_send_mwi_to_peer(peer);
-			ASTOBJ_UNLOCK(peer);
-			unref_peer(peer);
-		} else {
-			/* Reset where we come from */
-			lastpeernum = -1;
 		}
 		ast_mutex_unlock(&monlock);
 	}
@@ -17318,7 +17341,6 @@
 	struct ast_flags peerflags[2] = {{(0)}};
 	struct ast_flags mask[2] = {{(0)}};
 	char callback[256] = "";
-
 
 	if (!realtime)
 		/* Note we do NOT use find_peer here, to avoid realtime recursion */
@@ -17508,6 +17530,20 @@
 		global_allowsubscribe = TRUE;	/* No global ban any more */
 	if (!found && ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC) && !ast_test_flag(&peer->flags[0], SIP_REALTIME))
 		reg_source_db(peer);
+
+	/* If they didn't request that MWI is sent *only* on subscribe, go ahead and
+	 * subscribe to it now. */
+	if (!ast_test_flag(&peer->flags[1], SIP_PAGE2_SUBSCRIBEMWIONLY) && 
+		!ast_strlen_zero(peer->mailbox)) {
+		peer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, peer,
+			AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, peer->mailbox,
+			AST_EVENT_IE_END);
+		/* Send MWI from the event cache only.  This is so we can send initial
+		 * MWI if app_voicemail got loaded before chan_sip.  If it is the other
+		 * way, then we will get events when app_voicemail gets loaded. */
+		sip_send_mwi_to_peer(peer, NULL, 1);
+	}
+
 	ASTOBJ_UNMARK(peer);
 	ast_free_ha(oldha);
 	if (!ast_strlen_zero(callback)) { /* build string from peer info */
@@ -17577,6 +17613,11 @@
 	global_tos_audio = DEFAULT_TOS_AUDIO;
 	global_tos_video = DEFAULT_TOS_VIDEO;
 	global_tos_text = DEFAULT_TOS_TEXT;
+	global_cos_sip = DEFAULT_COS_SIP;
+	global_cos_audio = DEFAULT_COS_AUDIO;
+	global_cos_video = DEFAULT_COS_VIDEO;
+	global_cos_text = DEFAULT_COS_TEXT;
+
 	externhost[0] = '\0';			/* External host name (for behind NAT DynDNS support) */
 	externexpire = 0;			/* Expiration for DNS re-issuing */
 	externrefresh = 10;
@@ -17599,7 +17640,6 @@
 	global_reg_timeout = DEFAULT_REGISTRATION_TIMEOUT;
 	global_regattempts_max = 0;
 	pedanticsipchecking = DEFAULT_PEDANTIC;
-	global_mwitime = DEFAULT_MWITIME;
 	autocreatepeer = DEFAULT_AUTOCREATEPEER;
 	global_autoframing = 0;
 	global_allowguest = DEFAULT_ALLOWGUEST;
@@ -17674,7 +17714,6 @@
 		M_F("usereqphone", ast_set2_flag(&global_flags[0], ast_true(v->value), SIP_USEREQPHONE);)
 		M_BOOL("relaxdtmf", global_relaxdtmf)
 		M_BOOL("allowguest", global_allowguest)
-		M_INT_GE0("checkmwi", global_mwitime, DEFAULT_MWITIME)
 		M_STR("vmexten", default_vmexten)
 		M_INT_GE0("rtptimeout", global_rtptimeout, 0)
 		M_INT_GE0("rtpholdtimeout", global_rtpholdtimeout, 0)
@@ -17784,16 +17823,22 @@
 				registry_count++; } )
 		M_F("tos_sip", {
 			if (ast_str2tos(v->value, &global_tos_sip))
-				ast_log(LOG_WARNING, "Invalid tos_sip value at line %d, recommended value is 'cs3'. See doc/ip-tos.txt.\n", v->lineno); } )
+				ast_log(LOG_WARNING, "Invalid tos_sip value at line %d, recommended value is 'cs3'. See doc/qos.tex.\n", v->lineno); } )
+
 		M_F("tos_audio", {
 			if (ast_str2tos(v->value, &global_tos_audio))
-				ast_log(LOG_WARNING, "Invalid tos_audio value at line %d, recommended value is 'ef'. See doc/ip-tos.txt.\n", v->lineno); } )
+				ast_log(LOG_WARNING, "Invalid tos_audio value at line %d, recommended value is 'ef'. See doc/qos.tex.\n", v->lineno); } )
+
 		M_F("tos_video", {
 			if (ast_str2tos(v->value, &global_tos_video))
-				ast_log(LOG_WARNING, "Invalid tos_video value at line %d, recommended value is 'af41'. See doc/ip-tos.txt.\n", v->lineno); } )
+				ast_log(LOG_WARNING, "Invalid tos_video value at line %d, recommended value is 'af41'. See doc/qos.tex.\n", v->lineno); } )
 		M_F("tos_text", {
 			if (ast_str2tos(v->value, &global_tos_text))
-				ast_log(LOG_WARNING, "Invalid tos_text value at line %d, recommended value is 'af41'. See doc/ip-tos.txt.\n", v->lineno); } )
+				ast_log(LOG_WARNING, "Invalid tos_text value at line %d, recommended value is 'af41'. See doc/qos.tex.\n", v->lineno); } )
+		M_F("cos_sip", ast_str2cos(v->value, &global_cos_sip))
+		M_F("cos_audio", ast_str2cos(v->value, &global_cos_audio))
+		M_F("cos_video", ast_str2cos(v->value, &global_cos_video))
+		M_F("cos_text", ast_str2cos(v->value, &global_cos_text))
 		M_F("bindport", {
 			if (sscanf(v->value, "%d", &ourport) == 1) {
 				bindaddr.sin_port = htons(ourport);
@@ -17964,10 +18009,7 @@
 				if (option_verbose > 1)
 					ast_verbose(VERBOSE_PREFIX_2 "SIP Listening on %s:%d\n", 
 						ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port));
-				if (setsockopt(my_socket, IPPROTO_IP, IP_TOS, &global_tos_sip, sizeof(global_tos_sip))) 
-					ast_log(LOG_WARNING, "Unable to set SIP TOS to %s\n", ast_tos2str(global_tos_sip));
-				else if (option_verbose > 1)
-					ast_verbose(VERBOSE_PREFIX_2 "Using SIP TOS: %s\n", ast_tos2str(global_tos_sip));
+				ast_netsock_set_qos(my_socket, global_tos_sip, global_tos_sip);
 				sipsock = my_socket;
 				sipsock_read_id = ast_io_add(io, sipsock, sipsock_read, AST_IO_IN, NULL);
 			}
@@ -18604,7 +18646,7 @@
 
 	{ { "sip", "unregister", NULL },
 	sip_unregister, "Unregister (force expiration) a SIP peer from the registery\n",
-	sip_unregister_usage },
+	sip_unregister_usage, complete_sip_unregister },
 
 	{ { "sip", "show", "settings", NULL },
 	sip_show_settings, "Show SIP global settings",




More information about the asterisk-commits mailing list