libsyncml  0.5.4
data_sync_abort.c
1 /*
2  * libsyncml - A syncml protocol implementation
3  * Copyright (C) 2009 Michael Bell <michael.bell@opensync.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  */
20 
21 #include "../syncml.h"
22 #include "../syncml_internals.h"
23 #include "../sml_error_internals.h"
24 
25 #include <libsyncml/data_sync_api/defines.h>
26 #include <libsyncml/data_sync_api/standard.h>
27 #include <libsyncml/data_sync_api/callbacks.h>
28 
29 #include "data_sync.h"
30 
38 #include "../sml_session_internals.h"
39 #include "../sml_manager_internals.h"
40 
42  SmlDataSyncObject *dsObject,
43  SmlError **error)
44 {
45  smlTrace(TRACE_ENTRY, "%s", __func__);
46 
47  /* determine the state of the session */
48  if (!dsObject->session->sending && !dsObject->session->waiting)
49  {
50  /* send abort command */
51  smlTrace(TRACE_INTERNAL, "%s: A careful abort is possible.", __func__);
52  /* FIXME: Send a default abort command. */
53  /* FIXME: Is it necessary or recommended to abort every datastore. */
54  goto WORKAROUND;
55  } else {
56  /* stop transport */
57 WORKAROUND:
58  smlTrace(TRACE_INTERNAL, "%s: A hard abort is required.", __func__);
59 
60  if (SML_DATA_SYNC_STATE_CONNECTED <= dsObject->internalState &&
61  dsObject->internalState < SML_DATA_SYNC_STATE_DISCONNECT_IN_PROGRESS)
62  {
63  dsObject->internalState = SML_DATA_SYNC_STATE_DISCONNECT_IN_PROGRESS;
64 
65  SmlLink *link_ = smlManagerSessionGetLink(
66  dsObject->manager,
67  dsObject->session,
68  error);
69  if (!link_ && *error)
70  goto error;
71 
72  if (!smlTransportDisconnect(dsObject->tsp, link_, error))
73  goto error;
74  }
75  }
76 
77  smlTrace(TRACE_EXIT, "%s", __func__);
78  return TRUE;
79 error:
80  smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error));
81  return FALSE;
82 }
83 
const char * smlErrorPrint(SmlError **error)
Returns the message of the error.
Definition: sml_error.c:299
This is the central synchronization object.
Definition: data_sync.h:110
SmlBool smlDataSyncAbort(SmlDataSyncObject *dsObject, SmlError **error)
void smlTrace(SmlTraceType type, const char *message,...)
Used for tracing the application.
Definition: sml_support.c:120
Represent an error.