![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
debugs removidos - ligacao em pares ok
Dependencies: EthernetInterface NTPClient mbed-rtos mbed
Fork of header_main by
Diff: sip.cpp
- Revision:
- 4:de46f0d9b14d
- Parent:
- 3:cd9148672e25
diff -r cd9148672e25 -r de46f0d9b14d sip.cpp --- a/sip.cpp Wed Sep 10 18:21:48 2014 +0000 +++ b/sip.cpp Thu Sep 11 14:23:47 2014 +0000 @@ -106,9 +106,11 @@ void Sip::registry(){ char out[ 1000 ]; + debug_msg("registrando -- %d", this->my_ext ); build_registry_package( buffer ); - sock.sendTo( sip_server, buffer, sizeof( buffer ) ); + int sent = sock.sendTo( sip_server, buffer, sizeof( buffer ) ); sock.receiveFrom( sip_server, buffer, sizeof( buffer ) ); + debug_msg(" Recebidos %d bytes para o o ext %d", sent, my_ext ); if( decode_gettag( (unsigned char *)buffer, "cseq: ", out ) ){ if(strlen( out ) > 7){ if(strcasecmp("options",out+strlen(out)-7) == 0){ @@ -120,56 +122,6 @@ } } -VZ_call * Sip::old_invite(){ - Timer t; - char buffer[ 1024 ]; - char callbox_string[ 32 ]; - itoa( get_id(), callbox_string, 10 ); - int cseq; - - build_invite_package( buffer, callbox_string, &cseq ); - sock.sendTo( sip_server, buffer, sizeof( buffer ) ); - - t.start(); - while( sock.receiveFrom( sip_server, buffer, sizeof( buffer ) ) < 1 ) { - if( t.read() > __INVITE_MAX_WAITING_TIME__ ) { /* Trying package */ - change_sip_server(); - t.reset(); - break; - } - } - while( sock.receiveFrom( sip_server, buffer, sizeof( buffer ) ) < 1 ) { - if( t.read() > __INVITE_MAX_WAITING_TIME__ ) { /* Ringing package */ - change_sip_server(); - t.reset(); - break; - } - } - int call_trying = 1; - while( call_trying-- ){ - while( sock.receiveFrom( sip_server, buffer, sizeof( buffer ) ) < 1 ) { - if( t.read() > __INVITE_MAX_WAITING_TIME__ ) { /* ok package */ - change_sip_server(); - t.reset(); - break; - } - } - wait( 3 ); - char * ref = strstr( buffer, "audio" ); - if( ref != NULL ){ - ref += 6; /*audio */ - ref = strtok( ref, " "); - VZ_call * call = new VZ_call( this->my_ext, this->my_rtp_port, this->peer_ext, atoi( ref ) ); - char ans[ 1024 ]; - build_ack_package( ans, ( unsigned char *)buffer ); - sock.sendTo( sip_server, ans, sizeof( ans ) ); - - return( call ); - } - } - return( NULL ); -} - VZ_call * Sip::invite(){ Timer t; char callbox_string[ 32 ]; @@ -190,7 +142,6 @@ sock.set_blocking( false, 5 ); - char buffer_eth_invite[ 1024 ]; int loop_times = 0; int received_loop_times = 0; Timer reconnect; @@ -202,26 +153,25 @@ VZ_call * call = NULL; while( t.read() < __INVITE_MAX_WAITING_TIME__ ){ loop_times++; - length = sock.receiveFrom( sip_server, buffer_eth_invite, sizeof( buffer_eth_invite ) ); + length = sock.receiveFrom( sip_server, buffer, sizeof( buffer ) ); if( length > 0 ){ reconnect.reset(); debug_msg("Pacotes recebidos :: %d", id_ ); - buffer_eth_invite[ length ] = 0; - debug_msg("-- %d :: %s --", id_++, buffer_eth_invite ); + buffer[ length ] = 0; received_loop_times++; if( ( status == sip_trying ) || ( status == sip_ringing ) ){ - if( !( strncasecmp( buffer_eth_invite + 12, "ok", strlen("ok") ) ) ){ + if( !( strncasecmp( buffer + 12, "ok", strlen("ok") ) ) ){ // tratar depois o esquema do Cseq :: debug_msg( "Cseq == %d", cseq ); set_status(status, sip_on_call); - char *ref = strstr( buffer_eth_invite, "audio" ); + char *ref = strstr( buffer, "audio" ); debug_msg("ok"); if( ref != NULL ){ ref += 6; // audio ref = strtok( ref, " "); if( call == NULL ) call = new VZ_call( this->my_ext, this->my_rtp_port, this->peer_ext, atoi( ref ) ); char ans[ 1024 ]; - build_ack_package( ans, ( unsigned char *)buffer_eth_invite ); + build_ack_package( ans, ( unsigned char *)buffer ); sock.sendTo( sip_server, ans, sizeof( ans ) ); debug_msg("Call alocada -- Sip::status::%d -- loop_times :: %d :: received_loop_times :: %d", status, loop_times, received_loop_times ); set_status( status, sip_on_call ); @@ -230,9 +180,9 @@ } } if( ( status == sip_trying ) || ( status == sip_ringing ) ){ - if( !( strncasecmp( buffer_eth_invite + 12, "Session Progress", strlen("Session Progress") ) ) ){ - char *ref = strstr( buffer_eth_invite, "audio" ); + if( !( strncasecmp( buffer + 12, "Session Progress", strlen("Session Progress") ) ) ){ debug_msg( "Trocando dados de audio -- musica de espera com o CBx" ); + char *ref = strstr( buffer, "audio" ); if( ref != NULL ){ ref += 6; // audio ref = strtok( ref, " "); @@ -242,14 +192,14 @@ } } if( status == sip_trying ){ - if( !( strncasecmp( buffer_eth_invite + 12, "ringing", strlen("ringing") ) ) ){ + if( !( strncasecmp( buffer + 12, "ringing", strlen("ringing") ) ) ){ debug_msg("ringing"); t.reset(); set_status( status, sip_ringing ); } } if( status == sip_waiting_trying ){ - if( !( strncasecmp( buffer_eth_invite + 12, "trying", strlen("trying") ) ) ){ + if( !( strncasecmp( buffer + 12, "trying", strlen("trying") ) ) ){ debug_msg("trying") t.reset(); set_status( status, sip_trying ); @@ -304,6 +254,7 @@ strcat( buffer, ";branch=" ); strcat( buffer, branch ); strcat( buffer, "\r\nFrom: " ); + // mudar isso aqui pra algo mais compreensivel pra cc itoa( my_ext, itoa_buffer, 10 ); strcat( buffer, itoa_buffer ); strcat( buffer, " <sip:" ); @@ -927,7 +878,7 @@ } inline int Sip::fill_random_rtp_port(){ // o range [ 16384 - 32767 ] eh configuravel no server - return ( ( this->my_ext + 16384 ) > 32767 ) ? ( ( this->my_ext + 16384 ) % ( 32767 - 16384 ) + 16384 ) : this->my_ext + 16384; + return ( ( this->my_ext + 16384 ) ); } void Sip::change_sip_server(){ @@ -969,12 +920,11 @@ sock.set_blocking( false, 3 ); // verificar isso com mais cuidado depois uint8_t read = sock.receiveFrom( sip_server, this->buffer, sizeof( this->buffer ) ); if( read > 0 ){ - debug_msg( "-- SIP recebeu algo --" ); + //debug_msg( "-- SIP recebeu algo --" ); if( !( strncasecmp( buffer, "bye", strlen("bye") ) ) ){ char ans[ 2000 ]; build_reply_package( ans, (unsigned char*)buffer ); - sock.sendTo( sip_server, ans, sizeof( ans ) ); - + sock.sendTo( sip_server, ans, sizeof( ans ) ); debug_msg(" Server request BYE to %d ext", my_ext ); return( this->my_ext ); }else if( !( strncasecmp( buffer, "options", strlen("options") ) ) ){