Commit 73b631c6 authored by Zeeshan Ali's avatar Zeeshan Ali

Add a demo user-authorization agent

It uses libnotify to ask user to authorize the app for access to geolocation
info.
parent 34fe5033
......@@ -101,6 +101,23 @@ else
fi
AM_CONDITIONAL([BUILD_GEOIP_SERVER], [test "x$build_geoip_server" = "xyes"])
# Demo agent
AC_ARG_ENABLE(demo-agent,
AS_HELP_STRING([--enable-demo-agent=yes|no],
[Build demo agent (default=no)]),
[enable_demo_agent=$enableval],
[enable_demo_agent=no])
if test "x$enable_demo_agent" = "xyes"; then
PKG_CHECK_MODULES(DEMO_AGENT, [
glib-2.0 >= $GLIB_MIN_VERSION
gio-2.0 >= $GLIB_MIN_VERSION
gio-unix-2.0 >= $GLIB_MIN_VERSION
libnotify])
else
AC_DEFINE([BUILD_DEMO_AGENT], [0], [Build demo agent?])
fi
AM_CONDITIONAL([BUILD_DEMO_AGENT], [test "x$enable_demo_agent" = "xyes"])
GNOME_COMPILE_WARNINGS([maximum])
dnl Debugging
......
noinst_PROGRAMS = where-am-i
noinst_PROGRAMS = where-am-i agent
where_am_i_SOURCES = where-am-i.c
where_am_i_CFLAGS = $(GEOCLUE_CFLAGS) \
$(WARN_CFLAGS) \
-DLOCALEDIR="\"$(datadir)/locale\""
where_am_i_LDADD = $(GEOCLUE_LIBS)
if BUILD_DEMO_AGENT
interface_data = $(top_builddir)/src/agent/geoclue-agent-interface.xml
dbus_built_sources = geoclue-agent-interface.c geoclue-agent-interface.h
geoclue-agent-interface.c: geoclue-agent-interface.h
geoclue-agent-interface.h: Makefile.am $(interface_data)
gdbus-codegen \
--interface-prefix org.freedesktop.GeoClue2. \
--c-namespace GClue \
--generate-c-code geoclue-agent-interface \
$(interface_data)
BUILT_SOURCES = $(dbus_built_sources) \
$(NULL)
agent_SOURCES = $(BUILT_SOURCES) \
gclue-service-agent.h \
gclue-service-agent.c \
agent.c \
$(NULL)
agent_CFLAGS = $(DEMO_AGENT_CFLAGS) \
$(WARN_CFLAGS) \
-DLOCALEDIR="\"$(datadir)/locale\"" \
-DABS_SRCDIR=\""$(abs_srcdir)"\"
agent_LDADD = $(DEMO_AGENT_LIBS)
endif # BUILD_DEMO_AGENT
/* vim: set et ts=8 sw=8: */
/* agent.c
*
* Copyright (C) 2013 Red Hat, Inc.
*
* Geoclue 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.
*
* Geoclue 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 Geoclue; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
*/
#include <config.h>
#include <gio/gio.h>
#include <locale.h>
#include <glib/gi18n.h>
#include <stdlib.h>
#include <libnotify/notify.h>
#include "gclue-service-agent.h"
/* Commandline options */
static gboolean version;
static GOptionEntry entries[] =
{
{ "version",
0,
0,
G_OPTION_ARG_NONE,
&version,
N_("Display version number"),
NULL },
{ NULL }
};
GDBusConnection *connection;
GMainLoop *main_loop;
GClueServiceAgent *agent = NULL;
static void
on_service_agent_ready (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GError *error = NULL;
agent = gclue_service_agent_new_finish (res, &error);
if (agent == NULL) {
g_critical ("Failed to launch agent service: %s", error->message);
g_error_free (error);
exit (-3);
}
}
static void
on_get_bus_ready (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GError *error = NULL;
connection = g_bus_get_finish (res, &error);
if (connection == NULL) {
g_critical ("Failed to get connection to system bus: %s",
error->message);
g_error_free (error);
exit (-2);
}
gclue_service_agent_new_async (connection,
NULL,
on_service_agent_ready,
NULL);
}
#define ABS_PATH ABS_SRCDIR "/agent"
int
main (int argc, char **argv)
{
GError *error = NULL;
GOptionContext *context;
setlocale (LC_ALL, "");
textdomain (GETTEXT_PACKAGE);
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
g_set_application_name ("GeoClue Agent");
notify_init (_("GeoClue"));
context = g_option_context_new ("- Geoclue Agent service");
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
if (!g_option_context_parse (context, &argc, &argv, &error)) {
g_critical ("option parsing failed: %s\n", error->message);
exit (-1);
}
if (version) {
g_print ("%s\n", PACKAGE_VERSION);
exit (0);
}
if (g_strcmp0 (ABS_PATH, argv[0]) != 0) {
g_print ("Must be run with absolute path to binary: %s\n",
ABS_PATH);
exit (-4);
}
g_bus_get (G_BUS_TYPE_SYSTEM,
NULL,
on_get_bus_ready,
NULL);
main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (main_loop);
if (agent != NULL);
g_object_unref (agent);
g_main_loop_unref (main_loop);
return 0;
}
This diff is collapsed.
/* vim: set et ts=8 sw=8: */
/* gclue-service-agent.h
*
* Copyright (C) 2013 Red Hat, Inc.
*
* Geoclue 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.
*
* Geoclue 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 Geoclue; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
*/
#ifndef GCLUE_SERVICE_AGENT_H
#define GCLUE_SERVICE_AGENT_H
#include <glib-object.h>
#include "geoclue-agent-interface.h"
G_BEGIN_DECLS
#define GCLUE_TYPE_SERVICE_AGENT (gclue_service_agent_get_type())
#define GCLUE_SERVICE_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCLUE_TYPE_SERVICE_AGENT, GClueServiceAgent))
#define GCLUE_SERVICE_AGENT_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCLUE_TYPE_SERVICE_AGENT, GClueServiceAgent const))
#define GCLUE_SERVICE_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCLUE_TYPE_SERVICE_AGENT, GClueServiceAgentClass))
#define GCLUE_IS_SERVICE_AGENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCLUE_TYPE_SERVICE_AGENT))
#define GCLUE_IS_SERVICE_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCLUE_TYPE_SERVICE_AGENT))
#define GCLUE_SERVICE_AGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GCLUE_TYPE_SERVICE_AGENT, GClueServiceAgentClass))
typedef struct _GClueServiceAgent GClueServiceAgent;
typedef struct _GClueServiceAgentClass GClueServiceAgentClass;
typedef struct _GClueServiceAgentPrivate GClueServiceAgentPrivate;
struct _GClueServiceAgent
{
GClueAgentSkeleton parent;
/*< private >*/
GClueServiceAgentPrivate *priv;
};
struct _GClueServiceAgentClass
{
GClueAgentSkeletonClass parent_class;
};
GType gclue_service_agent_get_type (void) G_GNUC_CONST;
void gclue_service_agent_new_async (GDBusConnection *connection,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GClueServiceAgent * gclue_service_agent_new_finish (GAsyncResult *res,
GError **error);
G_END_DECLS
#endif /* GCLUE_SERVICE_AGENT_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment