Review Board 1.7.16


Support text messages outside of a call

Review Request #1042 - Created Dec. 1, 2010 and submitted

Russell Bryant
trunk
Reviewers
asterisk-dev
Asterisk
This branch contains a proposal for adding protocol independent support for processing text messages into and out of the dialplan, outside of a call.  The file doc/asterisk-messaging.txt contains more details on the proposal.  The introduction of the document is quoted here:

"    Asterisk has some limited support today for messaging.  The support that
exists primarily includes passing text messages in the context of a call.  The
SIP and IAX2 protocols have support for this, but that's it.

    There are a couple of other messaging protocols that are supported: Skype
and XMPP (Jabber).  The support of these is very minimal and not very integrated
into the architecture of Asterisk since these messages are not in the context of
a phone call.  They provide a combination of dialplan and manager interface
interfaces that are specific to each protocol.  There just is no current
architectural concept of dealing with text messages.

    The purpose of this proposal is to introduce text messaging into the
architecture of Asterisk.  For messaging support to exist in the true spirit of
Asterisk architecture, the design needs to achieve the following two goals:

    a) Protocol Independence
    b) Scriptable message routing

    The rest of this document goes through some details about how these goals
will be achieved in a way that is both architecturally compatible with Asterisk
as well as practical to implement."

----------

In addition to the documented proposal, I have made some good progress on implementation.  While the document includes some ideas for future enhancements, what is there so far should be usable.

 - core modifications to allow sending incoming messages through the dialplan
 - core modifications to allow outbound messages from the dialplan
 - modifications to res_jabber to allow inbound and outbound messages in the new architecture
 - changes to chan_sip to support inbound and outbound MESSAGE outside of a call
svn/testsuite/asterisk/team/russell/messaging:
  - This branch of the testsuite contains my tests for this branch, which include:
    - tests/sip/message_disabled
      - Ensure MESSAGE outside of a call is rejected when disabled.
    - tests/sip/message_unauth
      - When enabled, test sending a MESSAGE to Asterisk and send another back out from the dialplan.
    - tests/sip/message_auth
      - Same as the last test, but authenticate MESSAGE both inbound and outbound.
    - tests/sip/message_from_call
      - Set up a normal SIP call and send an out of call MESSAGE from the dialplan processing the call

I have also written some simple apps using the pjsua Python module from pjsip that can send and receive messages sent through Asterisk.

Lastly, I have done some manual testing of XMPP messages in and out of Asterisk using this code.
/trunk/channels/chan_sip.c
Diff Revision 1 Diff Revision 4
[20] 427 lines
[+20] [+] ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
428
						<para>Preferred codec index number <replaceable>x</replaceable> (beginning with zero).</para>
428
						<para>Preferred codec index number <replaceable>x</replaceable> (beginning with zero).</para>
429
					</enum>
429
					</enum>
430
				</enumlist>
430
				</enumlist>
431
			</parameter>
431
			</parameter>
432
		</syntax>
432
		</syntax>
433
		<description />
433
		<description></description>
434
	</function>
434
	</function>
435
	<function name="SIPCHANINFO" language="en_US">
435
	<function name="SIPCHANINFO" language="en_US">
436
		<synopsis>
436
		<synopsis>
437
			Gets the specified SIP parameter from the current channel.
437
			Gets the specified SIP parameter from the current channel.
438
		</synopsis>
438
		</synopsis>
[+20] [20] 23 lines
[+20] ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
462
						otherwise <literal>0</literal>.</para>
462
						otherwise <literal>0</literal>.</para>
463
					</enum>
463
					</enum>
464
				</enumlist>
464
				</enumlist>
465
			</parameter>
465
			</parameter>
466
		</syntax>
466
		</syntax>
467
		<description />
467
		<description></description>
468
	</function>
468
	</function>
469
	<function name="CHECKSIPDOMAIN" language="en_US">
469
	<function name="CHECKSIPDOMAIN" language="en_US">
470
		<synopsis>
470
		<synopsis>
471
			Checks if domain is a local domain.
471
			Checks if domain is a local domain.
472
		</synopsis>
472
		</synopsis>
[+20] [20] 221 lines
[+20] [+] static unsigned int default_primary_transport; /*!< Default primary Transport (enum sip_transport) for outbound connections to devices */
694
					\note in the future we could have multiple of these (per domain, per device group etc) */
694
					\note in the future we could have multiple of these (per domain, per device group etc) */
695

    
   
695

   
696
/*!< use this macro when ast_uri_decode is dependent on pedantic checking to be on. */
696
/*!< use this macro when ast_uri_decode is dependent on pedantic checking to be on. */
697
#define SIP_PEDANTIC_DECODE(str)	\
697
#define SIP_PEDANTIC_DECODE(str)	\
698
	if (sip_cfg.pedanticsipchecking && !ast_strlen_zero(str)) {	\
698
	if (sip_cfg.pedanticsipchecking && !ast_strlen_zero(str)) {	\
699
		ast_uri_decode(str);	\
699
		ast_uri_decode(str, ast_uri_sip_user);	\
700
	}	\
700
	}	\
701

    
   
701

   
702
static unsigned int chan_idx;       /*!< used in naming sip channel */
702
static unsigned int chan_idx;       /*!< used in naming sip channel */
703
static int global_match_auth_username;    /*!< Match auth username if available instead of From: Default off. */
703
static int global_match_auth_username;    /*!< Match auth username if available instead of From: Default off. */
704

    
   
704

   
[+20] [20] 76 lines
[+20] [+] AST_MUTEX_DEFINE_STATIC(sip_reload_lock);
781
static pthread_t monitor_thread = AST_PTHREADT_NULL;
781
static pthread_t monitor_thread = AST_PTHREADT_NULL;
782

    
   
782

   
783
static int sip_reloading = FALSE;                       /*!< Flag for avoiding multiple reloads at the same time */
783
static int sip_reloading = FALSE;                       /*!< Flag for avoiding multiple reloads at the same time */
784
static enum channelreloadreason sip_reloadreason;       /*!< Reason for last reload/load of configuration */
784
static enum channelreloadreason sip_reloadreason;       /*!< Reason for last reload/load of configuration */
785

    
   
785

   
786
struct sched_context *sched;     /*!< The scheduling context */
786
struct ast_sched_context *sched;     /*!< The scheduling context */
787
static struct io_context *io;           /*!< The IO context */
787
static struct io_context *io;           /*!< The IO context */
788
static int *sipsock_read_id;            /*!< ID of IO entry for sipsock FD */
788
static int *sipsock_read_id;            /*!< ID of IO entry for sipsock FD */
789
struct sip_pkt;
789
struct sip_pkt;
790
static AST_LIST_HEAD_STATIC(domain_list, domain);    /*!< The SIP domain list */
790
static AST_LIST_HEAD_STATIC(domain_list, domain);    /*!< The SIP domain list */
791

    
   
791

   
[+20] [20] 406 lines
[+20] [+] static struct ast_config *notify_types = NULL; /*!< The list of manual NOTIFY types we know how to send */
1198
/*---------------------------- Forward declarations of functions in chan_sip.c */
1198
/*---------------------------- Forward declarations of functions in chan_sip.c */
1199
/* Note: This is added to help splitting up chan_sip.c into several files
1199
/* Note: This is added to help splitting up chan_sip.c into several files
1200
	in coming releases. */
1200
	in coming releases. */
1201

    
   
1201

   
1202
/*--- PBX interface functions */
1202
/*--- PBX interface functions */
1203
static struct ast_channel *sip_request_call(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
1203
static struct ast_channel *sip_request_call(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
1204
static int sip_devicestate(void *data);
1204
static int sip_devicestate(void *data);
1205
static int sip_sendtext(struct ast_channel *ast, const char *text);
1205
static int sip_sendtext(struct ast_channel *ast, const char *text);
1206
static int sip_call(struct ast_channel *ast, char *dest, int timeout);
1206
static int sip_call(struct ast_channel *ast, char *dest, int timeout);
1207
static int sip_sendhtml(struct ast_channel *chan, int subclass, const char *data, int datalen);
1207
static int sip_sendhtml(struct ast_channel *chan, int subclass, const char *data, int datalen);
1208
static int sip_hangup(struct ast_channel *ast);
1208
static int sip_hangup(struct ast_channel *ast);
[+20] [20] 37 lines
[+20] [+] static int transmit_request_with_auth(struct sip_pvt *p, int sipmethod, int seqno, enum xmittype reliable, int newbranch);
1246
static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init, const char * const explicit_uri);
1246
static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init, const char * const explicit_uri);
1247
static int transmit_reinvite_with_sdp(struct sip_pvt *p, int t38version, int oldsdp);
1247
static int transmit_reinvite_with_sdp(struct sip_pvt *p, int t38version, int oldsdp);
1248
static int transmit_info_with_aoc(struct sip_pvt *p, struct ast_aoc_decoded *decoded);
1248
static int transmit_info_with_aoc(struct sip_pvt *p, struct ast_aoc_decoded *decoded);
1249
static int transmit_info_with_digit(struct sip_pvt *p, const char digit, unsigned int duration);
1249
static int transmit_info_with_digit(struct sip_pvt *p, const char digit, unsigned int duration);
1250
static int transmit_info_with_vidupdate(struct sip_pvt *p);
1250
static int transmit_info_with_vidupdate(struct sip_pvt *p);
1251
static int transmit_message_with_text(struct sip_pvt *p, const char *text, int init);
1251
static int transmit_message_with_text(struct sip_pvt *p, const char *text, int init, int auth);
1252
static int transmit_refer(struct sip_pvt *p, const char *dest);
1252
static int transmit_refer(struct sip_pvt *p, const char *dest);
1253
static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs, const char *vmexten);
1253
static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs, const char *vmexten);
1254
static int transmit_notify_with_sipfrag(struct sip_pvt *p, int cseq, char *message, int terminate);
1254
static int transmit_notify_with_sipfrag(struct sip_pvt *p, int cseq, char *message, int terminate);
1255
static int transmit_cc_notify(struct ast_cc_agent *agent, struct sip_pvt *subscription, enum sip_cc_notify_state state);
1255
static int transmit_cc_notify(struct ast_cc_agent *agent, struct sip_pvt *subscription, enum sip_cc_notify_state state);
1256
static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader);
1256
static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader);
1257
static int send_response(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno);
1257
static int send_response(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno);
1258
static int send_request(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno);
1258
static int send_request(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno);
1259
static void copy_request(struct sip_request *dst, const struct sip_request *src);
1259
static void copy_request(struct sip_request *dst, const struct sip_request *src);
1260
static void receive_message(struct sip_pvt *p, struct sip_request *req);
1260
static void receive_message(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e);
1261
static void parse_moved_contact(struct sip_pvt *p, struct sip_request *req, char **name, char **number, int set_call_forward);
1261
static void parse_moved_contact(struct sip_pvt *p, struct sip_request *req, char **name, char **number, int set_call_forward);
1262
static int sip_send_mwi_to_peer(struct sip_peer *peer, const struct ast_event *event, int cache_only);
1262
static int sip_send_mwi_to_peer(struct sip_peer *peer, const struct ast_event *event, int cache_only);
1263

    
   
1263

   
1264
/* Misc dialog routines */
1264
/* Misc dialog routines */
1265
static int __sip_autodestruct(const void *data);
1265
static int __sip_autodestruct(const void *data);
[+20] [20] 24 lines
[+20] [+] static int process_sdp_o(const char *o, struct sip_pvt *p);
1290
static int process_sdp_a_sendonly(const char *a, int *sendonly);
1290
static int process_sdp_a_sendonly(const char *a, int *sendonly);
1291
static int process_sdp_a_audio(const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newaudiortp, int *last_rtpmap_codec);
1291
static int process_sdp_a_audio(const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newaudiortp, int *last_rtpmap_codec);
1292
static int process_sdp_a_video(const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newvideortp, int *last_rtpmap_codec);
1292
static int process_sdp_a_video(const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newvideortp, int *last_rtpmap_codec);
1293
static int process_sdp_a_text(const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newtextrtp, char *red_fmtp, int *red_num_gen, int *red_data_pt, int *last_rtpmap_codec);
1293
static int process_sdp_a_text(const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newtextrtp, char *red_fmtp, int *red_num_gen, int *red_data_pt, int *last_rtpmap_codec);
1294
static int process_sdp_a_image(const char *a, struct sip_pvt *p);
1294
static int process_sdp_a_image(const char *a, struct sip_pvt *p);
1295
static void add_codec_to_sdp(const struct sip_pvt *p, format_t codec,
1295
static void add_codec_to_sdp(const struct sip_pvt *p, struct ast_format *codec,
1296
			     struct ast_str **m_buf, struct ast_str **a_buf,
1296
			     struct ast_str **m_buf, struct ast_str **a_buf,
1297
			     int debug, int *min_packet_size);
1297
			     int debug, int *min_packet_size);
1298
static void add_noncodec_to_sdp(const struct sip_pvt *p, int format,
1298
static void add_noncodec_to_sdp(const struct sip_pvt *p, int format,
1299
				struct ast_str **m_buf, struct ast_str **a_buf,
1299
				struct ast_str **m_buf, struct ast_str **a_buf,
1300
				int debug);
1300
				int debug);
