Review Board 1.7.16


WebSocket SIP Support

Review Request #2008 - Created July 2, 2012 and submitted

Joshua Colp
websocket-sip
Reviewers
asterisk-dev
Asterisk
These changes add WebSocket transport support to chan_sip and fix some minor issues uncovered in the stack when used with WebSocket as a transport.
Tested using sipml5 javascript SIP stack. Confirmed protocol traffic is correct, that connections are shutdown properly when they should be, that registration works, and that calling works.
/trunk/channels/chan_sip.c
Diff Revision 2 Diff Revision 3
[20] 7300 lines
[+20] [+] static int sip_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
7301
			ast_aoc_destroy_decoded(decoded);
7301
			ast_aoc_destroy_decoded(decoded);
7302
		}
7302
		}
7303
		break;
7303
		break;
7304
	case AST_CONTROL_UPDATE_RTP_PEER: /* Absorb this since it is handled by the bridge */
7304
	case AST_CONTROL_UPDATE_RTP_PEER: /* Absorb this since it is handled by the bridge */
7305
		break;
7305
		break;
7306
	case AST_CONTROL_FLASH: /* Absorb this since it is irrelevant to SIP. */
7306
	case AST_CONTROL_FLASH: /* We don't currently handle AST_CONTROL_FLASH here, but it is expected, so we don't need to warn either. */

    
   
7307
		res = -1;
7307
		break;
7308
		break;
7308
	case AST_CONTROL_PVT_CAUSE_CODE: /* these should be handled by the code in channel.c */
7309
	case AST_CONTROL_PVT_CAUSE_CODE: /* these should be handled by the code in channel.c */
7309
	case -1:
7310
	case -1:
7310
		res = -1;
7311
		res = -1;
7311
		break;
7312
		break;
[+20] [20] 2163 lines
[+20] [+] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
9475
				/* Check number of ports offered for stream */
9476
				/* Check number of ports offered for stream */
9476
				if (numberofports > 1) {
9477
				if (numberofports > 1) {
9477
					ast_log(LOG_WARNING, "%d ports offered for audio media, not supported by Asterisk. Will try anyway...\n", numberofports);
9478
					ast_log(LOG_WARNING, "%d ports offered for audio media, not supported by Asterisk. Will try anyway...\n", numberofports);
9478
				}
9479
				}
9479

    
   
9480

   
9480
				if (!strcmp(protocol, "SAVP") || !strcmp(protocol, "SAVPF")) {
9481
				if (!strcmp(protocol, "SAVP") || (!strcmp(protocol, "SAVPF") && ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF))) {
9481
					secure_audio = 1;
9482
					secure_audio = 1;

    
   
9483
				} else if ((!strcmp(protocol, "AVPF") || !strcmp(protocol, "SAVPF")) && !ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF)) {

    
   
9484
					ast_log(LOG_WARNING, "Received AVPF profile in audio offer but AVPF is not enabled: %s\n", m);

    
   
9485
					continue;
9482
				} else if (strcmp(protocol, "AVP") && strcmp(protocol, "AVPF")) {
9486
				} else if (strcmp(protocol, "AVP") && strcmp(protocol, "AVPF")) {
9483
					ast_log(LOG_WARNING, "Unknown RTP profile in audio offer: %s\n", m);
9487
					ast_log(LOG_WARNING, "Unknown RTP profile in audio offer: %s\n", m);
9484
					continue;
9488
					continue;
9485
				}
9489
				}
9486

    
   
9490

   
[+20] [20] 48 lines
[+20] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
9535
				/* Check number of ports offered for stream */
9539
				/* Check number of ports offered for stream */
9536
				if (numberofports > 1) {
9540
				if (numberofports > 1) {
9537
					ast_log(LOG_WARNING, "%d ports offered for video stream, not supported by Asterisk. Will try anyway...\n", numberofports);
9541
					ast_log(LOG_WARNING, "%d ports offered for video stream, not supported by Asterisk. Will try anyway...\n", numberofports);
9538
				}
9542
				}
9539

    
   
9543

   
9540
				if (!strcmp(protocol, "SAVP") || !strcmp(protocol, "SAVPF")) {
9544
				if (!strcmp(protocol, "SAVP") || (!strcmp(protocol, "SAVPF") && ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF))) {
9541
					secure_video = 1;
9545
					secure_video = 1;

    
   
9546
				} else if ((!strcmp(protocol, "AVPF") || !strcmp(protocol, "SAVPF")) && !ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF)) {

    
   
9547
					ast_log(LOG_WARNING, "Received AVPF profile in video offer but AVPF is not enabled: %s\n", m);

    
   
9548
					continue;
9542
				} else if (strcmp(protocol, "AVP") && strcmp(protocol, "AVPF")) {
9549
				} else if (strcmp(protocol, "AVP") && strcmp(protocol, "AVPF")) {
9543
					ast_log(LOG_WARNING, "Unknown RTP profile in video offer: %s\n", m);
9550
					ast_log(LOG_WARNING, "Unknown RTP profile in video offer: %s\n", m);
9544
					continue;
9551
					continue;
9545
				}
9552
				}
9546

    
   
