Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Revision:
112:6ae726539ab9
Parent:
109:a5b8264ffbbc
Child:
113:db67ae00550e
--- a/sip.cpp	Tue Apr 07 18:26:21 2015 +0000
+++ b/sip.cpp	Mon Apr 13 12:16:21 2015 +0000
@@ -15,7 +15,7 @@
     sock.init();
     sock.bind( this->my_port );
 }
-
+/*
 Sip::Sip( char * server_ip, int server_port, char * my_ip, int my_port, int my_ext, int peer_ext, int id ){
     this->id = id;
     strncpy( this->server_ip, server_ip, 20 );
@@ -24,7 +24,10 @@
     strncpy( this->my_ip, my_ip, 20 );
     this->my_ip[19] = 0;
     this->my_port = my_port;
-    this->my_rtp_port = fill_random_rtp_port();
+    //this->my_rtp_port = fill_random_rtp_port();
+    this->my_rtp_port = 0;
+    if( debug_rtp ) debug_msg("new with rtp port %d ", this->my_rtp_port );
+    
     this->my_ext = my_ext;
     itoa( this->my_ext, this->my_display, 10 );
     this->peer_ext = peer_ext;
@@ -49,6 +52,7 @@
     
     sip_new_counter++;
 }
+*/
   
 Sip::Sip( int id, uint16_t my_port ){
     FILE * fp = NULL;
@@ -57,6 +61,8 @@
     if( debug_sip ) debug_msg("Building SIP ext :: %d | Port :: %d", id, my_port );
     
     this->id = id;
+    this->my_ext = id;
+    this->my_port = my_port;
         
     fp = fopen( "/qspi/serverip.txt", "r");
     if( fp == NULL){
@@ -120,12 +126,12 @@
     
     this->my_ip[ 15 ] = '\0';
     
-    this->my_port = my_port;
     if( debug_sip ) debug_msg("Fixado na porta %d", this->my_port );
     
-    this->my_rtp_port = fill_random_rtp_port();
-    this->my_ext = id;
     itoa( this->my_ext, this->my_display, 10 );
+    
+    this->my_rtp_port = 0;
+    if( debug_rtp ) debug_msg("new with rtp port %d ", this->my_rtp_port );
 
     fp = fopen( "/qspi/peerext.txt", "r");
     if( fp == NULL ) {
@@ -338,6 +344,10 @@
     fill_random16h( branch );
     fill_random( tag,18 );
     fill_random16h( callid );
+    
+    debug_msg("branch :: %s", branch );
+    debug_msg("tag :: %s", tag );
+    debug_msg("callid :: %s", callid );
  
     strcpy( last_invite_tag,tag );
     strcpy( last_invite_callid, callid );
@@ -363,7 +373,7 @@
     strcat( header, "." );
     itoa( 0, itoa_buffer, 10 );
     strcat( header, itoa_buffer );
-    strcat( header, "/UDP"  ); // isso que dizer qu eue sempre coloco /UDP:192, quando deveria ser /UDP<0x20>192...
+    strcat( header, "/UDP "  ); // isso que dizer qu eue sempre coloco /UDP:192, quando deveria ser /UDP<0x20>192...
     strcat( header, this->my_ip );
     strcat( header, ":" );
     itoa( this->my_port, itoa_buffer, 10 );
@@ -422,7 +432,7 @@
     strcat( header, SVNREV );
     strcat( header, "\r\n" );
     strcat( header, "Expires: " );
-    itoa( 70, itoa_buffer, 10 );
+    itoa( 71, itoa_buffer, 10 );
     strcat( header, itoa_buffer );
     strcat( header, "\r\n" );
     strcat( header, SIP_ALLOW );
@@ -457,9 +467,18 @@
     itoa( 0, itoa_buffer, 10 );
     strcat( body, itoa_buffer );
     strcat( body, "\r\n" );
+    
+    
+    this->my_rtp_port = fill_random_rtp_port();
+    sprintf( itoa_buffer,"i=UDP %d\r\n", this->my_rtp_port );
+    strcat( body, itoa_buffer );
     strcat( body, "m=audio " );
     itoa( this->my_rtp_port, itoa_buffer, 10 );
-    debug_msg("my_rtp_port( %d )", my_rtp_port );
+    strcat( body, itoa_buffer );
+    
+    if( debug_rtp ) debug_msg("Invite PKG with rtp poOort ( %d - %s )", this->my_rtp_port, itoa_buffer );
+    
+    /*
     if ( chicago )
     {
         chicago = false;
@@ -479,7 +498,7 @@
             strcat( body, itoa_buffer );
         }
     }
-    
+    */
     strcat( body, " RTP/AVP " );
     itoa( 8, itoa_buffer, 10 );
     strcat( body, itoa_buffer );
@@ -913,9 +932,12 @@
 int Sip::get_my_rtp_port( void ){
     return this->my_rtp_port;
 }
-inline int Sip::fill_random_rtp_port(){  
-    // o range [ 16384 - 32767 ] eh configuravel no server
-    return ( ( this->my_ext + 16384 ) );
+int Sip::fill_random_rtp_port ()
+{
+    static uint16_t port = 0;
+    port += 2;
+    port &= 0x7fe; // 0 to 2046, always even
+    return port + 16384;
 }
  
 void Sip::change_sip_server(){
@@ -1129,7 +1151,8 @@
                     if ( drop_ack_pkg )
                     {
                         debug_msg("Droped ack pkt to ast");
-                        return -73;
+                        //return -73;
+                        // nao faz sentido ter esse return por que na logica o resto eh processado
                     }
                         else
                     {
@@ -1142,7 +1165,7 @@
                 }
             }
         }
-        if( ( status == sip_trying ) || ( status == sip_ringing ) ){            
+        if( ( status == sip_trying ) || ( status == sip_ringing ) ){                
             //if( !( strncmp( buffer + 7, " 4", 2 ) ) ){
             if( sip_response >= 400 && sip_response < 700 ){
                 if( debug_invite ) {