All pastes #1045245 Raw Edit

ctooley

public text v1 · immutable
#1045245 ·published 2008-06-11 18:33 UTC
rendered paste body
--- 1.4.19.1/channels/chan_sip.c	2008-06-11 14:37:44.000000000 +0000
+++ asterisk-1.4.19.1/channels/chan_sip.c	2008-03-26 19:04:35.000000000 +0000
@@ -115,7 +115,6 @@
 #include <netinet/ip.h>
 #include <regex.h>
 
-#include "../defaults.h"
 #include "asterisk/lock.h"
 #include "asterisk/channel.h"
 #include "asterisk/config.h"
@@ -676,30 +675,6 @@
 	char hop[0];
 };
 
-/*! \brief */
-enum failover_state {
-	NOT_CONFIGURED = 0,	/*!< This is not a failover server */
-	STANDBY,		/*!< This is a failover server in standby mode */
-	ACTIVE,			/*!< The primary server fails, so this server is active */
-};
-
-/*! \brief definition of a sip proxy server
- *
- * For outbound proxies, this is allocated in the SIP peer dynamically or
- * statically as the global_outboundproxy. The pointer in a SIP message is just
- * a pointer and should *not* be de-allocated.
- */
-struct sip_proxy {
-	char name[MAXHOSTNAMELEN];      /*!< DNS name of domain/host or IP */
-	struct sockaddr_in ip;          /*!< Currently used IP address and port */
-	time_t last_dnsupdate;          /*!< When this was resolved */
-	int force;                      /*!< If it's an outbound proxy, Force use of this outbound proxy for all outbound requests */
-	enum failover_state failoverstate;	/*!< If this is a failover proxy, what's the state ? */
-
-	/* Room for a SRV record chain based on the name */
-};
-
-
 /*! \brief Modes for SIP domain handling in the PBX */
 enum domain_mode {
 	SIP_DOMAIN_AUTO,		/*!< This domain is auto-configured */
@@ -951,7 +926,6 @@
 		AST_STRING_FIELD(fromuser);	/*!< User to show in the user field */
 		AST_STRING_FIELD(fromname);	/*!< Name to show in the user field */
 		AST_STRING_FIELD(tohost);	/*!< Host we should put in the "to" field */
-		AST_STRING_FIELD(failoverhostname);	/*!< Name of the failover peer */
 		AST_STRING_FIELD(language);	/*!< Default language for this call */
 		AST_STRING_FIELD(mohinterpret);	/*!< MOH class to use when put on hold */
 		AST_STRING_FIELD(mohsuggest);	/*!< MOH class to suggest when putting a peer on hold */
@@ -1001,8 +975,6 @@
 	int sessionid;				/*!< SDP Session ID */
 	int sessionversion;			/*!< SDP Session Version */
 	struct sockaddr_in sa;			/*!< Our peer */
-	struct sockaddr_in failoveraddr;	/*!< Our failover IP address */
-	enum failover_state failoverstate;	/*!< Failover state for this peer */
 	struct sockaddr_in redirip;		/*!< Where our RTP should be going if not to us */
 	struct sockaddr_in vredirip;		/*!< Where our Video RTP should be going if not to us */
 	time_t lastrtprx;			/*!< Last RTP received */
@@ -1020,6 +992,7 @@
 	int pendinginvite;			/*!< Any pending INVITE or state NOTIFY (in subscribe pvt's) ? (seqno of this) */
 	struct sip_request initreq;		/*!< Request that opened the latest transaction
 						     within this SIP dialog */
+	
 	int maxtime;				/*!< Max time for first response */
 	int initid;				/*!< Auto-congest ID if appropriate (scheduler) */
 	int waitid;				/*!< Wait ID for scheduler after 491 or other delays */
@@ -1091,8 +1064,7 @@
 	int amaflags;			/*!< AMA flags for billing */
 	int callingpres;		/*!< Calling id presentation */
 	int capability;			/*!< Codec capability */
-	int inUse;			/*!< Number of inbound calls in use */
-	int outUse;			/*!< Number of outbound calls in use */
+	int inUse;			/*!< Number of calls in use */
 	int call_limit;			/*!< Limit of concurrent calls */
 	enum transfermodes allowtransfer;	/*! SIP Refer restriction scheme */
 	struct ast_ha *ha;		/*!< ACL setting */
@@ -1115,7 +1087,6 @@
 	char accountcode[AST_MAX_ACCOUNT_CODE];	/*!< Account code */
 	int amaflags;			/*!< AMA Flags (for billing) */
 	char tohost[MAXHOSTNAMELEN];	/*!< If not dynamic, IP address */
-	char failoverhostname[MAXHOSTNAMELEN]; /*!< failover host name */
 	char regexten[AST_MAX_EXTENSION]; /*!< Extension to register (if regcontext is used) */
 	char fromuser[80];		/*!< From: user when calling this peer */
 	char fromdomain[MAXHOSTNAMELEN];	/*!< From: domain when calling this peer */
@@ -1123,8 +1094,7 @@
 	char cid_num[80];		/*!< Caller ID num */
 	char cid_name[80];		/*!< Caller ID name */
 	int callingpres;		/*!< Calling id presentation */
-	int inUse;			/*!< Number of inbound calls in use */
-	int outUse;			/*!< Number of outbound calls in use */
+	int inUse;			/*!< Number of calls in use */
 	int inRinging;			/*!< Number of calls ringing */
 	int onHold;                     /*!< Peer has someone on hold */
 	int call_limit;			/*!< Limit of concurrent calls */
@@ -1148,7 +1118,6 @@
 	ast_group_t callgroup;		/*!<  Call group */
 	ast_group_t pickupgroup;	/*!<  Pickup group */
 	struct sockaddr_in addr;	/*!<  IP address of peer */
-	struct sockaddr_in failoveraddr;	/*!<  IP address of failover peer */
 	int maxcallbitrate;		/*!< Maximum Bitrate for a video call */
 	
 	/* Qualification */
@@ -1258,7 +1227,6 @@
 static int sip_write(struct ast_channel *ast, struct ast_frame *frame);
 static int sip_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen);
 static int sip_transfer(struct ast_channel *ast, const char *dest);
