[Goodies-commits] r7690 - in xfce4-screenshooter/trunk: . lib panel-plugin src

Jerome Guelfucci jeromeg at xfce.org
Tue Jul 7 23:16:04 CEST 2009


Author: jeromeg
Date: 2009-07-07 21:16:04 +0000 (Tue, 07 Jul 2009)
New Revision: 7690

Modified:
   xfce4-screenshooter/trunk/ChangeLog
   xfce4-screenshooter/trunk/configure.ac.in
   xfce4-screenshooter/trunk/lib/Makefile.am
   xfce4-screenshooter/trunk/lib/screenshooter-actions.c
   xfce4-screenshooter/trunk/lib/screenshooter-actions.h
   xfce4-screenshooter/trunk/lib/screenshooter-dialogs.c
   xfce4-screenshooter/trunk/lib/screenshooter-global.h
   xfce4-screenshooter/trunk/lib/screenshooter-utils.c
   xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c
   xfce4-screenshooter/trunk/lib/screenshooter-zimagez.h
   xfce4-screenshooter/trunk/panel-plugin/Makefile.am
   xfce4-screenshooter/trunk/src/Makefile.am
   xfce4-screenshooter/trunk/src/main.c
Log:
Use libsoup instead of XMLRPC-C.

Add libsoup as a dependency, remove the XMLRPC-C stuff. Factorize the
xmlrpc calls in lib/screenshooter-zimagez.c and add some additional
error checking.


Modified: xfce4-screenshooter/trunk/ChangeLog
===================================================================
--- xfce4-screenshooter/trunk/ChangeLog	2009-07-07 13:50:40 UTC (rev 7689)
+++ xfce4-screenshooter/trunk/ChangeLog	2009-07-07 21:16:04 UTC (rev 7690)
@@ -1,5 +1,13 @@
 2009-07-07 jeromeg
 
+Use libsoup instead of XMLRPC-C.
+
+Add libsoup as a dependency, remove the XMLRPC-C stuff. Factorize the
+xmlrpc calls in lib/screenshooter-zimagez.c and add some additional
+error checking.
+
+2009-07-07 jeromeg
+
 Use integers instead of strings to identify the information fields.
 
 2009-07-05 jeromeg

Modified: xfce4-screenshooter/trunk/configure.ac.in
===================================================================
--- xfce4-screenshooter/trunk/configure.ac.in	2009-07-07 13:50:40 UTC (rev 7689)
+++ xfce4-screenshooter/trunk/configure.ac.in	2009-07-07 21:16:04 UTC (rev 7690)
@@ -56,36 +56,9 @@
 XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.16.0])
 XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.12.0])
 XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.16.0])
+XDT_CHECK_PACKAGE([SOUP], [libsoup-2.4], [2.26.0])
 
-dnl ************************************
-dnl *** Check for optional packages ***
-dnl ************************************
-
-XDT_CHECK_OPTIONAL_PACKAGE([CURL], [libcurl], [7])
-
 dnl **************************
-dnl *** Check for xmlrpc-c ***
-dnl **************************
-
-XMLRPC_LIBS=""
-XMLRPC_CFLAGS=""
-AC_PATH_PROG([XMLRPC_CONFIG], [xmlrpc-c-config], [no])
-if test x"$XMLRPC_CONFIG" != x"no"; then
-  AC_MSG_CHECKING([XMLRPC_CFLAGS])
-  XMLRPC_CFLAGS="`$XMLRPC_CONFIG --cflags client`"
-  AC_MSG_RESULT([$XMLRPC_CFLAGS])
-
-  AC_MSG_CHECKING([XMLRPC_LIBS])
-  XMLRPC_LIBS="`$XMLRPC_CONFIG --libs client`"
-  AC_MSG_RESULT([$XMLRPC_LIBS])
-
-  AC_DEFINE([HAVE_XMLRPC], [1], [Xmlrpc-c was found on the system])
-fi
-AM_CONDITIONAL([HAVE_XMLRPC], [test x"$XMLRPC_CONFIG" != x"no"])
-AC_SUBST([XMLRPC_CFLAGS])
-AC_SUBST([XMLRPC_LIBS])
-
-dnl **************************
 dnl *** Check for xsltproc ***
 dnl **************************
 AC_ARG_ENABLE([xsltproc], [AC_HELP_STRING([--enable-xsltproc], [Use xsltproc to build documentation @<:@default=no@:>@])],, [enable_xsltproc=no])
@@ -164,15 +137,6 @@
 echo ""
 
 echo "  * Debugging support:             $enable_debug"
-if test x"$CURL_FOUND" = x"yes"; then
-  if test x"$XMLRPC_CONFIG" != x"no"; then
-    echo "  * ZimageZ support:               yes"
-  else
-    echo "  * ZimageZ support:               no"
-  fi
-else
-  echo "  * ZimageZ support:               no"
-fi
 
 echo ""
 echo "Maintainer Configuration:"

