Implemented listening. Doesn't do anything except actually create the socket in ~/.guifications/gflib-unix, lots more work to go
--- a/gflib-unix/configure.ac Sun Jul 26 19:47:28 2009 -0500
+++ b/gflib-unix/configure.ac Sun Jul 26 23:11:55 2009 -0500
@@ -103,6 +103,14 @@
+if test x"${prefix}" = x"NONE" ; then + GFLIB_PLUGIN_DIR=`pkg-config --variable=plugin_dir gflib` + GFLIB_PLUGIN_DIR="${prefix}/lib/guifications/" +AC_SUBST(GFLIB_PLUGIN_DIR) dnl #######################################################################
dnl #######################################################################
@@ -120,5 +128,7 @@
echo Debugging enabled................: $enable_debug
+echo gflib plugin directory...........: $GFLIB_PLUGIN_DIR echo Type make to compile
--- a/gflib-unix/gflib-unix/Makefile.am Sun Jul 26 19:47:28 2009 -0500
+++ b/gflib-unix/gflib-unix/Makefile.am Sun Jul 26 23:11:55 2009 -0500
@@ -1,9 +1,17 @@
+ gf_unix_server_connection.h \ -lib_LTLIBRARIES = gflib-unix.la
+gflib_unixdir = $(GFLIB_PLUGIN_DIR) +gflib_unix_LTLIBRARIES = gflib-unix.la gflib_unix_la_SOURCES = \
+ gf_unix_server_connection.c \ --- a/gflib-unix/gflib-unix/gf_unix_core.c Sun Jul 26 19:47:28 2009 -0500
+++ b/gflib-unix/gflib-unix/gf_unix_core.c Sun Jul 26 23:11:55 2009 -0500
@@ -22,6 +22,8 @@
#include <gflib/gf_intl.h>
#include <gflib/gf_native_plugin.h>
+#include "gf_unix_server_connection.h" static gboolean initialized = FALSE;
@@ -36,6 +38,8 @@
# endif /* HAVE_BIND_TEXTDOMAIN_CODESET */
+ gf_unix_server_connection_register_type(plugin); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gflib-unix/gflib-unix/gf_unix_errors.c Sun Jul 26 23:11:55 2009 -0500
@@ -0,0 +1,28 @@
+ * Guifications - The end-all, be-all notification framework + * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com> + * 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 3 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, see <http://www.gnu.org/licenses/>. +#include "gf_unix_errors.h" +gf_unix_errors_quark(void) { + static GQuark quark = 0; + quark = g_quark_from_static_string("gflib-unix-errors"); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gflib-unix/gflib-unix/gf_unix_errors.h Sun Jul 26 23:11:55 2009 -0500
@@ -0,0 +1,37 @@
+ * Guifications - The end-all, be-all notification framework + * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com> + * 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 3 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, see <http://www.gnu.org/licenses/>. + FailedToMakeNonBlocking, +GQuark gf_unix_errors_quark(void); +#define GF_UNIX_ERRORS (gf_unix_errors_quark()) +#endif /* GF_UNIX_UTIL_H */ --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gflib-unix/gflib-unix/gf_unix_server_connection.c Sun Jul 26 23:11:55 2009 -0500
@@ -0,0 +1,204 @@
+ * Guifications - The end-all, be-all notification framework + * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com> + * 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 3 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, see <http://www.gnu.org/licenses/>. +#include <gflib/gf_intl.h> +#include <gflib/gf_log.h> +#include "gf_unix_errors.h" +#include "gf_unix_server_connection.h" +#include "gf_unix_utils.h" +#define GF_UNIX_SERVER_CONNECTION_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GF_TYPE_UNIX_SERVER_CONNECTION, GfUnixServerConnectionPrivate)) +/****************************************************************************** + *****************************************************************************/ +} GfUnixServerConnectionPrivate; +/****************************************************************************** + *****************************************************************************/ +static GfServerConnectionClass *parent_class = NULL; +/****************************************************************************** + *****************************************************************************/ +gf_unix_server_connection_listen(GfServerConnection *connection, + struct sockaddr_un saddr; + GfUnixServerConnectionPrivate *priv = + GF_UNIX_SERVER_CONNECTION_GET_PRIVATE(connection); + gf_connection_set_state(GF_CONNECTION(connection), + GF_CONNECTION_STATE_CONNECTING); + priv->fd = socket(AF_UNIX, SOCK_STREAM, 0); + *error = g_error_new(GF_UNIX_ERRORS, FailedToCreateSocket, + "Failed to create socket"); + saddr.sun_family = AF_UNIX; + priv->path = gf_unix_get_socket_path(); + g_snprintf(saddr.sun_path, 108, "%s", priv->path); + if(access(saddr.sun_path, F_OK) == 0) { + if(connect(priv->fd, (struct sockaddr *)&saddr, sizeof(saddr)) != -1) { + /* the socket is already in use */ + gf_connection_set_state(GF_CONNECTION(connection), + GF_CONNECTION_STATE_DISCONNECTED); + *error = g_error_new(GF_UNIX_ERRORS, SocketInUse, + "Socket is already in use!"); + unlink(saddr.sun_path); + if(bind(priv->fd, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) { + gf_connection_set_state(GF_CONNECTION(connection), + GF_CONNECTION_STATE_DISCONNECTED); + *error = g_error_new(GF_UNIX_ERRORS, FailedToBindToSocket, + "Failed to bind to the socket"); + if(!gf_unix_fd_make_nonblocking(priv->fd)) { + gf_connection_set_state(GF_CONNECTION(connection), + GF_CONNECTION_STATE_DISCONNECTED); + *error = g_error_new(GF_UNIX_ERRORS, FailedToMakeNonBlocking, + "Failed to make the socket nonblocking"); + gf_connection_set_state(GF_CONNECTION(connection), + GF_CONNECTION_STATE_CONNECTED); +gf_unix_server_connection_disconnect(GfConnection *connection, GError **error) +/****************************************************************************** + *****************************************************************************/ +gf_unix_server_connection_finalize(GObject *obj) { + GfUnixServerConnectionPrivate *priv = NULL; + priv = GF_UNIX_SERVER_CONNECTION_GET_PRIVATE(obj); + G_OBJECT_CLASS(parent_class)->finalize(obj); +gf_unix_server_connection_class_init(GfUnixServerConnectionClass *klass) { + GObjectClass *obj_class = G_OBJECT_CLASS(klass); + GfNamedObjectClass *gfno_class = GF_NAMED_OBJECT_CLASS(klass); + GfConnectionClass *conn_class = GF_CONNECTION_CLASS(klass); + GfServerConnectionClass *server_class = GF_SERVER_CONNECTION_CLASS(klass); + parent_class = g_type_class_peek_parent(klass); + obj_class->finalize = gf_unix_server_connection_finalize; + g_type_class_add_private(klass, sizeof(GfUnixServerConnectionPrivate)); + gfno_class->name = _("UNIX"); + server_class->listen = gf_unix_server_connection_listen; + conn_class->disconnect = gf_unix_server_connection_disconnect; +/****************************************************************************** + *****************************************************************************/ +gf_unix_server_connection_register_type(GfNativePlugin *plugin) { + static const GTypeInfo info = { + sizeof(GfUnixServerConnectionClass), + (GClassInitFunc)gf_unix_server_connection_class_init, + sizeof(GfUnixServerConnection), + type = gf_native_plugin_register_type(plugin, + GF_TYPE_SERVER_CONNECTION, + "GfUnixServerConnection", +gf_unix_server_connection_get_type(void) { + gf_log_warning("GfUnixServerConnection", + "gf_unix_server_connection_get_type called before the " + "type was registered!\n"); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gflib-unix/gflib-unix/gf_unix_server_connection.h Sun Jul 26 23:11:55 2009 -0500
@@ -0,0 +1,60 @@
+ * Guifications - The end-all, be-all notification framework + * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com> + * 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 3 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, see <http://www.gnu.org/licenses/>. +#ifndef GF_UNIX_SERVER_CONNECTION_H +#define GF_UNIX_SERVER_CONNECTION_H +#define GF_TYPE_UNIX_SERVER_CONNECTION (gf_unix_server_connection_get_type()) +#define GF_UNIX_SERVER_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GF_TYPE_UNIX_SERVER_CONNECTION, GfUnixServerConnection)) +#define GF_UNIX_SERVER_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GF_TYPE_UNIX_SERVER_CONNECTION, GfUnixServerConnectionClass)) +#define GF_IS_UNIX_SERVER_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GF_TYPE_UNIX_SERVER_CONNECTION)) +#define GF_IS_UNIX_SERVER_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GF_TYPE_UNIX_SERVER_CONNECTION)) +#define GF_UNIX_SERVER_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GF_TYPE_UNIX_SERVER_CONNECTION, GfUnixServerConnectionClass)) +typedef struct _GfUnixServerConnection GfUnixServerConnection; +typedef struct _GfUnixServerConnectionClass GfUnixServerConnectionClass; +#include <gflib/gf_server_connection.h> +#include <gflib/gf_native_plugin.h> +struct _GfUnixServerConnection { + GfServerConnection parent; + void (*_gf_reserved1)(void); + void (*_gf_reserved2)(void); + void (*_gf_reserved3)(void); + void (*_gf_reserved4)(void); +struct _GfUnixServerConnectionClass { + GfServerConnectionClass parent; + void (*_gf_reserved1)(void); + void (*_gf_reserved2)(void); + void (*_gf_reserved3)(void); + void (*_gf_reserved4)(void); +GType gf_unix_server_connection_get_type(void); +void gf_unix_server_connection_register_type(GfNativePlugin *plugin); +#endif /* GF_UNIX_SERVER_CONNECTION_H */ --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gflib-unix/gflib-unix/gf_unix_utils.c Sun Jul 26 23:11:55 2009 -0500
@@ -0,0 +1,52 @@
+ * Guifications - The end-all, be-all notification framework + * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com> + * 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 3 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, see <http://www.gnu.org/licenses/>. +#include "gf_unix_utils.h" +#include <gflib/gf_filesystem.h> +gf_unix_get_socket_path(void) { + gchar *dir = NULL, *path = NULL; + dir = gf_fs_user_settings_dir(); + path = g_build_filename(dir, "gflib-unix", NULL); +gf_unix_fd_make_nonblocking(gint fd) { + flags = fcntl(fd, F_GETFL, 0); + flags = fcntl(fd, F_SETFL, flags); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gflib-unix/gflib-unix/gf_unix_utils.h Sun Jul 26 23:11:55 2009 -0500
@@ -0,0 +1,31 @@
+ * Guifications - The end-all, be-all notification framework + * Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com> + * 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 3 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, see <http://www.gnu.org/licenses/>. +gchar *gf_unix_get_socket_path(void); +gboolean gf_unix_fd_make_nonblocking(gint fd); +#endif /* GF_UNIX_UTILS_H */