Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

aqbanking / src / libs / plugins / backends / aqhbci / joblayer / job_swift.c @ eb50ded7

History | View | Annotate | Download (8.13 KB)

1
/***************************************************************************
2
    begin       : Frin Oct 03 2020
3
    copyright   : (C) 2020 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

    
15
#include "job_swift.h"
16

    
17
#include "aqhbci/banking/user_l.h"
18

    
19
#include <aqbanking/i18n_l.h>
20
#include <aqbanking/backendsupport/user.h>
21

    
22
#include <gwenhywfar/db.h>
23
#include <gwenhywfar/debug.h>
24

    
25

    
26
/* ------------------------------------------------------------------------------------------------
27
 * forward declarations
28
 * ------------------------------------------------------------------------------------------------
29
 */
30

    
31
static void _parseAndProbablyAddDescriptor(const char *sName, const char *family, int version1,
32
                                           AB_SWIFT_DESCR_LIST *descrList,
33
                                           AB_SWIFT_DESCR_LIST *returnDescrList);
34

    
35

    
36
/* ------------------------------------------------------------------------------------------------
37
 * implementations
38
 * ------------------------------------------------------------------------------------------------
39
 */
40

    
41

    
42

    
43
AB_SWIFT_DESCR_LIST *AH_Job_GetSwiftDescriptorsSupportedByJob(AH_JOB *j,
44
                                                              const char *paramDbGroupName,
45
                                                              const char *paramDbVarName,
46
                                                              const char *family,
47
                                                              int version1)
48
{
49
  GWEN_DB_NODE *dbParams;
50
  AB_BANKING *ab;
51
  AB_SWIFT_DESCR_LIST *descrList;
52
  AB_SWIFT_DESCR_LIST *returnDescrList;
53
  int i;
54

    
55
  dbParams=AH_Job_GetParams(j);
56
  assert(dbParams);
57

    
58
  ab=AH_Job_GetBankingApi(j);
59
  assert(ab);
60

    
61
  if (paramDbGroupName && *paramDbGroupName) {
62
    dbParams=GWEN_DB_GetGroup(dbParams, GWEN_PATH_FLAGS_NAMEMUSTEXIST, paramDbGroupName);
63
    if (dbParams==NULL) {
64
      DBG_ERROR(AQHBCI_LOGDOMAIN, "Group \"%s\" not found in params for job \"%s\"",
65
                paramDbGroupName, AH_Job_GetName(j));
66
      return NULL;
67
    }
68
  }
69

    
70
  descrList=AB_Banking_GetSwiftDescriptorsForImExporter(ab, "xml");
71
  if (descrList==NULL) {
72
    DBG_ERROR(AQHBCI_LOGDOMAIN, "No SWIFT descriptors found for XML imexporter (job \"%s\")", AH_Job_GetName(j));
73
    return NULL;
74
  }
75

    
76
  returnDescrList=AB_SwiftDescr_List_new();
77
  for (i=0; i<100; i++) {
78
    const char *s;
79

    
80
    s=GWEN_DB_GetCharValue(dbParams, paramDbVarName, i, NULL);
81
    if (s==NULL) {
82
      if (i==0) {
83
        DBG_ERROR(AQHBCI_LOGDOMAIN, "No supported param stored in params (%s/%s)",
84
                  paramDbGroupName?paramDbGroupName:"<no group name>",
85
                  paramDbVarName?paramDbVarName:"<no var name>");
86
      }
87
      break;
88
    }
89
    else
90
      _parseAndProbablyAddDescriptor(s, family, version1, descrList, returnDescrList);
91
  } /* for */
92

    
93
  AB_SwiftDescr_List_free(descrList);
94

    
95
  if (AB_SwiftDescr_List_GetCount(returnDescrList)==0) {
96
    DBG_ERROR(AQHBCI_LOGDOMAIN, "No matching descriptors found for %s_%03d_* (job %s)",
97
              family?family:"<none>", version1,
98
              AH_Job_GetName(j));
99
    AB_SwiftDescr_List_free(returnDescrList);
100
    return NULL;
101
  }
102

    
103
  return returnDescrList;
104
}
105

    
106

    
107

    
108
void _parseAndProbablyAddDescriptor(const char *sName, const char *family, int version1,
109
                                    AB_SWIFT_DESCR_LIST *descrList,
110
                                    AB_SWIFT_DESCR_LIST *returnDescrList)
111
{
112
  AB_SWIFT_DESCR *tmpDescr;
113

    
114
  tmpDescr=AB_SwiftDescr_FromString(sName);
115
  if (tmpDescr) {
116
    if (AB_SwiftDescr_Matches(tmpDescr, family, version1, 0, 0)) {
117
      AB_SWIFT_DESCR *descrFromList;
118

    
119
      /* found a candidate */
120
      descrFromList=AB_SwiftDescr_List_FindFirst(descrList,
121
                                                 AB_SwiftDescr_GetFamily(tmpDescr),
122
                                                 AB_SwiftDescr_GetVersion1(tmpDescr),
123
                                                 AB_SwiftDescr_GetVersion2(tmpDescr),
124
                                                 AB_SwiftDescr_GetVersion3(tmpDescr));
125
      if (descrFromList) {
126
        AB_SWIFT_DESCR *descrCopy;
127

    
128
        /* store name of selected profile */
129
        AB_SwiftDescr_SetAlias2(descrFromList, sName);
130
        DBG_ERROR(AQHBCI_LOGDOMAIN,
131
                  "Adding matching profile [%s] (%s)",
132
                  AB_SwiftDescr_GetAlias1(tmpDescr),
133
                  AB_SwiftDescr_GetAlias2(tmpDescr));
134
        /* copy to return list */
135
        descrCopy=AB_SwiftDescr_dup(descrFromList);
136
        AB_SwiftDescr_List_Add(descrCopy, returnDescrList);
137
      }
138
    }
139
    else {
140
      DBG_ERROR(AQHBCI_LOGDOMAIN, "Param [%s] does not match family %s.%d", sName, family, version1);
141
    }
142
  }
143
  else {
144
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Could not create SWIFT descriptor from string \"%s\", ignoring", sName);
145
  }
