Review Board 1.7.16


1.4 implementation of fix for issue 12434

Review Request #311 - Created July 15, 2009 and submitted

Mark Michelson
/branches/1.4/
12434
Reviewers
asterisk-dev
Asterisk
In issue 12434, the reporter describes a situation in which audio and video is offered on the call, but because videosupport is disabled in sip.conf, Asterisk gives no response at all to the video offer. According to RFC 3264, all media offers should have a corresponding answer. For offers we do not intend to actually reply to with meaningful values, we should still reply with the port for the media stream set to 0.

In this patch, we take note of what types of media have been offered and save the information on the sip_pvt. The SDP in the response will take into account whether media was offered. If we are not otherwise going to answer a media offer, we will insert an appropriate m= line with the port set to 0.

It is important to note that this patch is pretty much a bandage being applied to a broken bone. The patch *only* helps for situations where video is offered but videosupport is disabled and when udptl_pt is disabled but T.38 is offered. Asterisk is not guaranteed to respond to every media offer. Notable cases are when multiple streams of the same type are offered. The 2 media stream limit is still present with this patch, too.

In trunk and the 1.6.X branches, things will be a bit different since Asterisk also supports text in SDPs as well. Also, since T.38 negotiation is different in those branches, further testing of T.38-specific code will be needed there. I will post a trunk version of these changes to reviewboard after I have written the code.
I set up 2 sipp scenarios. One offered audio and video, and the other offered audio and T.38. I verified that Asterisk gave always gave an appropriate answer to the video and T.38 offers.

Changes between revision 1 and 2

1 2
1 2

  1. /branches/1.4/channels/chan_sip.c: Loading...
/branches/1.4/channels/chan_sip.c
Diff Revision 1 Diff Revision 2
[20] 471 lines
[+20] [+] static const struct cfsip_options {
472
	{ SIP_OPT_RESPRIORITY,	NOT_SUPPORTED,	"resource-priority" },
472
	{ SIP_OPT_RESPRIORITY,	NOT_SUPPORTED,	"resource-priority" },
473
};
473
};
474

    
   
474

   
475

    
   
475

   
476
/*! \brief SIP Methods we support */
476
/*! \brief SIP Methods we support */
477
#define ALLOWED_METHODS "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO"
477
#define ALLOWED_METHODS "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY"
478

    
   
478

   
479
/*! \brief SIP Extensions we support */
479
/*! \brief SIP Extensions we support */
480
#define SUPPORTED_EXTENSIONS "replaces" 
480
#define SUPPORTED_EXTENSIONS "replaces" 
481

    
   
481

   
482
/*! \brief Standard SIP port from RFC 3261. DO NOT CHANGE THIS */
482
/*! \brief Standard SIP port from RFC 3261. DO NOT CHANGE THIS */
[+20] [20] 328 lines
[+20] [+] struct sip_auth {
811

    
   
811

   
812
/* SIP packet flags */
812
/* SIP packet flags */
813
#define SIP_PKT_DEBUG		(1 << 0)	/*!< Debug this packet */
813
#define SIP_PKT_DEBUG		(1 << 0)	/*!< Debug this packet */
814
#define SIP_PKT_WITH_TOTAG	(1 << 1)	/*!< This packet has a to-tag */
814
#define SIP_PKT_WITH_TOTAG	(1 << 1)	/*!< This packet has a to-tag */
815
#define SIP_PKT_IGNORE 		(1 << 2)	/*!< This is a re-transmit, ignore it */
815
#define SIP_PKT_IGNORE 		(1 << 2)	/*!< This is a re-transmit, ignore it */

    
   
816
#define SIP_PKT_IGNORE_RESP	(1 << 3)	/*!< Resp ignore - ??? */
816
#define SIP_PKT_IGNORE_REQ	(1 << 4)	/*!< Req ignore - ??? */
817
#define SIP_PKT_IGNORE_REQ	(1 << 4)	/*!< Req ignore - ??? */
817

    
   
818

   
818
/* T.38 set of flags */
819
/* T.38 set of flags */
819
#define T38FAX_FILL_BIT_REMOVAL		(1 << 0)	/*!< Default: 0 (unset)*/
820
#define T38FAX_FILL_BIT_REMOVAL		(1 << 0)	/*!< Default: 0 (unset)*/
820
#define T38FAX_TRANSCODING_MMR			(1 << 1)	/*!< Default: 0 (unset)*/
821
#define T38FAX_TRANSCODING_MMR			(1 << 1)	/*!< Default: 0 (unset)*/
[+20] [20] 140 lines
[+20] [+] static struct sip_pvt {
961
	unsigned int ocseq;			/*!< Current outgoing seqno */
962
	unsigned int ocseq;			/*!< Current outgoing seqno */
962
	unsigned int icseq;			/*!< Current incoming seqno */
963
	unsigned int icseq;			/*!< Current incoming seqno */
963
	ast_group_t callgroup;			/*!< Call group */
964
	ast_group_t callgroup;			/*!< Call group */
964
	ast_group_t pickupgroup;		/*!< Pickup group */
965
	ast_group_t pickupgroup;		/*!< Pickup group */
965
	int lastinvite;				/*!< Last Cseq of invite */
966
	int lastinvite;				/*!< Last Cseq of invite */

    
   
967
	int lastnoninvite;                      /*!< Last Cseq of non-invite */
966
	struct ast_flags flags[2];		/*!< SIP_ flags */
968
	struct ast_flags flags[2];		/*!< SIP_ flags */
967
	int timer_t1;				/*!< SIP timer T1, ms rtt */
969
	int timer_t1;				/*!< SIP timer T1, ms rtt */
968
	unsigned int sipoptions;		/*!< Supported SIP options on the other end */
970
	unsigned int sipoptions;		/*!< Supported SIP options on the other end */
969
	struct ast_codec_pref prefs;		/*!< codec prefs */
971
	struct ast_codec_pref prefs;		/*!< codec prefs */
970
	int capability;				/*!< Special capability (codec) */
972
	int capability;				/*!< Special capability (codec) */
[+20] [20] 26 lines
[+20] static struct sip_pvt {
997
	struct ast_channel *owner;		/*!< Who owns us (if we have an owner) */
999
	struct ast_channel *owner;		/*!< Who owns us (if we have an owner) */
998
	struct sip_route *route;		/*!< Head of linked list of routing steps (fm Record-Route) */
1000
	struct sip_route *route;		/*!< Head of linked list of routing steps (fm Record-Route) */
999
	int route_persistant;			/*!< Is this the "real" route? */
1001
	int route_persistant;			/*!< Is this the "real" route? */
1000
	struct sip_auth *peerauth;		/*!< Realm authentication */
1002
	struct sip_auth *peerauth;		/*!< Realm authentication */
1001
	int noncecount;				/*!< Nonce-count */
1003
	int noncecount;				/*!< Nonce-count */
1002
	unsigned int stalenonce:1;	/*!< Marks the current nonce as responded too */

   
1003
	char lastmsg[256];			/*!< Last Message sent/received */
1004
	char lastmsg[256];			/*!< Last Message sent/received */
1004
	int amaflags;				/*!< AMA Flags */
1005
	int amaflags;				/*!< AMA Flags */
1005
	int pendinginvite;			/*!< Any pending INVITE or state NOTIFY (in subscribe pvt's) ? (seqno of this) */
1006
	int pendinginvite;			/*!< Any pending INVITE or state NOTIFY (in subscribe pvt's) ? (seqno of this) */
1006
	int glareinvite;			/*!< A invite received while a pending invite is already present is stored here.  Its seqno is the
1007
	int glareinvite;			/*!< A invite received while a pending invite is already present is stored here.  Its seqno is the
1007
						value. Since this glare invite's seqno is not the same as the pending invite's, it must be 
1008
						value. Since this glare invite's seqno is not the same as the pending invite's, it must be 
[+20] [20] 56 lines
[+20] static struct sip_pvt {
1064
struct sip_pkt {
1065
struct sip_pkt {
1065
	struct sip_pkt *next;			/*!< Next packet in linked list */
1066
	struct sip_pkt *next;			/*!< Next packet in linked list */
1066
	int retrans;				/*!< Retransmission number */
1067
	int retrans;				/*!< Retransmission number */
1067
	int method;				/*!< SIP method for this packet */
1068
	int method;				/*!< SIP method for this packet */
1068
	int seqno;				/*!< Sequence number */
1069
	int seqno;				/*!< Sequence number */
1069
	int response_code;		/*!< If this is a response, the response code */

   
1070
	unsigned int flags;			/*!< non-zero if this is a response packet (e.g. 200 OK) */
1070
	unsigned int flags;			/*!< non-zero if this is a response packet (e.g. 200 OK) */
1071
	struct sip_pvt *owner;			/*!< Owner AST call */
1071
	struct sip_pvt *owner;			/*!< Owner AST call */
1072
	int retransid;				/*!< Retransmission ID */
1072
	int retransid;				/*!< Retransmission ID */
1073
	int timer_a;				/*!< SIP timer A, retransmission timer */
1073
	int timer_a;				/*!< SIP timer A, retransmission timer */
1074
	int timer_t1;				/*!< SIP Timer T1, estimated RTT or 500 ms */
1074
	int timer_t1;				/*!< SIP Timer T1, estimated RTT or 500 ms */
[+20] [20] 241 lines
[+20] [+] static struct sip_pvt *sip_alloc(ast_string_field callid, struct sockaddr_in *sin,
1316
static int __sip_autodestruct(const void *data);
1316
static int __sip_autodestruct(const void *data);
1317
static void sip_scheddestroy(struct sip_pvt *p, int ms);
1317
static void sip_scheddestroy(struct sip_pvt *p, int ms);
1318
static int sip_cancel_destroy(struct sip_pvt *p);
1318
static int sip_cancel_destroy(struct sip_pvt *p);
1319
static void sip_destroy(struct sip_pvt *p);
1319
static void sip_destroy(struct sip_pvt *p);
1320
static int __sip_destroy(struct sip_pvt *p, int lockowner);
1320
static int __sip_destroy(struct sip_pvt *p, int lockowner);
1321
static int __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod);
1321
static void __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod);
1322
static void __sip_pretend_ack(struct sip_pvt *p);
1322
static void __sip_pretend_ack(struct sip_pvt *p);
1323
static int __sip_semi_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod);
1323
static int __sip_semi_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod);
1324
static int auto_congest(const void *nothing);
1324
static int auto_congest(const void *nothing);
1325
static int update_call_counter(struct sip_pvt *fup, int event);
1325
static int update_call_counter(struct sip_pvt *fup, int event);
1326
static int hangup_sip2cause(int cause);
1326
static int hangup_sip2cause(int cause);
[+20] [20] 246 lines
[+20] [+] static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req, int debug, int ignore, int seqno, struct sockaddr_in *sin);
1573
static int local_attended_transfer(struct sip_pvt *transferer, struct sip_dual *current, struct sip_request *req, int seqno);
1573
static int local_attended_transfer(struct sip_pvt *transferer, struct sip_dual *current, struct sip_request *req, int seqno);
1574

    
   