Modified: xfce4-screenshooter/trunk/lib/Makefile.am
===================================================================
--- xfce4-screenshooter/trunk/lib/Makefile.am	2009-07-07 13:50:40 UTC (rev 7689)
+++ xfce4-screenshooter/trunk/lib/Makefile.am	2009-07-07 21:16:04 UTC (rev 7690)
@@ -3,12 +3,19 @@
 
 libscreenshooter_la_SOURCES =	\
 	$(libscreenshooter_built_sources) \
+  exo-job.c exo-job.h \
+	exo-simple-job.c exo-simple-job.h \
+	katze-throbber.c katze-throbber.h \
 	libscreenshooter.h \
+  sexy-url-label.c sexy-url-label.h \
 	screenshooter-actions.c screenshooter-actions.h \
 	screenshooter-capture.c screenshooter-capture.h \
   screenshooter-dialogs.c screenshooter-dialogs.h \
 	screenshooter-global.h \
-	screenshooter-utils.c screenshooter-utils.h 
+	screenshooter-job.c screenshooter-job.h \
+	screenshooter-simple-job.c screenshooter-simple-job.h \
+	screenshooter-utils.c screenshooter-utils.h \ 
+	screenshooter-zimagez.c screenshooter-zimagez.h
 
 libscreenshooter_la_CFLAGS = \
 	-I$(top_srcdir)	\
@@ -16,36 +23,19 @@
 	@GLIB_CFLAGS@ \
 	@LIBXFCE4UTIL_CFLAGS@ \
 	@LIBXFCEGUI4_CFLAGS@ \
+	@SOUP_CFLAGS@ \
   -DPACKAGE_LOCALE_DIR=\"$(localedir)\"
 	
 libscreenshooter_la_LIBADD = \
   @GTK_LIBS@ \
 	@LIBXFCE4UTIL_LIBS@ \
 	@LIBXFCEGUI4_LIBS@ \
-  @GLIB_LIBS@
+  @GLIB_LIBS@ \
+	@SOUP_LIBS@
 
-if HAVE_XMLRPC
-if HAVE_CURL
-
 libscreenshooter_built_sources = \
 	screenshooter-marshal.c screenshooter-marshal.h
 
-libscreenshooter_la_SOURCES +=	\
-	$(libscreenshooter_built_sources) \
-  exo-job.c exo-job.h \
-	exo-simple-job.c exo-simple-job.h \
-	katze-throbber.c katze-throbber.h \
-	screenshooter-job.c screenshooter-job.h \
-	screenshooter-simple-job.c screenshooter-simple-job.h \
-	screenshooter-zimagez.c screenshooter-zimagez.h \
-  sexy-url-label.c sexy-url-label.h
-
-libscreenshooter_la_CFLAGS += \
-	$(XMLRPC_CFLAGS)
-
-libscreenshooter_la_LIBADD += \
-	$(XMLRPC_LIBS) -lxmlrpc_client
-
 ##
 ## Rules to auto-generate built sources
 ##
@@ -84,6 +74,3 @@
 
 EXTRA_DIST = \
 	screenshooter-marshal.list
-
-endif
-endif

Modified: xfce4-screenshooter/trunk/lib/screenshooter-actions.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-actions.c	2009-07-07 13:50:40 UTC (rev 7689)
+++ xfce4-screenshooter/trunk/lib/screenshooter-actions.c	2009-07-07 21:16:04 UTC (rev 7690)
@@ -110,14 +110,10 @@
             {
               screenshooter_open_screenshot (screenshot_path, sd->app);
             }
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
           else
             {
               screenshooter_upload_to_zimagez (screenshot_path, sd->last_user);
             }
-#endif
-#endif
         }
 
       g_object_unref (temp_dir);

Modified: xfce4-screenshooter/trunk/lib/screenshooter-actions.h
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-actions.h	2009-07-07 13:50:40 UTC (rev 7689)
+++ xfce4-screenshooter/trunk/lib/screenshooter-actions.h	2009-07-07 21:16:04 UTC (rev 7690)
@@ -24,12 +24,7 @@
 #include "screenshooter-capture.h"
 #include "screenshooter-global.h"
 #include "screenshooter-dialogs.h"
-
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
 #include "screenshooter-zimagez.h"
-#endif
-#endif
 
 gboolean screenshooter_take_and_output_screenshot (ScreenshotData *sd);
 

Modified: xfce4-screenshooter/trunk/lib/screenshooter-dialogs.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-dialogs.c	2009-07-07 13:50:40 UTC (rev 7689)
+++ xfce4-screenshooter/trunk/lib/screenshooter-dialogs.c	2009-07-07 21:16:04 UTC (rev 7690)
@@ -50,13 +50,9 @@
 static void
 cb_clipboard_toggled               (GtkToggleButton    *tb,
                                     ScreenshotData     *sd);
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
 static void
 cb_zimagez_toggled                 (GtkToggleButton    *tb,
                                     ScreenshotData     *sd);
