1 /**********************************************************
2 * This file has been automatically created by "typemaker2"
3 * from the file "element.xml".
4 * Please do not edit this file, all changes will be lost.
5 * Better edit the mentioned source file instead.
6 **********************************************************/
7
8 #ifdef HAVE_CONFIG_H
9 # include <config.h>
10 #endif
11
12 #include "./element_p.h"
13
14 #include <gwenhywfar/misc.h>
15 #include <gwenhywfar/debug.h>
16
17 /* code headers */
18 #include <string.h>
19
20 /* macro functions */
GWEN_TREE2_FUNCTIONS(AQFINTS_ELEMENT,AQFINTS_Element)21 GWEN_TREE2_FUNCTIONS(AQFINTS_ELEMENT, AQFINTS_Element)
22
23
24 AQFINTS_ELEMENT_TYPE AQFINTS_ElementType_fromString(const char *p_s)
25 {
26 if (p_s && *p_s) {
27 if (strcasecmp(p_s, "root")==0)
28 return AQFINTS_ElementType_Root;
29 else if (strcasecmp(p_s, "group")==0)
30 return AQFINTS_ElementType_Group;
31 else if (strcasecmp(p_s, "de")==0)
32 return AQFINTS_ElementType_De;
33 else if (strcasecmp(p_s, "deg")==0)
34 return AQFINTS_ElementType_Deg;
35 }
36 return AQFINTS_ElementType_Unknown;
37 }
38
AQFINTS_ElementDataType_fromString(const char * p_s)39 AQFINTS_ELEMENT_DATATYPE AQFINTS_ElementDataType_fromString(const char *p_s)
40 {
41 if (p_s && *p_s) {
42 if (strcasecmp(p_s, "int")==0)
43 return AQFINTS_ElementDataType_Int;
44 else if (strcasecmp(p_s, "char")==0)
45 return AQFINTS_ElementDataType_Char;
46 else if (strcasecmp(p_s, "bin")==0)
47 return AQFINTS_ElementDataType_Bin;
48 }
49 return AQFINTS_ElementDataType_Unknown;
50 }
51
AQFINTS_ElementType_toString(AQFINTS_ELEMENT_TYPE p_i)52 const char *AQFINTS_ElementType_toString(AQFINTS_ELEMENT_TYPE p_i)
53 {
54 switch (p_i) {
55 case AQFINTS_ElementType_Root:
56 return "root";
57 case AQFINTS_ElementType_Group:
58 return "group";
59 case AQFINTS_ElementType_De:
60 return "de";
61 case AQFINTS_ElementType_Deg:
62 return "deg";
63 case AQFINTS_ElementType_Unknown:
64 default:
65 return "unknown";
66 }
67 }
68
AQFINTS_ElementDataType_toString(AQFINTS_ELEMENT_DATATYPE p_i)69 const char *AQFINTS_ElementDataType_toString(AQFINTS_ELEMENT_DATATYPE p_i)
70 {
71 switch (p_i) {
72 case AQFINTS_ElementDataType_Int:
73 return "int";
74 case AQFINTS_ElementDataType_Char:
75 return "char";
76 case AQFINTS_ElementDataType_Bin:
77 return "bin";
78 case AQFINTS_ElementDataType_Unknown:
79 default:
80 return "unknown";
81 }
82 }
83
AQFINTS_Element_new(void)84 AQFINTS_ELEMENT *AQFINTS_Element_new(void)
85 {
86 AQFINTS_ELEMENT *p_struct;
87
88 GWEN_NEW_OBJECT(AQFINTS_ELEMENT, p_struct)
89 p_struct->_refCount=1;
90 GWEN_TREE2_INIT(AQFINTS_ELEMENT, p_struct, AQFINTS_Element)
91 /* members */
92 p_struct->flags=0;
93 p_struct->elementType=AQFINTS_ElementType_De;
94 p_struct->id=NULL;
95 p_struct->name=NULL;
96 p_struct->version=0;
97 p_struct->type=NULL;
98 p_struct->minNum=1;
99 p_struct->maxNum=1;
100 p_struct->minSize=0;
101 p_struct->maxSize=-1;
102 p_struct->trustLevel=0;
103 p_struct->data.pointer=NULL;
104 p_struct->data.length=0;
105 p_struct->runtimeFlags=0;
106 /* virtual functions */
107
108 return p_struct;
109 }
110
AQFINTS_Element_free(AQFINTS_ELEMENT * p_struct)111 void AQFINTS_Element_free(AQFINTS_ELEMENT *p_struct)
112 {
113 if (p_struct) {
114 assert(p_struct->_refCount);
115 if (p_struct->_refCount==1) {
116 GWEN_TREE2_FINI(AQFINTS_ELEMENT, p_struct, AQFINTS_Element)
117 /* members */
118 free(p_struct->id);
119 p_struct->id=NULL;
120 free(p_struct->name);
121 p_struct->name=NULL;
122 free(p_struct->type);
123 p_struct->type=NULL;
124 if (p_struct->data.length && p_struct->data.pointer) {
125 free(p_struct->data.pointer);
126 }
127 p_struct->data.pointer=NULL;
128 p_struct->data.length=0;
129 p_struct->_refCount=0;
130 GWEN_FREE_OBJECT(p_struct);
131 }
132 else
133 p_struct->_refCount--;
134 }
135 }
136
AQFINTS_Element_Attach(AQFINTS_ELEMENT * p_struct)137 void AQFINTS_Element_Attach(AQFINTS_ELEMENT *p_struct)
138 {
139 assert(p_struct);
140 assert(p_struct->_refCount);
141 p_struct->_refCount++;
142 }
143
AQFINTS_Element_dup(const AQFINTS_ELEMENT * p_src)144 AQFINTS_ELEMENT *AQFINTS_Element_dup(const AQFINTS_ELEMENT *p_src)
145 {
146 AQFINTS_ELEMENT *p_struct;
147
148 assert(p_src);
149 p_struct=AQFINTS_Element_new();
150 /* member "flags" */
151 p_struct->flags=p_src->flags;
152
153 /* member "elementType" */
154 p_struct->elementType=p_src->elementType;
155
156 /* member "id" */
157 if (p_struct->id) {
158 free(p_struct->id);
159 p_struct->id=NULL;
160 p_struct->id=NULL;
161 }
162 if (p_src->id) {
163 p_struct->id=strdup(p_src->id);
164 }
165
166 /* member "name" */
167 if (p_struct->name) {
168 free(p_struct->name);
169 p_struct->name=NULL;
170 p_struct->name=NULL;
171 }
172 if (p_src->name) {
173 p_struct->name=strdup(p_src->name);
174 }
175
176 /* member "version" */
177 p_struct->version=p_src->version;
178
179 /* member "type" */
180 if (p_struct->type) {
181 free(p_struct->type);
182 p_struct->type=NULL;
183 p_struct->type=NULL;
184 }
185 if (p_src->type) {
186 p_struct->type=strdup(p_src->type);
187 }
188
189 /* member "minNum" */
190 p_struct->minNum=p_src->minNum;
191
192 /* member "maxNum" */
193 p_struct->maxNum=p_src->maxNum;
194
195 /* member "minSize" */
196 p_struct->minSize=p_src->minSize;
197
198 /* member "maxSize" */
199 p_struct->maxSize=p_src->maxSize;
200
201 /* member "trustLevel" */
202 p_struct->trustLevel=p_src->trustLevel;
203
204 /* member "data" */
205 if (p_src->data.length && p_src->data.pointer) {
206 p_struct->data.pointer=(uint8_t *) malloc(p_src->data.length);
207 if (p_struct->data.pointer) {
208 p_struct->data.length=p_src->data.length;
209 memmove(p_struct->data.pointer, p_src->data.pointer, p_src->data.length);
210 }
211 else {
212 p_struct->data.pointer=NULL;
213 p_struct->data.length=0;
214 }
215 }
216 else {
217 p_struct->data.pointer=NULL;
218 p_struct->data.length=0;
219 }
220
221 /* member "runtimeFlags" */
222 p_struct->runtimeFlags=p_src->runtimeFlags;
223
224 return p_struct;
225 }
226
AQFINTS_Element_copy(AQFINTS_ELEMENT * p_struct,const AQFINTS_ELEMENT * p_src)227 AQFINTS_ELEMENT *AQFINTS_Element_copy(AQFINTS_ELEMENT *p_struct, const AQFINTS_ELEMENT *p_src)
228 {
229 assert(p_struct);
230 assert(p_src);
231 /* member "flags" */
232 p_struct->flags=p_src->flags;
233
234 /* member "elementType" */
235 p_struct->elementType=p_src->elementType;
236
237 /* member "id" */
238 if (p_struct->id) {
239 free(p_struct->id);
240 p_struct->id=NULL;
241 p_struct->id=NULL;
242 }
243 if (p_src->id) {
244 p_struct->id=strdup(p_src->id);
245 }
246
247 /* member "name" */
248 if (p_struct->name) {
249 free(p_struct->name);
250 p_struct->name=NULL;
251 p_struct->name=NULL;
252 }
253 if (p_src->name) {
254 p_struct->name=strdup(p_src->name);
255 }
256
257 /* member "version" */
258 p_struct->version=p_src->version;
259
260 /* member "type" */
261 if (p_struct->type) {
262 free(p_struct->type);
263 p_struct->type=NULL;
264 p_struct->type=NULL;
265 }
266 if (p_src->type) {
267 p_struct->type=strdup(p_src->type);
268 }
269
270 /* member "minNum" */
271 p_struct->minNum=p_src->minNum;
272
273 /* member "maxNum" */
274 p_struct->maxNum=p_src->maxNum;
275
276 /* member "minSize" */
277 p_struct->minSize=p_src->minSize;
278
279 /* member "maxSize" */
280 p_struct->maxSize=p_src->maxSize;
281
282 /* member "trustLevel" */
283 p_struct->trustLevel=p_src->trustLevel;
284
285 /* member "data" */
286 if (p_src->data.length && p_src->data.pointer) {
287 p_struct->data.pointer=(uint8_t *) malloc(p_src->data.length);
288 if (p_struct->data.pointer) {
289 p_struct->data.length=p_src->data.length;
290 memmove(p_struct->data.pointer, p_src->data.pointer, p_src->data.length);
291 }
292 else {
293 p_struct->data.pointer=NULL;
294 p_struct->data.length=0;
295 }
296 }
297 else {
298 p_struct->data.pointer=NULL;
299 p_struct->data.length=0;
300 }
301
302 /* member "runtimeFlags" */
303 p_struct->runtimeFlags=p_src->runtimeFlags;
304
305 return p_struct;
306 }
307
AQFINTS_Element_GetFlags(const AQFINTS_ELEMENT * p_struct)308 uint32_t AQFINTS_Element_GetFlags(const AQFINTS_ELEMENT *p_struct)
309 {
310 assert(p_struct);
311 return p_struct->flags;
312 }
313
AQFINTS_Element_GetElementType(const AQFINTS_ELEMENT * p_struct)314 AQFINTS_ELEMENT_TYPE AQFINTS_Element_GetElementType(const AQFINTS_ELEMENT *p_struct)
315 {
316 assert(p_struct);
317 return p_struct->elementType;
318 }
319
AQFINTS_Element_GetId(const AQFINTS_ELEMENT * p_struct)320 const char *AQFINTS_Element_GetId(const AQFINTS_ELEMENT *p_struct)
321 {
322 assert(p_struct);
323 return p_struct->id;
324 }
325
AQFINTS_Element_GetName(const AQFINTS_ELEMENT * p_struct)326 const char *AQFINTS_Element_GetName(const AQFINTS_ELEMENT *p_struct)
327 {
328 assert(p_struct);
329 return p_struct->name;
330 }
331
AQFINTS_Element_GetVersion(const AQFINTS_ELEMENT * p_struct)332 int AQFINTS_Element_GetVersion(const AQFINTS_ELEMENT *p_struct)
333 {
334 assert(p_struct);
335 return p_struct->version;
336 }
337
AQFINTS_Element_GetType(const AQFINTS_ELEMENT * p_struct)338 const char *AQFINTS_Element_GetType(const AQFINTS_ELEMENT *p_struct)
339 {
340 assert(p_struct);
341 return p_struct->type;
342 }
343
AQFINTS_Element_GetMinNum(const AQFINTS_ELEMENT * p_struct)344 int AQFINTS_Element_GetMinNum(const AQFINTS_ELEMENT *p_struct)
345 {
346 assert(p_struct);
347 return p_struct->minNum;
348 }
349
AQFINTS_Element_GetMaxNum(const AQFINTS_ELEMENT * p_struct)350 int AQFINTS_Element_GetMaxNum(const AQFINTS_ELEMENT *p_struct)
351 {
352 assert(p_struct);
353 return p_struct->maxNum;
354 }
355
AQFINTS_Element_GetMinSize(const AQFINTS_ELEMENT * p_struct)356 int AQFINTS_Element_GetMinSize(const AQFINTS_ELEMENT *p_struct)
357 {
358 assert(p_struct);
359 return p_struct->minSize;
360 }
361
AQFINTS_Element_GetMaxSize(const AQFINTS_ELEMENT * p_struct)362 int AQFINTS_Element_GetMaxSize(const AQFINTS_ELEMENT *p_struct)
363 {
364 assert(p_struct);
365 return p_struct->maxSize;
366 }
367
AQFINTS_Element_GetTrustLevel(const AQFINTS_ELEMENT * p_struct)368 int AQFINTS_Element_GetTrustLevel(const AQFINTS_ELEMENT *p_struct)
369 {
370 assert(p_struct);
371 return p_struct->trustLevel;
372 }
373
AQFINTS_Element_GetRuntimeFlags(const AQFINTS_ELEMENT * p_struct)374 uint32_t AQFINTS_Element_GetRuntimeFlags(const AQFINTS_ELEMENT *p_struct)
375 {
376 assert(p_struct);
377 return p_struct->runtimeFlags;
378 }
379
AQFINTS_Element_SetFlags(AQFINTS_ELEMENT * p_struct,uint32_t p_src)380 void AQFINTS_Element_SetFlags(AQFINTS_ELEMENT *p_struct, uint32_t p_src)
381 {
382 assert(p_struct);
383 p_struct->flags=p_src;
384 }
385
AQFINTS_Element_AddFlags(AQFINTS_ELEMENT * p_struct,uint32_t p_src)386 void AQFINTS_Element_AddFlags(AQFINTS_ELEMENT *p_struct, uint32_t p_src)
387 {
388 assert(p_struct);
389 p_struct->flags|=p_src;
390 }
391
AQFINTS_Element_SubFlags(AQFINTS_ELEMENT * p_struct,uint32_t p_src)392 void AQFINTS_Element_SubFlags(AQFINTS_ELEMENT *p_struct, uint32_t p_src)
393 {
394 assert(p_struct);
395 p_struct->flags&=~p_src;
396 }
397
AQFINTS_Element_SetElementType(AQFINTS_ELEMENT * p_struct,AQFINTS_ELEMENT_TYPE p_src)398 void AQFINTS_Element_SetElementType(AQFINTS_ELEMENT *p_struct, AQFINTS_ELEMENT_TYPE p_src)
399 {
400 assert(p_struct);
401 p_struct->elementType=p_src;
402 }
403
AQFINTS_Element_SetId(AQFINTS_ELEMENT * p_struct,const char * p_src)404 void AQFINTS_Element_SetId(AQFINTS_ELEMENT *p_struct, const char *p_src)
405 {
406 assert(p_struct);
407 if (p_struct->id) {
408 free(p_struct->id);
409 p_struct->id=NULL;
410 }
411 if (p_src) {
412 p_struct->id=strdup(p_src);
413 }
414 else {
415 p_struct->id=NULL;
416 }
417 }
418
AQFINTS_Element_SetName(AQFINTS_ELEMENT * p_struct,const char * p_src)419 void AQFINTS_Element_SetName(AQFINTS_ELEMENT *p_struct, const char *p_src)
420 {
421 assert(p_struct);
422 if (p_struct->name) {
423 free(p_struct->name);
424 p_struct->name=NULL;
425 }
426 if (p_src) {
427 p_struct->name=strdup(p_src);
428 }
429 else {
430 p_struct->name=NULL;
431 }
432 }
433
AQFINTS_Element_SetVersion(AQFINTS_ELEMENT * p_struct,int p_src)434 void AQFINTS_Element_SetVersion(AQFINTS_ELEMENT *p_struct, int p_src)
435 {
436 assert(p_struct);
437 p_struct->version=p_src;
438 }
439
AQFINTS_Element_SetType(AQFINTS_ELEMENT * p_struct,const char * p_src)440 void AQFINTS_Element_SetType(AQFINTS_ELEMENT *p_struct, const char *p_src)
441 {
442 assert(p_struct);
443 if (p_struct->type) {
444 free(p_struct->type);
445 p_struct->type=NULL;
446 }
447 if (p_src) {
448 p_struct->type=strdup(p_src);
449 }
450 else {
451 p_struct->type=NULL;
452 }
453 }
454
AQFINTS_Element_SetMinNum(AQFINTS_ELEMENT * p_struct,int p_src)455 void AQFINTS_Element_SetMinNum(AQFINTS_ELEMENT *p_struct, int p_src)
456 {
457 assert(p_struct);
458 p_struct->minNum=p_src;
459 }
460
AQFINTS_Element_SetMaxNum(AQFINTS_ELEMENT * p_struct,int p_src)461 void AQFINTS_Element_SetMaxNum(AQFINTS_ELEMENT *p_struct, int p_src)
462 {
463 assert(p_struct);
464 p_struct->maxNum=p_src;
465 }
466
AQFINTS_Element_SetMinSize(AQFINTS_ELEMENT * p_struct,int p_src)467 void AQFINTS_Element_SetMinSize(AQFINTS_ELEMENT *p_struct, int p_src)
468 {
469 assert(p_struct);
470 p_struct->minSize=p_src;
471 }
472
AQFINTS_Element_SetMaxSize(AQFINTS_ELEMENT * p_struct,int p_src)473 void AQFINTS_Element_SetMaxSize(AQFINTS_ELEMENT *p_struct, int p_src)
474 {
475 assert(p_struct);
476 p_struct->maxSize=p_src;
477 }
478
AQFINTS_Element_SetTrustLevel(AQFINTS_ELEMENT * p_struct,int p_src)479 void AQFINTS_Element_SetTrustLevel(AQFINTS_ELEMENT *p_struct, int p_src)
480 {
481 assert(p_struct);
482 p_struct->trustLevel=p_src;
483 }
484
AQFINTS_Element_SetRuntimeFlags(AQFINTS_ELEMENT * p_struct,uint32_t p_src)485 void AQFINTS_Element_SetRuntimeFlags(AQFINTS_ELEMENT *p_struct, uint32_t p_src)
486 {
487 assert(p_struct);
488 p_struct->runtimeFlags=p_src;
489 }
490
AQFINTS_Element_AddRuntimeFlags(AQFINTS_ELEMENT * p_struct,uint32_t p_src)491 void AQFINTS_Element_AddRuntimeFlags(AQFINTS_ELEMENT *p_struct, uint32_t p_src)
492 {
493 assert(p_struct);
494 p_struct->runtimeFlags|=p_src;
495 }
496
AQFINTS_Element_SubRuntimeFlags(AQFINTS_ELEMENT * p_struct,uint32_t p_src)497 void AQFINTS_Element_SubRuntimeFlags(AQFINTS_ELEMENT *p_struct, uint32_t p_src)
498 {
499 assert(p_struct);
500 p_struct->runtimeFlags&=~p_src;
501 }
502
AQFINTS_Element_ReadDb(AQFINTS_ELEMENT * p_struct,GWEN_DB_NODE * p_db)503 void AQFINTS_Element_ReadDb(AQFINTS_ELEMENT *p_struct, GWEN_DB_NODE *p_db)
504 {
505 assert(p_struct);
506 /* member "flags" */
507 p_struct->flags=GWEN_DB_GetIntValue(p_db, "flags", 0, 0);
508
509 /* member "elementType" */
510 {
511 const char *s;
512 s=GWEN_DB_GetCharValue(p_db, "elementType", 0, NULL);
513 if (s)
514 p_struct->elementType=AQFINTS_ElementType_fromString(s);
515 else
516 p_struct->elementType=AQFINTS_ElementType_De;
517 }
518
519 /* member "id" */
520 if (p_struct->id) {
521 free(p_struct->id);
522 p_struct->id=NULL;
523 }
524 {
525 const char *s;
526 s=GWEN_DB_GetCharValue(p_db, "id", 0, NULL);
527 if (s)
528 p_struct->id=strdup(s);
529 }
530 if (p_struct->id==NULL) {
531 p_struct->id=NULL;
532 }
533
534 /* member "name" */
535 if (p_struct->name) {
536 free(p_struct->name);
537 p_struct->name=NULL;
538 }
539 {
540 const char *s;
541 s=GWEN_DB_GetCharValue(p_db, "name", 0, NULL);
542 if (s)
543 p_struct->name=strdup(s);
544 }
545 if (p_struct->name==NULL) {
546 p_struct->name=NULL;
547 }
548
549 /* member "version" */
550 p_struct->version=GWEN_DB_GetIntValue(p_db, "version", 0, 0);
551
552 /* member "type" */
553 if (p_struct->type) {
554 free(p_struct->type);
555 p_struct->type=NULL;
556 }
557 {
558 const char *s;
559 s=GWEN_DB_GetCharValue(p_db, "type", 0, NULL);
560 if (s)
561 p_struct->type=strdup(s);
562 }
563 if (p_struct->type==NULL) {
564 p_struct->type=NULL;
565 }
566
567 /* member "minNum" */
568 p_struct->minNum=GWEN_DB_GetIntValue(p_db, "minNum", 0, 1);
569
570 /* member "maxNum" */
571 p_struct->maxNum=GWEN_DB_GetIntValue(p_db, "maxNum", 0, 1);
572
573 /* member "minSize" */
574 p_struct->minSize=GWEN_DB_GetIntValue(p_db, "minSize", 0, 0);
575
576 /* member "maxSize" */
577 p_struct->maxSize=GWEN_DB_GetIntValue(p_db, "maxSize", 0, -1);
578
579 /* member "trustLevel" */
580 p_struct->trustLevel=GWEN_DB_GetIntValue(p_db, "trustLevel", 0, 0);
581
582 /* member "data" */
583 {
584 const void *v;
585 unsigned int vlen;
586 v=GWEN_DB_GetBinValue(p_db, "data", 0, NULL, 0, &vlen);
587 if (v && vlen) {
588 uint8_t *dest;
589 dest=(uint8_t *) malloc(vlen);
590 memmove(dest, v, vlen);
591 p_struct->data.pointer=dest;
592 p_struct->data.length=vlen;
593 }
594 }
595
596 /* member "runtimeFlags" */
597 /* member "runtimeFlags" is volatile, just presetting */
598 p_struct->runtimeFlags=0;
599
600 }
601
AQFINTS_Element_WriteDb(const AQFINTS_ELEMENT * p_struct,GWEN_DB_NODE * p_db)602 int AQFINTS_Element_WriteDb(const AQFINTS_ELEMENT *p_struct, GWEN_DB_NODE *p_db)
603 {
604 int p_rv;
605
606 assert(p_struct);
607 /* member "flags" */
608 p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "flags", p_struct->flags);
609 if (p_rv<0) {
610 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
611 return p_rv;
612 }
613
614 /* member "elementType" */
615 p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "elementType",
616 AQFINTS_ElementType_toString(p_struct->elementType));
617 if (p_rv<0) {
618 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
619 return p_rv;
620 }
621
622 /* member "id" */
623 if (p_struct->id)
624 p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "id", p_struct->id);
625 else {
626 GWEN_DB_DeleteVar(p_db, "id");
627 p_rv=0;
628 }
629 if (p_rv<0) {
630 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
631 return p_rv;
632 }
633
634 /* member "name" */
635 if (p_struct->name)
636 p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "name", p_struct->name);
637 else {
638 GWEN_DB_DeleteVar(p_db, "name");
639 p_rv=0;
640 }
641 if (p_rv<0) {
642 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
643 return p_rv;
644 }
645
646 /* member "version" */
647 p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "version", p_struct->version);
648 if (p_rv<0) {
649 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
650 return p_rv;
651 }
652
653 /* member "type" */
654 if (p_struct->type)
655 p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "type", p_struct->type);
656 else {
657 GWEN_DB_DeleteVar(p_db, "type");
658 p_rv=0;
659 }
660 if (p_rv<0) {
661 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
662 return p_rv;
663 }
664
665 /* member "minNum" */
666 p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "minNum", p_struct->minNum);
667 if (p_rv<0) {
668 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
669 return p_rv;
670 }
671
672 /* member "maxNum" */
673 p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "maxNum", p_struct->maxNum);
674 if (p_rv<0) {
675 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
676 return p_rv;
677 }
678
679 /* member "minSize" */
680 p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "minSize", p_struct->minSize);
681 if (p_rv<0) {
682 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
683 return p_rv;
684 }
685
686 /* member "maxSize" */
687 p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "maxSize", p_struct->maxSize);
688 if (p_rv<0) {
689 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
690 return p_rv;
691 }
692
693 /* member "trustLevel" */
694 p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "trustLevel", p_struct->trustLevel);
695 if (p_rv<0) {
696 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
697 return p_rv;
698 }
699
700 /* member "data" */
701 {
702 if (p_struct->data.length && p_struct->data.pointer) {
703 GWEN_DB_SetBinValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "data", p_struct->data.pointer, p_struct->data.length);
704 }
705 else {
706 GWEN_DB_DeleteVar(p_db, "data");
707 p_rv=0;
708 }
709 }
710 if (p_rv<0) {
711 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
712 return p_rv;
713 }
714
715 /* member "runtimeFlags" is volatile, not writing to db */
716
717 return 0;
718 }
719
AQFINTS_Element_fromDb(GWEN_DB_NODE * p_db)720 AQFINTS_ELEMENT *AQFINTS_Element_fromDb(GWEN_DB_NODE *p_db)
721 {
722 AQFINTS_ELEMENT *p_struct;
723 p_struct=AQFINTS_Element_new();
724 AQFINTS_Element_ReadDb(p_struct, p_db);
725 return p_struct;
726 }
727
AQFINTS_Element_toDb(const AQFINTS_ELEMENT * p_struct,GWEN_DB_NODE * p_db)728 int AQFINTS_Element_toDb(const AQFINTS_ELEMENT *p_struct, GWEN_DB_NODE *p_db)
729 {
730 return AQFINTS_Element_WriteDb(p_struct, p_db);
731 }
732
AQFINTS_Element_SetData(AQFINTS_ELEMENT * st,uint8_t * ptr,uint32_t len)733 void AQFINTS_Element_SetData(AQFINTS_ELEMENT *st, uint8_t *ptr, uint32_t len)
734 {
735 if (st->data.pointer && st->data.length) {
736 free(st->data.pointer);
737 }
738 st->data.pointer=ptr;
739 st->data.length=len;
740 }
AQFINTS_Element_SetDataCopy(AQFINTS_ELEMENT * st,const uint8_t * ptr,uint32_t len)741 void AQFINTS_Element_SetDataCopy(AQFINTS_ELEMENT *st, const uint8_t *ptr, uint32_t len)
742 {
743 /* free previous data */
744 if (st->data.pointer && st->data.length) {
745 free(st->data.pointer);
746 }
747 /* create copy if there is data to copy */
748 if (ptr && len) {
749 uint8_t *ptrCopy;
750 ptrCopy=(uint8_t *) malloc(len);
751 assert(ptrCopy);
752 memmove(ptrCopy, ptr, len);
753 st->data.pointer=ptrCopy;
754 st->data.length=len;
755 }
756 else {
757 st->data.pointer=NULL;
758 st->data.length=0;
759 }
760 }
AQFINTS_Element_SetTextDataCopy(AQFINTS_ELEMENT * st,const char * ptr)761 void AQFINTS_Element_SetTextDataCopy(AQFINTS_ELEMENT *st, const char *ptr)
762 {
763 /* free previous data */
764 if (st->data.pointer && st->data.length) {
765 free(st->data.pointer);
766 }
767 /* create copy if there is data to copy */
768 if (ptr) {
769 char *ptrCopy;
770 ptrCopy=strdup(ptr);
771 assert(ptrCopy);
772 st->data.pointer=(uint8_t *) ptrCopy;
773 st->data.length=strlen(ptrCopy)+1; /* count trailing zero */
774 }
775 else {
776 st->data.pointer=NULL;
777 st->data.length=0;
778 }
779 }
AQFINTS_Element_GetDataPointer(const AQFINTS_ELEMENT * st)780 const uint8_t *AQFINTS_Element_GetDataPointer(const AQFINTS_ELEMENT *st)
781 {
782 return st->data.pointer;
783 }
AQFINTS_Element_GetDataLength(const AQFINTS_ELEMENT * st)784 uint32_t AQFINTS_Element_GetDataLength(const AQFINTS_ELEMENT *st)
785 {
786 return st->data.length;
787 }
AQFINTS_Element_GetDataAsChar(const AQFINTS_ELEMENT * st,const char * defaultValue)788 const char *AQFINTS_Element_GetDataAsChar(const AQFINTS_ELEMENT *st, const char *defaultValue)
789 {
790 if (st->data.length && st->data.pointer && !(st->flags & AQFINTS_ELEMENT_FLAGS_ISBIN))
791 return (const char *)(st->data.pointer);
792 return defaultValue;
793 }
AQFINTS_Element_GetDataAsInt(const AQFINTS_ELEMENT * st,int defaultValue)794 int AQFINTS_Element_GetDataAsInt(const AQFINTS_ELEMENT *st, int defaultValue)
795 {
796 const char *s;
797 s=AQFINTS_Element_GetDataAsChar(st, NULL);
798 if (s && *s) {
799 long int retVal=0;
800 if (1==sscanf(s, "%li", &retVal))
801 return retVal;
802 }
803 return defaultValue;
804 }
AQFINTS_Element_SetDataAsInt(AQFINTS_ELEMENT * st,int value)805 void AQFINTS_Element_SetDataAsInt(AQFINTS_ELEMENT *st, int value)
806 {
807 char numbuf[32];
808 int i;
809 i=snprintf(numbuf, sizeof(numbuf)-1, "%i", value);
810 assert(i<=(sizeof(numbuf)-1));
811 numbuf[sizeof(numbuf)-1]=0;
812 AQFINTS_Element_SetTextDataCopy(st, numbuf);
813 }
814
815 /* code headers */
816
817