9553

   
[+20] [20] 7931 lines
[+20] [+] static void receive_message(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
17478
	struct ast_msg *msg;
17485
	struct ast_msg *msg;
17479
	int res;
17486
	int res;
17480
	char *from;
17487
	char *from;
17481
	char *to;
17488
	char *to;
17482
	char from_name[50];
17489
	char from_name[50];

    
   
17490
	char stripped[SIPBUFSIZE];
17483

    
   
17491

   
17484
	if (strncmp(content_type, "text/plain", strlen("text/plain"))) { /* No text/plain attachment */
17492
	if (strncmp(content_type, "text/plain", strlen("text/plain"))) { /* No text/plain attachment */
17485
		transmit_response(p, "415 Unsupported Media Type", req); /* Good enough, or? */
17493
		transmit_response(p, "415 Unsupported Media Type", req); /* Good enough, or? */
17486
		if (!p->owner) {
17494
		if (!p->owner) {
17487
			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
17495
			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
[+20] [20] 143 lines
[+20] static void receive_message(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
17631
	res |= ast_msg_set_var(msg, "SIP_RECVADDR", ast_sockaddr_stringify(&p->recv));
17639
	res |= ast_msg_set_var(msg, "SIP_RECVADDR", ast_sockaddr_stringify(&p->recv));
17632
	if (!ast_strlen_zero(p->peername)) {
17640
	if (!ast_strlen_zero(p->peername)) {
17633
		res |= ast_msg_set_var(msg, "SIP_PEERNAME", p->peername);
17641
		res |= ast_msg_set_var(msg, "SIP_PEERNAME", p->peername);
17634
	}
17642
	}
17635

    
   
17643

   

    
   
17644
	ast_copy_string(stripped, sip_get_header(req, "Contact"), sizeof(stripped));

    
   
17645
	res |= ast_msg_set_var(msg, "SIP_FULLCONTACT", get_in_brackets(stripped));

    
   
17646

   
17636
	res |= ast_msg_set_exten(msg, "%s", p->exten);
17647
	res |= ast_msg_set_exten(msg, "%s", p->exten);
17637
	res |= set_message_vars_from_req(msg, req);
17648
	res |= set_message_vars_from_req(msg, req);
17638

    
   
17649

   
17639
	if (res) {
17650
	if (res) {
17640
		ast_msg_destroy(msg);
17651
		ast_msg_destroy(msg);
[+20] [20] 7961 lines
[+20] [+] static int block_msg_header(const char *header_name)
25602
		"Contact",
25613
		"Contact",
25603
		"Call-ID",
25614
		"Call-ID",
25604
		"CSeq",
25615
		"CSeq",
25605
		"Allow",
25616
		"Allow",
25606
		"Content-Length",
25617
		"Content-Length",

    
   
25618
		"Request-URI",
25607
	};
25619
	};
25608

    
   
25620

   
25609
	for (idx = 0; idx < ARRAY_LEN(hdr); ++idx) {
25621
	for (idx = 0; idx < ARRAY_LEN(hdr); ++idx) {
25610
		if (!strcasecmp(header_name, hdr[idx])) {
25622
		if (!strcasecmp(header_name, hdr[idx])) {
25611
			/* Block addition of this header. */
25623
			/* Block addition of this header. */
[+20] [20] 17 lines
[+20] [+] static int sip_msg_send(const struct ast_msg *msg, const char *to, const char *from)
25629

    
   
25641

   
25630
	if (!(pvt = sip_alloc(NULL, NULL, 0, SIP_MESSAGE, NULL, NULL))) {
25642
	if (!(pvt = sip_alloc(NULL, NULL, 0, SIP_MESSAGE, NULL, NULL))) {
25631
		return -1;
25643
		return -1;
25632
	}
25644
	}
25633

    
   
25645

   

    
   
25646
        for (iter = ast_msg_var_iterator_init(msg);

    
   
25647
	     ast_msg_var_iterator_next(msg, iter, &var, &val);

    
   
25648
	     ast_msg_var_unref_current(iter)) {

    
   
25649
		if (!strcasecmp(var, "Request-URI")) {

    
   
25650
			ast_string_field_set(pvt, fullcontact, val);

    
   
25651
			ast_msg_var_unref_current(iter);

    
   
25652
			break;

    
   
25653
		}

    
   
25654
	}

    
   
25655
	ast_msg_var_iterator_destroy(iter);

    
   
25656

   
25634
	to_uri = ast_strdupa(to);
25657
	to_uri = ast_strdupa(to);
25635
	to_uri = get_in_brackets(to_uri);
25658
	to_uri = get_in_brackets(to_uri);
25636
	parse_uri(to_uri, "sip:,sips:", &to_user, NULL, &to_host, NULL);
25659
	parse_uri(to_uri, "sip:,sips:", &to_user, NULL, &to_host, NULL);
25637

    
   
25660

   
25638
	if (ast_strlen_zero(to_host)) {
25661
	if (ast_strlen_zero(to_host)) {
[+20] [20] 7251 lines
/trunk/channels/sip/sdp_crypto.c
Diff Revision 2 Diff Revision 3
 
/trunk/channels/sip/security_events.c
Diff Revision 2 Diff Revision 3
 
/trunk/channels/sip/include/sip.h
Diff Revision 2 Diff Revision 3
 
/trunk/configs/sip.conf.sample
Diff Revision 2 Diff Revision 3
 
/trunk/include/asterisk/http_websocket.h
Diff Revision 2 Diff Revision 3
 
/trunk/res/res_http_websocket.c
Diff Revision 2 Diff Revision 3
 
  1. /trunk/channels/chan_sip.c: Loading...
  2. /trunk/channels/sip/sdp_crypto.c: Loading...
  3. /trunk/channels/sip/security_events.c: Loading...
  4. /trunk/channels/sip/include/sip.h: Loading...
  5. /trunk/configs/sip.conf.sample: Loading...
  6. /trunk/include/asterisk/http_websocket.h: Loading...
  7. /trunk/res/res_http_websocket.c: Loading...

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