-#endif
-#endif
 static void
 cb_show_save_dialog_toggled        (GtkToggleButton    *tb,
                                     ScreenshotData     *sd);
@@ -207,8 +203,6 @@
 
 
 
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
 static void cb_zimagez_toggled (GtkToggleButton *tb, ScreenshotData *sd)
 {
   if (gtk_toggle_button_get_active (tb))
@@ -216,10 +210,9 @@
       sd->action = UPLOAD;
     }
 }
-#endif
-#endif
 
 
+
 /* Set sd->show_save_dialog when the button is toggled */
 static void cb_show_save_dialog_toggled (GtkToggleButton *tb, ScreenshotData *sd)
 {
@@ -700,16 +693,9 @@
   GtkWidget *save_checkbox;
 
   GtkWidget *actions_main_box, *actions_label, *actions_alignment;
-
   GtkWidget *save_radio_button, *dir_chooser;
-
   GtkWidget *clipboard_radio_button, *open_with_radio_button;
-
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
   GtkWidget *zimagez_radio_button;
-#endif
-#endif
 
   GtkListStore *liststore;
   GtkWidget *combobox;
@@ -1195,11 +1181,9 @@
   cb_toggle_set_sensi (GTK_TOGGLE_BUTTON (open_with_radio_button), combobox);
 
   /* Upload to zimagez radio button */
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
-  zimagez_radio_button = 
+  zimagez_radio_button =
     gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (save_radio_button),
-	                                               _("Host on ZimageZ"));
+                                                 _("Host on ZimageZ"));
 
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (zimagez_radio_button),
                                 (sd->action == UPLOAD));
@@ -1215,8 +1199,6 @@
                              0, 1, 3, 4);
 
   gtk_widget_show (zimagez_radio_button);
-#endif
-#endif
 
   return dlg;
 }
@@ -1237,7 +1219,7 @@
   gchar *savename = NULL;
 
   if (show_save_dialog)
-	  {
+    {
       GdkPixbuf *thumbnail;
 
       GtkWidget *preview;
@@ -1290,12 +1272,12 @@
       dialog_response = gtk_dialog_run (GTK_DIALOG (chooser));
 
       /* The user pressed the save button */
-	    if (G_LIKELY (dialog_response == GTK_RESPONSE_ACCEPT))
-	      {
+      if (G_LIKELY (dialog_response == GTK_RESPONSE_ACCEPT))
+       {
           save_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (chooser));
         }
 
-	    gtk_widget_destroy (chooser);
+      gtk_widget_destroy (chooser);
 
       if (G_LIKELY (save_uri != NULL))
         {
@@ -1303,10 +1285,10 @@
 
           g_free (save_uri);
         }
-	  }
-	else
-	  {
-	    /* Else, we just save the file in the default folder */
+   }
+ else
+   {
+      /* Else, we just save the file in the default folder */
       gchar *save_uri = g_build_filename (default_dir, filename, NULL);
 
       savename = save_screenshot_to (screenshot, save_uri);

Modified: xfce4-screenshooter/trunk/lib/screenshooter-global.h
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-global.h	2009-07-07 13:50:40 UTC (rev 7689)
+++ xfce4-screenshooter/trunk/lib/screenshooter-global.h	2009-07-07 21:16:04 UTC (rev 7690)
@@ -32,11 +32,7 @@
   SAVE,
   CLIPBOARD,
   OPEN,
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
   UPLOAD,
-#endif
-#endif
 };
 
 
@@ -52,11 +48,7 @@
   gint close;
   gchar *screenshot_dir;
   gchar *app;
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
   gchar *last_user;
-#endif
-#endif
   gboolean cli;
 }
 ScreenshotData;

Modified: xfce4-screenshooter/trunk/lib/screenshooter-utils.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-utils.c	2009-07-07 13:50:40 UTC (rev 7689)
+++ xfce4-screenshooter/trunk/lib/screenshooter-utils.c	2009-07-07 21:16:04 UTC (rev 7690)
@@ -65,11 +65,7 @@
   gint close_app = 1;
   gchar *screenshot_dir = g_strdup (home_uri);
   gchar *app = g_strdup ("none");
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
   gchar *last_user = g_strdup ("");
-#endif
-#endif
 
   if (G_LIKELY (file != NULL))
     {
@@ -91,12 +87,8 @@
           g_free (app);
           app = g_strdup (xfce_rc_read_entry (rc, "app", "none"));
 
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
           g_free (last_user);
           last_user = g_strdup (xfce_rc_read_entry (rc, "last_user", ""));
-#endif
-#endif
 
           g_free (screenshot_dir);
           screenshot_dir =
@@ -119,11 +111,7 @@
   sd->close = close_app;
   sd->screenshot_dir = screenshot_dir;
   sd->app = app;
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
   sd->last_user = last_user;
-#endif
-#endif
 }
 
 
