docs: added documentation for errors
authorAlexander Kanavin <alexander.kanavin@intel.com>
Fri, 28 Jun 2013 13:54:45 +0000 (16:54 +0300)
committerAlexander Kanavin <alexander.kanavin@intel.com>
Fri, 16 Aug 2013 14:28:20 +0000 (17:28 +0300)
include/gsignond/gsignond-error.h
include/gsignond/gsignond-log.h
src/common/gsignond-error.c

index aa94b29..41f0f61 100644 (file)
 
 G_BEGIN_DECLS
 
-#define GSIGNOND_ERROR_DOMAIN "gsignond"
-
-/**
- * GSIGNOND_ERROR:
- *
- */
 #define GSIGNOND_ERROR   (gsignond_error_quark())
 
 typedef enum {
     GSIGNOND_ERROR_NONE,
 
-    GSIGNOND_ERROR_UNKNOWN = 1,                /**< Catch-all for errors not distinguished by another code. */
-    GSIGNOND_ERROR_INTERNAL_SERVER = 2,        /**< Signon Daemon internal error. */
-    GSIGNOND_ERROR_INTERNAL_COMMUNICATION = 3, /**< Communication with Signon Daemon error. */
-    GSIGNOND_ERROR_PERMISSION_DENIED = 4,      /**< The operation cannot be performed due to insufficient client permissions. */
-    GSIGNOND_ERROR_ENCRYPTION_FAILURE,         /**< Failure during data encryption/decryption. */
+    GSIGNOND_ERROR_UNKNOWN = 1,
+    GSIGNOND_ERROR_INTERNAL_SERVER = 2,
+    GSIGNOND_ERROR_INTERNAL_COMMUNICATION = 3,
+    GSIGNOND_ERROR_PERMISSION_DENIED = 4,
+    GSIGNOND_ERROR_ENCRYPTION_FAILURE,
 
     GSIGNOND_ERROR_AUTH_SERVICE_ERR = 100,      /* Placeholder to rearrange enumeration - AuthService specific */
-    GSIGNOND_ERROR_METHOD_NOT_KNOWN,            /**< The method with this name is not found. */
-    GSIGNOND_ERROR_SERVICE_NOT_AVAILABLE,       /**< The service is temporarily unavailable. */
-    GSIGNOND_ERROR_INVALID_QUERY,               /**< Parameters for the query are invalid. */
+    GSIGNOND_ERROR_METHOD_NOT_KNOWN,
+    GSIGNOND_ERROR_SERVICE_NOT_AVAILABLE,
+    GSIGNOND_ERROR_INVALID_QUERY,
 
     GSIGNOND_ERROR_IDENTITY_ERR = 200,          /* Placeholder to rearrange enumeration - Identity specific */
-    GSIGNOND_ERROR_METHOD_NOT_AVAILABLE,        /**< The requested method is not available. */
-    GSIGNOND_ERROR_IDENTITY_NOT_FOUND,          /**< The identity matching this Identity object was not found on the service. */
-    GSIGNOND_ERROR_STORE_FAILED,                /**< Storing credentials failed. */
-    GSIGNOND_ERROR_REMOVE_FAILED,               /**< Removing credentials failed. */
-    GSIGNOND_ERROR_SIGN_OUT_FAILED,             /**< SignOut failed. */
-    GSIGNOND_ERROR_IDENTITY_OPERATION_CANCELED, /**< Identity operation was canceled by user. */
-    GSIGNOND_ERROR_CREDENTIALS_NOT_AVAILABLE,   /**< Query failed. */
-    GSIGNOND_ERROR_REFERENCE_NOT_FOUND,         /**< Trying to remove nonexistent reference. */
+    GSIGNOND_ERROR_METHOD_NOT_AVAILABLE,
+    GSIGNOND_ERROR_IDENTITY_NOT_FOUND,
+    GSIGNOND_ERROR_STORE_FAILED,
+    GSIGNOND_ERROR_REMOVE_FAILED,
+    GSIGNOND_ERROR_SIGN_OUT_FAILED,
+    GSIGNOND_ERROR_IDENTITY_OPERATION_CANCELED,
+    GSIGNOND_ERROR_CREDENTIALS_NOT_AVAILABLE,
+    GSIGNOND_ERROR_REFERENCE_NOT_FOUND,
 
     GSIGNOND_ERROR_AUTH_SESSION_ERR = 300,     /* Placeholder to rearrange enumeration - AuthSession/PluginInterface specific */
-    GSIGNOND_ERROR_MECHANISM_NOT_AVAILABLE,    /**< The requested mechanism is not available. */
-    GSIGNOND_ERROR_MISSING_DATA,               /**< The SessionData object does not contain necessary information. */
-    GSIGNOND_ERROR_INVALID_CREDENTIALS,        /**< The supplied credentials are invalid for the mechanism implementation. */
-    GSIGNOND_ERROR_NOT_AUTHORIZED,             /**< Authorization failed. */
-    GSIGNOND_ERROR_WRONG_STATE,                /**< An operation method has been called in a wrong state. */
-    GSIGNOND_ERROR_OPERATION_NOT_SUPPORTED,    /**< The operation is not supported by the mechanism implementation. */
-    GSIGNOND_ERROR_NO_CONNECTION,              /**< No Network connetion. */
-    GSIGNOND_ERROR_NETWORK,                    /**< Network connetion failed. */
-    GSIGNOND_ERROR_SSL,                        /**< Ssl connection failed. */
-    GSIGNOND_ERROR_RUNTIME,                    /**< Casting SessionData into subclass failed */
-    GSIGNOND_ERROR_SESSION_CANCELED,           /**< Challenge was cancelled. */
-    GSIGNOND_ERROR_TIMED_OUT,                  /**< Challenge was timed out. */
-    GSIGNOND_ERROR_USER_INTERACTION,           /**< User interaction dialog failed */
-    GSIGNOND_ERROR_OPERATION_FAILED,           /**< Temporary failure in authentication. */
-    GSIGNOND_ERROR_ENCRYPTION_FAILED,          /**< @deprecated Failure during data encryption/decryption. */
-    GSIGNOND_ERROR_TOS_NOT_ACCEPTED,           /**< User declined Terms of Service. */
-    GSIGNOND_ERROR_FORGOT_PASSWORD,            /**< User requested reset password sequence. */
-    GSIGNOND_ERROR_METHOD_OR_MECHANISM_NOT_ALLOWED, /**< Method or mechanism not allowed for this identity. */
-    GSIGNOND_ERROR_INCORRECT_DATE,             /**< Date time incorrect on device. */
-
-    GSIGNOND_ERROR_USER_ERR = 400              /* Placeholder to rearrange enumeration - User space specific */
+    GSIGNOND_ERROR_MECHANISM_NOT_AVAILABLE,
+    GSIGNOND_ERROR_MISSING_DATA,
+    GSIGNOND_ERROR_INVALID_CREDENTIALS,
+    GSIGNOND_ERROR_NOT_AUTHORIZED,
+    GSIGNOND_ERROR_WRONG_STATE,
+    GSIGNOND_ERROR_OPERATION_NOT_SUPPORTED,
+    GSIGNOND_ERROR_NO_CONNECTION,
+    GSIGNOND_ERROR_NETWORK,
+    GSIGNOND_ERROR_SSL,
+    GSIGNOND_ERROR_RUNTIME,
+    GSIGNOND_ERROR_SESSION_CANCELED,
+    GSIGNOND_ERROR_TIMED_OUT,
+    GSIGNOND_ERROR_USER_INTERACTION,
+    GSIGNOND_ERROR_OPERATION_FAILED,
+    GSIGNOND_ERROR_ENCRYPTION_FAILED,
+    GSIGNOND_ERROR_TOS_NOT_ACCEPTED,
+    GSIGNOND_ERROR_FORGOT_PASSWORD,
+    GSIGNOND_ERROR_METHOD_OR_MECHANISM_NOT_ALLOWED,
+    GSIGNOND_ERROR_INCORRECT_DATE,
+
+    GSIGNOND_ERROR_USER_ERR = 400
    
 } GSignondError;
 