1574

   
1575
/*------Response handling functions */
1575
/*------Response handling functions */
1576
static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno);
1576
static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno);
1577
static void handle_response_refer(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno);
1577
static void handle_response_refer(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno);
1578
static int handle_response_register(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno);
1578
static int handle_response_register(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno);
1579
static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno);
1579
static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno);
1580

    
   
1580

   
1581
/*----- RTP interface functions */
1581
/*----- RTP interface functions */
1582
static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active);
1582
static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active);
1583
static enum ast_rtp_get_result sip_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
1583
static enum ast_rtp_get_result sip_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
1584
static enum ast_rtp_get_result sip_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
1584
static enum ast_rtp_get_result sip_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
[+20] [20] 484 lines
[+20] [+] static int retrans_pkt(const void *data)
2069
static enum sip_result __sip_reliable_xmit(struct sip_pvt *p, int seqno, int resp, char *data, int len, int fatal, int sipmethod)
2069
static enum sip_result __sip_reliable_xmit(struct sip_pvt *p, int seqno, int resp, char *data, int len, int fatal, int sipmethod)
2070
{
2070
{
2071
	struct sip_pkt *pkt;
2071
	struct sip_pkt *pkt;
2072
	int siptimer_a = DEFAULT_RETRANS;
2072
	int siptimer_a = DEFAULT_RETRANS;
2073
	int xmitres = 0;
2073
	int xmitres = 0;
2074
	int respid;

   
2075

    
   
2074

   
2076
	if (!(pkt = ast_calloc(1, sizeof(*pkt) + len + 1)))
2075
	if (!(pkt = ast_calloc(1, sizeof(*pkt) + len + 1)))
2077
		return AST_FAILURE;
2076
		return AST_FAILURE;
2078
	memcpy(pkt->data, data, len);
2077
	memcpy(pkt->data, data, len);
2079
	pkt->method = sipmethod;
2078
	pkt->method = sipmethod;
2080
	pkt->packetlen = len;
2079
	pkt->packetlen = len;
2081
	pkt->next = p->packets;
2080
	pkt->next = p->packets;
2082
	pkt->owner = p;
2081
	pkt->owner = p;
2083
	pkt->seqno = seqno;
2082
	pkt->seqno = seqno;
2084
	pkt->data[len] = '\0';
2083
	if (resp)
2085
	if (resp) {

   
2086
		ast_set_flag(pkt, FLAG_RESPONSE);
2084
		ast_set_flag(pkt, FLAG_RESPONSE);
2087
		/* Parse out the response code */
2085
	pkt->data[len] = '\0';
2088
		if (sscanf(pkt->data, "SIP/2.0 %d", &respid) == 1) {

   
2089
			pkt->response_code = respid;

   
2090
		}

   
2091
	}

   
2092
	pkt->timer_t1 = p->timer_t1;	/* Set SIP timer T1 */
2086
	pkt->timer_t1 = p->timer_t1;	/* Set SIP timer T1 */
2093
	pkt->retransid = -1;
2087
	pkt->retransid = -1;
2094
	if (fatal)
2088
	if (fatal)
2095
		ast_set_flag(pkt, FLAG_FATAL);
2089
		ast_set_flag(pkt, FLAG_FATAL);
2096
	if (pkt->timer_t1)
2090
	if (pkt->timer_t1)
[+20] [20] 40 lines
[+20] [+] static int __sip_autodestruct(const void *data)
2137
	/* via bug 12101, the two usages of SIP_NEEDDESTROY in the following block
2131
	/* via bug 12101, the two usages of SIP_NEEDDESTROY in the following block
2138
	* of code make a sort of "safety relief valve", that allows sip channels
2132
	* of code make a sort of "safety relief valve", that allows sip channels
2139
	* that were created via INVITE, then thru some sequence were CANCELED,
2133
	* that were created via INVITE, then thru some sequence were CANCELED,
2140
	* to die, rather than infinitely be rescheduled */
2134
	* to die, rather than infinitely be rescheduled */
2141
	if (p->packets && !ast_test_flag(&p->flags[0], SIP_NEEDDESTROY)) {
2135
	if (p->packets && !ast_test_flag(&p->flags[0], SIP_NEEDDESTROY)) {
2142
		char method_str[30];

   
2143
		if (option_debug > 2)
2136
		if (option_debug > 2)
2144
			ast_log(LOG_DEBUG, "Re-scheduled destruction of SIP call %s\n", p->callid ? p->callid : "<unknown>");
2137
			ast_log(LOG_DEBUG, "Re-scheduled destruction of SIP call %s\n", p->callid ? p->callid : "<unknown>");
2145
		append_history(p, "ReliableXmit", "timeout");
2138
		append_history(p, "ReliableXmit", "timeout");
2146
		if (sscanf(p->lastmsg, "Tx: %s", method_str) == 1 || sscanf(p->lastmsg, "Rx: %s", method_str) == 1) {
2139
		if (p->method == SIP_CANCEL || p->method == SIP_BYE) {
2147
			if (method_match(SIP_CANCEL, method_str) || method_match(SIP_BYE, method_str)) {

   
2148
				ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
2140
			ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
2149
			}
2141
		}
2150
		}

   
2151
		return 10000;
2142
		return 10000;
2152
	}
2143
	}
2153

    
   
2144

   
2154
	/* If we're destroying a subscription, dereference peer object too */
2145
	/* If we're destroying a subscription, dereference peer object too */
2155
	if (p->subscribed == MWI_NOTIFICATION && p->relatedpeer)
2146
	if (p->subscribed == MWI_NOTIFICATION && p->relatedpeer)
[+20] [20] 48 lines
[+20] [+] static int sip_cancel_destroy(struct sip_pvt *p)
2204
	return res;
2195
	return res;
2205
}
2196
}
2206

    
   
2197

   
2207
/*! \brief Acknowledges receipt of a packet and stops retransmission 
2198
/*! \brief Acknowledges receipt of a packet and stops retransmission 
2208
 * called with p locked*/
2199
 * called with p locked*/
2209
static int __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod)
2200
static void __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod)
2210
{
2201
{
2211
	struct sip_pkt *cur, *prev = NULL;
2202
	struct sip_pkt *cur, *prev = NULL;
2212

    
   
2203

   
2213
	/* Just in case... */
2204
	/* Just in case... */
2214
	char *msg;
2205
	char *msg;
[+20] [20] 38 lines
[+20] static int __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod) static void __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod)
2253
			break;
2244
			break;
2254
		}
2245
		}
2255
	}
2246
	}
2256
	if (option_debug)
2247
	if (option_debug)
2257
		ast_log(LOG_DEBUG, "Stopping retransmission on '%s' of %s %d: Match %s\n", p->callid, resp ? "Response" : "Request", seqno, res == FALSE ? "Not Found" : "Found");
2248
		ast_log(LOG_DEBUG, "Stopping retransmission on '%s' of %s %d: Match %s\n", p->callid, resp ? "Response" : "Request", seqno, res == FALSE ? "Not Found" : "Found");
2258
	return res;

   
2259
}
2249
}
2260

    
   
2250

   
2261
/*! \brief Pretend to ack all packets
2251
/*! \brief Pretend to ack all packets
2262
 * called with p locked */
2252
 * called with p locked */
2263
static void __sip_pretend_ack(struct sip_pvt *p)
2253
static void __sip_pretend_ack(struct sip_pvt *p)
[+20] [20] 14 lines
[+20] static int __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod) static void __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod)
2278

    
   