[+20] [20] 221 lines
[+20] [+] static int handle_incoming(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, int *recount, int *nounlock);
1522
static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct ast_sockaddr *addr, int *recount, const char *e, int *nounlock);
1522
static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct ast_sockaddr *addr, int *recount, const char *e, int *nounlock);
1523
static int handle_request_refer(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, int *nounlock);
1523
static int handle_request_refer(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, int *nounlock);
1524
static int handle_request_bye(struct sip_pvt *p, struct sip_request *req);
1524
static int handle_request_bye(struct sip_pvt *p, struct sip_request *req);
1525
static int handle_request_register(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *sin, const char *e);
1525
static int handle_request_register(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *sin, const char *e);
1526
static int handle_request_cancel(struct sip_pvt *p, struct sip_request *req);
1526
static int handle_request_cancel(struct sip_pvt *p, struct sip_request *req);
1527
static int handle_request_message(struct sip_pvt *p, struct sip_request *req);
1527
static int handle_request_message(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e);
1528
static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, int seqno, const char *e);
1528
static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, int seqno, const char *e);
1529
static void handle_request_info(struct sip_pvt *p, struct sip_request *req);
1529
static void handle_request_info(struct sip_pvt *p, struct sip_request *req);
1530
static int handle_request_options(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e);
1530
static int handle_request_options(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e);
1531
static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct ast_sockaddr *addr, int *nounlock);
1531
static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct ast_sockaddr *addr, int *nounlock);
1532
static int handle_request_notify(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, int seqno, const char *e);
1532
static int handle_request_notify(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, int seqno, const char *e);
[+20] [20] 4 lines
[+20] [+] static int local_attended_transfer(struct sip_pvt *transferer, struct sip_dual *current, struct sip_request *req, int seqno, int *nounlock);
1537
static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1537
static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1538
static void handle_response_notify(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1538
static void handle_response_notify(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1539
static void handle_response_refer(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1539
static void handle_response_refer(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1540
static void handle_response_subscribe(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1540
static void handle_response_subscribe(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1541
static int handle_response_register(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1541
static int handle_response_register(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);

    
   
1542
static void handle_response_message(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1542
static void handle_response(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1543
static void handle_response(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1543

    
   
1544

   
1544
/*------ SRTP Support -------- */
1545
/*------ SRTP Support -------- */
1545
static int setup_srtp(struct sip_srtp **srtp);
1546
static int setup_srtp(struct sip_srtp **srtp);
1546
static int process_crypto(struct sip_pvt *p, struct ast_rtp_instance *rtp, struct sip_srtp **srtp, const char *a);
1547
static int process_crypto(struct sip_pvt *p, struct ast_rtp_instance *rtp, struct sip_srtp **srtp, const char *a);
[+20] [20] 17 lines
[+20] [+] static int parse_minse(const char *p_hdrval, int *const p_interval);
1564
static enum st_refresher st_get_refresher(struct sip_pvt *);
1565
static enum st_refresher st_get_refresher(struct sip_pvt *);
1565
static enum st_mode st_get_mode(struct sip_pvt *);
1566
static enum st_mode st_get_mode(struct sip_pvt *);
1566
static struct sip_st_dlg* sip_st_alloc(struct sip_pvt *const p);
1567
static struct sip_st_dlg* sip_st_alloc(struct sip_pvt *const p);
1567

    
   
1568

   
1568
/*------- RTP Glue functions -------- */
1569
/*------- RTP Glue functions -------- */
1569
static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, format_t codecs, int nat_active);
1570
static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, const struct ast_format_cap *cap, int nat_active);
1570

    
   
1571

   
1571
/*!--- SIP MWI Subscription support */
1572
/*!--- SIP MWI Subscription support */
1572
static int sip_subscribe_mwi(const char *value, int lineno);
1573
static int sip_subscribe_mwi(const char *value, int lineno);
1573
static void sip_subscribe_mwi_destroy(struct sip_subscription_mwi *mwi);
1574
static void sip_subscribe_mwi_destroy(struct sip_subscription_mwi *mwi);
1574
static void sip_send_all_mwi_subscriptions(void);
1575
static void sip_send_all_mwi_subscriptions(void);
1575
static int sip_subscribe_mwi_do(const void *data);
1576
static int sip_subscribe_mwi_do(const void *data);
1576
static int __sip_subscribe_mwi_do(struct sip_subscription_mwi *mwi);
1577
static int __sip_subscribe_mwi_do(struct sip_subscription_mwi *mwi);
1577

    
   
1578

   
1578
/*! \brief Definition of this channel for PBX channel registration */
1579
/*! \brief Definition of this channel for PBX channel registration */
1579
const struct ast_channel_tech sip_tech = {
1580
struct ast_channel_tech sip_tech = {
1580
	.type = "SIP",
1581
	.type = "SIP",
1581
	.description = "Session Initiation Protocol (SIP)",
1582
	.description = "Session Initiation Protocol (SIP)",
1582
	.capabilities = AST_FORMAT_AUDIO_MASK,	/* all audio formats */

   
1583
	.properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER,
1583
	.properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER,
1584
	.requester = sip_request_call,			/* called with chan unlocked */
1584
	.requester = sip_request_call,			/* called with chan unlocked */
1585
	.devicestate = sip_devicestate,			/* called with chan unlocked (not chan-specific) */
1585
	.devicestate = sip_devicestate,			/* called with chan unlocked (not chan-specific) */
1586
	.call = sip_call,			/* called with chan locked */
1586
	.call = sip_call,			/* called with chan locked */
1587
	.send_html = sip_sendhtml,
1587
	.send_html = sip_sendhtml,
[+20] [20] 26 lines
[+20] const struct ast_channel_tech sip_tech = { struct ast_channel_tech sip_tech = {
1614
struct ast_channel_tech sip_tech_info;
1614
struct ast_channel_tech sip_tech_info;
1615

    
   
1615

   
1616
static int sip_cc_agent_init(struct ast_cc_agent *agent, struct ast_channel *chan);
1616
static int sip_cc_agent_init(struct ast_cc_agent *agent, struct ast_channel *chan);
1617
static int sip_cc_agent_start_offer_timer(struct ast_cc_agent *agent);
1617
static int sip_cc_agent_start_offer_timer(struct ast_cc_agent *agent);
1618
static int sip_cc_agent_stop_offer_timer(struct ast_cc_agent *agent);
1618
static int sip_cc_agent_stop_offer_timer(struct ast_cc_agent *agent);
1619
static void sip_cc_agent_ack(struct ast_cc_agent *agent);
1619
static void sip_cc_agent_respond(struct ast_cc_agent *agent, enum ast_cc_agent_response_reason reason);
1620
static int sip_cc_agent_status_request(struct ast_cc_agent *agent);
1620
static int sip_cc_agent_status_request(struct ast_cc_agent *agent);
1621
static int sip_cc_agent_start_monitoring(struct ast_cc_agent *agent);
1621
static int sip_cc_agent_start_monitoring(struct ast_cc_agent *agent);
1622
static int sip_cc_agent_recall(struct ast_cc_agent *agent);
1622
static int sip_cc_agent_recall(struct ast_cc_agent *agent);
1623
static void sip_cc_agent_destructor(struct ast_cc_agent *agent);
1623
static void sip_cc_agent_destructor(struct ast_cc_agent *agent);
1624

    
   
1624

   
1625
static struct ast_cc_agent_callbacks sip_cc_agent_callbacks = {
1625
static struct ast_cc_agent_callbacks sip_cc_agent_callbacks = {
1626
	.type = "SIP",
1626
	.type = "SIP",
1627
	.init = sip_cc_agent_init,
1627
	.init = sip_cc_agent_init,
1628
	.start_offer_timer = sip_cc_agent_start_offer_timer,
1628
	.start_offer_timer = sip_cc_agent_start_offer_timer,
1629
	.stop_offer_timer = sip_cc_agent_stop_offer_timer,
1629
	.stop_offer_timer = sip_cc_agent_stop_offer_timer,
1630
	.ack = sip_cc_agent_ack,
1630
	.respond = sip_cc_agent_respond,
1631
	.status_request = sip_cc_agent_status_request,
1631
	.status_request = sip_cc_agent_status_request,
1632
	.start_monitoring = sip_cc_agent_start_monitoring,
1632
	.start_monitoring = sip_cc_agent_start_monitoring,
1633
	.callee_available = sip_cc_agent_recall,
1633
	.callee_available = sip_cc_agent_recall,
1634
	.destructor = sip_cc_agent_destructor,
1634
	.destructor = sip_cc_agent_destructor,
1635
};
1635
};
1636

    
   
1636

   
1637
static int find_by_notify_uri_helper(void *obj, void *arg, int flags)
1637
static int find_by_notify_uri_helper(void *obj, void *arg, int flags)
1638
{
1638
{
1639
	struct ast_cc_agent *agent = obj;
1639
	struct ast_cc_agent *agent = obj;
1640
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;
1640
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;
1641
	const char *uri = arg;
1641
	const char *uri = arg;
1642

    
   
1642

   
1643
	return !strcmp(agent_pvt->notify_uri, uri) ? CMP_MATCH | CMP_STOP : 0;
1643
	return !sip_uri_cmp(agent_pvt->notify_uri, uri) ? CMP_MATCH | CMP_STOP : 0;
1644
}
1644
}
1645

    
   
1645

   
1646
static struct ast_cc_agent *find_sip_cc_agent_by_notify_uri(const char * const uri)
1646
static struct ast_cc_agent *find_sip_cc_agent_by_notify_uri(const char * const uri)
1647
{
1647
{
1648
	struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_notify_uri_helper, (char *)uri, "SIP");
1648
	struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_notify_uri_helper, (char *)uri, "SIP");
[+20] [20] 4 lines
[+20] static struct ast_cc_agent *find_sip_cc_agent_by_notify_uri(const char * const uri)
1653
{
1653
{
1654
	struct ast_cc_agent *agent = obj;
1654
	struct ast_cc_agent *agent = obj;
1655
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;
1655
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;
1656
	const char *uri = arg;
1656
	const char *uri = arg;
1657

    
   
1657

   
1658
	return !strcmp(agent_pvt->subscribe_uri, uri) ? CMP_MATCH | CMP_STOP : 0;
1658
	return !sip_uri_cmp(agent_pvt->subscribe_uri, uri) ? CMP_MATCH | CMP_STOP : 0;
1659
}
1659
}
1660

    
   
1660

   
1661
static struct ast_cc_agent *find_sip_cc_agent_by_subscribe_uri(const char * const uri)
1661
static struct ast_cc_agent *find_sip_cc_agent_by_subscribe_uri(const char * const uri)
1662
{
1662
{
1663
	struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_subscribe_uri_helper, (char *)uri, "SIP");
1663
	struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_subscribe_uri_helper, (char *)uri, "SIP");
[+20] [20] 62 lines
[+20] [+] static int sip_cc_agent_stop_offer_timer(struct ast_cc_agent *agent)
1726

    
   
1726

   
1727
	AST_SCHED_DEL(sched, agent_pvt->offer_timer_id);
1727
	AST_SCHED_DEL(sched, agent_pvt->offer_timer_id);
1728
	return 0;
1728
	return 0;
1729
}
1729
}
1730

    
   
1730

   
1731
static void sip_cc_agent_ack(struct ast_cc_agent *agent)
1731
static void sip_cc_agent_respond(struct ast_cc_agent *agent, enum ast_cc_agent_response_reason reason)
1732
{
1732
{
1733
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;
1733
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;
1734

    
   
1734

   
1735
	sip_pvt_lock(agent_pvt->subscribe_pvt);
1735
	sip_pvt_lock(agent_pvt->subscribe_pvt);
1736
	ast_set_flag(&agent_pvt->subscribe_pvt->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
1736
	ast_set_flag(&agent_pvt->subscribe_pvt->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);

    
   
1737
	if (reason == AST_CC_AGENT_RESPONSE_SUCCESS || !ast_strlen_zero(agent_pvt->notify_uri)) {

    
   
1738
		/* The second half of this if statement may be a bit hard to grasp,

    
   
1739
		 * so here's an explanation. When a subscription comes into

    
   
1740
		 * chan_sip, as long as it is not malformed, it will be passed

    
   
1741
		 * to the CC core. If the core senses an out-of-order state transition,

    
   
1742
		 * then the core will call this callback with the "reason" set to a

    
   
1743
		 * failure condition.

    
   
1744
		 * However, an out-of-order state transition will occur during a resubscription

    
   
1745
		 * for CC. In such a case, we can see that we have already generated a notify_uri

    
   
1746
		 * and so we can detect that this isn't a *real* failure. Rather, it is just

    
   
1747
		 * something the core doesn't recognize as a legitimate SIP state transition.

    
   
1748
		 * Thus we respond with happiness and flowers.

    
   
1749
		 */
1737
	transmit_response(agent_pvt->subscribe_pvt, "200 OK", &agent_pvt->subscribe_pvt->initreq);
1750
		transmit_response(agent_pvt->subscribe_pvt, "200 OK", &agent_pvt->subscribe_pvt->initreq);
1738
	transmit_cc_notify(agent, agent_pvt->subscribe_pvt, CC_QUEUED);
1751
		transmit_cc_notify(agent, agent_pvt->subscribe_pvt, CC_QUEUED);

    
   
1752
	} else {

    
   
1753
		transmit_response(agent_pvt->subscribe_pvt, "500 Internal Error", &agent_pvt->subscribe_pvt->initreq);

    
   
1754
	}
1739
	sip_pvt_unlock(agent_pvt->subscribe_pvt);
1755
	sip_pvt_unlock(agent_pvt->subscribe_pvt);
1740
	agent_pvt->is_available = TRUE;
1756
	agent_pvt->is_available = TRUE;
1741
}
1757
}
1742

    
   
1758

   
1743
static int sip_cc_agent_status_request(struct ast_cc_agent *agent)
1759
static int sip_cc_agent_status_request(struct ast_cc_agent *agent)
[+20] [20] 847 lines
[+20] [+] static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_session_instance *tcptls_session)
2591
				goto cleanup;
2607
				goto cleanup;
2592
			case TCPTLS_ALERT_DATA:
2608
			case TCPTLS_ALERT_DATA:
2593
				ao2_lock(me);
2609
				ao2_lock(me);
2594
				if (!(packet = AST_LIST_REMOVE_HEAD(&me->packet_q, entry))) {
2610
				if (!(packet = AST_LIST_REMOVE_HEAD(&me->packet_q, entry))) {
2595
					ast_log(LOG_WARNING, "TCPTLS thread alert_pipe indicated packet should be sent, but frame_q is empty");
2611
					ast_log(LOG_WARNING, "TCPTLS thread alert_pipe indicated packet should be sent, but frame_q is empty");
2596
				} else if (ast_tcptls_server_write(tcptls_session, ast_str_buffer(packet->data), packet->len) == -1) {

   
2597
					ast_log(LOG_WARNING, "Failure to write to tcp/tls socket\n");

   
2598
				}
2612
				}

    
   
2613
				ao2_unlock(me);
2599

    
   
2614

   
2600
				if (packet) {
2615
				if (packet) {

    
   
2616
					if (ast_tcptls_server_write(tcptls_session, ast_str_buffer(packet->data), packet->len) == -1) {

    
   
2617
						ast_log(LOG_WARNING, "Failure to write to tcp/tls socket\n");

    
   
2618
					}
2601
					ao2_t_ref(packet, -1, "tcptls packet sent, this is no longer needed");
2619
					ao2_t_ref(packet, -1, "tcptls packet sent, this is no longer needed");
2602
				}
2620
				}
2603
				ao2_unlock(me);

   
2604
				break;
2621
				break;
2605
			default:
2622
			default:
2606
				ast_log(LOG_ERROR, "Unknown tcptls thread alert '%d'\n", alert);
2623
				ast_log(LOG_ERROR, "Unknown tcptls thread alert '%d'\n", alert);
2607
			}
2624
			}
2608
		}
2625
		}
[+20] [20] 527 lines
[+20] [+] static int __sip_xmit(struct sip_pvt *p, struct ast_str *data, int len)
3136
		return XMIT_ERROR;
3153
		return XMIT_ERROR;
3137
	}
3154
	}
3138

    
   
3155

   
3139
	if (res == -1) {
3156
	if (res == -1) {
3140
		switch (errno) {
3157
		switch (errno) {
3141
		case EBADF: 		/* Bad file descriptor - seems like this is generated when the host exist, but doesn't accept the UDP packet */
3158
		case EBADF:		/* Bad file descriptor - seems like this is generated when the host exist, but doesn't accept the UDP packet */
3142
		case EHOSTUNREACH: 	/* Host can't be reached */
3159
		case EHOSTUNREACH:	/* Host can't be reached */
3143
		case ENETDOWN: 		/* Interface down */
3160
		case ENETDOWN:		/* Interface down */
3144
		case ENETUNREACH:	/* Network failure */
3161
		case ENETUNREACH:	/* Network failure */
3145
		case ECONNREFUSED:      /* ICMP port unreachable */
3162
		case ECONNREFUSED:      /* ICMP port unreachable */
3146
			res = XMIT_ERROR;	/* Don't bother with trying to transmit again */
3163
			res = XMIT_ERROR;	/* Don't bother with trying to transmit again */
3147
		}
3164
		}
3148
	}
3165
	}
[+20] [20] 267 lines
[+20] [+] static int retrans_pkt(const void *data)
3416

    
   
3433

   
3417
	pkt->retransid = -1; /* Kill this scheduler item */
3434
	pkt->retransid = -1; /* Kill this scheduler item */
3418

    
   
3435

   
3419
	if (pkt->owner && pkt->method != SIP_OPTIONS && xmitres == 0) {
3436
	if (pkt->owner && pkt->method != SIP_OPTIONS && xmitres == 0) {
3420
		if (pkt->is_fatal || sipdebug) { /* Tell us if it's critical or if we're debugging */
3437
		if (pkt->is_fatal || sipdebug) { /* Tell us if it's critical or if we're debugging */
3421
			ast_log(LOG_WARNING, "Retransmission timeout reached on transmission %s for seqno %d (%s %s) -- See doc/sip-retransmit.txt.\n"
3438
			ast_log(LOG_WARNING, "Retransmission timeout reached on transmission %s for seqno %d (%s %s) -- See https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions\n"
3422
				"Packet timed out after %dms with no response\n",
3439
				"Packet timed out after %dms with no response\n",
3423
				pkt->owner->callid,
3440
				pkt->owner->callid,
3424
				pkt->seqno,
3441
				pkt->seqno,
3425
				pkt->is_fatal ? "Critical" : "Non-critical",
3442
				pkt->is_fatal ? "Critical" : "Non-critical",
3426
				pkt->is_resp ? "Response" : "Request",
3443
				pkt->is_resp ? "Response" : "Request",
3427
				(int) ast_tvdiff_ms(ast_tvnow(), pkt->time_sent));
3444
				(int) ast_tvdiff_ms(ast_tvnow(), pkt->time_sent));
3428
		}
3445
		}
3429
	} else if (pkt->method == SIP_OPTIONS && sipdebug) {
3446
	} else if (pkt->method == SIP_OPTIONS && sipdebug) {
3430
		ast_log(LOG_WARNING, "Cancelling retransmit of OPTIONs (call id %s)  -- See doc/sip-retransmit.txt.\n", pkt->owner->callid);
3447
		ast_log(LOG_WARNING, "Cancelling retransmit of OPTIONs (call id %s)  -- See https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions\n", pkt->owner->callid);
3431
	}
3448
	}
3432

    
   
3449

   
3433
	if (xmitres == XMIT_ERROR) {
3450
	if (xmitres == XMIT_ERROR) {
3434
		ast_log(LOG_WARNING, "Transmit error :: Cancelling transmission on Call ID %s\n", pkt->owner->callid);
3451
		ast_log(LOG_WARNING, "Transmit error :: Cancelling transmission on Call ID %s\n", pkt->owner->callid);
3435
		append_history(pkt->owner, "XmitErr", "%s", pkt->is_fatal ? "(Critical)" : "(Non-critical)");
3452
		append_history(pkt->owner, "XmitErr", "%s", pkt->is_fatal ? "(Critical)" : "(Non-critical)");
[+20] [20] 9 lines
[+20] static int retrans_pkt(const void *data)
3445
		}
3462
		}
3446
		if (pkt->owner->owner && !pkt->owner->owner->hangupcause) {
3463
		if (pkt->owner->owner && !pkt->owner->owner->hangupcause) {
3447
			pkt->owner->owner->hangupcause = AST_CAUSE_NO_USER_RESPONSE;
3464
			pkt->owner->owner->hangupcause = AST_CAUSE_NO_USER_RESPONSE;
3448
		}
3465
		}
3449
		if (pkt->owner->owner) {
3466
		if (pkt->owner->owner) {
3450
			ast_log(LOG_WARNING, "Hanging up call %s - no reply to our critical packet (see doc/sip-retransmit.txt).\n", pkt->owner->callid);
3467
			ast_log(LOG_WARNING, "Hanging up call %s - no reply to our critical packet (see https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions).\n", pkt->owner->callid);
3451

    
   
3468

   
3452
			if (pkt->is_resp &&
3469
			if (pkt->is_resp &&
3453
				(pkt->response_code >= 200) &&
3470
				(pkt->response_code >= 200) &&
3454
				(pkt->response_code < 300) &&
3471
				(pkt->response_code < 300) &&
3455
				pkt->owner->pendinginvite &&
3472
				pkt->owner->pendinginvite &&
[+20] [20] 25 lines
[+20] static int retrans_pkt(const void *data)
3481
		}
3498
		}
3482
	}
3499
	}
3483

    
   
3500

   
3484
	if (pkt->method == SIP_BYE) {
3501
	if (pkt->method == SIP_BYE) {
3485
		/* We're not getting answers on SIP BYE's.  Tear down the call anyway. */
3502
		/* We're not getting answers on SIP BYE's.  Tear down the call anyway. */

    
   
3503
		sip_alreadygone(pkt->owner);
3486
		if (pkt->owner->owner) {
3504
		if (pkt->owner->owner) {
3487
			ast_channel_unlock(pkt->owner->owner);
3505
			ast_channel_unlock(pkt->owner->owner);
3488
		}
3506
		}
3489
		append_history(pkt->owner, "ByeFailure", "Remote peer doesn't respond to bye. Destroying call anyway.");
3507
		append_history(pkt->owner, "ByeFailure", "Remote peer doesn't respond to bye. Destroying call anyway.");
3490
		pvt_set_needdestroy(pkt->owner, "no response to BYE");
3508
		pvt_set_needdestroy(pkt->owner, "no response to BYE");
[+20] [20] 545 lines
[+20] [+] static int sip_setoption(struct ast_channel *chan, int option, void *data, int datalen)
4036
	int res = -1;
4054
	int res = -1;
4037
	struct sip_pvt *p = chan->tech_pvt;
4055
	struct sip_pvt *p = chan->tech_pvt;
4038

    
   
4056

   
4039
	switch (option) {
4057
	switch (option) {
4040
	case AST_OPTION_FORMAT_READ:
4058
	case AST_OPTION_FORMAT_READ:
4041
		res = ast_rtp_instance_set_read_format(p->rtp, *(int *) data);
4059
		res = ast_rtp_instance_set_read_format(p->rtp, (struct ast_format *) data);
4042
		break;
4060
		break;
4043
	case AST_OPTION_FORMAT_WRITE:
4061
	case AST_OPTION_FORMAT_WRITE:
4044
		res = ast_rtp_instance_set_write_format(p->rtp, *(int *) data);
4062
		res = ast_rtp_instance_set_write_format(p->rtp, (struct ast_format *) data);
4045
		break;
4063
		break;
4046
	case AST_OPTION_MAKE_COMPATIBLE:
4064
	case AST_OPTION_MAKE_COMPATIBLE:
4047
		res = ast_rtp_instance_make_compatible(chan, p->rtp, (struct ast_channel *) data);
4065
		res = ast_rtp_instance_make_compatible(chan, p->rtp, (struct ast_channel *) data);
4048
		break;
4066
		break;
4049
	case AST_OPTION_DIGIT_DETECT:
4067
	case AST_OPTION_DIGIT_DETECT:
[+20] [20] 131 lines
[+20] [+] static int sip_sendhtml(struct ast_channel *chan, int subclass, const char *data, int datalen)
4181
		break;
4199
		break;
4182
	case AST_STATE_UP:
4200
	case AST_STATE_UP:
4183
		if (!p->pendinginvite) {		/* We are up, and have no outstanding invite */
4201
		if (!p->pendinginvite) {		/* We are up, and have no outstanding invite */
4184
			transmit_reinvite_with_sdp(p, FALSE, FALSE);
4202
			transmit_reinvite_with_sdp(p, FALSE, FALSE);
4185
		} else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) {
4203
		} else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) {
4186
			ast_set_flag(&p->flags[0], SIP_NEEDREINVITE);	
4204
			ast_set_flag(&p->flags[0], SIP_NEEDREINVITE);
4187
		}	
4205
		}
4188
		break;
4206
		break;
4189
	default:
4207
	default:
4190
		ast_log(LOG_WARNING, "Don't know how to send URI when state is %d!\n", chan->_state);
4208
		ast_log(LOG_WARNING, "Don't know how to send URI when state is %d!\n", chan->_state);
4191
	}
4209
	}
4192

    
   
4210

   
4193
	return 0;
4211
	return 0;
4194
}
4212
}
4195

    
   
4213

   
4196
/*! \brief Deliver SIP call ID for the call */
4214
/*! \brief Deliver SIP call ID for the call */
4197
static const char *sip_get_callid(struct ast_channel *chan)
4215
static const char *sip_get_callid(struct ast_channel *chan)
4198
{
4216
{
4199
	return chan->tech_pvt ? ((struct sip_pvt *) chan->tech_pvt)->callid : "";
4217
	return chan->tech_pvt ? ((struct sip_pvt *) chan->tech_pvt)->callid : "";
4200
}
4218
}
4201

    
   
4219

   
4202
/*! \brief Send SIP MESSAGE text within a call
4220
/*! \brief Send SIP MESSAGE text within a call
4203
	Called from PBX core sendtext() application */
4221
	Called from PBX core sendtext() application */
4204
static int sip_sendtext(struct ast_channel *ast, const char *text)
4222
static int sip_sendtext(struct ast_channel *ast, const char *text)
4205
{
4223
{
4206
	struct sip_pvt *dialog = ast->tech_pvt;
4224
	struct sip_pvt *dialog = ast->tech_pvt;
4207
	int debug = sip_debug_test_pvt(dialog);
4225
	int debug = sip_debug_test_pvt(dialog);
4208

    
   
4226

   
4209
	if (!dialog)
4227
	if (!dialog)
4210
		return -1;
4228
		return -1;
4211
	/* NOT ast_strlen_zero, because a zero-length message is specifically
4229
	/* NOT ast_strlen_zero, because a zero-length message is specifically
4212
	 * allowed by RFC 3428 (See section 10, Examples) */
4230
	 * allowed by RFC 3428 (See section 10, Examples) */
4213
	if (!text)
4231
	if (!text)
4214
		return 0;
4232
		return 0;
4215
	if(!is_method_allowed(&dialog->allowed_methods, SIP_MESSAGE)) {
4233
	if(!is_method_allowed(&dialog->allowed_methods, SIP_MESSAGE)) {
4216
		ast_debug(2, "Trying to send MESSAGE to device that does not support it.\n");
4234
		ast_debug(2, "Trying to send MESSAGE to device that does not support it.\n");
4217
		return(0);
4235
		return(0);
4218
	}
4236
	}
4219
	if (debug)
4237
	if (debug)
4220
		ast_verbose("Sending text %s on %s\n", text, ast->name);
4238
		ast_verbose("Sending text %s on %s\n", text, ast->name);
4221
	transmit_message_with_text(dialog, text, 0);
4239
	transmit_message_with_text(dialog, text, 0, 0);
4222
	return 0;	
4240
	return 0;
4223
}
4241
}
4224

    
   
4242

   
4225
/*! \brief Update peer object in realtime storage
4243
/*! \brief Update peer object in realtime storage
4226
	If the Asterisk system name is set in asterisk.conf, we will use
4244
	If the Asterisk system name is set in asterisk.conf, we will use
4227
	that name and store that in the "regserver" field in the sippeers
4245
	that name and store that in the "regserver" field in the sippeers
4228
	table to facilitate multi-server setups.
4246
	table to facilitate multi-server setups.
4229
*/
4247
*/
4230
static void realtime_update_peer(const char *peername, struct ast_sockaddr *addr, const char *defaultuser, const char *fullcontact, const char *useragent, int expirey, unsigned short deprecated_username, int lastms)
4248
static void realtime_update_peer(const char *peername, struct ast_sockaddr *addr, const char *defaultuser, const char *fullcontact, const char *useragent, int expirey, unsigned short deprecated_username, int lastms)
4231
{
4249
{
4232
	char port[10];
4250
	char port[10];
4233
	char ipaddr[INET_ADDRSTRLEN];
4251
	char ipaddr[INET6_ADDRSTRLEN];
4234
	char regseconds[20];
4252
	char regseconds[20];
4235
	char *tablename = NULL;
4253
	char *tablename = NULL;
4236
	char str_lastms[20];
4254
	char str_lastms[20];
4237

    
   
4255

   
4238
	const char *sysname = ast_config_AST_SYSTEM_NAME;
4256
	const char *sysname = ast_config_AST_SYSTEM_NAME;
4239
	char *syslabel = NULL;
4257
	char *syslabel = NULL;
4240

    
   
4258

   
4241
	time_t nowtime = time(NULL) + expirey;
4259
	time_t nowtime = time(NULL) + expirey;
4242
	const char *fc = fullcontact ? "fullcontact" : NULL;
4260
	const char *fc = fullcontact ? "fullcontact" : NULL;
4243

    
   
4261

   
4244
	int realtimeregs = ast_check_realtime("sipregs");
4262
	int realtimeregs = ast_check_realtime("sipregs");
4245

    
   
4263

   
4246
	tablename = realtimeregs ? "sipregs" : "sippeers";
4264
	tablename = realtimeregs ? "sipregs" : "sippeers";
4247
	
4265
	
4248

    
   
4266

   
4249
	snprintf(str_lastms, sizeof(str_lastms), "%d", lastms);
4267
	snprintf(str_lastms, sizeof(str_lastms), "%d", lastms);
4250
	snprintf(regseconds, sizeof(regseconds), "%d", (int)nowtime);	/* Expiration time */
4268
	snprintf(regseconds, sizeof(regseconds), "%d", (int)nowtime);	/* Expiration time */
4251
	ast_copy_string(ipaddr, ast_sockaddr_stringify_addr(addr), sizeof(ipaddr));
4269
	ast_copy_string(ipaddr, ast_sockaddr_stringify_addr(addr), sizeof(ipaddr));
4252
	ast_copy_string(port, ast_sockaddr_stringify_port(addr), sizeof(port));
4270
	ast_copy_string(port, ast_sockaddr_stringify_port(addr), sizeof(port));
4253

    
   
4271

   
4254
	if (ast_strlen_zero(sysname))	/* No system name, disable this */
4272
	if (ast_strlen_zero(sysname))	/* No system name, disable this */
4255
		sysname = NULL;
4273
		sysname = NULL;
4256
	else if (sip_cfg.rtsave_sysname)
4274
	else if (sip_cfg.rtsave_sysname)
4257
		syslabel = "regserver";
4275
		syslabel = "regserver";
4258

    
   
4276

   
4259
	/* XXX IMPORTANT: Anytime you add a new parameter to be updated, you
4277
	/* XXX IMPORTANT: Anytime you add a new parameter to be updated, you
4260
         *  must also add it to contrib/scripts/asterisk.ldap-schema,
4278
         *  must also add it to contrib/scripts/asterisk.ldap-schema,
4261
         *  contrib/scripts/asterisk.ldif,
4279
         *  contrib/scripts/asterisk.ldif,
4262
         *  and to configs/res_ldap.conf.sample as described in
4280
         *  and to configs/res_ldap.conf.sample as described in
4263
         *  bugs 15156 and 15895 
4281
         *  bugs 15156 and 15895 
4264
         */
4282
         */
4265
	if (fc) {
4283
	if (fc) {
4266
		ast_update_realtime(tablename, "name", peername, "ipaddr", ipaddr,
4284
		ast_update_realtime(tablename, "name", peername, "ipaddr", ipaddr,
4267
			"port", port, "regseconds", regseconds,
4285
			"port", port, "regseconds", regseconds,
4268
			deprecated_username ? "username" : "defaultuser", defaultuser,
4286
			deprecated_username ? "username" : "defaultuser", defaultuser,
4269
			"useragent", useragent, "lastms", str_lastms,
4287
			"useragent", useragent, "lastms", str_lastms,
4270
			fc, fullcontact, syslabel, sysname, SENTINEL); /* note fc and syslabel _can_ be NULL */
4288
			fc, fullcontact, syslabel, sysname, SENTINEL); /* note fc and syslabel _can_ be NULL */
4271
	} else {
4289
	} else {
4272
		ast_update_realtime(tablename, "name", peername, "ipaddr", ipaddr,
4290
		ast_update_realtime(tablename, "name", peername, "ipaddr", ipaddr,
4273
			"port", port, "regseconds", regseconds,
4291
			"port", port, "regseconds", regseconds,
4274
			"useragent", useragent, "lastms", str_lastms,
4292
			"useragent", useragent, "lastms", str_lastms,
4275
			deprecated_username ? "username" : "defaultuser", defaultuser,
4293
			deprecated_username ? "username" : "defaultuser", defaultuser,
4276
			syslabel, sysname, SENTINEL); /* note syslabel _can_ be NULL */
4294
			syslabel, sysname, SENTINEL); /* note syslabel _can_ be NULL */
4277
	}
4295
	}
4278
}
4296
}
4279

    
   
4297

   
4280
/*! \brief Automatically add peer extension to dial plan */
4298
/*! \brief Automatically add peer extension to dial plan */
4281
static void register_peer_exten(struct sip_peer *peer, int onoff)
4299
static void register_peer_exten(struct sip_peer *peer, int onoff)
4282
{
4300
{
4283
	char multi[256];
4301
	char multi[256];
4284
	char *stringp, *ext, *context;
4302
	char *stringp, *ext, *context;
4285
	struct pbx_find_info q = { .stacklen = 0 };
4303
	struct pbx_find_info q = { .stacklen = 0 };
4286

    
   
4304

   
4287
	/* XXX note that sip_cfg.regcontext is both a global 'enable' flag and
4305
	/* XXX note that sip_cfg.regcontext is both a global 'enable' flag and
4288
	 * the name of the global regexten context, if not specified
4306
	 * the name of the global regexten context, if not specified
4289
	 * individually.
4307
	 * individually.
4290
	 */
4308
	 */
4291
	if (ast_strlen_zero(sip_cfg.regcontext))
4309
	if (ast_strlen_zero(sip_cfg.regcontext))
4292
		return;
4310
		return;
4293

    
   
4311

   
4294
	ast_copy_string(multi, S_OR(peer->regexten, peer->name), sizeof(multi));
4312
	ast_copy_string(multi, S_OR(peer->regexten, peer->name), sizeof(multi));
4295
	stringp = multi;
4313
	stringp = multi;
4296
	while ((ext = strsep(&stringp, "&"))) {
4314
	while ((ext = strsep(&stringp, "&"))) {
4297
		if ((context = strchr(ext, '@'))) {
4315
		if ((context = strchr(ext, '@'))) {
4298
			*context++ = '\0';	/* split ext@context */
4316
			*context++ = '\0';	/* split ext@context */
4299
			if (!ast_context_find(context)) {
4317
			if (!ast_context_find(context)) {
4300
				ast_log(LOG_WARNING, "Context %s must exist in regcontext= in sip.conf!\n", context);
4318
				ast_log(LOG_WARNING, "Context %s must exist in regcontext= in sip.conf!\n", context);
4301
				continue;
4319
				continue;
4302
			}
4320
			}
4303
		} else {
4321
		} else {
4304
			context = sip_cfg.regcontext;
4322
			context = sip_cfg.regcontext;
4305
		}
4323
		}
4306
		if (onoff) {
4324
		if (onoff) {
4307
			if (!ast_exists_extension(NULL, context, ext, 1, NULL)) {
4325
			if (!ast_exists_extension(NULL, context, ext, 1, NULL)) {
4308
				ast_add_extension(context, 1, ext, 1, NULL, NULL, "Noop",
4326
				ast_add_extension(context, 1, ext, 1, NULL, NULL, "Noop",
4309
					 ast_strdup(peer->name), ast_free_ptr, "SIP");
4327
					 ast_strdup(peer->name), ast_free_ptr, "SIP");
4310
			}
4328
			}
4311
		} else if (pbx_find_extension(NULL, NULL, &q, context, ext, 1, NULL, "", E_MATCH)) {
4329
		} else if (pbx_find_extension(NULL, NULL, &q, context, ext, 1, NULL, "", E_MATCH)) {
4312
			ast_context_remove_extension(context, ext, 1, NULL);
4330
			ast_context_remove_extension(context, ext, 1, NULL);
4313
		}
4331
		}
4314
	}
4332
	}
4315
}
4333
}
4316

    
   
4334

   
4317
/*! Destroy mailbox subscriptions */
4335
/*! Destroy mailbox subscriptions */
4318
static void destroy_mailbox(struct sip_mailbox *mailbox)
4336
static void destroy_mailbox(struct sip_mailbox *mailbox)
4319
{
4337
{
4320
	if (mailbox->event_sub)
4338
	if (mailbox->event_sub)
4321
		ast_event_unsubscribe(mailbox->event_sub);
4339
		ast_event_unsubscribe(mailbox->event_sub);
4322
	ast_free(mailbox);
4340
	ast_free(mailbox);
4323
}
4341
}
4324

    
   
4342

   
4325
/*! Destroy all peer-related mailbox subscriptions */
4343
/*! Destroy all peer-related mailbox subscriptions */
4326
static void clear_peer_mailboxes(struct sip_peer *peer)
4344
static void clear_peer_mailboxes(struct sip_peer *peer)
4327
{
4345
{
4328
	struct sip_mailbox *mailbox;
4346
	struct sip_mailbox *mailbox;
4329

    
   
4347

   
4330
	while ((mailbox = AST_LIST_REMOVE_HEAD(&peer->mailboxes, entry)))
4348
	while ((mailbox = AST_LIST_REMOVE_HEAD(&peer->mailboxes, entry)))
4331
		destroy_mailbox(mailbox);
4349
		destroy_mailbox(mailbox);
4332
}
4350
}
4333

    
   
4351

   
4334
static void sip_destroy_peer_fn(void *peer)
4352
static void sip_destroy_peer_fn(void *peer)
4335
{
4353
{
4336
	sip_destroy_peer(peer);
4354
	sip_destroy_peer(peer);
4337
}
4355
}
4338

    
   
4356

   
4339
/*! \brief Destroy peer object from memory */
4357
/*! \brief Destroy peer object from memory */
4340
static void sip_destroy_peer(struct sip_peer *peer)
4358
static void sip_destroy_peer(struct sip_peer *peer)
4341
{
4359
{
4342
	ast_debug(3, "Destroying SIP peer %s\n", peer->name);
4360
	ast_debug(3, "Destroying SIP peer %s\n", peer->name);
4343
	if (peer->outboundproxy)
4361
	if (peer->outboundproxy)
4344
		ao2_ref(peer->outboundproxy, -1);
4362
		ao2_ref(peer->outboundproxy, -1);
4345
	peer->outboundproxy = NULL;
4363
	peer->outboundproxy = NULL;
4346

    
   
4364

   
4347
	/* Delete it, it needs to disappear */
4365
	/* Delete it, it needs to disappear */
4348
	if (peer->call) {
4366
	if (peer->call) {
4349
		dialog_unlink_all(peer->call, TRUE, TRUE);
4367
		dialog_unlink_all(peer->call, TRUE, TRUE);
4350
		peer->call = dialog_unref(peer->call, "peer->call is being unset");
4368
		peer->call = dialog_unref(peer->call, "peer->call is being unset");
4351
	}
4369
	}
4352
	
4370

   
4353

    
   
4371
	if (peer->mwipvt) {	/* We have an active subscription, delete it */
4354
	if (peer->mwipvt) {	/* We have an active subscription, delete it */
4372
		dialog_unlink_all(peer->mwipvt, TRUE, TRUE);
4355
		dialog_unlink_all(peer->mwipvt, TRUE, TRUE);
4373
		peer->mwipvt = dialog_unref(peer->mwipvt, "unreffing peer->mwipvt");
4356
		peer->mwipvt = dialog_unref(peer->mwipvt, "unreffing peer->mwipvt");
4374
	}
4357
	}
4375

   
4358
	
4376
	if (peer->chanvars) {
4359
	if (peer->chanvars) {
4377
		ast_variables_destroy(peer->chanvars);
4360
		ast_variables_destroy(peer->chanvars);
4378
		peer->chanvars = NULL;
4361
		peer->chanvars = NULL;
4379
	}
4362
	}
4380

   
4363
	
4381
	register_peer_exten(peer, FALSE);
4364
	register_peer_exten(peer, FALSE);
4382
	ast_free_ha(peer->ha);
4365
	ast_free_ha(peer->ha);
4383
	ast_free_ha(peer->directmediaha);
4366
	ast_free_ha(peer->directmediaha);
4384
	if (peer->selfdestruct)
4367
	if (peer->selfdestruct)
4385
		ast_atomic_fetchadd_int(&apeerobjs, -1);
4368
		ast_atomic_fetchadd_int(&apeerobjs, -1);
4386
	else if (peer->is_realtime) {
4369
	else if (peer->is_realtime) {
4387
		ast_atomic_fetchadd_int(&rpeerobjs, -1);
4370
		ast_atomic_fetchadd_int(&rpeerobjs, -1);
4388
		ast_debug(3, "-REALTIME- peer Destroyed. Name: %s. Realtime Peer objects: %d\n", peer->name, rpeerobjs);
4371
		ast_debug(3, "-REALTIME- peer Destroyed. Name: %s. Realtime Peer objects: %d\n", peer->name, rpeerobjs);
4389
	} else
4372
	} else
4390
		ast_atomic_fetchadd_int(&speerobjs, -1);
4373
		ast_atomic_fetchadd_int(&speerobjs, -1);
4391
	clear_realm_authentication(peer->auth);
4374
	clear_realm_authentication(peer->auth);
4392
	peer->auth = NULL;
4375
	peer->auth = NULL;
4393
	if (peer->dnsmgr)
4376
	if (peer->dnsmgr)
4394
		ast_dnsmgr_release(peer->dnsmgr);
4377
		ast_dnsmgr_release(peer->dnsmgr);
4395
	clear_peer_mailboxes(peer);
4378
	clear_peer_mailboxes(peer);
4396

   
4379

    
   
4397
	if (peer->socket.tcptls_session) {
4380
	if (peer->socket.tcptls_session) {
4398
		ao2_ref(peer->socket.tcptls_session, -1);
4381
		ao2_ref(peer->socket.tcptls_session, -1);
4399
		peer->socket.tcptls_session = NULL;
4382
		peer->socket.tcptls_session = NULL;
4400
	}
4383
	}
4401

   
4384

    
   
4402
	ast_cc_config_params_destroy(peer->cc_params);
4385
	ast_cc_config_params_destroy(peer->cc_params);
4403

   
4386

    
   
4404
	ast_string_field_free_memory(peer);
4387
	ast_string_field_free_memory(peer);
4405

   

    
   
4406
	peer->caps = ast_format_cap_destroy(peer->caps);
4388
}
4407
}
4389

    
   
4408

   
4390
/*! \brief Update peer data in database (if used) */
4409
/*! \brief Update peer data in database (if used) */
4391
static void update_peer(struct sip_peer *p, int expire)
4410
static void update_peer(struct sip_peer *p, int expire)
4392
{
4411
{
[+20] [20] 42 lines
[+20] [+] static struct sip_peer *realtime_peer(const char *newpeername, struct ast_sockaddr *addr, int devstate_only, int which_objects)
4435
	struct sip_peer *peer;
4454
	struct sip_peer *peer;
4436
	struct ast_variable *var = NULL;
4455
	struct ast_variable *var = NULL;
4437
	struct ast_variable *varregs = NULL;
4456
	struct ast_variable *varregs = NULL;
4438
	struct ast_variable *tmp;
4457
	struct ast_variable *tmp;
4439
	struct ast_config *peerlist = NULL;
4458
	struct ast_config *peerlist = NULL;
4440
	char ipaddr[INET_ADDRSTRLEN];
4459
	char ipaddr[INET6_ADDRSTRLEN];
4441
	char portstring[6]; /*up to 5 digits plus null terminator*/
4460
	char portstring[6]; /*up to 5 digits plus null terminator*/
4442
	char *cat = NULL;
4461
	char *cat = NULL;
4443
	int realtimeregs = ast_check_realtime("sipregs");
4462
	int realtimeregs = ast_check_realtime("sipregs");
4444

    
   
4463

   
4445
	/* First check on peer name */
4464
	/* First check on peer name */
[+20] [20] 378 lines
[+20] [+] static int dialog_initialize_rtp(struct sip_pvt *dialog)
4824
	if (!(dialog->rtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr_tmp, NULL))) {
4843
	if (!(dialog->rtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr_tmp, NULL))) {
4825
		return -1;
4844
		return -1;
4826
	}
4845
	}
4827

    
   
4846

   
4828
	if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS) ||
4847
	if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS) ||
4829
			(ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT) && (dialog->capability & AST_FORMAT_VIDEO_MASK))) {
4848
			(ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT) && (ast_format_cap_has_type(dialog->caps, AST_FORMAT_TYPE_VIDEO)))) {
4830
		if (!(dialog->vrtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr_tmp, NULL))) {
4849
		if (!(dialog->vrtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr_tmp, NULL))) {
4831
			return -1;
4850
			return -1;
4832
		}
4851
		}
4833
		ast_rtp_instance_set_timeout(dialog->vrtp, global_rtptimeout);
4852
		ast_rtp_instance_set_timeout(dialog->vrtp, global_rtptimeout);
4834
		ast_rtp_instance_set_hold_timeout(dialog->vrtp, global_rtpholdtimeout);
4853
		ast_rtp_instance_set_hold_timeout(dialog->vrtp, global_rtpholdtimeout);
[+20] [20] 50 lines
[+20] [+] static int create_addr_from_peer(struct sip_pvt *dialog, struct sip_peer *peer)
4885

    
   
4904

   
4886
	/* XXX TODO: get flags directly from peer only as they are needed using dialog->relatedpeer */
4905
	/* XXX TODO: get flags directly from peer only as they are needed using dialog->relatedpeer */
4887
	ast_copy_flags(&dialog->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
4906
	ast_copy_flags(&dialog->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
4888
	ast_copy_flags(&dialog->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
4907
	ast_copy_flags(&dialog->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
4889
	ast_copy_flags(&dialog->flags[2], &peer->flags[2], SIP_PAGE3_FLAGS_TO_COPY);
4908
	ast_copy_flags(&dialog->flags[2], &peer->flags[2], SIP_PAGE3_FLAGS_TO_COPY);
4890
	dialog->capability = peer->capability;
4909
	ast_format_cap_copy(dialog->caps, peer->caps);
4891
	dialog->prefs = peer->prefs;
4910
	dialog->prefs = peer->prefs;
4892
	if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_T38SUPPORT)) {
4911
	if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_T38SUPPORT)) {
4893
		/* t38pt_udptl was enabled in the peer and not in [general] */
4912
		/* t38pt_udptl was enabled in the peer and not in [general] */
4894
		if (dialog->udptl || (!dialog->udptl && (dialog->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, &bindaddr)))) {
4913
		if (dialog->udptl || (!dialog->udptl && (dialog->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, &bindaddr)))) {
4895
			dialog->t38_maxdatagram = peer->t38_maxdatagram;
4914
			dialog->t38_maxdatagram = peer->t38_maxdatagram;
[+20] [20] 355 lines
[+20] [+] static int sip_call(struct ast_channel *ast, char *dest, int timeout)
5251
	if (res == -1) {
5270
	if (res == -1) {
5252
		ast->hangupcause = AST_CAUSE_USER_BUSY;
5271
		ast->hangupcause = AST_CAUSE_USER_BUSY;
5253
		return res;
5272
		return res;
5254
	}
5273
	}
5255
	p->callingpres = ast_party_id_presentation(&ast->caller.id);
5274
	p->callingpres = ast_party_id_presentation(&ast->caller.id);
5256
	p->jointcapability = ast_rtp_instance_available_formats(p->rtp, p->capability, p->prefcodec);
5275
	ast_rtp_instance_available_formats(p->rtp, p->caps, p->prefcaps, p->jointcaps);
5257
	p->jointnoncodeccapability = p->noncodeccapability;
5276
	p->jointnoncodeccapability = p->noncodeccapability;
5258

    
   
5277

   
5259
	/* If there are no audio formats left to offer, punt */
5278
	/* If there are no audio formats left to offer, punt */
5260
	if (!(p->jointcapability & AST_FORMAT_AUDIO_MASK)) {
5279
	if (!(ast_format_cap_has_type(p->jointcaps, AST_FORMAT_TYPE_AUDIO))) {
5261
		ast_log(LOG_WARNING, "No audio format found to offer. Cancelling call to %s\n", p->username);
5280
		ast_log(LOG_WARNING, "No audio format found to offer. Cancelling call to %s\n", p->username);
5262
		res = -1;
5281
		res = -1;
5263
	} else {
5282
	} else {
5264
		int xmitres;
5283
		int xmitres;
5265

    
   
5284

   
[+20] [20] 27 lines
[+20] [+] static void sip_registry_destroy(struct sip_registry *reg)
5293
		ast_debug(3, "Destroying active SIP dialog for registry %s@%s\n", reg->username, reg->hostname);
5312
		ast_debug(3, "Destroying active SIP dialog for registry %s@%s\n", reg->username, reg->hostname);
5294
		dialog_unlink_all(reg->call, TRUE, TRUE);
5313
		dialog_unlink_all(reg->call, TRUE, TRUE);
5295
		reg->call = dialog_unref(reg->call, "unref reg->call");
5314
		reg->call = dialog_unref(reg->call, "unref reg->call");
5296
		/* reg->call = sip_destroy(reg->call); */
5315
		/* reg->call = sip_destroy(reg->call); */
5297
	}
5316
	}
5298
	AST_SCHED_DEL(sched, reg->expire);	
5317
	AST_SCHED_DEL(sched, reg->expire);
5299
	AST_SCHED_DEL(sched, reg->timeout);
5318
	AST_SCHED_DEL(sched, reg->timeout);
5300
	
5319

   
5301
	ast_string_field_free_memory(reg);
5320
	ast_string_field_free_memory(reg);
5302
	ast_atomic_fetchadd_int(&regobjs, -1);
5321
	ast_atomic_fetchadd_int(&regobjs, -1);
5303
	ast_dnsmgr_release(reg->dnsmgr);
5322
	ast_dnsmgr_release(reg->dnsmgr);
5304
	ast_free(reg);
5323
	ast_free(reg);
5305
}
5324
}
[+20] [20] 155 lines
[+20] [+] void __sip_destroy(struct sip_pvt *p, int lockowner, int lockdialoglist)
5461

    
   
5480

   
5462
	if (p->socket.tcptls_session) {
5481
	if (p->socket.tcptls_session) {
5463
		ao2_ref(p->socket.tcptls_session, -1);
5482
		ao2_ref(p->socket.tcptls_session, -1);
5464
		p->socket.tcptls_session = NULL;
5483
		p->socket.tcptls_session = NULL;
5465
	}
5484
	}

    
   
5485
	p->caps = ast_format_cap_destroy(p->caps);

    
   
5486
	p->jointcaps = ast_format_cap_destroy(p->jointcaps);

    
   
5487
	p->peercaps = ast_format_cap_destroy(p->peercaps);

    
   
5488
	p->redircaps = ast_format_cap_destroy(p->redircaps);

    
   
5489
	p->prefcaps = ast_format_cap_destroy(p->prefcaps);
5466
}
5490
}
5467

    
   
5491

   
5468
/*! \brief  update_call_counter: Handle call_limit for SIP devices
5492
/*! \brief  update_call_counter: Handle call_limit for SIP devices
5469
 * Setting a call-limit will cause calls above the limit not to be accepted.
5493
 * Setting a call-limit will cause calls above the limit not to be accepted.
5470
 *
5494
 *
[+20] [20] 327 lines
[+20] [+] const char *hangup_cause2sip(int cause)
5798
			return "502 Bad Gateway";
5822
			return "502 Bad Gateway";
5799
		case AST_CAUSE_BEARERCAPABILITY_NOTAVAIL:	/* Can't find codec to connect to host */
5823
		case AST_CAUSE_BEARERCAPABILITY_NOTAVAIL:	/* Can't find codec to connect to host */
5800
			return "488 Not Acceptable Here";
5824
			return "488 Not Acceptable Here";
5801
		case AST_CAUSE_INTERWORKING:	/* Unspecified Interworking issues */
5825
		case AST_CAUSE_INTERWORKING:	/* Unspecified Interworking issues */
5802
			return "500 Network error";
5826
			return "500 Network error";
5803
			
5827

   
5804
		case AST_CAUSE_NOTDEFINED:
5828
		case AST_CAUSE_NOTDEFINED:
5805
		default:
5829
		default:
5806
			ast_debug(1, "AST hangup cause %d (no match found in SIP)\n", cause);
5830
			ast_debug(1, "AST hangup cause %d (no match found in SIP)\n", cause);
5807
			return NULL;
5831
			return NULL;
5808
	}
5832
	}
[+20] [20] 214 lines
[+20] [+] static int sip_hangup(struct ast_channel *ast)
6023
}
6047
}
6024

    
   