-#define gsignond_gerr(error, handler) \
-    G_STMT_START {                 \
-        GString* msg = gsignond_prepend_domain_to_error_msg(error); \
-        handler(msg->str); \
-        g_string_free(msg, TRUE); \
-    } G_STMT_END\
-
-#define gsignond_error_gerr(err)       gsignond_gerr(err, g_error)
-
-#define gsignond_critical_gerr(err)    gsignond_gerr(err, g_critical)
-
-#define gsignond_warning_gerr(err)     gsignond_gerr(err, g_warning)
-
-#define gsignond_message_gerr(err)     gsignond_gerr(err, g_message)
-
-#define gsignond_debug_gerr(err)       gsignond_gerr(err, g_debug)
-
 GQuark
 gsignond_error_quark (void);
 
-GString*
-gsignond_concat_domain_and_error (
-        const gchar *str1,
-        const gchar *str2);
-
-GString*
-gsignond_prepend_domain_to_error_msg (
-        const GError *err);
-
 GError *
 gsignond_error_new_from_variant (
         GVariant *var);
index 2f66f92..65af19f 100644 (file)
 /**
  * SECTION:gsignond-log
  * @short_description: logging facilities
+ * @title: Logging
  * @include: gsignond/gsignond-log.h
  *
  * <filename>gsignond/gsignond-log.h</filename> file contains logging macros 
  * that plugins and extensions should use for debugging and tracing.
  * 
+ * For example:
  * |[    INFO("Plugin %s initialized", plugin_mechanism); ]|
  */
 
