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
21
AH_Control_GetItanModes(AB_PROVIDER * pro,GWEN_DB_NODE * dbArgs,int argc,char ** argv)22 int AH_Control_GetItanModes(AB_PROVIDER *pro,
23 GWEN_DB_NODE *dbArgs,
24 int argc,
25 char **argv)
26 {
27 GWEN_DB_NODE *db;
28 uint32_t uid;
29 AB_USER *u=NULL;
30 int rv;
31 const GWEN_ARGS args[]= {
32 {
33 GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
34 GWEN_ArgsType_Int, /* type */
35 "userId", /* name */
36 0, /* minnum */
37 1, /* maxnum */
38 "u", /* short option */
39 "user", /* long option */
40 "Specify the unique user id", /* short description */
41 "Specify the unique user id" /* long description */
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
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 AB_IMEXPORTER_CONTEXT *ctx;
98
99 ctx=AB_ImExporterContext_new();
100 rv=AH_Provider_GetItanModes(pro, u, ctx, 1, 0, 1);
101 AB_ImExporterContext_free(ctx);
102 if (rv) {
103 DBG_ERROR_ERR(0, rv);
104 AB_User_free(u);
105 return 3;
106 }
107 }
108 AB_User_free(u);
109
110 return 0;
111 }
112
113
114
115
116