6048

   
6025
/*! \brief Try setting codec suggested by the SIP_CODEC channel variable */
6049
/*! \brief Try setting codec suggested by the SIP_CODEC channel variable */
6026
static void try_suggested_sip_codec(struct sip_pvt *p)
6050
static void try_suggested_sip_codec(struct sip_pvt *p)
6027
{
6051
{
6028
	format_t fmt;
6052
	struct ast_format fmt;
6029
	const char *codec;
6053
	const char *codec;
6030

    
   
6054

   

    
   
6055
	ast_format_clear(&fmt);

    
   
6056

   
6031
	if (p->outgoing_call) {
6057
	if (p->outgoing_call) {
6032
		codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC_OUTBOUND");
6058
		codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC_OUTBOUND");
6033
	} else if (!(codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC_INBOUND"))) {
6059
	} else if (!(codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC_INBOUND"))) {
6034
		codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC");
6060
		codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC");
6035
	}
6061
	}
6036

    
   
6062

   
6037
	if (!codec) 
6063
	if (!codec) 
6038
		return;
6064
		return;
6039

    
   
6065

   
6040
	fmt = ast_getformatbyname(codec);
6066
	ast_getformatbyname(codec, &fmt);
6041
	if (fmt) {
6067
	if (fmt.id) {
6042
		ast_log(LOG_NOTICE, "Changing codec to '%s' for this call because of ${SIP_CODEC} variable\n", codec);
6068
		ast_log(LOG_NOTICE, "Changing codec to '%s' for this call because of ${SIP_CODEC} variable\n", codec);
6043
		if (p->jointcapability & fmt) {
6069
		if (ast_format_cap_iscompatible(p->jointcaps, &fmt)) {
6044
			p->jointcapability &= fmt;
6070
			ast_format_cap_set(p->jointcaps, &fmt);
6045
			p->capability &= fmt;
6071
			ast_format_cap_set(p->caps, &fmt);
6046
		} else
6072
		} else
6047
			ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because it is not shared by both ends.\n");
6073
			ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because it is not shared by both ends.\n");
6048
	} else
6074
	} else
6049
		ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because of unrecognized/not configured codec (check allow/disallow in sip.conf): %s\n", codec);
6075
		ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because of unrecognized/not configured codec (check allow/disallow in sip.conf): %s\n", codec);
6050
	return;	
6076
	return;
6051
}
6077
}
6052

    
   
6078

   
6053
/*! \brief  sip_answer: Answer SIP call , send 200 OK on Invite
6079
/*! \brief  sip_answer: Answer SIP call , send 200 OK on Invite
6054
 * Part of PBX interface */
6080
 * Part of PBX interface */
6055
static int sip_answer(struct ast_channel *ast)
6081
static int sip_answer(struct ast_channel *ast)
6056
{
6082
{
6057
	int res = 0;
6083
	int res = 0;
6058
	struct sip_pvt *p = ast->tech_pvt;
6084
	struct sip_pvt *p = ast->tech_pvt;
6059

    
   
6085

   
6060
	sip_pvt_lock(p);
6086
	sip_pvt_lock(p);
6061
	if (ast->_state != AST_STATE_UP) {
6087
	if (ast->_state != AST_STATE_UP) {
6062
		try_suggested_sip_codec(p);	
6088
		try_suggested_sip_codec(p);
6063

    
   
6089

   
6064
		ast_setstate(ast, AST_STATE_UP);
6090
		ast_setstate(ast, AST_STATE_UP);
6065
		ast_debug(1, "SIP answering channel: %s\n", ast->name);
6091
		ast_debug(1, "SIP answering channel: %s\n", ast->name);
6066
		ast_rtp_instance_update_source(p->rtp);
6092
		ast_rtp_instance_update_source(p->rtp);
6067
		res = transmit_response_with_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL, FALSE, TRUE);
6093
		res = transmit_response_with_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL, FALSE, TRUE);
[+20] [20] 9 lines
[+20] [+] static int sip_write(struct ast_channel *ast, struct ast_frame *frame)
6077
	struct sip_pvt *p = ast->tech_pvt;
6103
	struct sip_pvt *p = ast->tech_pvt;
6078
	int res = 0;
6104
	int res = 0;
6079

    
   
6105

   
6080
	switch (frame->frametype) {
6106
	switch (frame->frametype) {
6081
	case AST_FRAME_VOICE:
6107
	case AST_FRAME_VOICE:
6082
		if (!(frame->subclass.codec & ast->nativeformats)) {
6108
		if (!(ast_format_cap_iscompatible(ast->nativeformats, &frame->subclass.format))) {
6083
			char s1[512], s2[512], s3[512];
6109
			char s1[512];
6084
			ast_log(LOG_WARNING, "Asked to transmit frame type %s, while native formats is %s read/write = %s/%s\n",
6110
			ast_log(LOG_WARNING, "Asked to transmit frame type %s, while native formats is %s read/write = %s/%s\n",
6085
				ast_getformatname(frame->subclass.codec),
6111
				ast_getformatname(&frame->subclass.format),
6086
				ast_getformatname_multiple(s1, sizeof(s1), ast->nativeformats & AST_FORMAT_AUDIO_MASK),
6112
				ast_getformatname_multiple(s1, sizeof(s1), ast->nativeformats),
6087
				ast_getformatname_multiple(s2, sizeof(s2), ast->readformat),
6113
				ast_getformatname(&ast->readformat),
6088
				ast_getformatname_multiple(s3, sizeof(s3), ast->writeformat));
6114
				ast_getformatname(&ast->writeformat));
6089
			return 0;
6115
			return 0;
6090
		}
6116
		}
6091
		if (p) {
6117
		if (p) {
6092
			sip_pvt_lock(p);
6118
			sip_pvt_lock(p);
6093
			if (p->rtp) {
6119
			if (p->rtp) {
[+20] [20] 442 lines
[+20] [+] static int sip_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
6536
*/
6562
*/
6537
static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *title, const char *linkedid)
6563
static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *title, const char *linkedid)
6538
{
6564
{
6539
	struct ast_channel *tmp;
6565
	struct ast_channel *tmp;
6540
	struct ast_variable *v = NULL;
6566
	struct ast_variable *v = NULL;
6541
	format_t fmt;
6567
	struct ast_format fmt;
6542
	format_t what;
6568
	struct ast_format_cap *what = NULL; /* SHALLOW COPY DO NOT DESTROY! */
6543
	format_t video;
6569
	int needvideo = 0;
6544
	format_t text;

   
6545
	format_t needvideo = 0;

   
6546
	int needtext = 0;
6570
	int needtext = 0;
6547
	char buf[SIPBUFSIZE];
6571
	char buf[SIPBUFSIZE];
6548
	char *decoded_exten;
6572
	char *decoded_exten;
6549

    
   
6573

   
6550
	{
6574
	{
[+20] [20] 22 lines
[+20] static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *title, const char *linkedid)
6573

    
   
6597

   
6574
	tmp->tech = ( ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INFO || ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_SHORTINFO) ?  &sip_tech_info : &sip_tech;
6598
	tmp->tech = ( ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INFO || ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_SHORTINFO) ?  &sip_tech_info : &sip_tech;
6575

    
   
6599

   
6576
	/* Select our native format based on codec preference until we receive
6600
	/* Select our native format based on codec preference until we receive
6577
	   something from another device to the contrary. */
6601
	   something from another device to the contrary. */
6578
	if (i->jointcapability) { 	/* The joint capabilities of us and peer */
6602
	if (!(ast_format_cap_is_empty(i->jointcaps))) {	/* The joint capabilities of us and peer */
6579
		what = i->jointcapability;
6603
		what = i->jointcaps;
6580
		video = i->jointcapability & AST_FORMAT_VIDEO_MASK;
6604
	} else if (!(ast_format_cap_is_empty(i->caps))) {		/* Our configured capability for this peer */
6581
		text = i->jointcapability & AST_FORMAT_TEXT_MASK;
6605
		what = i->caps;
6582
	} else if (i->capability) {		/* Our configured capability for this peer */
6606
	} else {
6583
		what = i->capability;
6607
		what = sip_cfg.caps;
6584
		video = i->capability & AST_FORMAT_VIDEO_MASK;

   
6585
		text = i->capability & AST_FORMAT_TEXT_MASK;

   
6586
	} else {

   
6587
		what = sip_cfg.capability;	/* Global codec support */

   
6588
		video = sip_cfg.capability & AST_FORMAT_VIDEO_MASK;

   
6589
		text = sip_cfg.capability & AST_FORMAT_TEXT_MASK;

   
6590
	}
6608
	}
6591

    
   
6609

   
6592
	/* Set the native formats for audio  and merge in video */
6610
	/* Set the native formats */
6593
	tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | video | text;
6611
	ast_format_cap_copy(tmp->nativeformats, what);

    
   
6612
	/* choose and use only the best audio format for our native formats */

    
   
6613
	ast_codec_choose(&i->prefs, tmp->nativeformats, 1, &fmt); /* get the best audio format */

    
   
6614
	ast_format_cap_remove_bytype(tmp->nativeformats, AST_FORMAT_TYPE_AUDIO); /* remove only the other audio formats */

    
   
6615
	ast_format_cap_add(tmp->nativeformats, &fmt); /* add our best choice back */

    
   
6616

   
6594
	ast_debug(3, "*** Our native formats are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, tmp->nativeformats));
6617
	ast_debug(3, "*** Our native formats are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, tmp->nativeformats));
6595
	ast_debug(3, "*** Joint capabilities are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->jointcapability));
6618
	ast_debug(3, "*** Joint capabilities are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->jointcaps));
6596
	ast_debug(3, "*** Our capabilities are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->capability));
6619
	ast_debug(3, "*** Our capabilities are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->caps));
6597
	ast_debug(3, "*** AST_CODEC_CHOOSE formats are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, ast_codec_choose(&i->prefs, what, 1)));
6620
	ast_debug(3, "*** AST_CODEC_CHOOSE formats are %s \n", ast_getformatname(&fmt));
6598
	if (i->prefcodec) {
6621
	if (!ast_format_cap_is_empty(i->prefcaps)) {
6599
		ast_debug(3, "*** Our preferred formats from the incoming channel are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->prefcodec));
6622
		ast_debug(3, "*** Our preferred formats from the incoming channel are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->prefcaps));
6600
	}
6623
	}
6601

    
   
6624

   
6602
	/* XXX Why are we choosing a codec from the native formats?? */

   
6603
	fmt = ast_best_codec(tmp->nativeformats);

   
6604

    
   

   
6605
	/* If we have a prefcodec setting, we have an inbound channel that set a
6625
	/* If we have a prefcodec setting, we have an inbound channel that set a
6606
	   preferred format for this call. Otherwise, we check the jointcapability
6626
	   preferred format for this call. Otherwise, we check the jointcapability
6607
	   We also check for vrtp. If it's not there, we are not allowed do any video anyway.
6627
	   We also check for vrtp. If it's not there, we are not allowed do any video anyway.
6608
	 */
6628
	 */
6609
	if (i->vrtp) {
6629
	if (i->vrtp) {
6610
		if (ast_test_flag(&i->flags[1], SIP_PAGE2_VIDEOSUPPORT))
6630
		if (ast_test_flag(&i->flags[1], SIP_PAGE2_VIDEOSUPPORT))
6611
			needvideo = AST_FORMAT_VIDEO_MASK;
6631
			needvideo = 1;
6612
		else if (i->prefcodec)
6632
		else if (!ast_format_cap_is_empty(i->prefcaps))
6613
			needvideo = i->prefcodec & AST_FORMAT_VIDEO_MASK;	/* Outbound call */
6633
			needvideo = ast_format_cap_has_type(i->prefcaps, AST_FORMAT_TYPE_VIDEO);	/* Outbound call */
6614
 		else
6634
		else
6615
			needvideo = i->jointcapability & AST_FORMAT_VIDEO_MASK;	/* Inbound call */
6635
			needvideo = ast_format_cap_has_type(i->jointcaps, AST_FORMAT_TYPE_VIDEO);	/* Inbound call */
6616
	}
6636
	}
6617

    
   
6637

   
6618
	if (i->trtp) {
6638
	if (i->trtp) {
6619
		if (i->prefcodec)
6639
		if (!ast_format_cap_is_empty(i->prefcaps))
6620
			needtext = i->prefcodec & AST_FORMAT_TEXT_MASK;	/* Outbound call */
6640
			needtext = ast_format_cap_has_type(i->prefcaps, AST_FORMAT_TYPE_TEXT);	/* Outbound call */
6621
 		else
6641
		else
6622
			needtext = i->jointcapability & AST_FORMAT_TEXT_MASK;	/* Inbound call */
6642
			needtext = ast_format_cap_has_type(i->jointcaps, AST_FORMAT_TYPE_TEXT);	/* Inbound call */
6623
	}
6643
	}
6624

    
   
6644

   
6625
	if (needvideo) {
6645
	if (needvideo) {
6626
		ast_debug(3, "This channel can handle video! HOLLYWOOD next!\n");
6646
		ast_debug(3, "This channel can handle video! HOLLYWOOD next!\n");
6627
	} else {
6647
	} else {
[+20] [20] 32 lines
[+20] static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *title, const char *linkedid)
6660
	if (state == AST_STATE_RING) {
6680
	if (state == AST_STATE_RING) {
6661
		tmp->rings = 1;
6681
		tmp->rings = 1;
6662
	}
6682
	}
6663
	tmp->adsicpe = AST_ADSI_UNAVAILABLE;
6683
	tmp->adsicpe = AST_ADSI_UNAVAILABLE;
6664

    
   
6684

   
6665
	tmp->writeformat = fmt;
6685
	ast_format_copy(&tmp->writeformat, &fmt);
6666
	tmp->rawwriteformat = fmt;
6686
	ast_format_copy(&tmp->rawwriteformat, &fmt);
6667
	ast_rtp_instance_set_write_format(i->rtp, fmt);
6687
	ast_rtp_instance_set_write_format(i->rtp, &fmt);
6668

    
   
6688

   
6669
	tmp->readformat = fmt;
6689
	ast_format_copy(&tmp->readformat, &fmt);
6670
	tmp->rawreadformat = fmt;
6690
	ast_format_copy(&tmp->rawreadformat, &fmt);
6671
	ast_rtp_instance_set_read_format(i->rtp, fmt);
6691
	ast_rtp_instance_set_read_format(i->rtp, &fmt);
6672

    
   
6692

   
6673
	tmp->tech_pvt = dialog_ref(i, "sip_new: set chan->tech_pvt to i");
6693
	tmp->tech_pvt = dialog_ref(i, "sip_new: set chan->tech_pvt to i");
6674

    
   
6694

   
6675
	tmp->callgroup = i->callgroup;
6695
	tmp->callgroup = i->callgroup;
6676
	tmp->pickupgroup = i->pickupgroup;
6696
	tmp->pickupgroup = i->pickupgroup;
[+20] [20] 21 lines
[+20] static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *title, const char *linkedid)
6698
	if (ast_exists_extension(NULL, i->context, i->exten, 1, i->cid_num)) {
6718
	if (ast_exists_extension(NULL, i->context, i->exten, 1, i->cid_num)) {
6699
		/* encoded in dialplan, so keep extension encoded */
6719
		/* encoded in dialplan, so keep extension encoded */
6700
		ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
6720
		ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
6701
	} else {
6721
	} else {
6702
		decoded_exten = ast_strdupa(i->exten);
6722
		decoded_exten = ast_strdupa(i->exten);
6703
		ast_uri_decode(decoded_exten);
6723
		ast_uri_decode(decoded_exten, ast_uri_sip_user);
6704
		ast_copy_string(tmp->exten, decoded_exten, sizeof(tmp->exten));
6724
		ast_copy_string(tmp->exten, decoded_exten, sizeof(tmp->exten));
6705
	}
6725
	}
6706

    
   
6726

   
6707
	/* Don't use ast_set_callerid() here because it will
6727
	/* Don't use ast_set_callerid() here because it will
6708
	 * generate an unnecessary NewCallerID event  */
6728
	 * generate an unnecessary NewCallerID event  */
[+20] [20] 265 lines
[+20] [+] static struct ast_frame *sip_rtp_read(struct ast_channel *ast, struct sip_pvt *p, int *faxdetect)
6974
	/* We already hold the channel lock */
6994
	/* We already hold the channel lock */
6975
	if (!p->owner || (f && f->frametype != AST_FRAME_VOICE)) {
6995
	if (!p->owner || (f && f->frametype != AST_FRAME_VOICE)) {
6976
		return f;
6996
		return f;
6977
	}
6997
	}
6978

    
   
6998

   
6979
	if (f && f->subclass.codec != (p->owner->nativeformats & AST_FORMAT_AUDIO_MASK)) {
6999
	if (f && !ast_format_cap_iscompatible(p->owner->nativeformats, &f->subclass.format)) {
6980
		if (!(f->subclass.codec & p->jointcapability)) {
7000
		if (!ast_format_cap_iscompatible(p->jointcaps, &f->subclass.format)) {
6981
			ast_debug(1, "Bogus frame of format '%s' received from '%s'!\n",
7001
			ast_debug(1, "Bogus frame of format '%s' received from '%s'!\n",
6982
				ast_getformatname(f->subclass.codec), p->owner->name);
7002
				ast_getformatname(&f->subclass.format), p->owner->name);
6983
			return &ast_null_frame;
7003
			return &ast_null_frame;
6984
		}
7004
		}
6985
		ast_debug(1, "Oooh, format changed to %s\n",
7005
		ast_debug(1, "Oooh, format changed to %s\n",
6986
			ast_getformatname(f->subclass.codec));
7006
			ast_getformatname(&f->subclass.format));
6987
		p->owner->nativeformats = (p->owner->nativeformats & (AST_FORMAT_VIDEO_MASK | AST_FORMAT_TEXT_MASK)) | f->subclass.codec;
7007
		ast_format_cap_remove_bytype(p->owner->nativeformats, AST_FORMAT_TYPE_AUDIO);
6988
		ast_set_read_format(p->owner, p->owner->readformat);
7008
		ast_format_cap_add(p->owner->nativeformats, &f->subclass.format);
6989
		ast_set_write_format(p->owner, p->owner->writeformat);
7009
		ast_set_read_format(p->owner, &p->owner->readformat);

    
   
7010
		ast_set_write_format(p->owner, &p->owner->writeformat);
6990
	}
7011
	}
6991

    
   
7012

   
6992
	if (f && p->dsp) {
7013
	if (f && p->dsp) {
6993
		f = ast_dsp_process(p->owner, p->dsp, f);
7014
		f = ast_dsp_process(p->owner, p->dsp, f);
6994
		if (f && f->frametype == AST_FRAME_DTMF) {
7015
		if (f && f->frametype == AST_FRAME_DTMF) {
[+20] [20] 10 lines
[+20] static struct ast_frame *sip_rtp_read(struct ast_channel *ast, struct sip_pvt *p, int *faxdetect)
7005
			} else {
7026
			} else {
7006
				ast_debug(1, "* Detected inband DTMF '%c'\n", f->subclass.integer);
7027
				ast_debug(1, "* Detected inband DTMF '%c'\n", f->subclass.integer);
7007
			}
7028
			}
7008
		}
7029
		}
7009
	}
7030
	}
7010
	
7031

   
7011
	return f;
7032
	return f;
7012
}
7033
}
7013

    
   
7034

   
7014
/*! \brief Read SIP RTP from channel */
7035
/*! \brief Read SIP RTP from channel */
7015
static struct ast_frame *sip_read(struct ast_channel *ast)
7036
static struct ast_frame *sip_read(struct ast_channel *ast)
[+20] [20] 131 lines
[+20] [+] struct sip_pvt *sip_alloc(ast_string_field callid, struct ast_sockaddr *addr,
7147

    
   
7168

   
7148
	if (!(p->cc_params = ast_cc_config_params_init())) {
7169
	if (!(p->cc_params = ast_cc_config_params_init())) {
7149
		ao2_t_ref(p, -1, "Yuck, couldn't allocate cc_params struct. Get rid o' p");
7170
		ao2_t_ref(p, -1, "Yuck, couldn't allocate cc_params struct. Get rid o' p");
7150
		return NULL;
7171
		return NULL;
7151
	}
7172
	}

    
   
7173
	p->caps = ast_format_cap_alloc_nolock();

    
   
7174
	p->jointcaps = ast_format_cap_alloc_nolock();

    
   
7175
	p->peercaps = ast_format_cap_alloc_nolock();

    
   
7176
	p->redircaps = ast_format_cap_alloc_nolock();

    
   
7177
	p->prefcaps = ast_format_cap_alloc_nolock();

    
   
7178

   

    
   
7179
	if (!p->caps|| !p->jointcaps || !p->peercaps || !p->redircaps) {

    
   
7180
		p->caps = ast_format_cap_destroy(p->caps);

    
   
7181
		p->jointcaps = ast_format_cap_destroy(p->jointcaps);

    
   
7182
		p->peercaps = ast_format_cap_destroy(p->peercaps);

    
   
7183
		p->redircaps = ast_format_cap_destroy(p->redircaps);

    
   
7184
		p->prefcaps = ast_format_cap_destroy(p->prefcaps);

    
   
7185
		ao2_t_ref(p, -1, "Yuck, couldn't allocate cc_params struct. Get rid o' p");

    
   
7186
		return NULL;

    
   
7187
	}

    
   
7188

   
7152

    
   
7189

   
7153
	/* If this dialog is created as a result of a request or response, lets store
7190
	/* If this dialog is created as a result of a request or response, lets store
7154
	 * some information about it in the dialog. */
7191
	 * some information about it in the dialog. */
7155
	if (req) {
7192
	if (req) {
7156
		char *sent_by, *branch;
7193
		struct sip_via *via;
7157
		const char *cseq = get_header(req, "Cseq");
7194
		const char *cseq = get_header(req, "Cseq");
7158
		unsigned int seqno;
7195
		unsigned int seqno;
7159

    
   
7196

   
7160
		/* get branch parameter from initial Request that started this dialog */
7197
		/* get branch parameter from initial Request that started this dialog */
7161
		get_viabranch(ast_strdupa(get_header(req, "Via")), &sent_by, &branch);
7198
		via = parse_via(get_header(req, "Via"));

    
   
7199
		if (via) {
7162
		/* only store the branch if it begins with the magic prefix "z9hG4bK", otherwise
7200
			/* only store the branch if it begins with the magic prefix "z9hG4bK", otherwise
7163
		 * it is not useful to us to have it */
7201
			 * it is not useful to us to have it */
7164
		if (!ast_strlen_zero(branch) && !strncasecmp(branch, "z9hG4bK", 7)) {
7202
			if (!ast_strlen_zero(via->branch) && !strncasecmp(via->branch, "z9hG4bK", 7)) {
7165
			ast_string_field_set(p, initviabranch, branch);
7203
				ast_string_field_set(p, initviabranch, via->branch);
7166
			ast_string_field_set(p, initviasentby, sent_by);
7204
				ast_string_field_set(p, initviasentby, via->sent_by);

    
   
7205
			}

    
   
7206
			free_via(via);
7167
		}
7207
		}
7168

    
   
7208

   
7169
		/* Store initial incoming cseq. An error in sscanf here is ignored.  There is no approperiate
7209
		/* Store initial incoming cseq. An error in sscanf here is ignored.  There is no approperiate
7170
		 * except not storing the number.  CSeq validation must take place before dialog creation in find_call */
7210
		 * except not storing the number.  CSeq validation must take place before dialog creation in find_call */
7171
		if (!ast_strlen_zero(cseq) && (sscanf(cseq, "%30u", &seqno) == 1)) {
7211
		if (!ast_strlen_zero(cseq) && (sscanf(cseq, "%30u", &seqno) == 1)) {
[+20] [20] 78 lines
[+20] struct sip_pvt *sip_alloc(ast_string_field callid, struct ast_sockaddr *addr,
7250
	else
7290
	else
7251
		ast_string_field_set(p, callid, callid);
7291
		ast_string_field_set(p, callid, callid);
7252
	/* Assign default music on hold class */
7292
	/* Assign default music on hold class */
7253
	ast_string_field_set(p, mohinterpret, default_mohinterpret);
7293
	ast_string_field_set(p, mohinterpret, default_mohinterpret);
7254
	ast_string_field_set(p, mohsuggest, default_mohsuggest);
7294
	ast_string_field_set(p, mohsuggest, default_mohsuggest);
7255
	p->capability = sip_cfg.capability;
7295
	ast_format_cap_copy(p->caps, sip_cfg.caps);
7256
	p->allowtransfer = sip_cfg.allowtransfer;
7296
	p->allowtransfer = sip_cfg.allowtransfer;
7257
	if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
7297
	if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
7258
	    (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO))
7298
	    (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO))
7259
		p->noncodeccapability |= AST_RTP_DTMF;
7299
		p->noncodeccapability |= AST_RTP_DTMF;
7260
	if (p->udptl) {
7300
	if (p->udptl) {
[+20] [20] 7 lines
[+20] struct sip_pvt *sip_alloc(ast_string_field callid, struct ast_sockaddr *addr,
7268
	AST_LIST_HEAD_INIT_NOLOCK(&p->request_queue);
7308
	AST_LIST_HEAD_INIT_NOLOCK(&p->request_queue);
7269

    
   
7309

   
7270
	/* Add to active dialog list */
7310
	/* Add to active dialog list */
7271

    
   
7311

   
7272
	ao2_t_link(dialogs, p, "link pvt into dialogs table");
7312
	ao2_t_link(dialogs, p, "link pvt into dialogs table");
7273
	
7313

   
7274
	ast_debug(1, "Allocating new SIP dialog for %s - %s (%s)\n", callid ? callid : p->callid, sip_methods[intended_method].text, p->rtp ? "With RTP" : "No RTP");
7314
	ast_debug(1, "Allocating new SIP dialog for %s - %s (%s)\n", callid ? callid : p->callid, sip_methods[intended_method].text, p->rtp ? "With RTP" : "No RTP");
7275
	return p;
7315
	return p;
7276
}
7316
}
7277

    
   
7317

   

    
   
7318
static int process_via(struct sip_pvt *p, const struct sip_request *req)

    
   
7319
{

    
   
7320
	struct sip_via *via = parse_via(get_header(req, "Via"));

    
   
7321

   

    
   
7322
	if (!via) {

    
   
7323
		ast_log(LOG_ERROR, "error processing via header\n");

    
   
7324
		return -1;

    
   
7325
	}

    
   
7326

   

    
   
7327
	if (via->maddr) {

    
   
7328
		if (ast_sockaddr_resolve_first(&p->sa, via->maddr, PARSE_PORT_FORBID)) {

    
   
7329
			ast_log(LOG_WARNING, "Can't find address for maddr '%s'\n", via->maddr);

    
   
7330
			ast_log(LOG_ERROR, "error processing via header\n");

    
   
7331
			free_via(via);

    
   
7332
			return -1;

    
   
7333
		}

    
   
7334

   

    
   
7335
		if (via->port) {

    
   
7336
			ast_sockaddr_set_port(&p->sa, via->port);

    
   
7337
		} else {

    
   
7338
			ast_sockaddr_set_port(&p->sa, STANDARD_SIP_PORT);

    
   
7339
		}

    
   
7340

   

    
   
7341
		if (ast_sockaddr_is_ipv4_multicast(&p->sa)) {

    
   
7342
			setsockopt(sipsock, IPPROTO_IP, IP_MULTICAST_TTL, &via->ttl, sizeof(via->ttl));

    
   
7343
		}

    
   
7344
	}

    
   
7345

   

    
   
7346
	free_via(via);
Moved from 20469

    
   
7347
	return 0;
Moved from 20470

    
   
7348
}

    
   
7349

   
7278
/* \brief arguments used for Request/Response to matching */
7350
/* \brief arguments used for Request/Response to matching */
7279
struct match_req_args {
7351
struct match_req_args {
7280
	int method;
7352
	int method;
7281
	const char *callid;
7353
	const char *callid;
7282
	const char *totag;
7354
	const char *totag;
[+20] [20] 287 lines
[+20] [+] static struct sip_pvt *find_call(struct sip_request *req, struct ast_sockaddr *addr, const int intended_method)
7570
		struct ao2_iterator *iterator = ao2_t_callback(dialogs,
7642
		struct ao2_iterator *iterator = ao2_t_callback(dialogs,
7571
			OBJ_POINTER | OBJ_MULTIPLE,
7643
			OBJ_POINTER | OBJ_MULTIPLE,
7572
			dialog_find_multiple,
7644
			dialog_find_multiple,
7573
			&tmp_dialog,
7645
			&tmp_dialog,
7574
			"pedantic ao2_find in dialogs");
7646
			"pedantic ao2_find in dialogs");

    
   
7647
		struct sip_via *via = NULL;
7575

    
   
7648

   
7576
		args.method = req->method;
7649
		args.method = req->method;
7577
		args.callid = NULL; /* we already matched this. */
7650
		args.callid = NULL; /* we already matched this. */
7578
		args.totag = totag;
7651
		args.totag = totag;
7579
		args.fromtag = fromtag;
7652
		args.fromtag = fromtag;
7580
		args.seqno = seqno;
7653
		args.seqno = seqno;
7581
		/* get via header information. */
7654
		/* get via header information. */
7582
		args.ruri = REQ_OFFSET_TO_STR(req, rlPart2);
7655
		args.ruri = REQ_OFFSET_TO_STR(req, rlPart2);
7583
		get_viabranch(ast_strdupa(get_header(req, "Via")), (char **) &args.viasentby, (char **) &args.viabranch);
7656
		via = parse_via(get_header(req, "Via"));

    
   
7657
		if (via) {

    
   
7658
			args.viasentby = via->sent_by;

    
   
7659
			args.viabranch = via->branch;

    
   
7660
		}
7584
		/* determine if this is a Request with authentication credentials. */
7661
		/* determine if this is a Request with authentication credentials. */
7585
		if (!ast_strlen_zero(get_header(req, "Authorization")) ||
7662
		if (!ast_strlen_zero(get_header(req, "Authorization")) ||
7586
			!ast_strlen_zero(get_header(req, "Proxy-Authorization"))) {
7663
			!ast_strlen_zero(get_header(req, "Proxy-Authorization"))) {
7587
			args.authentication_present = 1;
7664
			args.authentication_present = 1;
7588
		}
7665
		}
[+20] [20] 13 lines
[+20] static struct sip_pvt *find_call(struct sip_request *req, struct ast_sockaddr *addr, const int intended_method)
7602
			switch (found) {
7679
			switch (found) {
7603
			case SIP_REQ_MATCH:
7680
			case SIP_REQ_MATCH:
7604
				sip_pvt_lock(sip_pvt_ptr);
7681
				sip_pvt_lock(sip_pvt_ptr);
7605
				ao2_iterator_destroy(iterator);
7682
				ao2_iterator_destroy(iterator);
7606
				dialog_unref(fork_pvt, "unref fork_pvt");
7683
				dialog_unref(fork_pvt, "unref fork_pvt");

    
   
7684
				free_via(via);
7607
				return sip_pvt_ptr; /* return pvt with ref */
7685
				return sip_pvt_ptr; /* return pvt with ref */
7608
			case SIP_REQ_LOOP_DETECTED:
7686
			case SIP_REQ_LOOP_DETECTED:
7609
				/* This is likely a forked Request that somehow resulted in us receiving multiple parts of the fork.
7687
				/* This is likely a forked Request that somehow resulted in us receiving multiple parts of the fork.
7610
			 	* RFC 3261 section 8.2.2.2, Indicate that we want to merge requests by sending a 482 response. */
7688
			 	* RFC 3261 section 8.2.2.2, Indicate that we want to merge requests by sending a 482 response. */
7611
				transmit_response_using_temp(callid, addr, 1, intended_method, req, "482 (Loop Detected)");
7689
				transmit_response_using_temp(callid, addr, 1, intended_method, req, "482 (Loop Detected)");
7612
				dialog_unref(sip_pvt_ptr, "pvt did not match incoming SIP msg, unref from search.");
7690
				dialog_unref(sip_pvt_ptr, "pvt did not match incoming SIP msg, unref from search.");
7613
				ao2_iterator_destroy(iterator);
7691
				ao2_iterator_destroy(iterator);
7614
				dialog_unref(fork_pvt, "unref fork_pvt");
7692
				dialog_unref(fork_pvt, "unref fork_pvt");

    
   
7693
				free_via(via);
7615
				return NULL;
7694
				return NULL;
7616
			case SIP_REQ_FORKED:
7695
			case SIP_REQ_FORKED:
7617
				dialog_unref(fork_pvt, "throwing way pvt to fork off of.");
7696
				dialog_unref(fork_pvt, "throwing way pvt to fork off of.");
7618
				fork_pvt = dialog_ref(sip_pvt_ptr, "this pvt has a forked request, save this off to copy information into new dialog\n");
7697
				fork_pvt = dialog_ref(sip_pvt_ptr, "this pvt has a forked request, save this off to copy information into new dialog\n");
7619
				/* fall through */
7698
				/* fall through */
[+20] [20] 11 lines
[+20] static struct sip_pvt *find_call(struct sip_request *req, struct ast_sockaddr *addr, const int intended_method)
7631
			/* XXX right now we only support handling forked INVITE Requests. Any other
7710
			/* XXX right now we only support handling forked INVITE Requests. Any other
7632
			 * forked request type must be added here. */
7711
			 * forked request type must be added here. */
7633
			if (fork_pvt->method == SIP_INVITE) {
7712
			if (fork_pvt->method == SIP_INVITE) {
7634
				forked_invite_init(req, args.totag, fork_pvt, addr);
7713
				forked_invite_init(req, args.totag, fork_pvt, addr);
7635
				dialog_unref(fork_pvt, "throwing way old forked pvt");
7714
				dialog_unref(fork_pvt, "throwing way old forked pvt");

    
   
7715
				free_via(via);
7636
				return NULL;
7716
				return NULL;
7637
			}
7717
			}
7638
			fork_pvt = dialog_unref(fork_pvt, "throwing way pvt to fork off of");
7718
			fork_pvt = dialog_unref(fork_pvt, "throwing way pvt to fork off of");
7639
		}
7719
		}

    
   
7720

   

    
   
7721
		free_via(via);
7640
	} /* end of pedantic mode Request/Reponse to Dialog matching */
7722
	} /* end of pedantic mode Request/Reponse to Dialog matching */
7641

    
   
7723

   
7642
	/* See if the method is capable of creating a dialog */
7724
	/* See if the method is capable of creating a dialog */
7643
	if (sip_methods[intended_method].can_create == CAN_CREATE_DIALOG) {
7725
	if (sip_methods[intended_method].can_create == CAN_CREATE_DIALOG) {
7644
		struct sip_pvt *p = NULL;
7726
		struct sip_pvt *p = NULL;
[+20] [20] 74 lines
[+20] [+] static int sip_register(const char *value, int lineno)
7719
{
7801
{
7720
	struct sip_subscription_mwi *mwi;
7802
	struct sip_subscription_mwi *mwi;
7721
	int portnum = 0;
7803
	int portnum = 0;
7722
	enum sip_transport transport = SIP_TRANSPORT_UDP;
7804
	enum sip_transport transport = SIP_TRANSPORT_UDP;
7723
	char buf[256] = "";
7805
	char buf[256] = "";
7724
	char *username = NULL, *hostname = NULL, *secret = NULL, *authuser = NULL, *porta = NULL, *mailbox = NULL;
7806
	char *username = NULL, *hostname = NULL, *secret = NULL, *authuser = NULL, *porta = NULL, *mailbox = NULL, *at = NULL;
7725
	
7807

   
7726
	if (!value) {
7808
	if (!value) {
7727
		return -1;
7809
		return -1;
7728
	}
7810
	}
7729
	
7811

   
7730
	ast_copy_string(buf, value, sizeof(buf));
7812
	ast_copy_string(buf, value, sizeof(buf));
7731

    
   
7813

   
7732
	sip_parse_host(buf, lineno, &username, &portnum, &transport);
7814
	if (!(at = strstr(buf, "@"))) {
7733
	
7815
		return -1;
7734
	if ((hostname = strrchr(username, '@'))) {
7816
	}

    
   
7817

   

    
   
7818
	if ((hostname = strrchr(buf, '@'))) {
7735
		*hostname++ = '\0';
7819
		*hostname++ = '\0';

    
   
7820
		username = buf;
7736
	}
7821
	}
7737
	
7822

   
7738
	if ((secret = strchr(username, ':'))) {
7823
	if ((secret = strchr(username, ':'))) {
7739
		*secret++ = '\0';
7824
		*secret++ = '\0';
7740
		if ((authuser = strchr(secret, ':'))) {
7825
		if ((authuser = strchr(secret, ':'))) {
7741
			*authuser++ = '\0';
7826
			*authuser++ = '\0';
7742
		}
7827
		}
7743
	}
7828
	}
7744
	
7829

   
7745
	if ((mailbox = strchr(hostname, '/'))) {
7830
	if ((mailbox = strchr(hostname, '/'))) {
7746
		*mailbox++ = '\0';
7831
		*mailbox++ = '\0';
7747
	}
7832
	}
7748

    
   
7833

   
7749
	if (ast_strlen_zero(username) || ast_strlen_zero(hostname) || ast_strlen_zero(mailbox)) {
7834
	if (ast_strlen_zero(username) || ast_strlen_zero(hostname) || ast_strlen_zero(mailbox)) {
7750
		ast_log(LOG_WARNING, "Format for MWI subscription is user[:secret[:authuser]]@host[:port][/mailbox] at line %d\n", lineno);
7835
		ast_log(LOG_WARNING, "Format for MWI subscription is user[:secret[:authuser]]@host[:port]/mailbox at line %d\n", lineno);
7751
		return -1;
7836
		return -1;
7752
	}
7837
	}
7753
	
7838

   
7754
	if ((porta = strchr(hostname, ':'))) {
7839
	if ((porta = strchr(hostname, ':'))) {
7755
		*porta++ = '\0';
7840
		*porta++ = '\0';
7756
		if (!(portnum = atoi(porta))) {
7841
		if (!(portnum = atoi(porta))) {
7757
			ast_log(LOG_WARNING, "%s is not a valid port number at line %d\n", porta, lineno);
7842
			ast_log(LOG_WARNING, "%s is not a valid port number at line %d\n", porta, lineno);
7758
			return -1;
7843
			return -1;
7759
		}
7844
		}
7760
	}
7845
	}
7761
	
7846

   
7762
	if (!(mwi = ast_calloc_with_stringfields(1, struct sip_subscription_mwi, 256))) {
7847
	if (!(mwi = ast_calloc_with_stringfields(1, struct sip_subscription_mwi, 256))) {
7763
		return -1;
7848
		return -1;
7764
	}
7849
	}
7765
	
7850

   
7766
	ASTOBJ_INIT(mwi);
7851
	ASTOBJ_INIT(mwi);
7767
	ast_string_field_set(mwi, username, username);
7852
	ast_string_field_set(mwi, username, username);
7768
	if (secret) {
7853
	if (secret) {
7769
		ast_string_field_set(mwi, secret, secret);
7854
		ast_string_field_set(mwi, secret, secret);
7770
	}
7855
	}
7771
	if (authuser) {
7856
	if (authuser) {
7772
		ast_string_field_set(mwi, authuser, authuser);
7857
		ast_string_field_set(mwi, authuser, authuser);
7773
	}
7858
	}
7774
	ast_string_field_set(mwi, hostname, hostname);
7859
	ast_string_field_set(mwi, hostname, hostname);
7775
	ast_string_field_set(mwi, mailbox, mailbox);
7860
	ast_string_field_set(mwi, mailbox, mailbox);
7776
	mwi->resub = -1;
7861
	mwi->resub = -1;
7777
	mwi->portno = portnum;
7862
	mwi->portno = portnum;
7778
	mwi->transport = transport;
7863
	mwi->transport = transport;
7779
	
7864

   
7780
	ASTOBJ_CONTAINER_LINK(&submwil, mwi);
7865
	ASTOBJ_CONTAINER_LINK(&submwil, mwi);
7781
	ASTOBJ_UNREF(mwi, sip_subscribe_mwi_destroy);
7866
	ASTOBJ_UNREF(mwi, sip_subscribe_mwi_destroy);
7782
	
7867

   
7783
	return 0;
7868
	return 0;
7784
}
7869
}
7785

    
   
7870

   
7786
static void mark_method_allowed(unsigned int *allowed_methods, enum sipmethod method)
7871
static void mark_method_allowed(unsigned int *allowed_methods, enum sipmethod method)
7787
{
7872
{
[+20] [20] 424 lines
[+20] [+] static int get_ip_and_port_from_sdp(struct sip_request *req, const enum media_type media, struct ast_sockaddr *addr)
8212
 	Return 0 on success, a negative value on errors.
8297
 	Return 0 on success, a negative value on errors.
8213
	Must be called after find_sdp().
8298
	Must be called after find_sdp().
8214
*/
8299
*/
8215
static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
8300
static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
8216
{
8301
{

    
   
8302
	int res = 0;

    
   
8303

   
8217
	/* Iterators for SDP parsing */
8304
	/* Iterators for SDP parsing */
8218
	int start = req->sdp_start;
8305
	int start = req->sdp_start;
8219
	int next = start;
8306
	int next = start;
8220
	int iterator = start;
8307
	int iterator = start;
8221

    
   
8308

   
[+20] [20] 18 lines
[+20] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
8240
 	int vportno = -1;		/*!< RTP Video port number */
8327
	int vportno = -1;		/*!< RTP Video port number */
8241
	int tportno = -1;		/*!< RTP Text port number */
8328
	int tportno = -1;		/*!< RTP Text port number */
8242
	int udptlportno = -1;		/*!< UDPTL Image port number */
8329
	int udptlportno = -1;		/*!< UDPTL Image port number */
8243

    
   
8330

   
8244
	/* Peer capability is the capability in the SDP, non codec is RFC2833 DTMF (101) */	
8331
	/* Peer capability is the capability in the SDP, non codec is RFC2833 DTMF (101) */	
8245
	format_t peercapability = 0, vpeercapability = 0, tpeercapability = 0;
8332
	struct ast_format_cap *peercapability = ast_format_cap_alloc_nolock();

    
   
8333
	struct ast_format_cap *vpeercapability = ast_format_cap_alloc_nolock();

    
   
8334
	struct ast_format_cap *tpeercapability = ast_format_cap_alloc_nolock();

    
   
8335

   
8246
	int peernoncodeccapability = 0, vpeernoncodeccapability = 0, tpeernoncodeccapability = 0;
8336
	int peernoncodeccapability = 0, vpeernoncodeccapability = 0, tpeernoncodeccapability = 0;
8247

    
   
8337

   
8248
	struct ast_rtp_codecs newaudiortp, newvideortp, newtextrtp;
8338
	struct ast_rtp_codecs newaudiortp, newvideortp, newtextrtp;
8249
	format_t newjointcapability;				/* Negotiated capability */
8339
	struct ast_format_cap *newjointcapability = ast_format_cap_alloc_nolock(); /* Negotiated capability */
8250
	format_t newpeercapability;
8340
	struct ast_format_cap *newpeercapability = ast_format_cap_alloc_nolock();
8251
	int newnoncodeccapability;
8341
	int newnoncodeccapability;
8252

    
   
8342

   
8253
	const char *codecs;
8343
	const char *codecs;
8254
	int codec;
8344
	int codec;
8255

    
   
8345

   
[+20] [20] 12 lines
[+20] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
8268
	char red_fmtp[100] = "empty";	/* For T.140 red */
8358
	char red_fmtp[100] = "empty";	/* For T.140 red */
8269
	int debug = sip_debug_test_pvt(p);
8359
	int debug = sip_debug_test_pvt(p);
8270

    
   
8360

   
8271
	/* START UNKNOWN */
8361
	/* START UNKNOWN */
8272
	char buf[SIPBUFSIZE];
8362
	char buf[SIPBUFSIZE];

    
   
8363
	struct ast_format tmp_fmt;
8273
	/* END UNKNOWN */
8364
	/* END UNKNOWN */
8274

    
   
8365

   
8275
	/* Initial check */
8366
	/* Initial check */
8276
	if (!p->rtp) {
8367
	if (!p->rtp) {
8277
		ast_log(LOG_ERROR, "Got SDP but have no RTP session allocated.\n");
8368
		ast_log(LOG_ERROR, "Got SDP but have no RTP session allocated.\n");
8278
		return -1;
8369
		res = -1;

    
   
8370
		goto process_sdp_cleanup;

    
   
8371
	}

    
   
8372
	if (!peercapability || !vpeercapability || !tpeercapability || !newpeercapability || !newjointcapability) {

    
   
8373
		res = -1;

    
   
8374
		goto process_sdp_cleanup;
8279
	}
8375
	}
8280

    
   
8376

   
8281
	/* Make sure that the codec structures are all cleared out */
8377
	/* Make sure that the codec structures are all cleared out */
8282
	ast_rtp_codecs_payloads_clear(&newaudiortp, NULL);
8378
	ast_rtp_codecs_payloads_clear(&newaudiortp, NULL);
8283
	ast_rtp_codecs_payloads_clear(&newvideortp, NULL);
8379
	ast_rtp_codecs_payloads_clear(&newvideortp, NULL);
[+20] [20] 19 lines
[+20] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
8303

    
   
8399

   
8304
	/* Scan for the first media stream (m=) line to limit scanning of globals */
8400
	/* Scan for the first media stream (m=) line to limit scanning of globals */
8305
	nextm = get_sdp_iterate(&next, req, "m");
8401
	nextm = get_sdp_iterate(&next, req, "m");
8306
	if (ast_strlen_zero(nextm)) {
8402
	if (ast_strlen_zero(nextm)) {
8307
		ast_log(LOG_WARNING, "Insufficient information for SDP (m= not found)\n");
8403
		ast_log(LOG_WARNING, "Insufficient information for SDP (m= not found)\n");
8308
 		return -1;
8404
		res = -1;

    
   
8405
		goto process_sdp_cleanup;
8309
 	}
8406
 	}
8310

    
   
8407

   
8311
	/* Scan session level SDP parameters (lines before first media stream) */
8408
	/* Scan session level SDP parameters (lines before first media stream) */
8312
	while ((type = get_sdp_line(&iterator, next - 1, req, &value)) != '\0') {
8409
	while ((type = get_sdp_line(&iterator, next - 1, req, &value)) != '\0') {
8313
		int processed = FALSE;
8410
		int processed = FALSE;
8314
		switch (type) {
8411
		switch (type) {
8315
		case 'o':
8412
		case 'o':
8316
			/* If we end up receiving SDP that doesn't actually modify the session we don't want to treat this as a fatal
8413
			/* If we end up receiving SDP that doesn't actually modify the session we don't want to treat this as a fatal
8317
			 * error. We just want to ignore the SDP and let the rest of the packet be handled as normal.
8414
			 * error. We just want to ignore the SDP and let the rest of the packet be handled as normal.
8318
			 */
8415
			 */
8319
			if (!process_sdp_o(value, p))
8416
			if (!process_sdp_o(value, p)) {
8320
				return (p->session_modify == FALSE) ? 0 : -1;
8417
				res = (p->session_modify == FALSE) ? 0 : -1;

    
   
8418
				goto process_sdp_cleanup;

    
   
8419
			}
8321
			break;
8420
			break;
8322
		case 'c':
8421
		case 'c':
8323
			if (process_sdp_c(value, &sessionsa)) {
8422
			if (process_sdp_c(value, &sessionsa)) {
8324
				processed = TRUE;
8423
				processed = TRUE;
8325
				sa = &sessionsa;
8424
				sa = &sessionsa;
[+20] [20] 57 lines
[+20] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
8383
			codecs = m + len;
8482
			codecs = m + len;
8384
			ast_copy_string(p->offered_media[SDP_AUDIO].codecs, codecs, sizeof(p->offered_media[SDP_AUDIO].codecs));
8483
			ast_copy_string(p->offered_media[SDP_AUDIO].codecs, codecs, sizeof(p->offered_media[SDP_AUDIO].codecs));
8385
			for (; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) {
8484
			for (; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) {
8386
				if (sscanf(codecs, "%30u%n", &codec, &len) != 1) {
8485
				if (sscanf(codecs, "%30u%n", &codec, &len) != 1) {
8387
					ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
8486
					ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
8388
					return -1;
8487
					res = -1;

    
   
8488
					goto process_sdp_cleanup;
8389
				}
8489
				}
8390
				if (debug)
8490
				if (debug)
8391
					ast_verbose("Found RTP audio format %d\n", codec);
8491
					ast_verbose("Found RTP audio format %d\n", codec);
8392
				
8492
				
8393
				ast_rtp_codecs_payloads_set_m_type(&newaudiortp, NULL, codec);
8493
				ast_rtp_codecs_payloads_set_m_type(&newaudiortp, NULL, codec);
[+20] [20] 17 lines
[+20] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
8411
			codecs = m + len;
8511
			codecs = m + len;
8412
			ast_copy_string(p->offered_media[SDP_VIDEO].codecs, codecs, sizeof(p->offered_media[SDP_VIDEO].codecs));
8512
			ast_copy_string(p->offered_media[SDP_VIDEO].codecs, codecs, sizeof(p->offered_media[SDP_VIDEO].codecs));
8413
			for (; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) {
8513
			for (; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) {
8414
				if (sscanf(codecs, "%30u%n", &codec, &len) != 1) {
8514
				if (sscanf(codecs, "%30u%n", &codec, &len) != 1) {
8415
					ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
8515
					ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
8416
					return -1;
8516
					res = -1;

    
   
8517
					goto process_sdp_cleanup;
8417
				}
8518
				}
8418
				if (debug)
8519
				if (debug)
8419
					ast_verbose("Found RTP video format %d\n", codec);
8520
					ast_verbose("Found RTP video format %d\n", codec);
8420
				ast_rtp_codecs_payloads_set_m_type(&newvideortp, NULL, codec);
8521
				ast_rtp_codecs_payloads_set_m_type(&newvideortp, NULL, codec);
8421
			}
8522
			}
[+20] [20] 10 lines
[+20] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
8432
			codecs = m + len;
8533
			codecs = m + len;
8433
			ast_copy_string(p->offered_media[SDP_TEXT].codecs, codecs, sizeof(p->offered_media[SDP_TEXT].codecs));
8534
			ast_copy_string(p->offered_media[SDP_TEXT].codecs, codecs, sizeof(p->offered_media[SDP_TEXT].codecs));
8434
			for (; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) {
8535
			for (; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) {
8435
				if (sscanf(codecs, "%30u%n", &codec, &len) != 1) {
8536
				if (sscanf(codecs, "%30u%n", &codec, &len) != 1) {
8436
					ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
8537
					ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
8437
					return -1;
8538
					res = -1;

    
   
8539
					goto process_sdp_cleanup;
8438
				}
8540
				}
8439
				if (debug)
8541
				if (debug)
8440
					ast_verbose("Found RTP text format %d\n", codec);
8542
					ast_verbose("Found RTP text format %d\n", codec);
8441
				ast_rtp_codecs_payloads_set_m_type(&newtextrtp, NULL, codec);
8543
				ast_rtp_codecs_payloads_set_m_type(&newtextrtp, NULL, codec);
8442
			}
8544
			}
[+20] [20] 94 lines
[+20] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
8537

    
   
8639

   
8538

    
   
8640

   
8539
	/* Sanity checks */
8641
	/* Sanity checks */
8540
	if (!sa && !vsa && !tsa && !isa) {
8642
	if (!sa && !vsa && !tsa && !isa) {
8541
		ast_log(LOG_WARNING, "Insufficient information in SDP (c=)...\n");
8643
		ast_log(LOG_WARNING, "Insufficient information in SDP (c=)...\n");
8542
		return -1;
8644
		res = -1;

    
   
8645
		goto process_sdp_cleanup;
8543
	}
8646
	}
8544

    
   
8647

   
8545
	if (portno == -1 && vportno == -1 && udptlportno == -1  && tportno == -1) {
8648
	if (portno == -1 && vportno == -1 && udptlportno == -1  && tportno == -1) {
8546
		/* No acceptable offer found in SDP  - we have no ports */
8649
		/* No acceptable offer found in SDP  - we have no ports */
8547
		/* Do not change RTP or VRTP if this is a re-invite */
8650
		/* Do not change RTP or VRTP if this is a re-invite */
8548
		ast_log(LOG_WARNING, "Failing due to no acceptable offer found\n");
8651
		ast_log(LOG_WARNING, "Failing due to no acceptable offer found\n");
8549
		return -2;
8652
		res = -2;

    
   
8653
		goto process_sdp_cleanup;
8550
	}
8654
	}
8551

    
   
8655

   
8552
	if (numberofmediastreams > 3) {
8656
	if (numberofmediastreams > 3) {
8553
		/* We have too many fax, audio and/or video and/or text media streams, fail this offer */
8657
		/* We have too many fax, audio and/or video and/or text media streams, fail this offer */
8554
		ast_log(LOG_WARNING, "Faling due to too many media streams\n");
8658
		ast_log(LOG_WARNING, "Faling due to too many media streams\n");
8555
		return -3;
8659
		res = -3;

    
   
8660
		goto process_sdp_cleanup;
8556
	}
8661
	}
8557

    
   
8662

   
8558
	if (secure_audio && !(p->srtp && (ast_test_flag(p->srtp, SRTP_CRYPTO_OFFER_OK)))) {
8663
	if (secure_audio && !(p->srtp && (ast_test_flag(p->srtp, SRTP_CRYPTO_OFFER_OK)))) {
8559
		ast_log(LOG_WARNING, "Can't provide secure audio requested in SDP offer\n");
8664
		ast_log(LOG_WARNING, "Can't provide secure audio requested in SDP offer\n");
8560
		return -4;
8665
		res = -4;

    
   
8666
		goto process_sdp_cleanup;
8561
	}
8667
	}
8562

    
   
8668

   
8563
	if (!secure_audio && p->srtp) {
8669
	if (!secure_audio && p->srtp) {
8564
		ast_log(LOG_WARNING, "We are requesting SRTP, but they responded without it!\n");
8670
		ast_log(LOG_WARNING, "We are requesting SRTP, but they responded without it!\n");
8565
		return -4;
8671
		res = -4;

    
   
8672
		goto process_sdp_cleanup;
8566
	}
8673
	}
8567

    
   
8674

   
8568
	if (secure_video && !(p->vsrtp && (ast_test_flag(p->vsrtp, SRTP_CRYPTO_OFFER_OK)))) {
8675
	if (secure_video && !(p->vsrtp && (ast_test_flag(p->vsrtp, SRTP_CRYPTO_OFFER_OK)))) {
8569
		ast_log(LOG_WARNING, "Can't provide secure video requested in SDP offer\n");
8676
		ast_log(LOG_WARNING, "Can't provide secure video requested in SDP offer\n");
8570
		return -4;
8677
		res = -4;

    
   
8678
		goto process_sdp_cleanup;
8571
	}
8679
	}
8572

    
   
8680

   
8573
	if (!p->novideo && !secure_video && p->vsrtp) {
8681
	if (!p->novideo && !secure_video && p->vsrtp) {
8574
		ast_log(LOG_WARNING, "We are requesting SRTP, but they responded without it!\n");
8682
		ast_log(LOG_WARNING, "We are requesting SRTP, but they responded without it!\n");
8575
		return -4;
8683
		res = -4;

    
   
8684
		goto process_sdp_cleanup;
8576
	}
8685
	}
8577

    
   
8686

   
8578
	if (!(secure_audio || secure_video) && ast_test_flag(&p->flags[1], SIP_PAGE2_USE_SRTP)) {
8687
	if (!(secure_audio || secure_video) && ast_test_flag(&p->flags[1], SIP_PAGE2_USE_SRTP)) {
8579
		ast_log(LOG_WARNING, "Matched device setup to use SRTP, but request was not!\n");
8688
		ast_log(LOG_WARNING, "Matched device setup to use SRTP, but request was not!\n");
8580
		return -4;
8689
		res = -4;

    
   
8690
		goto process_sdp_cleanup;
8581
	}
8691
	}
8582

    
   
8692

   
8583
	if (udptlportno == -1) {
8693
	if (udptlportno == -1) {
8584
		change_t38_state(p, T38_DISABLED);
8694
		change_t38_state(p, T38_DISABLED);
8585
	}
8695
	}
8586

    
   
8696

   
8587
	/* Now gather all of the codecs that we are asked for: */
8697
	/* Now gather all of the codecs that we are asked for: */
8588
	ast_rtp_codecs_payload_formats(&newaudiortp, &peercapability, &peernoncodeccapability);
8698
	ast_rtp_codecs_payload_formats(&newaudiortp, peercapability, &peernoncodeccapability);
8589
	ast_rtp_codecs_payload_formats(&newvideortp, &vpeercapability, &vpeernoncodeccapability);
8699
	ast_rtp_codecs_payload_formats(&newvideortp, vpeercapability, &vpeernoncodeccapability);
8590
	ast_rtp_codecs_payload_formats(&newtextrtp, &tpeercapability, &tpeernoncodeccapability);
8700
	ast_rtp_codecs_payload_formats(&newtextrtp, tpeercapability, &tpeernoncodeccapability);

    
   
8701

   

    
   
8702
	ast_format_cap_append(newpeercapability, peercapability);

    
   
8703
	ast_format_cap_append(newpeercapability, vpeercapability);

    
   
8704
	ast_format_cap_append(newpeercapability, tpeercapability);

    
   
8705

   

    
   
8706
	ast_format_cap_joint_copy(p->caps, newpeercapability, newjointcapability);

    
   
8707
	if (ast_format_cap_is_empty(newjointcapability) && (portno != -1)) {
Moved from 8618

    
   
8708
		ast_log(LOG_NOTICE, "No compatible codecs, not accepting this offer!\n");
Moved from 8619

    
   
8709
		/* Do NOT Change current setting */

    
   
8710
		res = -1;

    
   
8711
		goto process_sdp_cleanup;

    
   
8712
	}
8591

    
   
8713

   
8592
	newjointcapability = p->capability & (peercapability | vpeercapability | tpeercapability);

   
8593
	newpeercapability = (peercapability | vpeercapability | tpeercapability);

   
8594
	newnoncodeccapability = p->noncodeccapability & peernoncodeccapability;
8714
	newnoncodeccapability = p->noncodeccapability & peernoncodeccapability;
8595

    
   
8715

   
8596
	if (debug) {
8716
	if (debug) {
8597
		/* shame on whoever coded this.... */
8717
		/* shame on whoever coded this.... */
8598
		char s1[SIPBUFSIZE], s2[SIPBUFSIZE], s3[SIPBUFSIZE], s4[SIPBUFSIZE], s5[SIPBUFSIZE];
8718
		char s1[SIPBUFSIZE], s2[SIPBUFSIZE], s3[SIPBUFSIZE], s4[SIPBUFSIZE], s5[SIPBUFSIZE];
8599

    
   
8719

   
8600
		ast_verbose("Capabilities: us - %s, peer - audio=%s/video=%s/text=%s, combined - %s\n",
8720
		ast_verbose("Capabilities: us - %s, peer - audio=%s/video=%s/text=%s, combined - %s\n",
8601
			    ast_getformatname_multiple(s1, SIPBUFSIZE, p->capability),
8721
			    ast_getformatname_multiple(s1, SIPBUFSIZE, p->caps),
8602
			    ast_getformatname_multiple(s2, SIPBUFSIZE, peercapability),
8722
			    ast_getformatname_multiple(s2, SIPBUFSIZE, peercapability),
8603
			    ast_getformatname_multiple(s3, SIPBUFSIZE, vpeercapability),
8723
			    ast_getformatname_multiple(s3, SIPBUFSIZE, vpeercapability),
8604
			    ast_getformatname_multiple(s4, SIPBUFSIZE, tpeercapability),
8724
			    ast_getformatname_multiple(s4, SIPBUFSIZE, tpeercapability),
8605
			    ast_getformatname_multiple(s5, SIPBUFSIZE, newjointcapability));
8725
			    ast_getformatname_multiple(s5, SIPBUFSIZE, newjointcapability));
8606
	}
8726
	}
8607
	if (debug) {
8727
	if (debug) {
8608
		struct ast_str *s1 = ast_str_alloca(SIPBUFSIZE);
8728
		struct ast_str *s1 = ast_str_alloca(SIPBUFSIZE);
8609
		struct ast_str *s2 = ast_str_alloca(SIPBUFSIZE);
8729
		struct ast_str *s2 = ast_str_alloca(SIPBUFSIZE);
8610
		struct ast_str *s3 = ast_str_alloca(SIPBUFSIZE);
8730
		struct ast_str *s3 = ast_str_alloca(SIPBUFSIZE);
8611

    
   
8731

   
8612
		ast_verbose("Non-codec capabilities (dtmf): us - %s, peer - %s, combined - %s\n",
8732
		ast_verbose("Non-codec capabilities (dtmf): us - %s, peer - %s, combined - %s\n",
8613
			    ast_rtp_lookup_mime_multiple2(s1, p->noncodeccapability, 0, 0),
8733
			    ast_rtp_lookup_mime_multiple2(s1, NULL, p->noncodeccapability, 0, 0),
8614
			    ast_rtp_lookup_mime_multiple2(s2, peernoncodeccapability, 0, 0),
8734
			    ast_rtp_lookup_mime_multiple2(s2, NULL, peernoncodeccapability, 0, 0),
8615
			    ast_rtp_lookup_mime_multiple2(s3, newnoncodeccapability, 0, 0));
8735
			    ast_rtp_lookup_mime_multiple2(s3, NULL, newnoncodeccapability, 0, 0));
8616
	}

   
8617
	if (!newjointcapability && (portno != -1)) {

   
8618
		ast_log(LOG_NOTICE, "No compatible codecs, not accepting this offer!\n");
Moved to 8708

   
8619
		/* Do NOT Change current setting */
Moved to 8709

   
8620
		return -1;

   
8621
	}
8736
	}
8622

    
   
8737

   
8623
	/* Setup audio address and port */
8738
	/* Setup audio address and port */
8624
	if (p->rtp) {
8739
	if (p->rtp) {
8625
		if (portno > 0) {
8740
		if (portno > 0) {
8626
			ast_sockaddr_set_port(sa, portno);
8741
			ast_sockaddr_set_port(sa, portno);
8627
			ast_rtp_instance_set_remote_address(p->rtp, sa);
8742
			ast_rtp_instance_set_remote_address(p->rtp, sa);
8628
			if (debug) {
8743
			if (debug) {
8629
				ast_verbose("Peer audio RTP is at port %s\n",
8744
				ast_verbose("Peer audio RTP is at port %s\n",
8630
					    ast_sockaddr_stringify(sa));
8745
					    ast_sockaddr_stringify(sa));
8631
			}
8746
			}
8632
			/* We are now ready to change the sip session and p->rtp and p->vrtp with the offered codecs, since
8747
			/* We are now ready to change the sip session and p->rtp and p->vrtp with the offered codecs, since
8633
			   they are acceptable */
8748
			   they are acceptable */
8634
			p->jointcapability = newjointcapability;                /* Our joint codec profile for this call */
8749
			ast_format_cap_copy(p->jointcaps, newjointcapability);                /* Our joint codec profile for this call */
8635
			p->peercapability = newpeercapability;                  /* The other sides capability in latest offer */
8750
			ast_format_cap_copy(p->peercaps, newpeercapability);                  /* The other sides capability in latest offer */
8636
			p->jointnoncodeccapability = newnoncodeccapability;     /* DTMF capabilities */
8751
			p->jointnoncodeccapability = newnoncodeccapability;     /* DTMF capabilities */
8637

    
   
8752

   
8638
			if (ast_test_flag(&p->flags[1], SIP_PAGE2_PREFERRED_CODEC)) { /* respond with single most preferred joint codec, limiting the other side's choice */
8753
			if (ast_test_flag(&p->flags[1], SIP_PAGE2_PREFERRED_CODEC)) { /* respond with single most preferred joint codec, limiting the other side's choice */
8639
				p->jointcapability = ast_codec_choose(&p->prefs, p->jointcapability, 1);
8754
				ast_codec_choose(&p->prefs, p->jointcaps, 1, &tmp_fmt);

    
   
8755
				ast_format_cap_set(p->jointcaps, &tmp_fmt);
8640
			}
8756
			}
8641

    
   
8757

   
8642
			ast_rtp_codecs_payloads_copy(&newaudiortp, ast_rtp_instance_get_codecs(p->rtp), p->rtp);
8758
			ast_rtp_codecs_payloads_copy(&newaudiortp, ast_rtp_instance_get_codecs(p->rtp), p->rtp);
8643

    
   
8759

   
8644
			if (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO) {
8760
			if (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO) {
[+20] [20] 42 lines
[+20] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
8687
			ast_rtp_instance_set_remote_address(p->trtp, tsa);
8803
			ast_rtp_instance_set_remote_address(p->trtp, tsa);
8688
			if (debug) {
8804
			if (debug) {
8689
				ast_verbose("Peer T.140 RTP is at port %s\n",
8805
				ast_verbose("Peer T.140 RTP is at port %s\n",
8690
					    ast_sockaddr_stringify(tsa));
8806
					    ast_sockaddr_stringify(tsa));
8691
			}
8807
			}
8692
			if ((p->jointcapability & AST_FORMAT_T140RED)) {
8808
			if (ast_format_cap_iscompatible(p->jointcaps, ast_format_set(&tmp_fmt, AST_FORMAT_T140RED, 0))) {
8693
				p->red = 1;
8809
				p->red = 1;
8694
				ast_rtp_red_init(p->trtp, 300, red_data_pt, 2);
8810
				ast_rtp_red_init(p->trtp, 300, red_data_pt, 2);
8695
			} else {
8811
			} else {
8696
				p->red = 0;
8812
				p->red = 0;
8697
			}
8813
			}
[+20] [20] 59 lines
[+20] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
8757
		}
8873
		}
8758
	}
8874
	}
8759

    
   
8875

   
8760
	if ((portno == -1) && (p->t38.state != T38_DISABLED)) {
8876
	if ((portno == -1) && (p->t38.state != T38_DISABLED)) {
8761
		ast_debug(3, "Have T.38 but no audio, accepting offer anyway\n");
8877
		ast_debug(3, "Have T.38 but no audio, accepting offer anyway\n");
8762
		return 0;
8878
		res = 0;

    
   
8879
		goto process_sdp_cleanup;
8763
        }
8880
	}
8764

    
   
8881

   
8765
	/* Ok, we're going with this offer */
8882
	/* Ok, we're going with this offer */
8766
	ast_debug(2, "We're settling with these formats: %s\n", ast_getformatname_multiple(buf, SIPBUFSIZE, p->jointcapability));
8883
	ast_debug(2, "We're settling with these formats: %s\n", ast_getformatname_multiple(buf, SIPBUFSIZE, p->jointcaps));
8767

    
   
8884

   
8768
	if (!p->owner) 	/* There's no open channel owning us so we can return here. For a re-invite or so, we proceed */
8885
	if (!p->owner) { /* There's no open channel owning us so we can return here. For a re-invite or so, we proceed */
8769
		return 0;
8886
		res = 0;

    
   
8887
		goto process_sdp_cleanup;

    
   
8888
	}
8770

    
   
8889

   
8771
	ast_debug(4, "We have an owner, now see if we need to change this call\n");
8890
	ast_debug(4, "We have an owner, now see if we need to change this call\n");
8772

    
   
8891
	if (ast_format_cap_has_type(p->jointcaps, AST_FORMAT_TYPE_AUDIO)) {
8773
	if (!(p->owner->nativeformats & p->jointcapability) && (p->jointcapability & AST_FORMAT_AUDIO_MASK)) {

   
8774
		if (debug) {
8892
		if (debug) {
8775
			char s1[SIPBUFSIZE], s2[SIPBUFSIZE];
8893
			char s1[SIPBUFSIZE], s2[SIPBUFSIZE];
8776
			ast_debug(1, "Oooh, we need to change our audio formats since our peer supports only %s and not %s\n",
8894
			ast_debug(1, "Setting native formats after processing SDP. peer joint formats %s, old nativeformats %s\n",
8777
				ast_getformatname_multiple(s1, SIPBUFSIZE, p->jointcapability),
8895
				ast_getformatname_multiple(s1, SIPBUFSIZE, p->jointcaps),
8778
				ast_getformatname_multiple(s2, SIPBUFSIZE, p->owner->nativeformats));
8896
				ast_getformatname_multiple(s2, SIPBUFSIZE, p->owner->nativeformats));
8779
		}
8897
		}
8780
		p->owner->nativeformats = ast_codec_choose(&p->prefs, p->jointcapability, 1) | (p->capability & vpeercapability) | (p->capability & tpeercapability);
8898

   
8781
		ast_set_read_format(p->owner, p->owner->readformat);
8899
		ast_codec_choose(&p->prefs, p->jointcaps, 1, &tmp_fmt);
8782
		ast_set_write_format(p->owner, p->owner->writeformat);
8900

   

    
   
8901
		ast_format_cap_set(p->owner->nativeformats, &tmp_fmt);

    
   
8902
		ast_format_cap_joint_append(p->caps, vpeercapability, p->owner->nativeformats);

    
   
8903
		ast_format_cap_joint_append(p->caps, tpeercapability, p->owner->nativeformats);

    
   
8904

   

    
   
8905
		ast_set_read_format(p->owner, &p->owner->readformat);

    
   
8906
		ast_set_write_format(p->owner, &p->owner->writeformat);
8783
	}
8907
	}
8784
	
8908

   
8785
	if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) && (!ast_sockaddr_isnull(sa) || !ast_sockaddr_isnull(vsa) || !ast_sockaddr_isnull(tsa) || !ast_sockaddr_isnull(isa)) && (!sendonly || sendonly == -1)) {
8909
	if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) && (!ast_sockaddr_isnull(sa) || !ast_sockaddr_isnull(vsa) || !ast_sockaddr_isnull(tsa) || !ast_sockaddr_isnull(isa)) && (!sendonly || sendonly == -1)) {
8786
		ast_queue_control(p->owner, AST_CONTROL_UNHOLD);
8910
		ast_queue_control(p->owner, AST_CONTROL_UNHOLD);
8787
		/* Activate a re-invite */
8911
		/* Activate a re-invite */
8788
		ast_queue_frame(p->owner, &ast_null_frame);
8912
		ast_queue_frame(p->owner, &ast_null_frame);
8789
		change_hold_state(p, req, FALSE, sendonly);
8913
		change_hold_state(p, req, FALSE, sendonly);
[+20] [20] 6 lines
[+20] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
8796
		/* RTCP needs to go ahead, even if we're on hold!!! */
8920
		/* RTCP needs to go ahead, even if we're on hold!!! */
8797
		/* Activate a re-invite */
8921
		/* Activate a re-invite */
8798
		ast_queue_frame(p->owner, &ast_null_frame);
8922
		ast_queue_frame(p->owner, &ast_null_frame);
8799
		change_hold_state(p, req, TRUE, sendonly);
8923
		change_hold_state(p, req, TRUE, sendonly);
8800
	}
8924
	}
8801
	
8925

   
8802
	return 0;
8926
process_sdp_cleanup:

    
   
8927
	ast_format_cap_destroy(peercapability);

    
   
8928
	ast_format_cap_destroy(vpeercapability);

    
   
8929
	ast_format_cap_destroy(tpeercapability);

    
   
8930
	ast_format_cap_destroy(newjointcapability);

    
   
8931
	ast_format_cap_destroy(newpeercapability);

    
   
8932
	return res;
8803
}
8933
}
8804

    
   
8934

   
8805
static int process_sdp_o(const char *o, struct sip_pvt *p)
8935
static int process_sdp_o(const char *o, struct sip_pvt *p)
8806
{
8936
{
8807
	char *o_copy;
8937
	char *o_copy;
[+20] [20] 143 lines
[+20] [+] static int process_sdp_a_audio(const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newaudiortp, int *last_rtpmap_codec)
8951
		if (framing && p->autoframing) {
9081
		if (framing && p->autoframing) {
8952
			struct ast_codec_pref *pref = &ast_rtp_instance_get_codecs(p->rtp)->pref;
9082
			struct ast_codec_pref *pref = &ast_rtp_instance_get_codecs(p->rtp)->pref;
8953
			int codec_n;
9083
			int codec_n;
8954
			for (codec_n = 0; codec_n < AST_RTP_MAX_PT; codec_n++) {
9084
			for (codec_n = 0; codec_n < AST_RTP_MAX_PT; codec_n++) {
8955
				struct ast_rtp_payload_type format = ast_rtp_codecs_payload_lookup(ast_rtp_instance_get_codecs(p->rtp), codec_n);
9085
				struct ast_rtp_payload_type format = ast_rtp_codecs_payload_lookup(ast_rtp_instance_get_codecs(p->rtp), codec_n);
8956
				if (!format.asterisk_format || !format.code)	/* non-codec or not found */
9086
				if (!format.asterisk_format)	/* non-codec or not found */
8957
					continue;
9087
					continue;
8958
				ast_debug(1, "Setting framing for %s to %ld\n", ast_getformatname(format.code), framing);
9088
				ast_debug(1, "Setting framing for %s to %ld\n", ast_getformatname(&format.format), framing);
8959
				ast_codec_pref_setsize(pref, format.code, framing);
9089
				ast_codec_pref_setsize(pref, &format.format, framing);
8960
			}
9090
			}
8961
			ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, pref);
9091
			ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, pref);
8962
		}
9092
		}
8963
		found = TRUE;
9093
		found = TRUE;
8964
	} else if (sscanf(a, "rtpmap: %30u %127[^/]/%30u", &codec, mimeSubtype, &sample_rate) == 3) {
9094
	} else if (sscanf(a, "rtpmap: %30u %127[^/]/%30u", &codec, mimeSubtype, &sample_rate) == 3) {
[+20] [20] 14 lines
[+20] static int process_sdp_a_audio(const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newaudiortp, int *last_rtpmap_codec)
8979
		} else {
9109
		} else {
8980
			if (debug)
9110
			if (debug)
8981
				ast_verbose("Discarded description format %s for ID %d\n", mimeSubtype, codec);
9111
				ast_verbose("Discarded description format %s for ID %d\n", mimeSubtype, codec);
8982
		}
9112
		}
8983
	} else if (sscanf(a, "fmtp: %30u %63s", &codec, fmtp_string) == 2) {
9113
	} else if (sscanf(a, "fmtp: %30u %63s", &codec, fmtp_string) == 2) {
8984
		struct ast_rtp_payload_type payload;
9114
		struct ast_format *format;
8985

    
   
9115

   
8986
		payload = ast_rtp_codecs_payload_lookup(newaudiortp, codec);
9116
		if ((format = ast_rtp_codecs_get_payload_format(newaudiortp, codec))) {
8987
		if (payload.code && payload.asterisk_format) {

   
8988
			unsigned int bit_rate;
9117
			unsigned int bit_rate;
8989

    
   
9118

   
8990
			switch (payload.code) {
9119
			switch ((int) format->id) {
8991
			case AST_FORMAT_SIREN7:
9120
			case AST_FORMAT_SIREN7:
8992
				if (sscanf(fmtp_string, "bitrate=%30u", &bit_rate) == 1) {
9121
				if (sscanf(fmtp_string, "bitrate=%30u", &bit_rate) == 1) {
8993
					if (bit_rate != 32000) {
9122
					if (bit_rate != 32000) {
8994
						ast_log(LOG_WARNING, "Got Siren7 offer at %d bps, but only 32000 bps supported; ignoring.\n", bit_rate);
9123
						ast_log(LOG_WARNING, "Got Siren7 offer at %d bps, but only 32000 bps supported; ignoring.\n", bit_rate);
8995
						ast_rtp_codecs_payloads_unset(newaudiortp, NULL, codec);
9124
						ast_rtp_codecs_payloads_unset(newaudiortp, NULL, codec);
[+20] [20] 19 lines
[+20] static int process_sdp_a_audio(const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newaudiortp, int *last_rtpmap_codec)
9015
						ast_rtp_codecs_payloads_unset(newaudiortp, NULL, codec);
9144
						ast_rtp_codecs_payloads_unset(newaudiortp, NULL, codec);
9016
					} else {
9145
					} else {
9017
						found = TRUE;
9146
						found = TRUE;
9018
					}
9147
					}
9019
				}
9148
				}

    
   
9149
				break;

    
   
9150
			case AST_FORMAT_SILK:

    
   
9151
				{

    
   
9152
					int val = 0;

    
   
9153
					if (sscanf(fmtp_string, "maxaveragebitrate=%30u", &val) == 1) {

    
   
9154
						ast_format_append(format, SILK_ATTR_KEY_MAX_BITRATE, val, AST_FORMAT_ATTR_END);

    
   
9155
					}

    
   
9156
					if (sscanf(fmtp_string, "usedtx=%30u", &val) == 1) {

    
   
9157
						ast_format_append(format, SILK_ATTR_KEY_DTX, val ? 1 : 0, AST_FORMAT_ATTR_END);

    
   
9158
					}

    
   
9159
					if (sscanf(fmtp_string, "useinbandfec=%30u", &val) == 1) {

    
   
9160
						ast_format_append(format, SILK_ATTR_KEY_FEC, val ? 1 : 0, AST_FORMAT_ATTR_END);

    
   
9161
					}

    
   
9162
					break;

    
   
9163
				}
9020
			}
9164
			}
9021
		}
9165
		}
9022
	}
9166
	}
9023

    
   
9167

   
9024
	return found;
9168
	return found;
[+20] [20] 656 lines
[+20] [+] static int respprep(struct sip_request *resp, struct sip_pvt *p, const char *msg, const struct sip_request *req)
9681
	if (!ast_strlen_zero(p->url)) {
9825
	if (!ast_strlen_zero(p->url)) {
9682
		add_header(resp, "Access-URL", p->url);
9826
		add_header(resp, "Access-URL", p->url);
9683
		ast_string_field_set(p, url, NULL);
9827
		ast_string_field_set(p, url, NULL);
9684
	}
9828
	}
9685

    
   
9829

   

    
   
9830
	/* default to routing the response to the address where the request

    
   
9831
	 * came from.  Since we don't have a transport layer, we do this here.

    
   
9832
	 */

    
   
9833
	p->sa = p->recv;

    
   
9834

   

    
   
9835
	if (process_via(p, req)) {

    
   
9836
		ast_log(LOG_WARNING, "error processing via header, will send response to originating address\n");

    
   
9837
	}

    
   
9838

   
9686
	return 0;
9839
	return 0;
9687
}
9840
}
9688

    
   
9841

   
9689
/*! \brief Initialize a SIP request message (not the initial one in a dialog) */
9842
/*! \brief Initialize a SIP request message (not the initial one in a dialog) */
9690
static int reqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, int seqno, int newbranch)
9843
static int reqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, int seqno, int newbranch)
[+20] [20] 6 lines
[+20] static int respprep(struct sip_request *resp, struct sip_pvt *p, const char *msg, const struct sip_request *req)
9697
	const char *ot, *of;
9850
	const char *ot, *of;
9698
	int is_strict = FALSE;		/*!< Strict routing flag */
9851
	int is_strict = FALSE;		/*!< Strict routing flag */
9699
	int is_outbound = ast_test_flag(&p->flags[0], SIP_OUTGOING);	/* Session direction */
9852
	int is_outbound = ast_test_flag(&p->flags[0], SIP_OUTGOING);	/* Session direction */
9700

    
   
9853

   
9701
	memset(req, 0, sizeof(struct sip_request));
9854
	memset(req, 0, sizeof(struct sip_request));
9702
	
9855

   
9703
	snprintf(p->lastmsg, sizeof(p->lastmsg), "Tx: %s", sip_methods[sipmethod].text);
9856
	snprintf(p->lastmsg, sizeof(p->lastmsg), "Tx: %s", sip_methods[sipmethod].text);
9704
	
9857

   
9705
	if (!seqno) {
9858
	if (!seqno) {
9706
		p->ocseq++;
9859
		p->ocseq++;
9707
		seqno = p->ocseq;
9860
		seqno = p->ocseq;
9708
	}
9861
	}
9709
	
9862

   
9710
	/* A CANCEL must have the same branch as the INVITE that it is canceling. */
9863
	/* A CANCEL must have the same branch as the INVITE that it is canceling. */
9711
	if (sipmethod == SIP_CANCEL) {
9864
	if (sipmethod == SIP_CANCEL) {
9712
		p->branch = p->invite_branch;
9865
		p->branch = p->invite_branch;
9713
		build_via(p);
9866
		build_via(p);
9714
	} else if (newbranch && (sipmethod == SIP_INVITE)) {
9867
	} else if (newbranch && (sipmethod == SIP_INVITE)) {
[+20] [20] 9 lines
[+20] static int respprep(struct sip_request *resp, struct sip_pvt *p, const char *msg, const struct sip_request *req)
9724
	if (p->route && !ast_strlen_zero(p->route->hop) && strstr(p->route->hop, ";lr") == NULL) {
9877
	if (p->route && !ast_strlen_zero(p->route->hop) && strstr(p->route->hop, ";lr") == NULL) {
9725
		is_strict = TRUE;
9878
		is_strict = TRUE;
9726
		if (sipdebug)
9879
		if (sipdebug)
9727
			ast_debug(1, "Strict routing enforced for session %s\n", p->callid);
9880
			ast_debug(1, "Strict routing enforced for session %s\n", p->callid);
9728
	}
9881
	}
9729
	
9882

   
9730
	if (sipmethod == SIP_CANCEL)
9883
	if (sipmethod == SIP_CANCEL)
9731
		c = REQ_OFFSET_TO_STR(&p->initreq, rlPart2);	/* Use original URI */
9884
		c = REQ_OFFSET_TO_STR(&p->initreq, rlPart2);	/* Use original URI */
9732
	else if (sipmethod == SIP_ACK) {
9885
	else if (sipmethod == SIP_ACK) {
9733
		/* Use URI from Contact: in 200 OK (if INVITE)
9886
		/* Use URI from Contact: in 200 OK (if INVITE)
9734
		(we only have the contacturi on INVITEs) */
9887
		(we only have the contacturi on INVITEs) */
[+20] [20] 505 lines
[+20] [+] static int add_rpid(struct sip_request *req, struct sip_pvt *p)
10240
		return 0;
10393
		return 0;
10241
	if (ast_strlen_zero(lid_name))
10394
	if (ast_strlen_zero(lid_name))
10242
		lid_name = lid_num;
10395
		lid_name = lid_num;
10243
	fromdomain = S_OR(p->fromdomain, ast_sockaddr_stringify_host(&p->ourip));
10396
	fromdomain = S_OR(p->fromdomain, ast_sockaddr_stringify_host(&p->ourip));
10244

    
   
10397

   
10245
	lid_num = ast_uri_encode(lid_num, tmp2, sizeof(tmp2), 1);
10398
	lid_num = ast_uri_encode(lid_num, tmp2, sizeof(tmp2), ast_uri_sip_user);
10246

    
   
10399

   
10247
	if (ast_test_flag(&p->flags[0], SIP_SENDRPID_PAI)) {
10400
	if (ast_test_flag(&p->flags[0], SIP_SENDRPID_PAI)) {
10248
		if ((lid_pres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) {
10401
		if ((lid_pres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) {
10249
			ast_str_set(&tmp, -1, "%s", anonymous_string);
10402
			ast_str_set(&tmp, -1, "%s", anonymous_string);
10250
		} else {
10403
		} else {
[+20] [20] 63 lines
[+20] [+] static int add_vidupdate(struct sip_request *req)
10314
	add_content(req, xml_is_a_huge_waste_of_space);
10467
	add_content(req, xml_is_a_huge_waste_of_space);
10315
	return 0;
10468
	return 0;
10316
}
10469
}
10317

    
   
10470

   
10318
/*! \brief Add codec offer to SDP offer/answer body in INVITE or 200 OK */
10471
/*! \brief Add codec offer to SDP offer/answer body in INVITE or 200 OK */
10319
static void add_codec_to_sdp(const struct sip_pvt *p, format_t codec,
10472
static void add_codec_to_sdp(const struct sip_pvt *p,
10320
			     struct ast_str **m_buf, struct ast_str **a_buf,
10473
	struct ast_format *format,
10321
			     int debug, int *min_packet_size)
10474
	struct ast_str **m_buf,

    
   
10475
	struct ast_str **a_buf,

    
   
10476
	int debug,

    
   
10477
	int *min_packet_size)
10322
{
10478
{
10323
	int rtp_code;
10479
	int rtp_code;
10324
	struct ast_format_list fmt;
10480
	struct ast_format_list fmt;
10325

    
   
10481

   
10326

    
   
10482

   
10327
	if (debug)
10483
	if (debug)
10328
		ast_verbose("Adding codec 0x%" PRIx64 " (%s) to SDP\n", codec, ast_getformatname(codec));
10484
		ast_verbose("Adding codec %d (%s) to SDP\n", format->id, ast_getformatname(format));
10329
	if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->rtp), 1, codec)) == -1)
10485
	if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->rtp), 1, format, 0)) == -1)
10330
		return;
10486
		return;
10331

    
   
10487

   
10332
	if (p->rtp) {
10488
	if (p->rtp) {
10333
		struct ast_codec_pref *pref = &ast_rtp_instance_get_codecs(p->rtp)->pref;
10489
		struct ast_codec_pref *pref = &ast_rtp_instance_get_codecs(p->rtp)->pref;
10334
		fmt = ast_codec_pref_getsize(pref, codec);
10490
		fmt = ast_codec_pref_getsize(pref, format);
10335
	} else /* I don't see how you couldn't have p->rtp, but good to check for and error out if not there like earlier code */
10491
	} else /* I don't see how you couldn't have p->rtp, but good to check for and error out if not there like earlier code */
10336
		return;
10492
		return;
10337
	ast_str_append(m_buf, 0, " %d", rtp_code);
10493
	ast_str_append(m_buf, 0, " %d", rtp_code);
10338
	ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code,
10494
	ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n",
10339
		       ast_rtp_lookup_mime_subtype2(1, codec,
10495
		rtp_code,
10340
						   ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0),
10496
		ast_rtp_lookup_mime_subtype2(1, format, 0, ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0),
10341
		       ast_rtp_lookup_sample_rate2(1, codec));
10497
		ast_rtp_lookup_sample_rate2(1, format, 0));
10342

    
   
10498

   
10343
	switch (codec) {
10499
	switch ((int) format->id) {
10344
	case AST_FORMAT_G729A:
10500
	case AST_FORMAT_G729A:
10345
		/* Indicate that we don't support VAD (G.729 annex B) */
10501
		/* Indicate that we don't support VAD (G.729 annex B) */
10346
		ast_str_append(a_buf, 0, "a=fmtp:%d annexb=no\r\n", rtp_code);
10502
		ast_str_append(a_buf, 0, "a=fmtp:%d annexb=no\r\n", rtp_code);
10347
		break;
10503
		break;
10348
	case AST_FORMAT_G723_1:
10504
	case AST_FORMAT_G723_1:
[+20] [20] 14 lines
[+20] static void add_codec_to_sdp(const struct sip_pvt *p, format_t codec, [+] static void add_codec_to_sdp(const struct sip_pvt *p,
10363
		break;
10519
		break;
10364
	case AST_FORMAT_G719:
10520
	case AST_FORMAT_G719:
10365
		/* Indicate that we only expect 64Kbps */
10521
		/* Indicate that we only expect 64Kbps */
10366
		ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=64000\r\n", rtp_code);
10522
		ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=64000\r\n", rtp_code);
10367
		break;
10523
		break;

    
   
10524
	case AST_FORMAT_SILK:

    
   
10525
		{

    
   
10526
			int val = 0;

    
   
10527
			if (!ast_format_get_value(format, SILK_ATTR_KEY_MAX_BITRATE, &val) && val > 5000 && val < 40000) {

    
   
10528
				ast_str_append(a_buf, 0, "a=fmtp:%d maxaveragebitrate=%u\r\n", rtp_code, val);

    
   
10529
			}

    
   
10530
			if (!ast_format_get_value(format, SILK_ATTR_KEY_DTX, &val)) {

    
   
10531
				ast_str_append(a_buf, 0, "a=fmtp:%d usedtx=%u\r\n", rtp_code, val ? 1 : 0);

    
   
10532
			}

    
   
10533
			if (!ast_format_get_value(format, SILK_ATTR_KEY_FEC, &val)) {

    
   
10534
				ast_str_append(a_buf, 0, "a=fmtp:%d useinbandfec=%u\r\n", rtp_code, val ? 1 : 0);

    
   
10535
			}

    
   
10536
			break;

    
   
10537
		}
10368
	}
10538
	}
10369

    
   
10539

   
10370
	if (fmt.cur_ms && (fmt.cur_ms < *min_packet_size))
10540
	if (fmt.cur_ms && (fmt.cur_ms < *min_packet_size))
10371
		*min_packet_size = fmt.cur_ms;
10541
		*min_packet_size = fmt.cur_ms;
10372

    
   
10542

   
10373
	/* Our first codec packetization processed cannot be zero */
10543
	/* Our first codec packetization processed cannot be zero */
10374
	if ((*min_packet_size)==0 && fmt.cur_ms)
10544
	if ((*min_packet_size)==0 && fmt.cur_ms)
10375
		*min_packet_size = fmt.cur_ms;
10545
		*min_packet_size = fmt.cur_ms;
10376
}
10546
}
10377

    
   
10547

   
10378
/*! \brief Add video codec offer to SDP offer/answer body in INVITE or 200 OK */
10548
/*! \brief Add video codec offer to SDP offer/answer body in INVITE or 200 OK */
10379
/* This is different to the audio one now so we can add more caps later */
10549
/* This is different to the audio one now so we can add more caps later */
10380
static void add_vcodec_to_sdp(const struct sip_pvt *p, format_t codec,
10550
static void add_vcodec_to_sdp(const struct sip_pvt *p, struct ast_format *format,
10381
			     struct ast_str **m_buf, struct ast_str **a_buf,
10551
			     struct ast_str **m_buf, struct ast_str **a_buf,
10382
			     int debug, int *min_packet_size)
10552
			     int debug, int *min_packet_size)
10383
{
10553
{
10384
	int rtp_code;
10554
	int rtp_code;
10385

    
   
10555

   
10386
	if (!p->vrtp)
10556
	if (!p->vrtp)
10387
		return;
10557
		return;
10388

    
   
10558

   
10389
	if (debug)
10559
	if (debug)
10390
		ast_verbose("Adding video codec 0x%" PRIx64 " (%s) to SDP\n", codec, ast_getformatname(codec));
10560
		ast_verbose("Adding video codec %d (%s) to SDP\n", format->id, ast_getformatname(format));
10391

    
   
10561

   
10392
	if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->vrtp), 1, codec)) == -1)
10562
	if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->vrtp), 1, format, 0)) == -1)
10393
		return;
10563
		return;
10394

    
   
10564

   
10395
	ast_str_append(m_buf, 0, " %d", rtp_code);
10565
	ast_str_append(m_buf, 0, " %d", rtp_code);
10396
	ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code,
10566
	ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code,
10397
		       ast_rtp_lookup_mime_subtype2(1, codec, 0),
10567
		       ast_rtp_lookup_mime_subtype2(1, format, 0, 0),
10398
		       ast_rtp_lookup_sample_rate2(1, codec));
10568
		       ast_rtp_lookup_sample_rate2(1, format, 0));
10399
	/* Add fmtp code here */
10569
	/* Add fmtp code here */
10400
}
10570
}
10401

    
   
10571

   
10402
/*! \brief Add text codec offer to SDP offer/answer body in INVITE or 200 OK */
10572
/*! \brief Add text codec offer to SDP offer/answer body in INVITE or 200 OK */
10403
static void add_tcodec_to_sdp(const struct sip_pvt *p, int codec,
10573
static void add_tcodec_to_sdp(const struct sip_pvt *p, struct ast_format *format,
10404
			     struct ast_str **m_buf, struct ast_str **a_buf,
10574
			     struct ast_str **m_buf, struct ast_str **a_buf,
10405
			     int debug, int *min_packet_size)
10575
			     int debug, int *min_packet_size)
10406
{
10576
{
10407
	int rtp_code;
10577
	int rtp_code;
10408

    
   
10578

   
10409
	if (!p->trtp)
10579
	if (!p->trtp)
10410
		return;
10580
		return;
10411

    
   
10581

   
10412
	if (debug)
10582
	if (debug)
10413
		ast_verbose("Adding text codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec));
10583
		ast_verbose("Adding text codec %d (%s) to SDP\n", format->id, ast_getformatname(format));
10414

    
   
10584

   
10415
	if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->trtp), 1, codec)) == -1)
10585
	if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->trtp), 1, format, 0)) == -1)
10416
		return;
10586
		return;
10417

    
   
10587

   
10418
	ast_str_append(m_buf, 0, " %d", rtp_code);
10588
	ast_str_append(m_buf, 0, " %d", rtp_code);
10419
	ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code,
10589
	ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code,
10420
		       ast_rtp_lookup_mime_subtype2(1, codec, 0),
10590
		       ast_rtp_lookup_mime_subtype2(1, format, 0, 0),
10421
		       ast_rtp_lookup_sample_rate2(1, codec));
10591
		       ast_rtp_lookup_sample_rate2(1, format, 0));
10422
	/* Add fmtp code here */
10592
	/* Add fmtp code here */
10423

    
   
10593

   
10424
	if (codec == AST_FORMAT_T140RED) {
10594
	if (format->id == AST_FORMAT_T140RED) {
10425
		int t140code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->trtp), 1, AST_FORMAT_T140);
10595
		struct ast_format tmp_fmt;

    
   
10596
		int t140code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->trtp), 1, ast_format_set(&tmp_fmt, AST_FORMAT_T140, 0), 0);
10426
		ast_str_append(a_buf, 0, "a=fmtp:%d %d/%d/%d\r\n", rtp_code,
10597
		ast_str_append(a_buf, 0, "a=fmtp:%d %d/%d/%d\r\n", rtp_code,
10427
			 t140code,
10598
			 t140code,
10428
			 t140code,
10599
			 t140code,
10429
			 t140code);
10600
			 t140code);
10430

    
   
10601

   
[+20] [20] 28 lines
[+20] [+] static void add_noncodec_to_sdp(const struct sip_pvt *p, int format,
10459
				int debug)
10630
				int debug)
10460
{
10631
{
10461
	int rtp_code;
10632
	int rtp_code;
10462

    
   
10633

   
10463
	if (debug)
10634
	if (debug)
10464
		ast_verbose("Adding non-codec 0x%x (%s) to SDP\n", format, ast_rtp_lookup_mime_subtype2(0, format, 0));
10635
		ast_verbose("Adding non-codec 0x%x (%s) to SDP\n", format, ast_rtp_lookup_mime_subtype2(0, NULL, format, 0));
10465
	if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->rtp), 0, format)) == -1)
10636
	if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->rtp), 0, NULL, format)) == -1)
