From: <svn...@op...> - 2009-07-08 09:20:03
|
Author: bellmich Date: Wed Jul 8 11:19:54 2009 New Revision: 1156 URL: http://libsyncml.opensync.org/changeset/1156 Log: migrated objects/sml_devinf_obj from SmlError to GError Modified: trunk/libsyncml/objects/sml_devinf_obj.c trunk/libsyncml/objects/sml_devinf_obj.h trunk/libsyncml/objects/sml_devinf_obj_internals.h Modified: trunk/libsyncml/objects/sml_devinf_obj.c ============================================================================== --- trunk/libsyncml/objects/sml_devinf_obj.c Tue Jul 7 16:59:09 2009 (r1155) +++ trunk/libsyncml/objects/sml_devinf_obj.c Wed Jul 8 11:19:54 2009 (r1156) @@ -48,10 +48,10 @@ /* functions to manage SmlDevInfAgentSession */ -static SmlDevInfAgentSession* _new_session( - SmlDevInfAgent *agent, - SmlSession *session, - SmlError **error) +static SmlDevInfAgentSession* +_new_session (SmlDevInfAgent *agent, + SmlSession *session, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, agent, session, error); @@ -70,13 +70,13 @@ return as; error: smlSafeFree((gpointer *) &as); - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return NULL; } -static SmlDevInfAgentSession* _get_session( - SmlDevInfAgent *agent, - SmlSession *session) +static SmlDevInfAgentSession* +_get_session (SmlDevInfAgent *agent, + SmlSession *session) { smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, agent, session); @@ -89,7 +89,8 @@ return as; } -static void _free_session (gpointer data) +static void +_free_session (gpointer data) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, data); @@ -105,10 +106,13 @@ /* functions to manage SmlDevInfAgent */ -static void _get_devinf_reply(SmlSession *session, SmlStatus *status, void *userdata) +static void +_get_devinf_reply (SmlSession *session, + SmlStatus *status, + void *userdata) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, session, status, userdata); - SmlError *error = NULL; + GError *error = NULL; SmlDevInfAgent *agent = userdata; if (smlStatusIsResult(status)) { @@ -126,13 +130,15 @@ /* verify that it is a real result with data */ if (result->type != SML_COMMAND_TYPE_RESULTS) { - smlErrorSet(&error, SML_ERROR_GENERIC, "devinf command was not a result"); + g_set_error(&error, SML_ERROR, SML_ERROR_GENERIC, + "devinf command was not a result"); goto error; } SmlItem *item = result->private.results.status->item; if (!item) { - smlErrorSet(&error, SML_ERROR_GENERIC, "devinf result did not have a item"); + g_set_error(&error, SML_ERROR, SML_ERROR_GENERIC, + "devinf result did not have a item"); goto error; } @@ -163,21 +169,27 @@ smlTrace(TRACE_EXIT, "%s", __func__); 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); } -static void _devinf_reply(SmlSession *session, SmlStatus *status, void *userdata) +static void +_devinf_reply (SmlSession *session, + SmlStatus *status, + void *userdata) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, session, status, userdata); smlTrace(TRACE_EXIT, "%s", __func__); } -static SmlBool _send_devinf(SmlDevInfAgent *agent, SmlSession *session, SmlCommand *get, SmlError **error) +static gboolean +_send_devinf (SmlDevInfAgent *agent, + SmlSession *session, + SmlCommand *get, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, agent, session, get, error); CHECK_ERROR_REF @@ -195,7 +207,7 @@ session->sessionType == SML_SESSION_TYPE_SERVER && !sml_dev_inf_get_support_large_objs(agent->devinf)) { - smlErrorSet(error, SML_ERROR_INTERNAL_MISCONFIGURATION, + g_set_error(error, SML_ERROR, SML_ERROR_INTERNAL_MISCONFIGURATION, "OMA DS Server must support large object handling if SyncML 1.1 or higher is used."); goto error; } @@ -207,13 +219,13 @@ { if (smlSessionGetLocalMaxMsgSize(session) < 1) { - smlErrorSet(error, SML_ERROR_INTERNAL_MISCONFIGURATION, + g_set_error(error, SML_ERROR, SML_ERROR_INTERNAL_MISCONFIGURATION, "If large object support is enabled then MaxMsgSize must be set."); goto error; } if (smlSessionGetLocalMaxObjSize(session) < 1) { - smlErrorSet(error, SML_ERROR_INTERNAL_MISCONFIGURATION, + g_set_error(error, SML_ERROR, SML_ERROR_INTERNAL_MISCONFIGURATION, "If large object support is enabled then MaxObjSize must be set."); goto error; } @@ -311,17 +323,19 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static void _recv_devinf(SmlSession *session, SmlCommand *cmd, void *userdata) +static void +_recv_devinf (SmlSession *session, + SmlCommand *cmd, + void *userdata) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, session, cmd, userdata); SmlDevInfAgent *agent = userdata; - SmlError *error = NULL; + GError *error = NULL; char *data = NULL; unsigned int size = 0; @@ -352,35 +366,39 @@ smlTrace(TRACE_EXIT, "%s", __func__); 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); } -static void _request_devinf(SmlSession *session, SmlCommand *cmd, void *userdata) +static void +_request_devinf (SmlSession *session, + SmlCommand *cmd, + void *userdata) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, session, cmd, userdata); SmlDevInfAgent *agent = userdata; - SmlError *error = NULL; + GError *error = NULL; if (!_send_devinf(agent, session, cmd, &error)) goto error; smlTrace(TRACE_EXIT, "%s", __func__); return; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(&error)); + smlSessionDispatchEvent(session, SML_SESSION_EVENT_ERROR, NULL, NULL, NULL, error); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, error->message); + g_error_free(error); } -SmlDevInfAgent *smlDevInfAgentNew(SmlDevInf *devinf, SmlError **error) +SmlDevInfAgent* +smlDevInfAgentNew (SmlDevInf *devinf, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, devinf, error); CHECK_ERROR_REF smlAssert(devinf); - GError *gerror = NULL; SmlDevInfAgent *agent = smlTryMalloc0(sizeof(SmlDevInfAgent), error); if (!agent) @@ -389,20 +407,21 @@ agent->devinf = devinf; agent->sessions = g_hash_table_new_full(NULL, NULL, NULL, _free_session); if (!agent->sessions) { - smlErrorSet(error, SML_ERROR_INTERNAL_NO_MEMORY, "Cannot create new hash table."); + g_set_error(error, SML_ERROR, SML_ERROR_INTERNAL_NO_MEMORY, + "Cannot create new hash table."); goto error; } if (!sml_dev_inf_get_man(devinf) && - !sml_dev_inf_set_man(devinf, "OpenSync", &gerror)) + !sml_dev_inf_set_man(devinf, "OpenSync", error)) goto error; if (!sml_dev_inf_get_mod(devinf) && - !sml_dev_inf_set_mod(devinf, "libsyncml", &gerror)) + !sml_dev_inf_set_mod(devinf, "libsyncml", error)) goto error; if (!sml_dev_inf_get_oem(devinf)) { #ifdef WIN32 - if (!sml_dev_inf_set_oem(devinf, "Microsoft (R)", &gerror)) + if (!sml_dev_inf_set_oem(devinf, "Microsoft (R)", error)) goto error; DWORD dwVersion = GetVersion(); DWORD dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); @@ -412,40 +431,36 @@ char szVersion[1024]; sprintf(szVersion, "%d.%d (%d)", dwMajorVersion, dwMinorVersion, dwBuild); - if (!sml_dev_inf_set_fwv(devinf, szVersion, &gerror)) + if (!sml_dev_inf_set_fwv(devinf, szVersion, error)) goto error; #else struct utsname *buf = malloc(sizeof(struct utsname)); if (uname(buf) == 0) { - if (!sml_dev_inf_set_oem(devinf, buf->sysname, &gerror)) + if (!sml_dev_inf_set_oem(devinf, buf->sysname, error)) goto error; - if (!sml_dev_inf_set_fwv(devinf, buf->release, &gerror)) + if (!sml_dev_inf_set_fwv(devinf, buf->release, error)) goto error; } smlSafeFree((gpointer *)&buf); #endif } if (!sml_dev_inf_get_swv(devinf) && - !sml_dev_inf_set_swv(devinf, VERSION, &gerror)) + !sml_dev_inf_set_swv(devinf, VERSION, error)) goto error; smlTrace(TRACE_EXIT, "%s: %p", __func__, agent); return agent; - error: - if (gerror) { - smlErrorSet(error, gerror->code, "%s", gerror->message); - g_error_free(gerror); - } if (agent) smlSafeFree((gpointer *) &agent); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } -void smlDevInfAgentFree(SmlDevInfAgent *agent) +void +smlDevInfAgentFree (SmlDevInfAgent *agent) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, agent); smlAssert(agent); @@ -458,27 +473,12 @@ smlTrace(TRACE_EXIT, "%s", __func__); } -/* FIXME: DEPRECATED */ -void smlDevInfAgentSetDevInf(SmlDevInfAgent *agent, SmlDevInf *devinf) -{ - smlTrace(TRACE_ERROR, "%s(%p, %p)", __func__, agent, devinf); - smlAssertMsg(NULL, "This function is a design bug."); -} - -/* FIXME: DEPRECATED */ -SmlDevInf *smlDevInfAgentGetDevInf(SmlDevInfAgent *agent) -{ - smlTrace(TRACE_ERROR, "%s(%p, %p)", __func__, agent); - smlAssertMsg(NULL, "This function is a design bug."); - return NULL; -} - /* Set the devinf of the remote peer. */ -SmlBool smlDevInfAgentSetSessionDevInf( - SmlDevInfAgent *agent, - SmlSession *session, - SmlDevInf *devinf, - SmlError **error) +gboolean +smlDevInfAgentSetSessionDevInf (SmlDevInfAgent *agent, + SmlSession *session, + SmlDevInf *devinf, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, agent, session, devinf, error); @@ -500,12 +500,14 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; error: - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return FALSE; } /* Get the devinf that was sent in the session. Returns FALSE if no devinf was received yet. */ -SmlDevInf *smlDevInfAgentGetSessionDevInf(SmlDevInfAgent *agent, SmlSession *session) +SmlDevInf* +smlDevInfAgentGetSessionDevInf (SmlDevInfAgent *agent, + SmlSession *session) { smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, agent, session); @@ -525,7 +527,10 @@ } /** Issues a put request on the session if needed */ -SmlBool smlDevInfAgentSendDevInf(SmlDevInfAgent *agent, SmlSession *session, SmlError **error) +gboolean +smlDevInfAgentSendDevInf (SmlDevInfAgent *agent, + SmlSession *session, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, agent, session, error); CHECK_ERROR_REF @@ -536,14 +541,16 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } /** Issues a Get request for the devinf on the session if needed */ -SmlBool smlDevInfAgentRequestDevInf(SmlDevInfAgent *agent, SmlSession *session, SmlError **error) +gboolean +smlDevInfAgentRequestDevInf (SmlDevInfAgent *agent, + SmlSession *session, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, agent, session, error); CHECK_ERROR_REF @@ -588,33 +595,35 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlDevInfAgentRegisterSession(SmlDevInfAgent *agent, SmlManager *manager, SmlSession *session, SmlError **error) +gboolean +smlDevInfAgentRegisterSession (SmlDevInfAgent *agent, + SmlManager *manager, + SmlSession *session, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, agent, manager, session, error); CHECK_ERROR_REF smlAssert(agent); smlAssert(manager); - GError *gerror = NULL; SmlLocation *devinf10 = NULL; SmlLocation *devinf11 = NULL; SmlLocation *devinf12 = NULL; - devinf12 = sml_location_new_with_options("./devinf12", NULL, &gerror); + devinf12 = sml_location_new_with_options("./devinf12", NULL, error); if (!devinf12) goto error; - devinf11 = sml_location_new_with_options("./devinf11", NULL, &gerror); + devinf11 = sml_location_new_with_options("./devinf11", NULL, error); if (!devinf12) goto error; - devinf10 = sml_location_new_with_options("./devinf10", NULL, &gerror); + devinf10 = sml_location_new_with_options("./devinf10", NULL, error); if (!devinf12) goto error; @@ -732,7 +741,6 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: if (devinf10) g_object_unref(devinf10); @@ -740,26 +748,27 @@ g_object_unref(devinf11); if (devinf12) g_object_unref(devinf12); - GERROR_TO_SML_ERROR(gerror,error) - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlDevInfAgentRegister(SmlDevInfAgent *agent, SmlManager *manager, SmlError **error) +gboolean +smlDevInfAgentRegister (SmlDevInfAgent *agent, + SmlManager *manager, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, agent, manager, error); CHECK_ERROR_REF - SmlBool retval = smlDevInfAgentRegisterSession(agent, manager, NULL, error); + gboolean retval = smlDevInfAgentRegisterSession(agent, manager, NULL, error); if (!retval) goto error; smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } Modified: trunk/libsyncml/objects/sml_devinf_obj.h ============================================================================== --- trunk/libsyncml/objects/sml_devinf_obj.h Tue Jul 7 16:59:09 2009 (r1155) +++ trunk/libsyncml/objects/sml_devinf_obj.h Wed Jul 8 11:19:54 2009 (r1156) @@ -1,7 +1,7 @@ /* * libsyncml - A syncml protocol implementation * Copyright (C) 2005 Armin Bauer <arm...@op...> - * Copyright (C) 2008 Michael Bell <mic...@op...> + * Copyright (C) 2008-2009 Michael Bell <mic...@op...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -35,23 +35,15 @@ // only the SmlDevInf pointer of smlDevInfAgentNew is the local DevInf // all other SmlDevInf pointers are the DevInf of the remote peer -SmlDevInfAgent *smlDevInfAgentNew(SmlDevInf *devinf, GError **error); -void smlDevInfAgentFree(SmlDevInfAgent *agent); -gboolean smlDevInfAgentRegisterSession(SmlDevInfAgent *agent, SmlManager *manager, SmlSession *session, GError **error); -gboolean smlDevInfAgentRegister(SmlDevInfAgent *agent, SmlManager *manager, GError **error); -gboolean smlDevInfAgentSendDevInf(SmlDevInfAgent *agent, SmlSession *session, GError **error); -gboolean smlDevInfAgentRequestDevInf(SmlDevInfAgent *agent, SmlSession *session, GError **error); - -gboolean smlDevInfAgentSetSessionDevInf(SmlDevInfAgent *agent, SmlSession *session, SmlDevInf *devinf, GError **error); -SmlDevInf *smlDevInfAgentGetSessionDevInf(SmlDevInfAgent *agent, SmlSession *session); - -/* These functions can only work in a single session environemnt. - * This is a design bug. The functions are not removed immediately - * to avoid breaking applications which ignore the device information. - * These functions always fire an assertion. - */ -void smlDevInfAgentSetDevInf(SmlDevInfAgent *agent, SmlDevInf *devinf) LIBSYNCML_DEPRECATED; -SmlDevInf *smlDevInfAgentGetDevInf(SmlDevInfAgent *agent) LIBSYNCML_DEPRECATED; +SmlDevInfAgent* smlDevInfAgentNew (SmlDevInf *devinf, GError **error); +void smlDevInfAgentFree (SmlDevInfAgent *agent); +gboolean smlDevInfAgentRegisterSession (SmlDevInfAgent *agent, SmlManager *manager, SmlSession *session, GError **error); +gboolean smlDevInfAgentRegister (SmlDevInfAgent *agent, SmlManager *manager, GError **error); +gboolean smlDevInfAgentSendDevInf (SmlDevInfAgent *agent, SmlSession *session, GError **error); +gboolean smlDevInfAgentRequestDevInf (SmlDevInfAgent *agent, SmlSession *session, GError **error); + +gboolean smlDevInfAgentSetSessionDevInf (SmlDevInfAgent *agent, SmlSession *session, SmlDevInf *devinf, GError **error); +SmlDevInf* smlDevInfAgentGetSessionDevInf (SmlDevInfAgent *agent, SmlSession *session); #endif //_SML_DEVINF_OBJ_H_ /*@}*/ Modified: trunk/libsyncml/objects/sml_devinf_obj_internals.h ============================================================================== --- trunk/libsyncml/objects/sml_devinf_obj_internals.h Tue Jul 7 16:59:09 2009 (r1155) +++ trunk/libsyncml/objects/sml_devinf_obj_internals.h Wed Jul 8 11:19:54 2009 (r1156) @@ -1,6 +1,7 @@ /* * libsyncml - A syncml protocol implementation * Copyright (C) 2005 Armin Bauer <arm...@op...> + * Copyright (C) 2009 Michael Bell <mic...@op...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -31,8 +32,8 @@ typedef struct SmlDevInfAgentSession { /* states */ - SmlBool devinfSent; - SmlBool devinfRequested; + gboolean devinfSent; + gboolean devinfRequested; /* remote device information */ SmlDevInf *recvDevInf; |