2268

   
2279
/*! \brief Acks receipt of packet, keep it around (used for provisional responses) */
2269
/*! \brief Acks receipt of packet, keep it around (used for provisional responses) */
2280
static int __sip_semi_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod)
2270
static int __sip_semi_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod)
2281
{
2271
{
2282
	struct sip_pkt *cur;
2272
	struct sip_pkt *cur;
2283
	int res = FALSE;
2273
	int res = -1;
2284

    
   
2274

   
2285
	for (cur = p->packets; cur; cur = cur->next) {
2275
	for (cur = p->packets; cur; cur = cur->next) {
2286
		if (cur->seqno == seqno && ast_test_flag(cur, FLAG_RESPONSE) == resp &&
2276
		if (cur->seqno == seqno && ast_test_flag(cur, FLAG_RESPONSE) == resp &&
2287
			(ast_test_flag(cur, FLAG_RESPONSE) || method_match(sipmethod, cur->data))) {
2277
			(ast_test_flag(cur, FLAG_RESPONSE) || method_match(sipmethod, cur->data))) {
2288
			/* this is our baby */
2278
			/* this is our baby */
2289
			if (cur->retransid > -1) {
2279
			if (cur->retransid > -1) {
2290
				if (option_debug > 3 && sipdebug)
2280
				if (option_debug > 3 && sipdebug)
2291
					ast_log(LOG_DEBUG, "*** SIP TIMER: Cancelling retransmission #%d - %s (got response)\n", cur->retransid, sip_methods[sipmethod].text);
2281
					ast_log(LOG_DEBUG, "*** SIP TIMER: Cancelling retransmission #%d - %s (got response)\n", cur->retransid, sip_methods[sipmethod].text);
2292
			}
2282
			}
2293
			AST_SCHED_DEL(sched, cur->retransid);
2283
			AST_SCHED_DEL(sched, cur->retransid);
2294
			res = TRUE;
2284
			res = 0;
2295
			break;
2285
			break;
2296
		}
2286
		}
2297
	}
2287
	}
2298
	if (option_debug)
2288
	if (option_debug)
2299
		ast_log(LOG_DEBUG, "(Provisional) Stopping retransmission (but retaining packet) on '%s' %s %d: %s\n", p->callid, resp ? "Response" : "Request", seqno, res == -1 ? "Not Found" : "Found");
2289
		ast_log(LOG_DEBUG, "(Provisional) Stopping retransmission (but retaining packet) on '%s' %s %d: %s\n", p->callid, resp ? "Response" : "Request", seqno, res == -1 ? "Not Found" : "Found");
[+20] [20] 1385 lines
[+20] [+] static int sip_hangup(struct ast_channel *ast)
3685
	/* Start the process if it's not already started */
3675
	/* Start the process if it's not already started */
3686
	if (!ast_test_flag(&p->flags[0], SIP_ALREADYGONE) && !ast_strlen_zero(p->initreq.data)) {
3676
	if (!ast_test_flag(&p->flags[0], SIP_ALREADYGONE) && !ast_strlen_zero(p->initreq.data)) {
3687
		if (needcancel) {	/* Outgoing call, not up */
3677
		if (needcancel) {	/* Outgoing call, not up */
3688
			if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
3678
			if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
3689
				/* stop retransmitting an INVITE that has not received a response */
3679
				/* stop retransmitting an INVITE that has not received a response */
3690
				struct sip_pkt *cur;
3680
				__sip_pretend_ack(p);
3691
				for (cur = p->packets; cur; cur = cur->next) {

   
3692
					__sip_semi_ack(p, cur->seqno, ast_test_flag(cur, FLAG_RESPONSE), cur->method ? cur->method : find_sip_method(cur->data));

   
3693
				}

   
3694

    
   
3681

   
3695
				/* if we can't send right now, mark it pending */
3682
				/* if we can't send right now, mark it pending */
3696
				if (p->invitestate == INV_CALLING) {
3683
				if (p->invitestate == INV_CALLING) {
3697
					/* We can't send anything in CALLING state */
3684
					/* We can't send anything in CALLING state */
3698
					ast_set_flag(&p->flags[0], SIP_PENDINGBYE);
3685
					ast_set_flag(&p->flags[0], SIP_PENDINGBYE);
[+20] [20] 60 lines
[+20] static int sip_hangup(struct ast_channel *ast)
3759
static void try_suggested_sip_codec(struct sip_pvt *p)
3746
static void try_suggested_sip_codec(struct sip_pvt *p)
3760
{
3747
{
3761
	int fmt;
3748
	int fmt;
3762
	const char *codec;
3749
	const char *codec;
3763

    
   
3750

   
3764
	while (p->owner && ast_channel_trylock(p->owner)) {
3751
	codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC");
3765
		ast_mutex_unlock(&p->lock);
3752
	if (!codec) 
3766
		sched_yield();

   
3767
		ast_mutex_lock(&p->lock);

   
3768
	}

   
3769

    
   

   
3770
	if (!p->owner)

   
3771
		return;

   
3772

    
   

   
3773
	codec = ast_strdupa(S_OR(pbx_builtin_getvar_helper(p->owner, "SIP_CODEC"), ""));

   
3774

    
   

   
3775
	ast_channel_unlock(p->owner);

   
3776

    
   

   
3777
	if (ast_strlen_zero(codec))

   
3778
		return;
3753
		return;
3779

    
   
3754

   
3780
	fmt = ast_getformatbyname(codec);
3755
	fmt = ast_getformatbyname(codec);
3781
	if (fmt) {
3756
	if (fmt) {
3782
		ast_log(LOG_NOTICE, "Changing codec to '%s' for this call because of ${SIP_CODEC} variable\n", codec);
3757
		ast_log(LOG_NOTICE, "Changing codec to '%s' for this call because of ${SIP_CODEC} variable\n", codec);
[+20] [20] 840 lines
[+20] [+] static struct sip_pvt *sip_alloc(ast_string_field callid, struct sockaddr_in *sin,
4623
		if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT))
4598
		if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT))
4624
			p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr);
4599
			p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr);
4625
		if (!p->rtp || (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) && !p->vrtp)) {
4600
		if (!p->rtp || (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) && !p->vrtp)) {
4626
			ast_log(LOG_WARNING, "Unable to create RTP audio %s session: %s\n",
4601
			ast_log(LOG_WARNING, "Unable to create RTP audio %s session: %s\n",
4627
				ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "and video" : "", strerror(errno));
4602
				ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "and video" : "", strerror(errno));
4628
			/* If rtp was successfully allocated, but vrtp was not, then we need to be sure to free rtp here */

   
4629
			if (p->rtp) {

   
4630
				ast_rtp_destroy(p->rtp);

   
4631
			}

   
4632
			if (p->udptl) {

   
4633
				ast_udptl_destroy(p->udptl);

   
4634
			}

   
4635
			ast_mutex_destroy(&p->lock);
4603
			ast_mutex_destroy(&p->lock);
4636
			if (p->chanvars) {
4604
			if (p->chanvars) {
4637
				ast_variables_destroy(p->chanvars);
4605
				ast_variables_destroy(p->chanvars);
4638
				p->chanvars = NULL;
4606
				p->chanvars = NULL;
4639
			}
4607
			}
4640
			ast_string_field_free_memory(p);

   
4641
			free(p);
4608
			free(p);
4642
			return NULL;
4609
			return NULL;
4643
		}
4610
		}
4644
		ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
4611
		ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
4645
		ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
4612
		ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
[+20] [20] 540 lines
[+20] [+] static int get_ip_and_port_from_sdp(struct sip_request *req, const enum media_type media, struct sockaddr_in *sin)
5186
	if (sscanf(c, "IN IP4 %256s", host) != 1) {
5153
	if (sscanf(c, "IN IP4 %256s", host) != 1) {
5187
		ast_log(LOG_WARNING, "Invalid host in c= line, '%s'\n", c);
5154
		ast_log(LOG_WARNING, "Invalid host in c= line, '%s'\n", c);
5188
		/* Continue since there may be a valid host in a c= line specific to the audio stream */
5155
		/* Continue since there may be a valid host in a c= line specific to the audio stream */
5189
	}
5156
	}
5190
	/* We only want the m and c lines for audio */
5157
	/* We only want the m and c lines for audio */
5191
	for (m = get_sdp_iterate(&miterator, req, "m"); !ast_strlen_zero(m); m = get_sdp_iterate(&miterator, req, "m")) {
5158
	while ((m = get_sdp_iterate(&miterator, req, "m"))) {
5192
		if ((media == SDP_AUDIO && ((sscanf(m, "audio %d/%d RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) ||
5159
		if ((media == SDP_AUDIO && ((sscanf(m, "audio %d/%d RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) ||
5193
		    (sscanf(m, "audio %d RTP/AVP %n", &x, &len) == 1 && len > 0))) ||
5160
		    (sscanf(m, "audio %d RTP/AVP %n", &x, &len) == 1 && len > 0))) ||
5194
			(media == SDP_VIDEO && ((sscanf(m, "video %d/%d RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) ||
5161
			(media == SDP_VIDEO && ((sscanf(m, "video %d/%d RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) ||
5195
		    (sscanf(m, "video %d RTP/AVP %n", &x, &len) == 1 && len > 0)))) {
5162
		    (sscanf(m, "video %d RTP/AVP %n", &x, &len) == 1 && len > 0)))) {
5196
			/* See if there's a c= line for this media stream.
5163
			/* See if there's a c= line for this media stream.
[+20] [20] 159 lines
[+20] [+] static int process_sdp(struct sip_pvt *p, struct sip_request *req)
5356
			numberofmediastreams++;
5323
			numberofmediastreams++;
5357
			vportno = x;
5324
			vportno = x;
5358
			/* Scan through the RTP payload types specified in a "m=" line: */
5325
			/* Scan through the RTP payload types specified in a "m=" line: */
5359
			codecs = m + len;
5326
			codecs = m + len;
5360
			ast_copy_string(p->offered_media[SDP_VIDEO].text, codecs, sizeof(p->offered_media[SDP_VIDEO].text));
5327
			ast_copy_string(p->offered_media[SDP_VIDEO].text, codecs, sizeof(p->offered_media[SDP_VIDEO].text));
5361
			for (codecs = m + len; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) {
5328
			for (; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) {
5362
				if (sscanf(codecs, "%d%n", &codec, &len) != 1) {
5329
				if (sscanf(codecs, "%d%n", &codec, &len) != 1) {
5363
					ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
5330
					ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
5364
					return -1;
5331
					return -1;
5365
				}
5332
				}
5366
				if (debug)
5333
				if (debug)
[+20] [20] 1415 lines
[+20] [+] static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int add_audio, int add_t38)
6782
				vdest.sin_port = p->vredirip.sin_port;
6749
				vdest.sin_port = p->vredirip.sin_port;
6783
			} else {
6750
			} else {
6784
				vdest.sin_addr = p->ourip;
6751
				vdest.sin_addr = p->ourip;
6785
				vdest.sin_port = vsin.sin_port;
6752
				vdest.sin_port = vsin.sin_port;
6786
			}
6753
			}
6787
			ast_build_string(&m_video_next, &m_video_left, "m=video %d RTP/AVP", ntohs(vsin.sin_port));
6754
			ast_build_string(&m_video_next, &m_video_left, "m=video %d RTP/AVP", ntohs(vdest.sin_port));
6788

    
   
6755

   
6789
			/* Build max bitrate string */
6756
			/* Build max bitrate string */
6790
			if (p->maxcallbitrate)
6757
			if (p->maxcallbitrate)
6791
				snprintf(bandwidth, sizeof(bandwidth), "b=CT:%d\r\n", p->maxcallbitrate);
6758
				snprintf(bandwidth, sizeof(bandwidth), "b=CT:%d\r\n", p->maxcallbitrate);
6792
			if (debug) 
6759
			if (debug) 
[+20] [20] 565 lines
[+20] [+] static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod)
7358
	
7325
	
7359
	init_req(req, sipmethod, p->uri);
7326
	init_req(req, sipmethod, p->uri);
7360
	snprintf(tmp, sizeof(tmp), "%d %s", ++p->ocseq, sip_methods[sipmethod].text);
7327
	snprintf(tmp, sizeof(tmp), "%d %s", ++p->ocseq, sip_methods[sipmethod].text);
7361

    
   
7328

   
7362
	add_header(req, "Via", p->via);
7329
	add_header(req, "Via", p->via);
7363
	/* This will be a no-op most of the time. However, under certain circumstances,
7330
	/* SLD: FIXME?: do Route: here too?  I think not cos this is the first request.
7364
	 * NOTIFY messages will use this function for preparing the request and should
7331
	 * OTOH, then we won't have anything in p->route anyway */
7365
	 * have Route headers present.

   
7366
	 */

   
7367
	add_route(req, p->route);

   
7368
	/* Build Remote Party-ID and From */
7332
	/* Build Remote Party-ID and From */
7369
	if (ast_test_flag(&p->flags[0], SIP_SENDRPID) && (sipmethod == SIP_INVITE)) {
7333
	if (ast_test_flag(&p->flags[0], SIP_SENDRPID) && (sipmethod == SIP_INVITE)) {
7370
		build_rpid(p);
7334
		build_rpid(p);
7371
		add_header(req, "From", p->rpid_from);
7335
		add_header(req, "From", p->rpid_from);
7372
	} else 
7336
	} else 
[+20] [20] 310 lines
[+20] [+] static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs, char *vmexten)
7683
	initreqprep(&req, p, SIP_NOTIFY);
7647
	initreqprep(&req, p, SIP_NOTIFY);
7684
	add_header(&req, "Event", "message-summary");
7648
	add_header(&req, "Event", "message-summary");
7685
	add_header(&req, "Content-Type", default_notifymime);
7649
	add_header(&req, "Content-Type", default_notifymime);
7686

    
   
7650

   
7687
	ast_build_string(&t, &maxbytes, "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no");
7651
	ast_build_string(&t, &maxbytes, "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no");
7688
	/* if we listen to non-standard SIP port we have to specify the SIP port

   
7689
       in the URI, except domains are used - in this case the SRV records should be

   
7690
       used to redirect the client to the non-standard SIP port */

   
7691
	if ((ourport != STANDARD_SIP_PORT) && ast_strlen_zero(p->fromdomain)) {

   
7692
		ast_build_string(&t, &maxbytes, "Message-Account: sip:%s@%s:%d\r\n",

   
7693
		S_OR(vmexten, default_vmexten), ast_inet_ntoa(p->ourip), ourport);

   
7694
	} else {

   
7695
		ast_build_string(&t, &maxbytes, "Message-Account: sip:%s@%s\r\n",
7652
	ast_build_string(&t, &maxbytes, "Message-Account: sip:%s@%s\r\n",
7696
		S_OR(vmexten, default_vmexten), S_OR(p->fromdomain, ast_inet_ntoa(p->ourip)));
7653
		S_OR(vmexten, default_vmexten), S_OR(p->fromdomain, ast_inet_ntoa(p->ourip)));
7697
	}

   
7698
	/* Cisco has a bug in the SIP stack where it can't accept the
7654
	/* Cisco has a bug in the SIP stack where it can't accept the
7699
		(0/0) notification. This can temporarily be disabled in
7655
		(0/0) notification. This can temporarily be disabled in
7700
		sip.conf with the "buggymwi" option */
7656
		sip.conf with the "buggymwi" option */
7701
	ast_build_string(&t, &maxbytes, "Voice-Message: %d/%d%s\r\n", newmsgs, oldmsgs, (ast_test_flag(&p->flags[1], SIP_PAGE2_BUGGY_MWI) ? "" : " (0/0)"));
7657
	ast_build_string(&t, &maxbytes, "Voice-Message: %d/%d%s\r\n", newmsgs, oldmsgs, (ast_test_flag(&p->flags[1], SIP_PAGE2_BUGGY_MWI) ? "" : " (0/0)"));
7702

    
   
7658

   
[+20] [20] 42 lines
[+20] [+] static int transmit_notify_with_sipfrag(struct sip_pvt *p, int cseq, char *message, int terminate)
7745
	add_line(&req, tmp);
7701
	add_line(&req, tmp);
7746

    
   
7702

   
7747
	if (!p->initreq.headers)
7703
	if (!p->initreq.headers)
7748
		initialize_initreq(p, &req);
7704
		initialize_initreq(p, &req);
7749

    
   
7705

   

    
   
7706
	p->lastnoninvite = p->ocseq;

    
   
7707

   
7750
	return send_request(p, &req, XMIT_RELIABLE, p->ocseq);
7708
	return send_request(p, &req, XMIT_RELIABLE, p->ocseq);
7751
}
7709
}
7752

    
   
7710

   
7753
/*! \brief Convert registration state status to string */
7711
/*! \brief Convert registration state status to string */
7754
static char *regstate2str(enum sipregistrystate regstate)
7712
static char *regstate2str(enum sipregistrystate regstate)
[+20] [20] 983 lines
[+20] [+] static void build_route(struct sip_pvt *p, struct sip_request *req, int backwards)
8738
	/* For debugging dump what we ended up with */
8696
	/* For debugging dump what we ended up with */
8739
	if (sip_debug_test_pvt(p))
8697
	if (sip_debug_test_pvt(p))
8740
		list_route(p->route);
8698
		list_route(p->route);
8741
}
8699
}
8742

    
   
8700

   
8743
/*! \brief builds the sip_pvt's randdata field which is used for the nonce

   
8744
 *  challenge.  When forceupdate is not set, the nonce is only updated if

   
8745
 *  the current one is stale.  In this case, a stalenonce is one which

   
8746
 *  has already received a response, if a nonce has not received a response

   
8747
 *  it is not always necessary or beneficial to create a new one. */

   
8748

    
   

   
8749
static void set_nonce_randdata(struct sip_pvt *p, int forceupdate)

   
8750
{

   
8751
	if (p->stalenonce || forceupdate || ast_strlen_zero(p->randdata)) {

   
8752
		ast_string_field_build(p, randdata, "%08lx", ast_random());	/* Create nonce for challenge */

   
8753
		p->stalenonce = 0;

   
8754
	}

   
8755
}

   
8756

    
   

   
8757
AST_THREADSTORAGE(check_auth_buf, check_auth_buf_init);
8701
AST_THREADSTORAGE(check_auth_buf, check_auth_buf_init);
8758
#define CHECK_AUTH_BUF_INITLEN   256
8702
#define CHECK_AUTH_BUF_INITLEN   256
8759

    
   
8703

   
8760
/*! \brief  Check user authorization from peer definition 
8704
/*! \brief  Check user authorization from peer definition 
8761
	Some actions, like REGISTER and INVITEs from peers require
8705
	Some actions, like REGISTER and INVITEs from peers require
[+20] [20] 53 lines
[+20] [+] static enum check_auth_result check_auth(struct sip_pvt *p, struct sip_request *req, const char *username,
8815
			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
8759
			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
8816
		}
8760
		}
8817
		return AUTH_CHALLENGE_SENT;
8761
		return AUTH_CHALLENGE_SENT;
8818
	} else if (ast_strlen_zero(p->randdata) || ast_strlen_zero(authtoken)) {
8762
	} else if (ast_strlen_zero(p->randdata) || ast_strlen_zero(authtoken)) {
8819
		/* We have no auth, so issue challenge and request authentication */
8763
		/* We have no auth, so issue challenge and request authentication */
8820
		set_nonce_randdata(p, 1); /* Create nonce for challenge */
8764
		ast_string_field_build(p, randdata, "%08lx", ast_random());	/* Create nonce for challenge */
8821
		transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, 0);
8765
		transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, 0);
8822
		/* Schedule auto destroy in 32 seconds */
8766
		/* Schedule auto destroy in 32 seconds */
8823
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
8767
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
8824
		return AUTH_CHALLENGE_SENT;
8768
		return AUTH_CHALLENGE_SENT;
8825
	} 
8769
	} 
[+20] [20] 40 lines
[+20] static enum check_auth_result check_auth(struct sip_pvt *p, struct sip_request *req, const char *username,
8866
			username, keys[K_USER].s);
8810
			username, keys[K_USER].s);
8867
		/* Oops, we're trying something here */
8811
		/* Oops, we're trying something here */
8868
		return AUTH_USERNAME_MISMATCH;
8812
		return AUTH_USERNAME_MISMATCH;
8869
	}
8813
	}
8870

    
   
8814

   
8871
	/* Verify nonce from request matches our nonce, and the nonce has not already been responded to.
8815
	/* Verify nonce from request matches our nonce.  If not, send 401 with new nonce */
8872
	 * If this check fails, send 401 with new nonce */
8816
	if (strcasecmp(p->randdata, keys[K_NONCE].s)) { /* XXX it was 'n'casecmp ? */
8873
	if (strcasecmp(p->randdata, keys[K_NONCE].s) || p->stalenonce) { /* XXX it was 'n'casecmp ? */

   
8874
		wrongnonce = TRUE;
8817
		wrongnonce = TRUE;
8875
		usednonce = keys[K_NONCE].s;
8818
		usednonce = keys[K_NONCE].s;
8876
	} else {

   
8877
		p->stalenonce = 1; /* now, since the nonce has a response, mark it as stale so it can't be sent or responded to again */

   
8878
	}
8819
	}
8879

    
   
8820

   
8880
	if (!ast_strlen_zero(md5secret))
8821
	if (!ast_strlen_zero(md5secret))
8881
		ast_copy_string(a1_hash, md5secret, sizeof(a1_hash));
8822
		ast_copy_string(a1_hash, md5secret, sizeof(a1_hash));
8882
	else {
8823
	else {
[+20] [20] 20 lines
[+20] static enum check_auth_result check_auth(struct sip_pvt *p, struct sip_request *req, const char *username,
8903
	if (wrongnonce) {
8844
	if (wrongnonce) {
8904
		if (good_response) {
8845
		if (good_response) {
8905
			if (sipdebug)
8846
			if (sipdebug)
8906
				ast_log(LOG_NOTICE, "Correct auth, but based on stale nonce received from '%s'\n", get_header(req, "To"));
8847
				ast_log(LOG_NOTICE, "Correct auth, but based on stale nonce received from '%s'\n", get_header(req, "To"));
8907
			/* We got working auth token, based on stale nonce . */
8848
			/* We got working auth token, based on stale nonce . */
8908
			set_nonce_randdata(p, 0);
8849
			ast_string_field_build(p, randdata, "%08lx", ast_random());
8909
			transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, TRUE);
8850
			transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, TRUE);
8910
		} else {
8851
		} else {
8911
			/* Everything was wrong, so give the device one more try with a new challenge */
8852
			/* Everything was wrong, so give the device one more try with a new challenge */
8912
			if (!ast_test_flag(req, SIP_PKT_IGNORE)) {
8853
			if (!ast_test_flag(req, SIP_PKT_IGNORE)) {
8913
				if (sipdebug)
8854
				if (sipdebug)
8914
					ast_log(LOG_NOTICE, "Bad authentication received from '%s'\n", get_header(req, "To"));
8855
					ast_log(LOG_NOTICE, "Bad authentication received from '%s'\n", get_header(req, "To"));
8915
				set_nonce_randdata(p, 1);
8856
				ast_string_field_build(p, randdata, "%08lx", ast_random());
8916
			} else {
8857
			} else {
8917
				if (sipdebug)
8858
				if (sipdebug)
8918
					ast_log(LOG_NOTICE, "Duplicate authentication received from '%s'\n", get_header(req, "To"));
8859
					ast_log(LOG_NOTICE, "Duplicate authentication received from '%s'\n", get_header(req, "To"));
8919
			}
8860
			}
8920
			transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, FALSE);
8861
			transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, FALSE);
[+20] [20] 116 lines
[+20] [+] static void transmit_fake_auth_response(struct sip_pvt *p, int sipmethod, struct sip_request *req, enum xmittype reliable)
9037
		/* Schedule auto destroy in 32 seconds (according to RFC 3261) */
8978
		/* Schedule auto destroy in 32 seconds (according to RFC 3261) */
9038
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
8979
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
9039
		return;
8980
		return;
9040
	} else if (ast_strlen_zero(p->randdata) || ast_strlen_zero(authtoken)) {
8981
	} else if (ast_strlen_zero(p->randdata) || ast_strlen_zero(authtoken)) {
9041
		/* We have no auth, so issue challenge and request authentication */
8982
		/* We have no auth, so issue challenge and request authentication */
9042
		set_nonce_randdata(p, 1);
8983
		ast_string_field_build(p, randdata, "%08lx", ast_random());	/* Create nonce for challenge */
9043
		transmit_response_with_auth(p, response, req, p->randdata, 0, respheader, 0);
8984
		transmit_response_with_auth(p, response, req, p->randdata, 0, respheader, 0);
9044
		/* Schedule auto destroy in 32 seconds */
8985
		/* Schedule auto destroy in 32 seconds */
9045
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
8986
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
9046
		return;
8987
		return;
9047
	}
8988
	}
[+20] [20] 34 lines
[+20] static void transmit_fake_auth_response(struct sip_pvt *p, int sipmethod, struct sip_request *req, enum xmittype reliable)
9082
	}
9023
	}
9083

    
   
9024

   
9084
	/* Verify nonce from request matches our nonce.  If not, send 401 with new nonce */
9025
	/* Verify nonce from request matches our nonce.  If not, send 401 with new nonce */
9085
	if (strcasecmp(p->randdata, keys[K_NONCE].s)) {
9026
	if (strcasecmp(p->randdata, keys[K_NONCE].s)) {
9086
		if (!ast_test_flag(req, SIP_PKT_IGNORE)) {
9027
		if (!ast_test_flag(req, SIP_PKT_IGNORE)) {
9087
			set_nonce_randdata(p, 1);
9028
			ast_string_field_build(p, randdata, "%08lx", ast_random());
9088
		}
9029
		}
9089
		transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, FALSE);
9030
		transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, FALSE);
9090

    
   
9031

   
9091
		/* Schedule auto destroy in 32 seconds */
9032
		/* Schedule auto destroy in 32 seconds */
9092
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
9033
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
[+20] [20] 3891 lines
[+20] [+] static void handle_response_refer(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno)
12984
		break;
12925
		break;
12985
	}
12926
	}
