1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #include "prefix_file.h" |
14 | |
15 | #ifdef ENGINEINTERFACE_SUPPORT1 |
16 | |
17 | #include "engineinterface.h" |
18 | #include "syserial.h" |
19 | #include "syncappbase.h" |
20 | #include "SDK_util.h" |
21 | |
22 | namespace sysync { |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | TSettingsKeyImpl::TSettingsKeyImpl( |
30 | TEngineInterface *aEngineInterfaceP |
31 | ) : |
32 | fEngineInterfaceP(aEngineInterfaceP), |
33 | fImplicitParentKeyP(NULL__null) |
34 | { |
35 | |
36 | fCharSet = fEngineInterfaceP->fCharSet; |
37 | fBigEndian = fEngineInterfaceP->fBigEndian; |
38 | fLineEndMode = fEngineInterfaceP->fLineEndMode; |
39 | |
40 | fTimeMode = TMODE_LINEARTIME+TMODE_FLAG_FLOATING; |
41 | } |
42 | |
43 | |
44 | TSettingsKeyImpl::~TSettingsKeyImpl() |
45 | { |
46 | |
47 | |
48 | |
49 | if (fImplicitParentKeyP) { |
50 | delete fImplicitParentKeyP; |
51 | fImplicitParentKeyP=NULL__null; |
52 | } |
53 | } |
54 | |
55 | |
56 | |
57 | |
58 | TSyError TSettingsKeyImpl::OpenKeyByPath( |
59 | TSettingsKeyImpl *&aSettingsKeyP, |
60 | cAppCharP aPath, uInt16 aMode, |
61 | bool aImplicit |
62 | ) |
63 | { |
64 | TSyError sta; |
65 | TSettingsKeyImpl *subKeyP=NULL__null; |
66 | |
67 | |
68 | aSettingsKeyP=NULL__null; |
69 | |
70 | if (aPath==NULL__null) return LOCERR_WRONGUSAGE; |
71 | |
72 | while (*aPath==SETTINGSKEY_PATH_SEPARATOR'/') aPath++; |
73 | |
74 | cAppCharP e = aPath; |
75 | while (*e && *e!=SETTINGSKEY_PATH_SEPARATOR'/') e++; |
76 | |
77 | sta = OpenSubKeyByName(aSettingsKeyP,aPath,e-aPath,aMode); |
78 | if (sta == LOCERR_OK) { |
79 | |
80 | |
81 | if (aImplicit) { |
82 | aSettingsKeyP->fImplicitParentKeyP = this; |
83 | } |
84 | |
85 | aSettingsKeyP->SetTextMode(fCharSet, fLineEndMode,fBigEndian); |
86 | aSettingsKeyP->SetTimeMode(fTimeMode); |
87 | |
88 | while (*e==SETTINGSKEY_PATH_SEPARATOR'/') e++; |
89 | if (*e) { |
90 | |
91 | |
92 | sta = aSettingsKeyP->OpenKeyByPath(subKeyP,e,aMode,true); |
93 | if (subKeyP != NULL__null) { |
94 | |
95 | |
96 | |
97 | aSettingsKeyP = subKeyP; |
98 | } |
99 | } |
100 | } |
101 | |
102 | return sta; |
103 | } |
104 | |
105 | |
106 | const uInt16 engineCharSets[numCharSets] = { |
107 | CHS_UNKNOWN, |
108 | CHS_ASCII, |
109 | CHS_ANSI, |
110 | CHS_ISO_8859_1, |
111 | CHS_UTF8, |
112 | CHS_UTF16, |
113 | #ifdef CHINESE_SUPPORT |
114 | CHS_GB2312, |
115 | CHS_CP936 |
116 | #endif |
117 | }; |
118 | |
119 | const uInt16 engineLineEndModes[numLineEndModes] = { |
120 | LEM_NONE, |
121 | LEM_UNIX, |
122 | LEM_MAC, |
123 | LEM_DOS, |
124 | LEM_CSTR, |
125 | LEM_FILEMAKER |
126 | }; |
127 | |
128 | |
129 | |
130 | TSyError TSettingsKeyImpl::SetTextMode(uInt16 aCharSet, uInt16 aLineEndMode, bool aBigEndian) |
131 | { |
132 | |
133 | uInt16 chs; |
134 | for (chs=0; chs<numCharSets; chs++) { |
135 | if (engineCharSets[chs]==aCharSet) break; |
136 | } |
137 | if (chs==numCharSets) return LOCERR_BADPARAM; |
138 | |
139 | uInt16 lem; |
140 | for (lem=0; lem<numLineEndModes; lem++) { |
141 | if (engineLineEndModes[lem]==aLineEndMode) break; |
142 | } |
143 | if (lem==numLineEndModes) return LOCERR_BADPARAM; |
144 | |
145 | fCharSet = (TCharSets)chs; |
146 | fLineEndMode = (TLineEndModes)lem; |
147 | |
148 | fBigEndian = aBigEndian; |
149 | return LOCERR_OK; |
150 | } |
151 | |
152 | |
153 | |
154 | |
155 | TSyError TSettingsKeyImpl::GetValueByID( |
156 | sInt32 aID, sInt32 aArrayIndex, uInt16 aValType, |
157 | appPointer aBuffer, memSize aBufSize, memSize &aValSize |
158 | ) |
159 | { |
160 | TSyError sta; |
161 | string valStr; |
162 | cAppCharP txt; |
163 | string convStr; |
164 | sInt64 tempInt=0; |
165 | lineartime_t tempTime; |
166 | timecontext_t tctx; |
167 | |
168 | |
169 | uInt16 valType = GetValueType(aID); |
170 | if (valType==VALTYPE_UNKNOWN) return DB_NotFound; |
171 | |
172 | if ( |
173 | (aValType == VALTYPE_BUF) || |
174 | ((valType == aValType) && |
175 | (valType != VALTYPE_TEXT || (fCharSet==chs_utf8 && fLineEndMode==lem_cstr)) && |
176 | (valType != VALTYPE_TIME64 || ((fTimeMode & TMODE_MODEMASK)==TMODE_LINEARTIME)) ) |
177 | ) { |
178 | |
179 | if (aValType == VALTYPE_TEXT) { |
180 | if (!aBuffer || aBufSize==0) { |
181 | |
182 | return GetValueInternal(aID,aArrayIndex,NULL__null,0,aValSize); |
183 | } |
184 | else { |
185 | |
186 | |
187 | sta = GetValueInternal(aID,aArrayIndex,aBuffer,aBufSize-1,aValSize); |
188 | |
189 | ((appCharP)aBuffer)[aBufSize-1] = 0; |
190 | |
191 | if (sta==LOCERR_OK && aValSize<aBufSize) |
192 | ((appCharP)aBuffer)[aValSize] = 0; |
193 | |
194 | if (sta==LOCERR_OK && aValSize>aBufSize-1) { |
195 | sta = LOCERR_TRUNCATED; |
196 | aValSize = aBufSize-1; |
197 | } |
198 | return sta; |
199 | } |
200 | } |
201 | else { |
202 | |
203 | sta = GetValueInternal(aID,aArrayIndex,aBuffer,aBufSize,aValSize); |
204 | if (sta==LOCERR_OK && aBufSize && aBuffer && aValSize>aBufSize) { |
205 | |
206 | if (aValType==VALTYPE_BUF) { |
207 | |
208 | sta = LOCERR_TRUNCATED; |
209 | aValSize = aBufSize; |
210 | } |
211 | else { |
212 | |
213 | |
214 | sta = LOCERR_BUFTOOSMALL; |
215 | } |
216 | } |
217 | return sta; |
218 | } |
219 | } |
220 | |
221 | |
222 | memSize valSiz; |
223 | sta = GetValueInternal(aID,aArrayIndex,NULL__null,0,valSiz); |
224 | if (sta!=LOCERR_OK) return sta; |
225 | |
226 | memSize bufSiz = valSiz+1; |
227 | uInt8P bufP = (uInt8P) malloc(bufSiz); |
228 | bufP[valSiz]=0; |
229 | if (bufP==NULL__null) return LOCERR_OUTOFMEM; |
230 | |
231 | sta = GetValueInternal(aID,aArrayIndex,bufP,bufSiz,valSiz); |
232 | if (sta==LOCERR_OK) { |
233 | |
234 | |
235 | switch (valType) { |
236 | |
237 | case VALTYPE_TIME64: |
238 | tempTime = *((lineartime_t *)bufP); |
239 | tctx = (fTimeMode & TMODE_FLAG_UTC)==0 ? TCTX_SYSTEM((timecontext_t) ((tctx_tz_system) | TCTX_SYMBOLIC_TZ)) : TCTX_UTC((timecontext_t) ((tctx_tz_UTC) | TCTX_SYMBOLIC_TZ)); |
240 | |
241 | if ((fTimeMode & TMODE_FLAG_FLOATING)==0) |
242 | TzConvertTimestamp(tempTime,TCTX_UTC((timecontext_t) ((tctx_tz_UTC) | TCTX_SYMBOLIC_TZ)),tctx,getEngineInterface()->getSyncAppBase()->getAppZones()); |
243 | else |
244 | tctx = TCTX_UNKNOWN((timecontext_t) ((tctx_tz_unknown) | TCTX_SYMBOLIC_TZ)); |
245 | |
246 | if (aValType==VALTYPE_TEXT) { |
247 | |
248 | TimestampToISO8601Str(valStr, tempTime, tctx, false, false); |
249 | txt = valStr.c_str(); |
250 | goto textConv; |
251 | } |
252 | |
253 | if (tempTime==noLinearTime) { |
254 | |
255 | sta=DB_NoContent; |
256 | break; |
257 | } |
258 | |
259 | switch (fTimeMode & TMODE_MODEMASK) { |
260 | case TMODE_LINEARDATE: |
261 | tempInt = tempTime / linearDateToTimeFactor; |
262 | goto intConv; |
263 | case TMODE_UNIXTIME_MS: |
264 | tempInt = tempTime-UnixToLineartimeOffset; |
265 | goto intConv; |
266 | case TMODE_UNIXTIME: |
267 | tempInt = (tempTime-UnixToLineartimeOffset)/secondToLinearTimeFactor; |
268 | goto intConv; |
269 | default : |
270 | tempInt = tempTime; |
271 | goto intConv; |
272 | } |
273 | break; |
274 | |
275 | case VALTYPE_INT8: |
276 | tempInt = *((sInt8 *)bufP); |
277 | goto intConv; |
278 | case VALTYPE_INT16: |
279 | tempInt = *((sInt16 *)bufP); |
280 | goto intConv; |
281 | case VALTYPE_INT32: |
282 | tempInt = *((sInt32 *)bufP); |
283 | goto intConv; |
284 | case VALTYPE_INT64: |
285 | tempInt = *((sInt64 *)bufP); |
286 | intConv: |
287 | |
288 | switch (aValType) { |
289 | case VALTYPE_INT8: |
290 | case VALTYPE_ENUM: |
291 | aValSize=1; |
292 | if (aBufSize<aValSize) sta=LOCERR_BUFTOOSMALL; |
293 | else *((sInt8 *)aBuffer) = tempInt; |
294 | break; |
295 | case VALTYPE_INT16: |
296 | aValSize=2; |
297 | if (aBufSize<aValSize) sta=LOCERR_BUFTOOSMALL; |
298 | else *((sInt16 *)aBuffer) = tempInt; |
299 | break; |
300 | case VALTYPE_INT32: |
301 | case VALTYPE_TIME32: |
302 | aValSize=4; |
303 | if (aBufSize<aValSize) sta=LOCERR_BUFTOOSMALL; |
304 | else *((sInt32 *)aBuffer) = tempInt; |
305 | break; |
306 | case VALTYPE_INT64: |
307 | case VALTYPE_TIME64: |
308 | aValSize=8; |
309 | if (aBufSize<aValSize) sta=LOCERR_BUFTOOSMALL; |
310 | else *((sInt64 *)aBuffer) = tempInt; |
311 | break; |
312 | case VALTYPE_TEXT: |
313 | StringObjPrintf(valStr,PRINTF_LLD"%lld",PRINTF_LLD_ARG(tempInt)static_cast<long long>(tempInt)); |
314 | txt = valStr.c_str(); |
315 | goto textConv; |
316 | break; |
317 | } |
318 | break; |
319 | |
320 | case VALTYPE_TEXT: |
321 | txt = (cAppCharP)bufP; |
322 | textConv: |
323 | |
324 | if (aValType!=VALTYPE_TEXT) |
325 | sta = LOCERR_WRONGUSAGE; |
326 | else { |
327 | |
328 | if (fCharSet==chs_utf16) { |
329 | if (!appendUTF8ToUTF16ByteString( |
330 | txt, |
331 | convStr, |
332 | fBigEndian, |
333 | fLineEndMode, |
334 | aBufSize>0 ? aBufSize-2 : 0 |
335 | )) |
336 | sta = LOCERR_TRUNCATED; |
337 | |
338 | aValSize=convStr.size(); |
339 | |
340 | convStr+=(char)0; |
341 | } |
342 | else { |
343 | |
344 | if (!appendUTF8ToString( |
345 | txt, |
346 | convStr, |
347 | fCharSet, |
348 | fLineEndMode, |
349 | qm_none, |
350 | aBufSize>0 ? aBufSize-1 : 0 |
351 | )) |
352 | sta = LOCERR_TRUNCATED; |
353 | |
354 | aValSize=convStr.size(); |
355 | } |
356 | |
357 | if (aBufSize>0) { |
358 | |
359 | memcpy(aBuffer,(appPointer)convStr.c_str(),convStr.size()+1>aBufSize ? aBufSize : convStr.size()+1); |
360 | } |
361 | else { |
362 | |
363 | sta = LOCERR_OK; |
364 | } |
365 | } |
366 | break; |
367 | } |
368 | } |
369 | |
370 | |
371 | free(bufP); |
372 | |
373 | return sta; |
374 | } |
375 | |
376 | |
377 | |
378 | TSyError TSettingsKeyImpl::SetValueByID( |
379 | sInt32 aID, sInt32 aArrayIndex, uInt16 aValType, |
380 | cAppPointer aBuffer, memSize aValSize |
381 | ) |
382 | { |
383 | TSyError sta = LOCERR_OK; |
384 | sInt64 tempInt; |
385 | lineartime_t tempTime; |
386 | timecontext_t tctx; |
387 | appPointer bP; |
388 | memSize siz; |
389 | string convStr; |
390 | |
391 | |
392 | uInt16 valType = GetValueType(aID); |
393 | if (valType==VALTYPE_UNKNOWN) return DB_NotFound; |
394 | |
395 | if (aValType == VALTYPE_TEXT && aValSize == memSize(-1)) { |
396 | if (fCharSet==chs_utf16) |
397 | return LOCERR_NOTIMP; |
398 | |
399 | else |
400 | aValSize = strlen((char *)aBuffer); |
401 | } |
402 | |
403 | if ( |
404 | (aValType == VALTYPE_BUF) || |
405 | ((valType == aValType) && |
406 | (valType != VALTYPE_TEXT || (fCharSet==chs_utf8 && fLineEndMode==lem_cstr)) && |
407 | (valType != VALTYPE_TIME64 || ((fTimeMode & TMODE_MODEMASK)==TMODE_LINEARTIME)) ) |
408 | ) { |
409 | |
410 | return SetValueInternal(aID,aArrayIndex,aBuffer,aValSize); |
411 | } |
412 | |
413 | |
414 | switch (aValType) { |
415 | |
416 | case VALTYPE_NULL: |
417 | sta = SetValueInternal(aID,aArrayIndex,NULL__null,0); |
418 | break; |
419 | |
420 | |
421 | case VALTYPE_TEXT: |
422 | |
423 | if (fCharSet==chs_utf16) { |
424 | appendUTF16AsUTF8((uInt16 *)aBuffer,aValSize/2,fBigEndian,convStr, true, true); |
425 | } |
426 | else { |
427 | string s; s.assign((cAppCharP)aBuffer,aValSize); |
428 | appendStringAsUTF8(s.c_str(), convStr, fCharSet, lem_cstr, true); |
429 | } |
430 | |
431 | switch (valType) { |
432 | case VALTYPE_TIME64: |
433 | |
434 | ISO8601StrToTimestamp(convStr.c_str(), tempTime, tctx); |
435 | |
436 | if ((fTimeMode & TMODE_FLAG_FLOATING)==0) |
437 | TzConvertTimestamp(tempTime, tctx, TCTX_UTC((timecontext_t) ((tctx_tz_UTC) | TCTX_SYMBOLIC_TZ)), getEngineInterface()->getSyncAppBase()->getAppZones(), TCTX_SYSTEM((timecontext_t) ((tctx_tz_system) | TCTX_SYMBOLIC_TZ))); |
438 | siz=8; bP = &tempTime; |
439 | break; |
440 | case VALTYPE_INT8: |
441 | case VALTYPE_INT16: |
442 | case VALTYPE_INT32: |
443 | case VALTYPE_INT64: |
444 | |
445 | StrToLongLong(convStr.c_str(),tempInt); |
446 | goto intConv; |
447 | case VALTYPE_TEXT: |
448 | siz=convStr.size(); |
449 | bP=(appPointer)convStr.c_str(); |
450 | break; |
451 | default: |
452 | |
453 | return LOCERR_WRONGUSAGE; |
454 | } |
455 | |
456 | sta = SetValueInternal(aID,aArrayIndex,bP,siz); |
457 | break; |
458 | |
459 | |
460 | case VALTYPE_TIME32: |
461 | if (aValSize<4) return LOCERR_BUFTOOSMALL; |
462 | tempTime = *((sInt32 *)aBuffer); |
463 | goto timeConv; |
464 | case VALTYPE_TIME64: |
465 | if (aValSize<8) return LOCERR_BUFTOOSMALL; |
466 | tempTime = *((sInt64 *)aBuffer); |
467 | timeConv: |
468 | switch (fTimeMode & TMODE_MODEMASK) { |
469 | case TMODE_LINEARDATE: |
470 | tempInt = tempTime * linearDateToTimeFactor; |
471 | break; |
472 | case TMODE_UNIXTIME_MS: |
473 | tempInt = tempTime+UnixToLineartimeOffset; |
474 | break; |
475 | case TMODE_UNIXTIME: |
476 | tempInt = secondToLinearTimeFactor*tempTime+UnixToLineartimeOffset; |
477 | break; |
478 | case TMODE_LINEARTIME: |
479 | default : |
480 | tempInt = tempTime; |
481 | break; |
482 | } |
483 | tctx = (fTimeMode & TMODE_FLAG_UTC)==0 ? TCTX_SYSTEM((timecontext_t) ((tctx_tz_system) | TCTX_SYMBOLIC_TZ)) : TCTX_UTC((timecontext_t) ((tctx_tz_UTC) | TCTX_SYMBOLIC_TZ)); |
484 | |
485 | if ((fTimeMode & TMODE_FLAG_FLOATING)==0) |
486 | TzConvertTimestamp(tempInt,tctx,TCTX_UTC((timecontext_t) ((tctx_tz_UTC) | TCTX_SYMBOLIC_TZ)),getEngineInterface()->getSyncAppBase()->getAppZones()); |
487 | goto intConv; |
488 | |
489 | |
490 | case VALTYPE_INT8: |
491 | case VALTYPE_ENUM: |
492 | if (aValSize<1) return LOCERR_BUFTOOSMALL; |
493 | tempInt = *((sInt8 *)aBuffer); |
494 | goto intConv; |
495 | case VALTYPE_INT16: |
496 | if (aValSize<2) return LOCERR_BUFTOOSMALL; |
497 | tempInt = *((sInt16 *)aBuffer); |
498 | goto intConv; |
499 | case VALTYPE_INT32: |
500 | if (aValSize<4) return LOCERR_BUFTOOSMALL; |
501 | tempInt = *((sInt32 *)aBuffer); |
502 | goto intConv; |
503 | case VALTYPE_INT64: |
504 | if (aValSize<8) return LOCERR_BUFTOOSMALL; |
505 | tempInt = *((sInt64 *)aBuffer); |
506 | intConv: |
507 | |
508 | union { |
509 | sInt64 buffer64; |
510 | sInt32 buffer32; |
511 | sInt16 buffer16; |
512 | sInt8 buffer8; |
513 | } buffer; |
514 | bP = &buffer; |
515 | switch (valType) { |
516 | case VALTYPE_INT8: |
517 | siz=1; buffer.buffer8 = tempInt; |
518 | break; |
519 | case VALTYPE_INT16: |
520 | siz=2; buffer.buffer16 = tempInt; |
521 | break; |
522 | case VALTYPE_INT32: |
523 | siz=4; buffer.buffer32 = tempInt; |
524 | break; |
525 | case VALTYPE_INT64: |
526 | case VALTYPE_TIME64: |
527 | siz=8; buffer.buffer64 = tempInt; |
528 | break; |
529 | default: |
530 | |
531 | return LOCERR_WRONGUSAGE; |
532 | break; |
533 | } |
534 | |
535 | sta = SetValueInternal(aID,aArrayIndex,bP,siz); |
536 | break; |
537 | |
538 | } |
539 | |
540 | return sta; |
541 | } |
542 | |
543 | |
544 | |
545 | #define VALID_IDXOFFS_VALTYPE0x100000 0x100000 |
546 | #define VALID_MASK_IDX0x00FFFF 0x00FFFF |
547 | |
548 | |
549 | |
550 | bool TSettingsKeyImpl::checkFieldAttrs(cAppCharP aName, size_t &aBaseNameSize, sInt32 &aFldID) |
551 | { |
552 | aBaseNameSize = strlen(aName); |
553 | aFldID = 0; |
554 | if (aBaseNameSize >= strlen(VALSUFF_TYPE".VALTYPE") && |
555 | strucmp(aName+aBaseNameSize-strlen(VALSUFF_TYPE".VALTYPE"),VALSUFF_TYPE".VALTYPE")==0) { |
556 | |
557 | aBaseNameSize-=strlen(VALSUFF_TYPE".VALTYPE"); |
558 | aFldID += VALID_IDXOFFS_VALTYPE0x100000; |
559 | } |
560 | if (strucmp(aName,VALNAME_FLAG".FLAG",aBaseNameSize)==0) |
561 | return true; |
562 | return false; |
563 | } |
564 | |
565 | |
566 | |
567 | |
568 | bool TSettingsKeyImpl::checkAttrValueType(sInt32 aID, uInt16 &aValType) |
569 | { |
570 | if (aID>0 && (aID & VALID_IDXOFFS_VALTYPE0x100000)) { |
571 | aValType = VALTYPE_INT16; |
572 | return true; |
573 | } |
574 | return false; |
575 | } |
576 | |
577 | |
578 | |
579 | |
580 | bool TSettingsKeyImpl::checkAttrValue( |
581 | sInt32 aID, sInt32 aArrayIndex, |
582 | appPointer aBuffer, memSize aBufSize, memSize &aValSize |
583 | ) |
584 | { |
585 | if (aID>0 && (aID & VALID_IDXOFFS_VALTYPE0x100000)) { |
586 | |
587 | aValSize = 2; |
588 | uInt16 valtype = GetValueType(aID & VALID_MASK_IDX0x00FFFF); |
589 | if (aBufSize>=aValSize) { |
590 | memcpy(aBuffer,&valtype,aValSize); |
591 | } |
592 | return true; |
593 | } |
594 | return false; |
595 | } |
596 | |
597 | |
598 | |
599 | |
600 | |
601 | |
602 | |
603 | |
604 | |
605 | |
606 | |
607 | sInt32 TReadOnlyInfoKey::GetValueID(cAppCharP aName) |
608 | { |
609 | const TReadOnlyInfo *tblP = getInfoTable(); |
610 | |
611 | sInt32 idx=0; |
612 | size_t namsz; |
613 | sInt32 fldID; |
614 | if (checkFieldAttrs(aName,namsz,fldID)) |
615 | return fldID; |
616 | while(tblP && idx<numInfos()) { |
617 | if (strucmp(aName,tblP[idx].valName,namsz)==0) { |
618 | return fldID+idx; |
619 | } |
620 | |
621 | idx++; |
622 | } |
623 | |
624 | if (strucmp(aName,VALNAME_FIRST".FIRST")==0) { |
625 | fIterator=0; |
626 | if (fIterator<numInfos()) return fIterator; |
627 | } |
628 | else if (strucmp(aName,VALNAME_NEXT".NEXT")==0) { |
629 | if (fIterator<numInfos()) fIterator++; |
630 | if (fIterator<numInfos()) return fIterator; |
631 | } |
632 | |
633 | return KEYVAL_ID_UNKNOWN; |
634 | } |
635 | |
636 | |
637 | |
638 | uInt16 TReadOnlyInfoKey::GetValueType(sInt32 aID) |
639 | { |
640 | uInt16 valType; |
641 | if (checkAttrValueType(aID,valType)) |
642 | return valType; |
643 | if (aID>=numInfos()) return VALTYPE_UNKNOWN; |
644 | return getInfoTable()[aID].valType; |
645 | } |
646 | |
647 | |
648 | |
649 | TSyError TReadOnlyInfoKey::GetValueInternal( |
650 | sInt32 aID, sInt32 aArrayIndex, |
651 | appPointer aBuffer, memSize aBufSize, memSize &aValSize |
652 | ) |
653 | { |
654 | if (checkAttrValue(aID,aArrayIndex,aBuffer,aBufSize,aValSize)) |
655 | return LOCERR_OK; |
656 | const TReadOnlyInfo *infoP = &(getInfoTable()[aID]); |
657 | memSize siz = infoP->valSiz; |
658 | if (siz==0 && infoP->valType==VALTYPE_TEXT) |
659 | siz = strlen((cAppCharP)(infoP->valPtr)); |
660 | |
661 | aValSize = siz; |
662 | |
663 | if (siz>aBufSize) |
664 | siz=aBufSize; |
665 | memcpy(aBuffer,infoP->valPtr,siz); |
666 | return LOCERR_OK; |
667 | } |
668 | |
669 | |
670 | |
671 | |
672 | |
673 | |
674 | |
675 | |
676 | sInt32 TConfigVarKey::GetValueID(cAppCharP aName) |
677 | { |
678 | size_t namsz; |
679 | sInt32 fldID; |
680 | checkFieldAttrs(aName,namsz,fldID); |
681 | if (fldID!=0) |
682 | return fldID; |
683 | |
684 | fVarName = aName; |
685 | return KEYVAL_NO_ID; |
686 | }; |
687 | |
688 | |
689 | |
690 | uInt16 TConfigVarKey::GetValueType(sInt32 aID) |
691 | { |
692 | uInt16 valType; |
693 | if (checkAttrValueType(aID,valType)) |
694 | return valType; |
695 | |
696 | return VALTYPE_TEXT; |
697 | } |
698 | |
699 | |
700 | |
701 | TSyError TConfigVarKey::GetValueInternal( |
702 | sInt32 aID, sInt32 aArrayIndex, |
703 | appPointer aBuffer, memSize aBufSize, memSize &aValSize |
704 | ) { |
705 | if (checkAttrValue(aID,aArrayIndex,aBuffer,aBufSize,aValSize)) |
706 | return LOCERR_OK; |
707 | string s; |
708 | if (!fEngineInterfaceP->getSyncAppBase()->getConfigVar(fVarName.c_str(),s)) |
709 | return DB_NotFound; |
710 | |
711 | aValSize=s.size(); |
712 | strncpy((appCharP)aBuffer,s.c_str(),aBufSize); |
713 | return LOCERR_OK; |
714 | } |
715 | |
716 | |
717 | |
718 | TSyError TConfigVarKey::SetValueInternal( |
719 | sInt32 aID, sInt32 aArrayIndex, |
720 | cAppPointer aBuffer, memSize aValSize |
721 | ) { |
722 | if (!aBuffer) { |
723 | |
724 | fEngineInterfaceP->getSyncAppBase()->unsetConfigVar(fVarName.c_str()); |
725 | return LOCERR_OK; |
726 | } |
727 | string v; v.assign((cAppCharP)aBuffer,(size_t)aValSize); |
728 | if (!fEngineInterfaceP->getSyncAppBase()->setConfigVar(fVarName.c_str(),v.c_str())) |
729 | return DB_NotFound; |
730 | return LOCERR_OK; |
731 | } |
732 | |
733 | |
734 | |
735 | |
736 | |
737 | |
738 | |
739 | |
740 | |
741 | TSyError TStructFieldsKey::returnString(cAppCharP aReturnString, appPointer aBuffer, memSize aBufSize, memSize &aValSize) |
742 | { |
743 | aValSize=strlen(aReturnString); |
744 | if (aBufSize>=aValSize) { |
745 | |
746 | strncpy((appCharP)aBuffer,aReturnString,aValSize); |
747 | } |
748 | return LOCERR_OK; |
749 | } |
750 | |
751 | |
752 | |
753 | TSyError TStructFieldsKey::returnInt(sInt32 aInt, memSize aIntSize, appPointer aBuffer, memSize aBufSize, memSize &aValSize) |
754 | { |
755 | aValSize=aIntSize; |
756 | if (aBufSize==0) return LOCERR_OK; |
757 | if (aBufSize<aIntSize) return LOCERR_BUFTOOSMALL; |
758 | if (aValSize>=4) |
759 | *((sInt32 *)aBuffer) = (sInt32)aInt; |
760 | else if (aValSize>=2) |
761 | *((sInt16 *)aBuffer) = (sInt16)aInt; |
762 | else |
763 | *((sInt8 *)aBuffer) = (sInt8)aInt; |
764 | return LOCERR_OK; |
765 | } |
766 | |
767 | |
768 | TSyError TStructFieldsKey::returnLineartime(lineartime_t aTime, appPointer aBuffer, memSize aBufSize, memSize &aValSize) |
769 | { |
770 | aValSize=sizeof(lineartime_t); |
771 | if (aBufSize==0) return LOCERR_OK; |
772 | if (aBufSize<aValSize) return LOCERR_BUFTOOSMALL; |
773 | *((lineartime_t *)aBuffer) = aTime; |
774 | return LOCERR_OK; |
775 | } |
776 | |
777 | |
778 | |
779 | |
780 | |
781 | sInt32 TStructFieldsKey::GetValueID(cAppCharP aName) |
782 | { |
783 | const TStructFieldInfo *tblP = getFieldsTable(); |
784 | |
785 | sInt32 idx=0; |
786 | size_t namsz; |
787 | sInt32 fldID; |
788 | if (checkFieldAttrs(aName,namsz,fldID)) |
789 | return fldID; |
790 | while(tblP && idx<numFields()) { |
791 | if (strucmp(aName,tblP[idx].valName,namsz)==0) { |
792 | return fldID+idx; |
793 | } |
794 | |
795 | idx++; |
796 | } |
797 | |
798 | if (strucmp(aName,VALNAME_FIRST".FIRST")==0) { |
799 | fIterator=0; |
800 | if (fIterator<numFields()) return fIterator; |
801 | } |
802 | else if (strucmp(aName,VALNAME_NEXT".NEXT")==0) { |
803 | if (fIterator<numFields()) fIterator++; |
804 | if (fIterator<numFields()) return fIterator; |
805 | } |
806 | |
807 | return KEYVAL_ID_UNKNOWN; |
808 | } |
809 | |
810 | |
811 | |
812 | uInt16 TStructFieldsKey::GetValueType(sInt32 aID) |
813 | { |
814 | uInt16 valType; |
815 | if (checkAttrValueType(aID,valType)) |
816 | return valType; |
817 | if (aID>=numFields()) return VALTYPE_UNKNOWN; |
818 | const TStructFieldInfo *fldinfoP = &(getFieldsTable()[aID]); |
819 | valType = fldinfoP->valType; |
820 | if (valType == VALTYPE_ENUM) { |
821 | |
822 | switch (fldinfoP->valSiz) { |
823 | default : return VALTYPE_INT8; |
824 | case 2 : return VALTYPE_INT16; |
825 | case 4 : return VALTYPE_INT32; |
826 | case 8 : return VALTYPE_INT64; |
827 | } |
828 | } |
829 | else if (valType == VALTYPE_TEXT_OBFUS) |
830 | return VALTYPE_TEXT; |
831 | else |
832 | return valType; |
833 | } |
834 | |
835 | |
836 | |
837 | TSyError TStructFieldsKey::GetValueInternal( |
838 | sInt32 aID, sInt32 aArrayIndex, |
839 | appPointer aBuffer, memSize aBufSize, memSize &aValSize |
840 | ) |
841 | { |
842 | if (checkAttrValue(aID,aArrayIndex,aBuffer,aBufSize,aValSize)) |
| |
843 | return LOCERR_OK; |
844 | const TStructFieldInfo *fldinfoP = &(getFieldsTable()[aID]); |
| 2 | | 'fldinfoP' initialized to a null pointer value | |
|
845 | |
846 | if (fldinfoP->getValueProc) { |
| 3 | | Access to field 'getValueProc' results in a dereference of a null pointer (loaded from variable 'fldinfoP') |
|
847 | |
848 | return fldinfoP->getValueProc(this,fldinfoP,aBuffer,aBufSize,aValSize); |
849 | } |
850 | |
851 | memSize siz = fldinfoP->valSiz; |
852 | if (siz==0) return DB_Forbidden; |
853 | uInt8P valPtr = getStructAddr()+fldinfoP->fieldOffs; |
854 | |
855 | if (fldinfoP->valType==VALTYPE_TEXT) |
856 | siz = strlen((cAppCharP)valPtr); |
857 | |
858 | aValSize = siz; |
859 | |
860 | if (siz>aBufSize) |
861 | siz=aBufSize; |
862 | |
863 | if (fldinfoP->valType==VALTYPE_TEXT_OBFUS && siz>0) { |
864 | getUnmangledAsBuf((appCharP)aBuffer, siz, (cAppCharP)valPtr); |
865 | |
866 | aValSize = strlen((cAppCharP)aBuffer); |
867 | } |
868 | else |
869 | memcpy(aBuffer,valPtr,siz); |
870 | return LOCERR_OK; |
871 | } |
872 | |
873 | |
874 | |
875 | TSyError TStructFieldsKey::SetValueInternal( |
876 | sInt32 aID, sInt32 aArrayIndex, |
877 | cAppPointer aBuffer, memSize aValSize |
878 | ) |
879 | { |
880 | if (!aBuffer) return LOCERR_WRONGUSAGE; |
881 | if (aID & VALID_IDXOFFS_VALTYPE0x100000) |
882 | return DB_Forbidden; |
883 | TSyError sta = LOCERR_OK; |
884 | const TStructFieldInfo *fldinfoP = &(getFieldsTable()[aID]); |
885 | |
886 | if (!fldinfoP->writable) return DB_Forbidden; |
887 | |
888 | if (fldinfoP->setValueProc) { |
889 | |
890 | return fldinfoP->setValueProc(this,fldinfoP,aBuffer,aValSize); |
891 | } |
892 | |
893 | memSize siz = fldinfoP->valSiz; |
894 | if (siz==0) return DB_Forbidden; |
895 | uInt8P valPtr = getStructAddr()+fldinfoP->fieldOffs; |
896 | |
897 | if (fldinfoP->valType == VALTYPE_TEXT) |
898 | siz--; |
899 | |
900 | if (aValSize>siz) |
901 | sta=LOCERR_TRUNCATED; |
902 | else |
903 | siz=aValSize; |
904 | |
905 | if (fldinfoP->valType==VALTYPE_TEXT_OBFUS) { |
906 | string v; v.assign((cAppCharP)aBuffer,aValSize); |
907 | assignMangledToCString((appCharP)valPtr, v.c_str(), fldinfoP->valSiz, true); |
908 | } |
909 | else |
910 | memcpy(valPtr,aBuffer,siz); |
911 | |
912 | fDirty=true; |
913 | |
914 | if (fldinfoP->valType == VALTYPE_TEXT) |
915 | *(valPtr+siz)=0; |
916 | |
917 | return sta; |
918 | } |
919 | |
920 | |
921 | |
922 | #ifdef SYSER_REGISTRATION |
923 | |
924 | |
925 | |
926 | |
927 | |
928 | |
929 | |
930 | static TSyError readLicenseText( |
931 | TStructFieldsKey *aStructFieldsKeyP, const TStructFieldInfo *aFldInfoP, |
932 | appPointer aBuffer, memSize aBufSize, memSize &aValSize |
933 | ) |
934 | { |
935 | |
936 | aValSize=aStructFieldsKeyP->getEngineInterface()->getSyncAppBase()->getRootConfig()->fLicenseName.size(); |
937 | if (aBufSize>0) |
938 | strncpy((char *)aBuffer,aStructFieldsKeyP->getEngineInterface()->getSyncAppBase()->getRootConfig()->fLicenseName.c_str(),aBufSize); |
939 | return LOCERR_OK; |
940 | } |
941 | |
942 | |
943 | |
944 | static TSyError writeLicenseText( |
945 | TStructFieldsKey *aStructFieldsKeyP, const TStructFieldInfo *aFldInfoP, |
946 | cAppPointer aBuffer, memSize aValSize |
947 | ) |
948 | { |
949 | |
950 | aStructFieldsKeyP->getEngineInterface()->getSyncAppBase()->getRootConfig()->fLicenseName.assign((cAppCharP)aBuffer,aValSize); |
951 | |
952 | |
953 | |
954 | |
955 | return LOCERR_OK; |
956 | } |
957 | |
958 | |
959 | |
960 | static TSyError writeLicenseCode( |
961 | TStructFieldsKey *aStructFieldsKeyP, const TStructFieldInfo *aFldInfoP, |
962 | cAppPointer aBuffer, memSize aValSize |
963 | ) |
964 | { |
965 | |
966 | aStructFieldsKeyP->getEngineInterface()->getSyncAppBase()->getRootConfig()->fLicenseCode.assign((cAppCharP)aBuffer,aValSize); |
967 | |
968 | aStructFieldsKeyP->getEngineInterface()->getSyncAppBase()->isRegistered(); |
969 | |
970 | return LOCERR_OK; |
971 | } |
972 | |
973 | |
974 | |
975 | |
976 | |
977 | static TSyError readRegStatus( |
978 | TStructFieldsKey *aStructFieldsKeyP, const TStructFieldInfo *aFldInfoP, |
979 | appPointer aBuffer, memSize aBufSize, memSize &aValSize |
980 | ) |
981 | { |
982 | aValSize=2; |
983 | if (aBufSize>=aValSize) { |
984 | |
985 | localstatus sta = aStructFieldsKeyP->getEngineInterface()->getSyncAppBase()->isRegistered(); |
986 | |
987 | *((uInt16*)aBuffer)=sta; |
988 | } |
989 | return LOCERR_OK; |
990 | } |
991 | |
992 | |
993 | |
994 | |
995 | |
996 | static TSyError readEnabledStatus( |
997 | TStructFieldsKey *aStructFieldsKeyP, const TStructFieldInfo *aFldInfoP, |
998 | appPointer aBuffer, memSize aBufSize, memSize &aValSize |
999 | ) |
1000 | { |
1001 | aValSize=2; |
1002 | if (aBufSize>=aValSize) { |
1003 | |
1004 | |
1005 | localstatus sta = aStructFieldsKeyP->getEngineInterface()->getSyncAppBase()->appEnableStatus(); |
1006 | |
1007 | *((uInt16*)aBuffer)=sta; |
1008 | } |
1009 | return LOCERR_OK; |
1010 | } |
1011 | |
1012 | |
1013 | #if defined(EXPIRES_AFTER_DAYS) && defined(ENGINEINTERFACE_SUPPORT1) |
1014 | |
1015 | |
1016 | static TSyError writeFuv( |
1017 | TStructFieldsKey *aStructFieldsKeyP, const TStructFieldInfo *aFldInfoP, |
1018 | cAppPointer aBuffer, memSize aValSize |
1019 | ) |
1020 | { |
1021 | uInt32 fuv = *((uInt32 *)aBuffer); |
1022 | if (fuv==0x53595359) { |
1023 | |
1024 | aStructFieldsKeyP->getEngineInterface()->getSyncAppBase()->updateFirstUseInfo( |
1025 | aStructFieldsKeyP->getEngineInterface()->getSyncAppBase()->fFirstUseDate, |
1026 | aStructFieldsKeyP->getEngineInterface()->getSyncAppBase()->fFirstUseVers |
1027 | ); |
1028 | } |
1029 | else { |
1030 | |
1031 | aStructFieldsKeyP->getEngineInterface()->getSyncAppBase()->fFirstUseVers = fuv; |
1032 | } |
1033 | |
1034 | return LOCERR_OK; |
1035 | } |
1036 | |
1037 | #endif // EXPIRES_AFTER_DAYS+ENGINEINTERFACE_SUPPORT |
1038 | |
1039 | |
1040 | |
1041 | |
1042 | #define OFFS_SZ_AB(n) (offsetof(TSyncAppBase,n)__builtin_offsetof(TSyncAppBase, n)), sizeof(dP_ab->n) |
1043 | |
1044 | static const TSyncAppBase *dP_ab=NULL__null; |
1045 | |
1046 | |
1047 | static const TStructFieldInfo LicensingFieldInfos[] = |
1048 | { |
1049 | |
1050 | |
1051 | { "licensetext", VALTYPE_TEXT, true, 0, 0, &readLicenseText, &writeLicenseText }, |
1052 | { "licensecode", VALTYPE_TEXT, true, 0, 0, NULL__null, &writeLicenseCode }, |
1053 | #if defined(EXPIRES_AFTER_DAYS) && defined(ENGINEINTERFACE_SUPPORT1) |
1054 | |
1055 | { "fud", VALTYPE_INT32, true, OFFS_SZ_AB(fFirstUseDate) }, |
1056 | { "fuv", VALTYPE_INT32, true, OFFS_SZ_AB(fFirstUseVers), NULL__null, &writeFuv }, |
1057 | #endif |
1058 | |
1059 | { "regStatus", VALTYPE_INT16, false, 0, 0, &readRegStatus, NULL__null }, |
1060 | { "enabledStatus", VALTYPE_INT16, false, 0, 0, &readEnabledStatus, NULL__null }, |
1061 | { "regOK", VALTYPE_ENUM, false, OFFS_SZ_AB(fRegOK) }, |
1062 | { "productCode", VALTYPE_ENUM, false, OFFS_SZ_AB(fRegProductCode) }, |
1063 | { "productFlags", VALTYPE_ENUM, false, OFFS_SZ_AB(fRegProductFlags) }, |
1064 | { "quantity", VALTYPE_ENUM, false, OFFS_SZ_AB(fRegQuantity) }, |
1065 | { "licenseType", VALTYPE_ENUM, false, OFFS_SZ_AB(fRegLicenseType) }, |
1066 | { "daysleft", VALTYPE_ENUM, false, OFFS_SZ_AB(fDaysLeft) }, |
1067 | }; |
1068 | |
1069 | |
1070 | |
1071 | const TStructFieldInfo *TLicensingKey::getFieldsTable(void) |
1072 | { |
1073 | return LicensingFieldInfos; |
1074 | } |
1075 | |
1076 | sInt32 TLicensingKey::numFields(void) |
1077 | { |
1078 | return sizeof(LicensingFieldInfos)/sizeof(TStructFieldInfo); |
1079 | } |
1080 | |
1081 | |
1082 | |
1083 | |
1084 | uInt8P TLicensingKey::getStructAddr(void) |
1085 | { |
1086 | return (uInt8P)fEngineInterfaceP->getSyncAppBase(); |
1087 | } |
1088 | |
1089 | |
1090 | #endif // SYSER_REGISTRATION |
1091 | |
1092 | |
1093 | |
1094 | |
1095 | |
1096 | |
1097 | TEngineInterface::TEngineInterface() : |
1098 | fAppBaseP(NULL__null) |
1099 | { |
1100 | |
1101 | fCharSet = chs_utf8; |
1102 | fLineEndMode = lem_cstr; |
1103 | fBigEndian = false; |
1104 | } |
1105 | |
1106 | |
1107 | |
1108 | TSyError TEngineInterface::Init() |
1109 | { |
1110 | #ifdef DIRECT_APPBASE_GLOBALACCESS |
1111 | |
1112 | sysync_glob_setanchor(this); |
1113 | #endif |
1114 | |
1115 | fAppBaseP = newSyncAppBase(); |
1116 | if (fAppBaseP==NULL__null) |
1117 | return LOCERR_UNDEFINED; |
1118 | |
1119 | fAppBaseP->fEngineInterfaceP = this; |
1120 | |
1121 | #ifdef SYDEBUG2 |
1122 | if (fCI) { |
1123 | fCI->callbackRef = fAppBaseP; |
1124 | fCI->DB_DebugPuts = AppBaseLogDebugPuts; |
1125 | fCI->DB_DebugBlock = AppBaseLogDebugBlock; |
1126 | fCI->DB_DebugEndBlock = AppBaseLogDebugEndBlock; |
1127 | fCI->DB_DebugEndThread = AppBaseLogDebugEndThread; |
1128 | fCI->DB_DebugExotic = AppBaseLogDebugExotic; |
1129 | } |
1130 | #endif |
1131 | |
1132 | return LOCERR_OK; |
1133 | } |
1134 | |
1135 | |
1136 | TSyError TEngineInterface::Term() |
1137 | { |
1138 | return LOCERR_OK; |
1139 | } |
1140 | |
1141 | |
1142 | |
1143 | TEngineInterface::~TEngineInterface() |
1144 | { |
1145 | |
1146 | if (fAppBaseP) { |
1147 | delete fAppBaseP; |
1148 | fAppBaseP=NULL__null; |
1149 | } |
1150 | #ifdef DIRECT_APPBASE_GLOBALACCESS |
1151 | |
1152 | sysync_glob_setanchor(NULL__null); |
1153 | #endif |
1154 | } |
1155 | |
1156 | |
1157 | |
1158 | TSyError TEngineInterface::SetStringMode(uInt16 aCharSet, uInt16 aLineEndMode, bool aBigEndian) |
1159 | { |
1160 | |
1161 | uInt16 chs; |
1162 | for (chs=0; chs<numCharSets; chs++) { |
1163 | if (engineCharSets[chs]==aCharSet) break; |
1164 | } |
1165 | if (chs==numCharSets) return LOCERR_BADPARAM; |
1166 | |
1167 | uInt16 lem; |
1168 | for (lem=0; lem<numLineEndModes; lem++) { |
1169 | if (engineLineEndModes[lem]==aLineEndMode) break; |
1170 | } |
1171 | if (lem==numLineEndModes) return LOCERR_BADPARAM; |
1172 | |
1173 | fCharSet = (TCharSets)chs; |
1174 | fLineEndMode = (TLineEndModes)lem; |
1175 | |
1176 | fBigEndian = aBigEndian; |
1177 | return LOCERR_OK; |
1178 | } |
1179 | |
1180 | |
1181 | |
1182 | |
1183 | |
1184 | |
1185 | cAppCharP TEngineInterface::makeAppString(cAppCharP aTextP, string &aString) |
1186 | { |
1187 | |
1188 | if (fCharSet==chs_utf8) |
1189 | return cAppCharP(aTextP); |
1190 | |
1191 | if (fCharSet==chs_utf16) { |
1192 | appendUTF16AsUTF8((uInt16 *)aTextP,0x7FFFFFFF,fBigEndian,aString, true, true); |
1193 | } |
1194 | else { |
1195 | appendStringAsUTF8((cAppCharP)aTextP, aString, fCharSet, fLineEndMode, true); |
1196 | } |
1197 | |
1198 | return aString.c_str(); |
1199 | } |
1200 | |
1201 | |
1202 | |
1203 | |
1204 | |
1205 | |
1206 | TSyError TEngineInterface::InitEngineXML(cAppCharP aConfigXML) |
1207 | { |
1208 | #ifndef CONSTANTXML_CONFIG1 |
1209 | return LOCERR_NOTIMP; |
1210 | #else |
1211 | |
1212 | fAppBaseP->fApiInterModuleContext = fCI->gContext; |
1213 | |
1214 | string tempStr; |
1215 | aConfigXML = makeAppString(aConfigXML, tempStr); |
1216 | |
1217 | return getSyncAppBase()->readXMLConfigConstant(aConfigXML); |
1218 | #endif |
1219 | } |
1220 | |
1221 | |
1222 | |
1223 | |
1224 | |
1225 | TSyError TEngineInterface::InitEngineFile(cAppCharP aConfigFilePath) |
1226 | { |
1227 | |
1228 | string tempStr; |
1229 | aConfigFilePath = makeAppString(aConfigFilePath, tempStr); |
1230 | |
1231 | fAppBaseP->fApiInterModuleContext = fCI->gContext; |
1232 | |
1233 | string pathStr = aConfigFilePath; |
1234 | getSyncAppBase()->expandConfigVars(pathStr,2); |
1235 | |
1236 | return getSyncAppBase()->readXMLConfigFile(pathStr.c_str()); |
1237 | } |
1238 | |
1239 | |
1240 | |
1241 | |
1242 | |
1243 | |
1244 | TSyError TEngineInterface::InitEngineCB(TXMLConfigReadFunc aReaderFunc, void *aContext) |
1245 | { |
1246 | |
1247 | fAppBaseP->fApiInterModuleContext = fCI->gContext; |
1248 | |
1249 | return getSyncAppBase()->readXMLConfigStream(aReaderFunc, aContext); |
1250 | } |
1251 | |
1252 | |
1253 | |
1254 | |
1255 | |
1256 | |
1257 | |
1258 | TSyError TEngineInterface::OpenSession(SessionH &aNewSessionH, uInt32 aSelector, cAppCharP aSessionName) |
1259 | { |
1260 | |
1261 | localstatus sta=getSyncAppBase()->appEnableStatus(); |
1262 | if (sta!=LOCERR_OK) return sta; |
1263 | |
1264 | string tempStr; |
1265 | aSessionName = makeAppString(aSessionName, tempStr); |
1266 | |
1267 | return OpenSessionInternal(aNewSessionH, aSelector, aSessionName); |
1268 | } |
1269 | |
1270 | |
1271 | TSyError TEngineInterface::OpenSessionInternal(SessionH &aNewSessionH, uInt32 aSelector, cAppCharP aSessionName) |
1272 | { |
1273 | |
1274 | return LOCERR_NOTIMP; |
1275 | } |
1276 | |
1277 | |
1278 | |
1279 | |
1280 | |
1281 | |
1282 | |
1283 | |
1284 | TSyError TEngineInterface::OpenSessionKey(SessionH aSessionH, KeyH &aNewKeyH, uInt16 aMode) |
1285 | { |
1286 | |
1287 | return DB_NotFound; |
1288 | } |
1289 | |
1290 | |
1291 | |
1292 | |
1293 | |
1294 | |
1295 | |
1296 | TSyError TEngineInterface::CloseSession(SessionH aSessionH) |
1297 | { |
1298 | |
1299 | return LOCERR_NOTIMP; |
1300 | } |
1301 | |
1302 | |
1303 | |
1304 | |
1305 | |
1306 | |
1307 | |
1308 | |
1309 | |
1310 | TSyError TEngineInterface::SessionStep (SessionH aSessionH, uInt16 &aStepCmd, TEngineProgressInfo *aInfoP) |
1311 | { |
1312 | |
1313 | return LOCERR_NOTIMP; |
1314 | } |
1315 | |
1316 | |
1317 | |
1318 | |
1319 | |
1320 | |
1321 | |
1322 | |
1323 | TSyError TEngineInterface::GetSyncMLBuffer(SessionH aSessionH, bool aForSend, appPointer &aBuffer, memSize &aBufSize) |
1324 | { |
1325 | Ret_t rc; |
1326 | MemSize_t bufSz; |
1327 | |
1328 | InstanceID_t myInstance = getSmlInstanceOfSession(aSessionH); |
1329 | if (myInstance==0) |
1330 | return LOCERR_WRONGUSAGE; |
1331 | |
1332 | if (aForSend) { |
1333 | |
1334 | rc=smlLockReadBuffer( |
1335 | myInstance, |
1336 | (unsigned char **)&aBuffer, |
1337 | &bufSz |
1338 | ); |
1339 | aBufSize = bufSz; |
1340 | } |
1341 | else { |
1342 | |
1343 | rc=smlLockWriteBuffer( |
1344 | myInstance, |
1345 | (unsigned char **)&aBuffer, |
1346 | &bufSz |
1347 | ); |
1348 | aBufSize = bufSz; |
1349 | } |
1350 | |
1351 | if (rc!=SML_ERR_OK0x00) |
1352 | return LOCERR_SMLFATAL; |
1353 | |
1354 | return LOCERR_OK; |
1355 | } |
1356 | |
1357 | |
1358 | |
1359 | |
1360 | |
1361 | |
1362 | |
1363 | |
1364 | TSyError TEngineInterface::RetSyncMLBuffer(SessionH aSessionH, bool aForSend, memSize aProcessed) |
1365 | { |
1366 | Ret_t rc; |
1367 | |
1368 | |
1369 | InstanceID_t myInstance = getSmlInstanceOfSession(aSessionH); |
1370 | if (myInstance==0) |
1371 | return LOCERR_WRONGUSAGE; |
1372 | |
1373 | if (aForSend) { |
1374 | |
1375 | rc=smlUnlockReadBuffer( |
1376 | myInstance, |
1377 | aProcessed |
1378 | ); |
1379 | } |
1380 | else { |
1381 | |
1382 | rc=smlUnlockWriteBuffer( |
1383 | myInstance, |
1384 | aProcessed |
1385 | ); |
1386 | } |
1387 | |
1388 | if (rc!=SML_ERR_OK0x00) |
1389 | return LOCERR_SMLFATAL; |
1390 | |
1391 | return LOCERR_OK; |
1392 | } |
1393 | |
1394 | |
1395 | |
1396 | |
1397 | |
1398 | |
1399 | |
1400 | |
1401 | |
1402 | |
1403 | TSyError TEngineInterface::ReadSyncMLBuffer(SessionH aSessionH, appPointer aBuffer, memSize aBufSize, memSize &aMsgSize) |
1404 | { |
1405 | TSyError sta; |
1406 | appPointer bufP; |
1407 | memSize msgsiz; |
1408 | |
1409 | |
1410 | sta = GetSyncMLBuffer(aSessionH,true,bufP,msgsiz); |
1411 | if (sta!=LOCERR_OK) return sta; |
1412 | |
1413 | aMsgSize = msgsiz; |
1414 | |
1415 | if (aBufSize<msgsiz) { |
1416 | sta = LOCERR_TRUNCATED; |
1417 | |
1418 | msgsiz=aBufSize; |
1419 | } |
1420 | if (msgsiz>0) { |
1421 | |
1422 | memcpy(aBuffer,bufP,msgsiz); |
1423 | } |
1424 | |
1425 | RetSyncMLBuffer(aSessionH,true,msgsiz); |
1426 | |
1427 | return sta; |
1428 | } |
1429 | |
1430 | |
1431 | |
1432 | |
1433 | |
1434 | |
1435 | |
1436 | TSyError TEngineInterface::WriteSyncMLBuffer(SessionH aSessionH, appPointer aBuffer, memSize aMsgSize) |
1437 | { |
1438 | TSyError sta; |
1439 | appPointer bufP; |
1440 | memSize bufsiz; |
1441 | |
1442 | |
1443 | sta = GetSyncMLBuffer(aSessionH,false,bufP,bufsiz); |
1444 | if (sta!=LOCERR_OK) return sta; |
1445 | |
1446 | if (aMsgSize>bufsiz) { |
1447 | |
1448 | sta = LOCERR_BUFTOOSMALL; |
1449 | aMsgSize=0; |
1450 | } |
1451 | else { |
1452 | if (aMsgSize>0) { |
1453 | |
1454 | memcpy(bufP,aBuffer,aMsgSize); |
1455 | } |
1456 | } |
1457 | |
1458 | RetSyncMLBuffer(aSessionH,false,aMsgSize); |
1459 | |
1460 | return sta; |
1461 | } |
1462 | |
1463 | |
1464 | |
1465 | |
1466 | |
1467 | |
1468 | |
1469 | |
1470 | |
1471 | |
1472 | |
1473 | TSyError TEngineInterface::OpenKeyByPath ( |
1474 | KeyH &aNewKeyH, |
1475 | KeyH aParentKeyH, |
1476 | cAppCharP aPath, uInt16 aMode |
1477 | ) { |
1478 | TSettingsKeyImpl *aBaseKeyP = NULL__null; |
1479 | TSettingsKeyImpl *aKeyP = NULL__null; |
1480 | bool implicit = false; |
1481 | TSyError sta; |
1482 | |
1483 | |
1484 | string tempStr; |
1485 | aPath = makeAppString(aPath, tempStr); |
1486 | |
1487 | |
1488 | if (aParentKeyH) { |
1489 | |
1490 | aBaseKeyP = reinterpret_cast<TSettingsKeyImpl *>(aParentKeyH); |
1491 | implicit = false; |
1492 | } |
1493 | else { |
1494 | |
1495 | aBaseKeyP = newSettingsRootKey(); |
1496 | implicit = true; |
1497 | } |
1498 | |
1499 | if (implicit && (aPath==NULL__null || *aPath==0 || (*aPath==SETTINGSKEY_PATH_SEPARATOR'/' && *(aPath+1)==0))) { |
1500 | |
1501 | aKeyP = aBaseKeyP; |
1502 | sta = LOCERR_OK; |
1503 | } |
1504 | else { |
1505 | |
1506 | sta = aBaseKeyP->OpenKeyByPath(aKeyP,aPath,aMode,implicit); |
1507 | } |
1508 | if (sta!=LOCERR_OK) { |
1509 | if (aKeyP) { |
1510 | |
1511 | |
1512 | delete aKeyP; |
1513 | } |
1514 | } |
1515 | else { |
1516 | |
1517 | aNewKeyH = (KeyH)aKeyP; |
1518 | } |
1519 | return sta; |
1520 | } |
1521 | |
1522 | |
1523 | |
1524 | |
1525 | |
1526 | |
1527 | |
1528 | |
1529 | |
1530 | |
1531 | |
1532 | |
1533 | |
1534 | TSyError TEngineInterface::OpenSubkey( |
1535 | KeyH &aNewKeyH, |
1536 | KeyH aParentKeyH, |
1537 | sInt32 aID, uInt16 aMode |
1538 | ) { |
1539 | TSettingsKeyImpl *baseKeyP = NULL__null; |
1540 | TSettingsKeyImpl *keyP = NULL__null; |
1541 | TSyError sta; |
1542 | |
1543 | |
1544 | if (!aParentKeyH) return LOCERR_WRONGUSAGE; |
1545 | |
1546 | baseKeyP = reinterpret_cast<TSettingsKeyImpl *>(aParentKeyH); |
1547 | |
1548 | sta = baseKeyP->OpenSubkey(keyP,aID,aMode); |
1549 | if (sta == LOCERR_OK) { |
1550 | |
1551 | aNewKeyH = (KeyH)keyP; |
1552 | } |
1553 | return sta; |
1554 | } |
1555 | |
1556 | |
1557 | |
1558 | |
1559 | |
1560 | |
1561 | |
1562 | TSyError TEngineInterface::DeleteSubkey(KeyH aParentKeyH, sInt32 aID) |
1563 | { |
1564 | |
1565 | if (!aParentKeyH) return LOCERR_WRONGUSAGE; |
1566 | |
1567 | return reinterpret_cast<TSettingsKeyImpl *>(aParentKeyH)->DeleteSubkey(aID); |
1568 | } |
1569 | |
1570 | |
1571 | |
1572 | |
1573 | |
1574 | |
1575 | |
1576 | |
1577 | TSyError TEngineInterface::GetKeyID(KeyH aKeyH, sInt32 &aID) |
1578 | { |
1579 | if (!aKeyH) return LOCERR_WRONGUSAGE; |
1580 | return reinterpret_cast<TSettingsKeyImpl *>(aKeyH)->GetKeyID(aID); |
1581 | } |
1582 | |
1583 | |
1584 | |
1585 | |
1586 | |
1587 | |
1588 | |
1589 | |
1590 | |
1591 | |
1592 | TSyError TEngineInterface::SetTextMode(KeyH aKeyH, uInt16 aCharSet, uInt16 aLineEndMode, bool aBigEndian) |
1593 | { |
1594 | if (!aKeyH) return LOCERR_WRONGUSAGE; |
1595 | return reinterpret_cast<TSettingsKeyImpl *>(aKeyH)->SetTextMode(aCharSet,aLineEndMode,aBigEndian); |
1596 | } |
1597 | |
1598 | |
1599 | |
1600 | |
1601 | |
1602 | |
1603 | |
1604 | TSyError TEngineInterface::SetTimeMode(KeyH aKeyH, uInt16 aTimeMode) |
1605 | { |
1606 | if (!aKeyH) return LOCERR_WRONGUSAGE; |
1607 | return reinterpret_cast<TSettingsKeyImpl *>(aKeyH)->SetTimeMode(aTimeMode); |
1608 | } |
1609 | |
1610 | |
1611 | |
1612 | |
1613 | |
1614 | |
1615 | TSyError TEngineInterface::CloseKey(KeyH aKeyH) |
1616 | { |
1617 | if (aKeyH) { |
1618 | |
1619 | delete reinterpret_cast<TSettingsKeyImpl *>(aKeyH); |
1620 | } |
1621 | return LOCERR_OK; |
1622 | } |
1623 | |
1624 | |
1625 | |
1626 | |
1627 | |
1628 | |
1629 | sInt32 TEngineInterface::GetValueID(KeyH aKeyH, cAppCharP aName) |
1630 | { |
1631 | if (!aKeyH) return KEYVAL_ID_UNKNOWN; |
1632 | |
1633 | |
1634 | string tempStr; |
1635 | aName = makeAppString(aName, tempStr); |
1636 | |
1637 | return reinterpret_cast<TSettingsKeyImpl *>(aKeyH)->GetValueID(aName); |
1638 | } |
1639 | |
1640 | |
1641 | |
1642 | |
1643 | |
1644 | |
1645 | |
1646 | |
1647 | |
1648 | |
1649 | |
1650 | |
1651 | TSyError TEngineInterface::GetValue( |
1652 | KeyH aKeyH, cAppCharP aValueName, |
1653 | uInt16 aValType, |
1654 | appPointer aBuffer, memSize aBufSize, memSize &aValSize |
1655 | ) |
1656 | { |
1657 | if (!aKeyH) return LOCERR_WRONGUSAGE; |
1658 | |
1659 | |
1660 | sInt32 valId = GetValueID(aKeyH,aValueName); |
1661 | if (valId==KEYVAL_ID_UNKNOWN) return DB_NotFound; |
1662 | |
1663 | return reinterpret_cast<TSettingsKeyImpl *>(aKeyH)->GetValueByID( |
1664 | valId,0,aValType,aBuffer,aBufSize,aValSize |
1665 | ); |
1666 | } |
1667 | |
1668 | |
1669 | |
1670 | |
1671 | |
1672 | |
1673 | |
1674 | |
1675 | |
1676 | |
1677 | |
1678 | |
1679 | |
1680 | |
1681 | TSyError TEngineInterface::GetValueByID( |
1682 | KeyH aKeyH, sInt32 aID, sInt32 aArrayIndex, |
1683 | uInt16 aValType, |
1684 | appPointer aBuffer, memSize aBufSize, memSize &aValSize |
1685 | ) |
1686 | { |
1687 | if (!aKeyH) return LOCERR_WRONGUSAGE; |
1688 | if (aID==KEYVAL_NO_ID) return LOCERR_BADPARAM; |
1689 | return reinterpret_cast<TSettingsKeyImpl *>(aKeyH)->GetValueByID( |
1690 | aID,aArrayIndex,aValType,aBuffer,aBufSize,aValSize |
1691 | ); |
1692 | } |
1693 | |
1694 | |
1695 | |
1696 | |
1697 | |
1698 | |
1699 | |
1700 | |
1701 | |
1702 | |
1703 | TSyError TEngineInterface::SetValue( |
1704 | KeyH aKeyH, cAppCharP aValueName, |
1705 | uInt16 aValType, |
1706 | cAppPointer aBuffer, memSize aValSize |
1707 | ) { |
1708 | if (!aKeyH) return LOCERR_WRONGUSAGE; |
1709 | |
1710 | |
1711 | sInt32 valId = GetValueID(aKeyH,aValueName); |
1712 | if (valId==KEYVAL_ID_UNKNOWN) return DB_NotFound; |
1713 | return reinterpret_cast<TSettingsKeyImpl *>(aKeyH)->SetValueByID( |
1714 | valId,0,aValType,aBuffer,aValSize |
1715 | ); |
1716 | } |
1717 | |
1718 | |
1719 | |
1720 | |
1721 | |
1722 | |
1723 | |
1724 | |
1725 | |
1726 | |
1727 | TSyError TEngineInterface::SetValueByID( |
1728 | KeyH aKeyH, sInt32 aID, sInt32 aArrayIndex, |
1729 | uInt16 aValType, |
1730 | cAppPointer aBuffer, memSize aValSize |
1731 | ) |
1732 | { |
1733 | if (!aKeyH) return LOCERR_WRONGUSAGE; |
1734 | if (aID==KEYVAL_NO_ID) return LOCERR_BADPARAM; |
1735 | return reinterpret_cast<TSettingsKeyImpl *>(aKeyH)->SetValueByID( |
1736 | aID,aArrayIndex,aValType,aBuffer,aValSize |
1737 | ); |
1738 | } |
1739 | |
1740 | |
1741 | |
1742 | #ifdef DBAPI_TUNNEL_SUPPORT |
1743 | |
1744 | |
1745 | |
1746 | |
1747 | TSyError TEngineInterface::StartDataRead(SessionH aSessionH, cAppCharP lastToken, cAppCharP resumeToken) |
1748 | { |
1749 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1750 | if (!ds) return LOCERR_WRONGUSAGE; |
1751 | return ds->TunnelStartDataRead(lastToken,resumeToken); |
1752 | } |
1753 | |
1754 | |
1755 | TSyError TEngineInterface::ReadNextItem(SessionH aSessionH, ItemID aID, appCharP *aItemData, sInt32 *aStatus, bool aFirst) |
1756 | { |
1757 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1758 | if (!ds) return LOCERR_WRONGUSAGE; |
1759 | return ds->TunnelReadNextItem(aID,aItemData,aStatus,aFirst); |
1760 | } |
1761 | |
1762 | |
1763 | TSyError TEngineInterface::ReadItem(SessionH aSessionH, cItemID aID, appCharP *aItemData) |
1764 | { |
1765 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1766 | if (!ds) return LOCERR_WRONGUSAGE; |
1767 | return ds->TunnelReadItem(aID,aItemData); |
1768 | } |
1769 | |
1770 | |
1771 | TSyError TEngineInterface::EndDataRead(SessionH aSessionH) |
1772 | { |
1773 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1774 | if (!ds) return LOCERR_WRONGUSAGE; |
1775 | return ds->TunnelEndDataRead(); |
1776 | } |
1777 | |
1778 | |
1779 | TSyError TEngineInterface::StartDataWrite(SessionH aSessionH) |
1780 | { |
1781 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1782 | if (!ds) return LOCERR_WRONGUSAGE; |
1783 | return ds->TunnelStartDataWrite(); |
1784 | } |
1785 | |
1786 | |
1787 | TSyError TEngineInterface::InsertItem(SessionH aSessionH, cAppCharP aItemData, ItemID aID) |
1788 | { |
1789 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1790 | if (!ds) return LOCERR_WRONGUSAGE; |
1791 | return ds->TunnelInsertItem(aItemData,aID); |
1792 | } |
1793 | |
1794 | |
1795 | TSyError TEngineInterface::UpdateItem(SessionH aSessionH, cAppCharP aItemData, cItemID aID, ItemID updID ) |
1796 | { |
1797 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1798 | if (!ds) return LOCERR_WRONGUSAGE; |
1799 | return ds->TunnelUpdateItem(aItemData,aID,updID); |
1800 | } |
1801 | |
1802 | |
1803 | TSyError TEngineInterface::MoveItem(SessionH aSessionH, cItemID aID, cAppCharP newParID) |
1804 | { |
1805 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1806 | if (!ds) return LOCERR_WRONGUSAGE; |
1807 | return ds->TunnelMoveItem(aID,newParID); |
1808 | } |
1809 | |
1810 | |
1811 | TSyError TEngineInterface::DeleteItem(SessionH aSessionH, cItemID aID) |
1812 | { |
1813 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1814 | if (!ds) return LOCERR_WRONGUSAGE; |
1815 | return ds->TunnelDeleteItem(aID); |
1816 | } |
1817 | |
1818 | |
1819 | TSyError TEngineInterface::EndDataWrite(SessionH aSessionH, bool success, appCharP *newToken) |
1820 | { |
1821 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1822 | if (!ds) return LOCERR_WRONGUSAGE; |
1823 | return ds->TunnelEndDataWrite(success,newToken); |
1824 | } |
1825 | |
1826 | |
1827 | void TEngineInterface::DisposeObj(SessionH aSessionH, void* memory) |
1828 | { |
1829 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1830 | if (!ds) return; |
1831 | return ds->TunnelDisposeObj(memory); |
1832 | } |
1833 | |
1834 | |
1835 | |
1836 | TSyError TEngineInterface::ReadNextItemAsKey(SessionH aSessionH, ItemID aID, KeyH aItemKey, sInt32 *aStatus, bool aFirst) |
1837 | { |
1838 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1839 | if (!ds) return LOCERR_WRONGUSAGE; |
1840 | return ds->TunnelReadNextItemAsKey(aID,aItemKey,aStatus,aFirst); |
1841 | } |
1842 | |
1843 | |
1844 | TSyError TEngineInterface::ReadItemAsKey(SessionH aSessionH, cItemID aID, KeyH aItemKey) |
1845 | { |
1846 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1847 | if (!ds) return LOCERR_WRONGUSAGE; |
1848 | return ds->TunnelReadItemAsKey(aID,aItemKey); |
1849 | } |
1850 | |
1851 | |
1852 | TSyError TEngineInterface::InsertItemAsKey(SessionH aSessionH, KeyH aItemKey, ItemID aID) |
1853 | { |
1854 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1855 | if (!ds) return LOCERR_WRONGUSAGE; |
1856 | return ds->TunnelInsertItemAsKey(aItemKey,aID); |
1857 | } |
1858 | |
1859 | |
1860 | TSyError TEngineInterface::UpdateItemAsKey(SessionH aSessionH, KeyH aItemKey, cItemID aID, ItemID updID) |
1861 | { |
1862 | TLocalEngineDS *ds = reinterpret_cast<TSyncSession *>(aSessionH)->getTunnelDS(); |
1863 | if (!ds) return LOCERR_WRONGUSAGE; |
1864 | return ds->TunnelUpdateItemAsKey(aItemKey,aID,updID); |
1865 | } |
1866 | |
1867 | #endif // DBAPI_TUNNEL_SUPPORT |
1868 | |
1869 | TSyError TEngineInterface::debugPuts(cAppCharP aFile, int aLine, cAppCharP aFunction, |
1870 | int aDbgLevel, cAppCharP aPrefix, |
1871 | cAppCharP aText) |
1872 | { |
1873 | #if defined(SYDEBUG2) |
1874 | |
1875 | |
1876 | |
1877 | if (aPrefix) { |
1878 | std::string body = aPrefix; |
1879 | if (aText) { |
1880 | body += ": "; |
1881 | body += aText; |
1882 | } |
1883 | getSyncAppBase()->getDbgLogger()->DebugPuts(TDBG_LOCATION_ARGS(aFunction, aFile, aLine ) |
1884 | aDbgLevel, body.c_str()); |
1885 | } else { |
1886 | getSyncAppBase()->getDbgLogger()->DebugPuts(TDBG_LOCATION_ARGS(aFunction, aFile, aLine) |
1887 | aDbgLevel, aText); |
1888 | } |
1889 | return 0; |
1890 | #else |
1891 | return LOCERR_NOTIMP; |
1892 | #endif |
1893 | } |
1894 | |
1895 | #ifdef ENGINE_LIBRARY1 |
1896 | #ifndef SIMPLE_LINKING |
1897 | |
1898 | |
1899 | |
1900 | static TSyError internal_ConnectEngine( |
1901 | bool aIsServer, |
1902 | UI_Call_In *aCIP, |
1903 | uInt16 aCallbackVersion, |
1904 | CVersion *aEngVersionP, |
1905 | CVersion aPrgVersion, |
1906 | uInt16 aDebugFlags |
1907 | ) |
1908 | { |
1909 | |
1910 | TEngineModuleBase *engine = NULL__null; |
1911 | TSyError err = LOCERR_OK; |
1912 | if (aIsServer) { |
1913 | #ifdef SYSYNC_SERVER1 |
1914 | engine = newServerEngine(); |
1915 | #else |
1916 | err = LOCERR_WRONGUSAGE; |
1917 | #endif |
1918 | } |
1919 | else { |
1920 | #ifdef SYSYNC_CLIENT1 |
1921 | engine = newClientEngine(); |
1922 | #else |
1923 | err = LOCERR_WRONGUSAGE; |
1924 | #endif |
1925 | } |
1926 | if (err==LOCERR_OK) { |
1927 | |
1928 | if (aCallbackVersion!=0) { |
1929 | |
1930 | |
1931 | engine->fCIisStatic= true; |
1932 | |
1933 | (*aCIP)->callbackVersion = aCallbackVersion; |
1934 | engine->fCI = *aCIP; |
1935 | |
1936 | err = engine->Connect("", aPrgVersion, aDebugFlags); |
1937 | } |
1938 | else { |
1939 | |
1940 | |
1941 | err = engine->Connect("", aPrgVersion, aDebugFlags); |
1942 | |
1943 | *aCIP = engine->fCI; |
1944 | } |
1945 | |
1946 | if (aEngVersionP) *aEngVersionP = Plugin_Version(0); |
1947 | } |
1948 | return err; |
1949 | } |
1950 | |
1951 | |
1952 | |
1953 | TSyError SYSYNC_EXTERNAL(ConnectEngine)SySync_ConnectEngine( |
1954 | UI_Call_In *aCI, |
1955 | CVersion *aEngVersion, |
1956 | CVersion aPrgVersion, |
1957 | uInt16 aDebugFlags |
1958 | ) |
1959 | { |
1960 | return internal_ConnectEngine(false, aCI, 0, aEngVersion, aPrgVersion, aDebugFlags); |
1961 | } |
1962 | |
1963 | |
1964 | |
1965 | TSyError SYSYNC_EXTERNAL(ConnectEngineS)SySync_ConnectEngineS( |
1966 | UI_Call_In aCI, |
1967 | uInt16 aCallbackVersion, |
1968 | CVersion *aEngVersion, |
1969 | CVersion aPrgVersion, |
1970 | uInt16 aDebugFlags |
1971 | ) |
1972 | { |
1973 | return internal_ConnectEngine(false, &aCI, aCallbackVersion, aEngVersion, aPrgVersion, aDebugFlags); |
1974 | } |
1975 | |
1976 | |
1977 | |
1978 | TSyError SYSYNC_EXTERNAL_SRV(ConnectEngine)SySync_srv_ConnectEngine( |
1979 | UI_Call_In *aCI, |
1980 | CVersion *aEngVersion, |
1981 | CVersion aPrgVersion, |
1982 | uInt16 aDebugFlags |
1983 | ) |
1984 | { |
1985 | return internal_ConnectEngine(true, aCI, 0, aEngVersion, aPrgVersion, aDebugFlags); |
1986 | } |
1987 | |
1988 | |
1989 | |
1990 | TSyError SYSYNC_EXTERNAL_SRV(ConnectEngineS)SySync_srv_ConnectEngineS( |
1991 | UI_Call_In aCI, |
1992 | uInt16 aCallbackVersion, |
1993 | CVersion *aEngVersion, |
1994 | CVersion aPrgVersion, |
1995 | uInt16 aDebugFlags |
1996 | ) |
1997 | { |
1998 | return internal_ConnectEngine(true, &aCI, aCallbackVersion, aEngVersion, aPrgVersion, aDebugFlags); |
1999 | } |
2000 | |
2001 | |
2002 | |
2003 | |
2004 | static TSyError internal_DisconnectEngine(UI_Call_In aCI) |
2005 | { |
2006 | TSyError err= LOCERR_OK; |
2007 | |
2008 | if (aCI && aCI->thisBase) { |
2009 | |
2010 | TEngineModuleBase *engine = static_cast<TEngineModuleBase *>(aCI->thisBase); |
2011 | err= engine->Disconnect(); |
2012 | aCI->thisBase= NULL__null; |
2013 | |
2014 | SYSYNC_TRYtry { |
2015 | delete engine; |
2016 | } |
2017 | SYSYNC_CATCH (...)catch(...) { |
2018 | err = LOCERR_EXCEPTION; |
2019 | SYSYNC_ENDCATCH} |
2020 | |
2021 | } |
2022 | return err; |
2023 | } |
2024 | |
2025 | |
2026 | |
2027 | TSyError SYSYNC_EXTERNAL(DisconnectEngine)SySync_DisconnectEngine(UI_Call_In aCI) |
2028 | { |
2029 | return internal_DisconnectEngine(aCI); |
2030 | } |
2031 | |
2032 | |
2033 | |
2034 | TSyError SYSYNC_EXTERNAL_SRV(DisconnectEngine)SySync_srv_DisconnectEngine(UI_Call_In aCI) |
2035 | { |
2036 | return internal_DisconnectEngine(aCI); |
2037 | } |
2038 | |
2039 | |
2040 | #endif // not SIMPLE_LINKING |
2041 | #endif // ENGINE_LIBRARY |
2042 | |
2043 | |
2044 | } |
2045 | |
2046 | |
2047 | |
2048 | #endif // ENGINEINTERFACE_SUPPORT |
2049 | |
2050 | |