# HG changeset patch # User rosfran # Date 1176380573 -3600 # Node ID dfa28b22a36cdd6c13c88198ca75455f0a1f25e8 # Parent 4a604de8eaf5316dffeab7d6a40cae86e875fa77 [svn r534] Added GObject inheritance to the GMythFile* modules. diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/Makefile.am --- a/gmyth/src/Makefile.am Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/Makefile.am Thu Apr 12 13:22:53 2007 +0100 @@ -29,9 +29,10 @@ gmyth_jobqueue.c \ gmyth_transcoder.c \ gmyth_recprofile.c \ + gmyth_file.c \ + gmyth_file_local.c \ $(BUILT_SOURCES) - EXTRA_libgmyth_la_SOURCES = gmyth_marshal.list gmyth_marshal.h: gmyth_marshal.list @@ -88,6 +89,8 @@ gmyth_vlc.h \ gmyth_jobqueue.h \ gmyth_transcoder.h \ - gmyth_recprofile.h + gmyth_recprofile.h \ + gmyth_file.h \ + gmyth_file_local.h CLEANFILES = $(BUILT_SOURCES) diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_backendinfo.c --- a/gmyth/src/gmyth_backendinfo.c Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_backendinfo.c Thu Apr 12 13:22:53 2007 +0100 @@ -283,13 +283,42 @@ gmyth_backend_info_get_uri (GMythBackendInfo *backend_info) { GMythURI *uri = NULL; - gchar* uri_str = g_strdup_printf( "myth://%s:%s@%s:%d/?%s", backend_info->username, backend_info->password, - backend_info->hostname, backend_info->port, backend_info->db_name ); + gchar* uri_str = g_strdup(""); + gchar *user_info = g_strdup(""); + gchar *db_data = g_strdup(""); + + if ( ( backend_info->username != NULL && strlen(backend_info->username) > 0 ) ) + user_info = g_strdup_printf( "%s:%s@", backend_info->username, backend_info->password ); + + if ( backend_info->db_name != NULL && strlen(backend_info->db_name) > 0 ) + { + if ( ( g_strrstr( backend_info->db_name, "_" ) != NULL ) ) + db_data = backend_info->db_name; + else + db_data = g_strdup_printf( "?%s&", backend_info->db_name ); + } + //else if ( ( ( g_strrstr( backend_info->path, "livetv" ) != NULL ) || + // ( g_strrstr( backend_info->path, "/?" ) != NULL ) ) + + uri_str = g_strdup_printf( "myth://%s%s:%d/%s", user_info != NULL && strlen( user_info ) > 0 ? g_strdup( user_info ) : "", backend_info->hostname, + backend_info->port, db_data != NULL && strlen( db_data ) > 0 ? g_strdup( db_data ) : ""); uri = gmyth_uri_new_with_value (uri_str); + if ( user_info != NULL ) + g_free( user_info ); + + if ( db_data != NULL ) + g_free( db_data ); + g_free (uri_str); return uri; } - +gboolean +gmyth_backend_info_is_local_file(GMythBackendInfo *backend_info) +{ + g_return_val_if_fail (backend_info != NULL, FALSE); + + return gmyth_uri_is_local_file( gmyth_backend_info_get_uri( backend_info ) ); +} diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_backendinfo.h --- a/gmyth/src/gmyth_backendinfo.h Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_backendinfo.h Thu Apr 12 13:22:53 2007 +0100 @@ -106,6 +106,8 @@ GMythURI* gmyth_backend_info_get_uri (GMythBackendInfo *backend_info); +gboolean gmyth_backend_info_is_local_file(GMythBackendInfo *backend_info); + G_END_DECLS #endif /* __GMYTH_BACKEND_INFO_H__ */ diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_file.c --- a/gmyth/src/gmyth_file.c Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_file.c Thu Apr 12 13:22:53 2007 +0100 @@ -123,7 +123,7 @@ (gobject_class, PROP_GMYTH_FILE_BACKEND_INFO, g_param_spec_object ("backend-info", "backend-info", "The Backend Information about the remote server", - GMYTH_FILE_TYPE, G_PARAM_READWRITE)); + G_TYPE_OBJECT, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_GMYTH_FILE_FILEID, @@ -195,10 +195,7 @@ { GMythFile *file = GMYTH_FILE (g_object_new (GMYTH_FILE_TYPE, NULL)); - GValue val = {0,}; - g_value_init (&val, G_TYPE_OBJECT); - g_value_set_object (&val, backend_info); - g_object_set_property (G_OBJECT (file), "backend-info", &val); + g_object_set(G_OBJECT (file), "backend-info", &backend_info, NULL); return file; } @@ -206,17 +203,24 @@ gchar* gmyth_file_get_file_name (GMythFile *file) { - GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file); + gchar *filename; + + g_return_val_if_fail( file != NULL, NULL ); + g_return_val_if_fail( filename != NULL, NULL ); + + g_object_get(G_OBJECT (file), "filename", &filename, NULL); - return g_strdup (priv->filename); + return filename; } void gmyth_file_set_file_name (GMythFile *file, const gchar* filename) -{ - GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file); +{ + g_return_if_fail( file != NULL ); + g_return_if_fail( filename != NULL ); + + g_object_set (G_OBJECT (file), "filename", &filename, NULL); - return priv->filename = g_strdup (filename); } /** diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_file_local.c --- a/gmyth/src/gmyth_file_local.c Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_file_local.c Thu Apr 12 13:22:53 2007 +0100 @@ -153,14 +153,9 @@ GMythFileLocal* gmyth_file_local_new (GMythBackendInfo *backend_info) { - GMythFileLocal *file_local = NULL; - GValue val = {0,}; - g_value_init (&val, G_TYPE_OBJECT); - g_value_set_object (&val, backend_info); - g_object_set_property (G_OBJECT (file), "backend-info", &val); + GMythFileLocal *file_local = GMYTH_FILE_LOCAL (g_object_new (GMYTH_FILE_LOCAL_TYPE, NULL)); - file_local = GMYTH_FILE_LOCAL (g_object_new (GMYTH_FILE_TYPE, - "backend-info", val, NULL)); + g_object_set ( GMYTH_FILE( file_local ), "backend-info", &backend_info, NULL ); return file_local; } @@ -175,7 +170,7 @@ GMythFileLocal* gmyth_file_local_new_with_uri (const gchar* uri_str) { - GMythFileLocal *file_local = GMYTH_FILE_LOCAL (g_object_new (GMYTH_FILE_TYPE, NULL)); + GMythFileLocal *file_local = GMYTH_FILE_LOCAL (g_object_new (GMYTH_FILE_LOCAL_TYPE, NULL)); GMythURI *uri = gmyth_uri_new_with_value(uri_str); gmyth_debug( "GMythURI path segment = %s", gmyth_uri_get_path(uri) ); @@ -241,8 +236,6 @@ void gmyth_file_local_close (GMythFileLocal *file_local ) { - GMythFileLocalPrivate *priv; - g_return_if_fail (file_local != NULL); } @@ -314,8 +307,6 @@ GIOCondition io_cond; GIOStatus io_status = G_IO_STATUS_NORMAL; - gboolean ret = TRUE; - g_return_val_if_fail (file_local != NULL, FALSE); g_return_val_if_fail (data != NULL, GMYTH_FILE_READ_ERROR); @@ -348,8 +339,8 @@ data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read); total_read += bytes_read; - if (!read_unlimited && ( gmyth_file_local_get_file_size(file_local) > 0) && - (gmyth_file_local_get_offset(file_local) == gmyth_file_local_get_file_size(file_local))) { + if (!read_unlimited && ( gmyth_file_local_get_filesize(file_local) > 0) && + (gmyth_file_local_get_offset(file_local) == gmyth_file_local_get_filesize(file_local))) { retval = GMYTH_FILE_READ_EOF; goto error; } @@ -374,6 +365,28 @@ return retval; } +gint64 +gmyth_file_local_seek(GMythFileLocal *file_local, gint64 pos, GSeekType whence) +{ + GMythFileLocalPrivate *priv; + + GError *error; + + GIOStatus io_status = G_IO_STATUS_NORMAL; + + g_return_val_if_fail (file_local != NULL, -1); + + priv = GMYTH_FILE_LOCAL_GET_PRIVATE (file_local); + + io_status = g_io_channel_seek_position (priv->file_io, pos, whence, &error); + + if ( io_status == G_IO_STATUS_ERROR ) + pos = -1; + + return pos; + +} + /** * Gets the actual file_local size of the binary content. * @@ -386,7 +399,7 @@ { g_return_val_if_fail (file_local != NULL, 0); - return gmyth_file_get_filesize( GMYTH_FILE(g_type_peek_parent(file_local)) ); + return gmyth_file_get_filesize( GMYTH_FILE(file_local) ); } /** @@ -400,7 +413,7 @@ { g_return_if_fail (file_local != NULL); - gmyth_file_set_filesize( GMYTH_FILE(g_type_peek_parent(file_local)), filesize ); + gmyth_file_set_filesize( GMYTH_FILE(file_local), filesize ); } /** @@ -415,7 +428,7 @@ { g_return_val_if_fail (file_local != NULL, 0); - return gmyth_file_get_offset ( GMYTH_FILE(g_type_peek_parent(file_local)));; + return gmyth_file_get_offset ( GMYTH_FILE(file_local) ); } /** @@ -429,6 +442,6 @@ { g_return_if_fail (file_local != NULL); - gmyth_file_set_offset( GMYTH_FILE(g_type_peek_parent(file_local)), offset ); + gmyth_file_set_offset( GMYTH_FILE( file_local ), offset ); } diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_file_local.h --- a/gmyth/src/gmyth_file_local.h Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_file_local.h Thu Apr 12 13:22:53 2007 +0100 @@ -69,7 +69,7 @@ GType gmyth_file_local_get_type (void); GMythFileLocal* gmyth_file_local_new (GMythBackendInfo *backend_info); -GMythFileLocal* gmyth_file_local_new_with_uri (GMythBackendInfo *backend_info, const gchar* uri); +GMythFileLocal* gmyth_file_local_new_with_uri (const gchar* uri); gchar* gmyth_file_local_get_file_name (GMythFileLocal *file_local); void gmyth_file_local_set_file_name (GMythFileLocal *file_local, const gchar* filename); gboolean gmyth_file_local_open (GMythFileLocal *file_local); @@ -80,6 +80,10 @@ GByteArray *data, gint size, gboolean read_unlimited); + +gint64 gmyth_file_local_seek (GMythFileLocal *file_local, + gint64 pos, GSeekType whence); + guint64 gmyth_file_local_get_filesize (GMythFileLocal *file_local); void gmyth_file_local_set_filesize (GMythFileLocal *file, guint64 filesize); diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_file_transfer.c --- a/gmyth/src/gmyth_file_transfer.c Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_file_transfer.c Thu Apr 12 13:22:53 2007 +0100 @@ -69,26 +69,20 @@ }; struct _GMythFileTransferPrivate { - GMythRecorder *recorder; + GMythRecorder *recorder; - gboolean do_next_program_chain; - gboolean disposed; - gboolean livetv_wait; - gint64 offset; - guint64 filesize; + gboolean do_next_program_chain; + gboolean disposed; + gboolean livetv_wait; - /* Myth URI structure */ - gchar *filename; - GMythBackendInfo *backend_info; - /* MythTV version number */ - gint mythtv_version; + gint mythtv_version; /* socket descriptors */ - GMythSocket *control_sock; - GMythSocket *sock; - GMutex *mutex; - gint file_id; + GMythSocket *control_sock; + GMythSocket *sock; + GMutex *mutex; + gint file_id; }; static void gmyth_file_transfer_class_init (GMythFileTransferClass *klass); @@ -101,7 +95,7 @@ static gboolean _control_acquire_context (GMythFileTransfer *transfer, gboolean do_wait); static gboolean _control_release_context (GMythFileTransfer *transfer); -G_DEFINE_TYPE(GMythFileTransfer, gmyth_file_transfer, G_TYPE_OBJECT) +G_DEFINE_TYPE(GMythFileTransfer, gmyth_file_transfer, GMYTH_FILE_TYPE) static void gmyth_file_transfer_class_init (GMythFileTransferClass *klass) @@ -181,21 +175,11 @@ priv->sock = NULL; } - if (priv->backend_info != NULL ) { - g_object_unref (priv->backend_info ); - priv->backend_info = NULL; - } - if (priv->recorder != NULL ) { g_object_unref (priv->recorder ); priv->recorder = NULL; } - - if (priv->filename != NULL ) { - g_free (priv->filename ); - priv->filename = NULL; - } - + G_OBJECT_CLASS (gmyth_file_transfer_parent_class)->dispose (object); } @@ -218,20 +202,24 @@ GMythFileTransfer* gmyth_file_transfer_new (GMythBackendInfo *backend_info) { - GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL)); - GMythFileTransferPrivate *priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer); + GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL)); + + backend_info = g_object_ref( backend_info ); + + g_object_set (G_OBJECT (transfer), "backend-info", &backend_info, NULL); - priv->backend_info = g_object_ref (backend_info); - return transfer; + return transfer; } gchar* gmyth_file_transfer_get_file_name (GMythFileTransfer *transfer) { - GMythFileTransferPrivate *priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer); + gchar *filename; + + g_object_get( G_OBJECT(transfer), "filename", &filename, NULL ); - return g_strdup (priv->filename); + return g_strdup (filename); } /** @@ -244,18 +232,24 @@ GMythFileTransfer* gmyth_file_transfer_new_with_uri (const gchar* uri_str) { - GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL)); - GMythFileTransferPrivate *priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer); + GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL)); + gmyth_debug( "URI str = %s", uri_str ); + GMythBackendInfo *backend_info = gmyth_backend_info_new_with_uri (uri_str); + /* + GValue val = {0,}; + g_value_init (&val, G_TYPE_OBJECT); + g_value_set_object (&val, gmyth_backend_info_new_with_uri (uri_str)); + */ + g_object_set(G_OBJECT (transfer), "backend-info", &backend_info, NULL); - priv->backend_info = gmyth_backend_info_new_with_uri (uri_str); - return transfer; + return transfer; } /** * Open a File Transfer connection in order to get a remote file. * * @param transfer The actual File Transfer instance. - * @param filename The file name of the remote file to be transfered to the client. + * @param filename The file name of the remote file to be transferred to the client. * * @return true, if the connection opening had been done successfully. */ @@ -264,30 +258,27 @@ { gboolean ret = TRUE; GMythFileTransferPrivate *priv; + gchar *fname = NULL; g_return_val_if_fail (transfer != NULL, FALSE); g_return_val_if_fail (filename != NULL && strlen(filename) > 0, FALSE); priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer); - - if (priv->filename != NULL) - { - gmyth_file_transfer_close (transfer); - } - - priv->filename = g_strdup( filename ); + + //if ( ) + gmyth_file_set_file_name( GMYTH_FILE(transfer), filename ); /* configure the control socket */ if (priv->control_sock == NULL) { if (!_connect_to_backend (transfer)) { - gmyth_debug ("Connection to backend failed (Control Socket).\n"); + gmyth_debug ("Connection to backend failed (Control Socket)."); ret = FALSE; } } else { - gmyth_debug("Remote transfer control socket already created.\n"); + gmyth_debug("Remote transfer control socket already created."); } - gmyth_debug ("Got file with size = %lld.\n", priv->filesize); + gmyth_debug ("Got file with size = %lld.\n", gmyth_file_get_filesize(GMYTH_FILE(transfer))); return ret; } @@ -307,13 +298,15 @@ GMythStringList *strlist = NULL; gboolean ret = TRUE; GMythFileTransferPrivate *priv; + GMythBackendInfo *backend_info; g_return_val_if_fail (transfer != NULL, FALSE ); + + g_object_get( GMYTH_FILE(transfer), "backend-info", &backend_info, NULL ); priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer); _control_acquire_context (transfer, TRUE); - /* Creates the control socket */ if (priv->control_sock != NULL) { @@ -326,7 +319,7 @@ priv->control_sock = gmyth_socket_new(); // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version if (!gmyth_socket_connect_to_backend (priv->control_sock, - priv->backend_info->hostname, priv->backend_info->port, TRUE)) { + backend_info->hostname, backend_info->port, TRUE)) { g_object_unref (priv->control_sock); priv->control_sock = NULL; @@ -340,8 +333,8 @@ } priv->sock = gmyth_socket_new (); - gmyth_socket_connect (priv->sock, priv->backend_info->hostname, priv->backend_info->port); - gmyth_debug ("Connecting file transfer... (%s, %d)", priv->backend_info->hostname, priv->backend_info->port); + gmyth_socket_connect (priv->sock, backend_info->hostname, backend_info->port); + gmyth_debug ("Connecting file transfer... (%s, %d)", backend_info->hostname, backend_info->port); strlist = gmyth_string_list_new(); hostname = gmyth_socket_get_local_hostname(); @@ -352,7 +345,7 @@ g_string_printf (base_str, "ANN FileTransfer %s", hostname->str); gmyth_string_list_append_string (strlist, base_str ); - gmyth_string_list_append_char_array (strlist, priv->filename); + gmyth_string_list_append_char_array (strlist, gmyth_file_get_file_name(GMYTH_FILE(transfer))); gmyth_socket_write_stringlist (priv->sock, strlist ); gmyth_socket_read_stringlist (priv->sock, strlist ); @@ -361,13 +354,14 @@ priv->file_id = gmyth_string_list_get_int (strlist, 1); /* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */ - priv->filesize = gmyth_util_decode_long_long (strlist, 2); + gmyth_file_set_filesize( GMYTH_FILE(transfer), gmyth_util_decode_long_long (strlist, 2) ); - gmyth_debug ( "[%s] ***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", __FUNCTION__, - priv->file_id, priv->filesize ); + gmyth_debug ( "***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", + priv->file_id, gmyth_file_get_filesize(GMYTH_FILE(transfer)) ); - if (priv->filesize < 0 ) { - gmyth_debug ( "[%s] Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", __FUNCTION__, priv->filesize); + if ( gmyth_file_get_filesize(GMYTH_FILE(transfer)) < 0 ) { + gmyth_debug ( "Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", + gmyth_file_get_filesize(GMYTH_FILE(transfer)) ); g_object_unref (priv->sock); priv->sock = NULL; ret = FALSE; @@ -494,11 +488,6 @@ priv->control_sock = NULL; } - if (priv->filename) { - g_free (priv->filename); - priv->filename = NULL; - } - _control_release_context (transfer); } @@ -539,14 +528,13 @@ if (pos > 0 ) gmyth_string_list_append_uint64 (strlist, pos); else - gmyth_string_list_append_uint64 (strlist, priv->offset); + gmyth_string_list_append_uint64 (strlist, gmyth_file_get_offset( GMYTH_FILE(transfer) ) ); gmyth_socket_sendreceive_stringlist (priv->control_sock, strlist); gint64 retval = gmyth_string_list_get_int64 (strlist, 0); - priv->offset = retval; - gmyth_debug ( "[%s] got reading position pointer from the streaming = %lld\n", - __FUNCTION__, retval ); + gmyth_file_set_offset( GMYTH_FILE(transfer), retval ); + gmyth_debug ( "Got reading position pointer from the streaming = %lld\n", retval ); g_object_unref (strlist); g_string_free (query, TRUE); @@ -611,13 +599,13 @@ * @return The actual block size (in bytes) returned by REQUEST_BLOCK message, * or the error code. */ -GMythFileTransferReadResult +GMythFileReadResult gmyth_file_transfer_read(GMythFileTransfer *transfer, GByteArray *data, gint size, gboolean read_unlimited) { gint bytes_sent = 0; gsize bytes_read = 0; gint64 total_read = 0; - GMythFileTransferReadResult retval = GMYTH_FILE_TRANSFER_READ_OK; + GMythFileReadResult retval = GMYTH_FILE_READ_OK; GMythFileTransferPrivate *priv; GError *error = NULL; @@ -636,7 +624,7 @@ GString *query; g_return_val_if_fail (transfer != NULL, FALSE); - g_return_val_if_fail (data != NULL, GMYTH_FILE_TRANSFER_READ_ERROR); + g_return_val_if_fail (data != NULL, GMYTH_FILE_READ_ERROR); priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer); @@ -654,12 +642,12 @@ io_cond_control = g_io_channel_get_buffer_condition( io_channel ); if (priv->sock == NULL || ( io_status == G_IO_STATUS_ERROR ) ) { g_printerr( "gmyth_file_transfer_read(): Called with no raw socket.\n" ); - return GMYTH_FILE_TRANSFER_READ_ERROR; + return GMYTH_FILE_READ_ERROR; } if (priv->control_sock == NULL || ( io_status_control == G_IO_STATUS_ERROR ) ) { g_printerr( "gmyth_file_transfer_read(): Called with no control socket.\n" ); - return GMYTH_FILE_TRANSFER_READ_ERROR; + return GMYTH_FILE_READ_ERROR; } query = g_string_new (GMYTHTV_QUERY_HEADER); @@ -708,22 +696,24 @@ gmyth_debug ("Error on io_channel"); g_free (data_buffer); g_object_unref (strlist); - retval = GMYTH_FILE_TRANSFER_READ_ERROR; + retval = GMYTH_FILE_READ_ERROR; goto error; } /* append new data to the increasing byte array */ data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read); - priv->offset += bytes_read; + gmyth_file_set_offset( GMYTH_FILE(transfer), + gmyth_file_get_offset( GMYTH_FILE(transfer) ) + bytes_read ); - if (!read_unlimited && (priv->filesize > 0) && (priv->offset == priv->filesize)) { - retval = GMYTH_FILE_TRANSFER_READ_EOF; + if ( !read_unlimited && ( gmyth_file_get_filesize( GMYTH_FILE(transfer) ) > 0 ) && + ( gmyth_file_get_offset( GMYTH_FILE(transfer) ) == gmyth_file_get_filesize( GMYTH_FILE(transfer) ) ) ) { + retval = GMYTH_FILE_READ_EOF; goto error; } g_free (data_buffer); } else { - retval = GMYTH_FILE_TRANSFER_READ_ERROR; + retval = GMYTH_FILE_READ_ERROR; } if (strlist!=NULL) @@ -744,11 +734,12 @@ if (priv->recorder != NULL && priv->do_next_program_chain) { - retval = GMYTH_FILE_TRANSFER_READ_NEXT_PROG_CHAIN; + retval = GMYTH_FILE_READ_NEXT_PROG_CHAIN; GMythProgramInfo *prog_info = gmyth_recorder_get_current_program_info (priv->recorder); if (prog_info != NULL && prog_info->pathname != NULL && strlen( prog_info->pathname->str ) > 0 && - g_ascii_strcasecmp( prog_info->pathname->str, priv->filename ) != 0 ) + g_ascii_strcasecmp( prog_info->pathname->str, + gmyth_file_get_file_name( GMYTH_FILE(transfer) ) ) != 0 ) ret = gmyth_file_transfer_open (transfer, g_strrstr( prog_info->pathname->str, "/" ) ); if (prog_info != NULL ) @@ -758,7 +749,7 @@ gmyth_debug( "Cannot change to the next program info!" ); else gmyth_debug( "OK!!! MOVED to the next program info [%s]!", - priv->filename ); + gmyth_file_get_file_name( GMYTH_FILE(transfer) ) ); } } /* if */ @@ -775,12 +766,12 @@ } if ( total_read > 0 ) - priv->offset += total_read; + gmyth_file_set_offset( GMYTH_FILE(transfer), + gmyth_file_get_offset( GMYTH_FILE(transfer) ) + total_read ); return retval; } - static void _file_transfer_program_info_changed( GMythFileTransfer *transfer, gint msg_code, gpointer livetv_recorder ) @@ -864,10 +855,11 @@ guint64 gmyth_file_transfer_get_filesize (GMythFileTransfer *transfer) { - GMythFileTransferPrivate *priv; + guint64 filesize; + + g_return_val_if_fail (transfer != NULL, 0); + + g_object_get( GMYTH_FILE(transfer), "filesize", &filesize, NULL ); - g_return_val_if_fail (transfer != NULL, 0); - - priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer); - return priv->filesize; + return filesize; } diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_file_transfer.h --- a/gmyth/src/gmyth_file_transfer.h Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_file_transfer.h Thu Apr 12 13:22:53 2007 +0100 @@ -32,6 +32,7 @@ #include #include +#include "gmyth_file.h" #include "gmyth_socket.h" #include "gmyth_uri.h" #include "gmyth_backendinfo.h" @@ -52,27 +53,18 @@ #define IS_GMYTH_FILE_TRANSFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_FILE_TRANSFER_TYPE)) #define GMYTH_FILE_TRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferClass)) -typedef enum { - GMYTH_FILE_TRANSFER_READ_OK = 0, - GMYTH_FILE_TRANSFER_READ_NEXT_PROG_CHAIN = 1, - GMYTH_FILE_TRANSFER_READ_ERROR = 2, - GMYTH_FILE_TRANSFER_READ_EOF = 3 -} GMythFileTransferReadResult; - - typedef struct _GMythFileTransfer GMythFileTransfer; typedef struct _GMythFileTransferClass GMythFileTransferClass; typedef struct _GMythFileTransferPrivate GMythFileTransferPrivate; struct _GMythFileTransfer { - GObject parent; + GMythFile parent; }; - struct _GMythFileTransferClass { - GObjectClass parent_class; + GMythFileClass parent_class; /* callbacks */ guint program_info_changed_handler_signal_id; @@ -90,7 +82,7 @@ const gchar* filename); void gmyth_file_transfer_close (GMythFileTransfer *transfer); gboolean gmyth_file_transfer_is_open (GMythFileTransfer *transfer); -GMythFileTransferReadResult +GMythFileReadResult gmyth_file_transfer_read (GMythFileTransfer *transfer, GByteArray *data, gint size, diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_recorder.c --- a/gmyth/src/gmyth_recorder.c Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_recorder.c Thu Apr 12 13:22:53 2007 +0100 @@ -1210,5 +1210,5 @@ g_string_free (query, TRUE); return fr; + } - diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_remote_util.c --- a/gmyth/src/gmyth_remote_util.c Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_remote_util.c Thu Apr 12 13:22:53 2007 +0100 @@ -45,7 +45,7 @@ * @return the remote encoder instance available, or NULL if any error happens. */ GMythRecorder* -remote_request_next_free_recorder (GMythSocket *socket, int curr) +remote_request_next_free_recorder (GMythSocket *socket, gint curr) { GMythRecorder *recorder = NULL; GString *hostname; diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_remote_util.h --- a/gmyth/src/gmyth_remote_util.h Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_remote_util.h Thu Apr 12 13:22:53 2007 +0100 @@ -34,7 +34,7 @@ G_BEGIN_DECLS -GMythRecorder* remote_request_next_free_recorder (GMythSocket *socket, int curr); +GMythRecorder* remote_request_next_free_recorder (GMythSocket *socket, gint curr); gint gmyth_remote_util_get_free_recorder_count (GMythSocket *socket); G_END_DECLS diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_socket.c --- a/gmyth/src/gmyth_socket.c Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_socket.c Thu Apr 12 13:22:53 2007 +0100 @@ -151,7 +151,7 @@ } */ -static const gchar *PATH_PROC_NET_DEV = "/proc/net/dev"; +const gchar *PATH_PROC_NET_DEV = "/proc/net/dev"; /** Gets the list of all local network interfaces (using the /proc/net/dev directory). * @@ -159,7 +159,7 @@ * to be applied just like a filter. * @return List with all the local net interfaces. */ -static GList * +GList * gmyth_socket_get_local_addrs( GList *current_connections ) { @@ -208,14 +208,11 @@ return local_addrs; } - - /** * Get only the local addresses from the primary interface */ -/* -static gchar * -gmyth_socket_get_primary_addr() +gchar * +gmyth_socket_get_primary_addr(void) { gchar *if_eth0 = g_new0( gchar, sizeof(struct ifaddr)-1 ); GList *if_tmp = NULL; @@ -237,7 +234,6 @@ return if_eth0; } -*/ /** This function retrieves the local hostname of the * client machine. @@ -245,7 +241,7 @@ * @return GString* get local hostname. */ GString * -gmyth_socket_get_local_hostname () +gmyth_socket_get_local_hostname (void) { char hname[50]; gint res = gethostname (hname, 50); diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_socket.h --- a/gmyth/src/gmyth_socket.h Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_socket.h Thu Apr 12 13:22:53 2007 +0100 @@ -110,7 +110,9 @@ const gchar *hostname_backend, gint port, gboolean blocking_client); -GString * gmyth_socket_get_local_hostname (void); +gchar *gmyth_socket_get_primary_addr(void); + +GString *gmyth_socket_get_local_hostname (void); void gmyth_socket_close_connection (GMythSocket *gmyth_socket); diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_uri.c --- a/gmyth/src/gmyth_uri.c Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_uri.c Thu Apr 12 13:22:53 2007 +0100 @@ -32,6 +32,7 @@ #endif #include "gmyth_uri.h" +#include "gmyth_socket.h" #include #include @@ -356,7 +357,7 @@ uri->path = g_string_new_len (value+currIdx, uriLen-currIdx ); } - gmyth_debug( "uri value: %s", value ); + //gmyth_debug( "uri value: %s", value ); uri->query = g_string_new ( g_strstr_len( value, strlen(value), GMYTH_URI_QUESTION_DELIM ) ); eIdx = gmyth_strstr( value+currIdx, GMYTH_URI_QUESTION_DELIM ); @@ -373,6 +374,7 @@ uri->fragment = g_string_new_len (value+currIdx+sharpIdx+1, uriLen-(currIdx+sharpIdx+1)); } + /* gmyth_debug( "[%s] GMythURI: host = %s, port = %d, path = %s, query = %s, fragment = %s, "\ "user = %s, password = %s.\n", __FUNCTION__, gmyth_uri_print_field( uri->host ), uri->port, @@ -381,6 +383,7 @@ gmyth_uri_print_field( uri->fragment ), gmyth_uri_print_field ( uri->user ), gmyth_uri_print_field( uri->password ) ); + */ } @@ -482,3 +485,37 @@ return -1; } + +/** + * Checks if the URI instance represents a reference to a local file. + * + * @param uri The GMythURI instance. + * + * @return true, if the URI points to a local file. + */ +gboolean +gmyth_uri_is_local_file( const GMythURI* uri ) +{ + gboolean ret = FALSE; + gint len = -1; + + GString *hostname = gmyth_socket_get_local_hostname(); + + g_return_val_if_fail( uri != NULL, FALSE ); + + len = strlen( gmyth_uri_get_host(uri) ); + + // gmyth_debug("URI: host = %s, hostname = %s.", uri->host->str, hostname != NULL ? hostname->str : "[no hostname]"); + + ret = ( NULL != hostname && ( g_ascii_strncasecmp( uri->host->str, + (hostname)->str, len ) == 0 ) /*|| + ( g_ascii_strncasecmp( gmyth_uri_get_host(uri), gmyth_socket_get_primary_addr(), len ) == 0 ) */ ); + + if ( ret ) + gmyth_debug( "This URI is a local file..." ); + else + gmyth_debug( "This URI is NOT a local file..." ); + + return ret; + +} diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_uri.h --- a/gmyth/src/gmyth_uri.h Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_uri.h Thu Apr 12 13:22:53 2007 +0100 @@ -53,11 +53,11 @@ * Define ****************************************/ -#define GMYTH_URI_KNKOWN_PORT (-1) -#define GMYTH_URI_DEFAULT_HTTP_PORT 80 -#define GMYTH_URI_DEFAULT_FTP_PORT 21 +#define GMYTH_URI_KNKOWN_PORT (-1) +#define GMYTH_URI_DEFAULT_HTTP_PORT 80 +#define GMYTH_URI_DEFAULT_FTP_PORT 21 #define GMYTH_URI_DEFAULT_PATH "/" -#define GMYTH_URI_MAXLEN 256 +#define GMYTH_URI_MAXLEN 256 #define GMYTH_URI_PROTOCOL_DELIM "://" #define GMYTH_URI_USER_DELIM "@" @@ -105,20 +105,21 @@ GType gmyth_uri_get_type (void); GMythURI* gmyth_uri_new (void); GMythURI* gmyth_uri_new_with_value (const gchar *value); -gboolean gmyth_uri_is_equals ( GMythURI* uri1, GMythURI* uri2 ); -gboolean gmyth_uri_is_livetv ( GMythURI* uri ); -gint gmyth_uri_get_channel_num( GMythURI* uri ); -gchar* gmyth_uri_get_channel_name( GMythURI* uri ); +gboolean gmyth_uri_is_equals ( GMythURI* uri1, GMythURI* uri2 ); +gboolean gmyth_uri_is_livetv ( GMythURI* uri ); +gint gmyth_uri_get_channel_num( GMythURI* uri ); +gchar* gmyth_uri_get_channel_name( GMythURI* uri ); +gboolean gmyth_uri_is_local_file( const GMythURI* uri ); -#define gmyth_uri_get_host(urip) ( urip->host != NULL ? urip->host->str : "" ) -#define gmyth_uri_get_port(urip) ( urip->port ) -#define gmyth_uri_get_protocol(urip) ( urip->protocol != NULL ? urip->protocol->str : "" ) -#define gmyth_uri_get_path(urip) ( urip->path != NULL ? urip->path->str : "" ) -#define gmyth_uri_get_user(urip) ( urip->user != NULL ? urip->user->str : "" ) +#define gmyth_uri_get_host(urip) ( urip->host != NULL ? urip->host->str : "" ) +#define gmyth_uri_get_port(urip) ( urip->port ) +#define gmyth_uri_get_protocol(urip) ( urip->protocol != NULL ? urip->protocol->str : "" ) +#define gmyth_uri_get_path(urip) ( urip->path != NULL ? urip->path->str : "" ) +#define gmyth_uri_get_user(urip) ( urip->user != NULL ? urip->user->str : "" ) #define gmyth_uri_get_password(urip) ( urip->password != NULL ? urip->password->str : "" ) -#define gmyth_uri_get_fragment(urip) ( urip->fragment != NULL ? urip->fragment->str : "" ) -#define gmyth_uri_get_query(urip) ( urip->query != NULL ? urip->query->str : "" ) +#define gmyth_uri_get_fragment(urip) ( urip->fragment != NULL ? urip->fragment->str : "" ) +#define gmyth_uri_get_query(urip) ( urip->query != NULL ? urip->query->str : "" ) G_END_DECLS diff -r 4a604de8eaf5 -r dfa28b22a36c gmyth/src/gmyth_util.c --- a/gmyth/src/gmyth_util.c Thu Apr 12 00:01:16 2007 +0100 +++ b/gmyth/src/gmyth_util.c Thu Apr 12 13:22:53 2007 +0100 @@ -541,7 +541,6 @@ return basename; } - /** * Gets the channel list. *