-static int sip_routeresponse(struct ast_channel *ast, const char *dest, const char *routelist);
 static int sip_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
 static int sip_senddigit_begin(struct ast_channel *ast, char digit);
 static int sip_senddigit_end(struct ast_channel *ast, char digit, unsigned int duration);
@@ -1324,7 +1292,6 @@
 static void *sip_park_thread(void *stuff);
 static int sip_park(struct ast_channel *chan1, struct ast_channel *chan2, struct sip_request *req, int seqno);
 static int sip_sipredirect(struct sip_pvt *p, const char *dest);
-static int sip_redirect_multiplechoices(struct sip_pvt *p, const char *dest, const char *content);
 
 /*--- Codec handling / SDP */
 static void try_suggested_sip_codec(struct sip_pvt *p);
@@ -1526,7 +1493,7 @@
 static const struct sockaddr_in *sip_real_dst(const struct sip_pvt *p);
 static void build_via(struct sip_pvt *p);
 static int create_addr_from_peer(struct sip_pvt *r, struct sip_peer *peer);
-static int create_addr(struct sip_pvt *dialog, const char *opeer, int failover);
+static int create_addr(struct sip_pvt *dialog, const char *opeer);
 static char *generate_random_string(char *buf, size_t size);
 static void build_callid_pvt(struct sip_pvt *pvt);
 static void build_callid_registry(struct sip_registry *reg, struct in_addr ourip, const char *fromdomain);
@@ -1597,7 +1564,6 @@
 	.write_video = sip_write,
 	.indicate = sip_indicate,
 	.transfer = sip_transfer,
-	.routeresponse = sip_routeresponse,
 	.fixup = sip_fixup,
 	.send_digit_begin = sip_senddigit_begin,
 	.send_digit_end = sip_senddigit_end,
@@ -1624,7 +1590,6 @@
 	.write_video = sip_write,
 	.indicate = sip_indicate,
 	.transfer = sip_transfer,
-	.routeresponse = sip_routeresponse,
 	.fixup = sip_fixup,
 	.send_digit_end = sip_senddigit_end,
 	.bridge = ast_rtp_bridge,
@@ -1800,28 +1765,11 @@
 	return sip_debug_test_addr(sip_real_dst(p));
 }
 
-/*! \brief Append to SIP dialog history 
-	\return Always returns 0 */
-#define append_history(p, event, fmt , args... )	append_history_full(p, "%-15s " fmt, event, ## args)
-
-
-/*! \brief Transmit SIP message 
-
-	Sends message on socket. If transmit fails, reports an error. If there's a failover peer
-	defined in dialog, switches to failover peer.
-*/
+/*! \brief Transmit SIP message */
 static int __sip_xmit(struct sip_pvt *p, char *data, int len)
 {
 	int res;
-	const struct sockaddr_in *dst = p->failoverstate == ACTIVE ? &p->failoveraddr : sip_real_dst(p);
-
-	/* If we haven't resolved the failover hostname, we need to do that now */
-	if (p->failoverstate == ACTIVE && !p->failoveraddr.sin_addr.s_addr) {
-		create_addr(p, p->failoverhostname, TRUE);	/* Resolve to IP address */
-	}
-	if (option_debug > 2 && p->failoverstate == ACTIVE)
-		ast_log(LOG_DEBUG, "FAILOVER :: Using failover IP %s\n", ast_inet_ntoa(p->failoveraddr.sin_addr));
-
+	const struct sockaddr_in *dst = sip_real_dst(p);
 	res = sendto(sipsock, data, len, 0, (const struct sockaddr *)dst, sizeof(struct sockaddr_in));
 
 	if (res == -1) {
@@ -1832,16 +1780,6 @@
 			case ENETUNREACH:	/* Network failure */
 				res = XMIT_ERROR;	/* Don't bother with trying to transmit again */
 		}
-		if (p->failoverstate == STANDBY) {	/* Time to switch to failover mode for this dialog */
-			p->failoverstate = ACTIVE;
-			if (!p->failoveraddr.sin_addr.s_addr)
-				create_addr(p, p->failoverhostname, TRUE);	/* Resolve to IP address */
-			if (option_debug > 2)
-				ast_log(LOG_DEBUG, "FAILOVER:: Switching to failover peer for this dialog :: %s\n", p->callid);
-			append_history(p, "FailOver", "Activated failover peer for non-responsive peer %s", p->tohost);
-			return __sip_xmit(p, data, len);
-		}
-		
 	}
 	if (res != len)
 		ast_log(LOG_WARNING, "sip_xmit of %p (len %d) to %s:%d returned %d: %s\n", data, len, ast_inet_ntoa(dst->sin_addr), ntohs(dst->sin_port), res, strerror(errno));