12986
}
12927
}
12987

    
   
12928

   
12988
/*! \brief Handle responses on REGISTER to services */
12929
/*! \brief Handle responses on REGISTER to services */
12989
static int handle_response_register(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno)
12930
static int handle_response_register(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno)
12990
{
12931
{
12991
	int expires, expires_ms;
12932
	int expires, expires_ms;
12992
	struct sip_registry *r;
12933
	struct sip_registry *r;
12993
	r=p->registry;
12934
	r=p->registry;
12994

    
   
12935

   
[+20] [20] 189 lines
[+20] [+] static void stop_media_flows(struct sip_pvt *p)
13184
		ast_udptl_stop(p->udptl);
13125
		ast_udptl_stop(p->udptl);
13185
}
13126
}
13186

    
   
13127

   
13187
/*! \brief Handle SIP response in dialogue */
13128
/*! \brief Handle SIP response in dialogue */
13188
/* XXX only called by handle_request */
13129
/* XXX only called by handle_request */
13189
static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno)
13130
static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno)
13190
{
13131
{
13191
	struct ast_channel *owner;
13132
	struct ast_channel *owner;
13192
	int sipmethod;
13133
	int sipmethod;
13193
	int res = 1;
13134
	int res = 1;
13194
	int ack_res;

   
13195
	const char *c = get_header(req, "Cseq");
13135
	const char *c = get_header(req, "Cseq");
13196
	/* GCC 4.2 complains if I try to cast c as a char * when passing it to ast_skip_nonblanks, so make a copy of it */
13136
	/* GCC 4.2 complains if I try to cast c as a char * when passing it to ast_skip_nonblanks, so make a copy of it */
13197
	char *c_copy = ast_strdupa(c);
13137
	char *c_copy = ast_strdupa(c);
13198
	/* Skip the Cseq and its subsequent spaces */
13138
	/* Skip the Cseq and its subsequent spaces */
13199
	const char *msg = ast_skip_blanks(ast_skip_nonblanks(c_copy));
13139
	const char *msg = ast_skip_blanks(ast_skip_nonblanks(c_copy));
[+20] [20] 6 lines
[+20] static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno) static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno)
13206
	owner = p->owner;