10466
		return;
10637
		return;
10467

    
   
10638

   
10468
	ast_str_append(m_buf, 0, " %d", rtp_code);
10639
	ast_str_append(m_buf, 0, " %d", rtp_code);
10469
	ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code,
10640
	ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code,
10470
		       ast_rtp_lookup_mime_subtype2(0, format, 0),
10641
		       ast_rtp_lookup_mime_subtype2(0, NULL, format, 0),
10471
		       ast_rtp_lookup_sample_rate2(0, format));
10642
		       ast_rtp_lookup_sample_rate2(0, NULL, format));
10472
	if (format == AST_RTP_DTMF)	/* Indicate we support DTMF and FLASH... */
10643
	if (format == AST_RTP_DTMF)	/* Indicate we support DTMF and FLASH... */
10473
		ast_str_append(a_buf, 0, "a=fmtp:%d 0-16\r\n", rtp_code);
10644
		ast_str_append(a_buf, 0, "a=fmtp:%d 0-16\r\n", rtp_code);
10474
}
10645
}
10475

    
   
10646

   
10476
/*! \brief Set all IP media addresses for this call
10647
/*! \brief Set all IP media addresses for this call
[+20] [20] 115 lines
[+20] [+] static void get_crypto_attrib(struct sip_srtp *srtp, const char **a_crypto)
10592
    is used in Session-Timers where RE-INVITEs are used for refreshing SIP sessions
10763
    is used in Session-Timers where RE-INVITEs are used for refreshing SIP sessions
10593
    without modifying the media session in any way.
10764
    without modifying the media session in any way.
10594
*/
10765
*/
10595
static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int oldsdp, int add_audio, int add_t38)
10766
static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int oldsdp, int add_audio, int add_t38)
10596
{
10767
{
10597
	format_t alreadysent = 0;
10768
	struct ast_format_cap *alreadysent = ast_format_cap_alloc_nolock();
10598

    
   
10769
	struct ast_format_cap *tmpcap = ast_format_cap_alloc_nolock();

    
   
10770
	int res = AST_SUCCESS;

    
   
10771
	int doing_directmedia = FALSE;
10599
	struct ast_sockaddr addr = { {0,} };
10772
	struct ast_sockaddr addr = { {0,} };
10600
	struct ast_sockaddr vaddr = { {0,} };
10773
	struct ast_sockaddr vaddr = { {0,} };
10601
	struct ast_sockaddr taddr = { {0,} };
10774
	struct ast_sockaddr taddr = { {0,} };
10602
	struct ast_sockaddr udptladdr = { {0,} };
10775
	struct ast_sockaddr udptladdr = { {0,} };
10603
	struct ast_sockaddr dest = { {0,} };
10776
	struct ast_sockaddr dest = { {0,} };
[+20] [20] 19 lines
[+20] static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int oldsdp, int add_audio, int add_t38)
10623
	struct ast_str *a_modem = ast_str_alloca(1024); /* Attributes for modem */
10796
	struct ast_str *a_modem = ast_str_alloca(1024); /* Attributes for modem */
10624
	const char *a_crypto = NULL;
10797
	const char *a_crypto = NULL;
10625
	const char *v_a_crypto = NULL;
10798
	const char *v_a_crypto = NULL;
10626
	const char *t_a_crypto = NULL;
10799
	const char *t_a_crypto = NULL;
10627

    
   
10800

   
10628
	format_t x;
10801
	int x;
10629
	format_t capability = 0;
10802
	struct ast_format tmp_fmt;
10630
	int needaudio = FALSE;
10803
	int needaudio = FALSE;
10631
	int needvideo = FALSE;
10804
	int needvideo = FALSE;
10632
	int needtext = FALSE;
10805
	int needtext = FALSE;
10633
	int debug = sip_debug_test_pvt(p);
10806
	int debug = sip_debug_test_pvt(p);
10634
	int min_audio_packet_size = 0;
10807
	int min_audio_packet_size = 0;
[+20] [20] 5 lines
[+20] static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int oldsdp, int add_audio, int add_t38)
10640
	char dummy_answer[256];