@@ -1898,6 +1836,10 @@
 	return AST_SUCCESS;
 }
 
+/*! \brief Append to SIP dialog history 
+	\return Always returns 0 */
+#define append_history(p, event, fmt , args... )	append_history_full(p, "%-15s " fmt, event, ## args)
+
 static void append_history_full(struct sip_pvt *p, const char *fmt, ...)
 	__attribute__ ((format (printf, 2, 3)));
 
@@ -1986,12 +1928,10 @@
 
 		if (sip_debug_test_pvt(pkt->owner)) {
 			const struct sockaddr_in *dst = sip_real_dst(pkt->owner);
-			ast_verbose("Retransmitting #%d (%s) to %s%s:%d:\n%s\n---\n",
+			ast_verbose("Retransmitting #%d (%s) to %s:%d:\n%s\n---\n",
 				pkt->retrans, sip_nat_mode(pkt->owner),
-				pkt->owner->failoverstate == ACTIVE ? "failover peer " : "",
-				pkt->owner->failoverstate == ACTIVE ? ast_inet_ntoa(pkt->owner->failoveraddr.sin_addr) : ast_inet_ntoa(dst->sin_addr),
-				pkt->owner->failoverstate == ACTIVE ? ntohs(pkt->owner->failoveraddr.sin_port) : ntohs(dst->sin_port),
-				pkt->data);
+				ast_inet_ntoa(dst->sin_addr),
+				ntohs(dst->sin_port), pkt->data);
 		}
 
 		append_history(pkt->owner, "ReTx", "%d %s", reschedule, pkt->data);
@@ -2015,18 +1955,6 @@
 	} else
 		append_history(pkt->owner, "MaxRetries", "%s", (ast_test_flag(pkt, FLAG_FATAL)) ? "(Critical)" : "(Non-critical)");
  		
-
-	if (pkt->method != SIP_OPTIONS && pkt->owner->failoverstate == STANDBY) {
-		pkt->owner->failoverstate = ACTIVE;	/* Switching dialog to failover active mode */
-		append_history(pkt->owner, "FailOver", "Failover SIP host activated.");
-		pkt->retrans = 0;
- 		pkt->timer_a = 2 ;
-		ast_mutex_unlock(&pkt->owner->lock);
-		if (option_debug > 2)
-			ast_log(LOG_DEBUG, "FAILOVER :: Switching to failover peer due to retransmits\n");
-		return 100;	/* Restart with failover peer after 100 ms */
-	}
-
 	pkt->retransid = -1;
 
 	if (ast_test_flag(pkt, FLAG_FATAL)) {
@@ -2036,7 +1964,6 @@
 			ast_mutex_lock(&pkt->owner->lock);
 		}
 
-
 		if (pkt->owner->owner && !pkt->owner->owner->hangupcause) 
 			pkt->owner->owner->hangupcause = AST_CAUSE_NO_USER_RESPONSE;
 		
