1 /***************************************************************************
2  begin       : Mon Mar 01 2004
3  copyright   : (C) 2018 by Martin Preuss
4  email       : martin@libchipcard.de
5 
6  ***************************************************************************
7  *          Please see toplevel file COPYING for license details           *
8  ***************************************************************************/
9 
10 #ifdef HAVE_CONFIG_H
11 # include <config.h>
12 #endif
13 
14 #include "account_p.h"
15 
16 #include <gwenhywfar/debug.h>
17 #include <gwenhywfar/misc.h>
18 
19 
20 
GWEN_INHERIT(AB_ACCOUNT,AO_ACCOUNT)21 GWEN_INHERIT(AB_ACCOUNT, AO_ACCOUNT)
22 
23 
24 AB_ACCOUNT *AO_Account_new(AB_PROVIDER *pro)
25 {
26   AB_ACCOUNT *a;
27   AO_ACCOUNT *ae;
28 
29   a=AB_Account_new();
30   assert(a);
31   AB_Account_SetProvider(a, pro);
32   AB_Account_SetBackendName(a, "aqofxconnect");
33 
34   GWEN_NEW_OBJECT(AO_ACCOUNT, ae);
35   GWEN_INHERIT_SETDATA(AB_ACCOUNT, AO_ACCOUNT, a, ae, AO_Account_freeData);
36 
37   ae->maxPurposeLines=1;
38   ae->debitAllowed=0;
39 
40   ae->readFromDbFn=AB_Account_SetReadFromDbFn(a, AO_Account_ReadFromDb);
41   ae->writeToDbFn=AB_Account_SetWriteToDbFn(a, AO_Account_WriteToDb);
42 
43   return a;
44 }
45 
46 
47 
AO_Account_ReadFromDb(AB_ACCOUNT * a,GWEN_DB_NODE * db)48 int AO_Account_ReadFromDb(AB_ACCOUNT *a, GWEN_DB_NODE *db)
49 {
50   AO_ACCOUNT *ae;
51   GWEN_DB_NODE *dbP;
52   int rv;
53   AB_PROVIDER *pro;
54 
55   assert(a);
56   ae=GWEN_INHERIT_GETDATA(AB_ACCOUNT, AO_ACCOUNT, a);
57   assert(ae);
58 
59   /* save provider, because AB_Account_ReadFromDb clears it */
60   pro=AB_Account_GetProvider(a);
61 
62   /* read data for base class */
63   rv=(ae->readFromDbFn)(a, db);
64   if (rv<0) {
65     DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "here (%d)", rv);
66     return rv;
67   }
68 
69   /* set provider again */
70   AB_Account_SetProvider(a, pro);
71 
72   /* read data for provider */
73   dbP=GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_DEFAULT, "data/backend");
74 
75   ae->maxPurposeLines=GWEN_DB_GetIntValue(dbP, "maxPurposeLines", 0, 1);
76   ae->debitAllowed=GWEN_DB_GetIntValue(dbP, "debitAllowed", 0, 1);
77 
78   return 0;
79 }
80 
81 
82 
AO_Account_WriteToDb(const AB_ACCOUNT * a,GWEN_DB_NODE * db)83 int AO_Account_WriteToDb(const AB_ACCOUNT *a, GWEN_DB_NODE *db)
84 {
85   AO_ACCOUNT *ae;
86   GWEN_DB_NODE *dbP;
87   int rv;
88 
89   assert(a);
90   ae=GWEN_INHERIT_GETDATA(AB_ACCOUNT, AO_ACCOUNT, a);
91   assert(ae);
92 
93   rv=(ae->writeToDbFn)(a, db);
94   if (rv<0) {
95     DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "here (%d)", rv);
96     return rv;
97   }
98 
99   /* write data for provider */
100   dbP=GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_DEFAULT, "data/backend");
101 
102   GWEN_DB_SetIntValue(dbP, GWEN_DB_FLAGS_OVERWRITE_VARS, "maxPurposeLines", ae->maxPurposeLines);
103   GWEN_DB_SetIntValue(dbP, GWEN_DB_FLAGS_OVERWRITE_VARS, "debitAllowed", ae->debitAllowed);
104 
105   return 0;
106 }
107 
108 
109 
110 
AO_Account_freeData(void * bp,void * p)111 void GWENHYWFAR_CB AO_Account_freeData(void *bp, void *p)
112 {
113   AO_ACCOUNT *ae;
114 
115   ae=(AO_ACCOUNT *) p;
116 
117   GWEN_FREE_OBJECT(ae);
118 }
119 
120 
121 
AO_Account_GetMaxPurposeLines(const AB_ACCOUNT * a)122 int AO_Account_GetMaxPurposeLines(const AB_ACCOUNT *a)
123 {
124   AO_ACCOUNT *ae;
125 
126   assert(a);
127   ae=GWEN_INHERIT_GETDATA(AB_ACCOUNT, AO_ACCOUNT, a);
128   assert(ae);
129 
130   return ae->maxPurposeLines;
131 }
132 
133 
134 
AO_Account_SetMaxPurposeLines(AB_ACCOUNT * a,int i)135 void AO_Account_SetMaxPurposeLines(AB_ACCOUNT *a, int i)
136 {
137   AO_ACCOUNT *ae;
138 
139   assert(a);
140   ae=GWEN_INHERIT_GETDATA(AB_ACCOUNT, AO_ACCOUNT, a);
141   assert(ae);
142 
143   ae->maxPurposeLines=i;
144 }
145 
146 
147 
AO_Account_GetDebitAllowed(const AB_ACCOUNT * a)148 int AO_Account_GetDebitAllowed(const AB_ACCOUNT *a)
149 {
150   AO_ACCOUNT *ae;
151 
152   assert(a);
153   ae=GWEN_INHERIT_GETDATA(AB_ACCOUNT, AO_ACCOUNT, a);
154   assert(ae);
155 
156   return ae->debitAllowed;
157 }
158 
159 
160 
AO_Account_SetDebitAllowed(AB_ACCOUNT * a,int i)161 void AO_Account_SetDebitAllowed(AB_ACCOUNT *a, int i)
162 {
163   AO_ACCOUNT *ae;
164 
165   assert(a);
166   ae=GWEN_INHERIT_GETDATA(AB_ACCOUNT, AO_ACCOUNT, a);
167   assert(ae);
168 
169   ae->debitAllowed=i;
170 }
171 
172 
173 
174 
175