10813
	char dummy_answer[256];
10641

    
   
10814

   
10642
	/* Set the SDP session name */
10815
	/* Set the SDP session name */
10643
	snprintf(subject, sizeof(subject), "s=%s\r\n", ast_strlen_zero(global_sdpsession) ? "-" : global_sdpsession);
10816
	snprintf(subject, sizeof(subject), "s=%s\r\n", ast_strlen_zero(global_sdpsession) ? "-" : global_sdpsession);
10644

    
   
10817

   

    
   
10818
	if (!alreadysent || !tmpcap) {

    
   
10819
		res = AST_FAILURE;

    
   
10820
		goto add_sdp_cleanup;

    
   
10821
	}
10645
	if (!p->rtp) {
10822
	if (!p->rtp) {
10646
		ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n");
10823
		ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n");
10647
		return AST_FAILURE;
10824
		res = AST_FAILURE;

    
   
10825
		goto add_sdp_cleanup;

    
   
10826

   
10648
	}
10827
	}
10649
	/* XXX We should not change properties in the SIP dialog until
10828
	/* XXX We should not change properties in the SIP dialog until
10650
		we have acceptance of the offer if this is a re-invite */
10829
		we have acceptance of the offer if this is a re-invite */
10651

    
   
10830

   
10652
	/* Set RTP Session ID and version */
10831
	/* Set RTP Session ID and version */
[+20] [20] 4 lines
[+20] static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int oldsdp, int add_audio, int add_t38)
10657
		if (oldsdp == FALSE)
10836
		if (oldsdp == FALSE)
10658
			p->sessionversion++;
10837
			p->sessionversion++;
10659
	}
10838
	}
10660

    
   
10839

   
10661
	if (add_audio) {
10840
	if (add_audio) {

    
   
10841
		doing_directmedia = (!ast_sockaddr_isnull(&p->redirip) && !(ast_format_cap_is_empty(p->redircaps))) ? TRUE : FALSE;
10662
		/* Check if we need video in this call */
10842
		/* Check if we need video in this call */
10663
		if ((p->jointcapability & AST_FORMAT_VIDEO_MASK) && !p->novideo) {
10843
		if ((ast_format_cap_has_type(p->jointcaps, AST_FORMAT_TYPE_VIDEO)) && !p->novideo) {
10664
			if (p->vrtp) {
10844
			if (p->vrtp) {
10665
				needvideo = TRUE;
10845
				needvideo = TRUE;
10666
				ast_debug(2, "This call needs video offers!\n");
10846
				ast_debug(2, "This call needs video offers!\n");
10667
			} else
10847
			} else
10668
				ast_debug(2, "This call needs video offers, but there's no video support enabled!\n");
10848
				ast_debug(2, "This call needs video offers, but there's no video support enabled!\n");
10669
		}
10849
		}
10670
		/* Check if we need text in this call */
10850
		/* Check if we need text in this call */
10671
		if ((p->jointcapability & AST_FORMAT_TEXT_MASK) && !p->notext) {
10851
		if ((ast_format_cap_has_type(p->jointcaps, AST_FORMAT_TYPE_TEXT)) && !p->notext) {
10672
			if (sipdebug_text)
10852
			if (sipdebug_text)
10673
				ast_verbose("We think we can do text\n");
10853
				ast_verbose("We think we can do text\n");
10674
			if (p->trtp) {
10854
			if (p->trtp) {
10675
				if (sipdebug_text) {
10855
				if (sipdebug_text) {
10676
					ast_verbose("And we have a text rtp object\n");
10856
					ast_verbose("And we have a text rtp object\n");
[+20] [20] 19 lines
[+20] static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int oldsdp, int add_audio, int add_t38)
10696
		 (ast_sockaddr_is_ipv6(&dest) && !ast_sockaddr_is_ipv4_mapped(&dest)) ?
10876
		 (ast_sockaddr_is_ipv6(&dest) && !ast_sockaddr_is_ipv4_mapped(&dest)) ?
10697
			"IP6" : "IP4",
10877
			"IP6" : "IP4",
10698
		 ast_sockaddr_stringify_addr(&dest));
10878
		 ast_sockaddr_stringify_addr(&dest));
10699

    
   
10879

   
10700
	if (add_audio) {
10880
	if (add_audio) {
10701
		capability = p->jointcapability;
10881
		if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) == SIP_PAGE2_CALL_ONHOLD_ONEDIR) {

    
   
10882
			hold = "a=recvonly\r\n";

    
   
10883
			doing_directmedia = FALSE;

    
   
10884
		} else if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) == SIP_PAGE2_CALL_ONHOLD_INACTIVE) {

    
   
10885
			hold = "a=inactive\r\n";

    
   
10886
			doing_directmedia = FALSE;

    
   
10887
		} else {

    
   
10888
			hold = "a=sendrecv\r\n";

    
   
10889
		}

    
   
10890

   

    
   
10891
		ast_format_cap_copy(tmpcap, p->jointcaps);
10702

    
   
10892

   
10703
		/* XXX note, Video and Text are negated - 'true' means 'no' */
10893
		/* XXX note, Video and Text are negated - 'true' means 'no' */
10704
		ast_debug(1, "** Our capability: %s Video flag: %s Text flag: %s\n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), capability),
10894
		ast_debug(1, "** Our capability: %s Video flag: %s Text flag: %s\n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), tmpcap),
10705
			  p->novideo ? "True" : "False", p->notext ? "True" : "False");
10895
			  p->novideo ? "True" : "False", p->notext ? "True" : "False");
10706
		ast_debug(1, "** Our prefcodec: %s \n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), p->prefcodec));
10896
		ast_debug(1, "** Our prefcodec: %s \n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), p->prefcaps));

    
   
10897

   

    
   
10898
		if (doing_directmedia) {

    
   
10899
			ast_format_cap_joint_copy(p->jointcaps, p->redircaps, tmpcap);

    
   
10900
			ast_debug(1, "** Our native-bridge filtered capablity: %s\n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), tmpcap));

    
   
10901
		}
10707

    
   
10902

   
10708
		/* Check if we need audio */
10903
		/* Check if we need audio */
10709
		if (capability & AST_FORMAT_AUDIO_MASK)
10904
		if (ast_format_cap_has_type(tmpcap, AST_FORMAT_TYPE_AUDIO))
10710
			needaudio = TRUE;
10905
			needaudio = TRUE;
10711

    
   
10906

   
10712
		if (debug) {
10907
		if (debug) {
10713
			ast_verbose("Audio is at %s\n", ast_sockaddr_stringify_port(&p->ourip));
10908
			ast_verbose("Audio is at %s\n", ast_sockaddr_stringify_port(&p->ourip));
10714
		}
10909
		}
[+20] [20] 11 lines
[+20] static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int oldsdp, int add_audio, int add_t38)
10726
			if (debug) {
10921
			if (debug) {
10727
				ast_verbose("Video is at %s\n", ast_sockaddr_stringify(&p->ourip));
10922
				ast_verbose("Video is at %s\n", ast_sockaddr_stringify(&p->ourip));
10728
			}
10923
			}
10729
		}
10924
		}
10730

    
   
10925

   
10731
		/* Ok, we need text. Let's add what we need for text and set codecs.
10926
		/* Ok, we need text. Let's add what we need for text and set codecs.
10732
		   Text is handled differently than audio since we can not transcode. */
10927
		   Text is handled differently than audio since we can not transcode. */
10733
		if (needtext) {
10928
		if (needtext) {
10734
			if (sipdebug_text)
10929
			if (sipdebug_text)
10735
				ast_verbose("Lets set up the text sdp\n");
10930
				ast_verbose("Lets set up the text sdp\n");
10736
			get_crypto_attrib(p->tsrtp, &t_a_crypto);
10931
			get_crypto_attrib(p->tsrtp, &t_a_crypto);
10737
			ast_str_append(&m_text, 0, "m=text %d RTP/%s", ast_sockaddr_port(&tdest),
10932
			ast_str_append(&m_text, 0, "m=text %d RTP/%s", ast_sockaddr_port(&tdest),
10738
				t_a_crypto ? "SAVP" : "AVP");
10933
				t_a_crypto ? "SAVP" : "AVP");
10739
			if (debug) {  /* XXX should I use tdest below ? */
10934
			if (debug) {  /* XXX should I use tdest below ? */
10740
				ast_verbose("Text is at %s\n", ast_sockaddr_stringify(&p->ourip));
10935
				ast_verbose("Text is at %s\n", ast_sockaddr_stringify(&p->ourip));
10741
			}
10936
			}
10742
		}
10937
		}
10743

    
   
10938

   
10744
		/* Start building generic SDP headers */
10939
		/* Start building generic SDP headers */
10745

    
   
10940

   
10746
		/* We break with the "recommendation" and send our IP, in order that our
10941
		/* We break with the "recommendation" and send our IP, in order that our
10747
		   peer doesn't have to ast_gethostbyname() us */
10942
		   peer doesn't have to ast_gethostbyname() us */
10748

    
   
10943

   
10749
		get_crypto_attrib(p->srtp, &a_crypto);
10944
		get_crypto_attrib(p->srtp, &a_crypto);
10750
		ast_str_append(&m_audio, 0, "m=audio %d RTP/%s", ast_sockaddr_port(&dest),
10945
		ast_str_append(&m_audio, 0, "m=audio %d RTP/%s", ast_sockaddr_port(&dest),
10751
			a_crypto ? "SAVP" : "AVP");
10946
			a_crypto ? "SAVP" : "AVP");
10752

    
   
10947

   
10753
		if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) == SIP_PAGE2_CALL_ONHOLD_ONEDIR)

   
10754
			hold = "a=recvonly\r\n";

   
10755
		else if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) == SIP_PAGE2_CALL_ONHOLD_INACTIVE)

   
