libsyncml  0.5.4
data_sync.h
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 #ifndef _SML_DATA_SYNC_INTERNALS_H_
22 #define _SML_DATA_SYNC_INTERNALS_H_
23 
24 #include <libsyncml/data_sync_api/standard.h>
25 #include <libsyncml/data_sync_api/callbacks.h>
26 
27 #include <libsyncml/syncml_internals.h>
28 #include <libsyncml/sml_support.h>
29 
30 #include <libsyncml/sml_session.h>
31 #include <libsyncml/sml_transport.h>
32 #include <libsyncml/objects/sml_auth.h>
33 #include <libsyncml/objects/sml_ds_server.h>
34 #include <libsyncml/objects/sml_devinf_obj.h>
35 
36 #include <glib.h>
37 
38 /* typedef for internal function pointers */
39 
40 typedef SmlBool (* SmlFunctionDataSyncInit) (
41  SmlDataSyncObject *dsObject,
42  SmlError **error);
43 typedef SmlBool (* SmlFunctionDataSyncConnect) (
44  SmlDataSyncObject *dsObject,
45  SmlError **error);
46 typedef SmlBool (* SmlFunctionTransportInit) (
47  SmlDataSyncObject *dsObject,
48  SmlError **error);
49 typedef SmlBool (* SmlFunctionTransportConnect) (
50  SmlDataSyncObject *dsObject,
51  SmlError **error);
52 
64 typedef enum {
65  SML_PACKAGE_RECEIVED_UNKNOWN = -3,
66  SML_PACKAGE_RECEIVED_DEVINF_REQUEST = -2, /* only DevInf was requested */
67  SML_PACKAGE_RECEIVED_DEVINF = -1, /* only DevInf was received */
68  SML_PACKAGE_0 = 0, /* SAN */
69  SML_PACKAGE_1 = 1, /* alerts from client */
70  SML_PACKAGE_2 = 2, /* alerts from server */
71  SML_PACKAGE_3 = 3, /* sync from client */
72  SML_PACKAGE_4 = 4, /* sync from server */
73  SML_PACKAGE_5 = 5, /* map from client */
74  SML_PACKAGE_6 = 6, /* end from server */
75  SML_PACKAGE_END = 7, /* client after end received from server */
76 } SmlDataSyncPackageType;
77 
78 typedef enum {
79  SML_DATA_SYNC_STATE_UNKNOWN = 0,
80  SML_DATA_SYNC_STATE_NEW = 1,
81  SML_DATA_SYNC_STATE_INITIALIZED = 2,
82  SML_DATA_SYNC_STATE_CONNECTED = 3,
83  SML_DATA_SYNC_STATE_SESSION_READY = 4,
84  SML_DATA_SYNC_STATE_SENT_CHANGES = 5,
85  SML_DATA_SYNC_STATE_DISCONNECT_IN_PROGRESS = 6,
86  SML_DATA_SYNC_STATE_DISCONNECTED = 7,
87 } SmlDataSyncInternalStateType;
88 
89 /* typedefs for internal objects */
90 
93 typedef struct SmlDataSyncDatastore {
94  SmlDataSyncObject *dsObject;
95  void *syncChanges;
96  void *syncContexts;
97  char *sourceUri;
98  char *targetUri;
99  char *contentType;
100  SmlDsServer *server;
101  SmlDsSession *session;
102  char *localNext;
103  char *remoteNext;
104  SmlAlertType alertType;
105  GList *changes;
107 
111  SmlSessionType dsType;
112  SmlTransportType tspType;
113  SmlTransportConnectionType conType;
114 
115  SmlManager *manager;
116  SmlTransport *tsp;
117  SmlAuthenticator *auth;
118  SmlDevInf *localDevInf;
119  SmlDevInf *remoteDevInf;
120  SmlDevInfAgent *agent;
121  SmlSession *session;
122 
123  GMutex *managerMutex;
124 
125  /* loop management */
126 
127  GSourceFuncs *functions;
128  SmlThread *thread;
129  GMainContext *context;
130  GSource *source;
131 
132  /* config data */
133 
134  GList *datastores;
135 
136  SmlBool useNumberOfChanges;
137  SmlBool useTimestampAnchor;
138  SmlBool onlyLocaltime;
139  SmlBool onlyReplace;
140  SmlBool useStringTable;
141  SmlBool useWbxml;
142  unsigned int maxObjSize;
143  unsigned int maxMsgSize;
144  char *identifier;
145  SmlAuthType authType;
146  char *username;
147  char *password;
148 
149  char *url;
150  char *target;
151 
152  SmlProtocolVersion version;
153 
154  char *fakeDevice;
155  char *fakeManufacturer;
156  char *fakeModel;
157  char *fakeSoftwareVersion;
158 
159  /* states */
160 
161  SmlDataSyncInternalStateType internalState;
162  int refCount;
163  SmlDataSyncPackageType actualPackage;
164 
165  /* callbacks */
166 
167  SmlDataSyncEventCallback eventCallback;
168  void *eventUserdata;
169 
170  SmlDataSyncGetAlertTypeCallback getAlertTypeCallback;
171  void *getAlertTypeUserdata;
172 
173  SmlDataSyncChangeCallback changeCallback;
174  void *changeUserdata;
175 
176  SmlDataSyncChangeStatusCallback changeStatusCallback;
177 
178  SmlDataSyncMappingCallback mappingCallback;
179  void *mappingUserdata;
180 
181  SmlDataSyncGetAnchorCallback getAnchorCallback;
182  void *getAnchorUserdata;
183 
184  SmlDataSyncSetAnchorCallback setAnchorCallback;
185  void *setAnchorUserdata;
186 
187  SmlDataSyncWriteDevInfCallback writeDevInfCallback;
188  void *writeDevInfUserdata;
189 
190  SmlDataSyncReadDevInfCallback readDevInfCallback;
191  void *readDevInfUserdata;
192 
193  SmlDataSyncHandleRemoteDevInfCallback handleRemoteDevInfCallback;
194  void *handleRemoteDevInfUserdata;
195 
196  /* internal function pointers */
197 
198  SmlFunctionDataSyncInit funcDsInit;
199  SmlFunctionDataSyncInit funcDsConnect;
200  SmlFunctionTransportInit funcTspInit;
201  SmlFunctionTransportConnect funcTspConnect;
202  SmlDsSessionAlertCb funcDatastoreAlert;
203 };
204 
207 typedef struct SmlDataSyncChange {
208  SmlDataSyncDatastore *datastore;
209  SmlChangeType type;
210  char *name;
211  char *data;
212  unsigned int size;
213  void *userdata;
215 
216 void smlDataSyncSendEvent(
217  SmlDataSyncObject *dsObject,
219  void *userdata,
220  SmlError *error);
221 
222 SmlBool smlDataSyncSendMap(
223  SmlDataSyncObject *dsObject,
224  SmlError **error);
225 
226 #endif /* _SML_DATA_SYNC_INTERNALS_H_ */