[svn r156] code cleanup trunk
authorrenatofilho
Thu Nov 30 20:28:25 2006 +0000 (2006-11-30)
branchtrunk
changeset 1551842993f4473
parent 154 30f32f34287c
child 156 4b24a328c655
[svn r156] code cleanup
gmyth/src/gmyth_file_transfer.c
gmyth/src/gmyth_socket.c
     1.1 --- a/gmyth/src/gmyth_file_transfer.c	Thu Nov 30 20:06:25 2006 +0000
     1.2 +++ b/gmyth/src/gmyth_file_transfer.c	Thu Nov 30 20:28:25 2006 +0000
     1.3 @@ -665,7 +665,7 @@
     1.4                  bytes_sent -= bytes_read;
     1.5  	        
     1.6  	            /* append new data to the increasing byte array */
     1.7 -		    	data = g_byte_array_append (data, g_memdup (data_buffer, bytes_read), bytes_read);
     1.8 +		    	data = g_byte_array_append (data, data_buffer, bytes_read);
     1.9  		        gmyth_debug ("Total file transfer data read: %d\n", total_read);
    1.10  	        }
    1.11              g_free (data_buffer);
     2.1 --- a/gmyth/src/gmyth_socket.c	Thu Nov 30 20:06:25 2006 +0000
     2.2 +++ b/gmyth/src/gmyth_socket.c	Thu Nov 30 20:28:25 2006 +0000
     2.3 @@ -180,7 +180,7 @@
     2.4  			if ( current_connections == NULL || ( current_connections != NULL && 
     2.5  					g_list_find_custom( current_connections, (gchar *)addr, 
     2.6  						(GCompareFunc)gmyth_socket_find_match_address_uri ) == NULL ) )
     2.7 -				local_addrs = g_list_append( local_addrs, g_strdup( addr ) );
     2.8 +				local_addrs = g_list_append (local_addrs, addr);
     2.9  
    2.10  		}
    2.11  	} /* iterates over network interfaces */
    2.12 @@ -271,7 +271,7 @@
    2.13  		if_tmp = g_list_first( interfs );
    2.14  		
    2.15  		if ( if_tmp != NULL )
    2.16 -			g_strlcpy( if_eth0, g_strdup( (gchar *)if_tmp->data ), sizeof(struct ifaddr)-1 );
    2.17 +			g_strlcpy (if_eth0, (gchar *)if_tmp->data, sizeof(struct ifaddr)-1 );
    2.18  
    2.19  	}
    2.20  	
    2.21 @@ -289,7 +289,7 @@
    2.22  GString *
    2.23  gmyth_socket_get_local_hostname  ()
    2.24  {
    2.25 -    GString *str = g_string_sized_new( 1024 );
    2.26 +    GString *str = NULL;
    2.27  
    2.28      gchar localhostname[1024];
    2.29      gchar *localaddr = NULL; 
    2.30 @@ -297,7 +297,7 @@
    2.31      struct addrinfo* addr_info_data = NULL, *addr_info0 = NULL;
    2.32      struct sockaddr_in* sa = NULL;
    2.33  
    2.34 -    gethostname(localhostname, 1024);
    2.35 +    gethostname (localhostname, 1024);
    2.36      gint err = gmyth_socket_toaddrinfo (localhostname, -1,  &addr_info_data );
    2.37      
    2.38      if ( err == EADDRNOTAVAIL )
    2.39 @@ -315,7 +315,7 @@
    2.40      	localaddr = inet_ntoa( sa->sin_addr );
    2.41  
    2.42  	    if ( localaddr != NULL && ( g_strrstr( localaddr, "127" ) == NULL ) ) {
    2.43 -	        str = g_string_assign( str, g_strdup( localaddr ) );
    2.44 +	        str = g_string_new (localaddr);
    2.45  	        found_addr = TRUE;
    2.46  	        break;
    2.47  	    }
    2.48 @@ -324,20 +324,20 @@
    2.49      freeaddrinfo (addr_info_data);
    2.50  
    2.51      if ( found_addr == FALSE ) {
    2.52 -      gchar *prim_addr = gmyth_socket_get_primary_addr();
    2.53 +        gchar *prim_addr = gmyth_socket_get_primary_addr();
    2.54  
    2.55      	if ( prim_addr != NULL ) {
    2.56 -			    g_warning("[%s] Could not determine the local alphanumerical hostname. Setting to %s\n",
    2.57 -    				__FUNCTION__, prim_addr );
    2.58 +		    g_warning("[%s] Could not determine the local alphanumerical hostname. Setting to %s\n",
    2.59 +    	        __FUNCTION__, prim_addr );
    2.60        
    2.61 -	        str = g_string_assign( str, g_strdup( prim_addr ) );
    2.62 -	        g_free( prim_addr );
    2.63 +	        str = g_string_new (prim_addr);
    2.64 +	        g_free (prim_addr);
    2.65      	} else {
    2.66 -					str = g_string_assign (str, localhostname);
    2.67 +        	str = g_string_new (localhostname);
    2.68      	}
    2.69      }
    2.70  
    2.71 -    g_static_mutex_unlock( &mutex );
    2.72 +    g_static_mutex_unlock (&mutex);
    2.73  
    2.74      return str;
    2.75  }
    2.76 @@ -927,13 +927,13 @@
    2.77  gmyth_socket_write_stringlist(GMythSocket *gmyth_socket, GMythStringList* str_list)
    2.78  {
    2.79  
    2.80 -    GList *tmp_list;
    2.81 -    GPtrArray *ptr_array;
    2.82 -    gchar *str_array;
    2.83 +    GList *tmp_list = NULL;
    2.84 +    GPtrArray *ptr_array = NULL;
    2.85 +    gchar *str_array = NULL;
    2.86  
    2.87      g_static_mutex_lock( &mutex );
    2.88  
    2.89 -    ptr_array = g_ptr_array_sized_new(g_list_length(str_list->glist));
    2.90 +    ptr_array = g_ptr_array_sized_new (g_list_length(str_list->glist));
    2.91  
    2.92      gmyth_debug ( "[%s] Number of parameters = %d\n", __FUNCTION__, g_list_length(str_list->glist) );    
    2.93  
    2.94 @@ -943,7 +943,7 @@
    2.95  	if ( tmp_list->data != NULL ) {
    2.96  	    g_ptr_array_add(ptr_array, ((GString*)tmp_list->data)->str);
    2.97  	} else {
    2.98 -	    g_ptr_array_add (ptr_array, g_strdup (""));
    2.99 +	    g_ptr_array_add (ptr_array, "");
   2.100  	}
   2.101      }
   2.102      g_ptr_array_add(ptr_array, NULL); // g_str_joinv() needs a NULL terminated string
   2.103 @@ -955,8 +955,10 @@
   2.104      gmyth_debug ( "[%s]\t\tSending the String list = %s\n", __FUNCTION__, str_array );
   2.105  
   2.106      // Sends message to backend	
   2.107 -    // TODO: implement looping to send remaining data, and add timeout testing!
   2.108 -    gmyth_socket_send_command(gmyth_socket, g_string_new(str_array));
   2.109 +    // TODO: implement looping to send remaining data, and add timeout testing!    
   2.110 +    GString *command = g_string_new(str_array);
   2.111 +    gmyth_socket_send_command(gmyth_socket, command);
   2.112 +    g_string_free (command, TRUE);
   2.113  
   2.114      g_free (str_array);
   2.115      g_ptr_array_free (ptr_array, TRUE);