summaryrefslogtreecommitdiffstats
path: root/ncpwrapper.c
diff options
context:
space:
mode:
Diffstat (limited to 'ncpwrapper.c')
-rw-r--r--ncpwrapper.c138
1 files changed, 138 insertions, 0 deletions
diff --git a/ncpwrapper.c b/ncpwrapper.c
new file mode 100644
index 0000000..cdec0c5
--- /dev/null
+++ b/ncpwrapper.c
@@ -0,0 +1,138 @@
+#include <gtk/gtk.h>
+
+#include "globals.h"
+#include "ncpwrapper.h"
+#include "dialogs.h"
+
+
+static void
+cb_child_watch( GPid pid,
+ gint status)
+{
+ /* Close pid */
+ g_spawn_close_pid( pid );
+}
+
+
+static gboolean
+cb_out_watch( GIOChannel *channel,
+ GIOCondition cond)
+{
+ GString *string;
+ gchar *tmp;
+ gsize size;
+
+ if( cond == G_IO_HUP )
+ {
+ g_io_channel_unref( channel );
+ return( FALSE );
+ }
+
+ string = g_string_new("");
+
+ while (g_io_channel_read_line( channel, &tmp, &size, NULL, NULL) == G_IO_STATUS_NORMAL)
+ {
+ if(tmp != NULL)
+ string = g_string_append (string, tmp);
+
+ g_free( tmp );
+ }
+
+
+ show_message( GTK_MESSAGE_INFO,"%s", "ncpmount output","%s",string->str);
+ g_string_free(string, TRUE);
+
+ return( TRUE );
+}
+
+
+static gboolean
+cb_err_watch( GIOChannel *channel,
+ GIOCondition cond)
+{
+ GString *string;
+ gchar *tmp;
+ gsize size;
+
+ if( cond == G_IO_HUP )
+ {
+ g_io_channel_unref( channel );
+ return( FALSE );
+ }
+/*
+ g_io_channel_read_line( channel, &string, &size, NULL, NULL );
+ show_message( GTK_MESSAGE_ERROR,"ERROR: %s", string,"%s",string);
+ puts ("err");
+ puts (string);
+ g_free( string );*/
+
+ string = g_string_new("");
+
+ while (g_io_channel_read_line( channel, &tmp, &size, NULL, NULL) == G_IO_STATUS_NORMAL)
+ {
+ if(tmp != NULL)
+ string = g_string_append (string, tmp);
+
+ g_free( tmp );
+ }
+
+
+ show_message( GTK_MESSAGE_ERROR,"%s", "ncpmount error","%s",string->str);
+ g_string_free(string, TRUE);
+
+ return( TRUE );
+}
+
+/*
+ TODO - jak odchytit uspesne mountnuti???
+*/
+
+void run_ncpmount()
+{
+
+ GIOChannel *out_ch, *err_ch;
+ GError *gerror = NULL;
+ GPid pid;
+ gint out, err;
+ gboolean ret;
+ const gchar *command = get_ncpmount_command();
+
+ gchar **argv = g_strsplit(command, " ", 0);
+
+ puts (command);
+
+ g_free(argv[0]);
+ argv[0] = g_strdup("/usr/bin/ncpmount");
+
+ /* gchar *argv[] = {"/usr/bin/ncpmount", "-v", NULL};*/
+
+ /* Spawn child process */
+ ret = g_spawn_async_with_pipes( NULL, argv, NULL,
+ G_SPAWN_DO_NOT_REAP_CHILD, NULL,
+ NULL, &pid, NULL, &out, &err, &gerror);
+ if( !ret )
+ {
+ g_warning( "SPAWN FAILED" );
+ show_message( GTK_MESSAGE_ERROR,"ERROR: %s", "Spawn failed!","%s",gerror->message);
+
+ g_error_free(gerror);
+ return;
+ }
+
+ /* Add watch function to catch termination of the process. This function
+ * will clean any remnants of process. */
+ g_child_watch_add( pid, (GChildWatchFunc)cb_child_watch, NULL);
+
+ /* Create channels that will be used to read data from pipes. */
+#ifdef G_OS_WIN32
+ out_ch = g_io_channel_win32_new_fd( out );
+ err_ch = g_io_channel_win32_new_fd( err );
+#else
+ out_ch = g_io_channel_unix_new( out );
+ err_ch = g_io_channel_unix_new( err );
+#endif
+
+ /* Add watches to channels */
+ g_io_add_watch( out_ch, G_IO_IN | G_IO_HUP, (GIOFunc)cb_out_watch, NULL );
+ g_io_add_watch( err_ch, G_IO_IN | G_IO_HUP, (GIOFunc)cb_err_watch, NULL );
+}