@@ -155,14 +143,9 @@
   xfce_rc_write_int_entry (rc, "close", sd->close);
   xfce_rc_write_entry (rc, "screenshot_dir", sd->screenshot_dir);
   xfce_rc_write_entry (rc, "app", sd->app);
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
   xfce_rc_write_entry (rc, "last_user", sd->last_user);
-#endif
-#endif
 
   TRACE ("Flush and close the rc file");
-
   xfce_rc_flush (rc);
   xfce_rc_close (rc);
 }

Modified: xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c	2009-07-07 13:50:40 UTC (rev 7689)
+++ xfce4-screenshooter/trunk/lib/screenshooter-zimagez.c	2009-07-07 21:16:04 UTC (rev 7690)
@@ -54,6 +54,12 @@
 static void              open_url_hook             (SexyUrlLabel      *url_label,
                                                     gchar             *url,
                                                     gpointer           user_data);
+static gboolean          do_xmlrpc                 (SoupSession       *session,
+                                                    const gchar       *uri,
+                                                    const gchar       *method,
+                                                    GError           **error,
+                                                    GValue            *retval,
+                                                    ...);
 static gboolean          has_empty_field           (GtkListStore      *liststore);
 static ScreenshooterJob *zimagez_upload_to_zimagez (const gchar       *file_name,
                                                     gchar             *last_user);
@@ -100,11 +106,94 @@
 
 
 static gboolean
+do_xmlrpc (SoupSession *session, const gchar *uri, const gchar *method,
+           GError **error, GValue *retval, ...)
+{
+  SoupMessage *msg;
+  va_list args;
+  GValueArray *params;
+  GError *err = NULL;
+  char *body;
+
+  va_start (args, retval);
+  params = soup_value_array_from_args (args);
+  va_end (args);
+
+  body =
+    soup_xmlrpc_build_method_call (method, params->values,
+                                   params->n_values);
+  g_value_array_free (params);
+
+  if (!body)
+    {
+      err = g_error_new (SOUP_XMLRPC_FAULT,
+                         SOUP_XMLRPC_FAULT_APPLICATION_ERROR,
+                         _("An error occured when creating the XMLRPC"
+                           " request."));
+      g_propagate_error (error, err);
+
+      return FALSE;
+    }
+
+  msg = soup_message_new ("POST", uri);
+  soup_message_set_request (msg, "text/xml", SOUP_MEMORY_TAKE,
+                            body, strlen (body));
+  soup_session_send_message (session, msg);
+
+  if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
+    {
+      TRACE ("Error during the XMLRPC exchange: %d %s\n",
+             msg->status_code, msg->reason_phrase);
+
+      err = g_error_new (SOUP_XMLRPC_FAULT,
+                         SOUP_XMLRPC_FAULT_TRANSPORT_ERROR,
+                         _("An error occured when transfering the data"
+                           " to ZimageZ."));
+      g_propagate_error (error, err);
+      g_object_unref (msg);
+
+      return FALSE;
+    }
+
+  if (!soup_xmlrpc_parse_method_response (msg->response_body->data,
+                                          msg->response_body->length,
+                                          retval, &err))
+    {
+      if (err)
+        {
+          TRACE ("Fault when parsing the response: %d %s\n",
+                 err->code, err->message);
+
+          g_propagate_error (error, err);
+        }
+      else
+        {
+          TRACE ("Unable to parse the response, and no error...");
+
+          err = g_error_new (SOUP_XMLRPC_FAULT,
+                             SOUP_XMLRPC_FAULT_APPLICATION_ERROR,
+                             _("An error occured when parsing the response"
+                               " from ZimageZ."));
+          g_propagate_error (error, err);
+        }
+
+      g_object_unref (msg);
+      return FALSE;
+    }
+
+  g_object_unref (msg);
+
+  return TRUE;
+}
+
+
+
+static gboolean
 has_empty_field (GtkListStore *liststore)
 {
   GtkTreeIter iter;
   gboolean result = FALSE;
-  
+
   gtk_tree_model_get_iter_first (GTK_TREE_MODEL (liststore), &iter);
 
   do
@@ -132,9 +221,6 @@
   gchar *comment = g_strdup ("");
   gchar *data = NULL;
   gchar *encoded_password = NULL;
-  gchar *escaped_file_name;
-  gchar *escaped_title;
-  gchar *escaped_comment;
   gchar *file_name = NULL;
   gchar *login_response = NULL;
   gchar *online_file_name = NULL;
@@ -143,18 +229,18 @@
   gchar *user;
 
   gsize data_length;
+  gboolean response = FALSE;
 
-  xmlrpc_env env;
-  xmlrpc_value *resultP = NULL;
-  xmlrpc_bool response = 0;
+  const gchar *serverurl = g_strdup ("http://www.zimagez.com/apiXml.php");
+  const gchar *method_login = g_strdup ("apiXml.xmlrpcLogin");
+  const gchar *method_logout = g_strdup ("apiXml.xmlrpcLogout");
+  const gchar *method_upload = g_strdup ("apiXml.xmlrpcUpload");
+  SoupSession *session;
 
-  const gchar * const serverurl = "http://www.zimagez.com/apiXml.php";
-  const gchar * const method_login = "apiXml.xmlrpcLogin";
-  const gchar * const method_logout = "apiXml.xmlrpcLogout";
-  const gchar * const method_upload = "apiXml.xmlrpcUpload";
-
+  GError *tmp_error;
   GtkTreeIter iter;
   GtkListStore *liststore;
+  GValue response_value;
 
   g_return_val_if_fail (SCREENSHOOTER_IS_JOB (job), FALSE);
   g_return_val_if_fail (param_values != NULL, FALSE);
@@ -179,38 +265,16 @@
       user = g_strdup ("");
     }
 
