1.1 --- a/gmyth/src/gmyth_file_transfer.c Wed Nov 29 22:36:28 2006 +0000
1.2 +++ b/gmyth/src/gmyth_file_transfer.c Thu Nov 30 13:58:35 2006 +0000
1.3 @@ -84,16 +84,16 @@
1.4 GMYTH_RINGBUFFER_TYPE
1.5 };
1.6
1.7 -static GStaticMutex st_mutex = G_STATIC_MUTEX_INIT;
1.8 +//static GStaticMutex st_mutex = G_STATIC_MUTEX_INIT;
1.9
1.10 -static gboolean* myth_control_sock_listener( GIOChannel *io_channel );
1.11 +//static gboolean* myth_control_sock_listener( GIOChannel *io_channel );
1.12 /* static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data ); */
1.13
1.14 static GMutex* mutex = NULL;
1.15
1.16 static GCond* io_watcher_cond = NULL;
1.17
1.18 -static GMainContext* io_watcher_context = NULL;
1.19 +//static GMainContext* io_watcher_context = NULL;
1.20
1.21 static void gmyth_file_transfer_class_init (GMythFileTransferClass *klass);
1.22 static void gmyth_file_transfer_init (GMythFileTransfer *object);
1.23 @@ -177,16 +177,31 @@
1.24 {
1.25 gboolean ret = TRUE;
1.26
1.27 - transfer->uri = gmyth_uri_new_with_value ( uri_str->str );
1.28 - transfer->hostname = g_string_new( gmyth_uri_get_host(transfer->uri) );
1.29 - transfer->port = gmyth_uri_get_port( transfer->uri );
1.30 + if (transfer->uri != NULL) {
1.31 + g_object_unref (G_OBJECT (transfer->uri));
1.32 + transfer->uri = NULL;
1.33 + }
1.34 +
1.35 + if (transfer->hostname != NULL) {
1.36 + g_string_free (transfer->hostname, TRUE);
1.37 + transfer->hostname = NULL;
1.38 + }
1.39 +
1.40 + if (transfer->hostname != NULL) {
1.41 + g_string_free (transfer->hostname, TRUE);
1.42 + transfer->hostname = NULL;
1.43 + }
1.44 +
1.45 + transfer->uri = gmyth_uri_new_with_value (uri_str->str);
1.46 + transfer->hostname = g_string_new (gmyth_uri_get_host(transfer->uri));
1.47 + transfer->port = gmyth_uri_get_port (transfer->uri);
1.48
1.49 gmyth_debug ("[%s] URI: %s\n", __FUNCTION__, uri_str->str);
1.50 gmyth_debug ("hostname: %s, port %d\n", transfer->hostname->str, transfer->port);
1.51
1.52 /* configure the control socket */
1.53 if (transfer->control_sock == NULL) {
1.54 - if ( !gmyth_connect_to_backend (transfer)) {
1.55 + if (!gmyth_connect_to_backend (transfer)) {
1.56 g_printerr( "Connection to backend failed (Control Socket).\n" );
1.57 ret = FALSE;
1.58 }
1.59 @@ -198,6 +213,7 @@
1.60
1.61 }
1.62
1.63 +/*
1.64 static gboolean*
1.65 //myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data )
1.66 myth_control_sock_listener( GIOChannel *io_channel )
1.67 @@ -282,7 +298,9 @@
1.68 return ret;
1.69
1.70 }
1.71 +*/
1.72
1.73 +/*
1.74 static gboolean
1.75 gmyth_connect_to_backend_monitor (GMythFileTransfer *transfer, GString *hostname )
1.76 {
1.77 @@ -296,10 +314,9 @@
1.78 g_string_printf( base_str, "ANN Monitor %s %d", hostname->str, TRUE );
1.79
1.80 gmyth_socket_send_command( transfer->event_sock, base_str );
1.81 - GString *resp = gmyth_socket_receive_response( transfer->event_sock );
1.82 + //GString *resp = gmyth_socket_receive_response( transfer->event_sock );
1.83 gmyth_debug ( "[%s] Got Monitor response from %s: %s\n", __FUNCTION__, base_str->str, resp->str );
1.84 monitor_th = g_thread_create( (GThreadFunc)myth_control_sock_listener, transfer->event_sock->sd_io_ch, FALSE, NULL );
1.85 - /*
1.86 io_watcher_context = g_main_context_default();
1.87 GMainLoop *loop = g_main_loop_new( NULL, TRUE );
1.88
1.89 @@ -317,23 +334,17 @@
1.90
1.91 g_source_attach( source, io_watcher_context );
1.92
1.93 - */
1.94 -
1.95 -/*
1.96 if (source==NULL) {
1.97 g_printerr( "[%s] Error adding watch listener function to the IO control channel!\n", __FUNCTION__ );
1.98 goto cleanup;
1.99 }
1.100 -*/
1.101 gmyth_debug ( "[%s]\tOK! Starting listener on the MONITOR event socket...\n", __FUNCTION__ );
1.102
1.103 //g_main_loop_run( loop );
1.104
1.105 -cleanup:
1.106 - /*
1.107 +//cleanup:
1.108 if ( source != NULL )
1.109 g_source_unref( source );
1.110 - */
1.111
1.112 gmyth_debug( "[%s] Watch listener function over the IO control channel? %s!!!\n",
1.113 __FUNCTION__, ( ret == TRUE ? "YES" : "NO" ) );
1.114 @@ -341,22 +352,31 @@
1.115 return ret;
1.116
1.117 }
1.118 +*/
1.119
1.120 static gboolean
1.121 gmyth_connect_to_backend (GMythFileTransfer *transfer)
1.122 {
1.123 - GString *base_str = g_string_new( "" );
1.124 + GString *base_str = NULL;
1.125 GString *hostname = NULL;
1.126 - GMythStringList *strlist;
1.127 + GMythStringList *strlist = NULL;
1.128 + gchar *path_dir = NULL;
1.129 + gboolean ret = TRUE;
1.130
1.131 g_return_val_if_fail (transfer != NULL, FALSE );
1.132 g_return_val_if_fail (transfer->uri != NULL, FALSE );
1.133 g_return_val_if_fail (transfer->hostname != NULL, FALSE);
1.134 g_return_val_if_fail (transfer->port > 0, FALSE);
1.135
1.136 - gchar *path_dir = gmyth_uri_get_path (transfer->uri);
1.137 + base_str = g_string_new ("");
1.138 + path_dir = gmyth_uri_get_path (transfer->uri);
1.139
1.140 /* Creates the control socket */
1.141 + if (transfer->control_sock != NULL) {
1.142 + g_object_unref (transfer->control_sock);
1.143 + transfer->control_sock = NULL;
1.144 + }
1.145 +
1.146 transfer->control_sock = gmyth_socket_new();
1.147
1.148 // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version
1.149 @@ -369,6 +389,11 @@
1.150 }
1.151
1.152 /* Creates the data socket */
1.153 + if (transfer->sock != NULL) {
1.154 + g_object_unref (transfer->sock);
1.155 + transfer->sock = NULL;
1.156 + }
1.157 +
1.158 transfer->sock = gmyth_socket_new ();
1.159 gmyth_socket_connect (transfer->sock, transfer->hostname->str, transfer->port);
1.160
1.161 @@ -397,12 +422,14 @@
1.162
1.163 if (transfer->filesize < 0 ) {
1.164 gmyth_debug ( "[%s] Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", __FUNCTION__, transfer->filesize );
1.165 - g_object_unref(transfer->sock);
1.166 + g_object_unref (transfer->sock);
1.167 transfer->sock = NULL;
1.168 - return FALSE;
1.169 + ret = FALSE;
1.170 + goto cleanup;
1.171 }
1.172
1.173 //gmyth_connect_to_backend_monitor( transfer, hostname );
1.174 +cleanup:
1.175
1.176 if ( strlist != NULL )
1.177 g_object_unref( strlist );
1.178 @@ -410,7 +437,7 @@
1.179 g_string_free (base_str, TRUE);
1.180 g_string_free (hostname, TRUE);
1.181
1.182 - return TRUE;
1.183 + return ret;
1.184 }
1.185
1.186 gboolean
1.187 @@ -579,11 +606,8 @@
1.188 GIOCondition io_cond_control;
1.189 GIOStatus io_status = G_IO_STATUS_NORMAL, io_status_control = G_IO_STATUS_NORMAL;
1.190
1.191 - GMythStringList *strlist = NULL;
1.192 GString *query;
1.193
1.194 - gchar *data_buffer = NULL;
1.195 -
1.196 g_return_val_if_fail ( data != NULL, -2 );
1.197
1.198 io_channel = transfer->sock->sd_io_ch;
1.199 @@ -615,8 +639,7 @@
1.200 myth_control_acquire_context( TRUE );
1.201
1.202 while (total_read == 0) {
1.203 -
1.204 - strlist = gmyth_string_list_new();
1.205 + GMythStringList *strlist = gmyth_string_list_new();
1.206
1.207 gmyth_string_list_append_char_array( strlist, query->str );
1.208 gmyth_string_list_append_char_array( strlist, "REQUEST_BLOCK" );
1.209 @@ -629,44 +652,39 @@
1.210 gmyth_socket_read_stringlist( transfer->control_sock, strlist );
1.211
1.212 if ( strlist != NULL && gmyth_string_list_length( strlist ) > 0 ) {
1.213 - bytes_sent = gmyth_string_list_get_int( strlist, 0 ); // -1 on backend error
1.214 + bytes_sent = gmyth_string_list_get_int( strlist, 0 ); // -1 on backend error
1.215 + gmyth_debug ( "[%s] got SENT buffer message = %d\n", __FUNCTION__, bytes_sent );
1.216
1.217 - gmyth_debug ( "[%s] got SENT buffer message = %d\n", __FUNCTION__, bytes_sent );
1.218 if ( bytes_sent != 0 ) {
1.219 -
1.220 - data_buffer = g_new0( gchar, bytes_sent );
1.221 -
1.222 - while (total_read != bytes_sent) {
1.223 -
1.224 + gchar *data_buffer = g_new0 (gchar, bytes_sent);
1.225 + while ( 0 != bytes_sent) {
1.226 io_status = g_io_channel_read_chars( io_channel, data_buffer + total_read,
1.227 - (gsize) bytes_sent, // buffer_len
1.228 - &bytes_read, &error );
1.229 -
1.230 - total_read += bytes_read;
1.231 + (gsize) bytes_sent, // buffer_len
1.232 + &bytes_read, &error );
1.233 + total_read += bytes_read;
1.234 + bytes_sent -= bytes_read;
1.235
1.236 - /* append new data to the increasing byte array */
1.237 - data = g_byte_array_append ( data, g_memdup( data_buffer, bytes_read ), bytes_read );
1.238 -
1.239 - printf ("Total file transfer data read: %d\n", total_read);
1.240 + /* append new data to the increasing byte array */
1.241 + data = g_byte_array_append (data, g_memdup (data_buffer, bytes_read), bytes_read);
1.242 + gmyth_debug ("Total file transfer data read: %d\n", total_read);
1.243 + }
1.244 + g_free (data_buffer);
1.245 }
1.246 - }
1.247 }
1.248 + g_object_unref (strlist);
1.249 + strlist = NULL;
1.250 }
1.251
1.252 myth_control_release_context( );
1.253 + g_string_free (query, TRUE);
1.254
1.255 - g_object_unref( strlist );
1.256 - g_string_free (query, TRUE);
1.257 -
1.258 -
1.259 - if ( error != NULL ) {
1.260 - g_printerr( "Cleaning-up ERROR: %s [msg = %s, code = %d]\n", __FUNCTION__, error->message,
1.261 - error->code );
1.262 - g_error_free( error );
1.263 - }
1.264 + if ( error != NULL ) {
1.265 + gmyth_debug ("Cleaning-up ERROR: %s [msg = %s, code = %d]\n", __FUNCTION__, error->message,
1.266 + error->code);
1.267 + g_error_free (error);
1.268 + }
1.269
1.270 transfer->readposition += total_read;
1.271 -
1.272 return total_read;
1.273 }
1.274
2.1 --- a/gmyth/src/gmyth_uri.c Wed Nov 29 22:36:28 2006 +0000
2.2 +++ b/gmyth/src/gmyth_uri.c Thu Nov 30 13:58:35 2006 +0000
2.3 @@ -59,14 +59,6 @@
2.4 static void
2.5 gmyth_uri_init (GMythURI *gmyth_uri)
2.6 {
2.7 - gmyth_uri->host = g_string_new("");
2.8 - gmyth_uri->fragment = g_string_new("");
2.9 - gmyth_uri->password = g_string_new("");
2.10 - gmyth_uri->path = g_string_new("");
2.11 - gmyth_uri->protocol = g_string_new("");
2.12 - gmyth_uri->query = g_string_new("");
2.13 - gmyth_uri->uri = g_string_new("");
2.14 - gmyth_uri->user = g_string_new("");
2.15 }
2.16
2.17 static void
2.18 @@ -127,7 +119,7 @@
2.19 * @return a new instance of GMythURI.
2.20 */
2.21 GMythURI *
2.22 -gmyth_uri_new( )
2.23 +gmyth_uri_new (void)
2.24 {
2.25 GMythURI *gmyth_uri = GMYTH_URI (g_object_new (GMYTH_URI_TYPE, NULL));
2.26
2.27 @@ -139,17 +131,17 @@
2.28 * @return a new instance of GMythURI.
2.29 */
2.30 GMythURI *
2.31 -gmyth_uri_new_with_value( const gchar *value )
2.32 +gmyth_uri_new_with_value (const gchar *value)
2.33 {
2.34 GMythURI *gmyth_uri = GMYTH_URI (g_object_new (GMYTH_URI_TYPE, NULL));
2.35
2.36 - gmyth_uri_parser_setup_and_new( gmyth_uri, value );
2.37 + gmyth_uri_parser_setup_and_new (gmyth_uri, value);
2.38
2.39 return gmyth_uri;
2.40 }
2.41
2.42 static gint
2.43 -gmyth_strstr( const gchar *haystack, const gchar *needle )
2.44 +gmyth_strstr (const gchar *haystack, const gchar *needle)
2.45 {
2.46
2.47 gchar *strPos;
2.48 @@ -165,7 +157,7 @@
2.49 }
2.50
2.51 static gboolean
2.52 -gmyth_uri_isabsolute( const GMythURI *uri )
2.53 +gmyth_uri_isabsolute (const GMythURI *uri)
2.54 {
2.55 gboolean ret = FALSE;
2.56
2.57 @@ -203,17 +195,14 @@
2.58 gmyth_uri_parser_setup_and_new( GMythURI *uri, const gchar *value )
2.59 {
2.60
2.61 - gchar *protocol;
2.62 gint uriLen;
2.63 gint currIdx;
2.64 gint protoIdx;
2.65 gint atIdx;
2.66 gint colonIdx;
2.67 gint shashIdx;
2.68 - gchar *host;
2.69 + gchar *host;
2.70 gint eblacketIdx;
2.71 - GString *hostStr;
2.72 - GString *portStr;
2.73 gint hostLen;
2.74 gint sharpIdx;
2.75 gint questionIdx;
2.76 @@ -225,9 +214,9 @@
2.77 currIdx = 0;
2.78
2.79 /*** Protocol ****/
2.80 - protoIdx = gmyth_strstr( value, GMYTH_URI_PROTOCOL_DELIM );
2.81 + protoIdx = gmyth_strstr (value, GMYTH_URI_PROTOCOL_DELIM);
2.82 if (0 < protoIdx) {
2.83 - uri->protocol = g_string_append_len( uri->protocol, value, protoIdx );
2.84 + uri->protocol = g_string_append_len (uri->protocol, value, protoIdx);
2.85 currIdx += protoIdx + strlen( GMYTH_URI_PROTOCOL_DELIM );
2.86 }
2.87
2.88 @@ -252,16 +241,16 @@
2.89 else if ( gmyth_uri_isabsolute(uri) == TRUE )
2.90 uri->host = g_string_append_len( uri->host, value+currIdx, strlen(value) - currIdx );
2.91 host = g_strdup( gmyth_uri_get_host(uri) );
2.92 - colonIdx = gmyth_strrchr( host, GMYTH_URI_COLON_DELIM, 1 );
2.93 - eblacketIdx = gmyth_strrchr( host, GMYTH_URI_EBLACET_DELIM, 1 );
2.94 + colonIdx = gmyth_strrchr (host, GMYTH_URI_COLON_DELIM, 1);
2.95 + eblacketIdx = gmyth_strrchr (host, GMYTH_URI_EBLACET_DELIM, 1);
2.96 if ( ( 0 < colonIdx ) && ( eblacketIdx < colonIdx ) ) {
2.97 - hostStr = g_string_new( host );
2.98 + GString *portStr = NULL;
2.99 + GString *hostStr = g_string_new (host);
2.100
2.101 hostLen = hostStr->len;
2.102 /**** host ****/
2.103 - uri->host = g_string_erase( uri->host, 0, hostLen );
2.104 - uri->host = g_string_insert_len( uri->host, 0, hostStr->str, colonIdx );
2.105 - //host = gmyth_uri_gethost( uri );
2.106 + uri->host = g_string_erase (uri->host, 0, hostLen);
2.107 + uri->host = g_string_insert_len (uri->host, 0, hostStr->str, colonIdx);
2.108 if (0 < hostLen) {
2.109 if (host[0] == '[' && host[hostLen-1] == ']')
2.110 uri->host = g_string_append_len( uri->host, hostStr->str+1, colonIdx-2 );
2.111 @@ -274,13 +263,14 @@
2.112 g_string_free( hostStr, FALSE );
2.113 }
2.114 else {
2.115 + const gchar* protocol = gmyth_uri_get_protocol(uri);
2.116 uri->port = GMYTH_URI_KNKOWN_PORT;
2.117 - protocol = gmyth_uri_get_protocol(uri);
2.118 if ( strcmp(protocol, GMYTH_URI_PROTOCOL_HTTP) == 0 )
2.119 uri->port = GMYTH_URI_DEFAULT_HTTP_PORT;
2.120 if ( strcmp(protocol, GMYTH_URI_PROTOCOL_FTP) == 0 )
2.121 uri->port = GMYTH_URI_DEFAULT_FTP_PORT;
2.122 }
2.123 + g_free (host);
2.124
2.125 if (shashIdx > 0) currIdx += shashIdx;
2.126
3.1 --- a/gmyth/src/gmyth_uri.h Wed Nov 29 22:36:28 2006 +0000
3.2 +++ b/gmyth/src/gmyth_uri.h Thu Nov 30 13:58:35 2006 +0000
3.3 @@ -101,22 +101,18 @@
3.4
3.5 };
3.6
3.7 -GType gmyth_uri_get_type (void);
3.8 -
3.9 -GMythURI* gmyth_uri_new ( void );
3.10 -
3.11 -GMythURI* gmyth_uri_new_with_value ( const gchar *value );
3.12 -
3.13 -gboolean gmyth_uri_is_equals( GMythURI* uri1, GMythURI* uri2 );
3.14 -
3.15 -#define gmyth_uri_get_host(urip) (urip->host->str)
3.16 -#define gmyth_uri_get_port(urip) (urip->port)
3.17 -#define gmyth_uri_get_protocol(urip) (urip->protocol->str)
3.18 -#define gmyth_uri_get_path(urip) (urip->path->str)
3.19 -#define gmyth_uri_get_user(urip) (urip->user->str)
3.20 -#define gmyth_uri_get_password(urip) (urip->password->str)
3.21 -#define gmyth_uri_get_fragment(urip) (urip->fragment->str)
3.22 -#define gmyth_uri_get_query(urip) (urip->query->str)
3.23 +GType gmyth_uri_get_type (void);
3.24 +GMythURI* gmyth_uri_new (void);
3.25 +GMythURI* gmyth_uri_new_with_value (const gchar *value);
3.26 +gboolean gmyth_uri_is_equals (GMythURI* uri1, GMythURI* uri2);
3.27 +#define gmyth_uri_get_host(urip) (urip->host->str)
3.28 +#define gmyth_uri_get_port(urip) (urip->port)
3.29 +#define gmyth_uri_get_protocol(urip) (urip->protocol->str)
3.30 +#define gmyth_uri_get_path(urip) (urip->path->str)
3.31 +#define gmyth_uri_get_user(urip) (urip->user->str)
3.32 +#define gmyth_uri_get_password(urip) (urip->password->str)
3.33 +#define gmyth_uri_get_fragment(urip) (urip->fragment->str)
3.34 +#define gmyth_uri_get_query(urip) (urip->query->str)
3.35
3.36 G_END_DECLS
3.37