Project

General

Profile

Revision 0f293628

View differences:

src/tools/aqbanking-cli/Makefile.am
16 16
  main.c \
17 17
  addsepadebitnote.c \
18 18
  addtransaction.c \
19
  chkacc.c \
20 19
  chkiban.c \
21 20
  fillgaps.c \
22 21
  import.c \
src/tools/aqbanking-cli/chkacc.c
1
/***************************************************************************
2
 begin       : Tue May 03 2005
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 "globals.h"
15
#include <gwenhywfar/text.h>
16

  
17

  
18
int chkAcc(AB_BANKING *ab, GWEN_DB_NODE *dbArgs, int argc, char **argv) {
19
  GWEN_DB_NODE *db;
20
  int rv;
21
  AB_BANKINFO_CHECKRESULT res;
22
  const char *country;
23
  const char *bankId;
24
  const char *accountId;
25
  const GWEN_ARGS args[]={
26
  {
27
    GWEN_ARGS_FLAGS_HAS_ARGUMENT,  /* flags */
28
    GWEN_ArgsType_Char,             /* type */
29
    "remoteCountry",               /* name */
30
    0,                             /* minnum */
31
    1,                             /* maxnum */
32
    0,                             /* short option */
33
    "rcountry",                    /* long option */
34
    "Specify the remote country code",/* short description */
35
    "Specify the remote country code" /* long description */
36
  },
37
  {
38
    GWEN_ARGS_FLAGS_HAS_ARGUMENT,  /* flags */
39
    GWEN_ArgsType_Char,             /* type */
40
    "remoteBankId",                /* name */
41
    1,                             /* minnum */
42
    1,                             /* maxnum */
43
    0,                             /* short option */
44
    "rbank",                       /* long option */
45
    "Specify the remote bank code",/* short description */
46
    "Specify the remote bank code" /* long description */
47
  },
48
  {
49
    GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
50
    GWEN_ArgsType_Char,            /* type */
51
    "remoteAccountId",                  /* name */
52
    1,                            /* minnum */
53
    1,                            /* maxnum */
54
    0,                            /* short option */
55
    "raccount",                    /* long option */
56
    "Specify the remote account number",     /* short description */
57
    "Specify the remote account number"      /* long description */
58
  },
59
  {
60
    GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */
61
    GWEN_ArgsType_Int,             /* type */
62
    "help",                       /* name */
63
    0,                            /* minnum */
64
    0,                            /* maxnum */
65
    "h",                          /* short option */
66
    "help",                       /* long option */
67
    "Show this help screen",      /* short description */
68
    "Show this help screen"       /* long description */
69
  }
70
  };
71

  
72
  db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
73
  rv=GWEN_Args_Check(argc, argv, 1,
74
                     0 /*GWEN_ARGS_MODE_ALLOW_FREEPARAM*/,
75
                     args,
76
                     db);
77
  if (rv==GWEN_ARGS_RESULT_ERROR) {
78
    fprintf(stderr, "ERROR: Could not parse arguments\n");
79
    return 1;
80
  }
81
  else if (rv==GWEN_ARGS_RESULT_HELP) {
82
    GWEN_BUFFER *ubuf;
83

  
84
    ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
85
    if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
86
      fprintf(stderr, "ERROR: Could not create help string\n");
87
      return 1;
88
    }
89
    fprintf(stderr,
90
            I18N("This command checks the given combination of account id\n"
91
                 "and bank code for validity.\n"
92
                 "\n"
93
                 "Return codes:\n"
94
                 " 1: missing/bad arguments\n"
95
                 " 2: error while initializing AqBanking\n"
96
                 " 3: given combination is definately invalid\n"
97
                 " 4: either bank code or check result are unknown\n"
98
                 " 5: error while deinitializing AqBanking\n"
99
                 "\n"
100
                 "Arguments:\n"
101
                 "%s\n"),
102
            GWEN_Buffer_GetStart(ubuf));
103
    GWEN_Buffer_free(ubuf);
104
    return 0;
105
  }
106

  
107
  country=GWEN_DB_GetCharValue(db, "remoteCountry", 0, "de");
108
  assert(country);
109
  bankId=GWEN_DB_GetCharValue(db, "remoteBankId", 0, 0);
110
  assert(bankId);
111
  accountId=GWEN_DB_GetCharValue(db, "remoteAccountId", 0, 0);
112
  assert(bankId);
113

  
114
  rv=AB_Banking_Init(ab);
115
  if (rv) {
116
    DBG_ERROR(0, "Error on init (%d)", rv);
117
    return 2;
118
  }
119

  
120
  res=AB_Banking_CheckAccount(ab,
121
                              country,
122
                              0,
123
                              bankId,
124
                              accountId);
125
  switch(res) {
126
  case AB_BankInfoCheckResult_NotOk:
127
    DBG_ERROR(0,
128
              "Invalid combination of bank code and account number "
129
              "for remote account");
130
    return 3;
131

  
132
  case AB_BankInfoCheckResult_UnknownBank:
133
    DBG_ERROR(0, "Remote bank code is unknown");
134
    return 4;
135

  
136
  case AB_BankInfoCheckResult_UnknownResult:
137
    DBG_ERROR(0,
138
              "Indifferent result for remote account check");
139
    return 4;
140

  
141
  case AB_BankInfoCheckResult_Ok:
142
    break;
143
  default:
144
    DBG_ERROR(0, "Unknown check result %d", res);
145
    return 4;
146
  }
147

  
148
  rv=AB_Banking_Fini(ab);
149
  if (rv) {
150
    fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv);
151
    return 5;
152
  }
153

  
154
  return 0;
155
}
156

  
157

  
158

  
159

  
160

  
161

  
src/tools/aqbanking-cli/main.c
324 324
      return 1;
325 325
    }
326 326

  
327
    if (strcasecmp(cmd, "listaccs")==0) {
327
    if (strcasecmp(cmd, "listaccs")==0 ||
328
        strcasecmp(cmd, "listaccounts")==0) {
328 329
      rv=listAccs(ab, db, argc, argv);
329 330
    }
330 331
    else if (strcasecmp(cmd, "listbal")==0) {
......
334 335
      rv=listTrans(ab, db, argc, argv);
335 336
    }
336 337
    else if (strcasecmp(cmd, "listtransfers")==0) {
337
      fprintf(stderr, "ERROR: Please use the command \"listtrans\" and specify the transaction type via \"-tt TYPE\"\n");
338
      fprintf(stderr, "ERROR: Please use the commands \"listtrans\" or \"export\" and specify the transaction type via \"-tt TYPE\"\n");
338 339
      GWEN_DB_Group_free(db);
339 340
      return 1;
340 341
    }
341 342
    else if (strcasecmp(cmd, "request")==0) {
342 343
      rv=request(ab, db, argc, argv);
343 344
    }
344
    else if (strcasecmp(cmd, "chkacc")==0) {
345
      rv=chkAcc(ab, db, argc, argv);
346
    }
347 345
    else if (strcasecmp(cmd, "chkiban")==0) {
348 346
      rv=chkIban(ab, db, argc, argv);
349 347
    }

Also available in: Unified diff