summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarcus Lundblad <ml@update.uu.se>2015-11-30 22:50:27 +0100
committerJonas Danielsson <jonas@threetimestwo.org>2015-12-12 17:07:08 +0100
commit1754186adb30f706037a86f93ebea852770c8cf3 (patch)
tree7ad21bc62e0b9433384fd02de9705f53c858face /lib
parent60471b8eccc501019714c4020a59adf247469b21 (diff)
downloadgnome-maps-1754186adb30f706037a86f93ebea852770c8cf3.tar.gz
osmEdit: Add specialized OAuthProxyCall subclass
Add OAuthProxyCall class supporting setting the request content. https://bugzilla.gnome.org/show_bug.cgi?id=726628
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am9
-rw-r--r--lib/maps-osm-oauth-proxy-call.c100
-rw-r--r--lib/maps-osm-oauth-proxy-call.h59
3 files changed, 165 insertions, 3 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 74818e2d..6d4629bf 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -15,7 +15,8 @@ libgnome_maps_headers_private = \
maps-osm-node.h \
maps-osm-object.h \
maps-osm-relation.h \
- maps-osm-way.h
+ maps-osm-way.h \
+ maps-osm-oauth-proxy-call.h
libgnome_maps_sources = \
maps-contact-store.c \
@@ -26,7 +27,8 @@ libgnome_maps_sources = \
maps-osm-node.c \
maps-osm-object.c \
maps-osm-way.c \
- maps-osm-relation.c
+ maps-osm-relation.c \
+ maps-osm-oauth-proxy-call.c
libgnome_maps_la_SOURCES = \
$(libgnome_maps_sources) \
@@ -58,7 +60,8 @@ GnomeMaps_1_0_gir_INCLUDES = \
GLib-2.0 \
GObject-2.0 \
GeocodeGlib-1.0 \
- Champlain-0.12
+ Champlain-0.12 \
+ Rest-0.7
GnomeMaps_1_0_gir_PACKAGES = gobject-2.0 geocode-glib-1.0
GnomeMaps_1_0_gir_FILES = $(libgnome_maps_la_SOURCES)
GnomeMaps_1_0_gir_CFLAGS = $(MAPS_CFLAGS) -I$(top_srcdir) -I$(top_builddir) -I$(srcdir)
diff --git a/lib/maps-osm-oauth-proxy-call.c b/lib/maps-osm-oauth-proxy-call.c
new file mode 100644
index 00000000..5f6babd6
--- /dev/null
+++ b/lib/maps-osm-oauth-proxy-call.c
@@ -0,0 +1,100 @@
+/* maps-osm-oauth-proxy-call.c
+ *
+ * Copyright (C) 2015 Marcus Lundblad <ml@update.uu.se>
+ *
+ * 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 "maps-osm-oauth-proxy-call.h"
+
+#include <glib.h>
+#include <rest/rest-proxy-call.h>
+#include <string.h>
+
+#define MAPS_OSM_OAUTH_PROXY_CALL_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), MAPS_TYPE_OSM_OAUTH_PROXY_CALL,\
+ MapsOSMOAuthProxyCallPrivate))
+
+struct _MapsOSMOAuthProxyCallPrivate
+{
+ char *payload;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(MapsOSMOAuthProxyCall, maps_osm_oauth_proxy_call,
+ OAUTH_TYPE_PROXY_CALL);
+
+static gboolean
+maps_osm_oauth_proxy_call_serialize_params (RestProxyCall *call,
+ gchar **content_type,
+ gchar **content,
+ gsize *content_len,
+ GError **error)
+{
+ g_return_val_if_fail(MAPS_IS_OSM_OAUTH_PROXY_CALL (call), FALSE);
+ g_return_val_if_fail(content_type != NULL, FALSE);
+ g_return_val_if_fail(content != NULL, FALSE);
+ g_return_val_if_fail(content_len != NULL, FALSE);
+
+ gchar *payload = (MAPS_OSM_OAUTH_PROXY_CALL (call))->priv->payload;
+
+ *content_type = g_strdup ("text/xml");
+ *content = g_strdup (payload);
+ *content_len = strlen (payload);
+
+ return TRUE;
+}
+
+static void
+maps_osm_oauth_proxy_call_dispose (GObject *object)
+{
+ MapsOSMOAuthProxyCall *call = MAPS_OSM_OAUTH_PROXY_CALL (object);
+
+ g_free (call->priv->payload);
+ call->priv->payload = NULL;
+
+ G_OBJECT_CLASS (maps_osm_oauth_proxy_call_parent_class)->dispose (object);
+}
+
+static void
+maps_osm_oauth_proxy_call_class_init (MapsOSMOAuthProxyCallClass *klass)
+{
+ RestProxyCallClass *proxy_call_class = REST_PROXY_CALL_CLASS (klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ proxy_call_class->serialize_params =
+ maps_osm_oauth_proxy_call_serialize_params;
+ gobject_class->dispose = maps_osm_oauth_proxy_call_dispose;
+}
+
+static void
+maps_osm_oauth_proxy_call_init (MapsOSMOAuthProxyCall *call)
+{
+ call->priv = MAPS_OSM_OAUTH_PROXY_CALL_GET_PRIVATE (call);
+}
+
+MapsOSMOAuthProxyCall *
+maps_osm_oauth_proxy_call_new (OAuthProxy *proxy, const char *payload)
+{
+ g_return_val_if_fail (OAUTH_IS_PROXY (proxy), NULL);
+ g_return_val_if_fail (payload != NULL, NULL);
+
+ MapsOSMOAuthProxyCall *call =
+ g_object_new (MAPS_TYPE_OSM_OAUTH_PROXY_CALL, "proxy", proxy, NULL);
+
+ call->priv->payload = g_strdup (payload);
+
+ return call;
+}
+
+
diff --git a/lib/maps-osm-oauth-proxy-call.h b/lib/maps-osm-oauth-proxy-call.h
new file mode 100644
index 00000000..bdd9ef58
--- /dev/null
+++ b/lib/maps-osm-oauth-proxy-call.h
@@ -0,0 +1,59 @@
+/* maps-osm-oauth-proxy-call.h
+ *
+ * Copyright (C) 2015 Marcus Lundblad <ml@update.uu.se>
+ *
+ * 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/>.
+ *
+ * Author: Marcus Lundblad <ml@update.uu.se>
+ */
+
+#ifndef MAPS_OSM_OAUTH_PROXY_CALL_H
+#define MAPS_OSM_OAUTH_PROXY_CALL_H
+
+#include <glib-object.h>
+
+#include <rest/oauth-proxy-call.h>
+#include <rest/oauth-proxy.h>
+
+G_BEGIN_DECLS
+
+#define MAPS_TYPE_OSM_OAUTH_PROXY_CALL (maps_osm_oauth_proxy_call_get_type ())
+#define MAPS_OSM_OAUTH_PROXY_CALL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAPS_TYPE_OSM_OAUTH_PROXY_CALL, MapsOSMOAuthProxyCall))
+#define MAPS_OSM_OAUTH_PROXY_CALL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MAPS_TYPE_OSM_OAUTH_PROXY_CALL, MapsOSMOAuthProxyCallClass))
+#define MAPS_IS_OSM_OAUTH_PROXY_CALL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAPS_TYPE_OSM_OAUTH_PROXY_CALL))
+#define MAPS_IS_OSM_OAUTH_PROXY_CALL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MAPS_TYPE_OSM_OAUTH_PROXY_CALL))
+#define MAPS_OSM_OAUTH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MAPS_TYPE_OSM_OAUTH_PROXY_CALL, MapsOSMOAuthProxyCallClass))
+
+typedef struct _MapsOSMOAuthProxyCall MapsOSMOAuthProxyCall;
+typedef struct _MapsOSMOAuthProxyCallPrivate MapsOSMOAuthProxyCallPrivate;
+typedef struct _MapsOSMOAuthProxyCallClass MapsOSMOAuthProxyCallClass;
+
+struct _MapsOSMOAuthProxyCall
+{
+ OAuthProxyCall parent;
+ MapsOSMOAuthProxyCallPrivate *priv;
+};
+
+struct _MapsOSMOAuthProxyCallClass
+{
+ OAuthProxyCallClass parent_class;
+};
+
+GType maps_osm_oauth_proxy_call_get_type(void);
+MapsOSMOAuthProxyCall *maps_osm_oauth_proxy_call_new (OAuthProxy *proxy,
+ const char *content);
+
+G_END_DECLS
+
+#endif /* MAPS_OSM_OAUTH_PROXY_CALL_H */