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.

Changes between revision 3 and 4

1 2 3 4
1 2 3 4

  1. /trunk/channels/chan_sip.c: Loading...
/trunk/channels/chan_sip.c
Diff Revision 3 Diff Revision 4
[20] 9475 lines
[+20] [+] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
9476
				/* Check number of ports offered for stream */
9476
				/* Check number of ports offered for stream */
9477
				if (numberofports > 1) {
9477
				if (numberofports > 1) {
9478
					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);
9479
				}
9479
				}
9480

    
   
9480

   
9481
				if (!strcmp(protocol, "SAVP") || (!strcmp(protocol, "SAVPF") && ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF))) {
9481
				if (!strcmp(protocol, "SAVPF") && !ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF)) {

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

    
   
9483
					continue;

    
   
9484
				} else if (!strcmp(protocol, "SAVP") && ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF)) {

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

    
   
9486
					continue;

    
   
9487
				} else if (!strcmp(protocol, "SAVP") || !strcmp(protocol, "SAVPF")) {
9482
					secure_audio = 1;
9488
					secure_audio = 1;
9483
				} else if ((!strcmp(protocol, "AVPF") || !strcmp(protocol, "SAVPF")) && !ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF)) {
9489
				} else if (!strcmp(protocol, "AVPF") && !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);
9490
					ast_log(LOG_WARNING, "Received AVPF profile in audio offer but AVPF is not enabled: %s\n", m);
9485
					continue;
9491
					continue;

    
   
9492
				} else if (!strcmp(protocol, "AVP") && ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF)) {

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

    
   
9494
					continue;
9486
				} else if (strcmp(protocol, "AVP") && strcmp(protocol, "AVPF")) {
9495
				} else if (strcmp(protocol, "AVP") && strcmp(protocol, "AVPF")) {
9487
					ast_log(LOG_WARNING, "Unknown RTP profile in audio offer: %s\n", m);
9496
					ast_log(LOG_WARNING, "Unknown RTP profile in audio offer: %s\n", m);
9488
					continue;
9497
					continue;
9489
				}
9498
				}
9490

    
   
9499

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

    
   
9552

   
9544
				if (!strcmp(protocol, "SAVP") || (!strcmp(protocol, "SAVPF") && ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF))) {
9553
				if (!strcmp(protocol, "SAVPF") && !ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF)) {

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

    
   
9555
					continue;

    
   
9556
				} else if (!strcmp(protocol, "SAVP") && ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF)) {

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

    
   
9558
					continue;

    
   
9559
				} else if (!strcmp(protocol, "SAVP") || !strcmp(protocol, "SAVPF")) {
9545
					secure_video = 1;
9560
					secure_video = 1;
9546
				} else if ((!strcmp(protocol, "AVPF") || !strcmp(protocol, "SAVPF")) && !ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF)) {
9561
				} else if (!strcmp(protocol, "AVPF") && !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);
9562
					ast_log(LOG_WARNING, "Received AVPF profile in video offer but AVPF is not enabled: %s\n", m);
9548
					continue;
9563
					continue;

    
   
9564
				} else if (!strcmp(protocol, "AVP") && ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF)) {

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

    
   
9566
					continue;
9549
				} else if (strcmp(protocol, "AVP") && strcmp(protocol, "AVPF")) {
9567
				} else if (strcmp(protocol, "AVP") && strcmp(protocol, "AVPF")) {
9550
					ast_log(LOG_WARNING, "Unknown RTP profile in video offer: %s\n", m);
9568
					ast_log(LOG_WARNING, "Unknown RTP profile in video offer: %s\n", m);
9551
					continue;
9569
					continue;
9552
				}
9570
				}
9553

    
   
9571

   
[+20] [20] 25 lines
[+20] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
9579
				goto process_sdp_cleanup;
9597
				goto process_sdp_cleanup;
9580
			}
9598
			}
9581
		}
9599
		}
9582
		/* Check for 'text' media offer */
9600
		/* Check for 'text' media offer */
