[balsa] Implement testing reachability of a server
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa] Implement testing reachability of a server
- Date: Mon, 22 May 2017 22:50:00 +0000 (UTC)
commit 71f2908adc0173a6a35e3520c5836b6630171c07
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Mon May 22 18:29:23 2017 -0400
Implement testing reachability of a server
* libbalsa/server.c (libbalsa_server_can_reach_cb),
(libbalsa_server_test_can_reach_full),
(libbalsa_server_test_can_reach): new methods for testing
whether a server's host can be reached over the network;
* libbalsa/server.h: declare them.
ChangeLog | 10 +++++++++
libbalsa/server.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++
libbalsa/server.h | 12 +++++++++++
3 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c0e5f16..c1b3ee3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2017-05-22 Peter Bloomfield <pbloomfield bellsouth net>
+
+ Implement testing reachability of a server
+
+ * libbalsa/server.c (libbalsa_server_can_reach_cb),
+ (libbalsa_server_test_can_reach_full),
+ (libbalsa_server_test_can_reach): new methods for testing
+ whether a server's host can be reached over the network;
+ * libbalsa/server.h: declare them.
+
2017-05-14 Peter Bloomfield <pbloomfield bellsouth net>
* libbalsa/imap/imap-handle.c (idle_start): clear
diff --git a/libbalsa/server.c b/libbalsa/server.c
index 6dcd95e..5711829 100644
--- a/libbalsa/server.c
+++ b/libbalsa/server.c
@@ -689,3 +689,59 @@ libbalsa_server_get_cert_pass(NetClient *client,
/* FIXME - we just return the passphrase from the config, but we may also want to show a dialogue
here... */
return g_strdup(LIBBALSA_SERVER(user_data)->cert_passphrase);
}
+
+/* Test whether a server is reachable */
+
+typedef struct {
+ LibBalsaCanReachCallback * cb;
+ gpointer cb_data;
+ GObject * source_object;
+} CanReachInfo;
+
+static void
+libbalsa_server_can_reach_cb(GObject * monitor,
+ GAsyncResult * res,
+ gpointer user_data)
+{
+ CanReachInfo *info = user_data;
+ gboolean can_reach;
+
+ can_reach = g_network_monitor_can_reach_finish((GNetworkMonitor *) monitor, res, NULL);
+ info->cb(info->source_object, can_reach, info->cb_data);
+
+ g_object_unref(info->source_object);
+ g_free(info);
+}
+
+void
+libbalsa_server_test_can_reach_full(LibBalsaServer * server,
+ LibBalsaCanReachCallback * cb,
+ gpointer cb_data,
+ GObject * source_object)
+{
+ CanReachInfo *info;
+ const gchar *host;
+ GNetworkMonitor *monitor;
+ GSocketConnectable *address;
+
+ info = g_new(CanReachInfo, 1);
+ info->cb = cb;
+ info->cb_data = cb_data;
+ info->source_object = g_object_ref(source_object);
+
+ monitor = g_network_monitor_get_default();
+
+ host = server->host;
+ address = g_network_address_new(host, 0);
+ g_network_monitor_can_reach_async(monitor, address, NULL,
+ libbalsa_server_can_reach_cb, info);
+ g_object_unref(address);
+}
+
+void
+libbalsa_server_test_can_reach(LibBalsaServer * server,
+ LibBalsaCanReachCallback * cb,
+ gpointer cb_data)
+{
+ libbalsa_server_test_can_reach_full(server, cb, cb_data, (GObject *) server);
+}
diff --git a/libbalsa/server.h b/libbalsa/server.h
index 7b43ee5..af30ade 100644
--- a/libbalsa/server.h
+++ b/libbalsa/server.h
@@ -132,4 +132,16 @@ gchar *libbalsa_server_get_cert_pass(NetClient *client,
void libbalsa_server_connect_signals(LibBalsaServer * server, GCallback cb,
gpointer cb_data);
+/* Check whether a server can be reached */
+
+void libbalsa_server_test_can_reach(LibBalsaServer * server,
+ LibBalsaCanReachCallback * cb,
+ gpointer cb_data);
+
+/* Private: used only by LibBalsaMailboxRemote */
+void libbalsa_server_test_can_reach_full(LibBalsaServer * server,
+ LibBalsaCanReachCallback * cb,
+ gpointer cb_data,
+ GObject * source_object);
+
#endif /* __LIBBALSA_SERVER_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]