146
}
147

    
148

    
149

    
150
AB_SWIFT_DESCR_LIST *AH_Job_GetSwiftDescriptorsSupportedByUser(AH_JOB *j, const char *family, int version1)
151
{
152
  GWEN_DB_NODE *dbParams;
153
  AB_BANKING *ab;
154
  const GWEN_STRINGLIST *userDescriptors;
155
  GWEN_STRINGLISTENTRY *se;
156
  AB_SWIFT_DESCR_LIST *descrList;
157
  AB_SWIFT_DESCR_LIST *returnDescrList;
158
  AB_USER *user;
159

    
160
  dbParams=AH_Job_GetParams(j);
161
  assert(dbParams);
162

    
163
  ab=AH_Job_GetBankingApi(j);
164
  assert(ab);
165

    
166
  user=AH_Job_GetUser(j);
167
  assert(user);
168

    
169
  userDescriptors=AH_User_GetSepaDescriptors(user);
170
  if (GWEN_StringList_Count(userDescriptors)==0) {
171
    DBG_ERROR(AQHBCI_LOGDOMAIN, "No SEPA descriptor found, please update your account information");
172
    return NULL;
173
  }
174

    
175
  descrList=AB_Banking_GetSwiftDescriptorsForImExporter(ab, "xml");
176
  if (descrList==NULL) {
177
    DBG_ERROR(AQHBCI_LOGDOMAIN, "No SWIFT descriptors found for XML imexporter (job \"%s\")", AH_Job_GetName(j));
178
    return NULL;
179
  }
180

    
181
  returnDescrList=AB_SwiftDescr_List_new();
182
  se=GWEN_StringList_FirstEntry(userDescriptors);
183
  while (se) {
184
    const char *s;
185

    
186
    s=GWEN_StringListEntry_Data(se);
187
    if (s && *s) {
188
      AB_SWIFT_DESCR *tmpDescr;
189

    
190
      DBG_INFO(AQHBCI_LOGDOMAIN, "Checking user supported param [%s] (job \"%s\")", s, AH_Job_GetName(j));
191
      tmpDescr=AB_SwiftDescr_FromString(s);
192
      if (tmpDescr) {
193
        if (AB_SwiftDescr_Matches(tmpDescr, family, version1, 0, 0)) {
194
          AB_SWIFT_DESCR *descrFromList;
195

    
196
          /* found a candidate */
197
          descrFromList=AB_SwiftDescr_List_FindFirst(descrList,
198
                                                     AB_SwiftDescr_GetFamily(tmpDescr),
199
                                                     AB_SwiftDescr_GetVersion1(tmpDescr),
200
                                                     AB_SwiftDescr_GetVersion2(tmpDescr),
201
                                                     AB_SwiftDescr_GetVersion3(tmpDescr));
202
          if (descrFromList) {
203
            AB_SWIFT_DESCR *descrCopy;
204

    
205
            /* store name of selected profile */
206
            AB_SwiftDescr_SetAlias2(descrFromList, s);
207
            DBG_INFO(AQHBCI_LOGDOMAIN,
208
                     "Adding matching profile [%s] (%s)",
209
                     AB_SwiftDescr_GetAlias1(descrFromList),
210
                     AB_SwiftDescr_GetAlias2(descrFromList));
211
            /* copy to return list */
212
            descrCopy=AB_SwiftDescr_dup(descrFromList);
213
            AB_SwiftDescr_List_Add(descrCopy, returnDescrList);
214
          }
215
        }
216
        else {
217
          DBG_INFO(AQHBCI_LOGDOMAIN, "Param [%s] does not match family %s.%03d", s, family, version1);
218
        }
219
      }
220
      else {
221
        DBG_ERROR(AQHBCI_LOGDOMAIN,
222
                  "Could not create SWIFT descriptor from string \"%s\" (job \"%s\"), ignoring",
223
                  s, AH_Job_GetName(j));
224
      }
225
    }
226

    
227
    se=GWEN_StringListEntry_Next(se);
228
  }
229

    
230

    
231
  AB_SwiftDescr_List_free(descrList);
232
  if (AB_SwiftDescr_List_GetCount(returnDescrList)==0) {
233
    DBG_ERROR(AQHBCI_LOGDOMAIN,
234
              "No matching descriptors found for %s_%03d_* (job %s)",
235
              family?family:"<none>", version1, AH_Job_GetName(j));
236
    AB_SwiftDescr_List_free(returnDescrList);
237
    return NULL;
238
  }
239

    
240
  return returnDescrList;
241
}