9583
		else if (strncmp(m, "text ", 5) == 0) {
9601
		else if (strncmp(m, "text ", 5) == 0) {
9584
			if ((sscanf(m, "text %30u/%30u RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) ||
9602
			if ((sscanf(m, "text %30u/%30u RTP/%s %n", &x, &numberofports, protocol, &len) == 2 && len > 0) ||
9585
			    (sscanf(m, "text %30u RTP/AVP %n", &x, &len) == 1 && len > 0)) {
9603
			    (sscanf(m, "text %30u RTP/%s %n", &x, protocol, &len) == 1 && len > 0)) {
9586
				codecs = m + len;
9604
				codecs = m + len;
9587
				/* produce zero-port m-line since it may be needed later
9605
				/* produce zero-port m-line since it may be needed later
9588
				 * length is "m=text 0 RTP/AVP " + codecs + "\0" */
9606
				 * length is "m=text 0 RTP/" + protocol + " " + codecs + "\0" */
9589
				if (!(offer->decline_m_line = ast_malloc(17 + strlen(codecs) + 1))) {
9607
				if (!(offer->decline_m_line = ast_malloc(13 + strlen(protocol) + 1 + strlen(codecs) + 1))) {
9590
					ast_log(LOG_WARNING, "Failed to allocate memory for SDP offer declination\n");
9608
					ast_log(LOG_WARNING, "Failed to allocate memory for SDP offer declination\n");
9591
					res = -1;
9609
					res = -1;
9592
					goto process_sdp_cleanup;
9610
					goto process_sdp_cleanup;
9593
				}
9611
				}
9594
				/* guaranteed to be exactly the right length */
9612
				/* guaranteed to be exactly the right length */
9595
				sprintf(offer->decline_m_line, "m=text 0 RTP/AVP %s", codecs);
9613
				sprintf(offer->decline_m_line, "m=text 0 RTP/%s %s", protocol, codecs);
9596

    
   
9614

   
9597
				if (x == 0) {
9615
				if (x == 0) {
9598
					ast_log(LOG_WARNING, "Ignoring text stream offer because port number is zero\n");
9616
					ast_log(LOG_WARNING, "Ignoring text stream offer because port number is zero\n");
9599
					continue;
9617
					continue;
9600
				}
9618
				}
9601

    
   
9619

   
9602
				/* Check number of ports offered for stream */
9620
				/* Check number of ports offered for stream */
9603
				if (numberofports > 1) {
9621
				if (numberofports > 1) {
9604
					ast_log(LOG_WARNING, "%d ports offered for text stream, not supported by Asterisk. Will try anyway...\n", numberofports);
9622
					ast_log(LOG_WARNING, "%d ports offered for text stream, not supported by Asterisk. Will try anyway...\n", numberofports);
9605
				}
9623
				}
9606

    
   
9624

   

    
   
9625
				if (!strcmp(protocol, "AVPF") && !ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF)) {

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

    
   
9627
					continue;

    
   
9628
				} else if (!strcmp(protocol, "AVP") && ast_test_flag(&p->flags[2], SIP_PAGE3_USE_AVPF)) {

    
   
9629
					ast_log(LOG_WARNING, "Received AVP profile in text offer but AVPF is enabled: %s\n", m);

    
   
9630
					continue;

    
   
9631
				} else if (strcmp(protocol, "AVP") && strcmp(protocol, "AVPF")) {

    
   
9632
					ast_log(LOG_WARNING, "Unknown RTP profile in text offer: %s\n", m);

    
   
9633
					continue;

    
   
9634
				}

    
   
9635

   
9607
				if (has_media_stream(p, SDP_TEXT)) {
9636
				if (has_media_stream(p, SDP_TEXT)) {
9608
					ast_log(LOG_WARNING, "Declining non-primary text stream: %s\n", m);
9637
					ast_log(LOG_WARNING, "Declining non-primary text stream: %s\n", m);
9609
					continue;
9638
					continue;
9610
				}
9639
				}
9611

    
   
9640

   
[+20] [20] 23301 lines
  1. /trunk/channels/chan_sip.c: Loading...

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