1 /** aux-templ.c  -  Auxiliary functions template: cloning, freeing, walking data
2  ** Copyright (c) 2010 Sampo Kellomaki (sampo@iki.fi), All Rights Reserved.
3  ** Copyright (c) 2006 Symlabs (symlabs@symlabs.com), All Rights Reserved.
4  ** Author: Sampo Kellomaki (sampo@iki.fi)
5  ** This is confidential unpublished proprietary source code of the author.
6  ** NO WARRANTY, not even implied warranties. Contains trade secrets.
7  ** Distribution prohibited unless authorized in writing.
8  ** Licensed under Apache License 2.0, see file COPYING.
9  ** $Id: aux-templ.c,v 1.12 2008-10-04 23:42:14 sampo Exp $
10  **
11  ** 30.5.2006, created, Sampo Kellomaki (sampo@iki.fi)
12  ** 6.8.2006, factored from enc-templ.c to separate file --Sampo
13  **
14  ** N.B: wo=wire order (needed for exc-c14n), so=schema order
15  **/
16 
17 #ifdef EL_NAME
18 #undef EL_NAME
19 #endif
20 #ifdef EL_STRUCT
21 #undef EL_STRUCT
22 #endif
23 #ifdef EL_NS
24 #undef EL_NS
25 #endif
26 #ifdef EL_TAG
27 #undef EL_TAG
28 #endif
29 
30 #define EL_NAME   ELNAME
31 #define EL_STRUCT ELSTRUCT
32 #define EL_NS     ELNS
33 #define EL_TAG    ELTAG
34 
35 #ifdef ZX_ENA_AUX
36 
37 /* FUNC(TXDUP_STRS_ELNAME) */
38 
39 /* Depth first traversal of data structure to copy its simple strings
40  * to memory allocated from the memory allocator. The decoder will
41  * use the underlying wireprotocol PDU buffer for strings, i.e.
42  * strings are not copied - they point to the real data. If the
43  * datastructure needs to outlast the protocol data or needs a different
44  * memory allocation strategy, you need to call this function.  */
45 
46 /* Called by: */
TXDUP_STRS_ELNAME(struct zx_ctx * c,struct ELSTRUCT * x)47 void TXDUP_STRS_ELNAME(struct zx_ctx* c, struct ELSTRUCT* x)
48 {
49   struct zx_elem_s* se  MAYBE_UNUSED;
50   zx_dup_strs_common(c, &x->gg);
51   /* *** deal with xmlns specifications in exc c14n way */
52 
53 ATTRS_DUP_STRS;
54 ELEMS_DUP_STRS;
55 }
56 
57 /* FUNC(TXDEEP_CLONE_ELNAME) */
58 
59 /* Depth first traversal of data structure to clone it and its sublements.
60  * The simple strings are handled as a special case according to dup_strs flag. */
61 
62 /* Called by: */
TXDEEP_CLONE_ELNAME(struct zx_ctx * c,struct ELSTRUCT * x,int dup_strs)63 struct ELSTRUCT* TXDEEP_CLONE_ELNAME(struct zx_ctx* c, struct ELSTRUCT* x, int dup_strs)
64 {
65   struct zx_elem_s* e   MAYBE_UNUSED;
66   struct zx_elem_s* en  MAYBE_UNUSED;
67   struct zx_elem_s* enn MAYBE_UNUSED;
68 
69   x = (struct ELSTRUCT*)zx_clone_elem_common(c, &x->gg, sizeof(struct ELSTRUCT), dup_strs);
70   /* *** deal with xmlns specifications in exc c14n way */
71 
72 ATTRS_CLONE;
73 ELEMS_CLONE;
74   return x;
75 }
76 
77 /* FUNC(TXWALK_SO_ELNAME) */
78 
79 /* Depth first traversal of the tree in either schema order or the wire order. */
80 
TXWALK_SO_ELNAME(struct zx_ctx * c,struct ELSTRUCT * x,void * ctx,int (* callback)(struct zx_node_s * node,void * ctx))81 int TXWALK_SO_ELNAME(struct zx_ctx* c, struct ELSTRUCT* x, void* ctx, int (*callback)(struct zx_node_s* node, void* ctx))
82 {
83   struct zx_elem_s* e   MAYBE_UNUSED;
84   int ret = callback(&x->gg.g, ctx);
85   if (ret)
86     return ret;
87 
88   /* *** deal with xmlns specifications in exc c14n way */
89 
90 ATTRS_WALK_SO;
91 
92   ret = zx_walk_so_unknown_attributes(c, &x->gg, ctx, callback);
93   if (ret)
94     return ret;
95 
96 ELEMS_WALK_SO;
97 
98   return zx_walk_so_unknown_elems_and_content(c, &x->gg, ctx, callback);
99 }
100 
101 /* FUNC(TXWALK_WO_ELNAME) */
102 
TXWALK_WO_ELNAME(struct zx_ctx * c,struct ELSTRUCT * x,void * ctx,int (* callback)(struct zx_node_s * node,void * ctx))103 int TXWALK_WO_ELNAME(struct zx_ctx* c, struct ELSTRUCT* x, void* ctx, int (*callback)(struct zx_node_s* node, void* ctx))
104 {
105   ERR("*** walk_wo not implemented %d", 0);
106   return 0;
107 }
108 
109 #endif
110 
111 /* EOF */
112