index 462b43c..fe5c45a 100644 (file)
 #include <string.h>
 #include <gio/gio.h>
 
+/**
+ * SECTION:gsignond-error
+ * @short_description: error definitions and utilities
+ * @title: Errors
+ * @include: gsignond/gsignond-error.h
+ *
+ * This file provides GSignond error definitions and utilities.
+ * When creating an error, use #GSIGNOND_ERROR for the error domain and errors 
+ * from #GSignondError for the error code.
+ * 
+ * |[    GError* err = g_error_new(GSIGNOND_ERROR, GSIGNOND_ERROR_MISSING_DATA,
+ *     "Not enough data");
+ * ]| 
+ */
+
+/**
+ * GSIGNOND_ERROR:
+ *
+ * This macro should be used when creating a #GError in GSignond plugins and extensions.
+ * (for example with g_error_new() )
+ */
+
+/**
+ * GSignondError:
+ * @GSIGNOND_ERROR_NONE: No error
+ * @GSIGNOND_ERROR_UNKNOWN: Catch-all for errors not distinguished by another code.
+ * @GSIGNOND_ERROR_INTERNAL_SERVER: Signon Daemon internal error. 
+ * @GSIGNOND_ERROR_INTERNAL_COMMUNICATION: Communication with Signon Daemon error. 
+ * @GSIGNOND_ERROR_PERMISSION_DENIED: The operation cannot be performed due to insufficient client permissions. 
+ * @GSIGNOND_ERROR_ENCRYPTION_FAILURE: Failure during data encryption/decryption. 
+ * @GSIGNOND_ERROR_AUTH_SERVICE_ERR: Placeholder to rearrange enumeration - AuthService specific 
+ * @GSIGNOND_ERROR_METHOD_NOT_KNOWN: The method with this name is not found.
+ * @GSIGNOND_ERROR_SERVICE_NOT_AVAILABLE: The service is temporarily unavailable. 
+ * @GSIGNOND_ERROR_INVALID_QUERY: Parameters for the query are invalid. 
+ * @GSIGNOND_ERROR_IDENTITY_ERR: Placeholder to rearrange enumeration - Identity specific 
+ * @GSIGNOND_ERROR_METHOD_NOT_AVAILABLE: The requested method is not available. 
+ * @GSIGNOND_ERROR_IDENTITY_NOT_FOUND: The identity matching this Identity object was not found on the service. 
+ * @GSIGNOND_ERROR_STORE_FAILED: Storing credentials failed. 
+ * @GSIGNOND_ERROR_REMOVE_FAILED: Removing credentials failed. 
+ * @GSIGNOND_ERROR_SIGN_OUT_FAILED: SignOut failed. 
+ * @GSIGNOND_ERROR_IDENTITY_OPERATION_CANCELED: Identity operation was canceled by user. 
+ * @GSIGNOND_ERROR_CREDENTIALS_NOT_AVAILABLE: Query failed. 
+ * @GSIGNOND_ERROR_REFERENCE_NOT_FOUND: Trying to remove nonexistent reference. 
+ * @GSIGNOND_ERROR_AUTH_SESSION_ERR: Placeholder to rearrange enumeration - AuthSession/PluginInterface specific 
+ * @GSIGNOND_ERROR_MECHANISM_NOT_AVAILABLE: The requested mechanism is not available. 
+ * @GSIGNOND_ERROR_MISSING_DATA: The SessionData object does not contain necessary information. 
+ * @GSIGNOND_ERROR_INVALID_CREDENTIALS: The supplied credentials are invalid for the mechanism implementation. 
+ * @GSIGNOND_ERROR_NOT_AUTHORIZED: Authorization failed. 
+ * @GSIGNOND_ERROR_WRONG_STATE: An operation method has been called in a wrong state. 
+ * @GSIGNOND_ERROR_OPERATION_NOT_SUPPORTED: The operation is not supported by the mechanism implementation. 
+ * @GSIGNOND_ERROR_NO_CONNECTION: No Network connetion. 
+ * @GSIGNOND_ERROR_NETWORK: Network connetion failed. 
+ * @GSIGNOND_ERROR_SSL: Ssl connection failed. 
+ * @GSIGNOND_ERROR_RUNTIME: Casting SessionData into subclass failed 
+ * @GSIGNOND_ERROR_SESSION_CANCELED: Challenge was cancelled. 
+ * @GSIGNOND_ERROR_TIMED_OUT: Challenge was timed out. 
+ * @GSIGNOND_ERROR_USER_INTERACTION: User interaction dialog failed 
+ * @GSIGNOND_ERROR_OPERATION_FAILED: Temporary failure in authentication. 
+ * @GSIGNOND_ERROR_ENCRYPTION_FAILED: Failure during data encryption/decryption. 
+ * @GSIGNOND_ERROR_TOS_NOT_ACCEPTED: User declined Terms of Service. 
+ * @GSIGNOND_ERROR_FORGOT_PASSWORD: User requested reset password sequence. 
+ * @GSIGNOND_ERROR_METHOD_OR_MECHANISM_NOT_ALLOWED: Method or mechanism not allowed for this identity. 
+ * @GSIGNOND_ERROR_INCORRECT_DATE: Date time incorrect on device. 
+ * @GSIGNOND_ERROR_USER_ERR: Placeholder to rearrange enumeration - User space specific 
+ * 
+ * This enum provides a list of errors that plugins and extensions can use.
+ * 
+ */
+
+/**
+ * gsignond_get_gerror_for_id:
+ * @err: A #GSignondError specifying the error
+ * @message: Format string for the error message
+ * @...: parameters for the error string
+ * 
+ * A helper macro that creates a #GError with the proper gsignond domain
+ */
+
+#define GSIGNOND_ERROR_DOMAIN "gsignond"
 #define _ERROR_PREFIX "com.google.code.AccountsSSO.gSingleSignOn.Error"
 
 GDBusErrorEntry _gsignond_errors[] = 
