gwenhywfar  5.3.0
xml2db.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Sun Dec 16 2018
3  copyright : (C) 2018 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU Lesser General Public *
10  * License as published by the Free Software Foundation; either *
11  * version 2.1 of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * Lesser General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU Lesser General Public *
19  * License along with this library; if not, write to the Free Software *
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21  * MA 02111-1307 USA *
22  * *
23  ***************************************************************************/
24 
25 
26 #ifdef HAVE_CONFIG_H
27 # include <config.h>
28 #endif
29 
30 
31 
32 #include "xml2db_p.h"
33 
34 #include <gwenhywfar/debug.h>
35 #include <gwenhywfar/text.h>
36 #include <gwenhywfar/gwendate.h>
37 
38 
39 #include <ctype.h>
40 
41 
42 
43 
44 
45 
46 
47 GWEN_XML2DB_CONTEXT *GWEN_Xml2Db_Context_new(GWEN_XMLNODE *documentRoot, GWEN_DB_NODE *dbRoot)
48 {
49  GWEN_XML2DB_CONTEXT *ctx;
50 
51  GWEN_NEW_OBJECT(GWEN_XML2DB_CONTEXT, ctx);
52  assert(ctx);
53 
54  ctx->docRoot=documentRoot;
55  ctx->xmlNodeStack=GWEN_XMLNode_List2_new();
56  ctx->dbRoot=dbRoot;
57  ctx->tempDbRoot=GWEN_DB_Group_new("dbTempRoot");
58 
59  ctx->currentDbGroup=ctx->dbRoot;
60  ctx->currentTempDbGroup=ctx->tempDbRoot;
61  ctx->currentDocNode=documentRoot;
62 
63  return ctx;
64 }
65 
66 
67 
68 void GWEN_Xml2Db_Context_free(GWEN_XML2DB_CONTEXT *ctx)
69 {
70  if (ctx) {
71  GWEN_XMLNode_List2_free(ctx->xmlNodeStack);
72  ctx->xmlNodeStack=NULL;
73 
74  GWEN_DB_Group_free(ctx->tempDbRoot);
75  GWEN_FREE_OBJECT(ctx);
76  }
77 }
78 
79 
80 
81 void GWEN_Xml2Db_Context_EnterDocNode(GWEN_XML2DB_CONTEXT *ctx, GWEN_XMLNODE *xmlNode)
82 {
83  assert(ctx);
84  assert(xmlNode);
85 
86  GWEN_XMLNode_List2_PushBack(ctx->xmlNodeStack, ctx->currentDocNode);
87  ctx->currentDocNode=xmlNode;
88 }
89 
90 
91 
92 void GWEN_Xml2Db_Context_LeaveDocNode(GWEN_XML2DB_CONTEXT *ctx)
93 {
94  GWEN_XMLNODE *xmlNode;
95 
96  assert(ctx);
97 
98  xmlNode=GWEN_XMLNode_List2_GetBack(ctx->xmlNodeStack);
99  if (xmlNode==NULL) {
100  DBG_ERROR(GWEN_LOGDOMAIN, "Nothing on stack");
101  assert(xmlNode);
102  }
103  ctx->currentDocNode=xmlNode;
104  GWEN_XMLNode_List2_PopBack(ctx->xmlNodeStack);
105 }
106 
107 
108 
109 int GWEN_Xml2Db_Context_HandleChildren(GWEN_XML2DB_CONTEXT *ctx, GWEN_XMLNODE *xmlNode)
110 {
111  if (ctx->handleChildrenFn)
112  return (ctx->handleChildrenFn)(ctx, xmlNode);
113  else
115 }
116 
117 
118 
119 
120 
GWEN_XML2DB_CONTEXT * GWEN_Xml2Db_Context_new(GWEN_XMLNODE *documentRoot, GWEN_DB_NODE *dbRoot)
Definition: xml2db.c:47
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
void GWEN_DB_Group_free(GWEN_DB_NODE *n)
Definition: db.c:419
GWEN_XMLNODE_LIST2 * GWEN_XMLNode_List2_new()
void GWEN_Xml2Db_Context_EnterDocNode(GWEN_XML2DB_CONTEXT *ctx, GWEN_XMLNODE *xmlNode)
Definition: xml2db.c:81
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:61
#define NULL
Definition: binreloc.c:300
int GWEN_Xml2Db_Context_HandleChildren(GWEN_XML2DB_CONTEXT *ctx, GWEN_XMLNODE *xmlNode)
Definition: xml2db.c:109
void GWEN_XMLNode_List2_free(GWEN_XMLNODE_LIST2 *l)
#define GWEN_LOGDOMAIN
Definition: logger.h:35
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:55
void GWEN_Xml2Db_Context_free(GWEN_XML2DB_CONTEXT *ctx)
Definition: xml2db.c:68
void GWEN_XMLNode_List2_PopBack(GWEN_XMLNODE_LIST2 *l)
void GWEN_Xml2Db_Context_LeaveDocNode(GWEN_XML2DB_CONTEXT *ctx)
Definition: xml2db.c:92
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
GWEN_XMLNODE * GWEN_XMLNode_List2_GetBack(GWEN_XMLNODE_LIST2 *l)
void GWEN_XMLNode_List2_PushBack(GWEN_XMLNODE_LIST2 *l, GWEN_XMLNODE *p)
GWEN_DB_NODE * GWEN_DB_Group_new(const char *name)
Definition: db.c:171
struct GWEN__XMLNODE GWEN_XMLNODE
Definition: xml.h:149
#define GWEN_ERROR_NOT_IMPLEMENTED
Definition: error.h:108