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
20
AH_Control_ListAccounts(AB_PROVIDER * pro,GWEN_DB_NODE * dbArgs,int argc,char ** argv)21 int AH_Control_ListAccounts(AB_PROVIDER *pro,
22 GWEN_DB_NODE *dbArgs,
23 int argc,
24 char **argv)
25 {
26 GWEN_DB_NODE *db;
27 int rv, verbose;
28 AB_ACCOUNT_LIST *al;
29 AB_ACCOUNT *a;
30 int i=0;
31 const GWEN_ARGS args[]= {
32 {
33 0, /* flags */
34 GWEN_ArgsType_Int, /* type */
35 "verbose", /* name */
36 0, /* minnum */
37 1, /* maxnum */
38 "v", /* short option */
39 "verbose", /* long option */
40 "Show list in verbose form (with more columns)", /* short description */
41 0
42 },
43 {
44 GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */
45 GWEN_ArgsType_Int, /* type */
46 "help", /* name */
47 0, /* minnum */
48 0, /* maxnum */
49 "h", /* short option */
50 "help", /* long option */
51 "Show this help screen", /* short description */
52 "Show this help screen" /* long description */
53 }
54 };
55
56 db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
57 rv=GWEN_Args_Check(argc, argv, 1,
58 0 /*GWEN_ARGS_MODE_ALLOW_FREEPARAM*/,
59 args,
60 db);
61 if (rv==GWEN_ARGS_RESULT_ERROR) {
62 fprintf(stderr, "ERROR: Could not parse arguments\n");
63 return 1;
64 }
65 else if (rv==GWEN_ARGS_RESULT_HELP) {
66 GWEN_BUFFER *ubuf;
67
68 ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
69 if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
70 fprintf(stderr, "ERROR: Could not create help string\n");
71 return 1;
72 }
73 fprintf(stdout, "%s\n", GWEN_Buffer_GetStart(ubuf));
74 GWEN_Buffer_free(ubuf);
75 return 0;
76 }
77
78 verbose = GWEN_DB_VariableExists(db, "verbose");
79
80 al=AB_Account_List_new();
81 rv=AB_Provider_ReadAccounts(pro, al);
82 if (rv<0) {
83 if (rv==GWEN_ERROR_NOT_FOUND) {
84 DBG_ERROR(0, "No accounts found.");
85 }
86 else {
87 DBG_ERROR_ERR(0, rv);
88 }
89 AB_Account_List_free(al);
90 return 3;
91 }
92
93 a=AB_Account_List_First(al);
94 while (a) {
95 fprintf(stdout, "Account %d: Bank: %s Account Number: %s",
96 i++,
97 AB_Account_GetBankCode(a),
98 AB_Account_GetAccountNumber(a));
99 if (verbose) {
100 const char *subAccountId = AB_Account_GetSubAccountId(a);
101
102 fprintf(stdout, " SubAccountId: %s Account Type: %s LocalUniqueId: %d",
103 subAccountId ? subAccountId : "(none)",
104 AB_AccountType_toChar(AB_Account_GetAccountType(a)),
105 AB_Account_GetUniqueId(a));
106 }
107 fprintf(stdout, "\n");
108 a=AB_Account_List_Next(a);
109 }
110 AB_Account_List_free(al);
111
112 return 0;
113 }
114
115
116
117
118