@@ -72,6 +151,11 @@ GDBusErrorEntry _gsignond_errors[] =
     {GSIGNOND_ERROR_INCORRECT_DATE, _ERROR_PREFIX".IncorrectDate"},
 } ;
 
+/**
+ * gsignond_error_quark:
+ * 
+ * Creates and returns a domain for GSignond errors.
+ */
 GQuark
 gsignond_error_quark (void)
 {
@@ -85,31 +169,6 @@ gsignond_error_quark (void)
     return (GQuark) quark_volatile;
 }
 
-GString*
-gsignond_concat_domain_and_error (
-        const gchar *str1,
-        const gchar *str2)
-{
-    GString *str = NULL;
-    g_return_val_if_fail (str1 != NULL && str2 != NULL, NULL);
-    str = g_string_sized_new (strlen(str1)+strlen(str2)-1);
-    g_string_printf (str,"[%s].%s\n",str1,str2);
-    return str;
-}
-
-GString*
-gsignond_prepend_domain_to_error_msg (const GError *err)
-{
-    GString *msg = NULL;
-    const gchar *domain = NULL;
-    g_return_val_if_fail (err != NULL, NULL);
-    if (err->message != NULL) {
-        domain = g_quark_to_string(err->domain);
-        msg = gsignond_concat_domain_and_error(domain, err->message);
-    }
-    return msg;
-}
-
 /**
  * gsignond_error_new_from_variant:
  * @var: instance of #GVariant