Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

aqbanking / src / libs / plugins / imexporters / ofx / parser / g_bal.c @ f4a16f5b

History | View | Annotate | Download (4.52 KB)

1
/***************************************************************************
2
 $RCSfile$
3
 -------------------
4
 begin       : Mon Jan 07 2008
5
 copyright   : (C) 2008 by Martin Preuss
6
 email       : martin@libchipcard.de
7

8
 ***************************************************************************
9
 *          Please see toplevel file COPYING for license details           *
10
 ***************************************************************************/
11

    
12

    
13
#ifdef HAVE_CONFIG_H
14
# include <config.h>
15
#endif
16

    
17
#include "g_bal_p.h"
18
#include "ofxxmlctx_l.h"
19
#include "i18n_l.h"
20

    
21
#include "g_generic_l.h"
22
#include "g_ignore_l.h"
23

    
24
#include <gwenhywfar/misc.h>
25
#include <gwenhywfar/debug.h>
26
#include <gwenhywfar/buffer.h>
27
#include <gwenhywfar/gui.h>
28

    
29

    
30

    
31
GWEN_INHERIT(AIO_OFX_GROUP, AIO_OFX_GROUP_BAL)
32

    
33

    
34

    
35

    
36
AIO_OFX_GROUP *AIO_OfxGroup_BAL_new(const char *groupName,
37
                                        AIO_OFX_GROUP *parent,
38
                                        GWEN_XML_CONTEXT *ctx) {
39
  AIO_OFX_GROUP *g;
40
  AIO_OFX_GROUP_BAL *xg;
41

    
42
  /* create base group */
43
  g=AIO_OfxGroup_Generic_new(groupName, parent, ctx);
44
  assert(g);
45

    
46
  GWEN_NEW_OBJECT(AIO_OFX_GROUP_BAL, xg);
47
  assert(xg);
48
  GWEN_INHERIT_SETDATA(AIO_OFX_GROUP, AIO_OFX_GROUP_BAL, g, xg,
49
                       AIO_OfxGroup_BAL_FreeData);
50

    
51
  /* set virtual functions */
52
  AIO_OfxGroup_SetStartTagFn(g, AIO_OfxGroup_BAL_StartTag);
53
  AIO_OfxGroup_SetAddDataFn(g, AIO_OfxGroup_BAL_AddData);
54

    
55
  return g;
56
}
57

    
58

    
59

    
60
GWENHYWFAR_CB
61
void AIO_OfxGroup_BAL_FreeData(void *bp, void *p) {
62
  AIO_OFX_GROUP_BAL *xg;
63

    
64
  xg=(AIO_OFX_GROUP_BAL*)p;
65
  assert(xg);
66
  free(xg->currentElement);
67
  GWEN_Date_free(xg->date);
68
  AB_Value_free(xg->value);
69
  GWEN_FREE_OBJECT(xg);
70
}
71

    
72

    
73

    
74
const AB_VALUE *AIO_OfxGroup_BAL_GetValue(const AIO_OFX_GROUP *g) {
75
  AIO_OFX_GROUP_BAL *xg;
76

    
77
  assert(g);
78
  xg=GWEN_INHERIT_GETDATA(AIO_OFX_GROUP, AIO_OFX_GROUP_BAL, g);
79
  assert(xg);
80

    
81
  return xg->value;
82
}
83

    
84

    
85

    
86
void AIO_OfxGroup_BAL_SetValue(AIO_OFX_GROUP *g, const AB_VALUE *v) {
87
  AIO_OFX_GROUP_BAL *xg;
88

    
89
  assert(g);
90
  xg=GWEN_INHERIT_GETDATA(AIO_OFX_GROUP, AIO_OFX_GROUP_BAL, g);
91
  assert(xg);
92

    
93
  AB_Value_free(xg->value);
94
  if (v) xg->value=AB_Value_dup(v);
95
  else xg->value=NULL;
96
}
97

    
98

    
99

    
100
const GWEN_DATE *AIO_OfxGroup_BAL_GetDate(const AIO_OFX_GROUP *g) {
101
  AIO_OFX_GROUP_BAL *xg;
102

    
103
  assert(g);
104
  xg=GWEN_INHERIT_GETDATA(AIO_OFX_GROUP, AIO_OFX_GROUP_BAL, g);
105
  assert(xg);
106

    
107
  return xg->date;
108
}
109

    
110

    
111

    
112
void AIO_OfxGroup_BAL_SetDate(AIO_OFX_GROUP *g, const GWEN_DATE *dt) {
113
  AIO_OFX_GROUP_BAL *xg;
114

    
115
  assert(g);
116
  xg=GWEN_INHERIT_GETDATA(AIO_OFX_GROUP, AIO_OFX_GROUP_BAL, g);
117
  assert(xg);
118

    
119
  GWEN_Date_free(xg->date);
120
  if (dt) xg->date=GWEN_Date_dup(dt);
121
  else xg->date=NULL;
122
}
123

    
124

    
125

    
126

    
127
int AIO_OfxGroup_BAL_StartTag(AIO_OFX_GROUP *g, const char *tagName) {
128
  AIO_OFX_GROUP_BAL *xg;
129
  //GWEN_XML_CONTEXT *ctx;
130

    
131
  assert(g);
132
  xg=GWEN_INHERIT_GETDATA(AIO_OFX_GROUP, AIO_OFX_GROUP_BAL, g);
133
  assert(xg);
134

    
135
  //ctx=AIO_OfxGroup_GetXmlContext(g);
136

    
137
  if (strcasecmp(tagName, "BALAMT")==0 ||
138
      strcasecmp(tagName, "DTASOF")==0) {
139
    free(xg->currentElement);
140
    xg->currentElement=strdup(tagName);
141
  }
142
  else {
143
    DBG_WARN(AQBANKING_LOGDOMAIN,
144
             "Ignoring tag [%s]", tagName);
145
  }
146

    
147
  return 0;
148
}
149

    
150

    
151

    
152
int AIO_OfxGroup_BAL_AddData(AIO_OFX_GROUP *g, const char *data) {
153
  AIO_OFX_GROUP_BAL *xg;
154

    
155
  assert(g);
156
  xg=GWEN_INHERIT_GETDATA(AIO_OFX_GROUP, AIO_OFX_GROUP_BAL, g);
157
  assert(xg);
158

    
159
  if (xg->currentElement) {
160
    GWEN_BUFFER *buf;
161
    int rv;
162
    const char *s;
163

    
164
    buf=GWEN_Buffer_new(0, strlen(data), 0, 1);
165
    rv=AIO_OfxXmlCtx_SanitizeData(AIO_OfxGroup_GetXmlContext(g), data, buf);
166
    if (rv<0) {
167
      DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d)", rv);
168
      GWEN_Buffer_free(buf);
169
      return rv;
170
    }
171
    s=GWEN_Buffer_GetStart(buf);
172
    if (*s) {
173
      DBG_INFO(AQBANKING_LOGDOMAIN,
174
               "AddData: %s=[%s]", xg->currentElement, s);
175
      if (strcasecmp(xg->currentElement, "BALAMT")==0) {
176
        AB_VALUE *v;
177

    
178
        v=AB_Value_fromString(s);
179
        if (v==NULL) {
180
          DBG_ERROR(AQBANKING_LOGDOMAIN,
181
                    "Invalid data for BALAMT: [%s]", s);
182
          GWEN_Buffer_free(buf);
183
          return GWEN_ERROR_BAD_DATA;
184
        }
185
        AB_Value_free(xg->value);
186
        xg->value=v;
187
      }
188
      else if (strcasecmp(xg->currentElement, "DTASOF")==0) {
189
        GWEN_DATE *dt;
190

    
191
        dt=GWEN_Date_fromStringWithTemplate(s, "YYYYMMDD");
192
        if (dt==NULL) {
193
          DBG_ERROR(AQBANKING_LOGDOMAIN,
194
                    "Invalid data for DTASOF: [%s]", s);
195
          GWEN_Buffer_free(buf);
196
          return GWEN_ERROR_BAD_DATA;
197
        }
198
        GWEN_Date_free(xg->date);
199
        xg->date=dt;
200
      }
201
      else {
202
        DBG_INFO(AQBANKING_LOGDOMAIN,
203
                 "Ignoring data for unknown element [%s]",
204
                 xg->currentElement);
205
      }
206
    }
207
    GWEN_Buffer_free(buf);
208
  }
209

    
210
  return 0;
211
}
212

    
213

    
214

    
215

    
216