X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=client%2Fclient.c;h=8ca96abb1e0ca6147e554570cddded6d00cd4fe3;hp=99d6c54a00286ee64aa965faad2f93eac7ac1e14;hb=19a9c4f58563f2bb28d69647096491ae965fd377;hpb=3c03c66fdcf640bbf4c611a48bf8c74989d077f6 diff --git a/client/client.c b/client/client.c index 99d6c54..8ca96ab 100644 --- a/client/client.c +++ b/client/client.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2008 Index Data + * Copyright (C) 1995-2009 Index Data * See the file LICENSE for details. */ /** \file client.c @@ -92,7 +92,10 @@ static Z_SRW_PDU *srw_sr = 0; static FILE *apdu_file = 0; static FILE *ber_file = 0; static COMSTACK conn = 0; /* our z-association */ + static Z_IdAuthentication *auth = 0; /* our current auth definition */ +static NMEM nmem_auth = NULL; + char *databaseNames[128]; int num_databaseNames = 0; static Z_External *record_last = 0; @@ -205,7 +208,7 @@ static void do_hex_dump(const char* buf, size_t len) int x; for (i = 0; i < len ; i = i+16 ) { - printf(" %4.4d ",i); + printf(" %4.4ld ", (long) i); for(x=0 ; i+xwhich = Z_IdAuthentication_anonymous; + auth->u.anonymous = odr_nullval(); printf("Authentication set to Anonymous\n"); - } else { - au.which = Z_IdAuthentication_open; - au.u.open = user; - printf("Authentication set to Open (%s)\n", user); + } + else + { + auth->which = Z_IdAuthentication_open; + auth->u.open = args[0]; + printf("Authentication set to Open (%s)\n", args[0]); } } - if (r == 2) - { - auth = &au; - au.which = Z_IdAuthentication_idPass; - au.u.idPass = &idPass; - idPass.groupId = NULL; - idPass.userId = !strcmp(user, "-") ? 0 : user; - idPass.password = !strcmp(group, "-") ? 0 : group; - printf("Authentication set to User (%s), Pass (%s)\n", user, group); + else if (r == 2) + { + auth = nmem_malloc(nmem_auth, sizeof(*auth)); + auth->which = Z_IdAuthentication_idPass; + auth->u.idPass = nmem_malloc(nmem_auth, sizeof(*auth->u.idPass)); + auth->u.idPass->groupId = NULL; + auth->u.idPass->userId = !strcmp(args[0], "-") ? 0 : args[0]; + auth->u.idPass->password = !strcmp(args[1], "-") ? 0 : args[1]; + printf("Authentication set to User (%s), Pass (%s)\n", + args[0], args[1]); + } + else if (r == 3) + { + auth = nmem_malloc(nmem_auth, sizeof(*auth)); + auth->which = Z_IdAuthentication_idPass; + auth->u.idPass = nmem_malloc(nmem_auth, sizeof(*auth->u.idPass)); + auth->u.idPass->groupId = args[1]; + auth->u.idPass->userId = args[0]; + auth->u.idPass->password = args[2]; + printf("Authentication set to User (%s), Group (%s), Pass (%s)\n", + args[0], args[1], args[2]); } - if (r == 3) + else { - auth = &au; - au.which = Z_IdAuthentication_idPass; - au.u.idPass = &idPass; - idPass.groupId = group; - idPass.userId = user; - idPass.password = pass; - printf("Authentication set to User (%s), Group (%s), Pass (%s)\n", - user, group, pass); + printf("Bad number of args to auth\n"); + auth = 0; } + return 1; } @@ -2867,6 +2875,7 @@ void exit_client(int code) { file_history_save(file_history); file_history_destroy(&file_history); + nmem_destroy(nmem_auth); exit(code); } @@ -3547,16 +3556,12 @@ int cmd_source(const char* arg, int echo ) return -1; } - while (!feof(includeFile)) { - memset(line, 0, sizeof(line)); - if (!fgets(line, sizeof(line), includeFile)) - { - perror("fgets"); - break; - } - - if (strlen(line) < 2) continue; - if (line[0] == '#') continue; + while (fgets(line, sizeof(line), includeFile)) + { + if (strlen(line) < 2) + continue; + if (line[0] == '#') + continue; if ((cp = strrchr(line, '\n'))) *cp = '\0'; @@ -4926,6 +4931,8 @@ int main(int argc, char **argv) ODR_MASK_SET(&z3950_options, Z_Options_extendedServices); ODR_MASK_SET(&z3950_options, Z_Options_delSet); + nmem_auth = nmem_create(); + while ((ret = options("k:c:q:a:b:m:v:p:u:t:Vxd:f:", argv, argc, &arg)) != -2) { switch (ret) @@ -5054,6 +5061,7 @@ int main(int argc, char **argv) /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab