Bug Summary

File:libsynthesis/src/DB_interfaces/api_db/dbapi.cpp
Warning:line 671, column 17
Value stored to 'err' is never read

Annotated Source Code

1/*
2 * File: dbapi.cpp
3 *
4 * Author: Beat Forster (bfo@synthesis.ch)
5 *
6 *
7 * Programming interface between Synthesis SyncML engine
8 * and a database structure: C++ class interface
9 *
10 * Copyright (c) 2004-2011 by Synthesis AG + plan44.ch
11 *
12 */
13
14#include "dbapi.h"
15#include "SDK_util.h"
16#include "SDK_support.h"
17#include "DLL_interface.h"
18
19#ifndef SYSYNC_ENGINE1
20#include "stringutil.h"
21#endif
22
23#ifdef JNI_SUPPORT
24#include "JNI_interface.h"
25#endif
26
27
28// the simple demo adapter
29#ifdef DBAPI_DEMO
30 namespace SDK_demodb {
31 #include "dbapi_include.h"
32 } // namespace
33#endif
34
35// more built-in adapters of the same kind can be used
36#ifdef DBAPI_EXAMPLE
37 namespace example1 {
38 #include "dbapi_include.h"
39 } // namespace
40 namespace example2 {
41 #include "dbapi_include.h"
42 } // namespace
43#endif
44
45// a silent adapter, which always returns OK
46#ifdef DBAPI_SILENT
47 namespace silent {
48 #include "dbapi_include.h"
49 } // namespace
50#endif
51
52// the textdb adapter
53#ifdef DBAPI_TEXT1
54 namespace SDK_textdb {
55 #include "dbapi_include.h"
56 } // namespace
57#endif
58
59// the snowwhite/oceanblue adapter
60#ifdef DBAPI_SNOWWHITE
61 namespace oceanblue {
62 #include "dbapi_include.h"
63 } // namespace
64#endif
65
66// the JNI bridge to Java
67#if defined JNI_SUPPORT && defined PLUGIN_DLL1
68 namespace SDK_jni {
69 #include "dbapi_include.h"
70 } // namespace
71#endif
72
73// the C# bridge
74#if defined CSHARP_SUPPORT && defined PLUGIN_DLL1
75 namespace SDK_csharp {
76 #include "dbapi_include.h"
77 } // namespace
78#endif
79
80// the bridge to OMA-DS 1.2 FILEOBJ
81#ifdef DBAPI_FILEOBJ
82 namespace SDK_fileobj {
83 #include "dbapi_include.h"
84 } // namespace
85#endif
86
87// the dbapi logger bridge
88#ifdef DBAPI_LOGGER
89 namespace logger {
90 #include "dbapi_include.h"
91 } // namespace
92#endif
93
94
95// some internal modules do not have the full set of routines
96#define DISABLE_PLUGIN_SESSIONAUTH 1
97#define DISABLE_PLUGIN_DEVICEADMIN 1
98#define DISABLE_PLUGIN_DATASTOREADMIN 1
99#define DISABLE_PLUGIN_ADAPTITEM 1
100
101// the bridge via tunnel to any datastore inside the engine
102#if defined DBAPI_TUNNEL && defined PLUGIN_DLL1
103 namespace SDK_tunnel {
104 #include "dbapi_include.h"
105 } // namespace
106#endif
107
108
109// iPhone plugins are AsKey only
110#define DISABLE_PLUGIN_DATASTOREDATA_STR
111// static plugins required for iPhoneOS (no DLLs allowed)
112#ifdef IPHONE_PLUGINS_STATIC
113 #ifdef HARDCODED_CONTACTS
114 namespace iPhone_addressbook {
115 #include "dbapi_include.h"
116 } // namespace
117 #endif
118
119 #ifdef HARDCODED_CALENDAR
120 namespace iPhone_calendar {
121 #include "dbapi_include.h"
122 } // namespace
123 #endif
124
125 #ifdef HARDCODED_TODO
126 namespace iPhone_todos {
127 #include "dbapi_include.h"
128 } // namespace
129 #endif
130
131 #ifdef HARDCODED_NOTES
132 namespace iPhone_notes {
133 #include "dbapi_include.h"
134 } // namespace
135 #endif
136
137 #ifdef HARDCODED_EMAILS
138 namespace iPhone_emails {
139 #include "dbapi_include.h"
140 } // namespace
141 #endif
142
143 #ifdef HARDCODED_CUSTOM
144 namespace iPhone_dbplugin1 {
145 #include "dbapi_include.h"
146 } // namespace
147
148 namespace iPhone_dbplugin2 {
149 #include "dbapi_include.h"
150 } // namespace
151
152 namespace iPhone_dbplugin3 {
153 #include "dbapi_include.h"
154 } // namespace
155
156 namespace iPhone_dbplugin4 {
157 #include "dbapi_include.h"
158 } // namespace
159 #endif
160#endif
161#undef DISABLE_PLUGIN_DATASTOREDATA_STR
162
163
164#undef DISABLE_PLUGIN_ADAPTITEM
165#define DISABLE_PLUGIN_DATASTOREDATA 1
166
167// the "adaptitem" module does not contain most of the routines
168#ifdef ADAPTITEM_SUPPORT
169 namespace SDK_adapt {
170 #include "dbapi_include.h"
171 } // namespace
172#endif
173
174// the UI demo adapter is something special
175#define DISABLE_PLUGIN_ADAPTITEM 1
176#define ENABLE_PLUGIN_UI1 1
177
178#ifdef UIAPI_DEMO
179 namespace SDK_ui {
180 #include "dbapi_include.h"
181 } // namespace
182#endif
183
184#undef DISABLE_PLUGIN_ADAPTITEM
185#undef DISABLE_PLUGIN_SESSIONAUTH
186#undef DISABLE_PLUGIN_DEVICEADMIN
187#undef DISABLE_PLUGIN_DATASTOREADMIN
188#undef DISABLE_PLUGIN_DATASTOREDATA
189// all should be switched on now for "no_dbapi"
190
191
192
193// ------------------------------------------------------------
194#define MyDB"DBApi" "DBApi" // identifier of the sandwich layer
195
196
197namespace no_dbapi {
198 #include "dbapi_include.h"
199
200 // combine the definitions of different namespaces
201 using sysync::DB_Callback;
202 using sysync::UI_Call_In;
203 using sysync::ItemID;
204 using sysync::MapID;
205 using sysync::cItemID;
206 using sysync::cMapID;
207
208 using sysync::LOCERR_NOTIMP;
209 using sysync::Password_Mode_Undefined;
210
211 // default routines, if no context is available
212 // all of them are returning false or 0
213
214 /* --- MODULE ------------------------------------------------------------------------------------ */
215 TSyError Module_CreateContext ( CContext* mc, cAppCharP /* moduleName */,
216 cAppCharP /* subName */,
217 cAppCharP /* mContextName */,
218 DB_Callback /* mCB */ ) { *mc= 0; return LOCERR_OK; }
219
220 CVersion Module_Version ( CContext /* mc */ ) /* invalid */ { return VP_BadVersion;}
221 TSyError Module_Capabilities ( CContext /* mc */, appCharP *aCapaP )
222 { *aCapaP= NULL__null; return DB_NotFound; }
223 TSyError Module_PluginParams ( CContext /* mc */, cAppCharP /* mConfigParams */,
224 CVersion /* engineVersion */ ) { return DB_Error; }
225 void Module_DisposeObj ( CContext /* mc */, void* /* memory */ ) { }
226 TSyError Module_DeleteContext ( CContext /* mc */ ) { return LOCERR_OK; }
227
228
229 /* --- SESSION ----------------------------------------------------------------------------------- */
230 TSyError Session_CreateContext ( CContext* /* sc */, cAppCharP /* sessionName */,
231 DB_Callback /* sCB */ ) { return DB_Fatal; }
232
233 TSyError Session_AdaptItem ( CContext /* sc */, appCharP* /* sItemData1 */,
234 appCharP* /* sItemData2 */,
235 appCharP* /* sLocalvars */,
236 uInt32 /* sIdentifier */ ) { return DB_Forbidden; }
237
238 TSyError Session_CheckDevice ( CContext /* sc */, cAppCharP /* aDeviceID */,
239 appCharP* /* sDevKey */,
240 appCharP* /* nonce */ ) { return DB_Forbidden; }
241 sInt32 Session_PasswordMode ( CContext /* sc */ ) { return Password_Mode_Undefined; }
242 TSyError Session_Login ( CContext /* sc */, cAppCharP /* sUsername */,
243 appCharP* /* sPassword */,
244 appCharP* /* sUsrKey */ ) { return DB_Forbidden; }
245 TSyError Session_Logout ( CContext /* sc */ ) { return DB_Forbidden; }
246
247 TSyError Session_GetNonce ( CContext /* sc */, appCharP* /* nonce */ ) { return DB_Forbidden; }
248 TSyError Session_SaveNonce ( CContext /* sc */, cAppCharP /* nonce */ ) { return DB_Forbidden; }
249 TSyError Session_SaveDeviceInfo ( CContext /* sc */, cAppCharP /* aDeviceInfo */ ) { return DB_Forbidden; }
250 TSyError Session_GetDBTime ( CContext /* sc */, appCharP* /* currentDBTime */) { return DB_Forbidden; }
251
252 void Session_DisposeObj ( CContext /* sc */, void* /* memory */ ) { }
253 void Session_ThreadMayChangeNow( CContext /* sc */ ) { }
254 void Session_DispItems ( CContext /* sc */, bool, cAppCharP ) { }
255 TSyError Session_DeleteContext ( CContext /* sc */ ) { return DB_Fatal; }
256
257
258 /* --- DATASTORE --------------------------------------------------------------------------------- */
259 /* ----- OPEN ------------------------ */
260 TSyError CreateContext ( CContext* /* co */, cAppCharP /* aContextName */, DB_Callback /* aCB */,
261 cAppCharP /* sDevKey */,
262 cAppCharP /* sUsrKey */ ) { return DB_Fatal; }
263 uInt32 ContextSupport ( CContext /* co */, cAppCharP /* aContextRules */ ) { return 0; }
264 uInt32 FilterSupport ( CContext /* co */, cAppCharP /* aFilterRules */ ) { return 0; }
265
266
267 /* ----- ADMINISTRATION -------------- */
268 TSyError LoadAdminData ( CContext /* co */, cAppCharP /* aLocDB */,
269 cAppCharP /* aRemDB */,
270 appCharP* /* adminData */ ) { return DB_Forbidden; }
271 TSyError LoadAdminDataAsKey( CContext /* co */, cAppCharP /* aLocDB */,
272 cAppCharP /* aRemDB */,
273 KeyH /* adminKey */ ) { return DB_Forbidden; }
274
275 TSyError SaveAdminData ( CContext /* co */, cAppCharP /* adminData */ ) { return DB_Forbidden; }
276 TSyError SaveAdminDataAsKey( CContext /* co */, KeyH /* adminKey */ ) { return DB_Forbidden; }
277
278 bool ReadNextMapItem ( CContext /* co */, MapID /* mID */, bool /* aFirst */ ) { return false; }
279 TSyError InsertMapItem ( CContext /* co */, cMapID /* mID */ ) { return DB_Forbidden; }
280 TSyError UpdateMapItem ( CContext /* co */, cMapID /* mID */ ) { return DB_Forbidden; }
281 TSyError DeleteMapItem ( CContext /* co */, cMapID /* mID */ ) { return DB_Forbidden; }
282
283
284 /* ----- GENERAL --------------------- */
285 void DisposeObj ( CContext /* co */, void* /* memory */ ) { }
286 void ThreadMayChangeNow ( CContext /* co */ ) { }
287 void WriteLogData ( CContext /* co */, cAppCharP /* logData */ ) { }
288 void DispItems ( CContext /* co */, bool, cAppCharP ) { }
289
290 /* ----- "script-like" ADAPT --------- */
291 TSyError AdaptItem ( CContext /* co */, appCharP* /* aItemData1 */,
292 appCharP* /* aItemData2 */,
293 appCharP* /* aLocalvars */,
294 uInt32 /* aIdentifier */ ) { return DB_Forbidden; }
295
296 /* ----- READ ------------------------ */
297 TSyError StartDataRead ( CContext /* co */, cAppCharP /* lastToken */,
298 cAppCharP /* resumeToken */ ) { return DB_Fatal; }
299
300 TSyError ReadNextItem ( CContext /* co */, ItemID /* aID */, appCharP* /* aItemData */,
301 sInt32* /* aStatus */, bool /* aFirst */ ) { return DB_Fatal; }
302 TSyError ReadNextItemAsKey( CContext /* co */, ItemID /* aID */, KeyH /* aItemKey */,
303 sInt32* /* aStatus */, bool /* aFirst */ ) { return DB_Fatal; }
304
305 TSyError ReadItem ( CContext /* co */, cItemID /* aID */, appCharP* /* aItemData */ ) { return DB_Fatal; }
306 TSyError ReadItemAsKey ( CContext /* co */, cItemID /* aID */, KeyH /* aItemKey */ ) { return DB_Fatal; }
307
308 TSyError ReadBlob ( CContext /* co */, cItemID /* aID */, cAppCharP /* aBlobID */,
309 appPointer* /* aBlkPtr */, memSize* /* aBlkSize */,
310 memSize* /* aTotSize */,
311 bool /* aFirst */, bool* /* aLast */ ) { return DB_Fatal; }
312 TSyError EndDataRead ( CContext /* co */ ) { return DB_Fatal; }
313
314
315 /* ----- WRITE ----------------------- */
316 TSyError StartDataWrite ( CContext /* co */ ) { return DB_Fatal; }
317
318 TSyError InsertItem ( CContext /* co */, cAppCharP /* aItemData */, ItemID /* newID */ ) { return DB_Fatal; }
319 TSyError InsertItemAsKey ( CContext /* co */, KeyH /* aItemKey */, ItemID /* newID */ ) { return DB_Fatal; }
320 TSyError UpdateItem ( CContext /* co */, cAppCharP /* aItemData */, cItemID /* aID */,
321 ItemID /* updID */ ) { return DB_Fatal; }
322 TSyError UpdateItemAsKey ( CContext /* co */, KeyH /* aItemKey */, cItemID /* aID */,
323 ItemID /* updID */ ) { return DB_Fatal; }
324
325 TSyError MoveItem ( CContext /* co */, cItemID /* aID */, cAppCharP /* newParID */ ) { return DB_Fatal; }
326 TSyError DeleteItem ( CContext /* co */, cItemID /* aID */ ) { return DB_Fatal; }
327 TSyError FinalizeLocalID ( CContext /* co */, cItemID /* aID */, ItemID /* updID */ ) { return DB_Fatal; }
328 TSyError DeleteSyncSet ( CContext /* co */ ) { return DB_Fatal; }
329 TSyError WriteBlob ( CContext /* co */, cItemID /* aID */, cAppCharP /* aBlobID */,
330 appPointer /* aBlkPtr */,memSize /* aBlkSize */,
331 memSize /* aTotSize */,
332 bool /* aFirst */, bool /* aLast */ ) { return DB_Fatal; }
333
334 // There are older implementations, where "DeleteBlob" is not yet available.
335 TSyError DeleteBlob ( CContext /* co */, cItemID /* aID */, cAppCharP /* aBlobID */ ) { return LOCERR_NOTIMP; }
336 TSyError EndDataWrite ( CContext /* co */, bool /* success */, char** /* newToken */ ) { return DB_Fatal; }
337
338 /* ----- CLOSE ----------------------- */
339 TSyError DeleteContext ( CContext /* co */ ) { return DB_Fatal; }
340
341
342 /* ---- UI API ----------------------- */
343 TSyError UI_CreateContext ( CContext* /* co */, cAppCharP /* uiName */, UI_Call_In /* uCI */ ) { return DB_Fatal; }
344 TSyError UI_RunContext ( CContext /* co */ ) { return DB_Fatal; }
345 TSyError UI_DeleteContext ( CContext /* co */ ) { return DB_Fatal; }
346} // namespace no_dbapi
347
348
349
350/* ---- "TDB_Api_Str" implementation --------------------------------------- */
351namespace sysync {
352
353TDB_Api_Str::TDB_Api_Str() { clear(); } // constructor
354TDB_Api_Str::TDB_Api_Str( string &s ) { clear(); fStr= (char*)s.c_str(); } // alternative constructor
355TDB_Api_Str::~TDB_Api_Str() { DisposeStr(); } // destructor
356
357
358void TDB_Api_Str::AssignStr( CContext aContext, DisposeProc aDisposeProc, bool itself )
359{
360 fContext= aContext;
361 fItself = itself;
362
363 if (fStr!=NULL__null) fDisposeProc= aDisposeProc;
364 else { fDisposeProc= NULL__null; fStr= const_cast<char *>(""); /* this is okay because the string is not going to be disposed */ }
365} // AssignStr
366
367
368
369void TDB_Api_Str::DisposeStr()
370{
371 // nothing to do, already disposed ?
372 if (fStr !=NULL__null &&
373 fDisposeProc!=NULL__null) {
374 void* ref= const_cast<char *>(fStr);
375 if (fItself) ref= this; fDisposeProc( fContext,ref );
376 } // if
377
378 clear(); // don't do it again !!
379} // DisposeStr
380
381
382
383/* Dispose a string which has been allocated with 'StrAlloc'
384 * Used as handler for:
385 * typedef void( *DisposeProc)( long aContext, void* s );
386 */
387static void StrDispose_Handler( CContext /* aContext */, void* s ) {
388 StrDispose( s );
389} // StrDispose_Handler
390
391
392
393/* ---------- allocate local memory for a string ------------- */
394void TDB_Api_Str::LocalAlloc( CContext aContext, cAppCharP str )
395{
396 fStr= StrAlloc( str );
397 AssignStr( aContext, (DisposeProc)StrDispose_Handler );
398} // LocalAlloc
399
400
401
402/* ---- "DB_Api_Blk" implementation --------------------------------------- */
403TDB_Api_Blk::TDB_Api_Blk() { clear(); } // constructor
404TDB_Api_Blk::~TDB_Api_Blk() { DisposeBlk(); } // destructor
405
406
407void TDB_Api_Blk::AssignBlk( CContext aContext, DisposeProc aDisposeProc, bool itself )
408{
409 fContext= aContext;
410 fItself = itself;
411
412 if (fPtr!=NULL__null) fDisposeProc= (DisposeProc)aDisposeProc;
413 else { fDisposeProc= NULL__null; fSize= 0; }
414} // AssignBlk
415
416
417
418void TDB_Api_Blk::DisposeBlk()
419{
420 // nothing to do, already disposed ?
421 if (fPtr !=NULL__null &&
422 fDisposeProc!=NULL__null) {
423 void* ref= fPtr;
424 if (fItself) ref= this; fDisposeProc( fContext,ref );
425 } // if
426
427 clear(); // don't do it again !!
428} // DisposeBlk
429
430
431// Returns true if <ps> is name or #<n>
432static bool BuiltIn( string &ps, int &n, cAppCharP name )
433{
434 if (strucmp( ps.c_str(), name )==0) return true;
435
436 string s= "#" + IntStr( n++ );
437 if (strucmp( ps.c_str(), s.c_str() )==0) { ps= name; return true; }
438
439 return false;
440} // BuiltIn
441
442
443
444/* --- connect to library ------------------------------------------------- */
445/*! These are the built-in linked libraries, which can be accessed directly
446 * NOTE: Some of them are normally switched off with compile options
447 *
448 * SDK plugin modules can be also linked into the engine directly.
449 * Normally the compiler must be able to link all SDK routines.
450 * The SDK concept allows to have some routines unimplemented,
451 * they will be provided by the "no_dbapi" built-in module.
452 */
453static TSyError DBApi_LibAssign( appPointer aMod, string &ps, appPointer aField, int aFSize,
454 cAppCharP aKey= "" )
455{
456 TSyError err= DB_NotFound;
457 int n= 0; // incremental counter starting with 0
458
459 // the blind adapter is always available and acts as default as well
460 if (strucmp( ps.c_str(), "" )==0 ||
461 BuiltIn( ps,n, "no_dbapi" )) err= no_dbapi::AssignMethods( aMod, aField,aFSize, aKey );
462
463 #ifdef DBAPI_DEMO // demo (C) adapter, which will be delivered with SDK
464 else if (BuiltIn( ps,n, "SDK_demodb" )) err= SDK_demodb::AssignMethods( aMod, aField,aFSize, aKey );
465 #endif
466
467 #ifdef DBAPI_EXAMPLE // other (C++) linked versions of the demo adapter (for test)
468 else if (BuiltIn( ps,n, "example1" )) err= example1::AssignMethods( aMod, aField,aFSize, aKey );
469 else if (BuiltIn( ps,n, "example2" )) err= example2::AssignMethods( aMod, aField,aFSize, aKey );
470 #endif
471
472 #ifdef DBAPI_SILENT // a silent adapter, which always says, everthing is ok
473 else if (BuiltIn( ps,n, "silent" )) err= silent::AssignMethods( aMod, aField,aFSize, aKey );
474 #endif
475
476 #ifdef DBAPI_TEXT1 // "text_db" implementation, which emulates the "textdb"
477 else if (BuiltIn( ps,n, "SDK_textdb" )) err= SDK_textdb::AssignMethods( aMod, aField,aFSize, aKey );
478 #endif
479
480 #ifdef DBAPI_SNOWWHITE // "oceanblue/snowwhite" implementation
481 else if (BuiltIn( ps,n, "snowwhite" )) err= oceanblue::AssignMethods( aMod, aField,aFSize, aKey );
482 #endif
483
484 #ifdef PLUGIN_DLL1 // plugin bridges
485 #ifdef JNI_SUPPORT // the Java (JNI) adapter
486 else if (BuiltIn( ps,n, "JNI" )) err= SDK_jni::AssignMethods( aMod, aField,aFSize, aKey );
487 #endif
488
489 #ifdef CSHARP_SUPPORT // the C# adapter
490 else if (BuiltIn( ps,n, "CSHARP" )) err= SDK_csharp::AssignMethods( aMod, aField,aFSize, aKey );
491 #endif
492
493 #ifdef DBAPI_TUNNEL // direct access to internal adapters
494 else if (BuiltIn( ps,n, "tunnel" )) err= SDK_tunnel::AssignMethods( aMod, aField,aFSize, aKey );
495 #endif
496
497 #ifdef DBAPI_LOGGER // dbapi logger bridge
498 else if (BuiltIn( ps,n, "logger" )) err= logger::AssignMethods( aMod, aField,aFSize, aKey );
499 #endif
500 #endif
501
502 #ifdef DBAPI_FILEOBJ // dbapi fileobj
503 else if (BuiltIn( ps,n, "FILEOBJ" )) err= SDK_fileobj::AssignMethods( aMod, aField,aFSize, aKey );
504 #endif
505
506 #ifdef ADAPTITEM_SUPPORT // "script-like" adapt item
507 else if (BuiltIn( ps,n, "ADAPTITEM" )) err= SDK_adapt::AssignMethods( aMod, aField,aFSize, aKey );
508 #endif
509
510 #ifdef UIAPI_DEMO // demo (C++) UI interface adapter, which will be delivered with SDK
511 else if (BuiltIn( ps,n, "SDK_ui" )) err= SDK_ui::AssignMethods( aMod, aField,aFSize, aKey );
512 #endif
513
514 #ifdef IPHONE_PLUGINS_STATIC // iPhone OS does not allow DLL plugins at this time, so we must link them statically
515 #ifdef HARDCODED_CONTACTS
516 else if (BuiltIn( ps,n, "iPhone_addressbook")) err= iPhone_addressbook::AssignMethods( aMod, aField,aFSize, aKey );
517 #endif
518 #ifdef HARDCODED_CALENDAR
519 else if (BuiltIn( ps,n, "iPhone_calendar" )) err= iPhone_calendar::AssignMethods( aMod, aField,aFSize, aKey );
520 #endif
521 #ifdef HARDCODED_TODO
522 else if (BuiltIn( ps,n, "iPhone_todos" )) err= iPhone_todos::AssignMethods( aMod, aField,aFSize, aKey );
523 #endif
524 #ifdef HARDCODED_NOTES
525 else if (BuiltIn( ps,n, "iPhone_notes" )) err= iPhone_notes::AssignMethods( aMod, aField,aFSize, aKey );
526 #endif
527 #ifdef HARDCODED_EMAILS
528 else if (BuiltIn( ps,n, "iPhone_emails" )) err= iPhone_emails::AssignMethods( aMod, aField,aFSize, aKey );
529 #endif
530
531 #ifdef HARDCODED_CUSTOM
532 else if (BuiltIn( ps,n, "iPhone_dbplugin1" )) err= iPhone_dbplugin1::AssignMethods( aMod, aField,aFSize, aKey );
533 else if (BuiltIn( ps,n, "iPhone_dbplugin2" )) err= iPhone_dbplugin2::AssignMethods( aMod, aField,aFSize, aKey );
534 else if (BuiltIn( ps,n, "iPhone_dbplugin3" )) err= iPhone_dbplugin3::AssignMethods( aMod, aField,aFSize, aKey );
535 else if (BuiltIn( ps,n, "iPhone_dbplugin4" )) err= iPhone_dbplugin4::AssignMethods( aMod, aField,aFSize, aKey );
536 #endif
537 #endif
538
539 else if (strucmp( ps.c_str(), "#" )==0) err= LOCERR_UNKSUBSYSTEM;
540 else if (!BuiltIn( ps,n, "" )) ModuleConnectionError( NULL__null, AddBracks( ps ).c_str() );
541
542 return err;
543} // DBApi_LibAssign
544
545
546
547/* ---- wrapper for DB_Callback -------------------------------------------- */
548TDB_Api_Callback::TDB_Api_Callback() { InitCallback( &Callback, DB_Callback_Version, NULL__null,NULL__null ); }
549
550
551
552/* ---- "DB_Api_Config" implementation ------------------------------------- */
553TDB_Api_Config::TDB_Api_Config()
554{
555 fMod= NULL__null;
556 clear();
557
558 fTSTversion= VP_BadVersion;
559} // constructor
560
561
562TDB_Api_Config::~TDB_Api_Config()
563{
564 Disconnect();
565} // destructor
566
567
568
569static void connect_no_dbapi( appPointer &aMod, API_Methods &m )
570{
571 string no_dbapi= "";
572
573 DisconnectModule( aMod ); // avoid memory leak
574 ConnectModule ( aMod,"" ); // default: no db_api -> all methods return false
575//---- module --------------------------------
576 DBApi_LibAssign ( aMod,no_dbapi, &m.start, sizeof(m.start), Plugin_Start"plugin_start" );
577 DBApi_LibAssign ( aMod,no_dbapi, &m.param, sizeof(m.param), Plugin_Param"plugin_param" );
578 DBApi_LibAssign ( aMod,no_dbapi, &m, sizeof(m) );
579
580//---- session -------------------------------
581 DBApi_LibAssign ( aMod,no_dbapi, &m.se, sizeof(m.se), Plugin_Session"plugin_se" );
582 DBApi_LibAssign ( aMod,no_dbapi, &m.se.seAdapt, sizeof(m.se.seAdapt), Plugin_SE_Adapt"plugin_sessionadapt" );
583 DBApi_LibAssign ( aMod,no_dbapi, &m.se.seAuth, sizeof(m.se.seAuth), Plugin_SE_Auth"plugin_sessionauth" );
584 DBApi_LibAssign ( aMod,no_dbapi, &m.se.dvAdmin, sizeof(m.se.dvAdmin), Plugin_DV_Admin"plugin_deviceadmin" );
585 DBApi_LibAssign ( aMod,no_dbapi, &m.se.dvTime, sizeof(m.se.dvTime), Plugin_DV_DBTime"plugin_dbtime" );
586
587//---- datastore -----------------------------
588 DBApi_LibAssign ( aMod,no_dbapi, &m.ds, sizeof(m.ds), Plugin_Datastore"plugin_ds" );
589 DBApi_LibAssign ( aMod,no_dbapi, &m.ds.dsg, sizeof(m.ds.dsg), Plugin_DS_General"plugin_datageneral" );
590 DBApi_LibAssign ( aMod,no_dbapi, &m.ds.dsAdapt, sizeof(m.ds.dsAdapt), Plugin_DS_Adapt"plugin_dataadapt" );
591 DBApi_LibAssign ( aMod,no_dbapi, &m.ds.dsAdm.str, sizeof(m.ds.dsAdm.str), Plugin_DS_Admin_Str"plugin_datastoreadmin_str" );
592 DBApi_LibAssign ( aMod,no_dbapi, &m.ds.dsAdm.key, sizeof(m.ds.dsAdm.key), Plugin_DS_Admin_Key"plugin_datastoreadmin_key" );
593 DBApi_LibAssign ( aMod,no_dbapi, &m.ds.dsAdm.map, sizeof(m.ds.dsAdm.map), Plugin_DS_Admin_Map"plugin_datastoreadmin_map" );
594 DBApi_LibAssign ( aMod,no_dbapi, &m.ds.dsData, sizeof(m.ds.dsData), Plugin_DS_Data"plugin_datastore" );
595 DBApi_LibAssign ( aMod,no_dbapi, &m.ds.dsData.str,sizeof(m.ds.dsData.str),Plugin_DS_Data_Str"plugin_datastore_str" );
596 DBApi_LibAssign ( aMod,no_dbapi, &m.ds.dsData.key,sizeof(m.ds.dsData.key),Plugin_DS_Data_Key"plugin_datastore_key" );
597 DBApi_LibAssign ( aMod,no_dbapi, &m.ds.dsBlob, sizeof(m.ds.dsBlob), Plugin_DS_Blob"plugin_datablob" );
598//---- ui context ----------------------------
599 DBApi_LibAssign ( aMod,no_dbapi, &m.ui, sizeof(m.ui), Plugin_UI"plugin_ui" );
600 DisconnectModule( aMod ); // no longer used, avoid memory leak
601} // connect_no_dbapi
602
603
604
605void TDB_Api_Config::clear()
606{
607 connect_no_dbapi( fMod, m );
608
609 fConnected = false;
610 fADMIN_Info= false;
611 fSDKversion= VP_BadVersion;
612 fMODversion= VP_BadVersion;
613 mContext = 0;
614
615 DB_Callback mCB= &fCB.Callback;
616 mCB->cContext= 0; // set it to uninitialized default
617 mCB->mContext= 0;
618} // clear
619
620
621
622// ---------------------------------------------------------------------
623//! Module string disposer
624void TDB_Api_Config::DisposeStr( TDB_Api_Str &s )
625{
626 fSList.remove( &s ); // remove it from the list first to avoid double free
627
628 s.AssignStr( mContext, (DisposeProc)m.Module_DisposeObj );
629 s.DisposeStr();
630} // DisposeStr
631
632
633//! Local wrapper, because it must be DisposeProc type and can't be C++ method
634static void Local_Module_DisposeStr( CContext mObj, void* memory )
635{
636 TDB_Api_Config* c= (TDB_Api_Config*)mObj;
637 TDB_Api_Str* u= (TDB_Api_Str*)memory;
638 c->DisposeStr( *u );
639} // Local_Session_DisposeStr
640
641
642void TDB_Api_Config::AssignStr( TDB_Api_Str &s )
643{
644 if (s.fStr==NULL__null) return;
645
646 s.AssignStr( (CContext)this, Local_Module_DisposeStr, true );
647 fSList.push_back( &s ); // add the element to the list
648} // AssignStr
649
650
651
652// ---------------------------------------------------------------------
653// general datastore access ?
654bool DSConnect( cAppCharP aItem )
655{
656 return FlagOK( aItem, Plugin_Datastore"plugin_ds" ) &&
657 ( FlagOK( aItem, Plugin_DS_Admin"plugin_datastoreadmin" ) ||
658 FlagOK( aItem, Plugin_DS_Data"plugin_datastore" ) ||
659 FlagOK( aItem, Plugin_DS_Adapt"plugin_dataadapt" ) );
660} // DSConnect
661
662
663
664TSyError TDB_Api_Config::DBApi_Assign( cAppCharP aItem, appPointer aField,
665 memSize aFieldSize, cAppCharP aKey )
666{
667 TSyError err= LOCERR_OK;
668
669 if (FlagOK( aItem,aKey )) {
670 if (is_lib) err= DBApi_LibAssign( fMod, fPlugin, aField,aFieldSize, aKey );
671 else { err= DB_Forbidden; // only allowed, if PLUGIN_DLL is active
Value stored to 'err' is never read
672 #ifdef PLUGIN_DLL1
673 err= DBApi_DLLAssign( fMod, aField,aFieldSize, aKey, false );
674 #endif
675 } // if
676
677 DEBUG_Exotic_INT( &fCB.Callback,MyDB"DBApi", "DBApi_Assign", "aKey='%s' (size=%d) err=%d",
678 aKey, aFieldSize, err );
679 } // if
680
681 return err;
682} // DBApi_Assign
683
684
685
686// Returns the engine's SDK version
687long TDB_Api_Config::EngineSDKVersion()
688{ // If not changed ...
689 if (fTSTversion==VP_BadVersion) return Plugin_Version( 0 ); // Called here it's the engine's SDK version
690 else return fTSTversion; // modified for test
691} // EngineSDKVersion
692
693
694
695// Returns LOCERR_TOOOLD, if the <capa> version is too old
696TSyError TDB_Api_Config::MinVersionCheck( string capa, CVersion &vMin )
697{
698 TSyError err= LOCERR_OK;
699 vMin= 0;
700
701 string value;
702 while (RemoveField( capa, CA_MinVersion"MINVERSION", value )) {
703 CVersion minVersion= VersionNr( value ); // the minimum required version of the plugin
704 CVersion engVersion= EngineSDKVersion () | 0x000000ff; // the engine's version with max build number
705 if (engVersion<minVersion) err = LOCERR_TOOOLD;
706 if (vMin <minVersion) vMin= minVersion;
707
708 DB_Callback mCB= &fCB.Callback;
709 DEBUG_INT ( mCB, MyDB"DBApi", "MinVersionCheck", "engine=%08X >= %08X / err=%d",
710 engVersion, minVersion, err );
711 if (err) break;
712 } // while
713
714 return err;
715} // MinVersionCheck
716
717
718// Connect to internally linked library or external DLL, dependent on <aIsLib> and <allowDLL>
719TSyError TDB_Api_Config::Connect( cAppCharP aModName, CContext &globContext,
720 cAppCharP mContextName,
721 bool aIsLib, bool allowDLL )
722{
723 TSyError err;
724 string gcs;
725
726 if (fConnected) Disconnect();
727 if (fConnected) return DB_Error; // still connected ? => error
728
729 cAppCharP x= "";
730 DB_Callback mCB= &fCB.Callback;
731 CContext* mc= &mCB->mContext; // store it at a temporary var
732 *mc= 0;
733
734 clear();
735 is_lib = IsLib( aModName );
736 fModName= aModName; // make a local copy
737
738 if (aIsLib) { // && !is_lib) : special cases like "[aaa]!bbb" => "[[aaa]!bbb]"
739 fModName= AddBracks( aModName );
740 is_lib = true;
741 } // if
742
743 GlobContext* g;
744 GlobContext* gp;
745
746 if (CB_OK( mCB,8 )) { // <gContext> available ?
747 mCB->gContext= globContext;
748
749 for (int i= 1; i<=3; i++) { // create 3 empty elements
750 gp= new GlobContext; // create and init a new record
751 gp->ref = NULL__null;
752 gp->next= NULL__null;
753 gp->cnt = 0;
754 strcpy( gp->refName,"" );
755
756 if (!mCB->gContext) mCB->gContext= (CContext)gp; // assign it
757 else {
758 g= (GlobContext*)mCB->gContext; // or add it to the end of the chain
759 while (g->next!=NULL__null) g= (GlobContext*)g->next;
760 g->next= gp;
761 } // if
762 } // for
763 } // if
764
765 do { // exit part
766 if (!is_lib) {
767 x= "(DLL)";
768 if (!allowDLL) { err= DB_Forbidden; break; }
769 } // if
770
771 WithSubSystem ( fModName, fModMain, fModSub );
772 bool in_bracks= CutBracks( fModMain ); // "[aaa xx]" => "aaa xx"
773 fOptions= fModMain;
774 NextToken ( fOptions, fModMain, " " ); // separate <mOptions>
775 fModName= fModMain;
776 CutBracks( fModMain );
777 fPlugin = fModMain;
778
779 if (in_bracks) fModName = AddBracks( fModName );
780
781 /* this mode is no longer supported ( moduleName:globContext ) */
782 /* keep it for compatiblity */
783 if (globContext) {
784 g= (GlobContext*)globContext;
785 while (g!=NULL__null) {
786 if (strcmp( g->refName,"" )!=0) { // at least one field is set
787 fModMain+= ":" + RefStr( globContext ); break;
788 } // if
789
790 g= g->next;
791 } // while
792 } // if
793
794 if (!fOptions.empty()) fModMain+= " " + fOptions;
795
796 // create some downwards compatibility info
797 if (CB_OK( mCB,4 )) {
798 if (allowDLL) mCB->allow_DLL_legacy= 0xffff; // Assign DLL allowance info
799 else mCB->allow_DLL_legacy= 0x0000;
800
801 if (CB_OK( mCB,5 )) {
802 mCB->allow_DLL= mCB->allow_DLL_legacy;
803 } // if
804 } // if
805
806 // Connect "Module_CreateContext" and "Module_Version" first, to take decisions
807 err= ConnectModule( fMod, fModName.c_str() ); if (err) break;
808 err= DBApi_Assign( "", &m.start, sizeof(m.start), Plugin_Start"plugin_start" ); if (err) break;
809
810 Version_Func pv= (Version_Func)m.start.Module_Version;
811 fSDKversion= pv( 0 ); // get the plugin's version before making the first tests
812 DEBUG_INT( mCB,MyDB"DBApi", "Connect", "fSDKversion=%s", VersionStr( fSDKversion ).c_str() );
813
814 string sn= fModSub;
815 if (sn=="[#]" && !(fPlugin=="logger")) sn= ""; // remove the recursion breaker
816
817 CreateM_Func p= (CreateM_Func)m.start.Module_CreateContext;
818 err= p( &mContext, fModMain.c_str(), sn.c_str(), mContextName, mCB );
819 if (err==LOCERR_ALREADY) err= LOCERR_OK; // this is not an error, just avoid multiple assignment
820 DEBUG_INT( mCB,MyDB"DBApi", "Connect", "mContext=%08X err=%d", mContext,err );
821
822 if (err) break;
823 fMODversion= pv( mContext ); // get the plugin's version before making the first tests
824 mCB->cContext = mContext; // assign for the callback mechanism
825 if (*mc==0) *mc= mContext; // assign for session & datastores, if not already in use (e.g. for JNI)
826 //err= VersionCheck(); if (err) break;
827
828 TDB_Api_Str aCapa;
829 err= Capabilities( aCapa ); if (err) break;
830 cAppCharP ca= aCapa.c_str();
831 CVersion vMin;
832 err= MinVersionCheck( ca, vMin ); if (err) break;
833 fADMIN_Info= FlagOK( ca, CA_ADMIN_Info"ADMIN_Info", true );
834
835 GetField( ca, CA_Description"DESCRIPTION", fDesc );
836 GetField( ca, CA_GlobContext"GlobContext", gcs ); // is there a global context inside ?
837
838 // !Supported( VP_EngineVersionParam ): only JNI signature changes
839 // !Supported( VP_MD5_Nonce_IN ): only JNI signature changes
840
841 cAppCharP vda= Plugin_DS_Admin_Map"plugin_datastoreadmin_map";
842 if (!Supported( VP_InsertMapItem )) vda= Plugin_DS_Admin_OLD"plugin_datastoreadmin_OLD";
843 cAppCharP vdd= Plugin_DS_Data"plugin_datastore";
844 if (!Supported( VP_FLI_DSS )) vdd= Plugin_DS_Data_OLD2"plugin_datastore_OLD2";
845 if (!Supported( VP_ResumeToken )) vdd= Plugin_DS_Data_OLD1"plugin_datastore_OLD1";
846 cAppCharP vdb= Plugin_DS_Blob"plugin_datablob";
847 if (!Supported( VP_BLOB_JSignature )) vdb= Plugin_DS_Blob_OLD2"plugin_datablob_OLD2"; // new BLOB signature
848 if (!Supported( VP_DeleteBlob )) vdb= Plugin_DS_Blob_OLD1"plugin_datablob_OLD1";
849
850 //---- module ---------------------------------
851 if (!err) err= DBApi_Assign( "", &m.param, sizeof(m.param), Plugin_Param"plugin_param" );
852 if (!err) err= DBApi_Assign( "", &m, sizeof(m) );
853
854 //---- session --------------------------------
855 if (!err && FlagOK ( ca, Plugin_Session"plugin_se" )) {
856 err= DBApi_Assign( ca, &m.se, sizeof(m.se), Plugin_Session"plugin_se" );
857
858 if (!err && ( FlagOK ( ca, Plugin_SE_Auth"plugin_sessionauth" ) ||
859 FlagOK ( ca, Plugin_DV_Admin"plugin_deviceadmin" ) )) {
860 err= DBApi_Assign( ca, &m.se.seAuth, sizeof(m.se.seAuth), Plugin_SE_Auth"plugin_sessionauth" );
861 if (!err) err= DBApi_Assign( ca, &m.se.dvAdmin, sizeof(m.se.dvAdmin), Plugin_DV_Admin"plugin_deviceadmin" );
862
863 if (!err && Supported( VP_GetDBTime )) {
864 err= DBApi_Assign( ca, &m.se.dvTime, sizeof(m.se.dvTime), Plugin_DV_DBTime"plugin_dbtime" );
865 } // if
866 } // if
867
868 if (!err && Supported( VP_AdaptItem )) {
869 err= DBApi_Assign( ca, &m.se.seAdapt, sizeof(m.se.seAdapt), Plugin_SE_Adapt"plugin_sessionadapt" );
870 } // if
871 } // if
872
873 //---- datastore ------------------------------
874 if (!err && FlagOK ( ca, Plugin_Datastore"plugin_ds" )) {
875 if (!err && DSConnect( ca )) {
876 err= DBApi_Assign( ca, &m.ds, sizeof(m.ds), Plugin_Datastore"plugin_ds" );
877 } // if
878
879 if (!err && ( FlagOK ( ca, Plugin_DS_Admin"plugin_datastoreadmin" ) ||
880 FlagOK ( ca, Plugin_DS_Data"plugin_datastore" ) )) {
881 err= DBApi_Assign( ca, &m.ds.dsg, sizeof(m.ds.dsg), Plugin_DS_General"plugin_datageneral" );
882 if (!err) err= DBApi_Assign( ca, &m.ds.dsBlob, sizeof(m.ds.dsBlob), vdb );
883 } // if
884
885 if (!err && FlagOK ( ca, Plugin_DS_Admin"plugin_datastoreadmin" )) {
886 bool asK= FlagOK ( ca, CA_AdminAsKey"ADMIN_AS_KEY", true );
887 if (asK) err= DBApi_Assign( ca, &m.ds.dsAdm.key, sizeof(m.ds.dsAdm.key),Plugin_DS_Admin_Key"plugin_datastoreadmin_key" );
888
889 bool asS= !asK || FlagBoth( ca, CA_AdminAsKey"ADMIN_AS_KEY" );
890 if (asS) err= DBApi_Assign( ca, &m.ds.dsAdm.str, sizeof(m.ds.dsAdm.str),Plugin_DS_Admin_Str"plugin_datastoreadmin_str" );
891
892 if (!err) err= DBApi_Assign( ca, &m.ds.dsAdm.map, sizeof(m.ds.dsAdm.map), vda );
893 } // if
894
895 if (!err) err= DBApi_Assign( ca, &m.ds.dsData, sizeof(m.ds.dsData), vdd );
896
897 if (!err && FlagOK ( ca, Plugin_DS_Data"plugin_datastore" )) {
898 bool asK= FlagOK ( ca, CA_ItemAsKey"ITEM_AS_KEY", true );
899 if (asK) err= DBApi_Assign( ca, &m.ds.dsData.key,sizeof(m.ds.dsData.key),Plugin_DS_Data_Key"plugin_datastore_key" );
900
901 bool asS= !asK || FlagBoth( ca, CA_ItemAsKey"ITEM_AS_KEY" );
902 if (asS) err= DBApi_Assign( ca, &m.ds.dsData.str,sizeof(m.ds.dsData.str),Plugin_DS_Data_Str"plugin_datastore_str" );
903 } // if
904
905 if (!err && Supported( VP_AdaptItem )) {
906 err= DBApi_Assign( ca, &m.ds.dsAdapt, sizeof(m.ds.dsAdapt), Plugin_DS_Adapt"plugin_dataadapt" );
907 } // if
908 } // if
909
910 //---- ui context -----------------------------
911 if (!err && FlagOK( ca,Plugin_UI"plugin_ui", true )) {
912 err= DBApi_Assign( ca, &m.ui, sizeof(m.ui), Plugin_UI"plugin_ui" );
913 } // if
914 } while (false); // end exit part
915
916 if (err) clear();
917
918 if (CB_OK( mCB,8 )) { globContext= mCB->gContext; // <gContext> available ?
919 DeleteGlobContext ( globContext, mCB, true ); // remove elements with empty text and no ref
920 mCB->gContext= globContext; // can be fully removed again (gContext==0)
921 }
922 else {
923 // ---- the old fashioned way to do it ----
924 if (!gcs.empty()) {
925 uIntPtr u;
926 HexStrToUIntPtr( gcs.c_str(), u );
927
928 if (!globContext) globContext= (CContext)u;
929 if (globContext!=(CContext)u) { // link it if more than one element
930 GlobContext* gc= (GlobContext*)globContext;
931 gc->next= (GlobContext*)u;
932 } // if
933 } // if
934 // -----------------------------------------
935 } // if
936
937 string s= "ok";
938 if (err) {
939 char f[ 15 ];
940 sprintf( f, "err=%d", err );
941 s= f;
942 } // if
943
944 DEBUG_INT( mCB,MyDB"DBApi","Connect", "%s '%s' %-9s", s.c_str(), fModName.c_str(), x );
945 fConnected= !err;
946 return err;
947} // Connect
948
949
950/* Get the plug-in's version number */
951long TDB_Api_Config::Version() { return fMODversion; }
952
953
954/* Get the plug-in's capabilities */
955TSyError TDB_Api_Config::Capabilities( TDB_Api_Str &aCapa )
956{
957 typedef TSyError (*CapabFunc)( CContext mContext,
958 appCharP *mCapabilities );
959
960 aCapa.DisposeStr();
961 CapabFunc p= (CapabFunc)m.start.Module_Capabilities;
962 TSyError err= p( mContext, const_cast<char **>(&aCapa.fStr) );
963 if (!err) AssignStr( aCapa );
964 return err;
965} // Capabilities
966
967
968/* Check, if <version_feature> is supported
969 * NOTE: For the SyncML engine internally everything is supported
970 * This will be reflected with the fact that the engine's
971 * version is alway much much higher
972 */
973bool TDB_Api_Config::Supported( CVersion versionFeature ) {
974 return Feature_Supported( versionFeature, fSDKversion );
975} // Supported
976
977
978
979TSyError TDB_Api_Config::PluginParams( cAppCharP mConfigParams )
980{
981 typedef TSyError (*PlugProc)( CContext mContext,
982 cAppCharP mConfigParams, CVersion engineVersion );
983//typedef TSyError (*OLD_PlugProc)( CContext mContext,
984// cAppCharP mConfigParams ); // w/o <engineVersion>
985
986 TSyError err;
987 if (!fConnected) return DB_Error;
988
989 /*
990 // new param supported for Plugin Version >= 1.0.X.4
991 if (Supported( VP_EngineVersionParam )) {
992 PlugProc p= (PlugProc)m.param.Module_PluginParams;
993 err= p( mContext, mConfigParams, EngineSDKVersion() );
994 }
995 else {
996 OLD_PlugProc p= (OLD_PlugProc)m.param.Module_PluginParams; // w/o the SDK version parameter
997 err= p( mContext, mConfigParams );
998 } // if
999 */
1000
1001 PlugProc p= (PlugProc)m.param.Module_PluginParams;
1002 err= p( mContext, mConfigParams, EngineSDKVersion() );
1003 if (err==LOCERR_ALREADY) err= LOCERR_OK;
1004 return err;
1005} // PluginParams
1006
1007
1008
1009// Set the SDK version
1010// *** override the internal version number / for test only ***
1011void TDB_Api_Config::SetVersion( long versionNr )
1012{
1013 fTSTversion= versionNr;
1014 DEBUG_INT( &fCB.Callback, MyDB"DBApi","SetVersion", "%08X", fTSTversion );
1015} // SetVersion
1016
1017
1018
1019TSyError TDB_Api_Config::Disconnect()
1020{
1021 if (!fConnected) return DB_Error; // avoid double free
1022
1023 // remove all still allocated elements before removing the content
1024 while (!fSList.empty()) DisposeStr( *fSList.front() );
1025
1026 Context_Func p= (Context_Func)m.Module_DeleteContext;
1027 TSyError err= p( mContext );
1028
1029 fModName= "";
1030 DisconnectModule( fMod );
1031 fConnected= false;
1032 return err;
1033} // Disconnect
1034
1035
1036
1037/* ------------------------------------------------------------------------- */
1038void DispGlobContext( CContext &globContext, DB_Callback mCB )
1039{
1040 cAppCharP DGC= "DispGlobContext";
1041
1042 GlobContext* g= (GlobContext*)globContext;
1043 DEBUG_Exotic_DB ( mCB, MyDB"DBApi",DGC, "g=%s mCB->gContext=%s",
1044 RefStr( g ).c_str(), RefStr( mCB->gContext ).c_str() );
1045 while (g!=NULL__null) {
1046 GlobContext* nx= g->next;
1047 DEBUG_Exotic_DB( mCB, MyDB"DBApi",DGC, "g=%s g->ref=%s g->cnt=%-3d '%s'",
1048 RefStr( g ).c_str(), RefStr( g->ref ).c_str(),
1049 g->cnt, g->refName );
1050 g= nx;
1051 } // while
1052
1053 DEBUG_Exotic_DB ( mCB, MyDB"DBApi",DGC, "(eof)" );
1054} // DispGlobContext
1055
1056
1057// mCB->gContext will not be touched here
1058void DeleteGlobContext( CContext &globContext, DB_Callback mCB, bool emptyTextOnly )
1059{
1060 DispGlobContext( globContext, mCB );
1061 DEBUG_Exotic_DB( mCB, "","DeleteGlobContext", "" );
1062
1063 GlobContext* ls= NULL__null;
1064 GlobContext* gs= (GlobContext*)globContext;
1065 GlobContext* g= gs;
1066 while (g!=NULL__null) {
1067 GlobContext* nx= g->next;
1068
1069 bool remCond= g->ref==NULL__null && (!emptyTextOnly || strcmp( g->refName,"" )==0);
1070 if (remCond) {
1071 if (gs==g) gs = nx; // go forward if first element removed
1072 else ls->next= nx;
1073
1074 delete g;
1075 g= ls;
1076 } // if
1077
1078 ls= g;
1079 g = nx;
1080 } // while
1081
1082 globContext= (CContext)gs;
1083 DispGlobContext( globContext, mCB );
1084} // DeleteGlobContext
1085
1086
1087
1088/* ---- "DB_Api_Session" implementation ------------------------------------ */
1089TDB_Api_Session::TDB_Api_Session()
1090{
1091 sCreated= false;
1092 sContext= 0;
1093
1094 appPointer modu= NULL__null;
1095 connect_no_dbapi( modu, sNo_dbapi ); // the empty connector is default as well
1096 dm= &sNo_dbapi; // and assign it
1097
1098 sPwMode= Password_Mode_Undefined;
1099} // constructor
1100
1101
1102
1103/* Create a context for a new session */
1104TSyError TDB_Api_Session::CreateContext( cAppCharP sessionName, TDB_Api_Config &config )
1105{
1106 if (sCreated) return DB_Forbidden;
1107 sSessionName= sessionName; // make a local copy
1108
1109 dm= &config.m; // assign reference to the methods
1110 CreateS_Func p= (CreateS_Func)dm->se.Session_CreateContext;
1111
1112 DB_Callback sCB= &fCB.Callback;
1113 CContext* sc= &sCB->sContext; // store it at a temporary var
1114 *sc= 0; // set it to check later, if changed
1115
1116 string vers= VersionStr( config.fSDKversion );
1117 if (config.fMODversion!=config.fSDKversion) vers+= " / " + VersionStr( config.fMODversion );
1118
1119 DEBUG_INT( sCB,MyDB"DBApi",Se_CC"Session_CreateContext", "desc='%s', vers=%s", config.fDesc.c_str(),
1120 vers.c_str() );
1121
1122 sCB->cContext= config.mContext; // inherit info
1123 sContext= 0; sCB->mContext= config.fCB.Callback.mContext;
1124 TSyError err= p( &sContext, sSessionName.c_str(), sCB );
1125 if (!err) {
1126 sCreated= true;
1127 if (*sc==0) *sc= sContext; // assign for datastores, but only if not assigned in plug-in module
1128 } // if
1129
1130 return LOCERR_OK; // workaround to avoid problems w/o a session
1131 return err;
1132} // CreateContext
1133
1134
1135
1136// ---------------------------------------------------------------------
1137void TDB_Api_Session::DisposeStr( TDB_Api_Str &s )
1138// Session str disposer
1139{
1140 fSList.remove( &s ); // remove it from the list first to avoid double free
1141
1142 s.AssignStr( sContext, (DisposeProc)dm->se.Session_DisposeObj );
1143 s.DisposeStr();
1144} // DisposeStr
1145
1146
1147static void Local_Session_DisposeStr( CContext sObj, void* memory )
1148/* Local wrapper, because it must be DisposeProc type and can't be C++ method */
1149{
1150 TDB_Api_Session* s= (TDB_Api_Session*)sObj;
1151 TDB_Api_Str* u= (TDB_Api_Str*)memory;
1152 s->DisposeStr ( *u );
1153} // Local_Session_DisposeStr
1154
1155
1156void TDB_Api_Session::AssignStr( TDB_Api_Str &s )
1157{
1158 if (s.fStr==NULL__null) return;
1159
1160 s.AssignStr( (CContext)this, Local_Session_DisposeStr, true );
1161 fSList.push_back( &s ); // add the element to the list
1162} // AssignStr
1163
1164
1165
1166// --------------------------------------------------------------------------------
1167TSyError TDB_Api_Session::CheckDevice( cAppCharP deviceID, TDB_Api_Str &sDevKey,
1168 TDB_Api_Str &nonce )
1169{
1170 typedef TSyError (*ChkDevFunc)( CContext sContext,
1171 cAppCharP deviceID,
1172 appCharP *sDevKey,
1173 appCharP *nonce );
1174
1175 sDevKey.DisposeStr();
1176 nonce.DisposeStr();
1177 ChkDevFunc p= (ChkDevFunc)dm->se.dvAdmin.Session_CheckDevice;
1178 TSyError err= p( sContext, deviceID, &sDevKey.fStr, &nonce.fStr );
1179 if (!err) { AssignStr( sDevKey );
1180 AssignStr( nonce ); }
1181 return err;
1182} // CheckDevice
1183
1184
1185
1186TSyError TDB_Api_Session::GetNonce( TDB_Api_Str &nonce )
1187{
1188 typedef TSyError (*GetNcFunc)( CContext sContext,
1189 appCharP *nonce );
1190
1191 nonce.DisposeStr();
1192 GetNcFunc p= (GetNcFunc)dm->se.dvAdmin.Session_GetNonce;
1193 TSyError err= p( sContext, &nonce.fStr );
1194 if (!err) AssignStr( nonce );
1195 return err;
1196} // GetNonce
1197
1198
1199
1200TSyError TDB_Api_Session::SaveNonce( cAppCharP nonce )
1201{
1202 SvInfo_Func p= (SvInfo_Func)dm->se.dvAdmin.Session_SaveNonce;
1203 TSyError err= p( sContext, nonce );
1204 return err;
1205} // SaveNonce
1206
1207
1208
1209TSyError TDB_Api_Session::SaveDeviceInfo( cAppCharP aDeviceInfo )
1210{
1211 SvInfo_Func p= (SvInfo_Func)dm->se.dvAdmin.Session_SaveDeviceInfo;
1212 TSyError err= p( sContext, aDeviceInfo );
1213 return err;
1214} // SaveDeviceInfo
1215
1216
1217TSyError TDB_Api_Session::GetDBTime( TDB_Api_Str &currentDBTime )
1218{
1219 typedef TSyError (*DBTimeFunc)( CContext sContext,
1220 appCharP *currentDBTime );
1221
1222 currentDBTime.DisposeStr();
1223 DBTimeFunc p= (DBTimeFunc)dm->se.dvTime.Session_GetDBTime;
1224 TSyError err= p( sContext, &currentDBTime.fStr );
1225 if (!err) AssignStr( currentDBTime );
1226 return err;
1227} // GetDBTime
1228
1229
1230#ifdef SYSYNC_ENGINE1
1231// No 'lineartime_t' available for standalone
1232TSyError TDB_Api_Session::GetDBTime( lineartime_t &currentDBTime, GZones* g )
1233{
1234 timecontext_t tctx = 0;
1235 TDB_Api_Str s;
1236 TSyError err= GetDBTime( s ); currentDBTime= 0;
1237 if (!err && !ISO8601StrToTimestamp ( s.c_str(), currentDBTime, tctx )) return DB_Error;
1238
1239 TzConvertTimestamp( currentDBTime, tctx, TCTX_UTC((timecontext_t) ((tctx_tz_UTC) | TCTX_SYMBOLIC_TZ)), g, TCTX_SYSTEM((timecontext_t) ((tctx_tz_system) | TCTX_SYMBOLIC_TZ)) );
1240 return err;
1241} // GetDBTime
1242#endif
1243
1244
1245
1246/* ---- Login Handling ---------------------------------------- */
1247sInt32 TDB_Api_Session::PasswordMode()
1248{
1249 if (sContext==0) return Password_Mode_Undefined;
1250 PwMode_Func p= (PwMode_Func)dm->se.seAuth.Session_PasswordMode;
1251 sPwMode= p( sContext );
1252
1253 /* calculate it always
1254 if (sPwMode==Password_Mode_Undefined) {
1255 ...
1256 } // if
1257 */
1258
1259 return sPwMode;
1260} // PasswordMode
1261
1262
1263
1264/*! XXX_IN modes */
1265TSyError TDB_Api_Session::Login( cAppCharP sUsername,
1266 cAppCharP sPassword, TDB_Api_Str &sUsrKey )
1267{
1268 switch (PasswordMode()) {
1269 case Password_ClrText_IN :
1270 case Password_MD5_Nonce_IN : break;
1271 default : return DB_Forbidden; // !sCreated is covered here
1272 } // switch
1273
1274 sUsrKey.DisposeStr();
1275 Login_Func p= (Login_Func)dm->se.seAuth.Session_Login;
1276 TSyError err= p( sContext, sUsername, (char**)&sPassword, &sUsrKey.fStr );
1277 if (!err) AssignStr( sUsrKey );
1278 return err;
1279} // Login
1280
1281
1282/*! XXX_OUT modes */
1283TSyError TDB_Api_Session::Login( cAppCharP sUsername,
1284 TDB_Api_Str &sPassword, TDB_Api_Str &sUsrKey )
1285{
1286 switch (PasswordMode()) {
1287 case Password_ClrText_OUT :
1288 case Password_MD5_OUT : break;
1289 default : return DB_Forbidden; // !sCreated is covered here
1290 } // switch
1291
1292 sPassword.DisposeStr();
1293 sUsrKey.DisposeStr();
1294 Login_Func p= (Login_Func)dm->se.seAuth.Session_Login;
1295 TSyError err= p( sContext, sUsername, &sPassword.fStr, &sUsrKey.fStr );
1296 if (!err) { AssignStr( sPassword );
1297 AssignStr( sUsrKey ); }
1298 return err;
1299} // Login (overloaded)
1300
1301
1302
1303TSyError TDB_Api_Session::Logout()
1304{
1305 if (sContext==0) return LOCERR_OK;
1306 Context_Func p= (Context_Func)dm->se.seAuth.Session_Logout;
1307 return p( sContext );
1308} // Logout
1309
1310
1311
1312/* ---- General session routines ------------------------------- */
1313void TDB_Api_Session::AssignChanged( string &a, TDB_Api_Str &u ) {
1314 if (a.c_str()!=u.fStr) { a= u.fStr; AssignStr( u ); } // assign for destruction afterwards
1315} // AssignChanged
1316
1317
1318TSyError TDB_Api_Session::AdaptItem( string &sItemData1,
1319 string &sItemData2,
1320 string &sLocalVars, uInt32 sIdentifier )
1321{
1322 TDB_Api_Str updItemData1( sItemData1 );
1323 TDB_Api_Str updItemData2( sItemData2 );
1324 TDB_Api_Str updLocalVars( sLocalVars );
1325
1326 Adapt_Func p= (Adapt_Func)dm->se.seAdapt.Session_AdaptItem;
1327 TSyError err= p( sContext, &updItemData1.fStr,
1328 &updItemData2.fStr,
1329 &updLocalVars.fStr, sIdentifier );
1330
1331 AssignChanged( sItemData1, updItemData1 );
1332 AssignChanged( sItemData2, updItemData2 );
1333 AssignChanged( sLocalVars, updLocalVars );
1334
1335 return err;
1336} // AdaptItem
1337
1338
1339void TDB_Api_Session::ThreadMayChangeNow()
1340{
1341 VoidProc p= (VoidProc)dm->se.Session_ThreadMayChangeNow;
1342 p( sContext );
1343} // ThreadMayChangeNow
1344
1345
1346
1347void TDB_Api_Session::DispItems( bool allFields, cAppCharP specificItem )
1348{
1349 DispProc p= (DispProc)dm->se.Session_DispItems;
1350 p( sContext, allFields,specificItem );
1351} // DispItems
1352
1353
1354
1355/* ---- Delete the session context ---------------------------- */
1356TSyError TDB_Api_Session::DeleteContext()
1357{
1358 if (!sCreated) return DB_Forbidden;
1359
1360 // remove all still allocated elements before removing the content
1361 while (!fSList.empty()) DisposeStr( *fSList.front() );
1362
1363 Context_Func p= (Context_Func)dm->se.Session_DeleteContext;
1364 TSyError err= p( sContext );
1365 if (!err) sCreated= false;
1366 return err;
1367} // DeleteContext
1368
1369
1370
1371/* ---- "DB_Api" implementation ------------------------------------------- */
1372TDB_Api::TDB_Api()
1373{
1374 fCreated= false;
1375
1376 appPointer modu= NULL__null;
1377 connect_no_dbapi( modu, fNo_dbapi ); // the empty connector is default as well
1378 dm= &fNo_dbapi; // and assign it
1379} // constructor
1380
1381
1382TDB_Api::~TDB_Api()
1383{
1384 DeleteContext();
1385} // destructor
1386
1387
1388
1389// --- open section -------------------------------------
1390TSyError TDB_Api::CreateContext( cAppCharP aContextName, bool asAdmin, TDB_Api_Config* config,
1391 cAppCharP sDevKey,
1392 cAppCharP sUsrKey, TDB_Api_Session* session )
1393{
1394 if (fCreated || !config ||
1395 !config->fConnected) return DB_Forbidden;
1396
1397 string cNam= aContextName;
1398 if (cNam.empty()) return DB_NotFound; // empty <aContextName> is not allowed
1399
1400 fConfig= config; // make a local copy
1401
1402 /* inherit the context information of module and session */
1403 fCB.Callback.cContext= config->mContext;
1404 fCB.Callback.mContext= config->fCB.Callback.mContext;
1405 if (session) { fCB.Callback.sContext= session->fCB.Callback.sContext; }
1406 fDevKey = sDevKey;
1407 fUsrKey = sUsrKey;
1408
1409 if (config->fADMIN_Info && asAdmin) cNam+= ADMIN_Ident" ADMIN";
1410
1411 fContext= 0; dm= &config->m;
1412 CreateD_Func p= (CreateD_Func)dm->ds.CreateContext;
1413 TSyError err= p( &fContext, cNam.c_str(), &fCB.Callback, fDevKey.c_str(),
1414 fUsrKey.c_str() );
1415 if (!err) fCreated= true;
1416 return err;
1417} // CreateContext
1418
1419
1420
1421TSyError TDB_Api::RunContext( cAppCharP aContextName, bool asAdmin,
1422 SequenceProc sequence,
1423 string &token, TDB_Api_Config* config,
1424 cAppCharP sDevKey,
1425 cAppCharP sUsrKey, TDB_Api_Session* session )
1426{
1427 TSyError err= CreateContext( aContextName, asAdmin, config,
1428 sDevKey,sUsrKey, session ); if (err) return err;
1429 TSyError dErr;
1430 TDB_Api_Str newToken;
1431
1432 err= StartDataRead( token.c_str() );
1433 // no sequence is allowed as well
1434 if (!err && sequence!=NULL__null) {
1435 err = sequence( *this );
1436 dErr= EndDataWrite( !err, newToken ); if (!err) err= dErr;
1437 token= newToken.c_str();
1438 newToken.DisposeStr();
1439 } // if
1440
1441 dErr= DeleteContext(); if (!err) err= dErr;
1442 return err;
1443} // RunContext
1444
1445
1446
1447// ---------------------------------------------------------------------
1448// returns the nth config data field, which is supported (and activated)
1449// result= 0: no filter supported.
1450uInt32 TDB_Api::ContextSupport( cAppCharP aContextRules )
1451{
1452 Text_Func p= (Text_Func)dm->ds.dsg.ContextSupport;
1453 return p( fContext,aContextRules );
1454} // ContextSupport
1455
1456
1457// returns the nth filter rule, which is supported (and activated)
1458// result= 0: no filter supported.
1459uInt32 TDB_Api::FilterSupport ( cAppCharP aFilterRules )
1460{
1461 Text_Func p= (Text_Func)dm->ds.dsg.FilterSupport;
1462 return p( fContext,aFilterRules );
1463} // FilterSupport
1464
1465
1466
1467// ---------------------------------------------------------------------
1468// Str disposer
1469void TDB_Api::DisposeStr( TDB_Api_Str &s )
1470{
1471 fSList.remove( &s ); // remove it from the list first to avoid double free
1472
1473 s.AssignStr( fContext, (DisposeProc)dm->ds.DisposeObj );
1474 s.DisposeStr();
1475} // DisposeStr
1476
1477
1478
1479// Local wrapper, because it must be DisposeProc type and can't be C++ method
1480static void Local_DisposeStr( CContext aObj, void* memory )
1481{
1482 TDB_Api* a= (TDB_Api*)aObj;
1483 TDB_Api_Str* u= (TDB_Api_Str*)memory; a->DisposeStr( *u );
1484} // Local_DisposeStr
1485
1486
1487
1488void TDB_Api::AssignStr( TDB_Api_Str &s )
1489{
1490 if (s.fStr==NULL__null) return;
1491
1492 s.AssignStr( (CContext)this, Local_DisposeStr, true );
1493 fSList.push_back( &s ); // add the element to the list
1494} // AssignStr
1495
1496
1497
1498// ---------------------------------------------------------------------
1499// Blk disposer
1500void TDB_Api::DisposeBlk( TDB_Api_Blk &b )
1501{
1502 fBList.remove( &b ); // remove it from the list first to avoid double free
1503
1504 b.AssignBlk( fContext, (DisposeProc)dm->ds.DisposeObj );
1505 b.DisposeBlk();
1506} // DisposeBlk
1507
1508
1509
1510// Local wrapper, because it must be DisposeProc type and can't be C++ method
1511static void Local_DisposeBlk( CContext aObj, void* memory )
1512{
1513 TDB_Api* a= (TDB_Api*)aObj;
1514 TDB_Api_Blk* u= (TDB_Api_Blk*)memory; a->DisposeBlk( *u );
1515} // Local_DisposeBlk
1516
1517
1518
1519void TDB_Api::AssignBlk( TDB_Api_Blk &b )
1520{
1521 if (b.fPtr==NULL__null) return;
1522
1523 b.AssignBlk( (CContext)this, Local_DisposeBlk, true );
1524 fBList.push_back( &b ); // add the element to the list
1525} // AssignBlk
1526
1527
1528
1529// ---------------------------------------------------------------------
1530void TDB_Api::GetItemID( TDB_Api_ItemID &aID, TDB_Api_Str &aItemID )
1531{
1532 aItemID= aID.item;
1533 fSList.remove( &aID.item );
1534 aID.item.fStr= NULL__null; // avoid double delete
1535 AssignStr ( aItemID );
1536
1537 aID.parent.DisposeStr(); // not used
1538} // GetItemID
1539
1540
1541
1542// --- admin section -------------------------------
1543// This function gets the stored information about the record with the four paramters:
1544// <sDevKey>, <sUsrKey> (taken from the session context)
1545// <aLocDB>, <aRemDB>.
1546TSyError TDB_Api::LoadAdminData( cAppCharP aLocDB,
1547 cAppCharP aRemDB, TDB_Api_Str &adminData )
1548{
1549 adminData.DisposeStr();
1550 LoadAdm_SFunc p= (LoadAdm_SFunc)dm->ds.dsAdm.str.LoadAdminData;
1551 TSyError err= p( fContext, aLocDB,aRemDB, &adminData.fStr );
1552 if (!err) AssignStr( adminData );
1553 return err;
1554} // LoadAdminData
1555
1556TSyError TDB_Api::LoadAdminDataAsKey( cAppCharP aLocDB,
1557 cAppCharP aRemDB, KeyH aAdminKey )
1558{
1559 LoadAdm_KFunc p= (LoadAdm_KFunc)dm->ds.dsAdm.key.LoadAdminDataAsKey;
1560 TSyError err= p( fContext, aLocDB,aRemDB, aAdminKey );
1561 return err;
1562} // LoadAdminDataAsKey
1563
1564
1565//! This functions stores the new <adminData> for this context
1566TSyError TDB_Api::SaveAdminData( cAppCharP adminData )
1567{
1568 SaveAdm_SFunc p= (SaveAdm_SFunc)dm->ds.dsAdm.str.SaveAdminData;
1569 return p( fContext, adminData );
1570} // SaveAdminData
1571
1572TSyError TDB_Api::SaveAdminData_AsKey( KeyH adminKey )
1573{
1574 SaveAdm_KFunc p= (SaveAdm_KFunc)dm->ds.dsAdm.key.SaveAdminDataAsKey;
1575 return p( fContext, adminKey );
1576} // SaveAdminDataAsKey
1577
1578
1579
1580// --- Map table handling ----------------------------
1581//! Get a map item of this context
1582bool TDB_Api::ReadNextMapItem( TDB_Api_MapID &mID, bool aFirst )
1583{
1584 MapID_Struct u;
1585 mID.localID.DisposeStr();
1586 mID.remoteID.DisposeStr();
1587
1588 RdNMap_Func p= (RdNMap_Func)dm->ds.dsAdm.map.ReadNextMapItem;
1589 bool ok= p( fContext, &u, aFirst );
1590 if (ok) {
1591 mID.localID.fStr = u.localID; AssignStr( mID.localID );
1592 mID.remoteID.fStr= u.remoteID; AssignStr( mID.remoteID );
1593 mID.flags = u.flags;
1594 mID.ident = u.ident;
1595 } // if
1596
1597 return ok;
1598} // ReadNextMapItem
1599
1600
1601
1602// Insert a map item of this context
1603TSyError TDB_Api::InsertMapItem( MapID mID )
1604{
1605 InsMap_Func p= (InsMap_Func)dm->ds.dsAdm.map.InsertMapItem;
1606 return p( fContext, mID );
1607} // InsertMapItem
1608
1609
1610
1611// Update a map item of this context
1612TSyError TDB_Api::UpdateMapItem( MapID mID )
1613{
1614 UpdMap_Func p= (UpdMap_Func)dm->ds.dsAdm.map.UpdateMapItem;
1615 return p( fContext, mID );
1616} // UpdateMapItem
1617
1618
1619
1620// Delete a map item of this context
1621TSyError TDB_Api::DeleteMapItem( MapID mID )
1622{
1623 DelMap_Func p= (DelMap_Func)dm->ds.dsAdm.map.DeleteMapItem;
1624 return p( fContext, mID );
1625} // DeleteMapItem
1626
1627
1628
1629// --- general -----------------------------------------
1630void TDB_Api::ThreadMayChangeNow()
1631{
1632 VoidProc p= (VoidProc)dm->ds.dsg.ThreadMayChangeNow;
1633 p( fContext );
1634} // ThreadMayChangeNow
1635
1636
1637
1638//! This functions gets the <logData> for this datastore
1639void TDB_Api::WriteLogData( cAppCharP logData )
1640{
1641 SvInfo_Func p= (SvInfo_Func)dm->ds.dsg.WriteLogData;
1642 p( fContext, logData );
1643} // WriteLogData
1644
1645
1646
1647void TDB_Api::DispItems( bool allFields, cAppCharP specificItem )
1648{
1649 DispProc p= (DispProc)dm->ds.dsg.DispItems;
1650 p( fContext, allFields, specificItem );
1651} // DispItems
1652
1653
1654void TDB_Api::AssignChanged( string &a, TDB_Api_Str &u ) {
1655 if (a.c_str()!=u.fStr) { a= u.fStr; AssignStr( u ); } // assign for destruction afterwards
1656} // AssignChanged
1657
1658
1659TSyError TDB_Api::AdaptItem( string &sItemData1,
1660 string &sItemData2,
1661 string &sLocalVars, uInt32 sIdentifier )
1662{
1663 TDB_Api_Str updItemData1( sItemData1 );
1664 TDB_Api_Str updItemData2( sItemData2 );
1665 TDB_Api_Str updLocalVars( sLocalVars );
1666
1667 Adapt_Func p= (Adapt_Func)dm->ds.dsAdapt.AdaptItem;
1668 TSyError err= p( fContext, &updItemData1.fStr,
1669 &updItemData2.fStr,
1670 &updLocalVars.fStr, sIdentifier );
1671
1672 AssignChanged( sItemData1, updItemData1 );
1673 AssignChanged( sItemData2, updItemData2 );
1674 AssignChanged( sLocalVars, updLocalVars );
1675
1676 return err;
1677} // AdaptItem
1678
1679
1680
1681// --- read section ------------------------------------
1682TSyError TDB_Api::StartDataRead( cAppCharP lastToken, cAppCharP resumeToken )
1683{
1684 typedef TSyError (*OLD_SDR_Func)( CContext aContext, cAppCharP lastToken );
1685
1686 if (!fCreated) return DB_Fatal; // <fConfig> is not defined, if not created
1687
1688 // new param supported for Plugin Version >= 1.0.6.X
1689 if (fConfig->Supported( VP_ResumeToken )) {
1690 SDR_Func p= (SDR_Func)dm->ds.dsData.StartDataRead;
1691 return p( fContext, lastToken,resumeToken );
1692 }
1693 else {
1694 OLD_SDR_Func p= (OLD_SDR_Func)dm->ds.dsData.StartDataRead;
1695 return p( fContext, lastToken );
1696 } // if
1697} // StartDataRead
1698
1699
1700// overloaded for using DB:Api_ItemID class
1701TSyError TDB_Api::ReadNextItem( TDB_Api_ItemID &aID,
1702 TDB_Api_Str &aItemData, int &aStatus, bool aFirst )
1703{
1704 ItemID_Struct u;
1705 sInt32 lStatus;
1706
1707 aID.item.DisposeStr();
1708 aID.parent.DisposeStr();
1709 aItemData.DisposeStr();
1710
1711 u.parent= NULL__null; // works correctly, even if not implemented on user side
1712 RdNItemSFunc p= (RdNItemSFunc)dm->ds.dsData.str.ReadNextItem;
1713 TSyError err= p( fContext, &u, &aItemData.fStr, &lStatus, aFirst ); aStatus= (int)lStatus;
1714 if (err || aStatus==ReadNextItem_EOF) return err;
1715
1716 aID.item.fStr = u.item; AssignStr( aID.item );
1717 aID.parent.fStr= u.parent; AssignStr( aID.parent );
1718 AssignStr( aItemData );
1719
1720 // additional info for test
1721//DEBUG_Exotic_DB( fCB, aID.item.c_str(), "ReadNextItem", aItemData.c_str() );
1722
1723 return LOCERR_OK;
1724} // ReadNextItem
1725
1726
1727// overloaded for mode w/o aParentID
1728TSyError TDB_Api::ReadNextItem( TDB_Api_Str &aItemID,
1729 TDB_Api_Str &aItemData,
1730 int &aStatus, bool aFirst )
1731{
1732 TDB_Api_ItemID aID;
1733
1734 TSyError err= ReadNextItem( aID, aItemData, aStatus, aFirst );
1735 if (err || aStatus==ReadNextItem_EOF) return err;
1736 GetItemID ( aID, aItemID );
1737 return LOCERR_OK;
1738} // ReadNextItem
1739
1740
1741TSyError TDB_Api::ReadNextItemAsKey( TDB_Api_ItemID &aID,
1742 KeyH aItemKey,
1743 int &aStatus, bool aFirst )
1744{
1745 ItemID_Struct u;
1746 sInt32 lStatus;
1747
1748 aID.item.DisposeStr();
1749 aID.parent.DisposeStr();
1750
1751 u.parent= NULL__null; // works correctly, even if not implemented on user side
1752 RdNItemKFunc p= (RdNItemKFunc)dm->ds.dsData.key.ReadNextItemAsKey;
1753 TSyError err= p( fContext, &u, aItemKey, &lStatus, aFirst ); aStatus= (int) lStatus;
1754 if (err || aStatus==ReadNextItem_EOF) return err;
1755
1756 aID.item.fStr = u.item; AssignStr( aID.item );
1757 aID.parent.fStr= u.parent; AssignStr( aID.parent );
1758
1759 return LOCERR_OK;
1760} // ReadNextItemAsKey
1761
1762
1763
1764// overloaded for using ItemID_Struct
1765TSyError TDB_Api::ReadItem( ItemID_Struct aID, TDB_Api_Str &aItemData )
1766{
1767 aItemData.DisposeStr();
1768 Rd_ItemSFunc p= (Rd_ItemSFunc)dm->ds.dsData.str.ReadItem;
1769 TSyError err= p( fContext, &aID, &aItemData.fStr );
1770 if (!err) AssignStr ( aItemData );
1771 return err;
1772} // ReadItem
1773
1774
1775// overloaded for <aItemID>,<aParentID> call
1776TSyError TDB_Api::ReadItem( cAppCharP aItemID,
1777 cAppCharP aParentID, TDB_Api_Str &aItemData )
1778{
1779 ItemID_Struct a; a.item = (char*) aItemID;
1780 a.parent= (char*)aParentID;
1781 return ReadItem( a, aItemData );
1782} // ReadItem
1783
1784
1785// overloaded for mode w/o aParentID
1786TSyError TDB_Api::ReadItem( cAppCharP aItemID, TDB_Api_Str &aItemData ) {
1787 return ReadItem( aItemID,"", aItemData );
1788} // ReadItem
1789
1790
1791TSyError TDB_Api::ReadItemAsKey( ItemID_Struct aID, KeyH aItemKey )
1792{
1793 Rd_ItemKFunc p= (Rd_ItemKFunc)dm->ds.dsData.key.ReadItemAsKey;
1794 TSyError err= p( fContext, &aID, aItemKey );
1795 return err;
1796} // ReadItemAsKey
1797
1798
1799
1800// overloaded for using ItemID_Struct
1801TSyError TDB_Api::ReadBlob( ItemID_Struct aID,
1802 cAppCharP aBlobID, memSize blkSize,
1803 TDB_Api_Blk &aBlk, memSize &totSize, bool aFirst, bool &aLast )
1804{
1805 typedef TSyError (*Rd_Blob_Func)( CContext aContext,
1806 cItemID aID,
1807 cAppCharP aBlobID,
1808 appPointer *blkPtr,
1809 memSize *blkSize,
1810 memSize *totSize,
1811 bool aFirst,
1812 bool *aLast );
1813 aBlk.DisposeBlk();
1814 aBlk.fSize= blkSize;
1815
1816 Rd_Blob_Func p= (Rd_Blob_Func)dm->ds.dsBlob.ReadBlob;
1817 TSyError err= p( fContext, &aID,aBlobID,
1818 &aBlk.fPtr,&aBlk.fSize, &totSize, aFirst,&aLast );
1819 if (!err) aBlk.AssignBlk( fContext, (DisposeProc)dm->ds.DisposeObj );
1820 return err;
1821} // ReadBlob
1822
1823
1824// overloaded for <aItemID>,<aParentID> call
1825TSyError TDB_Api::ReadBlob( cAppCharP aItemID,
1826 cAppCharP aParentID,
1827 cAppCharP aBlobID, memSize blkSize,
1828 TDB_Api_Blk &aBlk, memSize &totSize, bool aFirst, bool &aLast )
1829{
1830 ItemID_Struct a; a.item = (char*)aItemID;
1831 a.parent= (char*)aParentID;
1832 return ReadBlob( a, aBlobID, blkSize,aBlk,totSize, aFirst,aLast );
1833} // ReadBlob
1834
1835
1836// overloaded for mode w/o aParentID
1837TSyError TDB_Api::ReadBlob( cAppCharP aItemID,
1838 cAppCharP aBlobID, memSize blkSize,
1839 TDB_Api_Blk &aBlk, memSize &totSize, bool aFirst, bool &aLast ) {
1840 return ReadBlob( aItemID,"", aBlobID, blkSize,aBlk,totSize, aFirst,aLast );
1841} // ReadBlob
1842
1843
1844
1845TSyError TDB_Api::EndDataRead()
1846{
1847 EDR_Func p= (EDR_Func)dm->ds.dsData.EndDataRead;
1848 return p( fContext );
1849} // EndDataRead
1850
1851
1852
1853// --- write section ----------------------------------------------------------------------
1854TSyError TDB_Api::StartDataWrite()
1855{
1856 SDW_Func p= (SDW_Func)dm->ds.dsData.StartDataWrite;
1857 return p( fContext );
1858} // StartDataWrite
1859
1860
1861
1862// Assign <aID> to <newID>, ignore new parent
1863void TDB_Api::Assign_ItemID( TDB_Api_ItemID &newID, ItemID_Struct &a, cAppCharP parentID )
1864{
1865 newID.item.fStr= a.item;
1866 AssignStr ( newID.item );
1867
1868 if (a.parent!=parentID) { // remove it, if explicitely allocated
1869 newID.parent.fStr= a.parent; // parent can't be changed !!
1870 AssignStr( newID.parent );
1871 newID.parent.DisposeStr();
1872 } // if
1873
1874 newID.parent.LocalAlloc( fContext, parentID );
1875} // Assign_ItemID
1876
1877
1878// -------------------------------------------------------------------------
1879// overloaded for <aParentID> call
1880TSyError TDB_Api::InsertItem( cAppCharP aItemData, cAppCharP parentID,
1881 TDB_Api_ItemID &newID )
1882{
1883 newID.item.DisposeStr();
1884 newID.parent.DisposeStr();
1885
1886 ItemID_Struct a;
1887 a.item = NULL__null;
1888 a.parent= (char*)parentID; // works correctly, even if not implemented on user side
1889
1890 InsItemSFunc p= (InsItemSFunc)dm->ds.dsData.str.InsertItem;
1891 TSyError err= p( fContext, aItemData, &a );
1892 if (!err || err==DB_DataMerged || err==DB_DataReplaced || err==DB_Conflict) {
1893 Assign_ItemID( newID, a, parentID );
1894 } // if
1895
1896 return err;
1897} // InsertItem
1898
1899
1900// overloaded for mode w/o aParentID
1901TSyError TDB_Api::InsertItem( cAppCharP aItemData, TDB_Api_Str &newItemID )
1902{
1903 TDB_Api_ItemID nID;
1904 TSyError err= InsertItem( aItemData, "",nID );
1905 if (!err || err==DB_DataMerged || err==DB_DataReplaced || err==DB_Conflict) {
1906 GetItemID( nID, newItemID );
1907 } // if
1908
1909 return err;
1910} // InsertItem
1911
1912
1913TSyError TDB_Api::InsertItemAsKey( KeyH aItemKey, cAppCharP parentID,
1914 TDB_Api_ItemID &newID )
1915{
1916 newID.item.DisposeStr();
1917 newID.parent.DisposeStr();
1918
1919 ItemID_Struct a;
1920 a.item = NULL__null;
1921 a.parent= (char*)parentID; // works correctly, even if not implemented on user side
1922
1923 InsItemKFunc p= (InsItemKFunc)dm->ds.dsData.key.InsertItemAsKey;
1924 TSyError err= p( fContext, aItemKey, &a );
1925 if (!err || err==DB_DataMerged || err==DB_DataReplaced || err==DB_Conflict) {
1926 Assign_ItemID( newID, a, parentID );
1927 } // if
1928
1929 return err;
1930} // InsertItemAsKey
1931
1932
1933
1934// -------------------------------------------------------------------------
1935// overloaded for using ItemID_Struct
1936TSyError TDB_Api::UpdateItem( cAppCharP aItemData, ItemID_Struct aID,
1937 TDB_Api_ItemID &updID )
1938{
1939 updID.item.DisposeStr();
1940 updID.parent.DisposeStr();
1941
1942 ItemID_Struct u;
1943 u.item = NULL__null;
1944 u.parent= (char*)aID.parent; // works correctly, even if not implemented on user side
1945
1946 UpdItemSFunc p= (UpdItemSFunc)dm->ds.dsData.str.UpdateItem;
1947 TSyError err= p( fContext, aItemData, &aID,&u );
1948 if (!err) {
1949 Assign_ItemID( updID, u, aID.parent );
1950 } // if
1951
1952 return err;
1953} // UpdateItem
1954
1955
1956// overloaded for <aItemID>,<aParentID> call
1957TSyError TDB_Api::UpdateItem( cAppCharP aItemData,
1958 cAppCharP aItemID,
1959 cAppCharP aParentID, TDB_Api_ItemID &updID )
1960{
1961 ItemID_Struct a; a.item = (char*)aItemID;
1962 a.parent= (char*)aParentID;
1963 return UpdateItem( aItemData, a,updID );
1964} // UpdateItem
1965
1966
1967// overloaded for mode w/o aParentID
1968TSyError TDB_Api::UpdateItem( cAppCharP aItemData, cAppCharP aItemID,
1969 TDB_Api_Str &updItemID )
1970{
1971 TDB_Api_ItemID uID;
1972 TSyError err= UpdateItem( aItemData, aItemID,"", uID );
1973 if (!err) GetItemID( uID, updItemID );
1974 return err;
1975} // UpdateItem
1976
1977
1978TSyError TDB_Api::UpdateItem( cAppCharP aItemData, TDB_Api_ItemID &aID,
1979 TDB_Api_ItemID &updID )
1980{
1981 return UpdateItem( aItemData, (char*)aID.item.c_str(),
1982 (char*)aID.parent.c_str(), updID );
1983} // UpdateItem
1984
1985
1986
1987TSyError TDB_Api::UpdateItemAsKey( KeyH aItemKey, ItemID_Struct aID,
1988 TDB_Api_ItemID &updID )
1989{
1990 updID.item.DisposeStr();
1991 updID.parent.DisposeStr();
1992
1993 ItemID_Struct u;
1994 u.item = NULL__null;
1995 u.parent= (char*)aID.parent; // works correctly, even if not implemented on user side
1996
1997 UpdItemKFunc p= (UpdItemKFunc)dm->ds.dsData.key.UpdateItemAsKey;
1998 TSyError err= p( fContext, aItemKey, &aID,&u );
1999 if (!err) {
2000 Assign_ItemID( updID, u, aID.parent );
2001 } // if
2002
2003 return err;
2004} // UpdateItemAsKey
2005
2006
2007TSyError TDB_Api::UpdateItemAsKey( KeyH aItemKey, TDB_Api_ItemID &aID,
2008 TDB_Api_ItemID &updID )
2009{
2010 ItemID_Struct a; a.item = (char*)aID.item.c_str();
2011 a.parent= (char*)aID.parent.c_str();
2012 return UpdateItemAsKey( aItemKey, a, updID );
2013} // UpdateItemAsKey
2014
2015
2016
2017// -------------------------------------------------------------------------
2018// overloaded for using ItemID_Struct
2019TSyError TDB_Api::MoveItem( ItemID_Struct aID, cAppCharP newParID )
2020{
2021 MovItem_Func p= (MovItem_Func)dm->ds.dsData.ind.MoveItem;
2022 return p( fContext, &aID,newParID );
2023} // MoveItem
2024
2025
2026// overloaded for <aItemID>,<aParentID> call
2027TSyError TDB_Api::MoveItem( cAppCharP aItemID,
2028 cAppCharP aParentID, cAppCharP newParID )
2029{
2030 ItemID_Struct a; a.item = (appCharP) aItemID;
2031 a.parent= (appCharP)aParentID;
2032 return MoveItem( a, newParID );
2033} // MoveItem
2034
2035
2036
2037// -------------------------------------------------------------------------
2038// overloaded for using ItemID_Struct
2039TSyError TDB_Api::DeleteItem( ItemID_Struct aID )
2040{
2041 DelItem_Func p= (DelItem_Func)dm->ds.dsData.ind.DeleteItem;
2042 return p( fContext, &aID );
2043} // DeleteItem
2044
2045
2046// overloaded for <aItemID>,<aParentID> call
2047TSyError TDB_Api::DeleteItem( cAppCharP aItemID, cAppCharP aParentID )
2048{
2049 ItemID_Struct a; a.item = (char*)aItemID;
2050 a.parent= (char*)aParentID;
2051 return DeleteItem( a );
2052} // DeleteItem
2053
2054
2055// overloaded for using TDB_Api_ItemID
2056// <aID> object will not be removed here
2057TSyError TDB_Api::DeleteItem( TDB_Api_ItemID &aID )
2058{
2059 return DeleteItem( (char*)aID.item.c_str(),
2060 (char*)aID.parent.c_str() );
2061} // DeleteItem
2062
2063
2064
2065// -------------------------------------------------------------------------
2066TSyError TDB_Api::FinalizeLocalID( ItemID_Struct aID,
2067 TDB_Api_ItemID &updID )
2068{
2069 updID.item.DisposeStr();
2070 updID.parent.DisposeStr();
2071
2072 if (!fConfig->Supported( VP_FLI_DSS )) return LOCERR_NOTIMP;
2073
2074 ItemID_Struct u;
2075 u.item = NULL__null;
2076 u.parent= (char*)aID.parent; // works correctly, even if not implemented on user side
2077
2078 FLI_Func p= (FLI_Func)dm->ds.dsData.ind.FinalizeLocalID;
2079 TSyError err= p( fContext, &aID,&u );
2080 if (!err) {
2081 Assign_ItemID( updID, u, aID.parent );
2082 } // if
2083
2084 return err;
2085} // FinalizeLocalID
2086
2087
2088TSyError TDB_Api::FinalizeLocalID( TDB_Api_ItemID &aID,
2089 TDB_Api_ItemID &updID ) {
2090 return FinalizeLocalID( (char*)aID.item.c_str(),
2091 (char*)aID.parent.c_str(), updID );
2092} // FinalizeLocalID
2093
2094
2095TSyError TDB_Api::FinalizeLocalID( cAppCharP aItemID,
2096 TDB_Api_Str &updItemID )
2097{
2098 TDB_Api_ItemID uID;
2099 TSyError err= FinalizeLocalID( aItemID,"", uID );
2100 if (!err) GetItemID( uID, updItemID );
2101 return err;
2102} // FinalizeLocalID
2103
2104
2105TSyError TDB_Api::FinalizeLocalID( cAppCharP aItemID,
2106 cAppCharP aParentID,
2107 TDB_Api_ItemID &updID )
2108{
2109 ItemID_Struct a; a.item = (char*)aItemID;
2110 a.parent= (char*)aParentID;
2111 return FinalizeLocalID( a, updID );
2112} // FinalizeLocalID
2113
2114
2115
2116TSyError TDB_Api::DeleteSyncSet()
2117{
2118 if (!fConfig->Supported( VP_FLI_DSS )) return LOCERR_NOTIMP;
2119
2120 DelSS_Func p= (DelSS_Func)dm->ds.dsData.ind.DeleteSyncSet;
2121 return p( fContext );
2122} // DeleteSyncSet
2123
2124
2125
2126// -------------------------------------------------------------------------
2127// overloaded for using ItemID_Struct
2128TSyError TDB_Api::WriteBlob( ItemID_Struct aID, cAppCharP aBlobID,
2129 appPointer blkPtr, memSize blkSize,
2130 memSize totSize, bool aFirst, bool aLast )
2131{
2132 typedef TSyError (*Wr_BlobFunc)( CContext aContext,
2133 cItemID aID,
2134 cAppCharP aBlobID,
2135 appPointer blkPtr,
2136 memSize blkSize,
2137 memSize totSize,
2138 bool aFirst,
2139 bool aLast );
2140
2141 Wr_BlobFunc p= (Wr_BlobFunc)dm->ds.dsBlob.WriteBlob;
2142 return p( fContext, &aID,aBlobID, blkPtr,blkSize,totSize, aFirst,aLast );
2143} // WriteBlob
2144
2145
2146// overloaded for mode with <aItemID> and <aParentID>
2147TSyError TDB_Api::WriteBlob( cAppCharP aItemID,
2148 cAppCharP aParentID, cAppCharP aBlobID,
2149 appPointer blkPtr, memSize blkSize,
2150 memSize totSize, bool aFirst, bool aLast )
2151{
2152 ItemID_Struct a; a.item = (char*)aItemID;
2153 a.parent= (char*)aParentID;
2154 return WriteBlob( a,aBlobID, blkPtr,blkSize,totSize, aFirst,aLast );
2155} // WriteBlob
2156
2157
2158// overloaded for mode w/o <aParentID>
2159TSyError TDB_Api::WriteBlob( cAppCharP aItemID, cAppCharP aBlobID,
2160 appPointer blkPtr, memSize blkSize,
2161 memSize totSize, bool aFirst, bool aLast )
2162{
2163 return WriteBlob( aItemID,"", aBlobID, blkPtr,blkSize,totSize, aFirst,aLast );
2164} // WriteBlob
2165
2166
2167// overloaded for using TDB_Api_ItemID
2168TSyError TDB_Api::WriteBlob( TDB_Api_ItemID &aID, cAppCharP aBlobID,
2169 appPointer blkPtr, memSize blkSize,
2170 memSize totSize, bool aFirst, bool aLast )
2171{
2172 return WriteBlob( (char*)aID.item.c_str(),
2173 (char*)aID.parent.c_str(), aBlobID, blkPtr,blkSize,totSize, aFirst,aLast );
2174} // WriteBlob
2175
2176
2177
2178// -------------------------------------------------------------------------
2179// overloaded for using ItemID_Struct
2180TSyError TDB_Api::DeleteBlob( ItemID_Struct aID, cAppCharP aBlobID )
2181{
2182 typedef TSyError (*DelBlobFunc)( CContext aContext,
2183 cItemID aID,
2184 cAppCharP aBlobID );
2185
2186 DelBlobFunc p= (DelBlobFunc)dm->ds.dsBlob.DeleteBlob;
2187 return p( fContext, &aID,aBlobID );
2188} // DeleteBlob
2189
2190
2191// overloaded for mode with <aItemID> and <aParentID>
2192TSyError TDB_Api::DeleteBlob( cAppCharP aItemID,
2193 cAppCharP aParentID,
2194 cAppCharP aBlobID )
2195{
2196 ItemID_Struct a; a.item = (char*)aItemID;
2197 a.parent= (char*)aParentID;
2198 return DeleteBlob( a,aBlobID );
2199} // DeleteBlob
2200
2201
2202// overloaded for mode w/o <aParentID>
2203TSyError TDB_Api::DeleteBlob( cAppCharP aItemID,
2204 cAppCharP aBlobID )
2205{
2206 return DeleteBlob( aItemID,"", aBlobID );
2207} // DeleteBlob
2208
2209
2210// overloaded for using TDB_Api_ItemID
2211TSyError TDB_Api::DeleteBlob( TDB_Api_ItemID &aID, cAppCharP aBlobID )
2212{
2213 return DeleteBlob( (char*)aID.item.c_str(),
2214 (char*)aID.parent.c_str(), aBlobID );
2215} // DeleteBlob
2216
2217
2218
2219// -------------------------------------------------------------------------
2220TSyError TDB_Api::EndDataWrite( bool success, TDB_Api_Str &newToken )
2221{
2222 newToken.DisposeStr();
2223 EDW_Func p= (EDW_Func)dm->ds.dsData.EndDataWrite;
2224 TSyError err= p( fContext, success, &newToken.fStr );
2225 if (!err) {
2226 AssignStr( newToken );
2227 if (!success) err= DB_Fatal;
2228 } // if
2229
2230 return err;
2231} // EndDataWrite
2232
2233
2234
2235// --- close section --------------------------------
2236TSyError TDB_Api::DeleteContext()
2237{
2238 if (!fCreated) return DB_Forbidden;
2239
2240 // remove all still allocated elements before removing the content
2241 while (!fSList.empty()) DisposeStr( *fSList.front() );
2242 while (!fBList.empty()) DisposeBlk( *fBList.front() );
2243
2244 Context_Func p= (Context_Func)dm->ds.DeleteContext;
2245 TSyError err= p( fContext );
2246 if (!err) fCreated= false;
2247 return err;
2248} // DeleteContext
2249
2250
2251} // namespace
2252/* eof */