1 /**********************************************************
2  * This file has been automatically created by "typemaker2"
3  * from the file "document.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 "./document_p.h"
13 
14 #include <gwenhywfar/misc.h>
15 #include <gwenhywfar/debug.h>
16 
17 /* code headers */
18 
19 /* macro functions */
GWEN_LIST_FUNCTIONS(AB_DOCUMENT,AB_Document)20 GWEN_LIST_FUNCTIONS(AB_DOCUMENT, AB_Document)
21 GWEN_LIST2_FUNCTIONS(AB_DOCUMENT, AB_Document)
22 
23 
24 AB_DOCUMENT *AB_Document_new(void)
25 {
26   AB_DOCUMENT *p_struct;
27 
28   GWEN_NEW_OBJECT(AB_DOCUMENT, p_struct)
29   p_struct->_refCount=1;
30   GWEN_LIST_INIT(AB_DOCUMENT, p_struct)
31   /* members */
32   p_struct->id=NULL;
33   p_struct->ownerId=0;
34   p_struct->mimeType=NULL;
35   p_struct->data.pointer=NULL;
36   p_struct->data.length=0;
37   p_struct->acknowledgeCode.pointer=NULL;
38   p_struct->acknowledgeCode.length=0;
39   /* virtual functions */
40 
41   return p_struct;
42 }
43 
AB_Document_free(AB_DOCUMENT * p_struct)44 void AB_Document_free(AB_DOCUMENT *p_struct)
45 {
46   if (p_struct) {
47     assert(p_struct->_refCount);
48     if (p_struct->_refCount==1) {
49       GWEN_LIST_FINI(AB_DOCUMENT, p_struct)
50       /* members */
51       free(p_struct->id);
52       p_struct->id=NULL;
53       free(p_struct->mimeType);
54       p_struct->mimeType=NULL;
55       if (p_struct->data.length && p_struct->data.pointer) {
56         free(p_struct->data.pointer);
57       }
58       p_struct->data.pointer=NULL;
59       p_struct->data.length=0;
60       if (p_struct->acknowledgeCode.length && p_struct->acknowledgeCode.pointer) {
61         free(p_struct->acknowledgeCode.pointer);
62       }
63       p_struct->acknowledgeCode.pointer=NULL;
64       p_struct->acknowledgeCode.length=0;
65       p_struct->_refCount=0;
66       GWEN_FREE_OBJECT(p_struct);
67     }
68     else
69       p_struct->_refCount--;
70   }
71 }
72 
AB_Document_Attach(AB_DOCUMENT * p_struct)73 void AB_Document_Attach(AB_DOCUMENT *p_struct)
74 {
75   assert(p_struct);
76   assert(p_struct->_refCount);
77   p_struct->_refCount++;
78 }
79 
AB_Document_dup(const AB_DOCUMENT * p_src)80 AB_DOCUMENT *AB_Document_dup(const AB_DOCUMENT *p_src)
81 {
82   AB_DOCUMENT *p_struct;
83 
84   assert(p_src);
85   p_struct=AB_Document_new();
86   /* member "id" */
87   if (p_struct->id) {
88     free(p_struct->id);
89     p_struct->id=NULL;
90     p_struct->id=NULL;
91   }
92   if (p_src->id) {
93     p_struct->id=strdup(p_src->id);
94   }
95 
96   /* member "ownerId" */
97   p_struct->ownerId=p_src->ownerId;
98 
99   /* member "mimeType" */
100   if (p_struct->mimeType) {
101     free(p_struct->mimeType);
102     p_struct->mimeType=NULL;
103     p_struct->mimeType=NULL;
104   }
105   if (p_src->mimeType) {
106     p_struct->mimeType=strdup(p_src->mimeType);
107   }
108 
109   /* member "data" */
110   if (p_src->data.length && p_src->data.pointer) {
111     p_struct->data.pointer=(uint8_t *) malloc(p_src->data.length);
112     if (p_struct->data.pointer) {
113       p_struct->data.length=p_src->data.length;
114       memmove(p_struct->data.pointer, p_src->data.pointer, p_src->data.length);
115     }
116     else {
117       p_struct->data.pointer=NULL;
118       p_struct->data.length=0;
119     }
120   }
121   else {
122     p_struct->data.pointer=NULL;
123     p_struct->data.length=0;
124   }
125 
126   /* member "acknowledgeCode" */
127   if (p_src->acknowledgeCode.length && p_src->acknowledgeCode.pointer) {
128     p_struct->acknowledgeCode.pointer=(uint8_t *) malloc(p_src->acknowledgeCode.length);
129     if (p_struct->acknowledgeCode.pointer) {
130       p_struct->acknowledgeCode.length=p_src->acknowledgeCode.length;
131       memmove(p_struct->acknowledgeCode.pointer, p_src->acknowledgeCode.pointer, p_src->acknowledgeCode.length);
132     }
133     else {
134       p_struct->acknowledgeCode.pointer=NULL;
135       p_struct->acknowledgeCode.length=0;
136     }
137   }
138   else {
139     p_struct->acknowledgeCode.pointer=NULL;
140     p_struct->acknowledgeCode.length=0;
141   }
142 
143   return p_struct;
144 }
145 
AB_Document_copy(AB_DOCUMENT * p_struct,const AB_DOCUMENT * p_src)146 AB_DOCUMENT *AB_Document_copy(AB_DOCUMENT *p_struct, const AB_DOCUMENT *p_src)
147 {
148   assert(p_struct);
149   assert(p_src);
150   /* member "id" */
151   if (p_struct->id) {
152     free(p_struct->id);
153     p_struct->id=NULL;
154     p_struct->id=NULL;
155   }
156   if (p_src->id) {
157     p_struct->id=strdup(p_src->id);
158   }
159 
160   /* member "ownerId" */
161   p_struct->ownerId=p_src->ownerId;
162 
163   /* member "mimeType" */
164   if (p_struct->mimeType) {
165     free(p_struct->mimeType);
166     p_struct->mimeType=NULL;
167     p_struct->mimeType=NULL;
168   }
169   if (p_src->mimeType) {
170     p_struct->mimeType=strdup(p_src->mimeType);
171   }
172 
173   /* member "data" */
174   if (p_src->data.length && p_src->data.pointer) {
175     p_struct->data.pointer=(uint8_t *) malloc(p_src->data.length);
176     if (p_struct->data.pointer) {
177       p_struct->data.length=p_src->data.length;
178       memmove(p_struct->data.pointer, p_src->data.pointer, p_src->data.length);
179     }
180     else {
181       p_struct->data.pointer=NULL;
182       p_struct->data.length=0;
183     }
184   }
185   else {
186     p_struct->data.pointer=NULL;
187     p_struct->data.length=0;
188   }
189 
190   /* member "acknowledgeCode" */
191   if (p_src->acknowledgeCode.length && p_src->acknowledgeCode.pointer) {
192     p_struct->acknowledgeCode.pointer=(uint8_t *) malloc(p_src->acknowledgeCode.length);
193     if (p_struct->acknowledgeCode.pointer) {
194       p_struct->acknowledgeCode.length=p_src->acknowledgeCode.length;
195       memmove(p_struct->acknowledgeCode.pointer, p_src->acknowledgeCode.pointer, p_src->acknowledgeCode.length);
196     }
197     else {
198       p_struct->acknowledgeCode.pointer=NULL;
199       p_struct->acknowledgeCode.length=0;
200     }
201   }
202   else {
203     p_struct->acknowledgeCode.pointer=NULL;
204     p_struct->acknowledgeCode.length=0;
205   }
206 
207   return p_struct;
208 }
209 
AB_Document_GetId(const AB_DOCUMENT * p_struct)210 const char *AB_Document_GetId(const AB_DOCUMENT *p_struct)
211 {
212   assert(p_struct);
213   return p_struct->id;
214 }
215 
AB_Document_GetOwnerId(const AB_DOCUMENT * p_struct)216 uint32_t AB_Document_GetOwnerId(const AB_DOCUMENT *p_struct)
217 {
218   assert(p_struct);
219   return p_struct->ownerId;
220 }
221 
AB_Document_GetMimeType(const AB_DOCUMENT * p_struct)222 const char *AB_Document_GetMimeType(const AB_DOCUMENT *p_struct)
223 {
224   assert(p_struct);
225   return p_struct->mimeType;
226 }
227 
AB_Document_SetId(AB_DOCUMENT * p_struct,const char * p_src)228 void AB_Document_SetId(AB_DOCUMENT *p_struct, const char *p_src)
229 {
230   assert(p_struct);
231   if (p_struct->id) {
232     free(p_struct->id);
233     p_struct->id=NULL;
234   }
235   if (p_src) {
236     p_struct->id=strdup(p_src);
237   }
238   else {
239     p_struct->id=NULL;
240   }
241 }
242 
AB_Document_SetOwnerId(AB_DOCUMENT * p_struct,uint32_t p_src)243 void AB_Document_SetOwnerId(AB_DOCUMENT *p_struct, uint32_t p_src)
244 {
245   assert(p_struct);
246   p_struct->ownerId=p_src;
247 }
248 
AB_Document_SetMimeType(AB_DOCUMENT * p_struct,const char * p_src)249 void AB_Document_SetMimeType(AB_DOCUMENT *p_struct, const char *p_src)
250 {
251   assert(p_struct);
252   if (p_struct->mimeType) {
253     free(p_struct->mimeType);
254     p_struct->mimeType=NULL;
255   }
256   if (p_src) {
257     p_struct->mimeType=strdup(p_src);
258   }
259   else {
260     p_struct->mimeType=NULL;
261   }
262 }
263 
264 /* list1 functions */
AB_Document_List_dup(const AB_DOCUMENT_LIST * p_src)265 AB_DOCUMENT_LIST *AB_Document_List_dup(const AB_DOCUMENT_LIST *p_src)
266 {
267   AB_DOCUMENT_LIST *p_dest;
268   AB_DOCUMENT *p_elem;
269 
270   assert(p_src);
271   p_dest=AB_Document_List_new();
272   p_elem=AB_Document_List_First(p_src);
273   while (p_elem) {
274     AB_DOCUMENT *p_cpy;
275 
276     p_cpy=AB_Document_dup(p_elem);
277     AB_Document_List_Add(p_cpy, p_dest);
278     p_elem=AB_Document_List_Next(p_elem);
279   }
280 
281   return p_dest;
282 }
283 
AB_Document_ReadDb(AB_DOCUMENT * p_struct,GWEN_DB_NODE * p_db)284 void AB_Document_ReadDb(AB_DOCUMENT *p_struct, GWEN_DB_NODE *p_db)
285 {
286   assert(p_struct);
287   /* member "id" */
288   if (p_struct->id) {
289     free(p_struct->id);
290     p_struct->id=NULL;
291   }
292   {
293     const char *s;
294     s=GWEN_DB_GetCharValue(p_db, "id", 0, NULL);
295     if (s)
296       p_struct->id=strdup(s);
297   }
298   if (p_struct->id==NULL) {
299     p_struct->id=NULL;
300   }
301 
302   /* member "ownerId" */
303   p_struct->ownerId=GWEN_DB_GetIntValue(p_db, "ownerId", 0, 0);
304 
305   /* member "mimeType" */
306   if (p_struct->mimeType) {
307     free(p_struct->mimeType);
308     p_struct->mimeType=NULL;
309   }
310   {
311     const char *s;
312     s=GWEN_DB_GetCharValue(p_db, "mimeType", 0, NULL);
313     if (s)
314       p_struct->mimeType=strdup(s);
315   }
316   if (p_struct->mimeType==NULL) {
317     p_struct->mimeType=NULL;
318   }
319 
320   /* member "data" */
321   {
322     const void *v;
323     unsigned int vlen;
324     v=GWEN_DB_GetBinValue(p_db, "data", 0, NULL, 0, &vlen);
325     if (v && vlen) {
326       uint8_t *dest;
327       dest=(uint8_t *) malloc(vlen);
328       memmove(dest, v, vlen);
329       p_struct->data.pointer=dest;
330       p_struct->data.length=vlen;
331     }
332   }
333 
334   /* member "acknowledgeCode" */
335   {
336     const void *v;
337     unsigned int vlen;
338     v=GWEN_DB_GetBinValue(p_db, "acknowledgeCode", 0, NULL, 0, &vlen);
339     if (v && vlen) {
340       uint8_t *dest;
341       dest=(uint8_t *) malloc(vlen);
342       memmove(dest, v, vlen);
343       p_struct->acknowledgeCode.pointer=dest;
344       p_struct->acknowledgeCode.length=vlen;
345     }
346   }
347 
348 }
349 
AB_Document_WriteDb(const AB_DOCUMENT * p_struct,GWEN_DB_NODE * p_db)350 int AB_Document_WriteDb(const AB_DOCUMENT *p_struct, GWEN_DB_NODE *p_db)
351 {
352   int p_rv;
353 
354   assert(p_struct);
355   /* member "id" */
356   if (p_struct->id)
357     p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "id", p_struct->id);
358   else {
359     GWEN_DB_DeleteVar(p_db, "id");
360     p_rv=0;
361   }
362   if (p_rv<0) {
363     DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
364     return p_rv;
365   }
366 
367   /* member "ownerId" */
368   p_rv=GWEN_DB_SetIntValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "ownerId", p_struct->ownerId);
369   if (p_rv<0) {
370     DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
371     return p_rv;
372   }
373 
374   /* member "mimeType" */
375   if (p_struct->mimeType)
376     p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "mimeType", p_struct->mimeType);
377   else {
378     GWEN_DB_DeleteVar(p_db, "mimeType");
379     p_rv=0;
380   }
381   if (p_rv<0) {
382     DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
383     return p_rv;
384   }
385 
386   /* member "data" */
387   {
388     if (p_struct->data.length && p_struct->data.pointer) {
389       GWEN_DB_SetBinValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "data", p_struct->data.pointer, p_struct->data.length);
390     }
391     else {
392       GWEN_DB_DeleteVar(p_db, "data");
393       p_rv=0;
394     }
395   }
396   if (p_rv<0) {
397     DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
398     return p_rv;
399   }
400 
401   /* member "acknowledgeCode" */
402   {
403     if (p_struct->acknowledgeCode.length && p_struct->acknowledgeCode.pointer) {
404       GWEN_DB_SetBinValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "acknowledgeCode", p_struct->acknowledgeCode.pointer,
405                           p_struct->acknowledgeCode.length);
406     }
407     else {
408       GWEN_DB_DeleteVar(p_db, "acknowledgeCode");
409       p_rv=0;
410     }
411   }
412   if (p_rv<0) {
413     DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
414     return p_rv;
415   }
416 
417   return 0;
418 }
419 
AB_Document_fromDb(GWEN_DB_NODE * p_db)420 AB_DOCUMENT *AB_Document_fromDb(GWEN_DB_NODE *p_db)
421 {
422   AB_DOCUMENT *p_struct;
423   p_struct=AB_Document_new();
424   AB_Document_ReadDb(p_struct, p_db);
425   return p_struct;
426 }
427 
AB_Document_toDb(const AB_DOCUMENT * p_struct,GWEN_DB_NODE * p_db)428 int AB_Document_toDb(const AB_DOCUMENT *p_struct, GWEN_DB_NODE *p_db)
429 {
430   return AB_Document_WriteDb(p_struct, p_db);
431 }
432 
AB_Document_ReadXml(AB_DOCUMENT * p_struct,GWEN_XMLNODE * p_db)433 void AB_Document_ReadXml(AB_DOCUMENT *p_struct, GWEN_XMLNODE *p_db)
434 {
435   assert(p_struct);
436   /* member "id" */
437   if (p_struct->id) {
438     free(p_struct->id);
439     p_struct->id=NULL;
440   }
441   {
442     const char *s;
443     s=GWEN_XMLNode_GetCharValue(p_db, "id", NULL);
444     if (s)
445       p_struct->id=strdup(s);
446   }
447   if (p_struct->id==NULL) {  /* preset member "id" if empty */
448     p_struct->id=NULL;
449   }
450 
451   /* member "ownerId" */
452   p_struct->ownerId=GWEN_XMLNode_GetIntValue(p_db, "ownerId", 0);
453 
454   /* member "mimeType" */
455   if (p_struct->mimeType) {
456     free(p_struct->mimeType);
457     p_struct->mimeType=NULL;
458   }
459   {
460     const char *s;
461     s=GWEN_XMLNode_GetCharValue(p_db, "mimeType", NULL);
462     if (s)
463       p_struct->mimeType=strdup(s);
464   }
465   if (p_struct->mimeType==NULL) {  /* preset member "mimeType" if empty */
466     p_struct->mimeType=NULL;
467   }
468 
469   /* member "data" */
470   {
471     const char *s;
472     s=GWEN_XMLNode_GetCharValue(p_db, "data", NULL);
473     if (s) {
474       GWEN_BUFFER *tbuf;
475       int rv;
476       tbuf=GWEN_Buffer_new(0, 1024, 0, 1);
477       rv=GWEN_Base64_Decode((const unsigned char *)s, strlen(s), tbuf);
478       if (rv < 0) {
479         DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
480       }
481       else {
482         char *t;
483         uint32_t len;
484         len=GWEN_Buffer_GetUsedBytes(tbuf);
485         t=GWEN_Buffer_GetStart(tbuf);
486         if (GWEN_Buffer_Relinquish(tbuf) < 0) {
487           uint8_t *dest;
488           dest=(uint8_t *) malloc(len);
489           memmove(dest, t, len);
490           p_struct->data.pointer=dest;
491           p_struct->data.length=len;
492         }
493         else {
494           p_struct->data.pointer=(uint8_t *) t;
495           p_struct->data.length=len;
496         }
497       }
498       GWEN_Buffer_free(tbuf);
499     }
500   }
501 
502   /* member "acknowledgeCode" */
503   {
504     const char *s;
505     s=GWEN_XMLNode_GetCharValue(p_db, "acknowledgeCode", NULL);
506     if (s) {
507       GWEN_BUFFER *tbuf;
508       int rv;
509       tbuf=GWEN_Buffer_new(0, 1024, 0, 1);
510       rv=GWEN_Base64_Decode((const unsigned char *)s, strlen(s), tbuf);
511       if (rv < 0) {
512         DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
513       }
514       else {
515         char *t;
516         uint32_t len;
517         len=GWEN_Buffer_GetUsedBytes(tbuf);
518         t=GWEN_Buffer_GetStart(tbuf);
519         if (GWEN_Buffer_Relinquish(tbuf) < 0) {
520           uint8_t *dest;
521           dest=(uint8_t *) malloc(len);
522           memmove(dest, t, len);
523           p_struct->acknowledgeCode.pointer=dest;
524           p_struct->acknowledgeCode.length=len;
525         }
526         else {
527           p_struct->acknowledgeCode.pointer=(uint8_t *) t;
528           p_struct->acknowledgeCode.length=len;
529         }
530       }
531       GWEN_Buffer_free(tbuf);
532     }
533   }
534 
535 }
536 
AB_Document_WriteXml(const AB_DOCUMENT * p_struct,GWEN_XMLNODE * p_db)537 void AB_Document_WriteXml(const AB_DOCUMENT *p_struct, GWEN_XMLNODE *p_db)
538 {
539   assert(p_struct);
540   /* member "id" */
541   GWEN_XMLNode_SetCharValue(p_db, "id", p_struct->id);
542 
543   /* member "ownerId" */
544   GWEN_XMLNode_SetIntValue(p_db, "ownerId", p_struct->ownerId);
545 
546   /* member "mimeType" */
547   GWEN_XMLNode_SetCharValue(p_db, "mimeType", p_struct->mimeType);
548 
549   /* member "data" */
550   {
551     if (p_struct->data.length && p_struct->data.pointer) {
552       GWEN_BUFFER *tbuf;
553       int rv;
554       tbuf=GWEN_Buffer_new(0, 1024, 0, 1);
555       rv=GWEN_Base64_Encode((const unsigned char *) p_struct->data.pointer, p_struct->data.length, tbuf, 80);
556       if (rv < 0) {
557         DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
558       }
559       else {
560         GWEN_XMLNode_SetCharValue(p_db, "data", GWEN_Buffer_GetStart(tbuf));
561         GWEN_Buffer_free(tbuf);
562       }
563     }
564   }
565 
566   /* member "acknowledgeCode" */
567   {
568     if (p_struct->acknowledgeCode.length && p_struct->acknowledgeCode.pointer) {
569       GWEN_BUFFER *tbuf;
570       int rv;
571       tbuf=GWEN_Buffer_new(0, 1024, 0, 1);
572       rv=GWEN_Base64_Encode((const unsigned char *) p_struct->acknowledgeCode.pointer, p_struct->acknowledgeCode.length, tbuf,
573                             80);
574       if (rv < 0) {
575         DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
576       }
577       else {
578         GWEN_XMLNode_SetCharValue(p_db, "acknowledgeCode", GWEN_Buffer_GetStart(tbuf));
579         GWEN_Buffer_free(tbuf);
580       }
581     }
582   }
583 
584 }
585 
AB_Document_toXml(const AB_DOCUMENT * p_struct,GWEN_XMLNODE * p_db)586 void AB_Document_toXml(const AB_DOCUMENT *p_struct, GWEN_XMLNODE *p_db)
587 {
588   AB_Document_WriteXml(p_struct, p_db);
589 }
590 
AB_Document_fromXml(GWEN_XMLNODE * p_db)591 AB_DOCUMENT *AB_Document_fromXml(GWEN_XMLNODE *p_db)
592 {
593   AB_DOCUMENT *p_struct;
594   p_struct=AB_Document_new();
595   AB_Document_ReadXml(p_struct, p_db);
596   return p_struct;
597 }
598 
AB_Document_toHashString(const AB_DOCUMENT * p_struct,GWEN_BUFFER * p_buffer)599 void AB_Document_toHashString(const AB_DOCUMENT *p_struct, GWEN_BUFFER *p_buffer)
600 {
601   assert(p_struct);
602   /* member "id" */
603   if (p_struct->id)
604     GWEN_Buffer_AppendString(p_buffer, p_struct->id);
605   GWEN_Buffer_AppendByte(p_buffer, ':');
606   /* member "ownerId" */
607   {
608     char numbuf[32];
609     snprintf(numbuf, sizeof(numbuf)-1, "%d", p_struct->ownerId);
610     numbuf[sizeof(numbuf)-1]=0;
611     GWEN_Buffer_AppendString(p_buffer, numbuf);
612   }
613   GWEN_Buffer_AppendByte(p_buffer, ':');
614   /* member "mimeType" */
615   if (p_struct->mimeType)
616     GWEN_Buffer_AppendString(p_buffer, p_struct->mimeType);
617   GWEN_Buffer_AppendByte(p_buffer, ':');
618   /* member "data" */
619 
620   GWEN_Buffer_AppendByte(p_buffer, ':');
621   /* member "acknowledgeCode" */
622 
623   GWEN_Buffer_AppendByte(p_buffer, ':');
624 }
625 
AB_Document_List2__freeAll_cb(AB_DOCUMENT * t,void * user_data)626 static AB_DOCUMENT *AB_Document_List2__freeAll_cb(AB_DOCUMENT *t, void *user_data)
627 {
628   AB_Document_free(t);
629   return NULL;
630 }
AB_Document_List2_freeAll(AB_DOCUMENT_LIST2 * tl)631 int AB_Document_List2_freeAll(AB_DOCUMENT_LIST2 *tl)
632 {
633   if (tl) {
634     AB_Document_List2_ForEach(tl, AB_Document_List2__freeAll_cb, NULL);
635     AB_Document_List2_free(tl);
636   }
637   else {
638     DBG_ERROR(AQBANKING_LOGDOMAIN, "List missing");
639     return GWEN_ERROR_INVALID;
640   }
641   return 0;
642 }
AB_Document_SetData(AB_DOCUMENT * st,const uint8_t * p,uint32_t len)643 void AB_Document_SetData(AB_DOCUMENT *st, const uint8_t *p, uint32_t len)
644 {
645   assert(st);
646   if (st->data.length && st->data.pointer)
647     free(st->data.pointer);
648   if (p && len) {
649     st->data.pointer=(uint8_t *) malloc(len);
650     if (st->data.pointer) {
651       st->data.length=len;
652       memmove(st->data.pointer, p, len);
653     }
654     else {
655       st->data.pointer=NULL;
656       st->data.length=0;
657     }
658   }
659   else {
660     st->data.length=0;
661     st->data.pointer=NULL;
662   }
663 }
AB_Document_GetDataPtr(const AB_DOCUMENT * st)664 const uint8_t *AB_Document_GetDataPtr(const AB_DOCUMENT *st)
665 {
666   assert(st);
667   return st->data.pointer;
668 }
AB_Document_GetDataLen(const AB_DOCUMENT * st)669 uint32_t AB_Document_GetDataLen(const AB_DOCUMENT *st)
670 {
671   assert(st);
672   return st->data.length;
673 }
AB_Document_SetAcknowledgeCode(AB_DOCUMENT * st,const uint8_t * p,uint32_t len)674 void AB_Document_SetAcknowledgeCode(AB_DOCUMENT *st, const uint8_t *p, uint32_t len)
675 {
676   assert(st);
677   if (st->acknowledgeCode.length && st->acknowledgeCode.pointer)
678     free(st->acknowledgeCode.pointer);
679   if (p && len) {
680     st->acknowledgeCode.pointer=(uint8_t *) malloc(len);
681     if (st->acknowledgeCode.pointer) {
682       st->acknowledgeCode.length=len;
683       memmove(st->acknowledgeCode.pointer, p, len);
684     }
685     else {
686       st->acknowledgeCode.pointer=NULL;
687       st->acknowledgeCode.length=0;
688     }
689   }
690   else {
691     st->acknowledgeCode.length=0;
692     st->acknowledgeCode.pointer=NULL;
693   }
694 }
AB_Document_GetAcknowledgeCodePtr(const AB_DOCUMENT * st)695 const uint8_t *AB_Document_GetAcknowledgeCodePtr(const AB_DOCUMENT *st)
696 {
697   assert(st);
698   return st->acknowledgeCode.pointer;
699 }
AB_Document_GetAcknowledgeCodeLen(const AB_DOCUMENT * st)700 uint32_t AB_Document_GetAcknowledgeCodeLen(const AB_DOCUMENT *st)
701 {
702   assert(st);
703   return st->acknowledgeCode.length;
704 }
705 
706 /* code headers */
707 
708