13146
	owner = p->owner;
13207
	if (owner) 
13147
	if (owner) 
13208
		owner->hangupcause = hangup_sip2cause(resp);
13148
		owner->hangupcause = hangup_sip2cause(resp);
13209

    
   
13149

   
13210
	/* Acknowledge whatever it is destined for */
13150
	/* Acknowledge whatever it is destined for */
13211
	if ((resp >= 100) && (resp <= 199)) {
13151
	if ((resp >= 100) && (resp <= 199))
13212
		ack_res = __sip_semi_ack(p, seqno, 0, sipmethod);
13152
		__sip_semi_ack(p, seqno, 0, sipmethod);
13213
	} else {
13153
	else
13214
		ack_res = __sip_ack(p, seqno, 0, sipmethod);
13154
		__sip_ack(p, seqno, 0, sipmethod);
13215
	}

   
13216

    
   

   
13217
	if (ack_res == FALSE) {

   
13218
		append_history(p, "Ignore", "Ignoring this retransmit\n");

   
13219
		return;

   
13220
	}

   
13221

    
   
13155

   
13222
	/* If this is a NOTIFY for a subscription clear the flag that indicates that we have a NOTIFY pending */
13156
	/* If this is a NOTIFY for a subscription clear the flag that indicates that we have a NOTIFY pending */
