gwenhywfar  4.99.8beta
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  GWEN_PARSER_ELEMENT_TYPE tDefinitions, tData;
45  const char *nameDefinitions, *nameData;
46 
47  if (eDefinitions==NULL) {
48  DBG_DEBUG(GWEN_LOGDOMAIN, "No definition element");
49  return GWEN_ERROR_BAD_DATA;
50  }
51 
52  if (eData==NULL) {
53  DBG_DEBUG(GWEN_LOGDOMAIN, "No data element");
54  return GWEN_ERROR_BAD_DATA;
55  }
56 
57  /* compare data type */
58  tDefinitions=GWEN_ParserElement_GetElementType(eDefinitions);
59  tData=GWEN_ParserElement_GetElementType(eData);
60  if (tDefinitions!=tData) {
61  DBG_DEBUG(GWEN_LOGDOMAIN, "Unexpected element type (expected \%s\", found \%s\")",
62  GWEN_ParserElementType_toString(tDefinitions),
63  GWEN_ParserElementType_toString(tData));
64  return GWEN_ERROR_BAD_DATA;
65  }
66 
67  /* compare element name */
68  nameDefinitions=GWEN_ParserElement_GetName(eDefinitions);
69  if (nameDefinitions && !(*nameDefinitions))
70  nameDefinitions=NULL;
71  nameData=GWEN_ParserElement_GetName(eData);
72  if (nameData && !(*nameData))
73  nameData=NULL;
74 
75  if (!((nameDefinitions==NULL && nameData==NULL) ||
76  (nameDefinitions && nameData && strcasecmp(nameDefinitions, nameData)==0))) {
78  "Unexpected element name (expected \"%s\", got \"%s\")",
79  nameDefinitions?nameDefinitions:"<-->",
80  nameData?nameData:"<-->");
81  return GWEN_ERROR_BAD_DATA;
82  }
83 
84  return 0;
85 }
86 
87 
88 
89 const GWEN_PARSER_ELEMENT *GWEN_Parser__GetChoice(const GWEN_PARSER_ELEMENT *eDefinitions, const GWEN_PARSER_ELEMENT *eData) {
90  GWEN_PARSER_ELEMENT *e;
91 
92  e=GWEN_ParserElement_Tree_GetFirstChild(eDefinitions);
93  while(e) {
94  if (0==GWEN_Parser__CheckElement(e, eData))
95  return e;
96  e=GWEN_ParserElement_Tree_GetNext(e);
97  }
98 
99  DBG_DEBUG(GWEN_LOGDOMAIN, "No matching choice found");
100  return NULL;
101 }
102 
103 
104 
105 
106 
107 
108 
109 
110 
#define NULL
Definition: binreloc.c:290
const GWEN_PARSER_ELEMENT * GWEN_Parser__GetChoice(const GWEN_PARSER_ELEMENT *eDefinitions, const GWEN_PARSER_ELEMENT *eData)
Definition: gwen_parser.c:89
#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:192
int GWEN_Parser__CheckElement(const GWEN_PARSER_ELEMENT *eDefinitions, const GWEN_PARSER_ELEMENT *eData)
Definition: gwen_parser.c:43