vino r1059 - in trunk: . capplet



Author: jwendell
Date: Fri Jan 23 17:26:46 2009
New Revision: 1059
URL: http://svn.gnome.org/viewvc/vino?rev=1059&view=rev

Log:
2009-01-23  Jonh Wendell  <jwendell gnome org>

	Make use of a file containinig URLs of WebServices, instead of hard
	code.
	* capplet/webservices: The file with the URLs.
	* capplet/vino-url-webservice.[ch]: Provide a function to retrieve
	a URL from the file.
	* capplet/vino-preferences.c: Use the function above instead of
	hard coding the URL.



Added:
   trunk/capplet/org.gnome.vino.Service.php
   trunk/capplet/vino-url-webservice.c
   trunk/capplet/vino-url-webservice.h
   trunk/capplet/webservices
Modified:
   trunk/ChangeLog
   trunk/capplet/Makefile.am
   trunk/capplet/vino-preferences.c

Modified: trunk/capplet/Makefile.am
==============================================================================
--- trunk/capplet/Makefile.am	(original)
+++ trunk/capplet/Makefile.am	Fri Jan 23 17:26:46 2009
@@ -18,6 +18,7 @@
 	gedit-spinner.h gedit-spinner.c \
 	vino-message-box.h vino-message-box.c \
 	sexy-url-label.h sexy-url-label.c \
+	vino-url-webservice.h vino-url-webservice.c \
 	$(NULL)
 vino_preferences_LDADD = \
 	$(VINO_CAPPLET_LIBS) \
@@ -27,7 +28,7 @@
 	$(NULL)
 
 gladedir   = $(datadir)/vino
-glade_DATA = vino-preferences.glade
+glade_DATA = vino-preferences.glade webservices
 
 desktopdir       = $(datadir)/applications
 desktop_in_files = vino-preferences.desktop.in
@@ -42,4 +43,5 @@
 EXTRA_DIST = \
 	vino-preferences.glade \
 	vino-preferences.desktop.in \
+	webservices \
 	$(NULL)

Added: trunk/capplet/org.gnome.vino.Service.php
==============================================================================
--- (empty file)
+++ trunk/capplet/org.gnome.vino.Service.php	Fri Jan 23 17:26:46 2009
@@ -0,0 +1,116 @@
+<?php
+/*
+ * Copyright (C) 2008 Jorge Pereira <jorge jorgepereira com br>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors:
+ *      Jorge Pereira <jorge jorgepereira com br>
+ */
+
+/** default timeout */
+define (TIMEOUT, 10);
+
+/** default port of vino server */
+define (DEFAULT_PORT, 5900);
+
+/** Version of service */
+define (VERSION, "0.1");
+
+/** disable message errors */
+error_reporting(0);
+
+/**
+ * Return the version of service
+ *
+ * @return string
+ */
+function vino_get_version ($method_name = null, $params = null, $app_data = null)
+{
+   return VERSION;
+}
+
+/**
+ * This function return the ip of client
+ *
+ * @return string
+ */
+function vino_get_ip ($method_name = null, $params = null, $app_data = null)
+{
+   return $_SERVER['REMOTE_ADDR'];
+}
+
+/**
+ * This function check and return array with fields below
+ *
+ * @return array
+ * + @field string  ip 
+ * + @field boolean status
+ * + @field string  version
+ */
+function vino_check ($method_name = null, $params = null, $app_data = null)
+{
+   return array (ip      => vino_get_ip (),
+                 status  => vino_check_port ($method_name, $params, $app_data),
+                 version => vino_get_version ()
+   );
+}
+
+/**
+ * This function verify if possible create a socket with client host 
+ * using the port in paramenter.
+ *
+ * @return bool
+ */
+function vino_check_port ($method_name = null, $params = null, $app_data = null)
+{
+  $port    = $params[0] > 0 ? $params[0] : DEFAULT_PORT;
+  $timeout = $params[1] > 0 ? $params[1] : TIMEOUT;
+  $server  = vino_get_ip ();
+  $status  = -1;
+
+  if ($server and $port and $timeout)
+  {
+    $status = @fsockopen("$server", $port, $errno, $errstr, $timeout);
+  }
+
+  return ($status) ? true : false;
+}
+
+/**
+ * Create a server
+ */
+$obj = xmlrpc_server_create ();
+
+/**
+ * Register the methods
+ */
+xmlrpc_server_register_method ($obj, "vino.get_ip", "vino_get_ip");
+xmlrpc_server_register_method ($obj, "vino.get_version", "vino_get_version");
+xmlrpc_server_register_method ($obj, "vino.check_port", "vino_check_port");
+xmlrpc_server_register_method ($obj, "vino.check", "vino_check");
+
+/**
+ * Call the method
+ */
+echo xmlrpc_server_call_method ($obj, $GLOBALS['HTTP_RAW_POST_DATA'], '');
+
+/**
+ * Destroy the xmlrpc object
+ */
+xmlrpc_server_destroy ($obj);
+
+?>

