From: <svn...@op...> - 2009-07-17 19:01:15
|
Author: bellmich Date: Fri Jul 17 21:01:06 2009 New Revision: 1220 URL: http://libsyncml.opensync.org/changeset/1220 Log: cleaned up header file usage in objects/sml_auth.c Modified: trunk/libsyncml/objects/sml_auth.c trunk/libsyncml/sml_command.c trunk/libsyncml/sml_command.h trunk/libsyncml/sml_session.c trunk/libsyncml/sml_session.h Modified: trunk/libsyncml/objects/sml_auth.c ============================================================================== --- trunk/libsyncml/objects/sml_auth.c Fri Jul 17 18:34:20 2009 (r1219) +++ trunk/libsyncml/objects/sml_auth.c Fri Jul 17 21:01:06 2009 (r1220) @@ -20,11 +20,14 @@ */ #include "sml_auth_internals.h" + #include <libsyncml/sml_support.h> -#include <libsyncml/sml_session_internals.h> -#include <libsyncml/sml_elements_internals.h> -#include <libsyncml/sml_command_internals.h> #include "libsyncml/sml_error_internals.h" + +#include <libsyncml/sml_session.h> +#include <libsyncml/sml_elements.h> +#include <libsyncml/sml_command.h> + #include <string.h> static SmlStatus* _smlAuthHeaderReply(SmlSession *session, SmlErrorType code, SmlAuthType auth, GError **error); @@ -45,7 +48,7 @@ SmlAuthenticator *auth = userdata; GError *error = NULL; - if (session->sessionType == SML_SESSION_TYPE_CLIENT) { + if (smlSessionGetType(session) == SML_SESSION_TYPE_CLIENT) { /* If this is an OMA DS client then there will be no * authentication. Only OMA DS servers can request an * authentication from the remote peer. @@ -75,7 +78,7 @@ */ smlTrace(TRACE_INTERNAL, "%s: Auth is required", __func__); auth->state = SML_ERROR_AUTH_REQUIRED; - session->authenticate = TRUE; + smlSessionSetAuthenticate(session, TRUE); } else { @@ -86,7 +89,7 @@ } } else { /* cred available */ - smlTrace(TRACE_INTERNAL, "%s: Cred is \"%s\"", __func__, VA_STRING(cred->data)); + smlTrace(TRACE_INTERNAL, "%s: Cred is \"%s\"", __func__, VA_STRING(smlCredGetData(cred))); if (!auth->enabled) { smlTrace(TRACE_INTERNAL, "%s: Cred received but unwanted", __func__); @@ -100,15 +103,15 @@ * Cred * LocName(username) */ - if (auth->verifyCallback(session->chal, cred, - sml_location_get_name(session->source), + if (auth->verifyCallback(smlSessionGetChal(session), cred, + sml_location_get_name(smlSessionGetSource(session)), auth->verifyCallbackUserdata, &error)) { auth->state = SML_AUTH_ACCEPTED; } else { g_set_error(&error, SML_ERROR, SML_ERROR_AUTH_REJECTED, "Auth rejected for username %s", - sml_location_get_name(session->source)); + sml_location_get_name(smlSessionGetSource(session))); smlSessionDispatchEvent(session, SML_SESSION_EVENT_ERROR, NULL, NULL, NULL, error); g_error_free(error); error = NULL; @@ -123,7 +126,7 @@ if (auth->state == SML_ERROR_AUTH_REJECTED) { smlTrace(TRACE_INTERNAL, "%s: Ending session due to wrong / missing creds", __func__); - session->end = TRUE; + smlSessionSetEnd(session, TRUE); } reply = _smlAuthHeaderReply(session, auth->state, auth->type, &error); @@ -137,11 +140,12 @@ smlStatusUnref(reply); - if (!session->established && !session->end && - !session->authenticate && - session->sessionType == SML_SESSION_TYPE_SERVER) + if (!smlSessionGetEstablished(session) && + !smlSessionGetEnd(session) && + !smlSessionGetAuthenticate(session) && + smlSessionGetType(session) == SML_SESSION_TYPE_SERVER) { - session->established = TRUE; + smlSessionSetEstablished(session, TRUE); smlSessionDispatchEvent( session, SML_SESSION_EVENT_ESTABLISHED, NULL, NULL, NULL, NULL); @@ -262,10 +266,10 @@ * SECURITY NOTE: against replay attacks. * */ - if (chal && chal->type != cred->type) + if (chal && smlChalGetType(chal) != smlCredGetType(cred)) { - if (chal->type == SML_AUTH_TYPE_BASIC && - cred->type == SML_AUTH_TYPE_MD5) + if (smlChalGetType(chal) == SML_AUTH_TYPE_BASIC && + smlCredGetType(cred) == SML_AUTH_TYPE_MD5) { /* This is an upgrade to more security. * So it is acceptable. @@ -281,7 +285,7 @@ smlTrace(TRACE_INTERNAL, "%s - authentication security policy ok", __func__); char *wanted = NULL; - switch (cred->type) { + switch (smlCredGetType(cred)) { case SML_AUTH_TYPE_BASIC: smlTrace(TRACE_INTERNAL, "%s - SML_AUTH_TYPE_BASIC", __func__); wanted = smlAuthGetCredString(SML_AUTH_TYPE_BASIC, username, password, NULL, error); @@ -292,7 +296,7 @@ wanted = smlAuthGetCredString( SML_AUTH_TYPE_MD5, username, password, - chal->nonce_b64, error); + smlChalGetNonce(chal), error); else wanted = smlAuthGetCredString( SML_AUTH_TYPE_MD5, @@ -307,7 +311,7 @@ smlTrace(TRACE_INTERNAL, "%s - credential string calculated", __func__); /* compare the authentication string */ - if (strcmp(wanted, cred->data)) + if (strcmp(wanted, smlCredGetData(cred))) { smlTrace(TRACE_INTERNAL, "%s - credentials mismatch", __func__); smlSafeCFree(&wanted); @@ -399,18 +403,22 @@ // of the remote peer // we have to revert source and target smlTrace(TRACE_INTERNAL, "%s: SourceRef: %s --> TargetRef: %s", - __func__, VA_STRING(sml_location_get_uri(session->target)), VA_STRING(sml_location_get_uri(session->source))); - SmlStatus *reply = smlStatusNew(code, 0, session->lastReceivedMessageID, session->target, session->source, SML_COMMAND_TYPE_HEADER, error); + __func__, + VA_STRING(sml_location_get_uri(smlSessionGetTarget(session))), + VA_STRING(sml_location_get_uri(smlSessionGetSource(session)))); + SmlStatus *reply = smlStatusNew(code, 0, smlSessionGetLastRecvMsgID(session), smlSessionGetTarget(session), smlSessionGetSource(session), SML_COMMAND_TYPE_HEADER, error); if (!reply) goto error; if (code == SML_ERROR_AUTH_REJECTED || code == SML_ERROR_AUTH_REQUIRED) { - reply->chal = smlChalNew(auth, error); - if (!reply->chal) + SmlChal *chal = smlChalNew(auth, error); + if (!chal) goto error; - session->chal = reply->chal; - smlChalRef(session->chal); + smlStatusSetChal(reply, chal); + smlSessionSetChal(session, chal); + smlChalUnref(chal); + chal = NULL; } smlTrace(TRACE_EXIT, "%s: %p", __func__, reply); Modified: trunk/libsyncml/sml_command.c ============================================================================== --- trunk/libsyncml/sml_command.c Fri Jul 17 18:34:20 2009 (r1219) +++ trunk/libsyncml/sml_command.c Fri Jul 17 21:01:06 2009 (r1220) @@ -222,6 +222,16 @@ return status->chal; } +void +smlStatusSetChal (SmlStatus *status, + SmlChal *chal) +{ + if (status->chal) + smlChalUnref(status->chal); + status->chal = chal; + smlChalRef(chal); +} + gsize smlStatusGetCommandRef (SmlStatus *status) { Modified: trunk/libsyncml/sml_command.h ============================================================================== --- trunk/libsyncml/sml_command.h Fri Jul 17 18:34:20 2009 (r1219) +++ trunk/libsyncml/sml_command.h Fri Jul 17 21:01:06 2009 (r1220) @@ -47,6 +47,7 @@ SmlCommandType smlStatusGetType (SmlStatus *status); SmlAnchor* smlStatusGetAnchor (SmlStatus *status); SmlChal* smlStatusGetChal (SmlStatus *status); +void smlStatusSetChal (SmlStatus *status, SmlChal *chal); gsize smlStatusGetCommandRef (SmlStatus *status); gsize smlStatusGetMessageRef (SmlStatus *status); const gchar* smlStatusGetData (SmlStatus *status); @@ -90,9 +91,9 @@ G_CONST_RETURN gchar *smlCommandTypeToString(SmlCommandType type, GError **error); -void smlCommandDisableChanges (SmlCommand *cmd); -void smlCommandEnableChanges (SmlCommand *cmd); -gsize smlCommandGetNumChanges (SmlCommand *cmd); +void smlCommandDisableChanges (SmlCommand *cmd); +void smlCommandEnableChanges (SmlCommand *cmd); +gsize smlCommandGetNumChanges (SmlCommand *cmd); SmlStatus* smlCommandResultsGetStatus (SmlCommand *cmd); void smlCommandTransferItems (SmlCommand *source, SmlCommand *target, gsize start); Modified: trunk/libsyncml/sml_session.c ============================================================================== --- trunk/libsyncml/sml_session.c Fri Jul 17 18:34:20 2009 (r1219) +++ trunk/libsyncml/sml_session.c Fri Jul 17 21:01:06 2009 (r1220) @@ -1820,6 +1820,48 @@ smlCredRef(session->cred); } +SmlChal* +smlSessionGetChal (SmlSession *session) +{ + return session->chal; +} + +void +smlSessionSetChal (SmlSession *session, + SmlChal *chal) +{ + if (session->chal) + smlChalUnref(session->chal); + session->chal = chal; + smlChalRef(chal); +} + +gboolean +smlSessionGetEnd (SmlSession *session) +{ + return session->end; +} + +void +smlSessionSetEnd (SmlSession *session, + gboolean end) +{ + session->end = end; +} + +gboolean +smlSessionGetAuthenticate (SmlSession *session) +{ + return session->authenticate; +} + +void +smlSessionSetAuthenticate (SmlSession *session, + gboolean authenticate) +{ + session->authenticate = authenticate; +} + /*@}*/ /** @@ -2577,6 +2619,12 @@ return FALSE; } +gsize +smlSessionGetLastRecvMsgID (SmlSession *session) +{ + return session->lastReceivedMessageID; +} + /*@}*/ /*@}*/ Modified: trunk/libsyncml/sml_session.h ============================================================================== --- trunk/libsyncml/sml_session.h Fri Jul 17 18:34:20 2009 (r1219) +++ trunk/libsyncml/sml_session.h Fri Jul 17 21:01:06 2009 (r1220) @@ -84,7 +84,13 @@ /* This function MUST NOT be used for servers. * This function is only used to set the credentials for a client. */ -void smlSessionRegisterCred (SmlSession *session, SmlCred *cred); +void smlSessionRegisterCred (SmlSession *session, SmlCred *cred); +SmlChal* smlSessionGetChal (SmlSession *session); +void smlSessionSetChal (SmlSession *session, SmlChal *chal); +gboolean smlSessionGetEnd (SmlSession *session); +void smlSessionSetEnd (SmlSession *session, gboolean end); +gboolean smlSessionGetAuthenticate (SmlSession *session); +void smlSessionSetAuthenticate (SmlSession *session, gboolean authenticate); /* Session Data input */ gboolean smlSessionReceiveHeader (SmlSession *session, SmlHeader *header, GError **error); @@ -106,4 +112,6 @@ void smlSessionRestoreTargetURI (SmlSession *session); gboolean smlSessionSetResponseURI (SmlSession *session, const gchar *responseURI, GError **error); +gsize smlSessionGetLastRecvMsgID (SmlSession *session); + #endif //_SML_SESSION_H_ |