Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
Diff: sip.cpp
- Revision:
- 125:8ff4dc96ad58
- Parent:
- 124:c1b6c893e1c3
- Child:
- 132:05cd37f7e007
diff -r c1b6c893e1c3 -r 8ff4dc96ad58 sip.cpp --- a/sip.cpp Wed May 13 14:25:57 2015 +0000 +++ b/sip.cpp Wed May 13 21:18:12 2015 +0000 @@ -24,7 +24,6 @@ Sip::Sip ( const int new_ext, const uint16_t my_port ) { - FILE * fp = NULL; char inner_tmp [ 20 ]; if ( debug_sip ) debug_msg ("[%d, %d] Building SIP", new_ext, my_port ); @@ -32,14 +31,14 @@ this->my_ext = new_ext; this->my_port = my_port; - fp = fopen ( "/qspi/serverip.txt", "r"); - if ( fp == NULL) + FILE * fip = fopen ( "/qspi/serverip.txt", "r"); + if ( fip == NULL) { if ( debug_sip ) debug_msg("[%d] Failed to open /qspi/serverip.txt", this->my_ext ); strncpy ( this->server_ip, SERVER_IP, 20 ); } else { char tmp [ 16 ] = "\0"; - int read = fread ( tmp, 1, 15, fp ); + int read = fread ( tmp, 1, 15, fip ); if ( read > 0 ){ for ( int i = 0; i < read; i++ ) if ( tmp [ i ] == '\n' || tmp[ i ] == '\r' ){ @@ -53,16 +52,16 @@ strncpy ( this->server_ip, SERVER_IP, 20 ); } } - if ( fp ) fclose ( fp ); + if ( fip ) fclose ( fip ); this->server_ip [ 15 ] = '\0'; - fp = fopen ( "/qspi/serverport.txt", "r"); - if ( fp == NULL ) + FILE * sp = fopen ( "/qspi/serverport.txt", "r"); + if ( sp == NULL ) { if ( debug_sip ) debug_msg ("[%d] Failed to open /qspi/serverport.txt", this->my_ext ); this->server_port = SERVER_PORT; } else { - if ( fread ( (void *)inner_tmp, 1, 20, fp ) > 0 ) + if ( fread ( (void *)inner_tmp, 1, 20, sp ) > 0 ) { server_port = atoi ( inner_tmp ); if ( debug_sip ) debug_msg ("[%d] server port %d", this->my_ext, this->server_port ); @@ -71,16 +70,16 @@ this->server_port = SERVER_PORT; } } - fclose ( fp ); + if ( sp ) fclose ( sp ); - fp = fopen ( "/qspi/myip.txt", "r"); - if ( fp == NULL ) + FILE * fhip = fopen ( "/qspi/myip.txt", "r"); + if ( fhip == NULL ) { if ( debug_sip ) debug_msg ("[%d] Failed to open /qspi/myip.txt", this->my_ext ); strncpy ( this->my_ip, MY_IP, 20 ); } else { char tmp[ 16 ] = "\0"; - int read = fread( tmp, 1, 15, fp ); + int read = fread( tmp, 1, 15, fhip ); if( read > 0 ){ for( int i = 0; i < read; i++ ) if( tmp[ i ] == '\n' || tmp[ i ] == '\r' ){ @@ -94,7 +93,7 @@ strncpy ( this->my_ip, MY_IP, 20 ); } } - fclose ( fp ); + if ( fhip ) fclose ( fhip ); this->my_ip[ 15 ] = '\0'; @@ -105,13 +104,13 @@ this->my_rtp_port = 0; if ( debug_rtp ) debug_msg ("[%d] rtp port %d ", this->my_ext, this->my_rtp_port ); - fp = fopen ( "/qspi/peerext.txt", "r"); - if ( fp == NULL ) + FILE * serext = fopen ( "/qspi/peerext.txt", "r"); + if ( serext == NULL ) { if( debug_sip ) debug_msg ("[%d] Failed to open /qspi/peerext.txt", this->my_ext ); this->peer_ext = PEER_EXT; } else { - if( fread ( (void *)inner_tmp, 1, 32, fp ) > 0 ) { + if( fread ( (void *)inner_tmp, 1, 32, serext ) > 0 ) { this->peer_ext = atoi ( inner_tmp ); if ( debug_sip ) debug_msg("[%d] server ext %d", this->my_ext, this->peer_ext ); } else { @@ -119,7 +118,7 @@ this->peer_ext = PEER_EXT; } } - fclose ( fp ); + if ( serext ) fclose ( serext ); strcpy( this->last_invite_tag, "" ); strcpy( this->last_invite_callid, "");