@@ -2169,7 +2096,7 @@
 		ast_log(LOG_DEBUG, "Auto destroying SIP dialog '%s'\n", p->callid);
 	append_history(p, "AutoDestroy", "%s", p->callid);
 	if (p->owner) {
-		/* ast_log(LOG_WARNING, "Autodestruct on dialog '%s' with owner in place (Method: %s)\n", p->callid, sip_methods[p->method].text); */
+		ast_log(LOG_WARNING, "Autodestruct on dialog '%s' with owner in place (Method: %s)\n", p->callid, sip_methods[p->method].text);
 		ast_queue_hangup(p->owner);
 	} else if (p->refer) {
 		if (option_debug > 2)
@@ -2339,13 +2266,10 @@
 	if (sip_debug_test_pvt(p)) {
 		const struct sockaddr_in *dst = sip_real_dst(p);
 
-		ast_verbose("\n<--- %sTransmitting (%s) to %s%s:%d --->\n%s\n<------------>\n",
+		ast_verbose("\n<--- %sTransmitting (%s) to %s:%d --->\n%s\n<------------>\n",
 			reliable ? "Reliably " : "", sip_nat_mode(p),
-			p->failoverstate == ACTIVE ? "failover peer " : "",
-			p->failoverstate == ACTIVE ? ast_inet_ntoa(p->failoveraddr.sin_addr) : ast_inet_ntoa(dst->sin_addr),
-			p->failoverstate == ACTIVE ? ntohs(p->failoveraddr.sin_port) : ntohs(dst->sin_port),
-			req->data);
-
+			ast_inet_ntoa(dst->sin_addr),
+			ntohs(dst->sin_port), req->data);
 	}
 	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) {
 		struct sip_request tmp;
@@ -2368,16 +2292,10 @@
 
 	add_blank(req);
 	if (sip_debug_test_pvt(p)) {
-		struct sockaddr_in *toaddr = ast_test_flag(&p->flags[0], SIP_NAT_ROUTE) ? &p->recv : &p->sa;
-		char *natstate = "";
-		if (p->failoverstate == ACTIVE)
-			toaddr = &p->failoveraddr;
-
 		if (ast_test_flag(&p->flags[0], SIP_NAT_ROUTE))
-			natstate = "(NAT)";
-		ast_verbose("\n---> %sTransmitting %s to %s%s:%d:\n%s\n---\n", reliable ? "Reliably " : "", natstate, 
-			p->failoverstate == ACTIVE ? "failover peer " : "",
-			ast_inet_ntoa(toaddr->sin_addr), ntohs(toaddr->sin_port), req->data);
+			ast_verbose("%sTransmitting (NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port), req->data);
+		else
+			ast_verbose("%sTransmitting (no NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(p->sa.sin_addr), ntohs(p->sa.sin_port), req->data);
 	}
 	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) {
 		struct sip_request tmp;
@@ -2863,18 +2781,8 @@
 	    (!peer->maxms || ((peer->lastms >= 0)  && (peer->lastms <= peer->maxms)))) {
 		dialog->sa = (peer->addr.sin_addr.s_addr) ? peer->addr : peer->defaddr;
 		dialog->recv = dialog->sa;
-	} else if (peer->failoveraddr.sin_addr.s_addr || !ast_strlen_zero(peer->failoverhostname)) {
-		/* There's a problem with the primary peer (unreachable) and we do have a failver
-		   peer definition. Activate that at the start of the dialog */
-		if (!peer->failoveraddr.sin_addr.s_addr) {
-			create_addr(dialog, peer->failoverhostname, TRUE);
-		}
-		dialog->failoverstate = ACTIVE;
-	} else {
+	} else 
 		return -1;
-	}
-
-	dialog->failoveraddr = peer->failoveraddr;
 
 	ast_copy_flags(&dialog->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
 	ast_copy_flags(&dialog->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
@@ -2930,7 +2838,6 @@
 	ast_string_field_set(dialog, mohsuggest, peer->mohsuggest);
 	ast_string_field_set(dialog, mohinterpret, peer->mohinterpret);
 	ast_string_field_set(dialog, tohost, peer->tohost);
-	ast_string_field_set(dialog, failoverhostname, peer->failoverhostname);
 	ast_string_field_set(dialog, fullcontact, peer->fullcontact);
 	if (!dialog->initreq.headers && !ast_strlen_zero(peer->fromdomain)) {
 		char *tmpcall;
@@ -2942,8 +2849,8 @@
 			ast_string_field_build(dialog, callid, "%s@%s", tmpcall, peer->fromdomain);
 		}
 	}
-	if (ast_strlen_zero(dialog->failoverhostname))
-		ast_string_field_set(dialog, failoverhostname, ast_inet_ntoa(dialog->failoveraddr.sin_addr)); 
+	if (ast_strlen_zero(dialog->tohost))
+		ast_string_field_set(dialog, tohost, ast_inet_ntoa(dialog->sa.sin_addr));
 	if (!ast_strlen_zero(peer->fromdomain))
 		ast_string_field_set(dialog, fromdomain, peer->fromdomain);
 	if (!ast_strlen_zero(peer->fromuser))
@@ -2969,17 +2876,14 @@
 	if (peer->call_limit)
 		ast_set_flag(&dialog->flags[0], SIP_CALL_LIMIT);
 	dialog->maxcallbitrate = peer->maxcallbitrate;
-	if (!ast_strlen_zero(dialog->failoverhostname))
-		dialog->failoverstate = STANDBY;
 	
 	return 0;
 }
 
 /*! \brief create address structure from peer name
  *      Or, if peer not found, find it in the global DNS 
- *	if failover is TRUE, the failover peer is configured, not the default peer
  *      returns TRUE (-1) on failure, FALSE on success */
-static int create_addr(struct sip_pvt *dialog, const char *opeer, int failover)
+static int create_addr(struct sip_pvt *dialog, const char *opeer)
 {
 	struct hostent *hp;
 	struct ast_hostent ahp;
@@ -2988,36 +2892,17 @@
 	int portno;
 	char host[MAXHOSTNAMELEN], *hostn;
 	char peer[256];
-	struct sockaddr_in *peersock = failover ? &dialog->failoveraddr : &dialog->sa;
-
-	if (failover) {
-		append_history(dialog, "FailOver", "Looking up failover peer %s for used peer %s", opeer, dialog->tohost);
-		if (option_debug > 2)
-			ast_log(LOG_DEBUG, "FAILOVER :: Looking up failover peer %s\n", opeer);
-	}
 
 	ast_copy_string(peer, opeer, sizeof(peer));
 	port = strchr(peer, ':');
 	if (port)
 		*port++ = '\0';
-	peersock->sin_family = AF_INET;
-	if (!failover) {
-		dialog->timer_t1 = 500; /* Default SIP retransmission timer T1 (RFC 3261) */
-	}
-
+	dialog->sa.sin_family = AF_INET;
+	dialog->timer_t1 = 500; /* Default SIP retransmission timer T1 (RFC 3261) */
 	p = find_peer(peer, NULL, 1);
 
 	if (p) {
-		int res;
-
-		if (failover) {
-			/* Avoid recursion if we're looking for a failover peer, so just take the address */
-			dialog->failoveraddr = (p->addr.sin_addr.s_addr) ? p->addr : p->defaddr;
-			p->failoveraddr = dialog->failoveraddr;		/* save it for next time */
-			return 0;
-		}
-
-		res = create_addr_from_peer(dialog, p);
+		int res = create_addr_from_peer(dialog, p);
 		ASTOBJ_UNREF(p, sip_destroy_peer);
 		return res;
 	}
@@ -3037,23 +2922,13 @@
 	}
 	hp = ast_gethostbyname(hostn, &ahp);
 	if (!hp) {
-		ast_log(LOG_WARNING, "No such %s host: %s\n", failover? "failover" : "", peer);
+		ast_log(LOG_WARNING, "No such host: %s\n", peer);
 		return -1;
 	}
-	//peersock->sin_addr = hp->h_addr;
-	memcpy(&peersock->sin_addr, hp->h_addr, sizeof(peersock->sin_addr));
-	peersock->sin_port = htons(portno);
-
-	if (!failover) {
-		/* This is potentially a bug, replacing the original hostname with the result of the DNS lookup 
-			We should separate these.
-	 	*/
-		ast_string_field_set(dialog, tohost, peer);
-		dialog->recv = dialog->sa;
-	} else {
-		if (option_debug > 2)
-			ast_log(LOG_DEBUG, "FAILOVER :: Found IP address %s\n", ast_inet_ntoa(peersock->sin_addr));
-	}
+	ast_string_field_set(dialog, tohost, peer);
+	memcpy(&dialog->sa.sin_addr, hp->h_addr, sizeof(dialog->sa.sin_addr));
+	dialog->sa.sin_port = htons(portno);
+	dialog->recv = dialog->sa;
 	return 0;
 }
 