13223
	if (!p->owner && sipmethod == SIP_NOTIFY && p->pendinginvite) 
13157
	if (!p->owner && sipmethod == SIP_NOTIFY && p->pendinginvite) 
13224
		p->pendinginvite = 0;
13158
		p->pendinginvite = 0;
13225

    
   
13159

   
[+20] [20] 66 lines
[+20] static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno) static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno)
13292
						ast_clear_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE);
13226
						ast_clear_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE);
13293
						cb_extensionstate((char *)p->context, (char *)p->exten, p->laststate, (void *) p);
13227
						cb_extensionstate((char *)p->context, (char *)p->exten, p->laststate, (void *) p);
13294
					}
13228
					}
13295
				}
13229
				}
13296
			} else if (sipmethod == SIP_REGISTER) 
13230
			} else if (sipmethod == SIP_REGISTER) 
13297
				res = handle_response_register(p, resp, rest, req, seqno);
13231
				res = handle_response_register(p, resp, rest, req, ignore, seqno);
13298
			else if (sipmethod == SIP_BYE) {		/* Ok, we're ready to go */
13232
			else if (sipmethod == SIP_BYE) {		/* Ok, we're ready to go */
13299
				ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
13233
				ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
13300
				ast_clear_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
13234
				ast_clear_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
13301
			} else if (sipmethod == SIP_SUBSCRIBE)
13235
			} else if (sipmethod == SIP_SUBSCRIBE)
13302
				ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
13236
				ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
[+20] [20] 6 lines
[+20] static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno) static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno)
13309
			if (sipmethod == SIP_INVITE)
13243
			if (sipmethod == SIP_INVITE)
13310
				handle_response_invite(p, resp, rest, req, seqno);
13244
				handle_response_invite(p, resp, rest, req, seqno);
13311
			else if (sipmethod == SIP_REFER)
13245
			else if (sipmethod == SIP_REFER)
13312
				handle_response_refer(p, resp, rest, req, seqno);
13246
				handle_response_refer(p, resp, rest, req, seqno);
13313
			else if (p->registry && sipmethod == SIP_REGISTER)
13247
			else if (p->registry && sipmethod == SIP_REGISTER)
13314
				res = handle_response_register(p, resp, rest, req, seqno);
13248
				res = handle_response_register(p, resp, rest, req, ignore, seqno);
13315
			else if (sipmethod == SIP_BYE) {
13249
			else if (sipmethod == SIP_BYE) {
13316
				if (ast_strlen_zero(p->authname)) {
13250
				if (ast_strlen_zero(p->authname)) {
13317
					ast_log(LOG_WARNING, "Asked to authenticate %s, to %s:%d but we have no matching peer!\n",
13251
					ast_log(LOG_WARNING, "Asked to authenticate %s, to %s:%d but we have no matching peer!\n",
13318
							msg, ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port));
13252
							msg, ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port));
13319
					ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
13253
					ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
[+20] [20] 10 lines
[+20] static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno) static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno)
13330
			break;
13264
			break;
13331
		case 403: /* Forbidden - we failed authentication */
13265
		case 403: /* Forbidden - we failed authentication */
13332
			if (sipmethod == SIP_INVITE)
13266
			if (sipmethod == SIP_INVITE)
13333
				handle_response_invite(p, resp, rest, req, seqno);
13267
				handle_response_invite(p, resp, rest, req, seqno);
13334
			else if (p->registry && sipmethod == SIP_REGISTER) 
13268
			else if (p->registry && sipmethod == SIP_REGISTER) 
13335
				res = handle_response_register(p, resp, rest, req, seqno);
13269
				res = handle_response_register(p, resp, rest, req, ignore, seqno);
13336
			else {
13270
			else {
13337
				ast_log(LOG_WARNING, "Forbidden - maybe wrong password on authentication for %s\n", msg);
13271
				ast_log(LOG_WARNING, "Forbidden - maybe wrong password on authentication for %s\n", msg);
13338
				ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
13272
				ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
13339
			}
13273
			}
13340
			break;
13274
			break;
13341
		case 404: /* Not found */
13275
		case 404: /* Not found */
13342
			if (p->registry && sipmethod == SIP_REGISTER)
13276
			if (p->registry && sipmethod == SIP_REGISTER)
13343
				res = handle_response_register(p, resp, rest, req, seqno);
13277
				res = handle_response_register(p, resp, rest, req, ignore, seqno);
13344
			else if (sipmethod == SIP_INVITE)
13278
			else if (sipmethod == SIP_INVITE)
13345
				handle_response_invite(p, resp, rest, req, seqno);
13279
				handle_response_invite(p, resp, rest, req, seqno);
13346
			else if (owner)
13280
			else if (owner)
13347
				ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
13281
				ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
13348
			break;
13282
			break;
13349
		case 407: /* Proxy auth required */
13283
		case 407: /* Proxy auth required */
13350
			if (sipmethod == SIP_INVITE)
13284
			if (sipmethod == SIP_INVITE)
13351
				handle_response_invite(p, resp, rest, req, seqno);
13285
				handle_response_invite(p, resp, rest, req, seqno);
13352
			else if (sipmethod == SIP_REFER)
13286
			else if (sipmethod == SIP_REFER)
13353
				handle_response_refer(p, resp, rest, req, seqno);
13287
				handle_response_refer(p, resp, rest, req, seqno);
13354
			else if (p->registry && sipmethod == SIP_REGISTER)
13288
			else if (p->registry && sipmethod == SIP_REGISTER)
13355
				res = handle_response_register(p, resp, rest, req, seqno);
13289
				res = handle_response_register(p, resp, rest, req, ignore, seqno);
13356
			else if (sipmethod == SIP_BYE) {
13290
			else if (sipmethod == SIP_BYE) {
13357
				if (ast_strlen_zero(p->authname)) {
13291
				if (ast_strlen_zero(p->authname)) {
13358
					ast_log(LOG_WARNING, "Asked to authenticate %s, to %s:%d but we have no matching peer!\n",
13292
					ast_log(LOG_WARNING, "Asked to authenticate %s, to %s:%d but we have no matching peer!\n",
13359
							msg, ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port));
13293
							msg, ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port));
13360
					ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
13294
					ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
[+20] [20] 7 lines
[+20] static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno) static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno)
13368
			break;
13302
			break;
13369
		case 408: /* Request timeout - terminate dialog */
13303
		case 408: /* Request timeout - terminate dialog */
13370
			if (sipmethod == SIP_INVITE)
13304
			if (sipmethod == SIP_INVITE)
13371
				handle_response_invite(p, resp, rest, req, seqno);
13305
				handle_response_invite(p, resp, rest, req, seqno);
13372
			else if (sipmethod == SIP_REGISTER) 
13306
			else if (sipmethod == SIP_REGISTER) 
13373
				res = handle_response_register(p, resp, rest, req, seqno);
13307
				res = handle_response_register(p, resp, rest, req, ignore, seqno);