-  g_object_set_data_full (G_OBJECT (job), "user", 
+  g_object_set_data_full (G_OBJECT (job), "user",
                           g_strdup (user), (GDestroyNotify) g_free);
 
   /* Get the path of the image that is to be uploaded */
   image_path = g_value_get_string (g_value_array_get_nth (param_values, 0));
 
-  /* Start the user XML RPC session */
+  /* Start the user soup session */
   exo_job_info_message (EXO_JOB (job), _("Initialize the connection..."));
+  session = soup_session_sync_new ();
 
-  TRACE ("Initialize the RPC environment");
-  xmlrpc_env_init(&env);
-
-  TRACE ("Initialize the RPC client");
-  xmlrpc_client_init2 (&env, XMLRPC_CLIENT_NO_FLAGS, PACKAGE_NAME, PACKAGE_VERSION,
-                       NULL, 0);
-
-  if (env.fault_occurred)
-    {
-      GError *tmp_error =
-        g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
-                     _("An error occurred during the XML exchange: %s (%d).\n "
-                       "The screenshot could not be uploaded."),
-                     env.fault_string, env.fault_code);
-
-      xmlrpc_env_clean (&env);
-      xmlrpc_client_cleanup ();
-
-      g_propagate_error (error, tmp_error);
-
-      return FALSE;
-    }
-
   TRACE ("Get the information liststore ready.");
   liststore = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING);
 
