summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGünther Wagner <info@gunibert.de>2022-01-12 19:15:20 +0000
committerGünther Wagner <info@gunibert.de>2022-01-12 19:15:20 +0000
commit85bd00adfa6e06d3426ce7c9007e68e62f51be14 (patch)
treee21e069019d003978fba09e127c979fbd0b7ebb2
parent6db3436246b94063b09f3957ee8cdccc8fb71dc3 (diff)
parent025e53c313850501500048cbc3c44d80a4f8cbec (diff)
downloadlibrest-1.0.0.tar.gz
Merge branch 'gwagner/deprecated' into 'master'1.0.00.9.0
Modernized the codebase See merge request GNOME/librest!11
-rw-r--r--rest-extras/flickr-proxy-call.c73
-rw-r--r--rest-extras/flickr-proxy-call.h39
-rw-r--r--rest-extras/flickr-proxy-private.h33
-rw-r--r--rest-extras/flickr-proxy.c172
-rw-r--r--rest-extras/flickr-proxy.h93
-rw-r--r--rest-extras/lastfm-proxy-call.c16
-rw-r--r--rest-extras/lastfm-proxy-call.h6
-rw-r--r--rest-extras/lastfm-proxy-private.h33
-rw-r--r--rest-extras/lastfm-proxy.c132
-rw-r--r--rest-extras/lastfm-proxy.h75
-rw-r--r--rest-extras/meson.build3
-rw-r--r--rest-extras/youtube-proxy.c79
-rw-r--r--rest-extras/youtube-proxy.h68
-rw-r--r--rest/meson.build7
-rw-r--r--rest/oauth-proxy-call.c49
-rw-r--r--rest/oauth-proxy-private.h45
-rw-r--r--rest/oauth-proxy.c119
-rw-r--r--rest/oauth-proxy.h151
-rw-r--r--rest/rest-oauth2-proxy-call.c3
-rw-r--r--rest/rest-param.c2
-rw-r--r--rest/rest-params.c196
-rw-r--r--rest/rest-params.h52
-rw-r--r--rest/rest-proxy-call.c2
-rw-r--r--rest/rest-proxy.c69
-rw-r--r--rest/rest-proxy.h61
-rw-r--r--rest/rest-xml-node.h34
-rw-r--r--rest/rest-xml-parser.h19
-rw-r--r--tests/meson.build7
-rw-r--r--tests/params.c141
-rw-r--r--tests/proxy-continuous.c2
-rw-r--r--tests/proxy.c18
-rw-r--r--tests/test-media.pngbin0 -> 2509 bytes
-rw-r--r--tests/threaded.c2
33 files changed, 957 insertions, 844 deletions
diff --git a/rest-extras/flickr-proxy-call.c b/rest-extras/flickr-proxy-call.c
index e7dfa07..fc38ca0 100644
--- a/rest-extras/flickr-proxy-call.c
+++ b/rest-extras/flickr-proxy-call.c
@@ -4,6 +4,7 @@
*
* Authors: Rob Bradford <rob@linux.intel.com>
* Ross Burton <ross@linux.intel.com>
+ * Günther Wagner <info@gunibert.de>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU Lesser General Public License,
@@ -24,50 +25,57 @@
#include <libsoup/soup.h>
#include <rest/rest-proxy-call.h>
#include "flickr-proxy-call.h"
-#include "flickr-proxy-private.h"
+#include "flickr-proxy.h"
#include "rest/sha1.h"
-G_DEFINE_TYPE (FlickrProxyCall, flickr_proxy_call, REST_TYPE_PROXY_CALL)
-
-#define GET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), FLICKR_TYPE_PROXY_CALL, FlickrProxyCallPrivate))
-
typedef struct {
gboolean upload;
} FlickrProxyCallPrivate;
+G_DEFINE_TYPE_WITH_PRIVATE (FlickrProxyCall, flickr_proxy_call, REST_TYPE_PROXY_CALL)
+
enum {
PROP_0,
- PROP_UPLOAD
+ PROP_UPLOAD,
+ N_PROPS
};
+static GParamSpec *properties [N_PROPS];
+
static void
flickr_proxy_call_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
- switch (property_id) {
- case PROP_UPLOAD:
- GET_PRIVATE (object)->upload = g_value_get_boolean (value);
- break;
+ FlickrProxyCall *self = FLICKR_PROXY_CALL (object);
+ FlickrProxyCallPrivate *priv = flickr_proxy_call_get_instance_private (self);
+
+ switch (property_id)
+ {
+ case PROP_UPLOAD:
+ priv->upload = g_value_get_boolean (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- }
+ }
}
static gboolean
-_prepare (RestProxyCall *call, GError **error)
+_prepare (RestProxyCall *call,
+ GError **error)
{
+ FlickrProxyCall *self = (FlickrProxyCall *)call;
+ FlickrProxyCallPrivate *priv = flickr_proxy_call_get_instance_private (self);
+
FlickrProxy *proxy = NULL;
- FlickrProxyPrivate *priv;
+ const gchar *token = NULL;
GHashTable *params;
char *s;
- g_object_get (call, "proxy", &proxy, NULL);
- priv = FLICKR_PROXY_GET_PRIVATE (proxy);
+ g_object_get (self, "proxy", &proxy, NULL);
- if (GET_PRIVATE (call)->upload) {
+ if (priv->upload) {
rest_proxy_bind (REST_PROXY(proxy), "up", "upload");
rest_proxy_call_set_function (call, NULL);
} else {
@@ -79,10 +87,11 @@ _prepare (RestProxyCall *call, GError **error)
rest_proxy_call_set_function (call, NULL);
}
- rest_proxy_call_add_param (call, "api_key", priv->api_key);
+ rest_proxy_call_add_param (call, "api_key", flickr_proxy_get_api_key (proxy));
+ token = flickr_proxy_get_token (proxy);
- if (priv->token)
- rest_proxy_call_add_param (call, "auth_token", priv->token);
+ if (token)
+ rest_proxy_call_add_param (call, "auth_token", token);
/* Get the string params as a hash for signing */
params = rest_params_as_string_hash_table (rest_proxy_call_get_params (call));
@@ -100,14 +109,11 @@ _prepare (RestProxyCall *call, GError **error)
static void
flickr_proxy_call_class_init (FlickrProxyCallClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
RestProxyCallClass *call_class = REST_PROXY_CALL_CLASS (klass);
- GObjectClass *obj_class = G_OBJECT_CLASS (klass);
- GParamSpec *pspec;
-
- g_type_class_add_private (klass, sizeof (FlickrProxyCallPrivate));
call_class->prepare = _prepare;
- obj_class->set_property = flickr_proxy_call_set_property;
+ object_class->set_property = flickr_proxy_call_set_property;
/**
* FlickrProxyCall:upload:
@@ -115,16 +121,19 @@ flickr_proxy_call_class_init (FlickrProxyCallClass *klass)
* Set if the call should be sent to the photo upload endpoint and not the
* general-purpose endpoint.
*/
- pspec = g_param_spec_boolean ("upload", "upload", "upload",
- FALSE, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (obj_class, PROP_UPLOAD, pspec);
+ properties [PROP_UPLOAD] =
+ g_param_spec_boolean ("upload",
+ "upload",
+ "upload",
+ FALSE,
+ (G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
flickr_proxy_call_init (FlickrProxyCall *self)
{
}
-
-#if BUILD_TESTS
-#warning TODO flickr signature test cases
-#endif
diff --git a/rest-extras/flickr-proxy-call.h b/rest-extras/flickr-proxy-call.h
index 195886e..3903631 100644
--- a/rest-extras/flickr-proxy-call.h
+++ b/rest-extras/flickr-proxy-call.h
@@ -20,49 +20,22 @@
*
*/
-#ifndef _FLICKR_PROXY_CALL
-#define _FLICKR_PROXY_CALL
+#pragma once
#include <rest/rest-proxy-call.h>
G_BEGIN_DECLS
-#define FLICKR_TYPE_PROXY_CALL flickr_proxy_call_get_type()
+#define FLICKR_TYPE_PROXY_CALL (flickr_proxy_call_get_type())
-#define FLICKR_PROXY_CALL(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), FLICKR_TYPE_PROXY_CALL, FlickrProxyCall))
+G_DECLARE_DERIVABLE_TYPE (FlickrProxyCall, flickr_proxy_call, FLICKR, PROXY_CALL, RestProxyCall)
-#define FLICKR_PROXY_CALL_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), FLICKR_TYPE_PROXY_CALL, FlickrProxyCallClass))
-
-#define FLICKR_IS_PROXY_CALL(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FLICKR_TYPE_PROXY_CALL))
-
-#define FLICKR_IS_PROXY_CALL_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), FLICKR_TYPE_PROXY_CALL))
-
-#define FLICKR_PROXY_CALL_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), FLICKR_TYPE_PROXY_CALL, FlickrProxyCallClass))
-
-/**
- * FlickrProxyCall:
- *
- * #FlickrProxyCall has no publicly available members.
- */
-typedef struct {
- RestProxyCall parent;
-} FlickrProxyCall;
-
-typedef struct {
+struct _FlickrProxyCallClass {
RestProxyCallClass parent_class;
+
/*< private >*/
/* padding for future expansion */
gpointer _padding_dummy[8];
-} FlickrProxyCallClass;
-
-GType flickr_proxy_call_get_type (void);
+};
G_END_DECLS
-
-#endif /* _FLICKR_PROXY_CALL */
-
diff --git a/rest-extras/flickr-proxy-private.h b/rest-extras/flickr-proxy-private.h
deleted file mode 100644
index 5932946..0000000
--- a/rest-extras/flickr-proxy-private.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * librest - RESTful web services access
- * Copyright (c) 2008, 2009, Intel Corporation.
- *
- * Authors: Rob Bradford <rob@linux.intel.com>
- * Ross Burton <ross@linux.intel.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 2.1, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-#include "flickr-proxy.h"
-
-#define FLICKR_PROXY_GET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), FLICKR_TYPE_PROXY, FlickrProxyPrivate))
-
-struct _FlickrProxyPrivate {
- char *api_key;
- char *shared_secret;
- char *token;
-};
-
diff --git a/rest-extras/flickr-proxy.c b/rest-extras/flickr-proxy.c
index 91403d9..7e60fa1 100644
--- a/rest-extras/flickr-proxy.c
+++ b/rest-extras/flickr-proxy.c
@@ -33,18 +33,26 @@
#include <rest/rest-proxy.h>
#include <libsoup/soup.h>
#include "flickr-proxy.h"
-#include "flickr-proxy-private.h"
#include "flickr-proxy-call.h"
-G_DEFINE_TYPE (FlickrProxy, flickr_proxy, REST_TYPE_PROXY)
+typedef struct {
+ char *api_key;
+ char *shared_secret;
+ char *token;
+} FlickrProxyPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (FlickrProxy, flickr_proxy, REST_TYPE_PROXY)
enum {
PROP_0,
PROP_API_KEY,
PROP_SHARED_SECRET,
PROP_TOKEN,
+ N_PROPS
};
+static GParamSpec *properties [N_PROPS];
+
GQuark
flickr_proxy_error_quark (void)
{
@@ -52,22 +60,25 @@ flickr_proxy_error_quark (void)
}
static RestProxyCall *
-_new_call (RestProxy *proxy)
+_new_call (RestProxy *self)
{
RestProxyCall *call;
call = g_object_new (FLICKR_TYPE_PROXY_CALL,
- "proxy", proxy,
+ "proxy", self,
NULL);
return call;
}
static void
-flickr_proxy_get_property (GObject *object, guint property_id,
- GValue *value, GParamSpec *pspec)
+flickr_proxy_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- FlickrProxyPrivate *priv = FLICKR_PROXY_GET_PRIVATE (object);
+ FlickrProxy *self = FLICKR_PROXY (object);
+ FlickrProxyPrivate *priv = flickr_proxy_get_instance_private (self);
switch (property_id) {
case PROP_API_KEY:
@@ -85,10 +96,13 @@ flickr_proxy_get_property (GObject *object, guint property_id,
}
static void
-flickr_proxy_set_property (GObject *object, guint property_id,
- const GValue *value, GParamSpec *pspec)
+flickr_proxy_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- FlickrProxyPrivate *priv = FLICKR_PROXY_GET_PRIVATE (object);
+ FlickrProxy *self = FLICKR_PROXY (object);
+ FlickrProxyPrivate *priv = flickr_proxy_get_instance_private (self);
switch (property_id) {
case PROP_API_KEY:
@@ -114,27 +128,21 @@ flickr_proxy_set_property (GObject *object, guint property_id,
static void
flickr_proxy_finalize (GObject *object)
{
- FlickrProxyPrivate *priv = FLICKR_PROXY_GET_PRIVATE (object);
+ FlickrProxy *self = FLICKR_PROXY (object);
+ FlickrProxyPrivate *priv = flickr_proxy_get_instance_private (self);
- g_free (priv->api_key);
- g_free (priv->shared_secret);
- g_free (priv->token);
+ g_clear_pointer (&priv->api_key, g_free);
+ g_clear_pointer (&priv->shared_secret, g_free);
+ g_clear_pointer (&priv->token, g_free);
G_OBJECT_CLASS (flickr_proxy_parent_class)->finalize (object);
}
-#ifndef G_PARAM_STATIC_STRINGS
-#define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)
-#endif
-
static void
flickr_proxy_class_init (FlickrProxyClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
RestProxyClass *proxy_class = REST_PROXY_CLASS (klass);
- GParamSpec *pspec;
-
- g_type_class_add_private (klass, sizeof (FlickrProxyPrivate));
object_class->get_property = flickr_proxy_get_property;
object_class->set_property = flickr_proxy_set_property;
@@ -142,37 +150,43 @@ flickr_proxy_class_init (FlickrProxyClass *klass)
proxy_class->new_call = _new_call;
- pspec = g_param_spec_string ("api-key", "api-key",
- "The API key", NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class,
- PROP_API_KEY,
- pspec);
-
- pspec = g_param_spec_string ("shared-secret", "shared-secret",
- "The shared secret", NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class,
- PROP_SHARED_SECRET,
- pspec);
-
- pspec = g_param_spec_string ("token", "token",
- "The request or access token", NULL,
- G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class,
- PROP_TOKEN,
- pspec);
+ properties [PROP_API_KEY] =
+ g_param_spec_string ("api-key",
+ "api-key",
+ "The API key",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ properties [PROP_SHARED_SECRET] =
+ g_param_spec_string ("shared-secret",
+ "shared-secret",
+ "The shared secret",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ properties [PROP_TOKEN] =
+ g_param_spec_string ("token",
+ "token",
+ "The request or access token",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
flickr_proxy_init (FlickrProxy *self)
{
- self->priv = FLICKR_PROXY_GET_PRIVATE (self);
}
RestProxy *
flickr_proxy_new (const char *api_key,
- const char *shared_secret)
+ const char *shared_secret)
{
return flickr_proxy_new_with_token (api_key,
shared_secret,
@@ -203,9 +217,12 @@ flickr_proxy_new_with_token (const char *api_key,
* freed.
*/
const char *
-flickr_proxy_get_api_key (FlickrProxy *proxy)
+flickr_proxy_get_api_key (FlickrProxy *self)
{
- FlickrProxyPrivate *priv = FLICKR_PROXY_GET_PRIVATE (proxy);
+ FlickrProxyPrivate *priv = flickr_proxy_get_instance_private (self);
+
+ g_return_val_if_fail (FLICKR_IS_PROXY (self), NULL);
+
return priv->api_key;
}
@@ -219,9 +236,12 @@ flickr_proxy_get_api_key (FlickrProxy *proxy)
* freed.
*/
const char *
-flickr_proxy_get_shared_secret (FlickrProxy *proxy)
+flickr_proxy_get_shared_secret (FlickrProxy *self)
{
- FlickrProxyPrivate *priv = FLICKR_PROXY_GET_PRIVATE (proxy);
+ FlickrProxyPrivate *priv = flickr_proxy_get_instance_private (self);
+
+ g_return_val_if_fail (FLICKR_IS_PROXY (self), NULL);
+
return priv->shared_secret;
}
@@ -235,9 +255,12 @@ flickr_proxy_get_shared_secret (FlickrProxy *proxy)
* by #FlickrProxy and should not be freed.
*/
const char *
-flickr_proxy_get_token (FlickrProxy *proxy)
+flickr_proxy_get_token (FlickrProxy *self)
{
- FlickrProxyPrivate *priv = FLICKR_PROXY_GET_PRIVATE (proxy);
+ FlickrProxyPrivate *priv = flickr_proxy_get_instance_private (self);
+
+ g_return_val_if_fail (FLICKR_IS_PROXY (self), NULL);
+
return priv->token;
}
@@ -249,31 +272,36 @@ flickr_proxy_get_token (FlickrProxy *proxy)
* Set the token.
*/
void
-flickr_proxy_set_token (FlickrProxy *proxy, const char *token)
+flickr_proxy_set_token (FlickrProxy *self,
+ const char *token)
{
FlickrProxyPrivate *priv;
- g_return_if_fail (FLICKR_IS_PROXY (proxy));
- priv = FLICKR_PROXY_GET_PRIVATE (proxy);
+ g_return_if_fail (FLICKR_IS_PROXY (self));
- if (priv->token)
- g_free (priv->token);
+ priv = flickr_proxy_get_instance_private (self);
- priv->token = g_strdup (token);
+ if (g_strcmp0 (priv->token, token) != 0)
+ {
+ g_clear_pointer (&priv->token, g_free);
+ priv->token = g_strdup (token);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TOKEN]);
+ }
}
char *
-flickr_proxy_sign (FlickrProxy *proxy, GHashTable *params)
+flickr_proxy_sign (FlickrProxy *self,
+ GHashTable *params)
{
FlickrProxyPrivate *priv;
GList *keys;
char *md5;
GChecksum *checksum;
- g_return_val_if_fail (FLICKR_IS_PROXY (proxy), NULL);
+ g_return_val_if_fail (FLICKR_IS_PROXY (self), NULL);
g_return_val_if_fail (params, NULL);
- priv = FLICKR_PROXY_GET_PRIVATE (proxy);
+ priv = flickr_proxy_get_instance_private (self);
checksum = g_checksum_new (G_CHECKSUM_MD5);
g_checksum_update (checksum, (guchar *)priv->shared_secret, -1);
@@ -300,26 +328,29 @@ flickr_proxy_sign (FlickrProxy *proxy, GHashTable *params)
}
char *
-flickr_proxy_build_login_url (FlickrProxy *proxy,
+flickr_proxy_build_login_url (FlickrProxy *self,
const char *frob,
const char *perms)
{
+ FlickrProxyPrivate *priv;
GUri *uri;
GHashTable *params;
char *sig, *s;
char *query;
- g_return_val_if_fail (FLICKR_IS_PROXY (proxy), NULL);
+ g_return_val_if_fail (FLICKR_IS_PROXY (self), NULL);
+
+ priv = flickr_proxy_get_instance_private (self);
params = g_hash_table_new (g_str_hash, g_str_equal);
- g_hash_table_insert (params, "api_key", proxy->priv->api_key);
+ g_hash_table_insert (params, "api_key", priv->api_key);
g_hash_table_insert (params, "perms", (gpointer)perms);
if (frob)
g_hash_table_insert (params, "frob", (gpointer)frob);
- sig = flickr_proxy_sign (proxy, params);
+ sig = flickr_proxy_sign (self, params);
g_hash_table_insert (params, "api_sig", sig);
query = soup_form_encode_hash (params);
@@ -353,7 +384,8 @@ flickr_proxy_build_login_url (FlickrProxy *proxy,
* Returns: %TRUE if this response is successful, %FALSE otherwise.
*/
gboolean
-flickr_proxy_is_successful (RestXmlNode *root, GError **error)
+flickr_proxy_is_successful (RestXmlNode *root,
+ GError **error)
{
RestXmlNode *node;
@@ -389,12 +421,12 @@ flickr_proxy_is_successful (RestXmlNode *root, GError **error)
* Returns: (type FlickrProxyCall) (transfer full): a new #FlickrProxyCall
*/
RestProxyCall *
-flickr_proxy_new_upload (FlickrProxy *proxy)
+flickr_proxy_new_upload (FlickrProxy *self)
{
- g_return_val_if_fail (FLICKR_IS_PROXY (proxy), NULL);
+ g_return_val_if_fail (FLICKR_IS_PROXY (self), NULL);
return g_object_new (FLICKR_TYPE_PROXY_CALL,
- "proxy", proxy,
+ "proxy", self,
"upload", TRUE,
NULL);
}
@@ -417,7 +449,9 @@ flickr_proxy_new_upload (FlickrProxy *proxy)
* Returns: (type FlickrProxyCall) (transfer full): a new #FlickrProxyCall
*/
RestProxyCall *
-flickr_proxy_new_upload_for_file (FlickrProxy *proxy, const char *filename, GError **error)
+flickr_proxy_new_upload_for_file (FlickrProxy *self,
+ const char *filename,
+ GError **error)
{
GMappedFile *map;
GError *err = NULL;
@@ -425,7 +459,7 @@ flickr_proxy_new_upload_for_file (FlickrProxy *proxy, const char *filename, GErr
RestParam *param;
RestProxyCall *call = NULL;
- g_return_val_if_fail (FLICKR_IS_PROXY (proxy), NULL);
+ g_return_val_if_fail (FLICKR_IS_PROXY (self), NULL);
g_return_val_if_fail (filename, NULL);
/* Open the file */
@@ -443,7 +477,7 @@ flickr_proxy_new_upload_for_file (FlickrProxy *proxy, const char *filename, GErr
NULL);
/* Make the call */
- call = flickr_proxy_new_upload (proxy);
+ call = flickr_proxy_new_upload (self);
param = rest_param_new_with_owner ("photo",
g_mapped_file_get_contents (map),
g_mapped_file_get_length (map),
diff --git a/rest-extras/flickr-proxy.h b/rest-extras/flickr-proxy.h
index 5cff622..bc13149 100644
--- a/rest-extras/flickr-proxy.h
+++ b/rest-extras/flickr-proxy.h
@@ -4,6 +4,7 @@
*
* Authors: Rob Bradford <rob@linux.intel.com>
* Ross Burton <ross@linux.intel.com>
+ * Günther Wagner <info@gunibert.de>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU Lesser General Public License,
@@ -20,81 +21,47 @@
*
*/
-#ifndef _FLICKR_PROXY
-#define _FLICKR_PROXY
+#pragma once
#include <rest/rest-proxy.h>
#include <rest/rest-xml-parser.h>
G_BEGIN_DECLS
+#define FLICKR_PROXY_ERROR flickr_proxy_error_quark()
#define FLICKR_TYPE_PROXY flickr_proxy_get_type()
-#define FLICKR_PROXY(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), FLICKR_TYPE_PROXY, FlickrProxy))
-
-#define FLICKR_PROXY_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), FLICKR_TYPE_PROXY, FlickrProxyClass))
-
-#define FLICKR_IS_PROXY(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FLICKR_TYPE_PROXY))
-
-#define FLICKR_IS_PROXY_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), FLICKR_TYPE_PROXY))
+G_DECLARE_DERIVABLE_TYPE (FlickrProxy, flickr_proxy, FLICKR, PROXY, RestProxy)
-#define FLICKR_PROXY_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), FLICKR_TYPE_PROXY, FlickrProxyClass))
-
-typedef struct _FlickrProxyPrivate FlickrProxyPrivate;
-
-/**
- * FlickrProxy:
- *
- * #FlickrProxy has no publicly available members.
- */
-typedef struct {
- RestProxy parent;
- FlickrProxyPrivate *priv;
-} FlickrProxy;
-
-typedef struct {
+struct _FlickrProxyClass {
RestProxyClass parent_class;
+
/*< private >*/
/* padding for future expansion */
gpointer _padding_dummy[8];
-} FlickrProxyClass;
-
-#define FLICKR_PROXY_ERROR flickr_proxy_error_quark()
-
-GType flickr_proxy_get_type (void);
-
-RestProxy* flickr_proxy_new (const char *api_key,
- const char *shared_secret);
-
-RestProxy* flickr_proxy_new_with_token (const char *api_key,
- const char *shared_secret,
- const char *token);
-
-const char * flickr_proxy_get_api_key (FlickrProxy *proxy);
-
-const char * flickr_proxy_get_shared_secret (FlickrProxy *proxy);
-
-const char * flickr_proxy_get_token (FlickrProxy *proxy);
-
-void flickr_proxy_set_token (FlickrProxy *proxy, const char *token);
-
-char * flickr_proxy_sign (FlickrProxy *proxy, GHashTable *params);
-
-char * flickr_proxy_build_login_url (FlickrProxy *proxy,
- const char *frob,
- const char *perms);
-
-gboolean flickr_proxy_is_successful (RestXmlNode *root, GError **error);
-
-RestProxyCall * flickr_proxy_new_upload (FlickrProxy *proxy);
-
-RestProxyCall * flickr_proxy_new_upload_for_file (FlickrProxy *proxy, const char *filename, GError **error);
+};
+
+
+RestProxy *flickr_proxy_new (const char *api_key,
+ const char *shared_secret);
+RestProxy *flickr_proxy_new_with_token (const char *api_key,
+ const char *shared_secret,
+ const char *token);
+const char *flickr_proxy_get_api_key (FlickrProxy *proxy);
+const char *flickr_proxy_get_shared_secret (FlickrProxy *proxy);
+const char *flickr_proxy_get_token (FlickrProxy *proxy);
+void flickr_proxy_set_token (FlickrProxy *proxy,
+ const char *token);
+char *flickr_proxy_sign (FlickrProxy *proxy,
+ GHashTable *params);
+char *flickr_proxy_build_login_url (FlickrProxy *proxy,
+ const char *frob,
+ const char *perms);
+gboolean flickr_proxy_is_successful (RestXmlNode *root,
+ GError **error);
+RestProxyCall *flickr_proxy_new_upload (FlickrProxy *proxy);
+RestProxyCall *flickr_proxy_new_upload_for_file (FlickrProxy *proxy,
+ const char *filename,
+ GError **error);
G_END_DECLS
-
-#endif /* _FLICKR_PROXY */
diff --git a/rest-extras/lastfm-proxy-call.c b/rest-extras/lastfm-proxy-call.c
index 417fa18..dd56715 100644
--- a/rest-extras/lastfm-proxy-call.c
+++ b/rest-extras/lastfm-proxy-call.c
@@ -25,7 +25,7 @@
#include <rest/rest-private.h>
#include <rest/rest-proxy-call.h>
#include "lastfm-proxy-call.h"
-#include "lastfm-proxy-private.h"
+#include "lastfm-proxy.h"
#include "rest/sha1.h"
G_DEFINE_TYPE (LastfmProxyCall, lastfm_proxy_call, REST_TYPE_PROXY_CALL)
@@ -34,23 +34,23 @@ static gboolean
_prepare (RestProxyCall *call, GError **error)
{
LastfmProxy *proxy = NULL;
- LastfmProxyPrivate *priv;
GHashTable *params;
+ const gchar *session_key;
char *s;
g_object_get (call, "proxy", &proxy, NULL);
- priv = LASTFM_PROXY_GET_PRIVATE (proxy);
rest_proxy_call_add_params (call,
"method", rest_proxy_call_get_function (call),
- "api_key", priv->api_key,
+ "api_key", lastfm_proxy_get_api_key (proxy),
NULL);
/* Reset function because Lastfm puts the function in the parameters */
rest_proxy_call_set_function (call, NULL);
- if (priv->session_key)
- rest_proxy_call_add_param (call, "sk", priv->session_key);
+ session_key = lastfm_proxy_get_session_key (proxy);
+ if (session_key)
+ rest_proxy_call_add_param (call, "sk", session_key);
params = rest_params_as_string_hash_table (rest_proxy_call_get_params (call));
s = lastfm_proxy_sign (proxy, params);
@@ -75,7 +75,3 @@ static void
lastfm_proxy_call_init (LastfmProxyCall *self)
{
}
-
-#if BUILD_TESTS
-#warning TODO lastfm signature test cases
-#endif
diff --git a/rest-extras/lastfm-proxy-call.h b/rest-extras/lastfm-proxy-call.h
index da4c7ad..20e9b8e 100644
--- a/rest-extras/lastfm-proxy-call.h
+++ b/rest-extras/lastfm-proxy-call.h
@@ -20,8 +20,7 @@
*
*/
-#ifndef _LASTFM_PROXY_CALL
-#define _LASTFM_PROXY_CALL
+#pragma once
#include <rest/rest-proxy-call.h>
@@ -44,6 +43,3 @@ struct _LastfmProxyCallClass {
};
G_END_DECLS
-
-#endif /* _LASTFM_PROXY_CALL */
-
diff --git a/rest-extras/lastfm-proxy-private.h b/rest-extras/lastfm-proxy-private.h
deleted file mode 100644
index 128f7a9..0000000
--- a/rest-extras/lastfm-proxy-private.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * librest - RESTful web services access
- * Copyright (c) 2010 Intel Corporation.
- *
- * Authors: Rob Bradford <rob@linux.intel.com>
- * Ross Burton <ross@linux.intel.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 2.1, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-#include "lastfm-proxy.h"
-
-#define LASTFM_PROXY_GET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), LASTFM_TYPE_PROXY, LastfmProxyPrivate))
-
-struct _LastfmProxyPrivate {
- char *api_key;
- char *secret;
- char *session_key;
-};
-
diff --git a/rest-extras/lastfm-proxy.c b/rest-extras/lastfm-proxy.c
index b9fc713..7b0dd28 100644
--- a/rest-extras/lastfm-proxy.c
+++ b/rest-extras/lastfm-proxy.c
@@ -26,18 +26,26 @@
#include <rest/rest-proxy.h>
#include <libsoup/soup.h>
#include "lastfm-proxy.h"
-#include "lastfm-proxy-private.h"
#include "lastfm-proxy-call.h"
-G_DEFINE_TYPE (LastfmProxy, lastfm_proxy, REST_TYPE_PROXY)
+typedef struct {
+ char *api_key;
+ char *secret;
+ char *session_key;
+} LastfmProxyPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (LastfmProxy, lastfm_proxy, REST_TYPE_PROXY)
enum {
PROP_0,
PROP_API_KEY,
PROP_SECRET,
PROP_SESSION_KEY,
+ N_PROPS,
};
+static GParamSpec *properties [N_PROPS];
+
GQuark
lastfm_proxy_error_quark (void)
{
@@ -57,10 +65,13 @@ _new_call (RestProxy *proxy)
}
static void
-lastfm_proxy_get_property (GObject *object, guint property_id,
- GValue *value, GParamSpec *pspec)
+lastfm_proxy_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- LastfmProxyPrivate *priv = LASTFM_PROXY_GET_PRIVATE (object);
+ LastfmProxy *self = LASTFM_PROXY (object);
+ LastfmProxyPrivate *priv = lastfm_proxy_get_instance_private (self);
switch (property_id) {
case PROP_API_KEY:
@@ -81,7 +92,8 @@ static void
lastfm_proxy_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
- LastfmProxyPrivate *priv = LASTFM_PROXY_GET_PRIVATE (object);
+ LastfmProxy *self = LASTFM_PROXY (object);
+ LastfmProxyPrivate *priv = lastfm_proxy_get_instance_private (self);
switch (property_id) {
case PROP_API_KEY:
@@ -107,7 +119,8 @@ lastfm_proxy_set_property (GObject *object, guint property_id,
static void
lastfm_proxy_finalize (GObject *object)
{
- LastfmProxyPrivate *priv = LASTFM_PROXY_GET_PRIVATE (object);
+ LastfmProxy *self = LASTFM_PROXY (object);
+ LastfmProxyPrivate *priv = lastfm_proxy_get_instance_private (self);
g_free (priv->api_key);
g_free (priv->secret);
@@ -116,18 +129,11 @@ lastfm_proxy_finalize (GObject *object)
G_OBJECT_CLASS (lastfm_proxy_parent_class)->finalize (object);
}
-#ifndef G_PARAM_STATIC_STRINGS
-#define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)
-#endif
-
static void
lastfm_proxy_class_init (LastfmProxyClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
RestProxyClass *proxy_class = REST_PROXY_CLASS (klass);
- GParamSpec *pspec;
-
- g_type_class_add_private (klass, sizeof (LastfmProxyPrivate));
object_class->get_property = lastfm_proxy_get_property;
object_class->set_property = lastfm_proxy_set_property;
@@ -135,32 +141,38 @@ lastfm_proxy_class_init (LastfmProxyClass *klass)
proxy_class->new_call = _new_call;
- pspec = g_param_spec_string ("api-key", "api-key",
- "The API key", NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class,
- PROP_API_KEY,
- pspec);
-
- pspec = g_param_spec_string ("secret", "secret",
- "The API key secret", NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class,
- PROP_SECRET,
- pspec);
-
- pspec = g_param_spec_string ("session-key", "session-key",
- "The session key", NULL,
- G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class,
- PROP_SESSION_KEY,
- pspec);
+ properties [PROP_API_KEY] =
+ g_param_spec_string ("api-key",
+ "api-key",
+ "The API key",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ properties [PROP_SECRET] =
+ g_param_spec_string ("secret",
+ "secret",
+ "The API key secret",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ properties [PROP_SESSION_KEY] =
+ g_param_spec_string ("session-key",
+ "session-key",
+ "The session key",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
lastfm_proxy_init (LastfmProxy *self)
{
- self->priv = LASTFM_PROXY_GET_PRIVATE (self);
}
RestProxy *
@@ -196,9 +208,12 @@ lastfm_proxy_new_with_session (const char *api_key,
* freed.
*/
const char *
-lastfm_proxy_get_api_key (LastfmProxy *proxy)
+lastfm_proxy_get_api_key (LastfmProxy *self)
{
- LastfmProxyPrivate *priv = LASTFM_PROXY_GET_PRIVATE (proxy);
+ LastfmProxyPrivate *priv = lastfm_proxy_get_instance_private (self);
+
+ g_return_val_if_fail (LASTFM_IS_PROXY (self), NULL);
+
return priv->api_key;
}
@@ -212,9 +227,12 @@ lastfm_proxy_get_api_key (LastfmProxy *proxy)
* freed.
*/
const char *
-lastfm_proxy_get_secret (LastfmProxy *proxy)
+lastfm_proxy_get_secret (LastfmProxy *self)
{
- LastfmProxyPrivate *priv = LASTFM_PROXY_GET_PRIVATE (proxy);
+ LastfmProxyPrivate *priv = lastfm_proxy_get_instance_private (self);
+
+ g_return_val_if_fail (LASTFM_IS_PROXY (self), NULL);
+
return priv->secret;
}
@@ -228,9 +246,12 @@ lastfm_proxy_get_secret (LastfmProxy *proxy)
* by #LastfmProxy and should not be freed.
*/
const char *
-lastfm_proxy_get_session_key (LastfmProxy *proxy)
+lastfm_proxy_get_session_key (LastfmProxy *self)
{
- LastfmProxyPrivate *priv = LASTFM_PROXY_GET_PRIVATE (proxy);
+ LastfmProxyPrivate *priv = lastfm_proxy_get_instance_private (self);
+
+ g_return_val_if_fail (LASTFM_IS_PROXY (self), NULL);
+
return priv->session_key;
}
@@ -242,12 +263,14 @@ lastfm_proxy_get_session_key (LastfmProxy *proxy)
* Set the session key.
*/
void
-lastfm_proxy_set_session_key (LastfmProxy *proxy, const char *session_key)
+lastfm_proxy_set_session_key (LastfmProxy *self,
+ const char *session_key)
{
LastfmProxyPrivate *priv;
- g_return_if_fail (LASTFM_IS_PROXY (proxy));
- priv = LASTFM_PROXY_GET_PRIVATE (proxy);
+ g_return_if_fail (LASTFM_IS_PROXY (self));
+
+ priv = lastfm_proxy_get_instance_private (self);
if (priv->session_key)
g_free (priv->session_key);
@@ -256,17 +279,18 @@ lastfm_proxy_set_session_key (LastfmProxy *proxy, const char *session_key)
}
char *
-lastfm_proxy_sign (LastfmProxy *proxy, GHashTable *params)
+lastfm_proxy_sign (LastfmProxy *self,
+ GHashTable *params)
{
LastfmProxyPrivate *priv;
GString *s;
GList *keys;
char *md5;
- g_return_val_if_fail (LASTFM_IS_PROXY (proxy), NULL);
+ g_return_val_if_fail (LASTFM_IS_PROXY (self), NULL);
g_return_val_if_fail (params, NULL);
- priv = LASTFM_PROXY_GET_PRIVATE (proxy);
+ priv = lastfm_proxy_get_instance_private (self);
s = g_string_new (NULL);
@@ -295,13 +319,18 @@ lastfm_proxy_sign (LastfmProxy *proxy, GHashTable *params)
}
char *
-lastfm_proxy_build_login_url (LastfmProxy *proxy, const char *token)
+lastfm_proxy_build_login_url (LastfmProxy *self,
+ const char *token)
{
- g_return_val_if_fail (LASTFM_IS_PROXY (proxy), NULL);
+ LastfmProxyPrivate *priv;
+
+ g_return_val_if_fail (LASTFM_IS_PROXY (self), NULL);
g_return_val_if_fail (token, NULL);
+ priv = lastfm_proxy_get_instance_private (self);
+
return g_strdup_printf ("http://www.last.fm/api/auth/?api_key=%s&token=%s",
- proxy->priv->api_key,
+ priv->api_key,
token);
}
@@ -316,7 +345,8 @@ lastfm_proxy_build_login_url (LastfmProxy *proxy, const char *token)
* Returns: %TRUE if this response is successful, %FALSE otherwise.
*/
gboolean
-lastfm_proxy_is_successful (RestXmlNode *root, GError **error)
+lastfm_proxy_is_successful (RestXmlNode *root,
+ GError **error)
{
RestXmlNode *node;
diff --git a/rest-extras/lastfm-proxy.h b/rest-extras/lastfm-proxy.h
index 85e612a..b378882 100644
--- a/rest-extras/lastfm-proxy.h
+++ b/rest-extras/lastfm-proxy.h
@@ -20,8 +20,7 @@
*
*/
-#ifndef _LASTFM_PROXY
-#define _LASTFM_PROXY
+#pragma once
#include <rest/rest-proxy.h>
#include <rest/rest-xml-parser.h>
@@ -30,65 +29,33 @@ G_BEGIN_DECLS
#define LASTFM_TYPE_PROXY lastfm_proxy_get_type()
-#define LASTFM_PROXY(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), LASTFM_TYPE_PROXY, LastfmProxy))
+G_DECLARE_DERIVABLE_TYPE (LastfmProxy, lastfm_proxy, LASTFM, PROXY, RestProxy)
-#define LASTFM_PROXY_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), LASTFM_TYPE_PROXY, LastfmProxyClass))
-
-#define LASTFM_IS_PROXY(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LASTFM_TYPE_PROXY))
-
-#define LASTFM_IS_PROXY_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), LASTFM_TYPE_PROXY))
-
-#define LASTFM_PROXY_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), LASTFM_TYPE_PROXY, LastfmProxyClass))
-
-typedef struct _LastfmProxyPrivate LastfmProxyPrivate;
-
-/**
- * LastfmProxy:
- *
- * #LastfmProxy has no publicly available members.
- */
-typedef struct {
- RestProxy parent;
- LastfmProxyPrivate *priv;
-} LastfmProxy;
-
-typedef struct {
+struct _LastfmProxyClass {
RestProxyClass parent_class;
+
/*< private >*/
/* padding for future expansion */
gpointer _padding_dummy[8];
-} LastfmProxyClass;
+};
#define LASTFM_PROXY_ERROR lastfm_proxy_error_quark()
-GType lastfm_proxy_get_type (void);
-
-RestProxy* lastfm_proxy_new (const char *api_key,
- const char *secret);
-
-RestProxy* lastfm_proxy_new_with_session (const char *api_key,
- const char *secret,
- const char *session_key);
-
-const char * lastfm_proxy_get_api_key (LastfmProxy *proxy);
-
-const char * lastfm_proxy_get_secret (LastfmProxy *proxy);
-
-const char * lastfm_proxy_get_session_key (LastfmProxy *proxy);
-
-void lastfm_proxy_set_session_key (LastfmProxy *proxy, const char *session_key);
-
-char * lastfm_proxy_sign (LastfmProxy *proxy, GHashTable *params);
-
-char * lastfm_proxy_build_login_url (LastfmProxy *proxy, const char *token);
-
-gboolean lastfm_proxy_is_successful (RestXmlNode *root, GError **error);
+RestProxy *lastfm_proxy_new (const char *api_key,
+ const char *secret);
+RestProxy *lastfm_proxy_new_with_session (const char *api_key,
+ const char *secret,
+ const char *session_key);
+const char *lastfm_proxy_get_api_key (LastfmProxy *proxy);
+const char *lastfm_proxy_get_secret (LastfmProxy *proxy);
+const char *lastfm_proxy_get_session_key (LastfmProxy *proxy);
+void lastfm_proxy_set_session_key (LastfmProxy *proxy,
+ const char *session_key);
+char *lastfm_proxy_sign (LastfmProxy *proxy,
+ GHashTable *params);
+char *lastfm_proxy_build_login_url (LastfmProxy *proxy,
+ const char *token);
+gboolean lastfm_proxy_is_successful (RestXmlNode *root,
+ GError **error);
G_END_DECLS
-
-#endif /* _LASTFM_PROXY */
diff --git a/rest-extras/meson.build b/rest-extras/meson.build
index 1ad9ee1..cf14ee8 100644
--- a/rest-extras/meson.build
+++ b/rest-extras/meson.build
@@ -49,9 +49,12 @@ if get_option('introspection')
librest_extras_gir = gnome.generate_gir(librest_extras_lib,
sources: librest_extras_sources + librest_extras_headers,
namespace: 'RestExtras',
+ symbol_prefix: 'rest_extras',
+ identifier_prefix: 'RestExtras',
nsversion: librest_api_version,
includes: [ 'GObject-2.0', 'Gio-2.0', 'Soup-@0@'.format(libsoup_api_version), librest_gir[0] ],
extra_args: [ '--accept-unprefixed' ],
+ dependencies: librest_extras_deps,
install: true,
)
endif
diff --git a/rest-extras/youtube-proxy.c b/rest-extras/youtube-proxy.c
index cd598f4..08faca4 100644
--- a/rest-extras/youtube-proxy.c
+++ b/rest-extras/youtube-proxy.c
@@ -29,9 +29,13 @@
#include "rest/rest-private.h"
#include "youtube-proxy.h"
-#include "youtube-proxy-private.h"
-G_DEFINE_TYPE (YoutubeProxy, youtube_proxy, REST_TYPE_PROXY)
+typedef struct {
+ char *developer_key;
+ char *user_auth;
+} YoutubeProxyPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (YoutubeProxy, youtube_proxy, REST_TYPE_PROXY)
#define UPLOAD_URL \
"http://uploads.gdata.youtube.com/feeds/api/users/default/uploads"
@@ -40,8 +44,11 @@ enum {
PROP_0,
PROP_DEVELOPER_KEY,
PROP_USER_AUTH,
+ N_PROPS,
};
+static GParamSpec *properties [N_PROPS];
+
GQuark
youtube_proxy_error_quark (void)
{
@@ -49,10 +56,13 @@ youtube_proxy_error_quark (void)
}
static void
-youtube_proxy_get_property (GObject *object, guint property_id,
- GValue *value, GParamSpec *pspec)
+youtube_proxy_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- YoutubeProxyPrivate *priv = YOUTUBE_PROXY_GET_PRIVATE (object);
+ YoutubeProxy *self = YOUTUBE_PROXY (object);
+ YoutubeProxyPrivate *priv = youtube_proxy_get_instance_private (self);
switch (property_id) {
case PROP_DEVELOPER_KEY:
@@ -67,10 +77,13 @@ youtube_proxy_get_property (GObject *object, guint property_id,
}
static void
-youtube_proxy_set_property (GObject *object, guint property_id,
- const GValue *value, GParamSpec *pspec)
+youtube_proxy_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- YoutubeProxyPrivate *priv = YOUTUBE_PROXY_GET_PRIVATE (object);
+ YoutubeProxy *self = YOUTUBE_PROXY (object);
+ YoutubeProxyPrivate *priv = youtube_proxy_get_instance_private (self);
switch (property_id) {
case PROP_DEVELOPER_KEY:
@@ -89,7 +102,8 @@ youtube_proxy_set_property (GObject *object, guint property_id,
static void
youtube_proxy_finalize (GObject *object)
{
- YoutubeProxyPrivate *priv = YOUTUBE_PROXY_GET_PRIVATE (object);
+ YoutubeProxy *self = YOUTUBE_PROXY (object);
+ YoutubeProxyPrivate *priv = youtube_proxy_get_instance_private (self);
g_free (priv->developer_key);
g_free (priv->user_auth);
@@ -101,36 +115,34 @@ static void
youtube_proxy_class_init (YoutubeProxyClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GParamSpec *pspec;
-
- g_type_class_add_private (klass, sizeof (YoutubeProxyPrivate));
object_class->get_property = youtube_proxy_get_property;
object_class->set_property = youtube_proxy_set_property;
object_class->finalize = youtube_proxy_finalize;
- pspec = g_param_spec_string ("developer-key", "developer-key",
- "The developer API key", NULL,
- G_PARAM_READWRITE|
- G_PARAM_CONSTRUCT_ONLY|
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class,
- PROP_DEVELOPER_KEY,
- pspec);
-
- pspec = g_param_spec_string ("user-auth", "user-auth",
- "The ClientLogin token", NULL,
- G_PARAM_READWRITE|
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class,
- PROP_USER_AUTH,
- pspec);
+ properties [PROP_DEVELOPER_KEY] =
+ g_param_spec_string ("developer-key",
+ "developer-key",
+ "The developer API key",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ properties [PROP_USER_AUTH] =
+ g_param_spec_string ("user-auth",
+ "user-auth",
+ "The ClientLogin token",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
youtube_proxy_init (YoutubeProxy *self)
{
- self->priv = YOUTUBE_PROXY_GET_PRIVATE (self);
}
RestProxy *
@@ -151,16 +163,17 @@ youtube_proxy_new_with_auth (const char *developer_key,
}
void
-youtube_proxy_set_user_auth (YoutubeProxy *proxy,
+youtube_proxy_set_user_auth (YoutubeProxy *self,
const gchar *user_auth)
{
- YoutubeProxyPrivate *priv = proxy->priv;
+ YoutubeProxyPrivate *priv = youtube_proxy_get_instance_private (self);
priv->user_auth = g_strdup (user_auth);
}
static gchar *
-_construct_upload_atom_xml (GHashTable *fields, gboolean incomplete)
+_construct_upload_atom_xml (GHashTable *fields,
+ gboolean incomplete)
{
GHashTableIter iter;
gpointer key, value;
@@ -215,7 +228,7 @@ _set_upload_headers (YoutubeProxy *self,
SoupMessageHeaders *headers,
const gchar *filename)
{
- YoutubeProxyPrivate *priv = self->priv;
+ YoutubeProxyPrivate *priv = youtube_proxy_get_instance_private (self);
gchar *user_auth_header;
gchar *devkey_header;
gchar *basename;
diff --git a/rest-extras/youtube-proxy.h b/rest-extras/youtube-proxy.h
index 1fe6c20..1215cf4 100644
--- a/rest-extras/youtube-proxy.h
+++ b/rest-extras/youtube-proxy.h
@@ -20,8 +20,7 @@
*
*/
-#ifndef _YOUTUBE_PROXY
-#define _YOUTUBE_PROXY
+#pragma once
#include <rest/rest-proxy.h>
@@ -29,52 +28,18 @@ G_BEGIN_DECLS
#define YOUTUBE_TYPE_PROXY youtube_proxy_get_type()
-#define YOUTUBE_PROXY(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), YOUTUBE_TYPE_PROXY, YoutubeProxy))
+G_DECLARE_DERIVABLE_TYPE (YoutubeProxy, youtube_proxy, YOUTUBE, PROXY, RestProxy)
-#define YOUTUBE_PROXY_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), YOUTUBE_TYPE_PROXY, YoutubeProxyClass))
-
-#define YOUTUBE_IS_PROXY(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), YOUTUBE_TYPE_PROXY))
-
-#define YOUTUBE_IS_PROXY_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), YOUTUBE_TYPE_PROXY))
-
-#define YOUTUBE_PROXY_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), YOUTUBE_TYPE_PROXY, YoutubeProxyClass))
-
-typedef struct _YoutubeProxyPrivate YoutubeProxyPrivate;
-
-/**
- * YoutubeProxy:
- *
- * #YoutubeProxy has no publicly available members.
- */
-typedef struct {
- RestProxy parent;
- YoutubeProxyPrivate *priv;
-} YoutubeProxy;
-
-typedef struct {
+struct _YoutubeProxyClass {
RestProxyClass parent_class;
+
/*< private >*/
/* padding for future expansion */
gpointer _padding_dummy[8];
-} YoutubeProxyClass;
+};
#define YOUTUBE_PROXY_ERROR youtube_proxy_error_quark()
-GType youtube_proxy_get_type (void);
-
-RestProxy* youtube_proxy_new (const gchar *developer_key);
-
-RestProxy* youtube_proxy_new_with_auth (const gchar *developer_key,
- const gchar *user_auth);
-
-void youtube_proxy_set_user_auth (YoutubeProxy *proxy,
- const gchar *user_auth);
-
typedef void (*YoutubeProxyUploadCallback)(YoutubeProxy *proxy,
const gchar *payload,
gsize total,
@@ -83,15 +48,18 @@ typedef void (*YoutubeProxyUploadCallback)(YoutubeProxy *proxy,
GObject *weak_object,
gpointer user_data);
-gboolean youtube_proxy_upload_async (YoutubeProxy *self,
- const gchar *filename,
- GHashTable *fields,
- gboolean incomplete,
- YoutubeProxyUploadCallback callback,
- GObject *weak_object,
- gpointer user_data,
- GError **error);
+RestProxy *youtube_proxy_new (const gchar *developer_key);
+RestProxy *youtube_proxy_new_with_auth (const gchar *developer_key,
+ const gchar *user_auth);
+void youtube_proxy_set_user_auth (YoutubeProxy *proxy,
+ const gchar *user_auth);
+gboolean youtube_proxy_upload_async (YoutubeProxy *self,
+ const gchar *filename,
+ GHashTable *fields,
+ gboolean incomplete,
+ YoutubeProxyUploadCallback callback,
+ GObject *weak_object,
+ gpointer user_data,
+ GError **error);
G_END_DECLS
-
-#endif /* _YOUTUBE_PROXY */
diff --git a/rest/meson.build b/rest/meson.build
index a22742e..58dfbd8 100644
--- a/rest/meson.build
+++ b/rest/meson.build
@@ -87,12 +87,11 @@ if get_option('introspection')
endforeach
librest_gir = gnome.generate_gir(librest_lib,
- sources: [ librest_headers, librest_sources, librest_enums[1] ],
- dependencies: librest_deps,
+ sources: librest_sources + librest_headers + librest_enums,
+ nsversion: librest_api_version,
namespace: 'Rest',
- identifier_prefix: 'Rest',
symbol_prefix: 'rest',
- nsversion: librest_api_version,
+ identifier_prefix: 'Rest',
includes: [ 'GObject-2.0', 'Gio-2.0', 'Soup-@0@'.format(libsoup_api_version) ],
extra_args: librest_gir_extra_args,
install: true,
diff --git a/rest/oauth-proxy-call.c b/rest/oauth-proxy-call.c
index b292cad..560e928 100644
--- a/rest/oauth-proxy-call.c
+++ b/rest/oauth-proxy-call.c
@@ -24,7 +24,7 @@
#include <libsoup/soup.h>
#include <rest/rest-proxy-call.h>
#include "oauth-proxy-call.h"
-#include "oauth-proxy-private.h"
+#include "oauth-proxy.h"
#include "rest-proxy-call-private.h"
#include "sha1.h"
@@ -33,14 +33,14 @@ G_DEFINE_TYPE (OAuthProxyCall, oauth_proxy_call, REST_TYPE_PROXY_CALL)
#define OAUTH_ENCODE_STRING(x_) (x_ ? g_uri_escape_string( (x_), NULL, TRUE) : g_strdup (""))
static char *
-sign_plaintext (OAuthProxyPrivate *priv)
+sign_plaintext (OAuthProxy *proxy)
{
char *cs;
char *ts;
char *rv;
- cs = OAUTH_ENCODE_STRING (priv->consumer_secret);
- ts = OAUTH_ENCODE_STRING (priv->token_secret);
+ cs = OAUTH_ENCODE_STRING (oauth_proxy_get_consumer_secret (proxy));
+ ts = OAUTH_ENCODE_STRING (oauth_proxy_get_token_secret (proxy));
rv = g_strconcat (cs, "&", ts, NULL);
g_free (cs);
@@ -117,7 +117,6 @@ merge_params (GHashTable *hash, RestParams *params)
static char *
sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
{
- OAuthProxyPrivate *priv;
const char *url_str;
char *key, *signature, *ep, *eep;
const char *content_type;
@@ -127,15 +126,14 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
RestParam *param;
gboolean encode_query_params = TRUE;
- priv = PROXY_GET_PRIVATE (proxy);
url_str = rest_proxy_call_get_url (call);
text = g_string_new (NULL);
g_string_append (text, rest_proxy_call_get_method (call));
g_string_append_c (text, '&');
- if (priv->oauth_echo) {
- g_string_append_uri_escaped (text, priv->service_url, NULL, FALSE);
- } else if (priv->signature_host != NULL) {
+ if (oauth_proxy_is_echo (proxy))
+ g_string_append_uri_escaped (text, oauth_proxy_get_service_url (proxy), NULL, FALSE);
+ else if (oauth_proxy_get_signature_host (proxy) != NULL) {
GUri *url = g_uri_parse (url_str, G_URI_FLAGS_ENCODED, NULL);
GUri *new_url;
gchar *signing_url;
@@ -143,7 +141,7 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
new_url = g_uri_build (g_uri_get_flags (url),
g_uri_get_scheme (url),
g_uri_get_userinfo (url),
- priv->signature_host,
+ oauth_proxy_get_signature_host (proxy),
g_uri_get_port (url),
g_uri_get_path (url),
g_uri_get_query (url),
@@ -178,7 +176,7 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
/* Merge the OAuth parameters with the query parameters */
all_params = g_hash_table_new (g_str_hash, g_str_equal);
merge_hashes (all_params, oauth_params);
- if (encode_query_params && !priv->oauth_echo) {
+ if (encode_query_params && !oauth_proxy_is_echo (proxy)) {
merge_params (all_params, rest_proxy_call_get_params (call));
}
@@ -191,7 +189,7 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
g_hash_table_destroy (all_params);
/* PLAINTEXT signature value is the HMAC-SHA1 key value */
- key = sign_plaintext (priv);
+ key = sign_plaintext (proxy);
signature = hmac_sha1 (key, text->str);
@@ -263,12 +261,10 @@ static gboolean
_prepare (RestProxyCall *call, GError **error)
{
OAuthProxy *proxy = NULL;
- OAuthProxyPrivate *priv;
char *s;
GHashTable *oauth_params;
g_object_get (call, "proxy", &proxy, NULL);
- priv = PROXY_GET_PRIVATE (proxy);
/* We have to make this hash free the strings and thus duplicate when we put
* them in since when we call call steal_oauth_params that has to duplicate
@@ -288,15 +284,15 @@ _prepare (RestProxyCall *call, GError **error)
g_hash_table_insert (oauth_params, g_strdup ("oauth_nonce"), s);
g_hash_table_insert (oauth_params, g_strdup ("oauth_consumer_key"),
- g_strdup (priv->consumer_key));
+ g_strdup (oauth_proxy_get_consumer_key (proxy)));
- if (priv->token)
- g_hash_table_insert (oauth_params, g_strdup ("oauth_token"), g_strdup (priv->token));
+ if (oauth_proxy_get_token (proxy))
+ g_hash_table_insert (oauth_params, g_strdup ("oauth_token"), g_strdup (oauth_proxy_get_token (proxy)));
- switch (priv->method) {
+ switch (oauth_proxy_get_sign_method (proxy)) {
case PLAINTEXT:
g_hash_table_insert (oauth_params, g_strdup ("oauth_signature_method"), g_strdup ("PLAINTEXT"));
- s = sign_plaintext (priv);
+ s = sign_plaintext (proxy);
break;
case HMAC_SHA1:
g_hash_table_insert (oauth_params, g_strdup ("oauth_signature_method"), g_strdup ("HMAC-SHA1"));
@@ -306,9 +302,9 @@ _prepare (RestProxyCall *call, GError **error)
g_hash_table_insert (oauth_params, g_strdup ("oauth_signature"), s);
s = make_authorized_header (oauth_params);
- if (priv->oauth_echo) {
+ if (oauth_proxy_is_echo (proxy)) {
rest_proxy_call_add_header (call, "X-Verify-Credentials-Authorization", s);
- rest_proxy_call_add_param (call, "X-Auth-Service-Provider", priv->service_url);
+ rest_proxy_call_add_param (call, "X-Auth-Service-Provider", oauth_proxy_get_service_url (proxy));
} else {
rest_proxy_call_add_header (call, "Authorization", s);
}
@@ -336,7 +332,6 @@ oauth_proxy_call_init (OAuthProxyCall *self)
void
oauth_proxy_call_parse_token_response (OAuthProxyCall *call)
{
- OAuthProxyPrivate *priv;
GHashTable *form;
OAuthProxy *proxy;
g_autofree gchar *formstr = NULL;
@@ -346,19 +341,15 @@ oauth_proxy_call_parse_token_response (OAuthProxyCall *call)
g_return_if_fail (OAUTH_IS_PROXY_CALL (call));
g_object_get (call, "proxy", &proxy, NULL);
- priv = PROXY_GET_PRIVATE (proxy);
g_object_unref (proxy);
- g_assert (priv);
formstr = g_strndup (rest_proxy_call_get_payload (REST_PROXY_CALL (call)), rest_proxy_call_get_payload_length (REST_PROXY_CALL (call)));
form = soup_form_decode (formstr);
- g_free (priv->token);
- g_free (priv->token_secret);
- priv->token = g_strdup (g_hash_table_lookup (form, "oauth_token"));
- priv->token_secret = g_strdup (g_hash_table_lookup (form, "oauth_token_secret"));
+ oauth_proxy_set_token (proxy, g_hash_table_lookup (form, "oauth_token"));
+ oauth_proxy_set_token_secret (proxy, g_hash_table_lookup (form, "oauth_token_secret"));
/* This header should only exist for request_token replies, but its easier just to always check it */
- priv->oauth_10a = g_hash_table_lookup (form, "oauth_callback_confirmed") != NULL;
+ oauth_proxy_set_oauth10a (proxy, g_hash_table_lookup (form, "oauth_callback_confirmed") != NULL);
g_hash_table_destroy (form);
}
diff --git a/rest/oauth-proxy-private.h b/rest/oauth-proxy-private.h
deleted file mode 100644
index 2d178a5..0000000
--- a/rest/oauth-proxy-private.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * librest - RESTful web services access
- * Copyright (c) 2008, 2009, Intel Corporation.
- *
- * Authors: Rob Bradford <rob@linux.intel.com>
- * Ross Burton <ross@linux.intel.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 2.1, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-
-#include "oauth-proxy.h"
-
-#define PROXY_GET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), OAUTH_TYPE_PROXY, OAuthProxyPrivate))
-
-typedef struct {
- /* Application "consumer" keys */
- char *consumer_key;
- char *consumer_secret;
- /* Authorisation "user" tokens */
- char *token;
- char *token_secret;
- /* How we're signing */
- OAuthSignatureMethod method;
- /* OAuth 1.0a */
- gboolean oauth_10a;
- char *verifier;
- /* OAuth Echo */
- gboolean oauth_echo;
- char *service_url;
- /* URL to use for signatures */
- char *signature_host;
-} OAuthProxyPrivate;
diff --git a/rest/oauth-proxy.c b/rest/oauth-proxy.c
index f8c0053..d81c0d7 100644
--- a/rest/oauth-proxy.c
+++ b/rest/oauth-proxy.c
@@ -23,10 +23,32 @@
#include <rest/rest-proxy.h>
#include <libsoup/soup.h>
#include "oauth-proxy.h"
-#include "oauth-proxy-private.h"
#include "oauth-proxy-call.h"
-G_DEFINE_TYPE (OAuthProxy, oauth_proxy, REST_TYPE_PROXY)
+typedef struct {
+ /* Application "consumer" keys */
+ char *consumer_key;
+ char *consumer_secret;
+ /* Authorisation "user" tokens */
+ char *token;
+ char *token_secret;
+ /* How we're signing */
+ OAuthSignatureMethod method;
+ /* OAuth 1.0a */
+ gboolean oauth_10a;
+ char *verifier;
+ /* OAuth Echo */
+ gboolean oauth_echo;
+ char *service_url;
+ /* URL to use for signatures */
+ char *signature_host;
+} OAuthProxyPrivate;
+
+struct _OAuthProxy {
+ RestProxy parent_instance;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (OAuthProxy, oauth_proxy, REST_TYPE_PROXY)
enum {
PROP_0,
@@ -54,7 +76,8 @@ static void
oauth_proxy_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
- OAuthProxyPrivate *priv = PROXY_GET_PRIVATE (object);
+ OAuthProxy *self = OAUTH_PROXY (object);
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (self);
switch (property_id) {
case PROP_CONSUMER_KEY:
@@ -84,7 +107,8 @@ static void
oauth_proxy_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
- OAuthProxyPrivate *priv = PROXY_GET_PRIVATE (object);
+ OAuthProxy *self = OAUTH_PROXY (object);
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (self);
switch (property_id) {
case PROP_CONSUMER_KEY:
@@ -123,7 +147,8 @@ oauth_proxy_set_property (GObject *object, guint property_id,
static void
oauth_proxy_finalize (GObject *object)
{
- OAuthProxyPrivate *priv = PROXY_GET_PRIVATE (object);
+ OAuthProxy *self = OAUTH_PROXY (object);
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (self);
g_free (priv->consumer_key);
g_free (priv->consumer_secret);
@@ -146,8 +171,6 @@ oauth_proxy_class_init (OAuthProxyClass *klass)
RestProxyClass *proxy_class = REST_PROXY_CLASS (klass);
GParamSpec *pspec;
- g_type_class_add_private (klass, sizeof (OAuthProxyPrivate));
-
object_class->get_property = oauth_proxy_get_property;
object_class->set_property = oauth_proxy_set_property;
object_class->finalize = oauth_proxy_finalize;
@@ -201,7 +224,8 @@ oauth_proxy_class_init (OAuthProxyClass *klass)
static void
oauth_proxy_init (OAuthProxy *self)
{
- PROXY_GET_PRIVATE (self)->method = HMAC_SHA1;
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (self);
+ priv->method = HMAC_SHA1;
}
/**
@@ -534,6 +558,22 @@ oauth_proxy_access_token_finish (OAuthProxy *proxy,
return g_task_propagate_boolean (G_TASK (result), error);
}
+const char *
+oauth_proxy_get_consumer_key (OAuthProxy *self)
+{
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (self);
+
+ return priv->consumer_key;
+}
+
+const char *
+oauth_proxy_get_consumer_secret (OAuthProxy *self)
+{
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (self);
+
+ return priv->consumer_secret;
+}
+
/**
* oauth_proxy_get_token:
* @proxy: an #OAuthProxy
@@ -546,7 +586,8 @@ oauth_proxy_access_token_finish (OAuthProxy *proxy,
const char *
oauth_proxy_get_token (OAuthProxy *proxy)
{
- OAuthProxyPrivate *priv = PROXY_GET_PRIVATE (proxy);
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (proxy);
+
return priv->token;
}
@@ -560,10 +601,9 @@ oauth_proxy_get_token (OAuthProxy *proxy)
void
oauth_proxy_set_token (OAuthProxy *proxy, const char *token)
{
- OAuthProxyPrivate *priv;
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (proxy);
g_return_if_fail (OAUTH_IS_PROXY (proxy));
- priv = PROXY_GET_PRIVATE (proxy);
g_free (priv->token);
priv->token = g_strdup (token);
@@ -581,7 +621,8 @@ oauth_proxy_set_token (OAuthProxy *proxy, const char *token)
const char *
oauth_proxy_get_token_secret (OAuthProxy *proxy)
{
- OAuthProxyPrivate *priv = PROXY_GET_PRIVATE (proxy);
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (proxy);
+
return priv->token_secret;
}
@@ -595,10 +636,9 @@ oauth_proxy_get_token_secret (OAuthProxy *proxy)
void
oauth_proxy_set_token_secret (OAuthProxy *proxy, const char *token_secret)
{
- OAuthProxyPrivate *priv;
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (proxy);
g_return_if_fail (OAUTH_IS_PROXY (proxy));
- priv = PROXY_GET_PRIVATE (proxy);
if (priv->token_secret)
g_free (priv->token_secret);
@@ -619,9 +659,22 @@ oauth_proxy_set_token_secret (OAuthProxy *proxy, const char *token_secret)
gboolean
oauth_proxy_is_oauth10a (OAuthProxy *proxy)
{
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (proxy);
+
g_return_val_if_fail (OAUTH_IS_PROXY (proxy), FALSE);
- return PROXY_GET_PRIVATE (proxy)->oauth_10a;
+ return priv->oauth_10a;
+}
+
+void
+oauth_proxy_set_oauth10a (OAuthProxy *self,
+ gboolean oauth10a)
+{
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (self);
+
+ g_return_if_fail (OAUTH_IS_PROXY (self));
+
+ priv->oauth_10a = oauth10a;
}
/**
@@ -636,10 +689,9 @@ oauth_proxy_is_oauth10a (OAuthProxy *proxy)
const char *
oauth_proxy_get_signature_host (OAuthProxy *proxy)
{
- OAuthProxyPrivate *priv;
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (proxy);
g_return_val_if_fail (OAUTH_IS_PROXY (proxy), NULL);
- priv = PROXY_GET_PRIVATE (proxy);
return priv->signature_host;
}
@@ -655,10 +707,9 @@ void
oauth_proxy_set_signature_host (OAuthProxy *proxy,
const char *signature_host)
{
- OAuthProxyPrivate *priv;
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (proxy);
g_return_if_fail (OAUTH_IS_PROXY (proxy));
- priv = PROXY_GET_PRIVATE (proxy);
g_free (priv->signature_host);
@@ -686,14 +737,13 @@ oauth_proxy_new_echo_proxy (OAuthProxy *proxy,
gboolean binding_required)
{
OAuthProxy *echo_proxy;
- OAuthProxyPrivate *priv, *echo_priv;
+ OAuthProxyPrivate *echo_priv;
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (proxy);
g_return_val_if_fail (OAUTH_IS_PROXY (proxy), NULL);
g_return_val_if_fail (service_url, NULL);
g_return_val_if_fail (url_format, NULL);
- priv = PROXY_GET_PRIVATE (proxy);
-
echo_proxy = g_object_new (OAUTH_TYPE_PROXY,
"url-format", url_format,
"binding-required", binding_required,
@@ -703,7 +753,7 @@ oauth_proxy_new_echo_proxy (OAuthProxy *proxy,
"token", priv->token,
"token-secret", priv->token_secret,
NULL);
- echo_priv = PROXY_GET_PRIVATE (echo_proxy);
+ echo_priv = oauth_proxy_get_instance_private (echo_proxy);
echo_priv->oauth_echo = TRUE;
echo_priv->service_url = g_strdup (service_url);
@@ -728,3 +778,26 @@ oauth_signature_method_get_type (void)
return enum_type_id;
}
+gboolean
+oauth_proxy_is_echo (OAuthProxy *self)
+{
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (self);
+
+ return priv->oauth_echo;
+}
+
+const char *
+oauth_proxy_get_service_url (OAuthProxy *self)
+{
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (self);
+
+ return priv->service_url;
+}
+
+OAuthSignatureMethod
+oauth_proxy_get_sign_method (OAuthProxy *self)
+{
+ OAuthProxyPrivate *priv = oauth_proxy_get_instance_private (self);
+
+ return priv->method;
+}
diff --git a/rest/oauth-proxy.h b/rest/oauth-proxy.h
index fa1a89e..2616a34 100644
--- a/rest/oauth-proxy.h
+++ b/rest/oauth-proxy.h
@@ -28,37 +28,7 @@
G_BEGIN_DECLS
#define OAUTH_TYPE_PROXY oauth_proxy_get_type()
-
-#define OAUTH_PROXY(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), OAUTH_TYPE_PROXY, OAuthProxy))
-
-#define OAUTH_PROXY_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), OAUTH_TYPE_PROXY, OAuthProxyClass))
-
-#define OAUTH_IS_PROXY(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OAUTH_TYPE_PROXY))
-
-#define OAUTH_IS_PROXY_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), OAUTH_TYPE_PROXY))
-
-#define OAUTH_PROXY_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), OAUTH_TYPE_PROXY, OAuthProxyClass))
-
-/**
- * OAuthProxy:
- *
- * #OAuthProxy has no publicly available members.
- */
-typedef struct {
- RestProxy parent;
-} OAuthProxy;
-
-typedef struct {
- RestProxyClass parent_class;
- /*< private >*/
- /* padding for future expansion */
- gpointer _padding_dummy[8];
-} OAuthProxyClass;
+G_DECLARE_FINAL_TYPE (OAuthProxy, oauth_proxy, OAUTH, PROXY, RestProxy)
GType oauth_signature_method_get_type (void) G_GNUC_CONST;
#define OAUTH_TYPE_SIGNATURE_METHOD (oauth_signature_method_get_type())
@@ -77,68 +47,63 @@ typedef enum {
HMAC_SHA1
} OAuthSignatureMethod;
-GType oauth_proxy_get_type (void);
-
-RestProxy* oauth_proxy_new (const char *consumer_key,
- const char *consumer_secret,
- const gchar *url_format,
- gboolean binding_required);
-
-RestProxy* oauth_proxy_new_with_token (const char *consumer_key,
- const char *consumer_secret,
- const char *token,
- const char *token_secret,
- const gchar *url_format,
- gboolean binding_required);
-
-gboolean oauth_proxy_request_token (OAuthProxy *proxy,
- const char *function,
- const char *callback_uri,
- GError **error);
-
-void oauth_proxy_request_token_async (OAuthProxy *proxy,
- const char *function,
- const char *callback_uri,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-gboolean oauth_proxy_request_token_finish (OAuthProxy *proxy,
- GAsyncResult *result,
- GError **error);
-
-gboolean oauth_proxy_is_oauth10a (OAuthProxy *proxy);
-
-gboolean oauth_proxy_access_token (OAuthProxy *proxy,
- const char *function,
- const char *verifier,
- GError **error);
-
-void oauth_proxy_access_token_async (OAuthProxy *proxy,
- const char *function,
- const char *verifier,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-gboolean oauth_proxy_access_token_finish (OAuthProxy *proxy,
- GAsyncResult *result,
- GError **error);
-
-const char * oauth_proxy_get_token (OAuthProxy *proxy);
-
-void oauth_proxy_set_token (OAuthProxy *proxy, const char *token);
-
-const char * oauth_proxy_get_token_secret (OAuthProxy *proxy);
-
-void oauth_proxy_set_token_secret (OAuthProxy *proxy, const char *token_secret);
-const char * oauth_proxy_get_signature_host (OAuthProxy *proxy);
-
-void oauth_proxy_set_signature_host (OAuthProxy *proxy,
- const char *signature_host);
-
-RestProxy *oauth_proxy_new_echo_proxy (OAuthProxy *proxy,
- const char *service_url,
- const gchar *url_format,
- gboolean binding_required);
+RestProxy *oauth_proxy_new (const char *consumer_key,
+ const char *consumer_secret,
+ const gchar *url_format,
+ gboolean binding_required);
+RestProxy *oauth_proxy_new_with_token (const char *consumer_key,
+ const char *consumer_secret,
+ const char *token,
+ const char *token_secret,
+ const gchar *url_format,
+ gboolean binding_required);
+gboolean oauth_proxy_request_token (OAuthProxy *proxy,
+ const char *function,
+ const char *callback_uri,
+ GError **error);
+void oauth_proxy_request_token_async (OAuthProxy *proxy,
+ const char *function,
+ const char *callback_uri,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean oauth_proxy_request_token_finish (OAuthProxy *proxy,
+ GAsyncResult *result,
+ GError **error);
+gboolean oauth_proxy_is_oauth10a (OAuthProxy *proxy);
+void oauth_proxy_set_oauth10a (OAuthProxy *proxy,
+ gboolean oauth10a);
+gboolean oauth_proxy_access_token (OAuthProxy *proxy,
+ const char *function,
+ const char *verifier,
+ GError **error);
+void oauth_proxy_access_token_async (OAuthProxy *proxy,
+ const char *function,
+ const char *verifier,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean oauth_proxy_access_token_finish (OAuthProxy *proxy,
+ GAsyncResult *result,
+ GError **error);
+const char *oauth_proxy_get_consumer_key (OAuthProxy *proxy);
+const char *oauth_proxy_get_consumer_secret (OAuthProxy *proxy);
+const char *oauth_proxy_get_token (OAuthProxy *proxy);
+void oauth_proxy_set_token (OAuthProxy *proxy,
+ const char *token);
+const char *oauth_proxy_get_token_secret (OAuthProxy *proxy);
+void oauth_proxy_set_token_secret (OAuthProxy *proxy,
+ const char *token_secret);
+const char *oauth_proxy_get_signature_host (OAuthProxy *proxy);
+void oauth_proxy_set_signature_host (OAuthProxy *proxy,
+ const char *signature_host);
+RestProxy *oauth_proxy_new_echo_proxy (OAuthProxy *proxy,
+ const char *service_url,
+ const gchar *url_format,
+ gboolean binding_required);
+gboolean oauth_proxy_is_echo (OAuthProxy *proxy);
+const char *oauth_proxy_get_service_url (OAuthProxy *proxy);
+OAuthSignatureMethod oauth_proxy_get_sign_method (OAuthProxy *proxy);
G_END_DECLS
diff --git a/rest/rest-oauth2-proxy-call.c b/rest/rest-oauth2-proxy-call.c
index cbea6f5..88840b3 100644
--- a/rest/rest-oauth2-proxy-call.c
+++ b/rest/rest-oauth2-proxy-call.c
@@ -1,6 +1,6 @@
/* rest-oauth2-proxy-call.c
*
- * Copyright 2021 Günther Wagner <info@gunibert.de>
+ * Copyright 2021-2022 Günther Wagner <info@gunibert.de>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU Lesser General Public License,
@@ -24,7 +24,6 @@ static gboolean
rest_oauth2_proxy_call_prepare (RestProxyCall *call,
GError **error)
{
- RestOAuth2ProxyCall *self = (RestOAuth2ProxyCall *)call;
RestOAuth2Proxy *proxy = NULL;
g_autoptr(GDateTime) now = NULL;
GDateTime *expiration_date = NULL;
diff --git a/rest/rest-param.c b/rest/rest-param.c
index 8ad105f..1f6f73c 100644
--- a/rest/rest-param.c
+++ b/rest/rest-param.c
@@ -89,7 +89,7 @@ rest_param_new_full (const char *name,
param = g_slice_new0 (RestParam);
if (use == REST_MEMORY_COPY) {
- data = g_memdup (data, length);
+ data = g_memdup2 (data, length);
use = REST_MEMORY_TAKE;
}
diff --git a/rest/rest-params.c b/rest/rest-params.c
index f246cc2..f2ac286 100644
--- a/rest/rest-params.c
+++ b/rest/rest-params.c
@@ -30,18 +30,7 @@
* @see_also: #RestParam, #RestProxyCall.
*/
-/*
- * RestParams is an alias for GHashTable achieved by opaque types in the public
- * headers and casting internally. This has several limitations, mainly
- * supporting multiple parameters with the same name and preserving the ordering
- * of parameters.
- *
- * These are not requirements for the bulk of the web services, but this
- * limitation does mean librest can't be used for a few web services.
- *
- * TODO: this should be a list to support multiple parameters with the same
- * name.
- */
+G_DEFINE_BOXED_TYPE (RestParams, rest_params, rest_params_ref, rest_params_unref)
/**
* rest_params_new:
@@ -53,11 +42,13 @@
RestParams *
rest_params_new (void)
{
- /* The key is a string that is owned by the RestParam, so we don't need to
- explicitly free it on removal. */
- return (RestParams *)
- g_hash_table_new_full (g_str_hash, g_str_equal,
- NULL, (GDestroyNotify)rest_param_unref);
+ RestParams *self;
+
+ self = g_slice_new0 (RestParams);
+ self->ref_count = 1;
+ self->params = NULL;
+
+ return self;
}
/**
@@ -67,13 +58,73 @@ rest_params_new (void)
* Destroy the #RestParams and the #RestParam objects that it contains.
**/
void
-rest_params_free (RestParams *params)
+rest_params_free (RestParams *self)
{
- GHashTable *hash = (GHashTable *)params;
+ g_assert (self);
+ g_assert_cmpint (self->ref_count, ==, 0);
- g_return_if_fail (params);
+ g_list_free_full (g_steal_pointer (&self->params), (GDestroyNotify) rest_param_unref);
+
+ g_slice_free (RestParams, self);
+}
+
+/**
+ * rest_params_copy:
+ * @self: a #RestParams
+ *
+ * Makes a deep copy of a #RestParams.
+ *
+ * Returns: (transfer full): A newly created #RestParams with the same
+ * contents as @self
+ */
+RestParams *
+rest_params_copy (RestParams *self)
+{
+ RestParams *copy;
+
+ g_return_val_if_fail (self, NULL);
+ g_return_val_if_fail (self->ref_count, NULL);
+
+ copy = rest_params_new ();
+ copy->params = g_list_copy_deep (self->params, (GCopyFunc) rest_param_ref, NULL);
+
+ return copy;
+}
+
+/**
+ * rest_params_ref:
+ * @self: A #RestParams
+ *
+ * Increments the reference count of @self by one.
+ *
+ * Returns: (transfer full): @self
+ */
+RestParams *
+rest_params_ref (RestParams *self)
+{
+ g_return_val_if_fail (self, NULL);
+ g_return_val_if_fail (self->ref_count, NULL);
+
+ g_atomic_int_inc (&self->ref_count);
- g_hash_table_destroy (hash);
+ return self;
+}
+
+/**
+ * rest_params_unref:
+ * @self: A #RestParams
+ *
+ * Decrements the reference count of @self by one, freeing the structure when
+ * the reference count reaches zero.
+ */
+void
+rest_params_unref (RestParams *self)
+{
+ g_return_if_fail (self);
+ g_return_if_fail (self->ref_count);
+
+ if (g_atomic_int_dec_and_test (&self->ref_count))
+ rest_params_free (self);
}
/**
@@ -84,14 +135,25 @@ rest_params_free (RestParams *params)
* Add @param to @params.
**/
void
-rest_params_add (RestParams *params, RestParam *param)
+rest_params_add (RestParams *self,
+ RestParam *param)
{
- GHashTable *hash = (GHashTable *)params;
-
- g_return_if_fail (params);
+ g_return_if_fail (self);
g_return_if_fail (param);
- g_hash_table_replace (hash, (gpointer)rest_param_get_name (param), param);
+ self->params = g_list_append (self->params, param);
+}
+
+static gint
+rest_params_find (gconstpointer self,
+ gconstpointer name)
+{
+ const RestParam *e = self;
+ const char *n = name;
+ const char *n2 = rest_param_get_name ((RestParam *)e);
+
+ if (g_strcmp0 (n2, n) == 0) return 0;
+ return -1;
}
/**
@@ -105,14 +167,13 @@ rest_params_add (RestParams *params, RestParam *param)
* doesn't exist
**/
RestParam *
-rest_params_get (RestParams *params, const char *name)
+rest_params_get (RestParams *self,
+ const char *name)
{
- GHashTable *hash = (GHashTable *)params;
-
- g_return_val_if_fail (params, NULL);
+ g_return_val_if_fail (self, NULL);
g_return_val_if_fail (name, NULL);
- return g_hash_table_lookup (hash, name);
+ return g_list_find_custom (self->params, name, rest_params_find)->data;
}
/**
@@ -123,14 +184,16 @@ rest_params_get (RestParams *params, const char *name)
* Remove the #RestParam called @name.
**/
void
-rest_params_remove (RestParams *params, const char *name)
+rest_params_remove (RestParams *self,
+ const char *name)
{
- GHashTable *hash = (GHashTable *)params;
+ GList *elem = NULL;
- g_return_if_fail (params);
+ g_return_if_fail (self);
g_return_if_fail (name);
- g_hash_table_remove (hash, name);
+ elem = g_list_find_custom (self->params, name, rest_params_find);
+ self->params = g_list_remove (self->params, elem->data);
}
/**
@@ -143,27 +206,22 @@ rest_params_remove (RestParams *params, const char *name)
* Returns: %TRUE if all of the parameters are simple strings, %FALSE otherwise.
**/
gboolean
-rest_params_are_strings (RestParams *params)
+rest_params_are_strings (RestParams *self)
{
- GHashTable *hash = (GHashTable *)params;
- GHashTableIter iter;
- RestParam *param;
-
- g_return_val_if_fail (params, FALSE);
+ g_return_val_if_fail (self, FALSE);
- g_hash_table_iter_init (&iter, hash);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer)&param)) {
- if (!rest_param_is_string (param))
- return FALSE;
- }
+ for (GList *cur = self->params; cur; cur = g_list_next (cur))
+ {
+ if (!rest_param_is_string (cur->data))
+ return FALSE;
+ }
return TRUE;
-
}
/**
* rest_params_as_string_hash_table:
- * @params: a valid #RestParams
+ * @self: a valid #RestParams
*
* Create a new #GHashTable which contains the name and value of all string
* (content type of text/plain) parameters.
@@ -174,23 +232,19 @@ rest_params_are_strings (RestParams *params)
* Returns: (element-type utf8 Rest.Param) (transfer container): a new #GHashTable.
**/
GHashTable *
-rest_params_as_string_hash_table (RestParams *params)
+rest_params_as_string_hash_table (RestParams *self)
{
- GHashTable *hash, *strings;
- GHashTableIter iter;
- const char *name = NULL;
- RestParam *param = NULL;
+ GHashTable *strings;
- g_return_val_if_fail (params, NULL);
+ g_return_val_if_fail (self, NULL);
- hash = (GHashTable *)params;
strings = g_hash_table_new (g_str_hash, g_str_equal);
- g_hash_table_iter_init (&iter, hash);
- while (g_hash_table_iter_next (&iter, (gpointer)&name, (gpointer)&param)) {
- if (rest_param_is_string (param))
- g_hash_table_insert (strings, (gpointer)name, (gpointer)rest_param_get_content (param));
- }
+ for (GList *cur = self->params; cur; cur = g_list_next (cur))
+ {
+ if (rest_param_is_string (cur->data))
+ g_hash_table_insert (strings, (gpointer)rest_param_get_name (cur->data), (gpointer)rest_param_get_content (cur->data));
+ }
return strings;
}
@@ -214,12 +268,14 @@ rest_params_as_string_hash_table (RestParams *params)
* ]|
**/
void
-rest_params_iter_init (RestParamsIter *iter, RestParams *params)
+rest_params_iter_init (RestParamsIter *iter,
+ RestParams *params)
{
g_return_if_fail (iter);
g_return_if_fail (params);
- g_hash_table_iter_init ((GHashTableIter *)iter, (GHashTable *)params);
+ iter->params = params;
+ iter->position = -1;
}
/**
@@ -235,9 +291,21 @@ rest_params_iter_init (RestParamsIter *iter, RestParams *params)
* Returns: %FALSE if the end of the #RestParams has been reached, %TRUE otherwise.
**/
gboolean
-rest_params_iter_next (RestParamsIter *iter, const char **name, RestParam **param)
+rest_params_iter_next (RestParamsIter *iter,
+ const char **name,
+ RestParam **param)
{
+ GList *cur = NULL;
+
g_return_val_if_fail (iter, FALSE);
- return g_hash_table_iter_next ((GHashTableIter *)iter, (gpointer)name, (gpointer)param);
+ iter->position++;
+ cur = g_list_nth (iter->params->params, iter->position);
+
+ if (cur == NULL) return FALSE;
+
+ *param = cur->data;
+ *name = rest_param_get_name (*param);
+ return TRUE;
}
+
diff --git a/rest/rest-params.h b/rest/rest-params.h
index caace9d..9f53f77 100644
--- a/rest/rest-params.h
+++ b/rest/rest-params.h
@@ -20,34 +20,52 @@
*
*/
-#ifndef _REST_PARAMS
-#define _REST_PARAMS
+#pragma once
#include <glib-object.h>
#include "rest-param.h"
G_BEGIN_DECLS
-typedef struct _RestParams RestParams;
-typedef struct _GHashTableIter RestParamsIter;
-
-RestParams * rest_params_new (void);
-
-void rest_params_free (RestParams *params);
+#define REST_TYPE_PARAMS (rest_params_get_type ())
-void rest_params_add (RestParams *params, RestParam *param);
+typedef struct _RestParams RestParams;
+typedef struct _RestParamsIter RestParamsIter;
-RestParam *rest_params_get (RestParams *params, const char *name);
+struct _RestParams
+{
+ /*< private >*/
+ guint ref_count;
-void rest_params_remove (RestParams *params, const char *name);
+ GList *params;
+};
-gboolean rest_params_are_strings (RestParams *params);
+struct _RestParamsIter
+{
+ /*< private >*/
+ RestParams *params;
+ gint position;
+};
-GHashTable * rest_params_as_string_hash_table (RestParams *params);
+GType rest_params_get_type (void) G_GNUC_CONST;
+RestParams *rest_params_new (void);
+RestParams *rest_params_copy (RestParams *self);
+RestParams *rest_params_ref (RestParams *self);
+void rest_params_unref (RestParams *self);
+void rest_params_add (RestParams *params,
+ RestParam *param);
+RestParam *rest_params_get (RestParams *params,
+ const char *name);
+void rest_params_remove (RestParams *params,
+ const char *name);
+gboolean rest_params_are_strings (RestParams *params);
+GHashTable *rest_params_as_string_hash_table (RestParams *params);
+void rest_params_iter_init (RestParamsIter *iter,
+ RestParams *params);
+gboolean rest_params_iter_next (RestParamsIter *iter,
+ const char **name,
+ RestParam **param);
-void rest_params_iter_init (RestParamsIter *iter, RestParams *params);
-gboolean rest_params_iter_next (RestParamsIter *iter, const char **name, RestParam **param);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (RestParams, rest_params_unref)
G_END_DECLS
-
-#endif /* _REST_PARAMS */
diff --git a/rest/rest-proxy-call.c b/rest/rest-proxy-call.c
index 24d952d..791a7dd 100644
--- a/rest/rest-proxy-call.c
+++ b/rest/rest-proxy-call.c
@@ -148,7 +148,7 @@ rest_proxy_call_dispose (GObject *object)
g_clear_object (&priv->cancellable);
}
- g_clear_pointer (&priv->params, rest_params_free);
+ g_clear_pointer (&priv->params, rest_params_unref);
g_clear_pointer (&priv->headers, g_hash_table_unref);
g_clear_pointer (&priv->response_headers, g_hash_table_unref);
g_clear_object (&priv->proxy);
diff --git a/rest/rest-proxy.c b/rest/rest-proxy.c
index 8231b6f..d8dbfc6 100644
--- a/rest/rest-proxy.c
+++ b/rest/rest-proxy.c
@@ -31,8 +31,6 @@
#include "rest-private.h"
-#define GET_PRIVATE(o) rest_proxy_get_instance_private(REST_PROXY(o))
-
typedef struct _RestProxyPrivate RestProxyPrivate;
struct _RestProxyPrivate {
@@ -74,16 +72,14 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
-static gboolean _rest_proxy_simple_run_valist (RestProxy *proxy,
- char **payload,
- goffset *len,
- GError **error,
- va_list params);
-
-static RestProxyCall *_rest_proxy_new_call (RestProxy *proxy);
-
-static gboolean _rest_proxy_bind_valist (RestProxy *proxy,
- va_list params);
+static gboolean _rest_proxy_simple_run_valist (RestProxy *proxy,
+ char **payload,
+ goffset *len,
+ GError **error,
+ va_list params);
+static RestProxyCall *_rest_proxy_new_call (RestProxy *proxy);
+static gboolean _rest_proxy_bind_valist (RestProxy *proxy,
+ va_list params);
GQuark
rest_proxy_error_quark (void)
@@ -97,7 +93,8 @@ rest_proxy_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- RestProxyPrivate *priv = GET_PRIVATE (object);
+ RestProxy *self = REST_PROXY (object);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (self);
switch (property_id) {
case PROP_URL_FORMAT:
@@ -145,7 +142,8 @@ rest_proxy_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- RestProxyPrivate *priv = GET_PRIVATE (object);
+ RestProxy *self = REST_PROXY (object);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (self);
switch (property_id) {
case PROP_URL_FORMAT:
@@ -199,7 +197,8 @@ rest_proxy_set_property (GObject *object,
static void
rest_proxy_dispose (GObject *object)
{
- RestProxyPrivate *priv = GET_PRIVATE (object);
+ RestProxy *self = REST_PROXY (object);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (self);
g_clear_object (&priv->session);
@@ -226,7 +225,7 @@ authenticate (RestProxy *self,
gboolean retrying,
SoupSession *session)
{
- RestProxyPrivate *priv = GET_PRIVATE (self);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (self);
RestProxyAuth *rest_auth;
gboolean try_auth;
@@ -241,7 +240,8 @@ authenticate (RestProxy *self,
static void
rest_proxy_constructed (GObject *object)
{
- RestProxyPrivate *priv = GET_PRIVATE (object);
+ RestProxy *self = REST_PROXY (object);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (self);
if (!priv->disable_cookies) {
SoupSessionFeature *cookie_jar =
@@ -270,7 +270,8 @@ rest_proxy_constructed (GObject *object)
static void
rest_proxy_finalize (GObject *object)
{
- RestProxyPrivate *priv = GET_PRIVATE (object);
+ RestProxy *self = REST_PROXY (object);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (self);
g_free (priv->url);
g_free (priv->url_format);
@@ -440,14 +441,17 @@ transform_tls_database_to_ssl_ca_file (GBinding *binding,
static void
rest_proxy_init (RestProxy *self)
{
- RestProxyPrivate *priv = GET_PRIVATE (self);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (self);
+#ifdef REST_SYSTEM_CA_FILE
GTlsDatabase *tls_database;
+#endif
#ifndef WITH_SOUP_2
priv->ssl_strict = TRUE;
#endif
priv->session = soup_session_new ();
+ soup_session_remove_feature_by_type (priv->session, SOUP_TYPE_AUTH_MANAGER);
#ifdef REST_SYSTEM_CA_FILE
/* with ssl-strict (defaults TRUE) setting ssl-ca-file forces all
@@ -532,7 +536,7 @@ static gboolean
_rest_proxy_bind_valist (RestProxy *proxy,
va_list params)
{
- RestProxyPrivate *priv = GET_PRIVATE (proxy);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (proxy);
g_return_val_if_fail (proxy != NULL, FALSE);
g_return_val_if_fail (priv->url_format != NULL, FALSE);
@@ -583,7 +587,7 @@ rest_proxy_set_user_agent (RestProxy *proxy,
const gchar *
rest_proxy_get_user_agent (RestProxy *proxy)
{
- RestProxyPrivate *priv = GET_PRIVATE (proxy);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (proxy);
g_return_val_if_fail (REST_IS_PROXY (proxy), NULL);
@@ -613,9 +617,10 @@ rest_proxy_get_user_agent (RestProxy *proxy)
* Since: 0.7.92
*/
void
-rest_proxy_add_soup_feature (RestProxy *proxy, SoupSessionFeature *feature)
+rest_proxy_add_soup_feature (RestProxy *proxy,
+ SoupSessionFeature *feature)
{
- RestProxyPrivate *priv = GET_PRIVATE (proxy);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (proxy);
g_return_if_fail (REST_IS_PROXY(proxy));
g_return_if_fail (feature != NULL);
@@ -659,7 +664,7 @@ rest_proxy_new_call (RestProxy *proxy)
gboolean
_rest_proxy_get_binding_required (RestProxy *proxy)
{
- RestProxyPrivate *priv = GET_PRIVATE (proxy);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (proxy);
g_return_val_if_fail (REST_IS_PROXY (proxy), FALSE);
@@ -669,14 +674,14 @@ _rest_proxy_get_binding_required (RestProxy *proxy)
const gchar *
_rest_proxy_get_bound_url (RestProxy *proxy)
{
- RestProxyPrivate *priv = GET_PRIVATE (proxy);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (proxy);
g_return_val_if_fail (REST_IS_PROXY (proxy), NULL);
if (!priv->url && !priv->binding_required)
- {
- priv->url = g_strdup (priv->url_format);
- }
+ {
+ priv->url = g_strdup (priv->url_format);
+ }
return priv->url;
}
@@ -791,7 +796,7 @@ _rest_proxy_queue_message (RestProxy *proxy,
RestMessageFinishedCallback callback,
gpointer user_data)
{
- RestProxyPrivate *priv = GET_PRIVATE (proxy);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (proxy);
RestMessageQueueData *data;
g_return_if_fail (REST_IS_PROXY (proxy));
@@ -841,7 +846,7 @@ _rest_proxy_send_message_async (RestProxy *proxy,
GAsyncReadyCallback callback,
gpointer user_data)
{
- RestProxyPrivate *priv = GET_PRIVATE (proxy);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (proxy);
GTask *task;
task = g_task_new (proxy, cancellable, callback, user_data);
@@ -868,7 +873,7 @@ _rest_proxy_cancel_message (RestProxy *proxy,
SoupMessage *message)
{
#ifdef WITH_SOUP_2
- RestProxyPrivate *priv = GET_PRIVATE (proxy);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (proxy);
g_return_if_fail (REST_IS_PROXY (proxy));
g_return_if_fail (SOUP_IS_MESSAGE (message));
@@ -885,7 +890,7 @@ _rest_proxy_send_message (RestProxy *proxy,
GCancellable *cancellable,
GError **error)
{
- RestProxyPrivate *priv = GET_PRIVATE (proxy);
+ RestProxyPrivate *priv = rest_proxy_get_instance_private (proxy);
GBytes *body;
g_return_val_if_fail (REST_IS_PROXY (proxy), NULL);
diff --git a/rest/rest-proxy.h b/rest/rest-proxy.h
index bb6d7b0..4b2a813 100644
--- a/rest/rest-proxy.h
+++ b/rest/rest-proxy.h
@@ -160,41 +160,32 @@ typedef enum {
GQuark rest_proxy_error_quark (void);
-RestProxy *rest_proxy_new (const gchar *url_format,
- gboolean binding_required);
-
-RestProxy *
-rest_proxy_new_with_authentication (const gchar *url_format,
- gboolean binding_required,
- const gchar *username,
- const gchar *password);
-
-gboolean rest_proxy_bind (RestProxy *proxy,
- ...);
-
-gboolean rest_proxy_bind_valist (RestProxy *proxy,
- va_list params);
-
-void rest_proxy_set_user_agent (RestProxy *proxy, const char *user_agent);
-
-const gchar *rest_proxy_get_user_agent (RestProxy *proxy);
-
-void rest_proxy_add_soup_feature (RestProxy *proxy,
- SoupSessionFeature *feature);
-
-RestProxyCall *rest_proxy_new_call (RestProxy *proxy);
-
-G_GNUC_NULL_TERMINATED
-gboolean rest_proxy_simple_run (RestProxy *proxy,
- gchar **payload,
- goffset *len,
- GError **error,
- ...);
-gboolean rest_proxy_simple_run_valist (RestProxy *proxy,
- gchar **payload,
- goffset *len,
- GError **error,
- va_list params);
+RestProxy *rest_proxy_new (const gchar *url_format,
+ gboolean binding_required);
+RestProxy *rest_proxy_new_with_authentication (const gchar *url_format,
+ gboolean binding_required,
+ const gchar *username,
+ const gchar *password);
+gboolean rest_proxy_bind (RestProxy *proxy,
+ ...);
+gboolean rest_proxy_bind_valist (RestProxy *proxy,
+ va_list params);
+void rest_proxy_set_user_agent (RestProxy *proxy,
+ const char *user_agent);
+const gchar *rest_proxy_get_user_agent (RestProxy *proxy);
+void rest_proxy_add_soup_feature (RestProxy *proxy,
+ SoupSessionFeature *feature);
+RestProxyCall *rest_proxy_new_call (RestProxy *proxy);
+gboolean rest_proxy_simple_run (RestProxy *proxy,
+ gchar **payload,
+ goffset *len,
+ GError **error,
+ ...) G_GNUC_NULL_TERMINATED;
+gboolean rest_proxy_simple_run_valist (RestProxy *proxy,
+ gchar **payload,
+ goffset *len,
+ GError **error,
+ va_list params);
G_END_DECLS
#endif /* _REST_PROXY */
diff --git a/rest/rest-xml-node.h b/rest/rest-xml-node.h
index 335bd64..05a4056 100644
--- a/rest/rest-xml-node.h
+++ b/rest/rest-xml-node.h
@@ -21,8 +21,7 @@
*
*/
-#ifndef _REST_XML_NODE
-#define _REST_XML_NODE
+#pragma once
#include <glib-object.h>
@@ -39,6 +38,8 @@ G_BEGIN_DECLS
* @attrs: a #GHashTable of string name to string values for the attributes of
* the element.
* @next: the sibling #RestXmlNode with the same name
+ *
+ * The #RestXmlNode contains a parsed XmlNode for easy consumption
*/
typedef struct _RestXmlNode RestXmlNode;
struct _RestXmlNode {
@@ -54,20 +55,21 @@ struct _RestXmlNode {
GType rest_xml_node_get_type (void);
-RestXmlNode *rest_xml_node_ref (RestXmlNode *node);
-void rest_xml_node_unref (RestXmlNode *node);
-const gchar *rest_xml_node_get_attr (RestXmlNode *node,
- const gchar *attr_name);
-RestXmlNode *rest_xml_node_find (RestXmlNode *start,
- const gchar *tag);
+RestXmlNode *rest_xml_node_ref (RestXmlNode *node);
+void rest_xml_node_unref (RestXmlNode *node);
+const gchar *rest_xml_node_get_attr (RestXmlNode *node,
+ const gchar *attr_name);
+RestXmlNode *rest_xml_node_find (RestXmlNode *start,
+ const gchar *tag);
+RestXmlNode *rest_xml_node_add_child (RestXmlNode *parent,
+ const char *tag);
+char *rest_xml_node_print (RestXmlNode *node);
+void rest_xml_node_add_attr (RestXmlNode *node,
+ const char *attribute,
+ const char *value);
+void rest_xml_node_set_content (RestXmlNode *node,
+ const char *value);
-RestXmlNode *rest_xml_node_add_child (RestXmlNode *parent, const char *tag);
-char *rest_xml_node_print (RestXmlNode *node);
-void rest_xml_node_add_attr (RestXmlNode *node,
- const char *attribute,
- const char *value);
-void rest_xml_node_set_content (RestXmlNode *node, const char *value);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (RestXmlNode, rest_xml_node_unref)
G_END_DECLS
-
-#endif /* _REST_XML_NODE */
diff --git a/rest/rest-xml-parser.h b/rest/rest-xml-parser.h
index cceda02..cee2570 100644
--- a/rest/rest-xml-parser.h
+++ b/rest/rest-xml-parser.h
@@ -20,8 +20,7 @@
*
*/
-#ifndef _REST_XML_PARSER
-#define _REST_XML_PARSER
+#pragma once
#include <glib-object.h>
#include <rest/rest-xml-node.h>
@@ -31,15 +30,19 @@ G_BEGIN_DECLS
#define REST_TYPE_XML_PARSER rest_xml_parser_get_type()
G_DECLARE_DERIVABLE_TYPE (RestXmlParser, rest_xml_parser, REST, XML_PARSER, GObject)
+/**
+ * RestXmlParser:
+ *
+ * A Xml Parser for Rest Responses
+ */
+
struct _RestXmlParserClass {
GObjectClass parent_class;
};
-RestXmlParser *rest_xml_parser_new (void);
-RestXmlNode *rest_xml_parser_parse_from_data (RestXmlParser *parser,
- const gchar *data,
- goffset len);
+RestXmlParser *rest_xml_parser_new (void);
+RestXmlNode *rest_xml_parser_parse_from_data (RestXmlParser *parser,
+ const gchar *data,
+ goffset len);
G_END_DECLS
-
-#endif /* _REST_XML_PARSER */
diff --git a/tests/meson.build b/tests/meson.build
index c7c9170..b3087a7 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -6,6 +6,7 @@ test_suites = {
'xml',
'custom-serialize',
'oauth2',
+ 'params',
],
'rest-extras': [
'flickr',
@@ -20,6 +21,11 @@ test_deps = [
librest_extras_dep,
]
+test_env = [
+ 'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()),
+ 'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
+]
+
foreach suite, test_names : test_suites
foreach name : test_names
test_bin = executable(name,
@@ -30,6 +36,7 @@ foreach suite, test_names : test_suites
test(name, test_bin,
suite: suite,
+ env: test_env,
)
endforeach
endforeach
diff --git a/tests/params.c b/tests/params.c
new file mode 100644
index 0000000..e477ba9
--- /dev/null
+++ b/tests/params.c
@@ -0,0 +1,141 @@
+#include <glib.h>
+#include "rest/rest-params.h"
+#include "rest/rest-param.h"
+#include <glib-object.h>
+
+static void
+test_params (void)
+{
+ RestParamsIter iter;
+ RestParam *param;
+ const char *name;
+ gint pos = 0;
+ g_autoptr(RestParams) params = NULL;
+
+ struct {
+ char *name;
+ char *value;
+ } data[] = {
+ {
+ .name = "name1",
+ .value = "value1"
+ },
+ {
+ .name = "name2",
+ .value = "value2"
+ }
+ };
+
+ params = rest_params_new ();
+ for (gint i = 0; i < sizeof (data)/sizeof (data[0]); i++)
+ {
+ RestParam *p = rest_param_new_string (data[i].name, REST_MEMORY_COPY, data[i].value);
+ rest_params_add (params, p);
+ }
+
+ rest_params_iter_init (&iter, params);
+ while (rest_params_iter_next (&iter, &name, &param))
+ {
+ g_assert_cmpstr (data[pos].name, ==, name);
+ g_assert_cmpstr (data[pos].value, ==, rest_param_get_content (param));
+ pos++;
+ }
+
+ rest_params_remove (params, "name2");
+ pos = 0;
+ rest_params_iter_init (&iter, params);
+ while (rest_params_iter_next (&iter, &name, &param))
+ {
+ g_assert_cmpstr (data[pos].name, ==, name);
+ g_assert_cmpstr (data[pos].value, ==, rest_param_get_content (param));
+ pos++;
+ }
+}
+
+static void
+test_params_get (void)
+{
+ g_autoptr(RestParams) params;
+ RestParam *p1;
+
+ struct {
+ char *name;
+ char *value;
+ } data[] = {
+ {
+ .name = "name1",
+ .value = "value1"
+ },
+ {
+ .name = "name2",
+ .value = "value2"
+ }
+ };
+
+ params = rest_params_new ();
+ for (gint i = 0; i < sizeof (data)/sizeof (data[0]); i++)
+ {
+ RestParam *p = rest_param_new_string (data[i].name, REST_MEMORY_COPY, data[i].value);
+ rest_params_add (params, p);
+ }
+
+ p1 = rest_params_get (params, "name2");
+
+ g_assert_cmpstr (rest_param_get_name (p1), ==, "name2");
+ g_assert_cmpstr (rest_param_get_content (p1), ==, "value2");
+}
+
+static void
+test_params_is_string (void)
+{
+ g_autoptr(GError) error = NULL;
+ g_autoptr(RestParams) params;
+ g_autofree char *file;
+ gsize length;
+ gchar *contents;
+ RestParam *p;
+
+ struct {
+ char *name;
+ char *value;
+ } data[] = {
+ {
+ .name = "name1",
+ .value = "value1"
+ },
+ {
+ .name = "name2",
+ .value = "value2"
+ }
+ };
+
+ params = rest_params_new ();
+ for (gint i = 0; i < sizeof (data)/sizeof (data[0]); i++)
+ {
+ RestParam *p = rest_param_new_string (data[i].name, REST_MEMORY_COPY, data[i].value);
+ rest_params_add (params, p);
+ }
+
+ g_assert_true (rest_params_are_strings (params));
+
+ file = g_test_build_filename (G_TEST_DIST, "test-media.png", NULL);
+ g_file_get_contents(file, &contents, &length, &error);
+
+ p = rest_param_new_full ("nostring", REST_MEMORY_COPY, contents, length, "image/png", "test-media.png");
+ rest_params_add (params, p);
+
+ g_assert_false (rest_params_are_strings (params));
+}
+
+gint
+main (gint argc,
+ gchar *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func("/rest/params", test_params);
+ g_test_add_func("/rest/params_get", test_params_get);
+ g_test_add_func("/rest/params_is_strings", test_params_is_string);
+
+ return g_test_run ();
+}
diff --git a/tests/proxy-continuous.c b/tests/proxy-continuous.c
index efc3de1..f489af5 100644
--- a/tests/proxy-continuous.c
+++ b/tests/proxy-continuous.c
@@ -154,7 +154,7 @@ continuous ()
GSList *uris;
- server = soup_server_new (NULL);
+ server = soup_server_new (NULL, NULL);
soup_server_listen_local (server, 0, 0, &error);
g_assert_no_error (error);
diff --git a/tests/proxy.c b/tests/proxy.c
index fc77869..a6d034a 100644
--- a/tests/proxy.c
+++ b/tests/proxy.c
@@ -174,8 +174,9 @@ server_callback (SoupServer *server,
static void
-ping_test (RestProxy *proxy)
+ping_test (gconstpointer data)
{
+ RestProxy *proxy = (RestProxy *)data;
g_autoptr(RestProxyCall) call;
GError *error = NULL;
@@ -197,8 +198,9 @@ ping_test (RestProxy *proxy)
}
static void
-echo_test (RestProxy *proxy)
+echo_test (gconstpointer data)
{
+ RestProxy *proxy = (RestProxy *)data;
g_autoptr(RestProxyCall) call;
GError *error = NULL;
@@ -213,8 +215,9 @@ echo_test (RestProxy *proxy)
}
static void
-reverse_test (RestProxy *proxy)
+reverse_test (gconstpointer data)
{
+ RestProxy *proxy = (RestProxy *)data;
g_autoptr(RestProxyCall) call;
GError *error = NULL;
@@ -245,8 +248,9 @@ status_ok_test (RestProxy *proxy, guint status)
}
static void
-status_test (RestProxy *proxy)
+status_test (gconstpointer data)
{
+ RestProxy *proxy = (RestProxy *)data;
status_ok_test (proxy, SOUP_STATUS_OK);
status_ok_test (proxy, SOUP_STATUS_NO_CONTENT);
}
@@ -268,8 +272,9 @@ status_error_test (RestProxy *proxy, guint status)
}
static void
-status_test_error (RestProxy *proxy)
+status_test_error (gconstpointer data)
{
+ RestProxy *proxy = (RestProxy *)data;
status_error_test (proxy, SOUP_STATUS_BAD_REQUEST);
status_error_test (proxy, SOUP_STATUS_NOT_IMPLEMENTED);
}
@@ -288,8 +293,9 @@ test_status_ok (RestProxy *proxy, const char *function)
}
static void
-test_user_agent (RestProxy *proxy)
+test_user_agent (gconstpointer data)
{
+ RestProxy *proxy = (RestProxy *)data;
test_status_ok (proxy, "useragent/none");
rest_proxy_set_user_agent (proxy, "TestSuite-1.0");
test_status_ok (proxy, "useragent/testsuite");
diff --git a/tests/test-media.png b/tests/test-media.png
new file mode 100644
index 0000000..2dbbccc
--- /dev/null
+++ b/tests/test-media.png
Binary files differ
diff --git a/tests/threaded.c b/tests/threaded.c
index 411361c..385156c 100644
--- a/tests/threaded.c
+++ b/tests/threaded.c
@@ -95,7 +95,7 @@ static void ping ()
int i;
GSList *uris;
- server = soup_server_new (NULL);
+ server = soup_server_new (NULL, NULL);
soup_server_listen_local (server, 0, 0, &error);
g_assert_no_error (error);