10756
			hold = "a=inactive\r\n";

   
10757
		else

   
10758
			hold = "a=sendrecv\r\n";

   
10759

    
   

   
10760
		/* Now, start adding audio codecs. These are added in this order:
10948
		/* Now, start adding audio codecs. These are added in this order:
10761
		   - First what was requested by the calling channel
10949
		   - First what was requested by the calling channel
10762
		   - Then preferences in order from sip.conf device config for this peer/user
10950
		   - Then preferences in order from sip.conf device config for this peer/user
10763
		   - Then other codecs in capabilities, including video
10951
		   - Then other codecs in capabilities, including video
10764
		*/
10952
		*/
10765

    
   
10953

   
10766
		/* Prefer the audio codec we were requested to use, first, no matter what
10954
		/* Prefer the audio codec we were requested to use, first, no matter what
10767
		   Note that p->prefcodec can include video codecs, so mask them out
10955
		   Note that p->prefcodec can include video codecs, so mask them out
10768
		*/
10956
		*/
10769
		if (capability & p->prefcodec) {
10957
		if (ast_format_cap_has_joint(tmpcap, p->prefcaps)) {
10770
			format_t codec = p->prefcodec & AST_FORMAT_AUDIO_MASK;
10958
			ast_format_cap_iter_start(p->prefcaps);
10771

    
   
10959
			while (!(ast_format_cap_iter_next(p->prefcaps, &tmp_fmt))) {
10772
			add_codec_to_sdp(p, codec, &m_audio, &a_audio, debug, &min_audio_packet_size);
10960
				if (AST_FORMAT_GET_TYPE(tmp_fmt.id) != AST_FORMAT_TYPE_AUDIO) {
10773
			alreadysent |= codec;
10961
					continue;

    
   
10962
				}

    
   
10963
				add_codec_to_sdp(p, &tmp_fmt, &m_audio, &a_audio, debug, &min_audio_packet_size);

    
   
10964
				ast_format_cap_add(alreadysent, &tmp_fmt);

    
   
10965
			}

    
   
10966
			ast_format_cap_iter_end(p->prefcaps);
10774
		}
10967
		}
10775

    
   
10968

   
10776
		/* Start by sending our preferred audio/video codecs */
10969
		/* Start by sending our preferred audio/video codecs */
10777
		for (x = 0; x < 64; x++) {
10970
		for (x = 0; x < AST_CODEC_PREF_SIZE; x++) {
10778
			format_t codec;
10971
			if (!(ast_codec_pref_index(&p->prefs, x, &tmp_fmt)))
10779

    
   

   
10780
			if (!(codec = ast_codec_pref_index(&p->prefs, x)))

   
10781
				break;
10972
				break;
10782

    
   
10973

   
10783
			if (!(capability & codec))
10974
			if (!(ast_format_cap_iscompatible(tmpcap, &tmp_fmt)))
10784
				continue;
10975
				continue;
10785

    
   
10976

   
10786
			if (alreadysent & codec)
10977
			if (ast_format_cap_iscompatible(alreadysent, &tmp_fmt))
10787
				continue;
10978
				continue;
10788

    
   
10979

   
10789
			add_codec_to_sdp(p, codec, &m_audio, &a_audio, debug, &min_audio_packet_size);
10980
			if (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_AUDIO) {
10790
			alreadysent |= codec;
10981
				add_codec_to_sdp(p, &tmp_fmt, &m_audio, &a_audio, debug, &min_audio_packet_size);

    
   
10982
			} else if (needvideo && (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_VIDEO)) {

    
   
10983
				add_vcodec_to_sdp(p, &tmp_fmt, &m_video, &a_video, debug, &min_video_packet_size);

    
   
10984
			} else if (needtext && (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_TEXT)) {

    
   
10985
				add_tcodec_to_sdp(p, &tmp_fmt, &m_text, &a_text, debug, &min_text_packet_size);
10791
		}
10986
			}
10792

    
   
10987

   
10793
		/* Now send any other common audio and video codecs, and non-codec formats: */
10988
			ast_format_cap_add(alreadysent, &tmp_fmt);
10794
		for (x = 1ULL; x <= (needtext ? AST_FORMAT_TEXT_MASK : (needvideo ? AST_FORMAT_VIDEO_MASK : AST_FORMAT_AUDIO_MASK)); x <<= 1) {
10989
		}
10795
			if (!(capability & x))	/* Codec not requested */

   
10796
				continue;

   
10797

    
   
10990

   
10798
			if (alreadysent & x)	/* Already added to SDP */
10991
		/* Now send any other common audio and video codecs, and non-codec formats: */

    
   
10992
		ast_format_cap_iter_start(tmpcap);

    
   
10993
		while (!(ast_format_cap_iter_next(tmpcap, &tmp_fmt))) {

    
   
10994
			if (ast_format_cap_iscompatible(alreadysent, &tmp_fmt))
10799
				continue;
10995
				continue;
10800

    
   
10996

   
10801
			if (x & AST_FORMAT_AUDIO_MASK)
10997
			if (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_AUDIO) {
10802
				add_codec_to_sdp(p, x, &m_audio, &a_audio, debug, &min_audio_packet_size);
10998
				add_codec_to_sdp(p, &tmp_fmt, &m_audio, &a_audio, debug, &min_audio_packet_size);
10803
			else if (x & AST_FORMAT_VIDEO_MASK)
10999
			} else if (needvideo && (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_VIDEO)) {
10804
				add_vcodec_to_sdp(p, x, &m_video, &a_video, debug, &min_video_packet_size);
11000
				add_vcodec_to_sdp(p, &tmp_fmt, &m_video, &a_video, debug, &min_video_packet_size);
10805
			else if (x & AST_FORMAT_TEXT_MASK)
11001
			} else if (needtext && (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_TEXT)) {
10806
				add_tcodec_to_sdp(p, x, &m_text, &a_text, debug, &min_text_packet_size);
11002
				add_tcodec_to_sdp(p, &tmp_fmt, &m_text, &a_text, debug, &min_text_packet_size);

    
   
11003
			}
10807
		}
11004
		}

    
   
11005
		ast_format_cap_iter_end(tmpcap);
10808

    
   
11006

   
10809
		/* Now add DTMF RFC2833 telephony-event as a codec */
11007
		/* Now add DTMF RFC2833 telephony-event as a codec */
10810
		for (x = 1LL; x <= AST_RTP_MAX; x <<= 1) {
11008
		for (x = 1LL; x <= AST_RTP_MAX; x <<= 1) {
10811
			if (!(p->jointnoncodeccapability & x))
11009
			if (!(p->jointnoncodeccapability & x))
10812
				continue;
11010
				continue;
[+20] [20] 142 lines
[+20] static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int oldsdp, int add_audio, int add_t38)
10955

    
   
11153

   
10956
	/* we unlink this dialog and link again into the dialogs_rtpcheck container to doesnt add it twice */
11154
	/* we unlink this dialog and link again into the dialogs_rtpcheck container to doesnt add it twice */
10957
	ao2_t_unlink(dialogs_rtpcheck, p, "unlink pvt into dialogs_rtpcheck container");
11155
	ao2_t_unlink(dialogs_rtpcheck, p, "unlink pvt into dialogs_rtpcheck container");
10958
	ao2_t_link(dialogs_rtpcheck, p, "link pvt into dialogs_rtpcheck container");
11156
	ao2_t_link(dialogs_rtpcheck, p, "link pvt into dialogs_rtpcheck container");
10959

    
   
11157

   
10960
	ast_debug(3, "Done building SDP. Settling with this capability: %s\n", ast_getformatname_multiple(buf, SIPBUFSIZE, capability));
11158
	ast_debug(3, "Done building SDP. Settling with this capability: %s\n", ast_getformatname_multiple(buf, SIPBUFSIZE, tmpcap));
10961

    
   
11159

   
10962
	return AST_SUCCESS;
11160
add_sdp_cleanup:

    
   
11161
	alreadysent = ast_format_cap_destroy(alreadysent);

    
   
11162
	tmpcap = ast_format_cap_destroy(tmpcap);

    
   
11163

   

    
   
11164
	return res;
10963
}
11165
}
10964

    
   
11166

   
10965
/*! \brief Used for 200 OK and 183 early media */
11167
/*! \brief Used for 200 OK and 183 early media */
10966
static int transmit_response_with_t38_sdp(struct sip_pvt *p, char *msg, struct sip_request *req, int retrans)
11168
static int transmit_response_with_t38_sdp(struct sip_pvt *p, char *msg, struct sip_request *req, int retrans)
10967
{
11169
{
10968
	struct sip_request resp;
11170
	struct sip_request resp;
10969
	int seqno;
11171
	int seqno;
10970
	
11172

   
10971
	if (sscanf(get_header(req, "CSeq"), "%30d ", &seqno) != 1) {
11173
	if (sscanf(get_header(req, "CSeq"), "%30d ", &seqno) != 1) {
10972
		ast_log(LOG_WARNING, "Unable to get seqno from '%s'\n", get_header(req, "CSeq"));
11174
		ast_log(LOG_WARNING, "Unable to get seqno from '%s'\n", get_header(req, "CSeq"));
10973
		return -1;
11175
		return -1;
10974
	}
11176
	}
10975
	respprep(&resp, p, msg, req);
11177
	respprep(&resp, p, msg, req);
[+20] [20] 228 lines
[+20] [+] static void extract_uri(struct sip_pvt *p, struct sip_request *req)
11204
}
11406
}
11205

    
   
11407

   
11206
/*! \brief Build contact header - the contact header we send out */
11408
/*! \brief Build contact header - the contact header we send out */
11207
static void build_contact(struct sip_pvt *p)
11409
static void build_contact(struct sip_pvt *p)
11208
{
11410
{

    
   
11411
	char tmp[SIPBUFSIZE];

    
   
11412
	char *user = ast_uri_encode(p->exten, tmp, sizeof(tmp), ast_uri_sip_user);

    
   
11413

   
11209
	if (p->socket.type == SIP_TRANSPORT_UDP) {
11414
	if (p->socket.type == SIP_TRANSPORT_UDP) {
11210
		ast_string_field_build(p, our_contact, "<sip:%s%s%s>", p->exten,
11415
		ast_string_field_build(p, our_contact, "<sip:%s%s%s>", user,
11211
			ast_strlen_zero(p->exten) ? "" : "@", ast_sockaddr_stringify(&p->ourip));
11416
			ast_strlen_zero(user) ? "" : "@", ast_sockaddr_stringify(&p->ourip));
11212
	} else {
11417
	} else {
11213
		ast_string_field_build(p, our_contact, "<sip:%s%s%s;transport=%s>", p->exten,
11418
		ast_string_field_build(p, our_contact, "<sip:%s%s%s;transport=%s>", user,
11214
			ast_strlen_zero(p->exten) ? "" : "@", ast_sockaddr_stringify(&p->ourip),
11419
			ast_strlen_zero(user) ? "" : "@", ast_sockaddr_stringify(&p->ourip),
11215
			get_transport(p->socket.type));
11420
			get_transport(p->socket.type));
11216
	}
11421
	}
11217
}
11422
}
11218

    
   
11423

   
11219
/*! \brief Initiate new SIP request to peer/user */
11424
/*! \brief Initiate new SIP request to peer/user */
[+20] [20] 70 lines
[+20] [+] static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, const char * const explicit_uri)
11290
		n = p->fromname;
11495
		n = p->fromname;
11291
	else /* Save for any further attempts */
11496
	else /* Save for any further attempts */
11292
		ast_string_field_set(p, fromname, n);
11497
		ast_string_field_set(p, fromname, n);
11293

    
   
11498

   
11294
	if (sip_cfg.pedanticsipchecking) {
11499
	if (sip_cfg.pedanticsipchecking) {
11295
		ast_uri_encode(n, tmp_n, sizeof(tmp_n), 0);
11500
		ast_escape_quoted(n, tmp_n, sizeof(tmp_n));
11296
		n = tmp_n;
11501
		n = tmp_n;
11297
		ast_uri_encode(l, tmp_l, sizeof(tmp_l), 0);
11502
		ast_uri_encode(l, tmp_l, sizeof(tmp_l), ast_uri_sip_user);
11298
		l = tmp_l;
11503
		l = tmp_l;
11299
	}
11504
	}
11300

    
   
11505

   
11301
	ourport = (p->fromdomainport) ? p->fromdomainport : ast_sockaddr_port(&p->ourip);
11506
	ourport = (p->fromdomainport) ? p->fromdomainport : ast_sockaddr_port(&p->ourip);
11302
	if (!sip_standard_port(p->socket.type, ourport)) {
11507
	if (!sip_standard_port(p->socket.type, ourport)) {
[+20] [20] 13 lines
[+20] static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, const char * const explicit_uri)
11316
			/* Otherwise, use the username while waiting for registration */
11521
			/* Otherwise, use the username while waiting for registration */
11317
			ast_str_append(&invite, 0, "sip:");
11522
			ast_str_append(&invite, 0, "sip:");
11318
			if (!ast_strlen_zero(p->username)) {
11523
			if (!ast_strlen_zero(p->username)) {
11319
				n = p->username;
11524
				n = p->username;
11320
				if (sip_cfg.pedanticsipchecking) {
11525
				if (sip_cfg.pedanticsipchecking) {
11321
					ast_uri_encode(n, tmp_n, sizeof(tmp_n), 0);
11526
					ast_uri_encode(n, tmp_n, sizeof(tmp_n), ast_uri_sip_user);
11322
					n = tmp_n;
11527
					n = tmp_n;
11323
				}
11528
				}
11324
				ast_str_append(&invite, 0, "%s@", n);
11529
				ast_str_append(&invite, 0, "%s@", n);
11325
			}
11530
			}
11326
			ast_str_append(&invite, 0, "%s", p->tohost);
11531
			ast_str_append(&invite, 0, "%s", p->tohost);
[+20] [20] 240 lines
[+20] [+] static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init, const char * const explicit_uri)
11567
					}
11772
					}
11568
					if ((content = strchr(headdup, ':'))) {
11773
					if ((content = strchr(headdup, ':'))) {
11569
						*content++ = '\0';
11774
						*content++ = '\0';
11570
						content = ast_skip_blanks(content); /* Skip white space */
11775
						content = ast_skip_blanks(content); /* Skip white space */
11571
						/* Strip the ending " (if it's there) */
11776
						/* Strip the ending " (if it's there) */
11572
				 		end = content + strlen(content) -1;	
11777
						end = content + strlen(content) -1;
11573
						if (*end == '"') {
11778
						if (*end == '"') {
11574
							*end = '\0';
11779
							*end = '\0';
11575
						}
11780
						}
11576
					
11781

   
11577
						add_header(&req, headdup, content);
11782
						add_header(&req, headdup, content);
11578
						if (sipdebug) {
11783
						if (sipdebug) {
11579
							ast_debug(1, "Adding SIP Header \"%s\" with content :%s: \n", headdup, content);
11784
							ast_debug(1, "Adding SIP Header \"%s\" with content :%s: \n", headdup, content);
11580
						}
11785
						}
11581
					}
11786
					}
[+20] [20] 981 lines
[+20] [+] static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader)
12563
	add_header(&req, "Call-ID", p->callid);
12768
	add_header(&req, "Call-ID", p->callid);
12564
	add_header(&req, "CSeq", tmp);
12769
	add_header(&req, "CSeq", tmp);
12565
	if (!ast_strlen_zero(global_useragent))
12770
	if (!ast_strlen_zero(global_useragent))
12566
		add_header(&req, "User-Agent", global_useragent);
12771
		add_header(&req, "User-Agent", global_useragent);
12567

    
   
12772

   
12568
	if (auth) { 	/* Add auth header */
12773
	if (auth) {	/* Add auth header */
12569
		add_header(&req, authheader, auth);
12774
		add_header(&req, authheader, auth);
12570
	} else if (!ast_strlen_zero(r->nonce)) {
12775
	} else if (!ast_strlen_zero(r->nonce)) {
12571
		char digest[1024];
12776
		char digest[1024];
12572

    
   
12777

   
12573
		/* We have auth data to reuse, build a digest header.
12778
		/* We have auth data to reuse, build a digest header.
[+20] [20] 34 lines
[+20] static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader)
12608
	dialog_unref(p, "p is finished here at the end of transmit_register");
12813
	dialog_unref(p, "p is finished here at the end of transmit_register");
12609
	return res;
12814
	return res;
12610
}
12815
}
12611

    
   
12816

   
12612
/*! \brief Transmit text with SIP MESSAGE method */
12817
/*! \brief Transmit text with SIP MESSAGE method */
12613
static int transmit_message_with_text(struct sip_pvt *p, const char *text, int init)
12818
static int transmit_message_with_text(struct sip_pvt *p, const char *text, int init, int auth)
12614
{
12819
{
12615
	struct sip_request req;
12820
	struct sip_request req;
12616

    
   
12821

   
12617
	if (init) {
12822
	if (init) {
12618
		initreqprep(&req, p, SIP_MESSAGE, NULL);
12823
		initreqprep(&req, p, SIP_MESSAGE, NULL);

    
   
12824
		ast_string_field_set(p, msg_body, text);

    
   
12825
		initialize_initreq(p, &req);
12619
	} else {
12826
	} else {
12620
		reqprep(&req, p, SIP_MESSAGE, 0, 1);
12827
		reqprep(&req, p, SIP_MESSAGE, 0, 1);
12621
	}
12828
	}

    
   
12829
	if (auth) {

    
   
12830
		return transmit_request_with_auth(p, SIP_MESSAGE, p->ocseq, XMIT_RELIABLE, 0);

    
   
12831
	} else {
12622
	add_text(&req, text);
12832
		add_text(&req, text);
12623
	return send_request(p, &req, XMIT_RELIABLE, p->ocseq);
12833
		return send_request(p, &req, XMIT_RELIABLE, p->ocseq);
12624
}
12834
	}

    
   
12835
}
12625

    
   
12836

   
12626
/*! \brief Allocate SIP refer structure */
12837
/*! \brief Allocate SIP refer structure */
12627
static int sip_refer_allocate(struct sip_pvt *p)
12838
static int sip_refer_allocate(struct sip_pvt *p)
12628
{
12839
{
12629
	p->refer = ast_calloc(1, sizeof(struct sip_refer));
12840
	p->refer = ast_calloc(1, sizeof(struct sip_refer));
[+20] [20] 16 lines
[+20] [+] static int sip_notify_allocate(struct sip_pvt *p)
12646
	\todo Fix the transfer() dialplan function so that a transfer may fail
12857
	\todo Fix the transfer() dialplan function so that a transfer may fail
12647
*/
12858
*/
12648
static int transmit_refer(struct sip_pvt *p, const char *dest)
12859
static int transmit_refer(struct sip_pvt *p, const char *dest)
12649
{
12860
{
12650
	struct sip_request req = {
12861
	struct sip_request req = {
12651
		.headers = 0,	
12862
		.headers = 0,
12652
	};
12863
	};
12653
	char from[256];
12864
	char from[256];
12654
	const char *of;
12865
	const char *of;
12655
	char *c;
12866
	char *c;
12656
	char referto[256];
12867
	char referto[256];
[+20] [20] 200 lines
[+20] [+] static int transmit_request_with_auth(struct sip_pvt *p, int sipmethod, int seqno, enum xmittype reliable, int newbranch)
12857
		add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->hangupcause));
13068
		add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->hangupcause));
12858
		snprintf(buf, sizeof(buf), "%d", p->hangupcause);
13069
		snprintf(buf, sizeof(buf), "%d", p->hangupcause);
12859
		add_header(&resp, "X-Asterisk-HangupCauseCode", buf);
13070
		add_header(&resp, "X-Asterisk-HangupCauseCode", buf);
12860
	}
13071
	}
12861

    
   
13072

   

    
   
13073
	if (sipmethod == SIP_MESSAGE) {

    
   
13074
		add_text(&resp, p->msg_body);

    
   
13075
	}

    
   
13076

   
12862
	return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq);	
13077
	return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq);	
12863
}
13078
}
12864

    
   
13079

   
12865
/*! \brief Remove registration data from realtime database or AST/DB when registration expires */
13080
/*! \brief Remove registration data from realtime database or AST/DB when registration expires */
12866
static void destroy_association(struct sip_peer *peer)
13081
static void destroy_association(struct sip_peer *peer)
[+20] [20] 248 lines
[+20] [+] static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, struct sip_peer *peer, struct sip_request *req)
13115
	int expire = atoi(expires);
13330
	int expire = atoi(expires);
13116
	char *curi, *domain, *transport;
13331
	char *curi, *domain, *transport;
13117
	int transport_type;
13332
	int transport_type;
13118
	const char *useragent;
13333
	const char *useragent;
13119
	struct ast_sockaddr oldsin, testsa;
13334
	struct ast_sockaddr oldsin, testsa;

    
   
13335
	char *firstcuri = NULL;

    
   
13336
	int start = 0;

    
   
13337
	int wildcard_found = 0;

    
   
13338
	int single_binding_found = 0;
13120

    
   
13339

   
13121
	ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact));
13340
	ast_copy_string(contact, __get_header(req, "Contact", &start), sizeof(contact));
13122

    
   
13341

   
13123
	if (ast_strlen_zero(expires)) {	/* No expires header, try look in Contact: */
13342
	if (ast_strlen_zero(expires)) {	/* No expires header, try look in Contact: */
13124
		char *s = strcasestr(contact, ";expires=");
13343
		char *s = strcasestr(contact, ";expires=");
13125
		if (s) {
13344
		if (s) {
13126
			expires = strsep(&s, ";"); /* trim ; and beyond */
13345
			expires = strsep(&s, ";"); /* trim ; and beyond */
[+20] [20] 6 lines
[+20] static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, struct sip_peer *peer, struct sip_request *req)
13133
		}
13352
		}
13134
	}
13353
	}
13135

    
   
13354

   
13136
	copy_socket_data(&pvt->socket, &req->socket);
13355
	copy_socket_data(&pvt->socket, &req->socket);
13137

    
   
13356

   

    
   
13357
	do {
13138
	/* Look for brackets */
13358
		/* Look for brackets */
13139
	curi = contact;
13359
		curi = contact;
13140
	if (strchr(contact, '<') == NULL)	/* No <, check for ; and strip it */
13360
		if (strchr(contact, '<') == NULL)	/* No <, check for ; and strip it */
13141
		strsep(&curi, ";");	/* This is Header options, not URI options */
13361
			strsep(&curi, ";");	/* This is Header options, not URI options */
13142
	curi = get_in_brackets(contact);
13362
		curi = get_in_brackets(contact);

    
   
13363
		if (!firstcuri) {

    
   
13364
			firstcuri = ast_strdupa(curi);

    
   
13365
		}

    
   
13366

   

    
   
13367
		if (!strcasecmp(curi, "*")) {

    
   
13368
			wildcard_found = 1;

    
   
13369
		} else {

    
   
13370
			single_binding_found = 1;

    
   
13371
		}

    
   
13372

   

    
   
13373
		if (wildcard_found && (ast_strlen_zero(expires) || expire != 0 || single_binding_found)) {

    
   
13374
			/* Contact header parameter "*" detected, so punt if: Expires header is missing,

    
   
13375
			 * Expires value is not zero, or another Contact header is present. */

    
   
13376
			return PARSE_REGISTER_FAILED;

    
   
13377
		}

    
   
13378

   

    
   
13379
		ast_copy_string(contact, __get_header(req, "Contact", &start), sizeof(contact));

    
   
13380
	} while (!ast_strlen_zero(contact));

    
   
13381
	curi = firstcuri;
13143

    
   
13382

   
13144
	/* if they did not specify Contact: or Expires:, they are querying
13383
	/* if they did not specify Contact: or Expires:, they are querying
13145
	   what we currently have stored as their contact address, so return
13384
	   what we currently have stored as their contact address, so return
13146
	   it
13385
	   it
13147
	*/
13386
	*/
[+20] [20] 203 lines
[+20] [+] static void build_route(struct sip_pvt *p, struct sip_request *req, int backwards)
13351
		p->route = NULL;
13590
		p->route = NULL;
13352
	}
13591
	}
13353

    
   
13592

   
13354
	/* We only want to create the route set the first time this is called */
13593
	/* We only want to create the route set the first time this is called */
13355
	p->route_persistent = 1;
13594
	p->route_persistent = 1;
13356
	
13595

   
13357
	/* Build a tailq, then assign it to p->route when done.
13596
	/* Build a tailq, then assign it to p->route when done.
13358
	 * If backwards, we add entries from the head so they end up
13597
	 * If backwards, we add entries from the head so they end up
13359
	 * in reverse order. However, we do need to maintain a correct
13598
	 * in reverse order. However, we do need to maintain a correct
13360
	 * tail pointer because the contact is always at the end.
13599
	 * tail pointer because the contact is always at the end.
13361
	 */
13600
	 */
[+20] [20] 1154 lines
[+20] [+] static enum sip_get_dest_result get_destination(struct sip_pvt *p, struct sip_request *oreq, int *cc_recall_core_id)
14516
	}
14755
	}
14517

    
   
14756

   
14518
	/* Since extensions.conf can have unescaped characters, try matching a
14757
	/* Since extensions.conf can have unescaped characters, try matching a
14519
	 * decoded uri in addition to the non-decoded uri. */
14758
	 * decoded uri in addition to the non-decoded uri. */
14520
	decoded_uri = ast_strdupa(uri);
14759
	decoded_uri = ast_strdupa(uri);
14521
	ast_uri_decode(decoded_uri);
14760
	ast_uri_decode(decoded_uri, ast_uri_sip_user);
14522

    
   
14761

   
14523
	/* If this is a subscription we actually just need to see if a hint exists for the extension */
14762
	/* If this is a subscription we actually just need to see if a hint exists for the extension */
14524
	if (req->method == SIP_SUBSCRIBE) {
14763
	if (req->method == SIP_SUBSCRIBE) {
14525
		char hint[AST_MAX_EXTENSION];
14764
		char hint[AST_MAX_EXTENSION];
14526
		int which = 0;
14765
		int which = 0;
[+20] [20] 61 lines
[+20] [+] static struct sip_pvt *get_sip_pvt_byid_locked(const char *callid, const char *totag, const char *fromtag)
14588
	if (totag) {
14827
	if (totag) {
14589
		ast_debug(4, "Looking for callid %s (fromtag %s totag %s)\n", callid, fromtag ? fromtag : "<no fromtag>", totag ? totag : "<no totag>");
14828
		ast_debug(4, "Looking for callid %s (fromtag %s totag %s)\n", callid, fromtag ? fromtag : "<no fromtag>", totag ? totag : "<no totag>");
14590
	}
14829
	}
14591

    
   
14830

   
14592
	/* Search dialogs and find the match */
14831
	/* Search dialogs and find the match */
14593
	
14832

   
14594
	sip_pvt_ptr = ao2_t_find(dialogs, &tmp_dialog, OBJ_POINTER, "ao2_find of dialog in dialogs table");
14833
	sip_pvt_ptr = ao2_t_find(dialogs, &tmp_dialog, OBJ_POINTER, "ao2_find of dialog in dialogs table");
14595
	if (sip_pvt_ptr) {
14834
	if (sip_pvt_ptr) {
14596
		/* Go ahead and lock it (and its owner) before returning */
14835
		/* Go ahead and lock it (and its owner) before returning */
14597
		sip_pvt_lock(sip_pvt_ptr);
14836
		sip_pvt_lock(sip_pvt_ptr);
14598
		if (sip_cfg.pedanticsipchecking) {
14837
		if (sip_cfg.pedanticsipchecking) {
[+20] [20] 42 lines
[+20] static struct sip_pvt *get_sip_pvt_byid_locked(const char *callid, const char *totag, const char *fromtag)
14641
						  totag, sip_pvt_ptr->tag);
14880
						  totag, sip_pvt_ptr->tag);
14642
				}
14881
				}
14643
				return NULL;
14882
				return NULL;
14644
			}
14883
			}
14645
		}
14884
		}
14646
		
14885

   
14647
		if (totag)
14886
		if (totag)
14648
			ast_debug(4, "Matched %s call - their tag is %s Our tag is %s\n",
14887
			ast_debug(4, "Matched %s call - their tag is %s Our tag is %s\n",
14649
					  sip_pvt_ptr->outgoing_call == TRUE ? "OUTGOING": "INCOMING",
14888
					  sip_pvt_ptr->outgoing_call == TRUE ? "OUTGOING": "INCOMING",
14650
					  sip_pvt_ptr->theirtag, sip_pvt_ptr->tag);
14889
					  sip_pvt_ptr->theirtag, sip_pvt_ptr->tag);
14651

    
   
14890

   
14652
		/* deadlock avoidance... */
14891
		/* deadlock avoidance... */
14653
		while (sip_pvt_ptr->owner && ast_channel_trylock(sip_pvt_ptr->owner)) {
14892
		while (sip_pvt_ptr->owner && ast_channel_trylock(sip_pvt_ptr->owner)) {
14654
			sip_pvt_unlock(sip_pvt_ptr);
14893
			sip_pvt_unlock(sip_pvt_ptr);
14655
			usleep(1);
14894
			usleep(1);
14656
			sip_pvt_lock(sip_pvt_ptr);
14895
			sip_pvt_lock(sip_pvt_ptr);
14657
		}
14896
		}
14658
	}

   
14659
	

   
14660
	return sip_pvt_ptr;

   
14661
}

   
14662

    
   

   
14663
/*! \brief Call transfer support (the REFER method)
Moved to 14902

   
14664
 * 	Extracts Refer headers into pvt dialog structure
Moved to 14903

   
14665
 *
Moved to 14904

   
14666
 * \note If we get a SIPS uri in the refer-to header, we're required to set up a secure signalling path
Moved to 14905

   
14667
 *	to that extension. As a minimum, this needs to be added to a channel variable, if not a channel
Moved to 14906

   
14668
 *	flag.
Moved to 14907

   
14669
 */
Moved to 14908

   
14670
static int get_refer_info(struct sip_pvt *transferer, struct sip_request *outgoing_req)
Moved to 14909

   
14671
{
Moved to 14910

   
14672

    
   

   
14673
	const char *p_referred_by = NULL;
Moved to 14912

   
14674
	char *h_refer_to = NULL;
Moved to 14913

   
14675
	char *h_referred_by = NULL;
Moved to 14914

   
14676
	char *refer_to;
Moved to 14915

   
14677
	const char *p_refer_to;
Moved to 14916

   
14678
	char *referred_by_uri = NULL;
Moved to 14917

   
14679
	char *ptr;
Moved to 14918

   
14680
	struct sip_request *req = NULL;
Moved to 14919

   
14681
	const char *transfer_context = NULL;
Moved to 14920

   
14682
	struct sip_refer *referdata;
Moved to 14921

   
14683

    
   

   
14684

    
   

   
14685
	req = outgoing_req;
Moved to 14924

   
14686
	referdata = transferer->refer;
Moved to 14925

   
14687

    
   

   
14688
	if (!req) {

   
14689
		req = &transferer->initreq;

   
14690
	}

   
14691

    
   

   
14692
	p_refer_to = get_header(req, "Refer-To");

   
14693
	if (ast_strlen_zero(p_refer_to)) {

   
14694
		ast_log(LOG_WARNING, "Refer-To Header missing. Skipping transfer.\n");

   
14695
		return -2;	/* Syntax error */

   
14696
	}

   
14697
	h_refer_to = ast_strdupa(p_refer_to);

   
14698
	refer_to = get_in_brackets(h_refer_to);

   
14699
	if (!strncasecmp(refer_to, "sip:", 4)) {

   
14700
		refer_to += 4;			/* Skip sip: */

   
14701
	} else if (!strncasecmp(refer_to, "sips:", 5)) {

   
14702
		refer_to += 5;

   
14703
	} else {

   
14704
		ast_log(LOG_WARNING, "Can't transfer to non-sip: URI.  (Refer-to: %s)?\n", refer_to);

   
14705
		return -3;

   
14706
	}

   
14707

    
   

   
14708
	/* Get referred by header if it exists */
Moved to 14947

   
14709
	p_referred_by = get_header(req, "Referred-By");
Moved to 14948

   
14710

    
   

   
14711
	/* Give useful transfer information to the dialplan */

   
14712
	if (transferer->owner) {

   
14713
		struct ast_channel *peer = ast_bridged_channel(transferer->owner);

   
14714
		if (peer) {

   
14715
			pbx_builtin_setvar_helper(peer, "SIPREFERRINGCONTEXT", transferer->context);

   
14716
			pbx_builtin_setvar_helper(peer, "SIPREFERREDBYHDR", p_referred_by);

   
14717
		}

   
14718
	}

   
14719

    
   

   
14720
	if (!ast_strlen_zero(p_referred_by)) {
Moved to 14959

   
14721
		char *lessthan;
Moved to 14960

   
14722
		h_referred_by = ast_strdupa(p_referred_by);
Moved to 14961

   
14723

    
   

   
14724
		/* Store referrer's caller ID name */

   
14725
		ast_copy_string(referdata->referred_by_name, h_referred_by, sizeof(referdata->referred_by_name));

   
14726
		if ((lessthan = strchr(referdata->referred_by_name, '<'))) {

   
14727
			*(lessthan - 1) = '\0';	/* Space */

   
14728
		}

   
14729

    
   

   
14730
		referred_by_uri = get_in_brackets(h_referred_by);

   
14731

    
   

   
14732
		if (!strncasecmp(referred_by_uri, "sip:", 4)) {

   
14733
			referred_by_uri += 4;		/* Skip sip: */

   
14734
		} else if (!strncasecmp(referred_by_uri, "sips:", 5)) {

   
14735
			referred_by_uri += 5;		/* Skip sips: */

   
14736
		} else {

   
14737
			ast_log(LOG_WARNING, "Huh?  Not a sip: header (Referred-by: %s). Skipping.\n", referred_by_uri);

   
14738
			referred_by_uri = NULL;

   
14739
		}

   
14740
	}

   
14741

    
   

   
14742
	/* Check for arguments in the refer_to header */
Moved to 14981

   
14743
	if ((ptr = strcasestr(refer_to, "replaces="))) {
Moved to 14982

   
14744
		char *to = NULL, *from = NULL;
Moved to 14983

   
14745
		

   
14746
		/* This is an attended transfer */
Moved to 14985

   
14747
		referdata->attendedtransfer = 1;
Moved to 14986

   
14748
		ast_copy_string(referdata->replaces_callid, ptr+9, sizeof(referdata->replaces_callid));
Moved to 14987

   
14749
		ast_uri_decode(referdata->replaces_callid);

   
14750
		if ((ptr = strchr(referdata->replaces_callid, ';'))) 	/* Find options */ {

   
14751
			*ptr++ = '\0';

   
14752
		}

   
14753
		

   
14754
		if (ptr) {

   
14755
			/* Find the different tags before we destroy the string */

   
14756
			to = strcasestr(ptr, "to-tag=");

   
14757
			from = strcasestr(ptr, "from-tag=");

   
14758
		}

   
14759
		

   
14760
		/* Grab the to header */

   
14761
		if (to) {

   
14762
			ptr = to + 7;

   
14763
			if ((to = strchr(ptr, '&'))) {

   
14764
				*to = '\0';

   
14765
			}

   
14766
			if ((to = strchr(ptr, ';'))) {

   
14767
				*to = '\0';

   
14768
			}

   
14769
			ast_copy_string(referdata->replaces_callid_totag, ptr, sizeof(referdata->replaces_callid_totag));

   
14770
		}

   
14771
		

   
14772
		if (from) {

   
14773
			ptr = from + 9;

   
14774
			if ((to = strchr(ptr, '&'))) {

   
14775
				*to = '\0';

   
14776
			}

   
14777
			if ((to = strchr(ptr, ';'))) {

   
14778
				*to = '\0';

   
14779
			}

   
14780
			ast_copy_string(referdata->replaces_callid_fromtag, ptr, sizeof(referdata->replaces_callid_fromtag));

   
14781
		}

   
14782
		

   
14783
		if (!sip_cfg.pedanticsipchecking) {

   
14784
			ast_debug(2, "Attended transfer: Will use Replace-Call-ID : %s (No check of from/to tags)\n", referdata->replaces_callid );

   
14785
		} else {

   
14786
			ast_debug(2, "Attended transfer: Will use Replace-Call-ID : %s F-tag: %s T-tag: %s\n", referdata->replaces_callid, referdata->replaces_callid_fromtag ? referdata->replaces_callid_fromtag : "<none>", referdata->replaces_callid_totag ? referdata->replaces_callid_totag : "<none>" );

   
14787
		}

   
14788
	}
14897
	}
14789
	
14898
	
Moved from 14660

    
   
14899
	return sip_pvt_ptr;
Moved from 14661

    
   
14900
}

    
   
14901

   
Moved from 14663

    
   
14902
/*! \brief Call transfer support (the REFER method)
Moved from 14664

    
   
14903
 * 	Extracts Refer headers into pvt dialog structure
Moved from 14665

    
   
14904
 *
Moved from 14666

    
   
14905
 * \note If we get a SIPS uri in the refer-to header, we're required to set up a secure signalling path
Moved from 14667

    
   
14906
 *	to that extension. As a minimum, this needs to be added to a channel variable, if not a channel
Moved from 14668

    
   
14907
 *	flag.
Moved from 14669

    
   
14908
 */
Moved from 14670

    
   
14909
static int get_refer_info(struct sip_pvt *transferer, struct sip_request *outgoing_req)
Moved from 14671

    
   
14910
{

    
   
14911

   
Moved from 14673

    
   
14912
	const char *p_referred_by = NULL;
Moved from 14674

    
   
14913
	char *h_refer_to = NULL;
Moved from 14675

    
   
14914
	char *h_referred_by = NULL;
Moved from 14676

    
   
14915
	char *refer_to;
Moved from 14677

    
   
14916
	const char *p_refer_to;
Moved from 14678

    
   
14917
	char *referred_by_uri = NULL;
Moved from 14679

    
   
14918
	char *ptr;
Moved from 14680

    
   
14919
	struct sip_request *req = NULL;
Moved from 14681

    
   
14920
	const char *transfer_context = NULL;
Moved from 14682

    
   
14921
	struct sip_refer *referdata;

    
   
14922

   

    
   
14923

   
Moved from 14685

    
   
14924
	req = outgoing_req;
Moved from 14686

    
   
14925
	referdata = transferer->refer;

    
   
14926

   
Moved from 14688

    
   
14927
	if (!req) {
Moved from 14689

    
   
14928
		req = &transferer->initreq;
Moved from 14690

    
   
14929
	}

    
   
14930

   
Moved from 14692

    
   
14931
	p_refer_to = get_header(req, "Refer-To");
Moved from 14693

    
   
14932
	if (ast_strlen_zero(p_refer_to)) {
Moved from 14694

    
   
14933
		ast_log(LOG_WARNING, "Refer-To Header missing. Skipping transfer.\n");
Moved from 14695

    
   
14934
		return -2;	/* Syntax error */
Moved from 14696

    
   
14935
	}
Moved from 14697

    
   
14936
	h_refer_to = ast_strdupa(p_refer_to);
Moved from 14698

    
   
14937
	refer_to = get_in_brackets(h_refer_to);
Moved from 14699

    
   
14938
	if (!strncasecmp(refer_to, "sip:", 4)) {
Moved from 14700

    
   
14939
		refer_to += 4;			/* Skip sip: */
Moved from 14701

    
   
14940
	} else if (!strncasecmp(refer_to, "sips:", 5)) {
Moved from 14702

    
   
14941
		refer_to += 5;
Moved from 14703

    
   
14942
	} else {
Moved from 14704

    
   
14943
		ast_log(LOG_WARNING, "Can't transfer to non-sip: URI.  (Refer-to: %s)?\n", refer_to);
Moved from 14705

    
   
14944
		return -3;
Moved from 14706

    
   
14945
	}

    
   
14946

   
Moved from 14708

    
   
14947
	/* Get referred by header if it exists */
Moved from 14709

    
   
14948
	p_referred_by = get_header(req, "Referred-By");

    
   
14949

   
Moved from 14711

    
   
14950
	/* Give useful transfer information to the dialplan */
Moved from 14712

    
   
14951
	if (transferer->owner) {
Moved from 14713

    
   
14952
		struct ast_channel *peer = ast_bridged_channel(transferer->owner);
Moved from 14714

    
   
14953
		if (peer) {
Moved from 14715

    
   
14954
			pbx_builtin_setvar_helper(peer, "SIPREFERRINGCONTEXT", transferer->context);
Moved from 14716

    
   
14955
			pbx_builtin_setvar_helper(peer, "SIPREFERREDBYHDR", p_referred_by);
Moved from 14717

    
   
14956
		}
Moved from 14718

    
   
14957
	}

    
   
14958

   
Moved from 14720

    
   
14959
	if (!ast_strlen_zero(p_referred_by)) {
Moved from 14721

    
   
14960
		char *lessthan;
Moved from 14722

    
   
14961
		h_referred_by = ast_strdupa(p_referred_by);

    
   
14962

   
Moved from 14724

    
   
14963
		/* Store referrer's caller ID name */
Moved from 14725

    
   
14964
		ast_copy_string(referdata->referred_by_name, h_referred_by, sizeof(referdata->referred_by_name));
Moved from 14726

    
   
14965
		if ((lessthan = strchr(referdata->referred_by_name, '<'))) {
Moved from 14727

    
   
14966
			*(lessthan - 1) = '\0';	/* Space */
Moved from 14728

    
   
14967
		}

    
   
14968

   

    
   
14969
		referred_by_uri = get_in_brackets(h_referred_by);

    
   
14970

   
Moved from 14732

    
   
14971
		if (!strncasecmp(referred_by_uri, "sip:", 4)) {
Moved from 14733

    
   
14972
			referred_by_uri += 4;		/* Skip sip: */
Moved from 14734

    
   
14973
		} else if (!strncasecmp(referred_by_uri, "sips:", 5)) {
Moved from 14735

    
   
14974
			referred_by_uri += 5;		/* Skip sips: */
Moved from 14736

    
   
14975
		} else {
Moved from 14737

    
   
14976
			ast_log(LOG_WARNING, "Huh?  Not a sip: header (Referred-by: %s). Skipping.\n", referred_by_uri);
Moved from 14738

    
   
14977
			referred_by_uri = NULL;
Moved from 14739

    
   
14978
		}
Moved from 14740

    
   
14979
	}

    
   
14980

   
Moved from 14742

    
   
14981
	/* Check for arguments in the refer_to header */
Moved from 14743

    
   
14982
	if ((ptr = strcasestr(refer_to, "replaces="))) {
Moved from 14744

    
   
14983
		char *to = NULL, *from = NULL;

    
   
14984
		
Moved from 14746

    
   
14985
		/* This is an attended transfer */
Moved from 14747

    
   
14986
		referdata->attendedtransfer = 1;
Moved from 14748

    
   
14987
		ast_copy_string(referdata->replaces_callid, ptr+9, sizeof(referdata->replaces_callid));

    
   
14988
		ast_uri_decode(referdata->replaces_callid, ast_uri_sip_user);
Moved from 14750

    
   
14989
		if ((ptr = strchr(referdata->replaces_callid, ';'))) 	/* Find options */ {
Moved from 14751

    
   
14990
			*ptr++ = '\0';
Moved from 14752

    
   
14991
		}

    
   
14992
		
Moved from 14754

    
   
14993
		if (ptr) {
Moved from 14755

    
   
14994
			/* Find the different tags before we destroy the string */
Moved from 14756

    
   
14995
			to = strcasestr(ptr, "to-tag=");
Moved from 14757

    
   
14996
			from = strcasestr(ptr, "from-tag=");
Moved from 14758

    
   
14997
		}

    
   
14998
		
Moved from 14760

    
   
14999
		/* Grab the to header */
Moved from 14761

    
   
15000
		if (to) {
Moved from 14762

    
   
15001
			ptr = to + 7;
Moved from 14763

    
   
15002
			if ((to = strchr(ptr, '&'))) {
Moved from 14764

    
   
15003
				*to = '\0';
Moved from 14765

    
   
15004
			}
Moved from 14766

    
   
15005
			if ((to = strchr(ptr, ';'))) {
Moved from 14767

    
   
15006
				*to = '\0';
Moved from 14768

    
   
15007
			}
Moved from 14769

    
   
15008
			ast_copy_string(referdata->replaces_callid_totag, ptr, sizeof(referdata->replaces_callid_totag));
Moved from 14770

    
   
15009
		}

    
   
15010

   
Moved from 14772

    
   
15011
		if (from) {
Moved from 14773

    
   
15012
			ptr = from + 9;
Moved from 14774

    
   
15013
			if ((to = strchr(ptr, '&'))) {
Moved from 14775

    
   
15014
				*to = '\0';
Moved from 14776

    
   
15015
			}
Moved from 14777

    
   
15016
			if ((to = strchr(ptr, ';'))) {
Moved from 14778

    
   
15017
				*to = '\0';
Moved from 14779

    
   
15018
			}
Moved from 14780

    
   
15019
			ast_copy_string(referdata->replaces_callid_fromtag, ptr, sizeof(referdata->replaces_callid_fromtag));
Moved from 14781

    
   
15020
		}

    
   
15021

   

    
   
15022
		if (!strcmp(referdata->replaces_callid, transferer->callid) &&

    
   
15023
			(!sip_cfg.pedanticsipchecking ||

    
   
15024
			(!strcmp(referdata->replaces_callid_fromtag, transferer->theirtag) &&

    
   
15025
			!strcmp(referdata->replaces_callid_totag, transferer->tag)))) {

    
   
15026
				ast_log(LOG_WARNING, "Got an attempt to replace own Call-ID on %s\n", transferer->callid);

    
   
15027
				return -4;

    
   
15028
		}

    
   
15029

   
Moved from 14783

    
   
15030
		if (!sip_cfg.pedanticsipchecking) {
Moved from 14784

    
   
15031
			ast_debug(2, "Attended transfer: Will use Replace-Call-ID : %s (No check of from/to tags)\n", referdata->replaces_callid );
Moved from 14785

    
   
15032
		} else {
Moved from 14786

    
   
15033
			ast_debug(2, "Attended transfer: Will use Replace-Call-ID : %s F-tag: %s T-tag: %s\n", referdata->replaces_callid, referdata->replaces_callid_fromtag ? referdata->replaces_callid_fromtag : "<none>", referdata->replaces_callid_totag ? referdata->replaces_callid_totag : "<none>" );
Moved from 14787

    
   
15034
		}

    
   
15035
	}

    
   
15036

   
14790
	if ((ptr = strchr(refer_to, '@'))) {	/* Separate domain */
15037
	if ((ptr = strchr(refer_to, '@'))) {	/* Separate domain */
14791
		char *urioption = NULL, *domain;
15038
		char *urioption = NULL, *domain;
14792
		int bracket = 0;
15039
		int bracket = 0;
14793
		*ptr++ = '\0';
15040
		*ptr++ = '\0';
14794

    
   
15041

   
[+20] [20] 370 lines
[+20] [+] static enum check_auth_result check_peer_ok(struct sip_pvt *p, char *of,
15165
		ast_string_field_set(p, language, peer->language);
15412
		ast_string_field_set(p, language, peer->language);
15166
		ast_string_field_set(p, accountcode, peer->accountcode);
15413
		ast_string_field_set(p, accountcode, peer->accountcode);
15167
		p->amaflags = peer->amaflags;
15414
		p->amaflags = peer->amaflags;
15168
		p->callgroup = peer->callgroup;
15415
		p->callgroup = peer->callgroup;
15169
		p->pickupgroup = peer->pickupgroup;
15416
		p->pickupgroup = peer->pickupgroup;
15170
		p->capability = peer->capability;
15417
		ast_format_cap_copy(p->caps, peer->caps);

    
   
15418
		ast_format_cap_copy(p->jointcaps, peer->caps);
15171
		p->prefs = peer->prefs;
15419
		p->prefs = peer->prefs;
15172
		p->jointcapability = peer->capability;

   
15173
 		if (peer->maxforwards > 0) {
15420
 		if (peer->maxforwards > 0) {
15174
			p->maxforwards = peer->maxforwards;
15421
			p->maxforwards = peer->maxforwards;
15175
		}
15422
		}
15176
		if (p->peercapability)
15423
		if (!(ast_format_cap_is_empty(p->peercaps))) {
15177
			p->jointcapability &= p->peercapability;
15424
			struct ast_format_cap *tmp = ast_format_cap_joint(p->jointcaps, p->peercaps);

    
   
15425
			struct ast_format_cap *tmp2;

    
   
15426
			if (tmp) {

    
   
15427
				tmp2 = p->jointcaps;

    
   
15428
				p->jointcaps = tmp;

    
   
15429
				ast_format_cap_destroy(tmp2);

    
   
15430
			}

    
   
15431
		}
15178
		p->maxcallbitrate = peer->maxcallbitrate;
15432
		p->maxcallbitrate = peer->maxcallbitrate;
15179
		if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
15433
		if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
15180
		    (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO))
15434
		    (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO))
15181
			p->noncodeccapability |= AST_RTP_DTMF;
15435
			p->noncodeccapability |= AST_RTP_DTMF;
15182
		else
15436
		else
[+20] [20] 188 lines
[+20] [+] static int get_msg_text2(struct ast_str **buf, struct sip_request *req, int addnewline)
15371
AST_THREADSTORAGE(sip_msg_buf);
15625
AST_THREADSTORAGE(sip_msg_buf);
15372

    
   
15626

   
15373
/*! \brief  Receive SIP MESSAGE method messages
15627
/*! \brief  Receive SIP MESSAGE method messages
15374
\note	We only handle messages within current calls currently
15628
\note	We only handle messages within current calls currently
15375
	Reference: RFC 3428 */
15629
	Reference: RFC 3428 */
15376
static void receive_message(struct sip_pvt *p, struct sip_request *req)
15630
static void receive_message(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
15377
{
15631
{
15378
	struct ast_str *buf;
15632
	struct ast_str *buf;
15379
	struct ast_frame f;
15633
	struct ast_frame f;
15380
	const char *content_type = get_header(req, "Content-Type");
15634
	const char *content_type = get_header(req, "Content-Type");
15381
	struct ast_msg *msg;
15635
	struct ast_msg *msg;
[+20] [20] 29 lines
[+20] static void receive_message(struct sip_pvt *p, struct sip_request *req) [+] static void receive_message(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
15411
		memset(&f, 0, sizeof(f));
15665
		memset(&f, 0, sizeof(f));
15412
		f.frametype = AST_FRAME_TEXT;
15666
		f.frametype = AST_FRAME_TEXT;
15413
		f.subclass.integer = 0;
15667
		f.subclass.integer = 0;
15414
		f.offset = 0;
15668
		f.offset = 0;
15415
		f.data.ptr = ast_str_buffer(buf);
15669
		f.data.ptr = ast_str_buffer(buf);
15416
		f.datalen = ast_str_strlen(buf);
15670
		f.datalen = ast_str_strlen(buf) + 1;
15417
		ast_queue_frame(p->owner, &f);
15671
		ast_queue_frame(p->owner, &f);
15418
		transmit_response(p, "202 Accepted", req); /* We respond 202 accepted, since we relay the message */
15672
		transmit_response(p, "202 Accepted", req); /* We respond 202 accepted, since we relay the message */
15419
		return;
15673
		return;
15420
	}
15674
	}
15421

    
   
15675

   
15422
#if 0
15676
	if (!sip_cfg.accept_outofcall_message) {
15423
	/* Message outside of a call, we do not support that */
15677
		/* Message outside of a call, we do not support that */

    
   
15678
		ast_debug(1, "MESSAGE outside of a call administratively disabled.\n");
15424
	transmit_response(p, "405 Method Not Allowed", req);
15679
		transmit_response(p, "405 Method Not Allowed", req);
15425
	sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
15680
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
15426
#endif
15681
		return;

    
   
15682
	}

    
   
15683

   

    
   
15684
	if (sip_cfg.auth_message_requests) {

    
   
15685
		int res;

    
   
15686

   

    
   
15687
		copy_request(&p->initreq, req);

    
   
15688
		set_pvt_allowed_methods(p, req);

    
   
15689
		res = check_user(p, req, SIP_MESSAGE, e, XMIT_UNRELIABLE, addr);

    
   
15690
		if (res == AUTH_CHALLENGE_SENT) {

    
   
15691
			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);

    
   
15692
			return;

    
   
15693
		}

    
   
15694
		if (res < 0) { /* Something failed in authentication */

    
   
15695
			if (res == AUTH_FAKE_AUTH) {

    
   
15696
				ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", get_header(req, "From"));

    
   
15697
				transmit_fake_auth_response(p, SIP_OPTIONS, req, XMIT_UNRELIABLE);

    
   
15698
			} else {

    
   
15699
				ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", get_header(req, "From"));

    
   
15700
				transmit_response(p, "403 Forbidden", req);

    
   
15701
			}

    
   
15702
			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);

    
   
15703
			return;

    
   
15704
		}

    
   
15705
		/* Auth was successful.  Proceed. */

    
   
15706
	} else {

    
   
15707
		struct sip_peer *peer;
15427

    
   
15708

   
15428
	/*
15709
		/*
15429
	 * XXX Need to optionally authenticate MESSAGE.  Also, make passing MESSAGE up to
15710
		 * MESSAGE outside of a call, not authenticating it.
15430
	 * the dialplan configurable.
15711
		 * Check to see if we match a peer anyway so that we can direct

    
   
15712
		 * it to the right context.
15431
	 */
15713
		 */
15432

    
   
15714

   

    
   
15715
		peer = find_peer(NULL, &p->recv, TRUE, FINDPEERS, 0, p->socket.type);

    
   
15716
		if (peer) {

    
   
15717
			/* Only if no auth is required. */

    
   
15718
			if (ast_strlen_zero(peer->secret) && ast_strlen_zero(peer->md5secret)) {

    
   
15719
				ast_string_field_set(p, context, peer->context);

    
   
15720
			}

    
   
15721
			peer = unref_peer(peer, "from find_peer() in receive_message");

    
   
15722
		}

    
   
15723
	}

    
   
15724

   
15433
	if (!(msg = ast_msg_alloc())) {
15725
	if (!(msg = ast_msg_alloc())) {
15434
		transmit_response(p, "500 Internal Server Error", req);
15726
		transmit_response(p, "500 Internal Server Error", req);
15435
		if (!p->owner) {
15727
		if (!p->owner) {
15436
			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
15728
			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
15437
		}
15729
		}
[+20] [20] 4 lines
[+20] static void receive_message(struct sip_pvt *p, struct sip_request *req) [+] static void receive_message(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
15442
	from = ast_strdupa(get_header(req, "From"));
15734
	from = ast_strdupa(get_header(req, "From"));
15443

    
   
15735

   
15444
	res = ast_msg_set_to(msg, "%s", to);
15736
	res = ast_msg_set_to(msg, "%s", to);
15445
	res |= ast_msg_set_from(msg, "%s", get_in_brackets(from));
15737
	res |= ast_msg_set_from(msg, "%s", get_in_brackets(from));
15446
	res |= ast_msg_set_body(msg, "%s", ast_str_buffer(buf));
15738
	res |= ast_msg_set_body(msg, "%s", ast_str_buffer(buf));
15447
	/* XXX set configurable context */
15739
	res |= ast_msg_set_context(msg, "%s", p->context);
15448

    
   
15740

   
15449
	if (res) {
15741
	if (res) {
15450
		ao2_ref(msg, -1);
15742
		ast_msg_destroy(msg);
15451
	} else {
15743
	} else {
15452
		ast_msg_queue(msg);
15744
		ast_msg_queue(msg);
15453
	}
15745
	}
15454

    
   
15746

   
15455
	transmit_response(p, "202 Accepted", req);
15747
	transmit_response(p, "202 Accepted", req);
[+20] [20] 687 lines
[+20] [+] static int dialog_needdestroy(void *dialogobj, void *arg, int flags)
16143
		if (dialog->rtp && ast_rtp_instance_get_bridged(dialog->rtp)) {
16435
		if (dialog->rtp && ast_rtp_instance_get_bridged(dialog->rtp)) {
16144
			ast_debug(2, "Bridge still active.  Delaying destruction of SIP dialog '%s' Method: %s\n", dialog->callid, sip_methods[dialog->method].text);
16436
			ast_debug(2, "Bridge still active.  Delaying destruction of SIP dialog '%s' Method: %s\n", dialog->callid, sip_methods[dialog->method].text);
16145
			sip_pvt_unlock(dialog);
16437
			sip_pvt_unlock(dialog);
16146
			return 0;
16438
			return 0;
16147
		}
16439
		}
16148
		
16440

   
16149
		if (dialog->vrtp && ast_rtp_instance_get_bridged(dialog->vrtp)) {
16441
		if (dialog->vrtp && ast_rtp_instance_get_bridged(dialog->vrtp)) {
16150
			ast_debug(2, "Bridge still active.  Delaying destroy of SIP dialog '%s' Method: %s\n", dialog->callid, sip_methods[dialog->method].text);
16442
			ast_debug(2, "Bridge still active.  Delaying destroy of SIP dialog '%s' Method: %s\n", dialog->callid, sip_methods[dialog->method].text);
16151
			sip_pvt_unlock(dialog);
16443
			sip_pvt_unlock(dialog);
16152
			return 0;
16444
			return 0;
16153
		}
16445
		}
[+20] [20] 145 lines
[+20] [+] static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
16299

    
   
16591

   
16300
/*! \brief Print codec list from preference to CLI/manager */
16592
/*! \brief Print codec list from preference to CLI/manager */
16301
static void print_codec_to_cli(int fd, struct ast_codec_pref *pref)
16593
static void print_codec_to_cli(int fd, struct ast_codec_pref *pref)
16302
{
16594
{
16303
	int x;
16595
	int x;
16304
	format_t codec;
16596
	struct ast_format codec;
16305

    
   
16597

   
16306
	for(x = 0; x < 64 ; x++) {
16598
	for(x = 0; x < AST_CODEC_PREF_SIZE; x++) {
16307
		codec = ast_codec_pref_index(pref, x);
16599
		if (!(ast_codec_pref_index(pref, x, &codec))) {
16308
		if (!codec)

   
16309
			break;
16600
			break;
16310
		ast_cli(fd, "%s", ast_getformatname(codec));
16601
		}

    
   
16602
		ast_cli(fd, "%s", ast_getformatname(&codec));
16311
		ast_cli(fd, ":%d", pref->framing[x]);
16603
		ast_cli(fd, ":%d", pref->framing[x]);
16312
		if (x < 31 && ast_codec_pref_index(pref, x + 1))
16604
		if (x < 31 && ast_codec_pref_index(pref, x + 1, &codec))
16313
			ast_cli(fd, ",");
16605
			ast_cli(fd, ",");
16314
	}
16606
	}
16315
	if (!x)
16607
	if (!x)
16316
		ast_cli(fd, "none");
16608
		ast_cli(fd, "none");
16317
}
16609
}
[+20] [20] 177 lines
[+20] [+] static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[])
16495
	char codec_buf[512];
16787
	char codec_buf[512];
16496
	struct ast_codec_pref *pref;
16788
	struct ast_codec_pref *pref;
16497
	struct ast_variable *v;
16789
	struct ast_variable *v;
16498
	struct sip_auth *auth;
16790
	struct sip_auth *auth;
16499
	int x = 0, load_realtime;
16791
	int x = 0, load_realtime;
16500
	format_t codec = 0;
16792
	struct ast_format codec;
16501
	int realtimepeers;
16793
	int realtimepeers;
16502

    
   
16794

   
16503
	realtimepeers = ast_check_realtime("sippeers");
16795
	realtimepeers = ast_check_realtime("sippeers");
16504

    
   
16796

   
16505
	if (argc < 4)
16797
	if (argc < 4)
[+20] [20] 104 lines
[+20] static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[])
16610
		} else
16902
		} else
16611
			ast_cli(fd, "(none)");
16903
			ast_cli(fd, "(none)");
16612

    
   
16904

   
16613
		ast_cli(fd, "\n");
16905
		ast_cli(fd, "\n");
16614
		ast_cli(fd, "  Codecs       : ");
16906
		ast_cli(fd, "  Codecs       : ");
16615
		ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability);
16907
		ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->caps);
16616
		ast_cli(fd, "%s\n", codec_buf);
16908
		ast_cli(fd, "%s\n", codec_buf);
16617
		ast_cli(fd, "  Codec Order  : (");
16909
		ast_cli(fd, "  Codec Order  : (");
16618
		print_codec_to_cli(fd, &peer->prefs);
16910
		print_codec_to_cli(fd, &peer->prefs);
16619
		ast_cli(fd, ")\n");
16911
		ast_cli(fd, ")\n");
16620

    
   
16912

   
[+20] [20] 83 lines
[+20] static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[])
16704
		astman_append(s, "Default-addr-IP: %s\r\nDefault-addr-port: %d\r\n", ast_sockaddr_stringify_addr(&peer->defaddr), ast_sockaddr_port(&peer->defaddr));
16996
		astman_append(s, "Default-addr-IP: %s\r\nDefault-addr-port: %d\r\n", ast_sockaddr_stringify_addr(&peer->defaddr), ast_sockaddr_port(&peer->defaddr));
16705
		astman_append(s, "Default-Username: %s\r\n", peer->username);
16997
		astman_append(s, "Default-Username: %s\r\n", peer->username);
16706
		if (!ast_strlen_zero(sip_cfg.regcontext))
16998
		if (!ast_strlen_zero(sip_cfg.regcontext))
16707
			astman_append(s, "RegExtension: %s\r\n", peer->regexten);
16999
			astman_append(s, "RegExtension: %s\r\n", peer->regexten);
16708
		astman_append(s, "Codecs: ");
17000
		astman_append(s, "Codecs: ");
16709
		ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability);
17001
		ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->caps);
16710
		astman_append(s, "%s\r\n", codec_buf);
17002
		astman_append(s, "%s\r\n", codec_buf);
16711
		astman_append(s, "CodecOrder: ");
17003
		astman_append(s, "CodecOrder: ");
16712
		pref = &peer->prefs;
17004
		pref = &peer->prefs;
16713
		for(x = 0; x < 64 ; x++) {
17005
		for(x = 0; x < AST_CODEC_PREF_SIZE ; x++) {
16714
			codec = ast_codec_pref_index(pref, x);
17006
			if (!(ast_codec_pref_index(pref, x, &codec))) {
16715
			if (!codec)

   
16716
				break;
17007
				break;
16717
			astman_append(s, "%s", ast_getformatname(codec));
17008
			}
16718
			if (x < 63 && ast_codec_pref_index(pref, x+1))
17009
			astman_append(s, "%s", ast_getformatname(&codec));

    
   
17010
			if ((x < (AST_CODEC_PREF_SIZE - 1)) && ast_codec_pref_index(pref, x+1, &codec))
16719
				astman_append(s, ",");
17011
				astman_append(s, ",");
16720
		}
17012
		}
16721

    
   
17013

   
16722
		astman_append(s, "\r\n");
17014
		astman_append(s, "\r\n");
16723
		astman_append(s, "Status: ");
17015
		astman_append(s, "Status: ");
[+20] [20] 41 lines
[+20] [+] static char *complete_sip_user(const char *word, int state)
16765
		if (!strncasecmp(word, user->name, wordlen) && ++which > state) {
17057
		if (!strncasecmp(word, user->name, wordlen) && ++which > state) {
16766
			result = ast_strdup(user->name);
17058
			result = ast_strdup(user->name);
16767
		}
17059
		}
16768
		ao2_unlock(user);
17060
		ao2_unlock(user);
16769
		unref_peer(user, "complete sip user");
17061
		unref_peer(user, "complete sip user");

    
   
17062
		if (result) {

    
   
17063
			break;

    
   
17064
		}
16770
	}
17065
	}
16771
	ao2_iterator_destroy(&user_iter);
17066
	ao2_iterator_destroy(&user_iter);
16772
	return result;
17067
	return result;
16773
}
17068
}
16774
/*! \brief Support routine for 'sip show user' CLI */
17069
/*! \brief Support routine for 'sip show user' CLI */
[+20] [20] 431 lines
[+20] [+] static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
17206
		}
17501
		}
17207
	}
17502
	}
17208
	ast_cli(a->fd, "\nGlobal Signalling Settings:\n");
17503
	ast_cli(a->fd, "\nGlobal Signalling Settings:\n");
17209
	ast_cli(a->fd, "---------------------------\n");
17504
	ast_cli(a->fd, "---------------------------\n");
17210
	ast_cli(a->fd, "  Codecs:                 ");
17505
	ast_cli(a->fd, "  Codecs:                 ");
17211
	ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, sip_cfg.capability);
17506
	ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, sip_cfg.caps);
17212
	ast_cli(a->fd, "%s\n", codec_buf);
17507
	ast_cli(a->fd, "%s\n", codec_buf);
17213
	ast_cli(a->fd, "  Codec Order:            ");
17508
	ast_cli(a->fd, "  Codec Order:            ");
17214
	print_codec_to_cli(a->fd, &default_prefs);
17509
	print_codec_to_cli(a->fd, &default_prefs);
17215
	ast_cli(a->fd, "\n");
17510
	ast_cli(a->fd, "\n");
17216
	ast_cli(a->fd, "  Relax DTMF:             %s\n", AST_CLI_YESNO(global_relaxdtmf));
17511
	ast_cli(a->fd, "  Relax DTMF:             %s\n", AST_CLI_YESNO(global_relaxdtmf));
[+20] [20] 146 lines
[+20] [+] static int show_channels_cb(void *__cur, void *__arg, int flags)
17363
		char formatbuf[SIPBUFSIZE/2];
17658
		char formatbuf[SIPBUFSIZE/2];
17364
		
17659
		
17365
		ast_cli(arg->fd, FORMAT, ast_sockaddr_stringify_addr(dst),
17660
		ast_cli(arg->fd, FORMAT, ast_sockaddr_stringify_addr(dst),
17366
				S_OR(cur->username, S_OR(cur->cid_num, "(None)")),
17661
				S_OR(cur->username, S_OR(cur->cid_num, "(None)")),
17367
				cur->callid,
17662
				cur->callid,
17368
				ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0),
17663
				cur->owner ? ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner->nativeformats) : "(nothing)",
17369
				AST_CLI_YESNO(ast_test_flag(&cur->flags[1], SIP_PAGE2_CALL_ONHOLD)),
17664
				AST_CLI_YESNO(ast_test_flag(&cur->flags[1], SIP_PAGE2_CALL_ONHOLD)),
17370
				cur->needdestroy ? "(d)" : "",
17665
				cur->needdestroy ? "(d)" : "",
17371
				cur->lastmsg ,
17666
				cur->lastmsg ,
17372
				referstatus,
17667
				referstatus,
17373
				cur->relatedpeer ? cur->relatedpeer->name : "<guest>"
17668
				cur->relatedpeer ? cur->relatedpeer->name : "<guest>"
[+20] [20] 238 lines
[+20] [+] static char *sip_show_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
17612
				ast_cli(a->fd, "  * SIP Call\n");