Modified: trunk/capplet/vino-preferences.c
==============================================================================
--- trunk/capplet/vino-preferences.c	(original)
+++ trunk/capplet/vino-preferences.c	Fri Jan 23 17:26:46 2009
@@ -31,6 +31,7 @@
 #include <glib/gi18n.h>
 #include <libsoup/soup.h>
 #include "vino-message-box.h"
+#include "vino-url-webservice.h"
 
 #ifdef VINO_ENABLE_KEYRING
 #include <gnome-keyring.h>
@@ -194,7 +195,7 @@
     {
       vino_message_box_show_image (VINO_MESSAGE_BOX (dialog->message));
       vino_message_box_set_label (VINO_MESSAGE_BOX (dialog->message),
-                                  _("Checking the conectivity of this machine..."));
+                                  _("Checking the connectivity of this machine..."));
       g_timeout_add_seconds (3, (GSourceFunc) delay_update_message, dialog);
     }
   else
@@ -925,6 +926,7 @@
 vino_preferences_dialog_update_message_box (VinoPreferencesDialog *dialog)
 {
   gboolean allowed;
+  gchar *url;
 
   if (dialog->retrieving_info)
     return;
@@ -940,9 +942,16 @@
       return;
     }
 
+  url = vino_url_webservice_get_random ();
+  if (!url)
+    {
+      error_message (dialog);
+      return;
+    }
+
   vino_message_box_show_image (VINO_MESSAGE_BOX (dialog->message));
   vino_message_box_set_label (VINO_MESSAGE_BOX (dialog->message),
-			      _("Checking the conectivity of this machine..."));
+			      _("Checking the connectivity of this machine..."));
 
   dbus_g_proxy_call (dialog->proxy,
                      "GetExternalPort",
@@ -954,7 +963,7 @@
   if (!dialog->session)
     dialog->session = soup_session_async_new ();
 
-  dialog->msg = soup_xmlrpc_request_new ("http://blog.jorgepereira.com.br/jorge/org.gnome.vino.Service.php";,
+  dialog->msg = soup_xmlrpc_request_new (url,
 					 "vino.check",
 					 G_TYPE_INT, dialog->port,
 					 G_TYPE_INT, TIMEOUT,
@@ -967,6 +976,7 @@
   g_timeout_add_seconds (TIMEOUT+1,
 			 (GSourceFunc) request_timeout_cb,
 			 dialog);
+  g_free (url);
 }
 
 static void

Added: trunk/capplet/vino-url-webservice.c
==============================================================================
--- (empty file)
+++ trunk/capplet/vino-url-webservice.c	Fri Jan 23 17:26:46 2009
@@ -0,0 +1,73 @@
+/*
+ * vino-url-webservice.c
+ * Copyright (C) Jonh Wendell 2009 <wendell bani com br>
+ * 
+ * vino-url-webservice.c is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * vino-url-webservice.c is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author:
+ *      Jonh Wendell <wendell bani com br>
+ */
+
+#include "vino-url-webservice.h"
+
+#define VINO_WEBSERVICE_FILE "webservices"
+
+gchar *
+vino_url_webservice_get_random (void)
+{
+  gchar       *file_contents, *result;
+  gchar      **entries;
+  gint32      i;
+  GSList      *string_list = NULL;
+  GError      *error = NULL;
+  const gchar *filename;
+
+  if (g_file_test (VINO_WEBSERVICE_FILE, G_FILE_TEST_EXISTS))
+    filename = VINO_WEBSERVICE_FILE;
+  else
+    filename = VINO_GLADEDIR G_DIR_SEPARATOR_S VINO_WEBSERVICE_FILE;
+
+  if (!g_file_get_contents (filename,
+                            &file_contents,
+                            NULL,
+                            &error))
+    {
+      g_warning ("%s", error->message);
+      g_error_free (error);
+      return NULL;
+    }
+
+  entries = g_strsplit (file_contents, "\n", 0);
+  for (i=0; entries[i]; i++)
+    {
+      g_strstrip (entries[i]);
+      if (entries[i][0] != '\0' && entries[i][0] != '#')
+        string_list = g_slist_append (string_list, entries[i]);
+    }
+
+  i = g_slist_length (string_list);
+  switch (i)
+    {
+      case 0: result = NULL; break;
+      case 1: result = g_strdup (string_list->data); break;
+      default: result = g_strdup (g_slist_nth_data (string_list, g_random_int_range (0,  i)));
+    }
+
+  g_free (file_contents);
+  g_strfreev (entries);
+  g_slist_free (string_list);
+
+  return result;
+}
+

Added: trunk/capplet/vino-url-webservice.h
==============================================================================
--- (empty file)
+++ trunk/capplet/vino-url-webservice.h	Fri Jan 23 17:26:46 2009
@@ -0,0 +1,29 @@
+/*
+ * vino-url-webservice.h
+ * Copyright (C) Jonh Wendell 2009 <wendell bani com br>
+ * 
+ * vino-url-webservice.h is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * vino-url-webservice.h is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author:
+ *      Jonh Wendell <wendell bani com br>
+ */
+
+#ifndef _VINO_URL_WEBSERVICE_H_
+#define _VINO_URL_WEBSERVICE_H_
+
+#include <glib.h>
+
+gchar *vino_url_webservice_get_random (void);
+
+#endif /* _VINO_URL_WEBSERVICE_H_ */

Added: trunk/capplet/webservices
==============================================================================
--- (empty file)
+++ trunk/capplet/webservices	Fri Jan 23 17:26:46 2009
@@ -0,0 +1,28 @@
+# This file lists all webservices URLs that can be used by vino to provide
+# a connectivity test.
+
+# The webservice must be a XMLRPC service, which provides a method 'vino.check':
+# vino.check (
+#   IN int port, -> port to be tested against. Default is 5900.
+#   IN int timeout, -> timeout, in seconds to cancel the testing. Default is 10.
+#   OUT string IP, -> The public IP of the machine (variable 'REMOTE_ADDR').
+#   OUT bool status, -> True if can connect to the host at specified port.
+#   OUT string version -> Version of the method signature, currently is "0.1".
+# )
+# 
+# Basically what the service does is: Try to open a connection into the
+# incoming host (REMOTE_ADDR) at the specified port. It returns the IP and
+# if the connection was established successfully.
+
+# Check a PHP implementation of that service in the file org.gnome.vino.Service.php,
+# shipped in vino source code, in 'capplet' folder.
+
+# Put one address per line. Blank lines and started with a '#' are ignored.
+
+
+
+# Jorge Pereira
+http://blog.jorgepereira.com.br/jorge/org.gnome.vino.Service.php
+
+# Jonh Wendell
+http://www.bani.com.br/org.gnome.vino.Service.php



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]