@@ -262,10 +326,10 @@
 
       switch (field_index)
         {
-          case USER: 
+          case USER:
             user = g_strdup (field_value);
             break;
-          case PASSWORD: 
+          case PASSWORD:
             password = g_strdup (field_value);
             break;
           case TITLE:
@@ -286,8 +350,8 @@
     {
       if (exo_job_set_error_if_cancelled (EXO_JOB (job), error))
         {
-          xmlrpc_env_clean (&env);
-          xmlrpc_client_cleanup ();
+          soup_session_abort (session);
+          g_object_unref (session);
 
           g_free (user);
           g_free (password);
@@ -317,97 +381,69 @@
       encoded_password = g_strdup (g_strreverse (rot13 (password)));
 
       TRACE ("User: %s", user);
+      TRACE ("Encoded password: %s", encoded_password);
 
       /* Start the user session */
       TRACE ("Call the login method");
 
       exo_job_info_message (EXO_JOB (job), _("Login on ZimageZ..."));
 
-      resultP = xmlrpc_client_call (&env, serverurl, method_login,
-                                    "(ss)", user, encoded_password);
-
-      if (env.fault_occurred)
+      if (!do_xmlrpc (session, serverurl, method_login,
+                      &tmp_error, &response_value,
+                      G_TYPE_STRING, user,
+                      G_TYPE_STRING, encoded_password,
+                      G_TYPE_INVALID))
         {
-          GError *tmp_error =
-            g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
-                         _("An error occurred during the XML exchange: %s (%d).\n "
-                           "The screenshot could not be uploaded."),
-                         env.fault_string, env.fault_code);
+          g_propagate_error (error, tmp_error);
+          soup_session_abort (session);
+          g_object_unref (session);
 
-          xmlrpc_env_clean (&env);
-          xmlrpc_client_cleanup ();
-
-          g_free (user);
           g_free (password);
           g_free (title);
           g_free (comment);
           g_free (encoded_password);
 
-          g_propagate_error (error, tmp_error);
-
           return FALSE;
         }
 
       TRACE ("Read the login response");
 
       /* If the response is a boolean, there was an error */
-      if (xmlrpc_value_type (resultP) == XMLRPC_TYPE_BOOL)
+      if (G_VALUE_HOLDS_BOOLEAN (&response_value))
         {
-          xmlrpc_read_bool (&env, resultP, &response);
-
-          if (env.fault_occurred)
-            {
-              GError *tmp_error =
-                g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
-                             _("An error occurred during the XML exchange: %s (%d).\n "
-                               "The screenshot could not be uploaded."),
-                             env.fault_string, env.fault_code);
-
-              xmlrpc_env_clean (&env);
-              xmlrpc_client_cleanup ();
-
-              g_free (user);
-              g_free (password);
-              g_free (title);
-              g_free (comment);
-              g_free (encoded_password);
-
-              g_propagate_error (error, tmp_error);
-
-              return FALSE;
-            }
+          response = g_value_get_boolean (&response_value);
         }
       /* Else we read the string response to get the session ID */
+      else if (G_VALUE_HOLDS_STRING (&response_value))
+        {
+          TRACE ("Read the session ID");
+          login_response = g_strdup (g_value_get_string (&response_value));
+          response = TRUE;
+        }
+      /* We received an unexpected reply */
       else
         {
-          TRACE ("Read the session ID");
-          xmlrpc_read_string (&env, resultP, (const gchar ** const)&login_response);
+          GError *tmp_err =
+            g_error_new (SOUP_XMLRPC_FAULT,
+                         SOUP_XMLRPC_FAULT_PARSE_ERROR_NOT_WELL_FORMED,
+                         "%s", _("An unexpected reply from ZimageZ was received."
+                                 " The upload of the screenshot failed."));
+          soup_session_abort (session);
+          g_object_unref (session);
 
-          if (env.fault_occurred)
-           {
-             GError *tmp_error =
-               g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
-                            _("An error occurred during the XML exchange: %s (%d).\n "
-                              "The screenshot could not be uploaded."),
-                            env.fault_string, env.fault_code);
+          g_free (user);
+          g_free (password);
+          g_free (title);
+          g_free (comment);
+          g_free (encoded_password);
 
-             xmlrpc_env_clean (&env);
-             xmlrpc_client_cleanup ();
+          g_propagate_error (error, tmp_err);
 
-             g_free (user);
-             g_free (password);
-             g_free (title);
-             g_free (comment);
-             g_free (encoded_password);
+          return FALSE;
+        }
 
-             g_propagate_error (error, tmp_error);
+      g_value_unset (&response_value);
 
-             return FALSE;
-           }
-
-          response = 1;
-        }
-
       if (!response)
         {
           /* Login failed, erase the password and ask for the correct on to the
@@ -470,9 +506,7 @@
         }
     }
 
-  xmlrpc_DECREF (resultP);
-
-  g_object_set_data_full (G_OBJECT (job), "user", 
+  g_object_set_data_full (G_OBJECT (job), "user",
                           g_strdup (user), (GDestroyNotify) g_free);
 
   g_free (user);
@@ -489,117 +523,91 @@
   /* Get the basename of the image path */
   file_name = g_path_get_basename (image_path);
 
-  /* Escape the strings before passing them to xmlrpc-c */
-  escaped_file_name = g_markup_escape_text (file_name, -1);
-  escaped_title = g_markup_escape_text (title, -1);
-  escaped_comment = g_markup_escape_text (comment, -1);
-
   exo_job_info_message (EXO_JOB (job), _("Upload the screenshot..."));
 
   TRACE ("Call the upload method");
-  resultP = xmlrpc_client_call (&env, serverurl, method_upload,
-                                "(sssss)", encoded_data, escaped_file_name, 
-                                escaped_title, escaped_comment,
-                                login_response);
+  do_xmlrpc (session, serverurl, method_upload,
+             &tmp_error, &response_value,
+             G_TYPE_STRING, encoded_data,
+             G_TYPE_STRING, file_name,
+             G_TYPE_STRING, title,
+             G_TYPE_STRING, comment,
+             G_TYPE_STRING, login_response,
+             G_TYPE_INVALID);
 
-  g_free (escaped_file_name);
-  g_free (escaped_title);
-  g_free (escaped_comment);
   g_free (title);
   g_free (comment);
   g_free (file_name);
 
-  if (env.fault_occurred)
+  if (tmp_error)
     {
-      GError *tmp_error =
-        g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
-                     _("An error occurred during the XML exchange: %s (%d).\n "
-                       "The screenshot could not be uploaded."),
-                     env.fault_string, env.fault_code);
+      soup_session_abort (session);
+      g_object_unref (session);
 
-      xmlrpc_env_clean (&env);
-      xmlrpc_client_cleanup ();
-
       g_propagate_error (error, tmp_error);
 
       return FALSE;
     }
 
   /* If the response is a boolean, there was an error */
