From: <svn...@op...> - 2009-07-07 15:04:53
|
Author: bellmich Date: Tue Jul 7 16:59:09 2009 New Revision: 1155 URL: http://libsyncml.opensync.org/changeset/1155 Log: migrated objects/sml_auth from SmlError to GError Modified: trunk/libsyncml/objects/sml_auth.c trunk/libsyncml/objects/sml_auth.h trunk/libsyncml/objects/sml_auth_internals.h Modified: trunk/libsyncml/objects/sml_auth.c ============================================================================== --- trunk/libsyncml/objects/sml_auth.c Tue Jul 7 16:47:34 2009 (r1154) +++ trunk/libsyncml/objects/sml_auth.c Tue Jul 7 16:59:09 2009 (r1155) @@ -29,11 +29,7 @@ #include <libsyncml/sml_command_internals.h> #include "libsyncml/sml_error_internals.h" -static SmlStatus *_smlAuthHeaderReply( - SmlSession *session, - SmlErrorType code, - SmlAuthType auth, - SmlError **error); +static SmlStatus* _smlAuthHeaderReply(SmlSession *session, SmlErrorType code, SmlAuthType auth, GError **error); void _status_callback(SmlSession *session, SmlStatus *status, void *userdata) { @@ -49,7 +45,7 @@ smlAssert(userdata); SmlStatus *reply = NULL; SmlAuthenticator *auth = userdata; - SmlError *error = NULL; + GError *error = NULL; if (session->sessionType == SML_SESSION_TYPE_CLIENT) { /* If this is an OMA DS client then there will be no @@ -112,11 +108,12 @@ { auth->state = SML_AUTH_ACCEPTED; } else { - smlErrorSet(&error, SML_ERROR_AUTH_REJECTED, + g_set_error(&error, SML_ERROR, SML_ERROR_AUTH_REJECTED, "Auth rejected for username %s", sml_location_get_name(session->source)); smlSessionDispatchEvent(session, SML_SESSION_EVENT_ERROR, NULL, NULL, NULL, error); - smlErrorDeref(&error); + g_error_free(error); + error = NULL; auth->state = SML_ERROR_AUTH_REJECTED; } } else { @@ -156,17 +153,17 @@ return; error: smlSessionDispatchEvent(session, SML_SESSION_EVENT_ERROR, NULL, NULL, NULL, error); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(&error)); - smlErrorDeref(&error); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, error->message); + g_error_free(error); return; } -char *smlAuthGetCredString( - SmlAuthType type, - const char *username, - const char *password, - const char *b64_nonce, - SmlError **error) +gchar* +smlAuthGetCredString (SmlAuthType type, + const gchar *username, + const gchar *password, + const gchar *b64_nonce, + GError **error) { smlTrace(TRACE_ENTRY, "%s", __func__); CHECK_ERROR_REF @@ -179,7 +176,7 @@ char *plain = g_strjoin(":", username, password, NULL); cred = g_base64_encode((unsigned char *) plain, strlen(plain)); if (!cred) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The syncml:auth-basic credential cannot be base64 encoded."); smlSafeCFree(&plain); goto error; @@ -212,7 +209,7 @@ smlSafeCFree(&auth); cred = g_base64_encode(digest, 16); if (!cred) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The username:password part of the syncml:auth-md5 "\ "credential cannot be base64 encoded."); goto error; @@ -223,7 +220,7 @@ smlSafeCFree(&auth); cred = g_base64_encode(digest, 16); if (!cred) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The complete syncml:auth-md5 credential cannot be base64 encoded."); goto error; } @@ -231,7 +228,7 @@ break; default: smlTrace(TRACE_ERROR, "%s - unknown authentication type", __func__); - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown auth format"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown auth format"); goto error; } @@ -240,12 +237,18 @@ error: smlTrace(TRACE_EXIT_ERROR, "%s - cannot create credential string"); if (*error == NULL) - smlErrorSet(error, SML_ERROR_GENERIC, "Cannot create credential string for user %s.", - username); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Cannot create credential string for user %s.", + username); return NULL; } -SmlBool smlAuthVerify(SmlChal *chal, SmlCred *cred, const char *username, const char *password, SmlError **error) +gboolean +smlAuthVerify (SmlChal *chal, + SmlCred *cred, + const gchar *username, + const gchar *password, + GError **error) { smlTrace(TRACE_ENTRY, "%s", __func__); CHECK_ERROR_REF @@ -272,7 +275,7 @@ smlTrace(TRACE_INTERNAL, "%s - replace syncml:auth-basic by syncml:auth-md5", __func__); } else { /* This is a security event. */ - smlErrorSet(error, SML_ERROR_AUTH_REJECTED, + g_set_error(error, SML_ERROR, SML_ERROR_AUTH_REJECTED, "The type of the authentication was changed to a lower security level."); goto error; } @@ -300,7 +303,7 @@ break; default: smlTrace(TRACE_ERROR, "%s - unknown authentication type", __func__); - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown auth format"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown auth format"); goto error; } smlTrace(TRACE_INTERNAL, "%s - credential string calculated", __func__); @@ -319,12 +322,14 @@ error: smlTrace(TRACE_EXIT_ERROR, "%s - auth rejected"); if (*error == NULL) - smlErrorSet(error, SML_ERROR_AUTH_REJECTED, "Authentication rejected for username %s.", - username); + g_set_error(error, SML_ERROR, SML_ERROR_AUTH_REJECTED, + "Authentication rejected for username %s.", + username); return FALSE; } -SmlAuthenticator *smlAuthNew(SmlError **error) +SmlAuthenticator* +smlAuthNew (GError **error) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, error); CHECK_ERROR_REF @@ -337,14 +342,14 @@ smlTrace(TRACE_EXIT, "%s: %p", __func__, auth); return auth; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } -void smlAuthFree(SmlAuthenticator *auth) +void +smlAuthFree (SmlAuthenticator *auth) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, auth); smlAssert(auth); @@ -354,7 +359,10 @@ smlTrace(TRACE_EXIT, "%s", __func__); } -SmlBool smlAuthRegister(SmlAuthenticator *auth, SmlManager *manager, SmlError **error) +gboolean +smlAuthRegister (SmlAuthenticator *auth, + SmlManager *manager, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, auth, manager, error); CHECK_ERROR_REF @@ -367,7 +375,9 @@ return TRUE; } -void smlAuthSetState(SmlAuthenticator *auth, SmlErrorType type) +void +smlAuthSetState (SmlAuthenticator *auth, + SmlErrorType type) { smlTrace(TRACE_ENTRY, "%s(%p, %i)", __func__, auth, type); smlAssert(auth); @@ -377,21 +387,11 @@ smlTrace(TRACE_EXIT, "%s", __func__); } -/* FIXME: DEPRECATED*/ -SmlStatus *smlAuthHeaderReply( - SmlSession *session, - SmlAuthType code, - SmlError **error) { - CHECK_ERROR_REF - g_warning("SmlAuthType of smlAuthHeaderReply is used as SmlErrorType."); - return _smlAuthHeaderReply(session, (SmlErrorType) code, SML_AUTH_TYPE_BASIC, error); -} - -static SmlStatus *_smlAuthHeaderReply( - SmlSession *session, - SmlErrorType code, - SmlAuthType auth, - SmlError **error) +static SmlStatus* +_smlAuthHeaderReply (SmlSession *session, + SmlErrorType code, + SmlAuthType auth, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %i, %i, %p)", __func__, session, code, auth, error); CHECK_ERROR_REF @@ -410,18 +410,17 @@ code == SML_ERROR_AUTH_REQUIRED) { reply->chal = smlChalNew(auth, error); if (!reply->chal) - goto error_free_reply; + goto error; session->chal = reply->chal; smlChalRef(session->chal); } smlTrace(TRACE_EXIT, "%s: %p", __func__, reply); return reply; - -error_free_reply: - smlStatusUnref(reply); error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + if (reply) + smlStatusUnref(reply); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } @@ -434,7 +433,7 @@ smlTrace(TRACE_EXIT, "%s", __func__); } -void smlAuthSetEnable(SmlAuthenticator *auth, SmlBool enabled) +void smlAuthSetEnable(SmlAuthenticator *auth, gboolean enabled) { smlTrace(TRACE_ENTRY, "%s(%p, %i)", __func__, auth, enabled); smlAssert(auth); @@ -444,7 +443,7 @@ smlTrace(TRACE_EXIT, "%s", __func__); } -SmlBool smlAuthIsEnabled(SmlAuthenticator *auth) +gboolean smlAuthIsEnabled(SmlAuthenticator *auth) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, auth); smlAssert(auth); Modified: trunk/libsyncml/objects/sml_auth.h ============================================================================== --- trunk/libsyncml/objects/sml_auth.h Tue Jul 7 16:47:34 2009 (r1154) +++ trunk/libsyncml/objects/sml_auth.h Tue Jul 7 16:59:09 2009 (r1155) @@ -31,24 +31,21 @@ #define _SML_AUTH_H_ typedef struct SmlAuthenticator SmlAuthenticator; -typedef SmlBool (* SmlAuthVerifyCb)(SmlChal *chal, SmlCred *cred, const gchar *username, void *userdata, GError **error); +typedef gboolean (* SmlAuthVerifyCb)(SmlChal *chal, SmlCred *cred, const gchar *username, void *userdata, GError **error); -SmlAuthenticator *smlAuthNew(GError **error); -void smlAuthFree(SmlAuthenticator *auth); -SmlBool smlAuthRegister(SmlAuthenticator *auth, SmlManager *manager, GError **error); -void smlAuthSetState(SmlAuthenticator *auth, SmlErrorType type); -void smlAuthSetVerifyCallback(SmlAuthenticator *auth, SmlAuthVerifyCb callback, void *userdata); -void smlAuthSetEnable(SmlAuthenticator *auth, SmlBool enabled); -SmlBool smlAuthIsEnabled(SmlAuthenticator *auth); +SmlAuthenticator* smlAuthNew (GError **error); +void smlAuthFree (SmlAuthenticator *auth); +gboolean smlAuthRegister (SmlAuthenticator *auth, SmlManager *manager, GError **error); +void smlAuthSetState (SmlAuthenticator *auth, SmlErrorType type); +void smlAuthSetVerifyCallback (SmlAuthenticator *auth, SmlAuthVerifyCb callback, void *userdata); +void smlAuthSetEnable (SmlAuthenticator *auth, gboolean enabled); +gboolean smlAuthIsEnabled (SmlAuthenticator *auth); /* This can be used from within the SmlAuthVerifyCb to do the authentication itself. */ -SmlBool smlAuthVerify(SmlChal *chal, SmlCred *cred, const gchar *username, const gchar *password, GError **error); +gboolean smlAuthVerify (SmlChal *chal, SmlCred *cred, const gchar *username, const gchar *password, GError **error); /* set required authentication type if this is a server */ void smlAuthSetType(SmlAuthenticator *auth, SmlAuthType code); -/* expire date: 20090813 */ -SmlStatus *smlAuthHeaderReply(SmlSession *session, SmlAuthType code, SmlError **error) LIBSYNCML_DEPRECATED; - #endif //_SML_AUTH_H_ /*@}*/ Modified: trunk/libsyncml/objects/sml_auth_internals.h ============================================================================== --- trunk/libsyncml/objects/sml_auth_internals.h Tue Jul 7 16:47:34 2009 (r1154) +++ trunk/libsyncml/objects/sml_auth_internals.h Tue Jul 7 16:59:09 2009 (r1155) @@ -36,11 +36,11 @@ SmlErrorType state; SmlAuthVerifyCb verifyCallback; void *verifyCallbackUserdata; - SmlBool enabled; + gboolean enabled; SmlAuthType type; }; -char *smlAuthGetCredString( +gchar *smlAuthGetCredString( SmlAuthType type, const gchar *username, const gchar *password, |