13374
			else if (sipmethod == SIP_BYE) {
13308
			else if (sipmethod == SIP_BYE) {
13375
				ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 
13309
				ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 
13376
				if (option_debug)
13310
				if (option_debug)
13377
					ast_log(LOG_DEBUG, "Got timeout on bye. Thanks for the answer. Now, kill this call\n");
13311
					ast_log(LOG_DEBUG, "Got timeout on bye. Thanks for the answer. Now, kill this call\n");
13378
			} else {
13312
			} else {
[+20] [20] 1555 lines
[+20] [+] static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct sockaddr_in *sin, int *recount, char *e, int *nounlock)
14934
		return handle_invite_replaces(p, req, debug, ast_test_flag(req, SIP_PKT_IGNORE), seqno, sin);
14868
		return handle_invite_replaces(p, req, debug, ast_test_flag(req, SIP_PKT_IGNORE), seqno, sin);
14935
	}
14869
	}
14936

    
   
14870

   
14937

    
   
14871

   
14938
	if (c) {	/* We have a call  -either a new call or an old one (RE-INVITE) */
14872
	if (c) {	/* We have a call  -either a new call or an old one (RE-INVITE) */
14939
		enum ast_channel_state c_state = c->_state;
14873
		switch(c->_state) {
14940

    
   

   
14941
		if (c_state != AST_STATE_UP && reinvite &&

   
14942
			(p->invitestate == INV_TERMINATED || p->invitestate == INV_CONFIRMED)) {

   
14943
			/* If these conditions are true, and the channel is still in the 'ringing'

   
14944
			 * state, then this likely means that we have a situation where the initial

   
14945
			 * INVITE transaction has completed *but* the channel's state has not yet been

   
14946
			 * changed to UP. The reason this could happen is if the reinvite is received

   
14947
			 * on the SIP socket prior to an application calling ast_read on this channel

   
14948
			 * to read the answer frame we earlier queued on it. In this case, the reinvite

   
14949
			 * is completely legitimate so we need to handle this the same as if the channel 

   
14950
			 * were already UP. Thus we are purposely falling through to the AST_STATE_UP case.

   
14951
			 */

   
14952
			c_state = AST_STATE_UP;

   
14953
		}

   
14954

    
   

   
14955
		switch(c_state) {

   
14956
		case AST_STATE_DOWN:
14874
		case AST_STATE_DOWN:
14957
			if (option_debug > 1)
14875
			if (option_debug > 1)
14958
				ast_log(LOG_DEBUG, "%s: New call is still down.... Trying... \n", c->name);
14876
				ast_log(LOG_DEBUG, "%s: New call is still down.... Trying... \n", c->name);
14959
			transmit_response(p, "100 Trying", req);
14877
			transmit_response(p, "100 Trying", req);
14960
			p->invitestate = INV_PROCEEDING;
14878
			p->invitestate = INV_PROCEEDING;
[+20] [20] 61 lines
[+20] static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct sockaddr_in *sin, int *recount, char *e, int *nounlock)
15022
		case AST_STATE_RING:
14940
		case AST_STATE_RING:
15023
			transmit_response(p, "100 Trying", req);
14941
			transmit_response(p, "100 Trying", req);
15024
			p->invitestate = INV_PROCEEDING;
14942
			p->invitestate = INV_PROCEEDING;
15025
			break;
14943
			break;
15026
		case AST_STATE_RINGING:
14944
		case AST_STATE_RINGING:

    
   
14945
			if (reinvite && (p->invitestate == INV_TERMINATED || p->invitestate == INV_CONFIRMED)) {
Moved from 14943

    
   
14946
			/* If these conditions are true, and the channel is still in the 'ringing'
Moved from 14944

    
   
14947
			 * state, then this likely means that we have a situation where the initial
Moved from 14945

    
   
14948
			 * INVITE transaction has completed *but* the channel's state has not yet been
Moved from 14946

    
   
14949
			 * changed to UP. The reason this could happen is if the reinvite is received
Moved from 14947

    
   
14950
			 * on the SIP socket prior to an application calling ast_read on this channel
Moved from 14948

    
   
14951
			 * to read the answer frame we earlier queued on it. In this case, the reinvite
Moved from 14949

    
   
14952
			 * is completely legitimate so we need to handle this the same as if the channel 
Moved from 14950

    
   
14953
			 * were already UP. Thus we are purposely falling through to the AST_STATE_UP case.
Moved from 14951

    
   
14954
			 */

    
   
14955
			} else {
15027
			transmit_response(p, "180 Ringing", req);
14956
				transmit_response(p, "180 Ringing", req);
15028
			p->invitestate = INV_PROCEEDING;
14957
				p->invitestate = INV_PROCEEDING;
15029
			break;
14958
				break;

    
   
14959
			}
15030
		case AST_STATE_UP:
14960
		case AST_STATE_UP:
15031
			if (option_debug > 1)
14961
			if (option_debug > 1)
15032
				ast_log(LOG_DEBUG, "%s: This call is UP.... \n", c->name);
14962
				ast_log(LOG_DEBUG, "%s: This call is UP.... \n", c->name);
15033

    
   
14963

   
15034
			transmit_response(p, "100 Trying", req);
14964
			transmit_response(p, "100 Trying", req);
[+20] [20] 553 lines
[+20] [+] static int handle_request_cancel(struct sip_pvt *p, struct sip_request *req)
15588
	if (p->owner)
15518
	if (p->owner)
15589
		ast_queue_hangup(p->owner);
15519
		ast_queue_hangup(p->owner);
15590
	else
15520
	else
15591
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
15521
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
15592
	if (p->initreq.len > 0) {
15522
	if (p->initreq.len > 0) {
15593
		struct sip_pkt *pkt, *prev_pkt;

   
15594
		/* If the CANCEL we are receiving is a retransmission, and we already have scheduled

   
15595
		 * a reliable 487, then we don't want to schedule another one on top of the previous

   
15596
		 * one.

   
15597
		 *

   
15598
		 * As odd as this may sound, we can't rely on the previously-transmitted "reliable" 

   
15599
		 * response in this situation. What if we've sent all of our reliable responses 

   
15600
		 * already and now all of a sudden, we get this second CANCEL?

   
15601
		 *

   
15602
		 * The only way to do this correctly is to cancel our previously-scheduled reliably-

   
15603
		 * transmitted response and send a new one in its place.

   
15604
		 */

   
15605
		for (pkt = p->packets, prev_pkt = NULL; pkt; prev_pkt = pkt, pkt = pkt->next) {

   
15606
			if (pkt->seqno == p->lastinvite && pkt->response_code == 487) {

   
15607
				AST_SCHED_DEL(sched, pkt->retransid);

   
15608
				UNLINK(pkt, p->packets, prev_pkt);

   
15609
				ast_free(pkt);

   
15610
				break;

   
15611
			}

   
15612
		}

   
15613
		transmit_response_reliable(p, "487 Request Terminated", &p->initreq);
15523
		transmit_response_reliable(p, "487 Request Terminated", &p->initreq);
15614
		transmit_response(p, "200 OK", req);
15524
		transmit_response(p, "200 OK", req);
15615
		return 1;
15525
		return 1;
15616
	} else {
15526
	} else {
15617
		transmit_response(p, "481 Call Leg Does Not Exist", req);
15527
		transmit_response(p, "481 Call Leg Does Not Exist", req);
[+20] [20] 29 lines
[+20] [+] static int acf_channel_read(struct ast_channel *chan, char *funcname, char *preparse, char *buf, size_t buflen)
15647
		args.field = "all";
15557
		args.field = "all";
15648

    
   
15558

   
15649
	memset(buf, 0, buflen);
15559
	memset(buf, 0, buflen);
15650
	memset(&qos, 0, sizeof(qos));
15560
	memset(&qos, 0, sizeof(qos));
15651

    
   
15561

   
15652
	if (p == NULL) {

   
15653
		return -1;

   
15654
	}

   
15655

    
   

   
15656
	if (strcasecmp(args.type, "AUDIO") == 0) {
15562
	if (strcasecmp(args.type, "AUDIO") == 0) {
15657
		all = ast_rtp_get_quality(p->rtp, &qos);
15563
		all = ast_rtp_get_quality(p->rtp, &qos);
15658
	} else if (strcasecmp(args.type, "VIDEO") == 0) {
15564
	} else if (strcasecmp(args.type, "VIDEO") == 0) {
15659
		all = ast_rtp_get_quality(p->vrtp, &qos);
15565
		all = ast_rtp_get_quality(p->vrtp, &qos);
15660
	}
15566
	}
[+20] [20] 172 lines
[+20] [+] static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, char *e)
15833
		if (ast_test_flag(req, SIP_PKT_DEBUG))
15739
		if (ast_test_flag(req, SIP_PKT_DEBUG))
15834
			ast_verbose("Creating new subscription\n");
15740
			ast_verbose("Creating new subscription\n");
15835

    
   
15741

   
15836
		copy_request(&p->initreq, req);
15742
		copy_request(&p->initreq, req);
15837
		check_via(p, req);
15743
		check_via(p, req);
15838
		build_route(p, req, 0);

   
15839
	} else if (ast_test_flag(req, SIP_PKT_DEBUG) && ast_test_flag(req, SIP_PKT_IGNORE))
15744
	} else if (ast_test_flag(req, SIP_PKT_DEBUG) && ast_test_flag(req, SIP_PKT_IGNORE))
15840
		ast_verbose("Ignoring this SUBSCRIBE request\n");
15745
		ast_verbose("Ignoring this SUBSCRIBE request\n");
15841

    
   
15746

   
15842
	/* Find parameters to Event: header value and remove them for now */
15747
	/* Find parameters to Event: header value and remove them for now */
15843
	if (ast_strlen_zero(eventheader)) {
15748
	if (ast_strlen_zero(eventheader)) {
[+20] [20] 63 lines
[+20] static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, char *e)
15907
	/* Initialize tag for new subscriptions */	
15812
	/* Initialize tag for new subscriptions */	
15908
	if (ast_strlen_zero(p->tag))
15813
	if (ast_strlen_zero(p->tag))
15909
		make_our_tag(p->tag, sizeof(p->tag));
15814
		make_our_tag(p->tag, sizeof(p->tag));
15910

    
   
15815

   
15911
	if (!strcmp(event, "presence") || !strcmp(event, "dialog")) { /* Presence, RFC 3842 */
15816
	if (!strcmp(event, "presence") || !strcmp(event, "dialog")) { /* Presence, RFC 3842 */
15912
		unsigned int pidf_xml;

   
15913

    
   

   
15914
		if (authpeer)	/* No need for authpeer here */
15817
		if (authpeer)	/* No need for authpeer here */
15915
			ASTOBJ_UNREF(authpeer, sip_destroy_peer);
15818
			ASTOBJ_UNREF(authpeer, sip_destroy_peer);
15916

    
   
15819

   
15917
		/* Header from Xten Eye-beam Accept: multipart/related, application/rlmi+xml, application/pidf+xml, application/xpidf+xml */
15820
		/* Header from Xten Eye-beam Accept: multipart/related, application/rlmi+xml, application/pidf+xml, application/xpidf+xml */
15918

    
   
15821
		/* Polycom phones only handle xpidf+xml, even if they say they can
15919
		pidf_xml = strstr(accept, "application/pidf+xml") ? 1 : 0;
15822
		   handle pidf+xml as well
15920

    
   
15823
		*/
15921
		/* Older versions of Polycom firmware will claim pidf+xml, but really
15824
		if (strstr(p->useragent, "Polycom")) {
15922
		 * they only support xpidf+xml. */

   
15923
		if (pidf_xml && strstr(p->useragent, "Polycom")) {

   
15924
			p->subscribed = XPIDF_XML;
15825
			p->subscribed = XPIDF_XML;
15925
		} else if (pidf_xml) {
15826
		} else if (strstr(accept, "application/pidf+xml")) {
15926
			p->subscribed = PIDF_XML;         /* RFC 3863 format */
15827
			p->subscribed = PIDF_XML;         /* RFC 3863 format */
15927
		} else if (strstr(accept, "application/dialog-info+xml")) {
15828
		} else if (strstr(accept, "application/dialog-info+xml")) {
15928
			p->subscribed = DIALOG_INFO_XML;
15829
			p->subscribed = DIALOG_INFO_XML;
15929
			/* IETF draft: draft-ietf-sipping-dialog-package-05.txt */
15830
			/* IETF draft: draft-ietf-sipping-dialog-package-05.txt */
15930
		} else if (strstr(accept, "application/cpim-pidf+xml")) {
15831
		} else if (strstr(accept, "application/cpim-pidf+xml")) {
[+20] [20] 237 lines
[+20] [+] static int handle_request(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int *recount, int *nounlock)
16168
		return -1;
16069
		return -1;
16169
	}
16070
	}
16170
	/* Get the command XXX */
16071
	/* Get the command XXX */
16171

    
   
16072

   
16172
	cmd = req->rlPart1;
16073
	cmd = req->rlPart1;
16173
	e = ast_skip_blanks(req->rlPart2);
16074
	e = req->rlPart2;
16174

    
   
16075

   
16175
	/* Save useragent of the client */
16076
	/* Save useragent of the client */
16176
	useragent = get_header(req, "User-Agent");
16077
	useragent = get_header(req, "User-Agent");
16177
	if (!ast_strlen_zero(useragent))
16078
	if (!ast_strlen_zero(useragent))
16178
		ast_string_field_set(p, useragent, useragent);
16079
		ast_string_field_set(p, useragent, useragent);
16179

    
   
16080

   
16180
	/* Find out SIP method for incoming request */
16081
	/* Find out SIP method for incoming request */
16181
	if (req->method == SIP_RESPONSE) {	/* Response to our request */
16082
	if (req->method == SIP_RESPONSE) {	/* Response to our request */
16182
		/* Response to our request -- Do some sanity checks */	
16083
		/* Response to our request -- Do some sanity checks */	
16183
		if (ast_strlen_zero(e)) {

   
16184
			return 0;

   
16185
		}

   
16186
		if (sscanf(e, "%d %n", &respid, &len) != 1) {

   
16187
			ast_log(LOG_WARNING, "Invalid response: '%s'\n", e);

   
16188
			return 0;

   
16189
		}

   
16190
		if (respid <= 0) {

   
16191
			ast_log(LOG_WARNING, "Invalid SIP response code: '%d'\n", respid);
Moved to 16106

   
16192
			return 0;
Moved to 16107

   
16193
		}
Moved to 16108

   
16194
		if (!p->initreq.headers) {
16084
		if (!p->initreq.headers) {
16195
			if (option_debug)
16085
			if (option_debug)
16196
				ast_log(LOG_DEBUG, "That's odd...  Got a response on a call we dont know about. Cseq %d Cmd %s\n", seqno, cmd);
16086
				ast_log(LOG_DEBUG, "That's odd...  Got a response on a call we dont know about. Cseq %d Cmd %s\n", seqno, cmd);
16197
			ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
16087
			ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
16198
			return 0;
16088
			return 0;
16199
		}
16089
		} else if (p->ocseq && (p->ocseq < seqno) && (seqno != p->lastnoninvite)) {
16200
		if (p->ocseq && (p->ocseq < seqno)) {

   
16201
			if (option_debug)
16090
			if (option_debug)
16202
				ast_log(LOG_DEBUG, "Ignoring out of order response %d (expecting %d)\n", seqno, p->ocseq);
16091
				ast_log(LOG_DEBUG, "Ignoring out of order response %d (expecting %d)\n", seqno, p->ocseq);
16203
			return -1;
16092
			return -1;

    
   
16093
		} else if (p->ocseq && (p->ocseq != seqno) && (seqno != p->lastnoninvite)) {

    
   
16094
			/* ignore means "don't do anything with it" but still have to 

    
   
16095
			   respond appropriately  */

    
   
16096
			ignore = TRUE;

    
   
16097
			ast_set_flag(req, SIP_PKT_IGNORE);

    
   
16098
			ast_set_flag(req, SIP_PKT_IGNORE_RESP);

    
   
16099
			append_history(p, "Ignore", "Ignoring this retransmit\n");

    
   
16100
		} else if (e) {

    
   
16101
			e = ast_skip_blanks(e);

    
   
16102
			if (sscanf(e, "%d %n", &respid, &len) != 1) {

    
   
16103
				ast_log(LOG_WARNING, "Invalid response: '%s'\n", e);
16204
		} else {
16104
			} else {
16205
			if ((respid == 200) || ((respid >= 300) && (respid <= 399))) {
16105
				if (respid <= 0) {
Moved from 16191

    
   
16106
					ast_log(LOG_WARNING, "Invalid SIP response code: '%d'\n", respid);
Moved from 16192

    
   
16107
					return 0;
Moved from 16193

    
   
16108
				}

    
   
16109
				/* More SIP ridiculousness, we have to ignore bogus contacts in 100 etc responses */

    
   
16110
				if ((respid == 200) || ((respid >= 300) && (respid <= 399)))
16206
				extract_uri(p, req);
16111
					extract_uri(p, req);

    
   
16112
				handle_response(p, respid, e + len, req, ignore, seqno);
16207
			}
16113
			}
16208
			handle_response(p, respid, e + len, req, seqno);

   
16209
		}
16114
		}
16210
		return 0;
16115
		return 0;
16211
	}
16116
	}
16212

    
   
16117

   
16213
	/* New SIP request coming in 
16118
	/* New SIP request coming in 
[+20] [20] 1555 lines
[+20] [+] static struct sip_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime)
17769
					ASTOBJ_UNREF(peer_ptr, sip_destroy_peer);
17674
					ASTOBJ_UNREF(peer_ptr, sip_destroy_peer);
17770
				}
17675
				}
17771
				ast_clear_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC);
17676
				ast_clear_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC);
17772
				if (!obproxyfound || !strcasecmp(v->name, "outboundproxy")) {
17677
				if (!obproxyfound || !strcasecmp(v->name, "outboundproxy")) {
17773
					if (ast_get_ip_or_srv(&peer->addr, v->value, srvlookup ? "_sip._udp" : NULL)) {
17678
					if (ast_get_ip_or_srv(&peer->addr, v->value, srvlookup ? "_sip._udp" : NULL)) {
17774
						ast_log(LOG_ERROR, "srvlookup failed for outboundproxy: %s, on peer %s, removing peer\n", v->value, peer->name);

   
17775
						ASTOBJ_UNREF(peer, sip_destroy_peer);
17679
						ASTOBJ_UNREF(peer, sip_destroy_peer);
17776
						return NULL;
17680
						return NULL;
17777
					}
17681
					}
17778
				}
17682
				}
17779
				if (!strcasecmp(v->name, "outboundproxy"))
17683
				if (!strcasecmp(v->name, "outboundproxy"))
[+20] [20] 1557 lines
  1. /branches/1.4/channels/chan_sip.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.