-  if (xmlrpc_value_type (resultP) == XMLRPC_TYPE_BOOL)
+  if (G_VALUE_HOLDS_BOOLEAN (&response_value))
     {
-      xmlrpc_bool response_upload;
-
-      xmlrpc_read_bool (&env, resultP, &response_upload);
-
-      if (env.fault_occurred)
+      if (!g_value_get_boolean (&response_value))
         {
-          GError *tmp_error =
+          GError *tmp_err =
             g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
-                         _("An error occurred during the XML exchange: %s (%d).\n "
-                           "The screenshot could not be uploaded."),
-                         env.fault_string, env.fault_code);
-
-          xmlrpc_env_clean (&env);
-          xmlrpc_client_cleanup ();
-
-          g_propagate_error (error, tmp_error);
-
-          return FALSE;
-        }
-
-      if (!response_upload)
-        {
-          GError *tmp_error =
-            g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
                          _("An error occurred while uploading the screenshot."));
 
-          xmlrpc_env_clean (&env);
-          xmlrpc_client_cleanup ();
+          soup_session_abort (session);
+          g_object_unref (session);
+          g_propagate_error (error, tmp_err);
 
-          g_propagate_error (error, tmp_error);
-
           return FALSE;
         }
     }
   /* Else we get the file name */
+  else if (G_VALUE_HOLDS_STRING (&response_value))
+    {
+      TRACE ("The screenshot has been uploaded, get the file name.");
+      online_file_name = g_strdup (g_value_get_string (&response_value));
+    }
+  /* We received un unexpected reply */
   else
     {
-      xmlrpc_read_string (&env, resultP, (const char **)&online_file_name);
+      GError *tmp_err =
+        g_error_new (SOUP_XMLRPC_FAULT,
+                     SOUP_XMLRPC_FAULT_PARSE_ERROR_NOT_WELL_FORMED,
+                     "%s", _("An unexpected reply from ZimageZ was received."
+                       " The upload of the screenshot failed."));
+      soup_session_abort (session);
+      g_object_unref (session);
+      g_propagate_error (error, tmp_err);
 
-      TRACE ("The screenshot has been uploaded, get the file name.");
-
-      if (env.fault_occurred)
-        {
-          GError *tmp_error =
-            g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
-                         _("An error occurred during the XML exchange: %s (%d).\n "
-                           "The screenshot could not be uploaded."),
-                         env.fault_string, env.fault_code);
-
-          xmlrpc_env_clean (&env);
-          xmlrpc_client_cleanup ();
-
-          g_propagate_error (error, tmp_error);
-
-          return FALSE;
-        }
+      return FALSE;
     }
 
-  xmlrpc_DECREF (resultP);
+  g_value_unset (&response_value);
 
   /* End the user session */
-
   exo_job_info_message (EXO_JOB (job), _("Close the session on ZimageZ..."));
 
   TRACE ("Closing the user session");
 
-  xmlrpc_client_call (&env, serverurl, method_logout, "(s)", login_response);
+  do_xmlrpc (session, serverurl, method_logout,
+             &tmp_error, &response_value,
+             G_TYPE_STRING, login_response,
+             G_TYPE_INVALID);
 
-  TRACE ("Cleanup the XMLRPC session");
-  xmlrpc_env_clean (&env);
-  xmlrpc_client_cleanup ();
+  if (tmp_error)
+    g_error_free (tmp_error);
 
+  g_value_unset (&response_value);
+
+  /* Clean the soup session */
+  soup_session_abort (session);
+  g_object_unref (session);
+  g_free (login_response);
+
   screenshooter_job_image_uploaded (job, online_file_name);
 
   return TRUE;
@@ -775,7 +783,7 @@
           default:
             break;
         }
-      
+
       g_free (field_value);
     }
   while (gtk_tree_model_iter_next (GTK_TREE_MODEL (liststore), &iter));
@@ -882,7 +890,7 @@
     last_user_temp = g_strdup ("");
 
   last_user = g_strdup (last_user_temp);
