gwenhywfar  5.3.0
gwen_parser.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Fri Apr 18 2014
3  copyright : (C) 2014 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 #ifdef HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 #include "gwen_parser_p.h"
30 
31 #include <gwenhywfar/debug.h>
32 
33 
34 /* pull in check code */
35 #include "gwen_parser_check.c"
36 #include "gwen_parser_update.c"
37 #include "gwen_parser_todb.c"
38 
39 
40 
41 
42 /* Checks whether the given eData matches the given eDefinitions element */
43 int GWEN_Parser__CheckElement(const GWEN_PARSER_ELEMENT *eDefinitions, const GWEN_PARSER_ELEMENT *eData)
44 {
45  GWEN_PARSER_ELEMENT_TYPE tDefinitions, tData;
46  const char *nameDefinitions, *nameData;
47 
48  if (eDefinitions==NULL) {
49  DBG_DEBUG(GWEN_LOGDOMAIN, "No definition element");
50  return GWEN_ERROR_BAD_DATA;
51  }
52 
53  if (eData==NULL) {
54  DBG_DEBUG(GWEN_LOGDOMAIN, "No data element");
55  return GWEN_ERROR_BAD_DATA;
56  }
57 
58  /* compare data type */
59  tDefinitions=GWEN_ParserElement_GetElementType(eDefinitions);
60  tData=GWEN_ParserElement_GetElementType(eData);
61  if (tDefinitions!=tData) {
62  DBG_DEBUG(GWEN_LOGDOMAIN, "Unexpected element type (expected \%s\", found \%s\")",
63  GWEN_ParserElementType_toString(tDefinitions),
64  GWEN_ParserElementType_toString(tData));
65  return GWEN_ERROR_BAD_DATA;
66  }
67 
68  /* compare element name */
69  nameDefinitions=GWEN_ParserElement_GetName(eDefinitions);
70  if (nameDefinitions && !(*nameDefinitions))
71  nameDefinitions=NULL;
72  nameData=GWEN_ParserElement_GetName(eData);
73  if (nameData && !(*nameData))
74  nameData=NULL;
75 
76  if (!((nameDefinitions==NULL && nameData==NULL) ||
77  (nameDefinitions && nameData && strcasecmp(nameDefinitions, nameData)==0))) {
79  "Unexpected element name (expected \"%s\", got \"%s\")",
80  nameDefinitions?nameDefinitions:"<-->",
81  nameData?nameData:"<-->");
82  return GWEN_ERROR_BAD_DATA;
83  }
84 
85  return 0;
86 }
87 
88 
89 
90 const GWEN_PARSER_ELEMENT *GWEN_Parser__GetChoice(const GWEN_PARSER_ELEMENT *eDefinitions,
91  const GWEN_PARSER_ELEMENT *eData)
92 {
93  GWEN_PARSER_ELEMENT *e;
94 
95  e=GWEN_ParserElement_Tree_GetFirstChild(eDefinitions);
96  while (e) {
97  if (0==GWEN_Parser__CheckElement(e, eData))
98  return e;
99  e=GWEN_ParserElement_Tree_GetNext(e);
100  }
101 
102  DBG_DEBUG(GWEN_LOGDOMAIN, "No matching choice found");
103  return NULL;
104 }
105 
106 
107 
108 
109 
110 
111 
112 
113 
#define NULL
Definition: binreloc.c:300
const GWEN_PARSER_ELEMENT * GWEN_Parser__GetChoice(const GWEN_PARSER_ELEMENT *eDefinitions, const GWEN_PARSER_ELEMENT *eData)
Definition: gwen_parser.c:90
#define GWEN_LOGDOMAIN
Definition: logger.h:35
#define GWEN_ERROR_BAD_DATA
Definition: error.h:121
#define DBG_DEBUG(dbg_logger, format, args...)
Definition: debug.h:209
int GWEN_Parser__CheckElement(const GWEN_PARSER_ELEMENT *eDefinitions, const GWEN_PARSER_ELEMENT *eData)
Definition: gwen_parser.c:43