Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

aqbanking / src / libs / plugins / backends / aqhbci / control / listitanmodes.c @ f1787c2f

History | View | Annotate | Download (4.54 KB)

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

    
15
#include "globals_l.h"
16

    
17
#include <gwenhywfar/text.h>
18

    
19
#include "aqhbci/banking/user.h"
20

    
21

    
22

    
23
int AH_Control_ListItanModes(AB_PROVIDER *pro,
24
                             GWEN_DB_NODE *dbArgs,
25
                             int argc,
26
                             char **argv)
27
{
28
  GWEN_DB_NODE *db;
29
  uint32_t uid;
30
  AB_USER *u=NULL;
31
  int rv;
32
  const GWEN_ARGS args[]= {
33
    {
34
      GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
35
      GWEN_ArgsType_Int,            /* type */
36
      "userId",                     /* name */
37
      0,                            /* minnum */
38
      1,                            /* maxnum */
39
      "u",                          /* short option */
40
      "user",                       /* long option */
41
      "Specify the unique user id",    /* short description */
42
      "Specify the unique user id"     /* long description */
43
    },
44
    {
45
      GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */
46
      GWEN_ArgsType_Int,            /* type */
47
      "help",                       /* name */
48
      0,                            /* minnum */
49
      0,                            /* maxnum */
50
      "h",                          /* short option */
51
      "help",                       /* long option */
52
      "Show this help screen",      /* short description */
53
      "Show this help screen"       /* long description */
54
    }
55
  };
56

    
57
  db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
58
  rv=GWEN_Args_Check(argc, argv, 1,
59
                     0 /*GWEN_ARGS_MODE_ALLOW_FREEPARAM*/,
60
                     args,
61
                     db);
62
  if (rv==GWEN_ARGS_RESULT_ERROR) {
63
    fprintf(stderr, "ERROR: Could not parse arguments\n");
64
    return 1;
65
  }
66
  else if (rv==GWEN_ARGS_RESULT_HELP) {
67
    GWEN_BUFFER *ubuf;
68

    
69
    ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
70
    if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
71
      fprintf(stderr, "ERROR: Could not create help string\n");
72
      return 1;
73
    }
74
    fprintf(stdout, "%s\n", GWEN_Buffer_GetStart(ubuf));
75
    GWEN_Buffer_free(ubuf);
76
    return 0;
77
  }
78

    
79
  /* doit */
80
  uid=(uint32_t) GWEN_DB_GetIntValue(db, "userId", 0, 0);
81
  if (uid==0) {
82
    fprintf(stderr, "ERROR: Invalid or missing unique user id\n");
83
    return 1;
84
  }
85

    
86
  rv=AB_Provider_HasUser(pro, uid);
87
  if (rv<0) {
88
    fprintf(stderr, "ERROR: User with id %lu not found\n", (unsigned long int) uid);
89
    return 2;
90
  }
91
  rv=AB_Provider_GetUser(pro, uid, 1, 1, &u);
92
  if (rv<0) {
93
    fprintf(stderr, "ERROR: User with id %lu not found\n", (unsigned long int) uid);
94
    return 2;
95
  }
96
  else {
97
    const AH_TAN_METHOD_LIST *tl;
98

    
99
    tl=AH_User_GetTanMethodDescriptions(u);
100
    if (tl) {
101
      const AH_TAN_METHOD *tm;
102

    
103
      tm=AH_TanMethod_List_First(tl);
104
      fprintf(stdout, "TAN Methods\n");
105
      while (tm) {
106
        const char *mid;
107
        const char *zkaName;
108
        const char *mname;
109
        int combinedVersion;
110

    
111
        combinedVersion=AH_TanMethod_GetFunction(tm)+(AH_TanMethod_GetGvVersion(tm)*1000);
112
        fprintf(stdout,
113
                "- %4d (F%3d/V%1d/P%1d)",
114
                combinedVersion,
115
                AH_TanMethod_GetFunction(tm),
116
                AH_TanMethod_GetGvVersion(tm),
117
                AH_TanMethod_GetProcess(tm));
118
        mid=AH_TanMethod_GetMethodId(tm);
119
        mname=AH_TanMethod_GetMethodName(tm);
120
        zkaName=AH_TanMethod_GetZkaTanName(tm);
121
        if (mid && mname) {
122
          fprintf(stdout, ": %s (%s)", mid, mname);
123
        }
124
        else if (mid && !mname) {
125
          fprintf(stdout, ": %s", mid);
126
        }
127
        else if (!mid && mname) {
128
          fprintf(stdout, ": %s", mname);
129
        }
130
        else {
131
          fprintf(stdout, ": <no name>");
132
        }
133

    
134
        if (zkaName && *zkaName) {
135
            fprintf(stdout, " ZKA-ID=%s", zkaName);
136
        }
137

    
138
        if (AH_User_HasTanMethod(u, AH_TanMethod_GetFunction(tm))) {
139
          if (AH_User_GetSelectedTanMethod(u)==combinedVersion)
140
            fprintf(stdout, " [available and selected]");
141
          else
142
            fprintf(stdout, " [available]");
143
        }
144
        else
145
          fprintf(stdout, " [not available]");
146
        fprintf(stdout, "\n");
147

    
148
        tm=AH_TanMethod_List_Next(tm);
149
      }
150
    }
151

    
152
  }
153
  AB_User_free(u);
154

    
155
  return 0;
156
}
157

    
158

    
159

    
160