libsyncml  0.5.4
transport_obex_client.c
1 /*
2  * libsyncml - A syncml protocol implementation
3  * Copyright (C) 2008-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 "transport.h"
22 #include "libsyncml/sml_error_internals.h"
23 #include "libsyncml/sml_support.h"
24 
25 SmlBool smlDataSyncTransportObexClientInit(
26  SmlDataSyncObject *dsObject,
27  SmlError **error)
28 {
29  smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, dsObject, error);
30  CHECK_ERROR_REF
31 
32  if (dsObject->url &&
34  dsObject->tsp,
35  SML_TRANSPORT_CONFIG_URL, dsObject->url,
36  error))
37  goto error;
38 
39  smlTrace(TRACE_EXIT, "%s - TRUE", __func__);
40  return TRUE;
41 error:
42  smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error));
43  return FALSE;
44 }
45 
46 SmlBool smlDataSyncTransportObexClientConnect(SmlDataSyncObject *dsObject, SmlError **error)
47 {
48  smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, dsObject, error);
49  CHECK_ERROR_REF
50 
51  /* Connect transport layer */
52 
53  if (!smlTransportConnect(dsObject->tsp, error))
54  goto error;
55 
56  /* Create a SAN */
57 
58  SmlNotificationVersion sanVersion = SML_SAN_VERSION_UNKNOWN;
59  switch(dsObject->version)
60  {
61  case SML_VERSION_10:
62  sanVersion = SML_SAN_VERSION_10;
63  break;
64  case SML_VERSION_11:
65  sanVersion = SML_SAN_VERSION_11;
66  break;
67  case SML_VERSION_12:
68  sanVersion = SML_SAN_VERSION_12;
69  break;
70  case SML_VERSION_UNKNOWN:
71  smlErrorSet(error, SML_ERROR_GENERIC, "Unknown SyncML SAN Version.");
72  goto error;
73  break;
74  }
75 
76  SmlNotification *san = smlNotificationNew(
77  sanVersion,
78  SML_SAN_UIMODE_UNSPECIFIED,
79  SML_SAN_INITIATOR_USER, 1,
80  dsObject->identifier, "/",
81  dsObject->useWbxml ? SML_MIMETYPE_WBXML : SML_MIMETYPE_XML,
82  error);
83  if (!san)
84  goto error;
85 
86  smlNotificationSetManager(san, dsObject->manager);
87 
88  /* init digest - SAN uses always MD5 */
89  if (dsObject->username != NULL && strlen(dsObject->username))
90  {
91  SmlCred *cred = smlCredNewAuth(
92  SML_AUTH_TYPE_MD5,
93  dsObject->username,
94  dsObject->password,
95  error);
96  if (!cred)
97  goto error;
98  smlNotificationSetCred(san, cred);
99  smlCredUnref(cred);
100  cred = NULL;
101  }
102 
103  GList *o = dsObject->datastores;
104  for (; o; o = o->next) {
105  SmlDataSyncDatastore *datastore = o->data;
106  if (!smlDsServerAddSan(datastore->server, san, error))
107  goto error;
108  }
109 
110  if (!smlNotificationSend(san, dsObject->tsp, error))
111  goto error;
112 
113  smlNotificationFree(san);
114  san = NULL;
115 
116  smlTrace(TRACE_EXIT, "%s", __func__);
117  return TRUE;
118 error:
119  smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error));
120  return FALSE;
121 }
122 
This object represents an OMA DS datastore.
Definition: data_sync.h:93
SmlBool smlTransportSetConfigOption(SmlTransport *tsp, const char *name, const char *value, SmlError **error)
Sets a configuration parameter.
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
void smlTrace(SmlTraceType type, const char *message,...)
Used for tracing the application.
Definition: sml_support.c:120
void smlErrorSet(SmlError **error, SmlErrorType type, const char *format,...)
Sets the error.
Definition: sml_error.c:355
Represent an error.