[librest/wip/baedert/tests: 10/10] OAuthProxy: Add missing annotations and precondition checks



commit dd5ff40573094fb3f4652ee9d90478b31e01cf48
Author: Timm Bäder <mail baedert org>
Date:   Fri Jul 22 09:24:47 2016 +0200

    OAuthProxy: Add missing annotations and precondition checks

 rest/oauth-proxy.c |   49 ++++++++++++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 15 deletions(-)
---
diff --git a/rest/oauth-proxy.c b/rest/oauth-proxy.c
index f8c0053..8877014 100644
--- a/rest/oauth-proxy.c
+++ b/rest/oauth-proxy.c
@@ -282,8 +282,8 @@ oauth_proxy_new_with_token (const char *consumer_key,
 /**
  * oauth_proxy_request_token:
  * @proxy: an #OAuthProxy
- * @function: the function name to invoke
- * @callback_uri: the callback URI
+ * @function: (nullable): the function name to invoke
+ * @callback_uri: (nullable): the callback URI
  * @error: a #GError, or %NULL
  *
  * Perform the Request Token phase of OAuth, invoking @function (defaulting to
@@ -304,6 +304,8 @@ oauth_proxy_request_token (OAuthProxy *proxy,
 {
   RestProxyCall *call;
 
+  g_return_val_if_fail (OAUTH_IS_PROXY (proxy), FALSE);
+
   call = rest_proxy_new_call (REST_PROXY (proxy));
   rest_proxy_call_set_function (call, function ? function : "request_token");
   rest_proxy_call_set_method (call, "POST");
@@ -352,6 +354,7 @@ request_token_cb (GObject      *source_object,
  * @proxy: an #OAuthProxy
  * @function: (nullable): the function name to invoke
  * @callback_uri: (nullable): the callback URI
+ * @cancellable: (nullable): A #GCancellable to cancel the call, or %NULL
  * @callback: (scope async): a #OAuthProxyAuthCallback to invoke on completion
  * @user_data: user data to pass to @callback
  *
@@ -376,6 +379,9 @@ oauth_proxy_request_token_async (OAuthProxy          *proxy,
   RestProxyCall *call;
   GTask *task;
 
+  g_return_if_fail (OAUTH_IS_PROXY (proxy));
+  g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+
   call = rest_proxy_new_call (REST_PROXY (proxy));
   rest_proxy_call_set_function (call, function ? function : "request_token");
   rest_proxy_call_set_method (call, "POST");
@@ -415,8 +421,8 @@ oauth_proxy_request_token_finish (OAuthProxy *proxy,
 /**
  * oauth_proxy_access_token:
  * @proxy: an #OAuthProxy
- * @function: the function name to invoke
- * @verifier: the verifier
+ * @function: (nullable): the function name to invoke
+ * @verifier: (nullable):  the verifier
  * @error: a #GError, or %NULL
  *
  * Perform the Access Token phase of OAuth, invoking @function (defaulting to
@@ -437,6 +443,8 @@ oauth_proxy_access_token (OAuthProxy *proxy,
 {
   RestProxyCall *call;
 
+  g_return_val_if_fail (OAUTH_IS_PROXY (proxy), FALSE);
+
   call = rest_proxy_new_call (REST_PROXY (proxy));
   rest_proxy_call_set_function (call, function ? function : "access_token");
   rest_proxy_call_set_method (call, "POST");
@@ -483,8 +491,9 @@ access_token_cb (GObject      *source_object,
 /**
  * oauth_proxy_access_token_async:
  * @proxy: an #OAuthProxy
- * @function: the function name to invoke
- * @verifier: the verifier
+ * @function: (nullable): the function name to invoke
+ * @verifier: (nullable): the verifier
+ * @cancellable: A #GCancellable or %NULL
  * @callback: (scope async): a #OAuthProxyAuthCallback to invoke on completion
  * @user_data: user data to pass to @callback
  *
@@ -510,6 +519,9 @@ oauth_proxy_access_token_async (OAuthProxy          *proxy,
   RestProxyCall *call;
   GTask *task;
 
+  g_return_if_fail (OAUTH_IS_PROXY (proxy));
+  g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+
   call = rest_proxy_new_call (REST_PROXY (proxy));
   rest_proxy_call_set_function (call, function ? function : "access_token");
   rest_proxy_call_set_method (call, "POST");
@@ -540,8 +552,9 @@ oauth_proxy_access_token_finish (OAuthProxy *proxy,
  *
  * Get the current request or access token.
  *
- * Returns: the token, or %NULL if there is no token yet.  This string is owned
- * by #OAuthProxy and should not be freed.
+ * Returns: (transfer none) (nullable): the token, or %NULL
+ *   if there is no token yet. This string is owned by #OAuthProxy
+ *   and should not be freed.
  */
 const char *
 oauth_proxy_get_token (OAuthProxy *proxy)
@@ -563,6 +576,8 @@ oauth_proxy_set_token (OAuthProxy *proxy, const char *token)
   OAuthProxyPrivate *priv;
 
   g_return_if_fail (OAUTH_IS_PROXY (proxy));
+  g_return_if_fail (token != NULL);
+
   priv = PROXY_GET_PRIVATE (proxy);
 
   g_free (priv->token);
@@ -575,8 +590,9 @@ oauth_proxy_set_token (OAuthProxy *proxy, const char *token)
  *
  * Get the current request or access token secret.
  *
- * Returns: the token secret, or %NULL if there is no token secret yet.  This
- * string is owned by #OAuthProxy and should not be freed.
+ * Returns: (transfer none) (nullable): the token secret,
+ *   or %NULL if there is no token secret yet.
+ *   This stringis owned by #OAuthProxy and should not be freed.
  */
 const char *
 oauth_proxy_get_token_secret (OAuthProxy *proxy)
@@ -598,11 +614,11 @@ oauth_proxy_set_token_secret (OAuthProxy *proxy, const char *token_secret)
   OAuthProxyPrivate *priv;
 
   g_return_if_fail (OAUTH_IS_PROXY (proxy));
-  priv = PROXY_GET_PRIVATE (proxy);
+  g_return_if_fail (token_secret != NULL);
 
-  if (priv->token_secret)
-    g_free (priv->token_secret);
+  priv = PROXY_GET_PRIVATE (proxy);
 
+  g_free (priv->token_secret);
   priv->token_secret = g_strdup (token_secret);
 }
 
@@ -630,8 +646,9 @@ oauth_proxy_is_oauth10a (OAuthProxy *proxy)
  *
  * Get the signature hostname used when creating a signature base string.
  *
- * Returns: the signature hostname, or %NULL if there is none set.
- *  This string is owned by #OAuthProxy and should not be freed.
+ * Returns: (transfer none) (nullable): the signature hostname,
+ *   or %NULL if there is none set. This string is owned by
+ *   #OAuthProxy and should not be freed.
  */
 const char *
 oauth_proxy_get_signature_host (OAuthProxy *proxy)
@@ -658,6 +675,8 @@ oauth_proxy_set_signature_host (OAuthProxy *proxy,
   OAuthProxyPrivate *priv;
 
   g_return_if_fail (OAUTH_IS_PROXY (proxy));
+  g_return_if_fail (signature_host != NULL);
+
   priv = PROXY_GET_PRIVATE (proxy);
 
   g_free (priv->signature_host);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]