-    
+
   /* Dialog */
   dialog =
     xfce_titled_dialog_new_with_buttons (_("My screenshot on ZimageZ"),
@@ -910,7 +918,7 @@
 
   /* Links bold label */
   link_label = gtk_label_new ("");
-  gtk_label_set_markup (GTK_LABEL (link_label), 
+  gtk_label_set_markup (GTK_LABEL (link_label),
                         _("<span weight=\"bold\" stretch=\"semiexpanded\">"
                           "Links</span>"));
   gtk_misc_set_alignment (GTK_MISC (link_label), 0, 0);
@@ -955,7 +963,7 @@
 
   /* Examples bold label */
   example_label = gtk_label_new ("");
-  gtk_label_set_markup (GTK_LABEL (example_label), 
+  gtk_label_set_markup (GTK_LABEL (example_label),
                         _("<span weight=\"bold\" stretch=\"semiexpanded\">"
                           "Code for a thumbnail pointing to the full size image</span>"));
   gtk_misc_set_alignment (GTK_MISC (example_label), 0, 0);
@@ -1028,7 +1036,7 @@
 {
   g_return_if_fail (error != NULL);
 
-  screenshooter_error ("%s", error->message); 
+  screenshooter_error ("%s", error->message);
 }
 
 

Modified: xfce4-screenshooter/trunk/lib/screenshooter-zimagez.h
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-zimagez.h	2009-07-07 13:50:40 UTC (rev 7689)
+++ xfce4-screenshooter/trunk/lib/screenshooter-zimagez.h	2009-07-07 21:16:04 UTC (rev 7690)
@@ -26,10 +26,8 @@
 
 #include <glib.h>
 #include <glib/gstdio.h>
+#include <libsoup/soup.h>
 
-#include <xmlrpc-c/base.h>
-#include <xmlrpc-c/client.h>
-
 #include "screenshooter-utils.h"
 #include "screenshooter-simple-job.h"
 #include "sexy-url-label.h"

Modified: xfce4-screenshooter/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-screenshooter/trunk/panel-plugin/Makefile.am	2009-07-07 13:50:40 UTC (rev 7689)
+++ xfce4-screenshooter/trunk/panel-plugin/Makefile.am	2009-07-07 21:16:04 UTC (rev 7690)
@@ -6,12 +6,14 @@
 	-I$(top_srcdir)	\
 	-I$(top_srcdir)/lib	\
 	@LIBXFCE4PANEL_CFLAGS@ \
-	@GTHREAD_CFLAGS@
+	@GTHREAD_CFLAGS@ \
+	@SOUP_CFLAGS@
 
 xfce4_screenshooter_plugin_LDFLAGS = \
+	$(top_builddir)/lib/libscreenshooter.la \
 	@LIBXFCE4PANEL_LIBS@ \
 	@GTHREAD_LIBS@ \
-	$(top_builddir)/lib/libscreenshooter.la
+	@SOUP_LIBS@
 
 xfce4_screenshooter_plugin_SOURCES = \
 	screenshooter-plugin.c

Modified: xfce4-screenshooter/trunk/src/Makefile.am
===================================================================
--- xfce4-screenshooter/trunk/src/Makefile.am	2009-07-07 13:50:40 UTC (rev 7689)
+++ xfce4-screenshooter/trunk/src/Makefile.am	2009-07-07 21:16:04 UTC (rev 7690)
@@ -7,6 +7,7 @@
 	@LIBXFCE4UTIL_CFLAGS@ \
 	@LIBXFCEGUI4_CFLAGS@ \
 	@GTHREAD_CFLAGS@ \
+	@SOUP_CFLAGS@ \
 	-DPACKAGE_LOCALE_DIR=\"$(localedir)\"
 	
 xfce4_screenshooter_LDFLAGS = \
@@ -14,6 +15,7 @@
 	@GTK_LIBS@ \
 	@GLIB_LIBS@ \
 	@GTHREAD_LIBS@ \
+	@SOUP_LIBS@ \
 	@LIBXFCE4UTIL_LIBS@ \
 	@LIBXFCEGUI4_LIBS@
 

Modified: xfce4-screenshooter/trunk/src/main.c
===================================================================
--- xfce4-screenshooter/trunk/src/main.c	2009-07-07 13:50:40 UTC (rev 7689)
+++ xfce4-screenshooter/trunk/src/main.c	2009-07-07 21:16:04 UTC (rev 7690)
@@ -34,11 +34,7 @@
 gboolean fullscreen = FALSE;
 gboolean no_save_dialog = FALSE;
 gboolean hide_mouse = FALSE;
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
 gboolean upload = FALSE;
-#endif
-#endif
 gchar *screenshot_dir;
 gchar *application;
 gint delay = 0;
@@ -85,15 +81,11 @@
     N_("Directory where the screenshot will be saved"),
     NULL
   },
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL  
   {
     "upload", 'u', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &upload,
     N_("Host the screenshot on ZimageZ, a free online image hosting service"),
     NULL
   },
-#endif
-#endif
   {
     "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &version,
     N_("Version information"),
@@ -204,15 +196,11 @@
           sd->app = application;
           sd->action = OPEN;
         }
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
       else if (upload)
         {
           sd->app = g_strdup ("none");
           sd->action = UPLOAD;
         }
-#endif
-#endif
       else
         {
           sd->app = g_strdup ("none");
@@ -262,8 +250,6 @@
       if (preferences_file != NULL)
         screenshooter_write_rc_file (preferences_file, sd);
     }
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
   else if (sd->action == UPLOAD)
     {
       const gchar *preferences_file =
@@ -287,16 +273,10 @@
             }
         }
     }
-#endif
-#endif
 
   g_free (sd->screenshot_dir);
   g_free (sd->app);
-#ifdef HAVE_XMLRPC
-#ifdef HAVE_CURL
   g_free (sd->last_user);
-#endif
-#endif
   g_free (sd);
 
   TRACE ("Ciao");




More information about the Goodies-commits mailing list