@@ -3142,13 +3017,6 @@
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Outgoing Call for %s\n", p->username);
 
-	
-	/* tell the A-leg the call id */
-	if(ast->bridge_channel) {
-		ast_log(LOG_DEBUG, "Setting DIALEDCALLID variable to %s\n", p->callid);
-		pbx_builtin_setvar_helper(ast->bridge_channel, "DIALEDCALLID", p->callid);
-	}
-	
 	res = update_call_counter(p, INC_CALL_RINGING);
 	if ( res != -1 ) {
 		p->callingpres = ast->cid.cid_pres;
@@ -3328,7 +3196,7 @@
 static int update_call_counter(struct sip_pvt *fup, int event)
 {
 	char name[256];
-	int *inuse = NULL, *call_limit = NULL, *inringing = NULL, *outuse = NULL;
+	int *inuse = NULL, *call_limit = NULL, *inringing = NULL;
 	int outgoing = ast_test_flag(&fup->flags[1], SIP_PAGE2_OUTGOING_CALL);
 	struct sip_user *u = NULL;
 	struct sip_peer *p = NULL;
@@ -3346,12 +3214,10 @@
 	/* Check the list of users only for incoming calls */
 	if (global_limitonpeers == FALSE && !outgoing && (u = find_user(name, 1)))  {
 		inuse = &u->inUse;
-		outuse = &u->outUse;
 		call_limit = &u->call_limit;
 		inringing = NULL;
 	} else if ( (p = find_peer(ast_strlen_zero(fup->peername) ? name : fup->peername, NULL, 1) ) ) { /* Try to find peer */
 		inuse = &p->inUse;
-		outuse = &p->outUse;
 		call_limit = &p->call_limit;
 		inringing = &p->inRinging;
 		ast_copy_string(name, fup->peername, sizeof(name));
@@ -3364,8 +3230,6 @@
 
 	switch(event) {
 	/* incoming and outgoing affects the inUse counter */
-	/* REPLACING WITH MY CALL COUNTER INSTEAD OF THE DEFAULT ONE */
-	/*
 	case DEC_CALL_LIMIT:
 		if ( *inuse > 0 ) {
 			if (ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) {
@@ -3392,65 +3256,8 @@
 			ast_log(LOG_DEBUG, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
 		}
 		break;
-	case INC_CALL_RINGING:
-	*/
-  	case DEC_CALL_LIMIT:
- 		if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
- 			if ( *outuse > 0 ) {
- 				if (ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) {
- 					(*outuse)--;
- 					ast_clear_flag(&fup->flags[0], SIP_INC_COUNT);
- 				}
- 			} else {
- 				*outuse = 0;
- 			}
- 			if (option_debug > 1 || sipdebug) {
- 				ast_log(LOG_DEBUG, "Call %s %s '%s' removed from outbound call counter %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *outuse);
- 			}
- 		}
- 		else {
- 			if ( *inuse > 0 ) {
- 				if (ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) {
- 					(*inuse)--;
- 					ast_clear_flag(&fup->flags[0], SIP_INC_COUNT);
- 				}
- 			} else {
- 				*inuse = 0;
- 			}
- 			if (inringing) {
- 				if (ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
- 					if (*inringing > 0)
- 						(*inringing)--;
- 					else if (!ast_test_flag(&fup->flags[0], SIP_REALTIME) || ast_test_flag(&fup->flags[1], SIP_PAGE2_RTCACHEFRIENDS))
- 						ast_log(LOG_WARNING, "Inringing for peer '%s' < 0?\n", fup->peername);
- 					ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
- 				}
- 			}
- 			if (ast_test_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD) && global_notifyhold) {
- 				ast_clear_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD);
- 				sip_peer_hold(fup, 0);
- 			}
- 			if (option_debug > 1 || sipdebug) {
- 				ast_log(LOG_DEBUG, "Call %s %s '%s' removed from inbound call limit %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
- 			}
- 		}
- 		break;
- 
- 	case INC_CALL_RINGING:
- 		if (inringing && (event == INC_CALL_RINGING)) {
- 			if (!ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) {
- 				(*inringing)++;
- 				ast_set_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING);
- 			}
- 		}
- 		/* Continue */
- 		(*outuse)++;
- 		ast_set_flag(&fup->flags[0], SIP_INC_COUNT);
- 		if (option_debug > 1 || sipdebug) {
- 			ast_log(LOG_DEBUG, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *outuse, *call_limit);
-  		}
-  		break;
 
+	case INC_CALL_RINGING:
 	case INC_CALL_LIMIT:
 		if (*call_limit > 0 ) {
 			if (*inuse >= *call_limit) {
@@ -3646,7 +3453,6 @@
 			return "484 Address incomplete";
 		case AST_CAUSE_USER_BUSY:
 			return "486 Busy here";
-		case AST_CAUSE_NORMAL_TEMPORARY_FAILURE: /* 41 */
 		case AST_CAUSE_FAILURE:
 			return "500 Server internal failure";
 		case AST_CAUSE_FACILITY_REJECTED:	/* 29 */
@@ -4049,23 +3855,6 @@
 	return res;
 }
 
-/*! \brief Respond to a Route Request SIP INVITE */
-static int sip_routeresponse(struct ast_channel *ast, const char *dest, const char *routelist)
-{
-	struct sip_pvt *p = ast->tech_pvt;
-	int res;
-
-	if(!routelist)	/* functions below do not take a NULL */
-		routelist = "";
-
-	if (!dest)	/* functions below do not take a NULL */
-		dest = "";
-	ast_mutex_lock(&p->lock);
-	res = sip_redirect_multiplechoices(p, dest, routelist);
-	ast_mutex_unlock(&p->lock);
-	return res;
-}
-
 /*! \brief Transfer SIP call */
 static int sip_transfer(struct ast_channel *ast, const char *dest)
 {
@@ -4462,7 +4251,7 @@
 	 */
 	for (pass = 0; name && pass < 2;pass++) {
 		int x, len = strlen(name);
-		for (x=*start; x<req->headers && req->header[x]; x++) {
+		for (x=*start; x<req->headers; x++) {
 			if (!strncasecmp(req->header[x], name, len)) {
 				char *r = req->header[x] + len;	/* skip name */
 				if (pedanticsipchecking)
@@ -6222,19 +6011,13 @@
 {
 	struct sip_request resp;
 	int seqno = 0;
-	const char *clheader;
 
 	if (reliable && (sscanf(get_header(req, "CSeq"), "%d ", &seqno) != 1)) {
 		ast_log(LOG_WARNING, "Unable to determine sequence number from '%s'\n", get_header(req, "CSeq"));
 		return -1;
 	}
 	respprep(&resp, p, msg, req);
-
-	// if this
-	clheader = get_header(req, "Content-Length");
-	if (!clheader[0]) {
-		add_header_contentLength(&resp, 0);
-	}
+	add_header_contentLength(&resp, 0);
 	/* If we are cancelling an incoming invite for some reason, add information
 		about the reason why we are doing this in clear text */
 	if (p->method == SIP_INVITE && msg[0] != '1' && p->owner && p->owner->hangupcause) {
@@ -6313,18 +6096,6 @@
 	return __transmit_response(p, msg, req, XMIT_UNRELIABLE);
 }
 
-/*! \brief Transmit response, with routedata */
-static int transmit_response_with_routedata(struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *routedata) 
-{
-	struct sip_request resp;
-	respprep(&resp, p, msg, req);
-	append_date(&resp);
-	add_header(&resp, "Content-Type", "text/plain");
-	add_header_contentLength(&resp, strlen(routedata));
-	add_line(&resp, routedata);
-	return send_response(p, &resp, XMIT_CRITICAL, 1);
-}
-
 /*! \brief Transmit response, no retransmits */
 static int transmit_response_with_unsupported(struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *unsupported) 
 {
@@ -7788,7 +7559,7 @@
 		if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
 			append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);
 		/* Find address to hostname */
-		if (create_addr(p, r->hostname, FALSE)) {
+		if (create_addr(p, r->hostname)) {
 			/* we have what we hope is a temporary network error,
 			 * probably DNS.  We need to reschedule a registration try */
 			sip_destroy(p);
@@ -9771,12 +9542,6 @@
 			ast_string_field_set(p, subscribecontext, peer->subscribecontext);
 			ast_string_field_set(p, mohinterpret, peer->mohinterpret);
 			ast_string_field_set(p, mohsuggest, peer->mohsuggest);
-
-			/* If we have a failover peer, activate it */
-			if (!ast_strlen_zero(peer->failoverhostname)) {
-				ast_string_field_set(p, failoverhostname, peer->failoverhostname);
-				p->failoverstate = STANDBY;
-			}
 			if (peer->callingpres)	/* Peer calling pres setting will override RPID */
 				p->callingpres = peer->callingpres;
 			if (peer->maxms && peer->lastms)
@@ -10672,14 +10437,8 @@
 		/* - is enumerated */
 		ast_cli(fd, "  DTMFmode     : %s\n", dtmfmode2str(ast_test_flag(&peer->flags[0], SIP_DTMF)));
 		ast_cli(fd, "  LastMsg      : %d\n", peer->lastmsg);
-		ast_cli(fd, "  Remote Host  : %s\n", peer->tohost);
-		ast_cli(fd, "  Remote IP    : %s Port %d\n",  peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "(Unspecified)", ntohs(peer->addr.sin_port));
-		if (!ast_strlen_zero(peer->failoverhostname)) {
-			ast_cli(fd, "  Failover Host: %s\n", peer->failoverhostname);
-			ast_cli(fd, "  Failover IP  : %s Port %d\n",  peer->failoveraddr.sin_addr.s_addr ? ast_inet_ntoa(peer->failoveraddr.sin_addr) : "(Unspecified)", ntohs(peer->failoveraddr.sin_port));
-		} else {
-			ast_cli(fd, "  Failover Host: Disabled\n");
-		}
+		ast_cli(fd, "  ToHost       : %s\n", peer->tohost);
+		ast_cli(fd, "  Addr->IP     : %s Port %d\n",  peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "(Unspecified)", ntohs(peer->addr.sin_port));
 		ast_cli(fd, "  Defaddr->IP  : %s Port %d\n", ast_inet_ntoa(peer->defaddr.sin_addr), ntohs(peer->defaddr.sin_port));
 		if (!ast_strlen_zero(global_regcontext))
 			ast_cli(fd, "  Reg. exten   : %s\n", peer->regexten);
@@ -10760,8 +10519,6 @@
 		astman_append(s, "SIPLastMsg: %d\r\n", peer->lastmsg);
 		astman_append(s, "ToHost: %s\r\n", peer->tohost);
 		astman_append(s, "Address-IP: %s\r\nAddress-Port: %d\r\n",  peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "", ntohs(peer->addr.sin_port));
-		astman_append(s, "FailoverHostName: %s\r\n", peer->failoverhostname);
-		astman_append(s, "FailoverAddress-IP: %s\r\nAddress-Port: %d\r\n",  peer->failoveraddr.sin_addr.s_addr ? ast_inet_ntoa(peer->failoveraddr.sin_addr) : "", ntohs(peer->failoveraddr.sin_port));
 		astman_append(s, "Default-addr-IP: %s\r\nDefault-addr-port: %d\r\n", ast_inet_ntoa(peer->defaddr.sin_addr), ntohs(peer->defaddr.sin_port));
 		astman_append(s, "Default-Username: %s\r\n", peer->username);
 		if (!ast_strlen_zero(global_regcontext))
@@ -11593,7 +11350,7 @@
 			return RESULT_FAILURE;
 		}
 
-		if (create_addr(p, argv[i], FALSE)) {
+		if (create_addr(p, argv[i])) {
 			/* Maybe they're not registered, etc. */
 			sip_destroy(p);
 			ast_cli(fd, "Could not create address for '%s'\n", argv[i]);
@@ -14171,7 +13928,7 @@
 		if ((res = update_call_counter(p, INC_CALL_LIMIT))) {
 			if (res < 0) {
 				ast_log(LOG_NOTICE, "Failed to place call for user %s, too many calls\n", p->username);
-				transmit_response_reliable(p, "503 Service Unavailable (Call limit) ", req);
+				transmit_response_reliable(p, "480 Temporarily Unavailable (Call limit) ", req);
 				sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
 				p->invitestate = INV_COMPLETED;	
 			}
@@ -14268,9 +14025,9 @@
 					ast_log(LOG_WARNING, "Failed to start PBX (call limit reached) \n");
 					p->invitestate = INV_COMPLETED;
 					if (ast_test_flag(req, SIP_PKT_IGNORE))
-						transmit_response(p, "503 Service Unavailable", req);
+						transmit_response(p, "480 Temporarily Unavailable", req);
 					else
-						transmit_response_reliable(p, "503 Service Unavailable", req);
+						transmit_response_reliable(p, "480 Temporarily Unavailable", req);
 					break;
 				case AST_PBX_SUCCESS:
 					/* nothing to do */
@@ -15936,8 +15693,8 @@
 		ast_mutex_lock(&monlock);
 		if (res >= 0)  {
 			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); */
+			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 */
@@ -15998,49 +15755,18 @@
 	ast_mutex_unlock(&monlock);
 	return 0;
 }
-  
-/*! \brief Activate failover state for all calls 
-	when peer becomes unreachable 
-
-	This is advisory only, so if we can't lock a dialog, let's 
-	just skip it and move on. The dialog will failover when xmit fails.
-*/
-static void device_failover_calls(struct sip_peer *device) 
-{
-	struct sip_pvt *dialog;
-	int dialogs = 0;
-
-	ast_mutex_lock(&iflock);
-	for (dialog = iflist; dialog; dialog = dialog->next) {
-		if (strcmp(device->tohost, dialog->tohost))
-			continue;
-		/* If dialog is locked for some reason, don't deadlock, just continue */
-		if (ast_mutex_trylock(&dialog->lock))
-			continue;
-		dialogs++;
-		dialog->failoverstate = ACTIVE;
-		append_history(dialog, "FailOver", "Activated failover peer for unreachable peer %s :: %s", device->name, device->tohost);
-		ast_mutex_unlock(&dialog->lock);
-		if (dialogs == device->inUse)
-			break;	/* We've found all, let's release the iflock quickly */
- 	}
-	if (option_debug > 2)
-		ast_log(LOG_DEBUG, "FAILOVER :: Activated failover for %d dialogs. Unreachable peer has %d active calls\n", dialogs, device->inUse);
-	ast_mutex_unlock(&iflock);
-}
 
 /*! \brief React to lack of answer to Qualify poke */
 static int sip_poke_noanswer(const void *data)
 {
 	struct sip_peer *peer = (struct sip_peer *)data;
 	
- 	AST_SCHED_DEL(sched, peer->pokeexpire);
 	peer->pokeexpire = -1;
 	if (peer->lastms > -1) {
 		ast_log(LOG_NOTICE, "Peer '%s' is now UNREACHABLE!  Last qualify: %d\n", peer->name, peer->lastms);
 		manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Unreachable\r\nTime: %d\r\n", peer->name, -1);
 	}
- 	if (peer->call)		/* Delete the NOTIFY operation */
+	if (peer->call)
 		sip_destroy(peer->call);
 	peer->call = NULL;
 	peer->lastms = -1;
@@ -16048,9 +15774,6 @@
 	/* Try again quickly */
 	AST_SCHED_DEL(sched, peer->pokeexpire);
 	peer->pokeexpire = ast_sched_add(sched, DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer);
- 	if (!ast_strlen_zero(peer->failoverhostname) && peer->inUse) 
- 		/* We have a failover solution and active calls for this peer */
- 		device_failover_calls(peer);
 	return 0;
 }
 
@@ -16266,7 +15989,7 @@
 		host = tmp;
 	}
 
-	if (create_addr(p, host, FALSE)) {
+	if (create_addr(p, host)) {
 		*cause = AST_CAUSE_UNREGISTERED;
 		if (option_debug > 2)
 			ast_log(LOG_DEBUG, "Cant create SIP call - target device not registred\n");
@@ -16894,12 +16617,6 @@
 			ast_set2_flag(&peer->flags[0], ast_true(v->value), SIP_USEREQPHONE);
 		} else if (!strcasecmp(v->name, "fromuser")) {
 			ast_copy_string(peer->fromuser, v->value, sizeof(peer->fromuser));
-		} else if (!strcasecmp(v->name, "failoverhostport")) {
-			peer->failoveraddr.sin_port = htons(atoi(v->value));
-		} else if (!strcasecmp(v->name, "failoverhost")) {
-			ast_copy_string(peer->failoverhostname, v->value, sizeof(peer->failoverhostname));
-			if (!peer->failoveraddr.sin_port)
-				peer->failoveraddr.sin_port = htons(STANDARD_SIP_PORT);
 		} else if (!strcasecmp(v->name, "host") || !strcasecmp(v->name, "outboundproxy")) {
 			if (!strcasecmp(v->value, "dynamic")) {
 				if (!strcasecmp(v->name, "outboundproxy") || obproxyfound) {
@@ -17081,9 +16798,6 @@
 
 	cfg = ast_config_load(config);
 
-	pbx_builtin_setvar_helper(NULL, "ast_config_dir", AST_CONFIG_DIR);
-	// setenv("ast_config_dir", AST_CONFIG_DIR,1);
-
 	/* We *must* have a config file otherwise stop immediately */
 	if (!cfg) {
 		ast_log(LOG_NOTICE, "Unable to load config %s\n", config);
@@ -18080,29 +17794,6 @@
 	return 0;
 }
 
-
-/*! \brief Redirect call connect with a 300 multiple choices redirect
-\note	Called by the routeresponse() dialplan application through the sip_routeresponse()
-	pbx interface function
- */
-static int sip_redirect_multiplechoices(struct sip_pvt *p, const char *dest, const char *content)
-{
-	/* we'll issue the redirect message here */
-	/* Got to check for "verazcompatibility" and create contact headers here */
-
-	if (!p->uri) {
-		ast_log(LOG_ERROR, "Cannot retrieve the Request URI from the original SIP request!\n");
-		return 0;
-	} else {
-		ast_log(LOG_DEBUG, "The SIP Request URI [%s]\n", p->uri);
-	}
-
-	transmit_response_with_routedata(p, "300 Multiple choices", &p->initreq, content);
-	sip_scheddestroy(p, 10);	 /* Make sure we stop send this reply. */
-	sip_alreadygone(p);
-	return 0;
-}
-
 /*! \brief Return SIP UA's codec (part of the RTP interface) */
 static int sip_get_codec(struct ast_channel *chan)
 {