17907
				ast_cli(a->fd, "  * SIP Call\n");
17613
			}
17908
			}
17614
			ast_cli(a->fd, "  Curr. trans. direction:  %s\n", ast_test_flag(&cur->flags[0], SIP_OUTGOING) ? "Outgoing" : "Incoming");
17909
			ast_cli(a->fd, "  Curr. trans. direction:  %s\n", ast_test_flag(&cur->flags[0], SIP_OUTGOING) ? "Outgoing" : "Incoming");
17615
			ast_cli(a->fd, "  Call-ID:                %s\n", cur->callid);
17910
			ast_cli(a->fd, "  Call-ID:                %s\n", cur->callid);
17616
			ast_cli(a->fd, "  Owner channel ID:       %s\n", cur->owner ? cur->owner->name : "<none>");
17911
			ast_cli(a->fd, "  Owner channel ID:       %s\n", cur->owner ? cur->owner->name : "<none>");
17617
			ast_cli(a->fd, "  Our Codec Capability:   %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->capability));
17912
			ast_cli(a->fd, "  Our Codec Capability:   %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->caps));
17618
			ast_cli(a->fd, "  Non-Codec Capability (DTMF):   %d\n", cur->noncodeccapability);
17913
			ast_cli(a->fd, "  Non-Codec Capability (DTMF):   %d\n", cur->noncodeccapability);
17619
			ast_cli(a->fd, "  Their Codec Capability:   %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->peercapability));
17914
			ast_cli(a->fd, "  Their Codec Capability:   %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->peercaps));
17620
			ast_cli(a->fd, "  Joint Codec Capability:   %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->jointcapability));
17915
			ast_cli(a->fd, "  Joint Codec Capability:   %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->jointcaps));
17621
			ast_cli(a->fd, "  Format:                 %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0) );
17916
			ast_cli(a->fd, "  Format:                 %s\n", cur->owner ? ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner->nativeformats) : "(nothing)" );
17622
			ast_cli(a->fd, "  T.38 support            %s\n", AST_CLI_YESNO(cur->udptl != NULL));
17917
			ast_cli(a->fd, "  T.38 support            %s\n", AST_CLI_YESNO(cur->udptl != NULL));
17623
			ast_cli(a->fd, "  Video support           %s\n", AST_CLI_YESNO(cur->vrtp != NULL));
17918
			ast_cli(a->fd, "  Video support           %s\n", AST_CLI_YESNO(cur->vrtp != NULL));
17624
			ast_cli(a->fd, "  MaxCallBR:              %d kbps\n", cur->maxcallbitrate);
17919
			ast_cli(a->fd, "  MaxCallBR:              %d kbps\n", cur->maxcallbitrate);
17625
			ast_cli(a->fd, "  Theoretical Address:    %s\n", ast_sockaddr_stringify(&cur->sa));
17920
			ast_cli(a->fd, "  Theoretical Address:    %s\n", ast_sockaddr_stringify(&cur->sa));
17626
			ast_cli(a->fd, "  Received Address:       %s\n", ast_sockaddr_stringify(&cur->recv));
17921
			ast_cli(a->fd, "  Received Address:       %s\n", ast_sockaddr_stringify(&cur->recv));
[+20] [20] 718 lines
[+20] [+] static int build_reply_digest(struct sip_pvt *p, int method, char* digest, int digest_len)
18345
		if (sipdebug)
18640
		if (sipdebug)
18346
 			ast_debug(1, "Using realm %s authentication for call %s\n", p->realm, p->callid);
18641
			ast_debug(1, "Using realm %s authentication for call %s\n", p->realm, p->callid);
18347
 	} else {
18642
	} else {
18348
 		/* No authentication, use peer or register= config */
18643
		/* No authentication, use peer or register= config */
18349
 		username = p->authname;
18644
		username = p->authname;
18350
 		secret =  p->peersecret;
18645
 		secret = p->relatedpeer 

    
   
18646
			&& !ast_strlen_zero(p->relatedpeer->remotesecret)

    
   
18647
			? p->relatedpeer->remotesecret : p->peersecret;
18351
 		md5secret = p->peermd5secret;
18648
		md5secret = p->peermd5secret;
18352
 	}
18649
	}
18353
	if (ast_strlen_zero(username))	/* We have no authentication */
18650
	if (ast_strlen_zero(username))	/* We have no authentication */
18354
		return -1;
18651
		return -1;
18355

    
   
18652

   
[+20] [20] 165 lines
[+20] [+] static int function_sippeer(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
18521
	} else  if (!strcasecmp(colname, "callerid_name")) {
18818
	} else  if (!strcasecmp(colname, "callerid_name")) {
18522
		ast_copy_string(buf, peer->cid_name, len);
18819
		ast_copy_string(buf, peer->cid_name, len);
18523
	} else  if (!strcasecmp(colname, "callerid_num")) {
18820
	} else  if (!strcasecmp(colname, "callerid_num")) {
18524
		ast_copy_string(buf, peer->cid_num, len);
18821
		ast_copy_string(buf, peer->cid_num, len);
18525
	} else  if (!strcasecmp(colname, "codecs")) {
18822
	} else  if (!strcasecmp(colname, "codecs")) {
18526
		ast_getformatname_multiple(buf, len -1, peer->capability);
18823
		ast_getformatname_multiple(buf, len -1, peer->caps);
18527
	} else if (!strcasecmp(colname, "encryption")) {
18824
	} else if (!strcasecmp(colname, "encryption")) {
18528
		snprintf(buf, len, "%d", ast_test_flag(&peer->flags[1], SIP_PAGE2_USE_SRTP));
18825
		snprintf(buf, len, "%d", ast_test_flag(&peer->flags[1], SIP_PAGE2_USE_SRTP));
18529
	} else  if (!strncasecmp(colname, "chanvar[", 8)) {
18826
	} else  if (!strncasecmp(colname, "chanvar[", 8)) {
18530
		char *chanvar=colname + 8;
18827
		char *chanvar=colname + 8;
18531
		struct ast_variable *v;
18828
		struct ast_variable *v;
18532
	
18829

   
18533
		chanvar = strsep(&chanvar, "]");
18830
		chanvar = strsep(&chanvar, "]");
18534
		for (v = peer->chanvars ; v ; v = v->next) {
18831
		for (v = peer->chanvars ; v ; v = v->next) {
18535
			if (!strcasecmp(v->name, chanvar)) {
18832
			if (!strcasecmp(v->name, chanvar)) {
18536
				ast_copy_string(buf, v->value, len);
18833
				ast_copy_string(buf, v->value, len);
18537
			}
18834
			}
18538
		}
18835
		}
18539
	} else  if (!strncasecmp(colname, "codec[", 6)) {
18836
	} else  if (!strncasecmp(colname, "codec[", 6)) {
18540
		char *codecnum;
18837
		char *codecnum;
18541
		format_t codec = 0;
18838
		struct ast_format codec;
18542
		
18839

   
18543
		codecnum = colname + 6;	/* move past the '[' */
18840
		codecnum = colname + 6;	/* move past the '[' */
18544
		codecnum = strsep(&codecnum, "]"); /* trim trailing ']' if any */
18841
		codecnum = strsep(&codecnum, "]"); /* trim trailing ']' if any */
18545
		if((codec = ast_codec_pref_index(&peer->prefs, atoi(codecnum)))) {
18842
		if((ast_codec_pref_index(&peer->prefs, atoi(codecnum), &codec))) {
18546
			ast_copy_string(buf, ast_getformatname(codec), len);
18843
			ast_copy_string(buf, ast_getformatname(&codec), len);
18547
		} else {
18844
		} else {
18548
			buf[0] = '\0';
18845
			buf[0] = '\0';
18549
		}
18846
		}
18550
	} else {
18847
	} else {
18551
		buf[0] = '\0';
18848
		buf[0] = '\0';
[+20] [20] 230 lines
[+20] [+] static void parse_moved_contact(struct sip_pvt *p, struct sip_request *req, char **name, char **number, int set_call_forward)
18782
		else if (!strncasecmp(contact_number, "sips:", 5))
19079
		else if (!strncasecmp(contact_number, "sips:", 5))
18783
			contact_number += 5;
19080
			contact_number += 5;
18784
		separator = strchr(contact_number, ';');	/* And username ; parameters? */
19081
		separator = strchr(contact_number, ';');	/* And username ; parameters? */
18785
		if (separator)
19082
		if (separator)
18786
			*separator = '\0';
19083
			*separator = '\0';
18787
		ast_uri_decode(contact_number);
19084
		ast_uri_decode(contact_number, ast_uri_sip_user);
18788
		if (set_call_forward) {
19085
		if (set_call_forward) {
18789
			ast_debug(2, "Received 302 Redirect to extension '%s' (domain %s)\n", contact_number, domain);
19086
			ast_debug(2, "Received 302 Redirect to extension '%s' (domain %s)\n", contact_number, domain);
18790
			if (p->owner) {
19087
			if (p->owner) {
18791
				pbx_builtin_setvar_helper(p->owner, "SIPDOMAIN", domain);
19088
				pbx_builtin_setvar_helper(p->owner, "SIPDOMAIN", domain);
18792
				ast_string_field_set(p->owner, call_forward, contact_number);
19089
				ast_string_field_set(p->owner, call_forward, contact_number);
[+20] [20] 43 lines
[+20] [+] static void check_pendings(struct sip_pvt *p)
18836
				ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_DEV);
19133
				ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_DEV);
18837
			}
19134
			}
18838
			/* Perhaps there is an SD change INVITE outstanding */
19135
			/* Perhaps there is an SD change INVITE outstanding */
18839
			transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, TRUE);
19136
			transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, TRUE);
18840
		}
19137
		}
18841
		ast_clear_flag(&p->flags[0], SIP_PENDINGBYE);	
19138
		ast_clear_flag(&p->flags[0], SIP_PENDINGBYE);
18842
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
19139
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
18843
	} else if (ast_test_flag(&p->flags[0], SIP_NEEDREINVITE)) {
19140
	} else if (ast_test_flag(&p->flags[0], SIP_NEEDREINVITE)) {
18844
		/* if we can't REINVITE, hold it for later */
19141
		/* if we can't REINVITE, hold it for later */
18845
		if (p->pendinginvite || p->invitestate == INV_CALLING || p->invitestate == INV_PROCEEDING || p->invitestate == INV_EARLY_MEDIA || p->waitid > 0) {
19142
		if (p->pendinginvite || p->invitestate == INV_CALLING || p->invitestate == INV_PROCEEDING || p->invitestate == INV_EARLY_MEDIA || p->waitid > 0) {
18846
			ast_debug(2, "NOT Sending pending reinvite (yet) on '%s'\n", p->callid);
19143
			ast_debug(2, "NOT Sending pending reinvite (yet) on '%s'\n", p->callid);
18847
		} else {
19144
		} else {
18848
			ast_debug(2, "Sending pending reinvite on '%s'\n", p->callid);
19145
			ast_debug(2, "Sending pending reinvite on '%s'\n", p->callid);
18849
			/* Didn't get to reinvite yet, so do it now */
19146
			/* Didn't get to reinvite yet, so do it now */
18850
			transmit_reinvite_with_sdp(p, (p->t38.state == T38_LOCAL_REINVITE ? TRUE : FALSE), FALSE);
19147
			transmit_reinvite_with_sdp(p, (p->t38.state == T38_LOCAL_REINVITE ? TRUE : FALSE), FALSE);
18851
			ast_clear_flag(&p->flags[0], SIP_NEEDREINVITE);	
19148
			ast_clear_flag(&p->flags[0], SIP_NEEDREINVITE);
18852
		}
19149
		}
18853
	}
19150
	}
18854
}
19151
}
18855

    
   
19152

   
18856
/*! \brief Reset the NEEDREINVITE flag after waiting when we get 491 on a Re-invite
19153
/*! \brief Reset the NEEDREINVITE flag after waiting when we get 491 on a Re-invite
18857
	to avoid race conditions between asterisk servers.
19154
	to avoid race conditions between asterisk servers.
[+20] [20] 842 lines
[+20] [+] static int handle_response_register(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
19700
		if (!r) {
19997
		if (!r) {
19701
			ast_log(LOG_WARNING, "Got 200 OK on REGISTER, but there isn't a registry entry for '%s' (we probably already got the OK)\n", S_OR(p->peername, p->username));
19998
			ast_log(LOG_WARNING, "Got 200 OK on REGISTER, but there isn't a registry entry for '%s' (we probably already got the OK)\n", S_OR(p->peername, p->username));
19702
			pvt_set_needdestroy(p, "received erroneous 200 response");
19999
			pvt_set_needdestroy(p, "received erroneous 200 response");
19703
			return 0;
20000
			return 0;
19704
		}
20001
		}
19705
		
20002

   
19706
		r->regstate = REG_STATE_REGISTERED;
20003
		r->regstate = REG_STATE_REGISTERED;
19707
		r->regtime = ast_tvnow();		/* Reset time of last successful registration */
20004
		r->regtime = ast_tvnow();		/* Reset time of last successful registration */
19708
		manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: SIP\r\nDomain: %s\r\nStatus: %s\r\n", r->hostname, regstate2str(r->regstate));
20005
		manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: SIP\r\nDomain: %s\r\nStatus: %s\r\n", r->hostname, regstate2str(r->regstate));
19709
		r->regattempts = 0;
20006
		r->regattempts = 0;
19710
		ast_debug(1, "Registration successful\n");
20007
		ast_debug(1, "Registration successful\n");
[+20] [20] 5 lines
[+20] static int handle_response_register(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
19716
			r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 200");
20013
			r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 200");
19717
		p->registry = registry_unref(p->registry, "unref registry entry p->registry");
20014
		p->registry = registry_unref(p->registry, "unref registry entry p->registry");
19718
		/* Let this one hang around until we have all the responses */
20015
		/* Let this one hang around until we have all the responses */
19719
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
20016
		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
19720
		/* p->needdestroy = 1; */
20017
		/* p->needdestroy = 1; */
19721
		
20018

   
19722
		/* set us up for re-registering
20019
		/* set us up for re-registering
19723
		 * figure out how long we got registered for
20020
		 * figure out how long we got registered for
19724
		 * according to section 6.13 of RFC, contact headers override
20021
		 * according to section 6.13 of RFC, contact headers override
19725
		 * expires headers, so check those first */
20022
		 * expires headers, so check those first */
19726
		expires = 0;
20023
		expires = 0;
[+20] [20] 262 lines
[+20] [+] static void handle_response(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
19989
				handle_response_subscribe(p, resp, rest, req, seqno);
20286
				handle_response_subscribe(p, resp, rest, req, seqno);
19990
			else if (p->registry && sipmethod == SIP_REGISTER)
20287
			else if (p->registry && sipmethod == SIP_REGISTER)
19991
				res = handle_response_register(p, resp, rest, req, seqno);
20288
				res = handle_response_register(p, resp, rest, req, seqno);
19992
			else if (sipmethod == SIP_UPDATE) {
20289
			else if (sipmethod == SIP_UPDATE) {
19993
				handle_response_update(p, resp, rest, req, seqno);
20290
				handle_response_update(p, resp, rest, req, seqno);

    
   
20291
			} else if (sipmethod == SIP_MESSAGE) {

    
   
20292
				handle_response_message(p, resp, rest, req, seqno);
19994
			} else if (sipmethod == SIP_BYE) {
20293
			} else if (sipmethod == SIP_BYE) {
19995
				if (p->options)
20294
				if (p->options)
19996
					p->options->auth_type = resp;
20295
					p->options->auth_type = resp;
19997
				if (ast_strlen_zero(p->authname)) {
20296
				if (ast_strlen_zero(p->authname)) {
19998
					ast_log(LOG_WARNING, "Asked to authenticate %s, to %s but we have no matching peer!\n",
20297
					ast_log(LOG_WARNING, "Asked to authenticate %s, to %s but we have no matching peer!\n",
[+20] [20] 275 lines
[+20] static void handle_response(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
20274
			if (sipmethod == SIP_INVITE)
20573
			if (sipmethod == SIP_INVITE)
20275
				handle_response_invite(p, resp, rest, req, seqno);
20574
				handle_response_invite(p, resp, rest, req, seqno);
20276
			break;
20575
			break;
20277
		default:	/* Errors without handlers */
20576
		default:	/* Errors without handlers */
20278
			if ((resp >= 100) && (resp < 200)) {
20577
			if ((resp >= 100) && (resp < 200)) {
20279
				if (sipmethod == SIP_INVITE) { 	/* re-invite */
20578
				if (sipmethod == SIP_INVITE) {	/* re-invite */
20280
					if (!req->ignore && sip_cancel_destroy(p))
20579
					if (!req->ignore && sip_cancel_destroy(p))
20281
						ast_log(LOG_WARNING, "Unable to cancel SIP destruction.  Expect bad things.\n");
20580
						ast_log(LOG_WARNING, "Unable to cancel SIP destruction.  Expect bad things.\n");
20282
				}
20581
				}
20283
			} else if ((resp >= 200) && (resp < 300)) { /* on any unrecognized 2XX response do the following */
20582
			} else if ((resp >= 200) && (resp < 300)) { /* on any unrecognized 2XX response do the following */
20284
				if (sipmethod == SIP_INVITE) {
20583
				if (sipmethod == SIP_INVITE) {
[+20] [20] 42 lines
[+20] [+] static void *sip_park_thread(void *stuff)
20327
	copy_request(&req, &d->req);
20626
	copy_request(&req, &d->req);
20328

    
   
20627

   
20329
	if (!transferee || !transferer) {
20628
	if (!transferee || !transferer) {
20330
		ast_log(LOG_ERROR, "Missing channels for parking! Transferer %s Transferee %s\n", transferer ? "<available>" : "<missing>", transferee ? "<available>" : "<missing>" );
20629
		ast_log(LOG_ERROR, "Missing channels for parking! Transferer %s Transferee %s\n", transferer ? "<available>" : "<missing>", transferee ? "<available>" : "<missing>" );
20331
		deinit_req(&d->req);
20630
		deinit_req(&d->req);
20332
		free(d);
20631
		ast_free(d);
20333
		return NULL;
20632
		return NULL;
20334
	}
20633
	}
20335
	ast_debug(4, "SIP Park: Transferer channel %s, Transferee %s\n", transferer->name, transferee->name);
20634
	ast_debug(4, "SIP Park: Transferer channel %s, Transferee %s\n", transferer->name, transferee->name);
20336

    
   
20635

   
20337
	if (ast_do_masquerade(transferee)) {
20636
	if (ast_do_masquerade(transferee)) {
20338
		ast_log(LOG_WARNING, "Masquerade failed.\n");
20637
		ast_log(LOG_WARNING, "Masquerade failed.\n");
20339
		transmit_response(transferer->tech_pvt, "503 Internal error", &req);
20638
		transmit_response(transferer->tech_pvt, "503 Internal error", &req);
20340
		deinit_req(&d->req);
20639
		deinit_req(&d->req);
20341
		free(d);
20640
		ast_free(d);
20342
		return NULL;
20641
		return NULL;
20343
	}
20642
	}
20344

    
   
20643

   
20345
	res = ast_park_call(transferee, transferer, 0, d->parkexten, &ext);
20644
	res = ast_park_call(transferee, transferer, 0, d->parkexten, &ext);
20346
	

   
20347

    
   
20645

   
20348
#ifdef WHEN_WE_KNOW_THAT_THE_CLIENT_SUPPORTS_MESSAGE
20646
#ifdef WHEN_WE_KNOW_THAT_THE_CLIENT_SUPPORTS_MESSAGE
20349
	if (!res) {
20647
	if (!res) {
20350
		transmit_message_with_text(transferer->tech_pvt, "Unable to park call.\n", 0);
20648
		transmit_message_with_text(transferer->tech_pvt, "Unable to park call.\n", 0, 0);
20351
	} else {
20649
	} else {
20352
		/* Then tell the transferer what happened */
20650
		/* Then tell the transferer what happened */
20353
		sprintf(buf, "Call parked on extension '%d'", ext);
20651
		sprintf(buf, "Call parked on extension '%d'", ext);
20354
		transmit_message_with_text(transferer->tech_pvt, buf, 0);
20652
		transmit_message_with_text(transferer->tech_pvt, buf, 0, 0);
20355
	}
20653
	}
20356
#endif
20654
#endif
20357

    
   
20655

   
20358
	/* Any way back to the current call??? */
20656
	/* Any way back to the current call??? */
20359
	/* Transmit response to the REFER request */
20657
	/* Transmit response to the REFER request */
20360
	transmit_response(transferer->tech_pvt, "202 Accepted", &req);

   
20361
	if (!res)	{
20658
	if (!res)	{
20362
		/* Transfer succeeded */
20659
		/* Transfer succeeded */
20363
		append_history(transferer->tech_pvt, "SIPpark", "Parked call on %d", ext);
20660
		append_history(transferer->tech_pvt, "SIPpark", "Parked call on %d", ext);
20364
		transmit_notify_with_sipfrag(transferer->tech_pvt, d->seqno, "200 OK", TRUE);
20661
		transmit_notify_with_sipfrag(transferer->tech_pvt, d->seqno, "200 OK", TRUE);
20365
		transferer->hangupcause = AST_CAUSE_NORMAL_CLEARING;
20662
		transferer->hangupcause = AST_CAUSE_NORMAL_CLEARING;
[+20] [20] 4 lines
[+20] static void *sip_park_thread(void *stuff)
20370
		append_history(transferer->tech_pvt, "SIPpark", "Parking failed\n");
20667
		append_history(transferer->tech_pvt, "SIPpark", "Parking failed\n");
20371
		ast_debug(1, "SIP Call parked failed \n");
20668
		ast_debug(1, "SIP Call parked failed \n");
20372
		/* Do not hangup call */
20669
		/* Do not hangup call */
20373
	}
20670
	}
20374
	deinit_req(&d->req);
20671
	deinit_req(&d->req);
20375
	free(d);
20672
	ast_free(d);
20376
	return NULL;
20673
	return NULL;
20377
}
20674
}
20378

    
   
20675

   
20379
/*! \brief Park a call using the subsystem in res_features.c
20676
/*! \brief Park a call using the subsystem in res_features.c
20380
	This is executed in a separate thread
20677
	This is executed in a separate thread
[+20] [20] 70 lines
[+20] [+] static int sip_park(struct ast_channel *chan1, struct ast_channel *chan2, struct sip_request *req, int seqno, char *parkexten)
20451
		if (!transferee) {
20748
		if (!transferee) {
20452
			ast_debug(1, "No transferee channel, giving up parking\n");
20749
			ast_debug(1, "No transferee channel, giving up parking\n");
20453
		}
20750
		}
20454
		return -1;
20751
		return -1;
20455
	}
20752
	}
20456
	if ((d = ast_calloc(1, sizeof(*d)))) {
20753
	if (!(d = ast_calloc(1, sizeof(*d)))) {

    
   
20754
		return -1;

    
   
20755
	}
20457

    
   
20756

   
20458
		/* Save original request for followup */
20757
	/* Save original request for followup */
20459
		copy_request(&d->req, req);
20758
	copy_request(&d->req, req);
20460
		d->chan1 = transferee;	/* Transferee */
20759
	d->chan1 = transferee;	/* Transferee */
20461
		d->chan2 = transferer;	/* Transferer */
20760
	d->chan2 = transferer;	/* Transferer */
20462
		d->seqno = seqno;
20761
	d->seqno = seqno;
20463
		d->parkexten = parkexten;
20762
	d->parkexten = parkexten;
20464
		if (ast_pthread_create_detached_background(&th, NULL, sip_park_thread, d) < 0) {
20763
	if (ast_pthread_create_detached_background(&th, NULL, sip_park_thread, d) < 0) {
20465
			/* Could not start thread */
20764
		/* Could not start thread */
20466
			deinit_req(&d->req);
20765
		deinit_req(&d->req);
20467
			ast_free(d);	/* We don't need it anymore. If thread is created, d will be free'd
20766
		ast_free(d);	/* We don't need it anymore. If thread is created, d will be free'd
20468
					   by sip_park_thread() */
20767
				   by sip_park_thread() */
20469
			return 0;
Moved to 28337

   
20470
		}
Moved to 28338

   
20471
	}

   
20472
	return -1;
20768
		return -1;
20473
}
20769
	}
Moved from 20469

    
   
20770
	return 0;
Moved from 20470

    
   
20771
}
20474

    
   
20772

   
20475
/*! \brief Turn off generator data
20773
/*! \brief Turn off generator data
20476
	XXX Does this function belong in the SIP channel?
20774
	XXX Does this function belong in the SIP channel?
20477
*/
20775
*/
20478
static void ast_quiet_chan(struct ast_channel *chan)
20776
static void ast_quiet_chan(struct ast_channel *chan)
[+20] [20] 9 lines
[+20] static int sip_park(struct ast_channel *chan1, struct ast_channel *chan2, struct sip_request *req, int seqno, char *parkexten)
20488
/*! \brief Attempt transfer of SIP call
20786
/*! \brief Attempt transfer of SIP call
20489
	This fix for attended transfers on a local PBX */
20787
	This fix for attended transfers on a local PBX */
20490
static int attempt_transfer(struct sip_dual *transferer, struct sip_dual *target)
20788
static int attempt_transfer(struct sip_dual *transferer, struct sip_dual *target)
20491
{
20789
{
20492
	int res = 0;
20790
	int res = 0;
20493
	struct ast_channel *peera = NULL,	
20791
	struct ast_channel *peera = NULL,
20494
		*peerb = NULL,
20792
		*peerb = NULL,
20495
		*peerc = NULL,
20793
		*peerc = NULL,
20496
		*peerd = NULL;
20794
		*peerd = NULL;
20497

    
   
20795

   
20498

    
   
20796

   
20499
	/* We will try to connect the transferee with the target and hangup
20797
	/* We will try to connect the transferee with the target and hangup
20500
	   all channels to the transferer */	
20798
	   all channels to the transferer */
20501
	ast_debug(4, "Sip transfer:--------------------\n");
20799
	ast_debug(4, "Sip transfer:--------------------\n");
20502
	if (transferer->chan1)
20800
	if (transferer->chan1)
20503
		ast_debug(4, "-- Transferer to PBX channel: %s State %s\n", transferer->chan1->name, ast_state2str(transferer->chan1->_state));
20801
		ast_debug(4, "-- Transferer to PBX channel: %s State %s\n", transferer->chan1->name, ast_state2str(transferer->chan1->_state));
20504
	else
20802
	else
20505
		ast_debug(4, "-- No transferer first channel - odd??? \n");
20803
		ast_debug(4, "-- No transferer first channel - odd??? \n");
[+20] [20] 24 lines
[+20] static int attempt_transfer(struct sip_dual *transferer, struct sip_dual *target)
20530
		ast_debug(3, "SIP transfer: Three channels to handle\n");
20828
		ast_debug(3, "SIP transfer: Three channels to handle\n");
20531
	}
20829
	}
20532

    
   
20830

   
20533
	if (peera && peerb && peerc && (peerb != peerc)) {
20831
	if (peera && peerb && peerc && (peerb != peerc)) {
20534
		ast_quiet_chan(peera);		/* Stop generators */
20832
		ast_quiet_chan(peera);		/* Stop generators */
20535
		ast_quiet_chan(peerb);	
20833
		ast_quiet_chan(peerb);
20536
		ast_quiet_chan(peerc);
20834
		ast_quiet_chan(peerc);
20537
		if (peerd)
20835
		if (peerd)
20538
			ast_quiet_chan(peerd);
20836
			ast_quiet_chan(peerd);
20539

    
   
20837

   
20540
		ast_debug(4, "SIP transfer: trying to masquerade %s into %s\n", peerc->name, peerb->name);
20838
		ast_debug(4, "SIP transfer: trying to masquerade %s into %s\n", peerc->name, peerb->name);
[+20] [20] 108 lines
[+20] [+] static int handle_request_notify(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, int seqno, const char *e)
20649

    
   
20947

   
20650
	if( (sep = strchr(event, ';')) ) {	/* XXX bug here - overwriting string ? */
20948
	if( (sep = strchr(event, ';')) ) {	/* XXX bug here - overwriting string ? */
20651
		*sep++ = '\0';
20949
		*sep++ = '\0';
20652
		eventid = sep;
20950
		eventid = sep;
20653
	}
20951
	}
20654
	
20952

   
20655
	if (sipdebug)
20953
	if (sipdebug)
20656
		ast_debug(2, "Got NOTIFY Event: %s\n", event);
20954
		ast_debug(2, "Got NOTIFY Event: %s\n", event);
20657

    
   
20955

   
20658
	if (!strcmp(event, "refer")) {
20956
	if (!strcmp(event, "refer")) {
20659
		/* Save nesting depth for now, since there might be other events we will
20957
		/* Save nesting depth for now, since there might be other events we will
[+20] [20] 9 lines
[+20] static int handle_request_notify(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, int seqno, const char *e)
20669
		/* EventID for each transfer... EventID is basically the REFER cseq
20967
		/* EventID for each transfer... EventID is basically the REFER cseq
20670

    
   
20968

   
20671
		 We are getting notifications on a call that we transfered
20969
		 We are getting notifications on a call that we transfered
20672
		 We should hangup when we are getting a 200 OK in a sipfrag
20970
		 We should hangup when we are getting a 200 OK in a sipfrag
20673
		 Check if we have an owner of this event */
20971
		 Check if we have an owner of this event */
20674
		
20972

   
20675
		/* Check the content type */
20973
		/* Check the content type */
20676
		if (strncasecmp(get_header(req, "Content-Type"), "message/sipfrag", strlen("message/sipfrag"))) {
20974
		if (strncasecmp(get_header(req, "Content-Type"), "message/sipfrag", strlen("message/sipfrag"))) {
20677
			/* We need a sipfrag */
20975
			/* We need a sipfrag */
20678
			transmit_response(p, "400 Bad request", req);
20976
			transmit_response(p, "400 Bad request", req);
20679
			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
20977
			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
[+20] [20] 116 lines
[+20] static int handle_request_notify(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, int seqno, const char *e)
20796
			transmit_response(p, "489 Bad event", req);
21094
			transmit_response(p, "489 Bad event", req);
20797
			res = -1;
21095
			res = -1;
20798
		}
21096
		}
20799
	} else if (!strcmp(event, "keep-alive")) {
21097
	} else if (!strcmp(event, "keep-alive")) {
20800
		 /* Used by Sipura/Linksys for NAT pinhole,
21098
		 /* Used by Sipura/Linksys for NAT pinhole,
20801
		  * just confirm that we recieved the packet. */
21099
		  * just confirm that we received the packet. */
20802
		transmit_response(p, "200 OK", req);
21100
		transmit_response(p, "200 OK", req);
20803
	} else if (!strcmp(event, "call-completion")) {
21101
	} else if (!strcmp(event, "call-completion")) {
20804
		res = handle_cc_notify(p, req);
21102
		res = handle_cc_notify(p, req);
20805
	} else {
21103
	} else {
20806
		/* We don't understand this event. */
21104
		/* We don't understand this event. */
[+20] [20] 463 lines
[+20] [+] static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct ast_sockaddr *addr, int *recount, const char *e, int *nounlock)
21270

    
   
21568

   
21271
		if (sipdebug)
21569
		if (sipdebug)
21272
			ast_debug(3, "INVITE part of call transfer. Replaces [%s]\n", p_replaces);
21570
			ast_debug(3, "INVITE part of call transfer. Replaces [%s]\n", p_replaces);
21273
		/* Create a buffer we can manipulate */
21571
		/* Create a buffer we can manipulate */
21274
		replace_id = ast_strdupa(p_replaces);
21572
		replace_id = ast_strdupa(p_replaces);
21275
		ast_uri_decode(replace_id);
21573
		ast_uri_decode(replace_id, ast_uri_sip_user);
21276

    
   
21574

   
21277
		if (!p->refer && !sip_refer_allocate(p)) {
21575
		if (!p->refer && !sip_refer_allocate(p)) {
21278
			transmit_response_reliable(p, "500 Server Internal Error", req);
21576
			transmit_response_reliable(p, "500 Server Internal Error", req);
21279
			append_history(p, "Xfer", "INVITE/Replace Failed. Out of memory.");
21577
			append_history(p, "Xfer", "INVITE/Replace Failed. Out of memory.");
21280
			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
21578
			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
[+20] [20] 166 lines
[+20] static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct ast_sockaddr *addr, int *recount, const char *e, int *nounlock)
21447
					res = -1;
21745
					res = -1;
21448
					goto request_invite_cleanup;
21746
					goto request_invite_cleanup;
21449
				}
21747
				}
21450
				ast_queue_control(p->owner, AST_CONTROL_SRCUPDATE);
21748
				ast_queue_control(p->owner, AST_CONTROL_SRCUPDATE);
21451
			} else {
21749
			} else {
21452
				p->jointcapability = p->capability;
21750
				ast_format_cap_copy(p->jointcaps, p->caps);
21453
				ast_debug(1, "Hm....  No sdp for the moment\n");
21751
				ast_debug(1, "Hm....  No sdp for the moment\n");
21454
				/* Some devices signal they want to be put off hold by sending a re-invite
21752
				/* Some devices signal they want to be put off hold by sending a re-invite
21455
				   *without* an SDP, which is supposed to mean "Go back to your state"
21753
				   *without* an SDP, which is supposed to mean "Go back to your state"
21456
				   and since they put os on remote hold, we go back to off hold */
21754
				   and since they put os on remote hold, we go back to off hold */
21457
				if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) {
21755
				if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) {
[+20] [20] 71 lines
[+20] static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct ast_sockaddr *addr, int *recount, const char *e, int *nounlock)
21529
				ast_debug(1, "No compatible codecs for this SIP call.\n");
21827
				ast_debug(1, "No compatible codecs for this SIP call.\n");
21530
				res = -1;
21828
				res = -1;
21531
				goto request_invite_cleanup;
21829
				goto request_invite_cleanup;
21532
			}
21830
			}
21533
		} else {	/* No SDP in invite, call control session */
21831
		} else {	/* No SDP in invite, call control session */
21534
			p->jointcapability = p->capability;
21832
			ast_format_cap_copy(p->jointcaps, p->caps);
21535
			ast_debug(2, "No SDP in Invite, third party call control\n");
21833
			ast_debug(2, "No SDP in Invite, third party call control\n");
21536
		}
21834
		}
21537

    
   
21835

   
21538
		/* Queue NULL frame to prod ast_rtp_bridge if appropriate */
21836
		/* Queue NULL frame to prod ast_rtp_bridge if appropriate */
21539
		/* This seems redundant ... see !p-owner above */
21837
		/* This seems redundant ... see !p-owner above */
[+20] [20] 42 lines