YAZ_{BEGIN,END}_CDECL yaz_init_globals
[yaz-moved-to-github.git] / util / yaz-illclient.c
index 62d7026..5693366 100644 (file)
@@ -1,8 +1,6 @@
-/*
- * Copyright (C) 1995-2006, Index Data ApS
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) Index Data
  * See the file LICENSE for details.
- *
- * $Id: yaz-illclient.c,v 1.5 2007-04-25 16:51:47 heikki Exp $
  */
 
 /* WARNING - This is work in progress - not at all ready */
@@ -15,7 +13,7 @@
  *  and yaz already provides the APDUS for it.
  *
  *  This is not an interactive client like yaz-client, but driven by command-
- *  line arguments. Its output is a return code, and possibly some text on 
+ *  line arguments. Its output is a return code, and possibly some text on
  *  stdout.
  *
  *  Exit codes  (note, the program exits as soon as it finds a good reason)
@@ -33,6 +31,9 @@
  *
  *
  */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -71,6 +72,8 @@ struct prog_args {
     char *host;
     char *auth_userid;
     char *auth_passwd;
+    char *oclc_recno; /* record number in oclc-mode */
+    int oclc_auth;  /* 1=use oclc-type auth */
     struct nameval* namevals; /* circular list, points to last */
 } ;
 
@@ -79,7 +82,7 @@ struct prog_args {
 /* Call-back to be called for every field in the ill-request */
 /* It can set values to any field, perhaps from the prog_args */
 const char *get_ill_element(void *clientData, const char *element) {
-    struct prog_args *args = clientData;
+    struct prog_args *args = (struct prog_args *) clientData;
     struct nameval *nv=args->namevals;
     char *ret=0;
     if (!nv)
@@ -90,25 +93,6 @@ const char *get_ill_element(void *clientData, const char *element) {
         if ( strcmp(element, nv->name) == 0 )
             ret = nv->val;
     } while ( ( !ret) && ( nv != args->namevals) );
-#if 0
-    if (!strcmp(element,"foo")) {
-        ret=args->host;
-    } else if (!strcmp(element,"ill,protocol-version-num")) {
-        ret="2";
-    } else if (!strcmp(element,"ill,transaction-id,initial-requester-id,person-or-institution-symbol,institution")) {
-        ret=args->auth_userid; 
-    } else if (!strcmp(element,"ill,requester-id,person-or-institution-symbol,institution")) {
-        ret=args->auth_userid;
-    } else if (!strcmp(element,"ill,responder-id,person-or-institution-symbol,institution")) {
-        ret=args->auth_userid;
-    } else if (!strcmp(element,"ill,ill-service-type")) {
-        ret="1"; /* Loan */
-    } 
-#endif
- /*
-    } else if (!strcmp(element,"ill,transaction-id,initial-requester-id,person-or-institution-symbol,institution")) {
-        ret="IndexData";
- */
     yaz_log(YLOG_DEBUG,"get_ill_element:'%s'->'%s'", element, ret );
     return ret;
 }
@@ -119,17 +103,17 @@ const char *get_ill_element(void *clientData, const char *element) {
 /** \brief parse a parameter string */
 /* string is like 'name=value' */
 struct nameval *parse_nameval( char *arg ) {
-    struct nameval *nv = xmalloc(sizeof(*nv));
+    struct nameval *nv = (struct nameval *) xmalloc(sizeof(*nv));
     char *p=arg;
     int len;
-    if (!p || !*p) 
+    if (!p || !*p)
         return 0; /* yeah, leaks a bit of memory. so what */
-    while ( *p && ( *p != '=' ) ) 
+    while ( *p && ( *p != '=' ) )
         p++;
     len = p - arg;
     if (!len)
         return 0;
-    nv->name = xmalloc(len+1);
+    nv->name = (char *) xmalloc(len+1);
     strncpy(nv->name, arg, len);
     nv->name[len]='\0';
     if (*p == '=' )
@@ -150,7 +134,7 @@ void append_nameval (struct prog_args *args, struct nameval *nv) {
         return;
     if (args->namevals) {
         nv->next=args->namevals->next; /* first */
-        args->namevals->next=nv; 
+        args->namevals->next=nv;
         args->namevals=nv;
     } else {
         nv->next=nv;
@@ -161,7 +145,7 @@ void append_nameval (struct prog_args *args, struct nameval *nv) {
 /** \brief parse a parameter file */
 void parse_paramfile(char *arg, struct prog_args *args) {
     FILE *f=fopen(arg,"r");
-#define BUFSIZE 4096    
+#define BUFSIZE 4096
     char buf[BUFSIZE];
     int len;
     struct nameval *nv;
@@ -201,27 +185,25 @@ void parseargs( int argc, char * argv[],  struct prog_args *args) {
     int ret;
     char *arg;
     char *prog=*argv;
-    char *version="$Id: yaz-illclient.c,v 1.5 2007-04-25 16:51:47 heikki Exp $"; /* from cvs */
+    char version[60];
     struct nameval *nv;
 
     /* default values */
     args->host = 0; /* not known (yet) */
     args->namevals=0; /* none set up */
-#if 0    
-    /* Example 1, from TSLAC */
-    args->auth_userid = "100-228-301" ; /* FIXME - get from cmd line */
-    args->auth_passwd = "dxg5magxc" ;   /* FIXME - get from cmd line */
-    /* Example 2, from TSLAC */
-    args->auth_userid = "100070049" ; /* FIXME - get from cmd line */
-    args->auth_passwd = "cowgirl" ;   /* FIXME - get from cmd line */
-#else
+    args->oclc_auth=0;
+    args->oclc_recno=0;
+    args->auth_userid = 0;
+    args->auth_passwd = 0;
+#if 0
     /* Example 3 - directly from OCLC, supposed to work on their test server*/
     args->auth_userid = "100-310-658" ; /* FIXME - get from cmd line */
     args->auth_passwd = "apii2test" ;   /* FIXME - get from cmd line */
 #endif
 
-    while ((ret = options("v:D:f:V", argv, argc, &arg)) != -2)
+    while ((ret = options("Vov:p:u:D:f:r:l:", argv, argc, &arg)) != -2)
     {
+        yaz_log(YLOG_DEBUG,"parsing option '%c' '%s'",ret, arg);
         switch (ret)
         {
         case 0:
@@ -239,8 +221,12 @@ void parseargs( int argc, char * argv[],  struct prog_args *args) {
         case 'v':
             yaz_log_init(yaz_log_mask_str(arg), "", 0);
             break;
+        case 'l':
+            yaz_log_init_file(arg);
+            break;
         case 'V':
-            printf("%s %s",prog, version );
+            yaz_version(version, 0);
+            printf("%s %s\n",prog, version);
             break;
         case 'D':
             nv=parse_nameval(arg);
@@ -249,10 +235,24 @@ void parseargs( int argc, char * argv[],  struct prog_args *args) {
         case 'f':
             parse_paramfile(arg,args);
             break;
+        case 'o':
+            args->oclc_auth=1;
+            break;
+        case 'u':
+            args->auth_userid=xstrdup(arg);
+            break;
+        case 'p':
+            args->auth_passwd=xstrdup(arg);
+            break;
+        case 'r':
+            args->oclc_recno=xstrdup(arg);
+            break;
         default:
             fprintf (stderr, "Usage: %s "
+                     " [-f filename]"
                      " [-v loglevel...]"
                      " [-D name=value ]"
+                     " [-o -u user -p passwd]"
                      " [-V]"
                      " <server-addr>\n",
                      prog);
@@ -269,6 +269,10 @@ void validateargs( struct prog_args *args) {
                         "as in 'bagel.indexdata.dk:210' \n");
         exit(1);
     }
+    if (args->oclc_auth && ((!args->auth_userid) || (!args->auth_passwd))){
+        fprintf(stderr, "-o option requires -u <user> and -p <pwd>\n");
+        exit(1);
+    }
 } /* validateargs */
 
 
@@ -286,7 +290,7 @@ COMSTACK connect_to( char *hostaddr ){
                  hostaddr );
         exit(2);
     }
-    
+
     yaz_log(YLOG_DEBUG,"Created stack ok ");
 
     status = cs_connect(stack, server_address_ip);
@@ -303,33 +307,33 @@ COMSTACK connect_to( char *hostaddr ){
 /* * * * * * * * * * * * * * * */
 /* Makes a Z39.50-like prompt package with username and password */
 Z_PromptObject1 *makeprompt(struct prog_args *args, ODR odr) {
-    Z_PromptObject1 *p = odr_malloc(odr, sizeof(*p) );
-    Z_ResponseUnit1 *ru = odr_malloc(odr, sizeof(*ru) );
-    
+    Z_PromptObject1 *p = (Z_PromptObject1 *) odr_malloc(odr, sizeof(*p) );
+    Z_ResponseUnit1 *ru = (Z_ResponseUnit1 *) odr_malloc(odr, sizeof(*ru) );
+
     p->which=Z_PromptObject1_response;
-    p->u.response = odr_malloc(odr, sizeof(*(p->u.response)) );
+    p->u.response = (Z_Response1*) odr_malloc(odr, sizeof(*(p->u.response)) );
     p->u.response->num=2;
-    p->u.response->elements=odr_malloc(odr, 
+    p->u.response->elements= (Z_ResponseUnit1 **) odr_malloc(odr,
              p->u.response->num*sizeof(*(p->u.response->elements)) );
     /* user id, aka "oclc authorization number" */
     p->u.response->elements[0] = ru;
-    ru->promptId = odr_malloc(odr, sizeof(*(ru->promptId) ));
+    ru->promptId = (Z_PromptId *) odr_malloc(odr, sizeof(*(ru->promptId) ));
     ru->promptId->which = Z_PromptId_enumeratedPrompt;
-    ru->promptId->u.enumeratedPrompt =  
+    ru->promptId->u.enumeratedPrompt = (Z_PromptIdEnumeratedPrompt *)
         odr_malloc(odr, sizeof(*(ru->promptId->u.enumeratedPrompt) ));
-    ru->promptId->u.enumeratedPrompt->type = 
+    ru->promptId->u.enumeratedPrompt->type =
          odr_intdup(odr,Z_PromptIdEnumeratedPrompt_userId);
     ru->promptId->u.enumeratedPrompt->suggestedString = 0 ;
     ru->which = Z_ResponseUnit1_string ;
     ru->u.string = odr_strdup(odr, args->auth_userid);
     /* password */
-    ru = odr_malloc(odr, sizeof(*ru) );
+    ru = (Z_ResponseUnit1 *) odr_malloc(odr, sizeof(*ru) );
     p->u.response->elements[1] = ru;
-    ru->promptId = odr_malloc(odr, sizeof(*(ru->promptId) ));
+    ru->promptId = (Z_PromptId *) odr_malloc(odr, sizeof(*(ru->promptId) ));
     ru->promptId->which = Z_PromptId_enumeratedPrompt;
-    ru->promptId->u.enumeratedPrompt =  
+    ru->promptId->u.enumeratedPrompt =  (Z_PromptIdEnumeratedPrompt *)
         odr_malloc(odr, sizeof(*(ru->promptId->u.enumeratedPrompt) ));
-    ru->promptId->u.enumeratedPrompt->type = 
+    ru->promptId->u.enumeratedPrompt->type =
          odr_intdup(odr,Z_PromptIdEnumeratedPrompt_password);
     ru->promptId->u.enumeratedPrompt->suggestedString = 0 ;
     ru->which = Z_ResponseUnit1_string ;
@@ -340,11 +344,11 @@ Z_PromptObject1 *makeprompt(struct prog_args *args, ODR odr) {
 ILL_Extension *makepromptextension(struct prog_args *args, ODR odr) {
     ODR odr_ext = odr_createmem(ODR_ENCODE);
     ODR odr_prt = odr_createmem(ODR_PRINT);
-    ILL_Extension *e = odr_malloc(odr, sizeof(*e));
+    ILL_Extension *e = (ILL_Extension *) odr_malloc(odr, sizeof(*e));
     Z_PromptObject1 *p = makeprompt(args,odr_ext);
     char * buf;
     int siz;
-    Z_External *ext = odr_malloc(odr, sizeof(*ext));
+    Z_External *ext = (Z_External *) odr_malloc(odr, sizeof(*ext));
     ext->direct_reference = odr_getoidbystr(odr,"1.2.840.10003.8.1");
     ext->indirect_reference=0;
     ext->descriptor=0;
@@ -353,31 +357,32 @@ ILL_Extension *makepromptextension(struct prog_args *args, ODR odr) {
         yaz_log(YLOG_FATAL,"Encoding of z_PromptObject1 failed ");
         exit (6);
     }
-    
+
     printf ("Prompt: \n"); /*!*/
     z_PromptObject1(odr_prt, &p, 0,0 ); /*!*/
 
     buf= odr_getbuf(odr_ext,&siz,0);
-    ext->u.single_ASN1_type=odr_malloc(odr,sizeof(*ext->u.single_ASN1_type));
-    ext->u.single_ASN1_type->buf= odr_malloc(odr, siz);
+    ext->u.single_ASN1_type=(Odr_any *)
+        odr_malloc(odr,sizeof(*ext->u.single_ASN1_type));
+    ext->u.single_ASN1_type->buf= (char *) odr_malloc(odr, siz);
     memcpy(ext->u.single_ASN1_type->buf,buf, siz );
-    ext->u.single_ASN1_type->len = ext->u.single_ASN1_type->size = siz;
+    ext->u.single_ASN1_type->len = siz;
     odr_reset(odr_ext);
     odr_reset(odr_prt); /*!*/
 
     e->identifier = odr_intdup(odr,1);
-    e->critical = odr_intdup(odr,0);
-    e->item=odr_malloc(odr,sizeof(*e->item));
+    e->critical = odr_booldup(odr,0);
+    e->item = (Odr_any *) odr_malloc(odr,sizeof(*e->item));
     if ( ! z_External(odr_ext, &ext,0,0) ) {
         yaz_log(YLOG_FATAL,"Encoding of z_External failed ");
         exit (6);
     }
     printf("External: \n");
     z_External(odr_prt, &ext,0,0);  /*!*/
-    buf= odr_getbuf(odr_ext,&siz,0); 
-    e->item->buf= odr_malloc(odr, siz);
+    buf= odr_getbuf(odr_ext,&siz,0);
+    e->item->buf= (char *) odr_malloc(odr, siz);
     memcpy(e->item->buf,buf, siz );
-    e->item->len = e->item->size = siz;
+    e->item->len = siz;
 
     odr_destroy(odr_prt);
     odr_destroy(odr_ext);
@@ -389,11 +394,12 @@ ILL_Extension *makeoclcextension(struct prog_args *args, ODR odr) {
     /* fields. Here we just null them all out */
     ODR odr_ext = odr_createmem(ODR_ENCODE);
     ODR odr_prt = odr_createmem(ODR_PRINT);
-    ILL_Extension *e = odr_malloc(odr, sizeof(*e));
-    ILL_OCLCILLRequestExtension *oc = odr_malloc(odr_ext, sizeof(*oc));
+    ILL_Extension *e = (ILL_Extension *) odr_malloc(odr, sizeof(*e));
+    ILL_OCLCILLRequestExtension *oc = (ILL_OCLCILLRequestExtension *)
+        odr_malloc(odr_ext, sizeof(*oc));
     char * buf;
     int siz;
-    Z_External *ext = odr_malloc(odr, sizeof(*ext));
+    Z_External *ext = (Z_External *) odr_malloc(odr, sizeof(*ext));
     oc->clientDepartment = 0;
     oc->paymentMethod = 0;
     oc->uniformTitle = 0;
@@ -410,31 +416,32 @@ ILL_Extension *makeoclcextension(struct prog_args *args, ODR odr) {
         yaz_log(YLOG_FATAL,"Encoding of ill_OCLCILLRequestExtension failed ");
         exit (6);
     }
-    
+
     printf ("OCLC: \n"); /*!*/
     ill_OCLCILLRequestExtension(odr_prt, &oc, 0,0 ); /*!*/
 
     buf= odr_getbuf(odr_ext,&siz,0);
-    ext->u.single_ASN1_type=odr_malloc(odr,sizeof(*ext->u.single_ASN1_type));
-    ext->u.single_ASN1_type->buf= odr_malloc(odr, siz);
+    ext->u.single_ASN1_type = (Odr_any*)
+        odr_malloc(odr,sizeof(*ext->u.single_ASN1_type));
+    ext->u.single_ASN1_type->buf = (char *) odr_malloc(odr, siz);
     memcpy(ext->u.single_ASN1_type->buf,buf, siz );
-    ext->u.single_ASN1_type->len = ext->u.single_ASN1_type->size = siz;
+    ext->u.single_ASN1_type->len = siz;
     odr_reset(odr_ext);
     odr_reset(odr_prt); /*!*/
 
     e->identifier = odr_intdup(odr,1);
-    e->critical = odr_intdup(odr,0);
-    e->item=odr_malloc(odr,sizeof(*e->item));
+    e->critical = odr_booldup(odr,0);
+    e->item = (Odr_any *) odr_malloc(odr,sizeof(*e->item));
     if ( ! z_External(odr_ext, &ext,0,0) ) {
         yaz_log(YLOG_FATAL,"Encoding of z_External failed ");
         exit (6);
     }
     printf("External: \n");
     z_External(odr_prt, &ext,0,0);  /*!*/
-    buf= odr_getbuf(odr_ext,&siz,0); 
-    e->item->buf= odr_malloc(odr, siz);
-    memcpy(e->item->buf,buf, siz );
-    e->item->len = e->item->size = siz;
+    buf= odr_getbuf(odr_ext,&siz,0);
+    e->item->buf= (char *) odr_malloc(odr, siz);
+    memcpy(e->item->buf, buf, siz);
+    e->item->len = siz;
 
     odr_destroy(odr_prt);
     odr_destroy(odr_ext);
@@ -450,15 +457,19 @@ ILL_APDU *createrequest( struct prog_args *args, ODR odr) {
     ctl.odr = odr;
     ctl.clientData = args;
     ctl.f = get_ill_element;
-    apdu = odr_malloc( odr, sizeof(*apdu) );
+    apdu = (ILL_APDU *) odr_malloc( odr, sizeof(*apdu) );
     apdu->which=ILL_APDU_ILL_Request;
     req = ill_get_ILLRequest(&ctl, "ill", 0);
     apdu->u.illRequest=req;
-    req->num_iLL_request_extensions=2;
-    req->iLL_request_extensions=
-        odr_malloc(odr, req->num_iLL_request_extensions*sizeof(*req->iLL_request_extensions));
-    req->iLL_request_extensions[0]=makepromptextension(args,odr);
-    req->iLL_request_extensions[1]=makeoclcextension(args,odr);
+    if (args->oclc_auth) {
+        req->num_iLL_request_extensions=2;
+        req->iLL_request_extensions=
+            (ILL_Extension **)
+            odr_malloc(odr, req->num_iLL_request_extensions*
+                       sizeof(*req->iLL_request_extensions));
+        req->iLL_request_extensions[0]=makepromptextension(args,odr);
+        req->iLL_request_extensions[1]=makeoclcextension(args,odr);
+    }
     if (!req) {
         yaz_log(YLOG_FATAL,"Could not create ill request");
         exit(2);
@@ -473,7 +484,7 @@ void sendrequest(ILL_APDU *apdu, ODR odr, COMSTACK stack ) {
     char *buf_out;
     int len_out;
     int res;
-    if (!ill_APDU  (odr, &apdu, 0, 0)) { 
+    if (!ill_APDU  (odr, &apdu, 0, 0)) {
         yaz_log(YLOG_FATAL,"ill_Apdu failed");
         exit(2);
     }
@@ -495,10 +506,19 @@ void sendrequest(ILL_APDU *apdu, ODR odr, COMSTACK stack ) {
     }
     if (1) {
         FILE *F = fopen("req.apdu","w");
-        fwrite ( buf_out, 1, len_out, F);
-        fclose(F);
+        if (!F)
+        {
+            yaz_log(YLOG_FATAL|YLOG_ERRNO, "open req.apdu failed");
+        }
+        else
+        {
+            if (fwrite ( buf_out, 1, len_out, F) != len_out)
+                yaz_log(YLOG_FATAL|YLOG_ERRNO, "write req.apdu failed");
+            if (fclose(F))
+                yaz_log(YLOG_FATAL|YLOG_ERRNO, "write req.apdu failed");
+        }
     }
-    
+
 } /* sendrequest */
 
 /* * * * * * * * * * * * * * * */
@@ -513,7 +533,7 @@ ILL_APDU *getresponse( COMSTACK stack, ODR in_odr ){
     yaz_log(YLOG_DEBUG,"Got a response of %d bytes at %p. res=%d", len_in,buf_in, res);
     if (res<0) {
         yaz_log(YLOG_FATAL,"Could not receive packet. code %d",res );
-        yaz_log(YLOG_DEBUG,"%02x %02x %02x %02x %02x %02x %02x %02x ...", 
+        yaz_log(YLOG_DEBUG,"%02x %02x %02x %02x %02x %02x %02x %02x ...",
                 buf_in[0], buf_in[1], buf_in[2], buf_in[3],
                 buf_in[4], buf_in[5], buf_in[6], buf_in[7]  );
         yaz_log(YLOG_DEBUG,"PDU Dump:");
@@ -530,7 +550,7 @@ ILL_APDU *getresponse( COMSTACK stack, ODR in_odr ){
         sprintf(msg, "ODR code %d:%d element=%-20s",
                 err, x, element ? element : "<unknown>");
         yaz_log(YLOG_FATAL,"Error decoding incoming packet: %s",msg);
-        yaz_log(YLOG_DEBUG,"%02x %02x %02x %02x %02x %02x %02x %02x ...", 
+        yaz_log(YLOG_DEBUG,"%02x %02x %02x %02x %02x %02x %02x %02x ...",
                 buf_in[0], buf_in[1], buf_in[2], buf_in[3],
                 buf_in[4], buf_in[5], buf_in[6], buf_in[7]  );
         yaz_log(YLOG_DEBUG,"PDU Dump:");
@@ -553,7 +573,7 @@ void dumpapdu( ILL_APDU *apdu) {
 ILL_Status_Or_Error_Report *getstaterr( ILL_APDU *resp, ODR in_odr ) {
     if (resp->which != ILL_APDU_Status_Or_Error_Report ) {
         const char *element = odr_getelement(in_odr);
-        if (!element) 
+        if (!element)
             element="unknown";
         printf("Server returned wrong packet type: %d\n", resp->which);
         yaz_log(YLOG_FATAL,"Server returned a (%d) and "
@@ -566,9 +586,9 @@ ILL_Status_Or_Error_Report *getstaterr( ILL_APDU *resp, ODR in_odr ) {
 
 /** \brief  Return a printable string from an ILL_String */
 char *getillstring( ILL_String *s) {
-    if (s->which == ILL_String_GeneralString ) 
+    if (s->which == ILL_String_GeneralString )
         return s->u.GeneralString;
-    else if (s->which == ILL_String_EDIFACTString ) 
+    else if (s->which == ILL_String_EDIFACTString )
         return s->u.EDIFACTString;
     else {
         yaz_log(YLOG_FATAL,"Invalid ILL_String ");
@@ -591,15 +611,15 @@ void checkerr( ILL_Status_Or_Error_Report *staterr ) {
                     printf("Already forwarded: \n");
                     break;
                 case ILL_User_Error_Report_intermediary_problem:
-                    printf("Intermediary problem: %d\n", 
+                    printf("Intermediary problem: " ODR_INT_PRINTF "\n",
                         *uerr->u.intermediary_problem);
                     break;
                 case ILL_User_Error_Report_security_problem:
-                    printf("Security problem: %s\n", 
+                    printf("Security problem: %s\n",
                         getillstring(uerr->u.security_problem));
                     break;
                 case ILL_User_Error_Report_unable_to_perform:
-                    printf("Unable to perform: %d\n", 
+                    printf("Unable to perform: " ODR_INT_PRINTF "\n",
                           *uerr->u.unable_to_perform);
                     break;
                 default:
@@ -611,24 +631,25 @@ void checkerr( ILL_Status_Or_Error_Report *staterr ) {
             ILL_Provider_Error_Report *perr= err->provider_error_report;
             switch( perr->which ) {
                 case ILL_Provider_Error_Report_general_problem:
-                    printf("General Problem: %d\n", 
+                    printf("General Problem: " ODR_INT_PRINTF ":",
                           *perr->u.general_problem);
                     break;
                 case ILL_Provider_Error_Report_transaction_id_problem:
-                    printf("Transaction Id Problem: %d\n", 
+                    printf("Transaction Id Problem: " ODR_INT_PRINTF ":",
                           *perr->u.general_problem);
                     break;
                 case ILL_Provider_Error_Report_state_transition_prohibited:
-                    printf("State Transition prohibited \n");
+                    printf("State Transition prohibited:");
                     break;
             }
-            exit(7);
-        } 
+            /*exit(7);*/
+        }
         /* fallbacks */
-        if ( staterr->note ) 
+        if ( staterr->note )
             printf("%s", getillstring(staterr->note));
-        else 
+        else
             printf("Unknown error type");
+        printf("\n");
         exit(7);
     }
 } /* checkerr */
@@ -637,7 +658,7 @@ void checkerr( ILL_Status_Or_Error_Report *staterr ) {
 
 /* * * * * * * * * * * * * * * */
 
-/** \brief Main program 
+/** \brief Main program
  *
  * Parse arguments
  * Validate arguments
@@ -662,11 +683,11 @@ int main (int argc, char * argv[]) {
     validateargs(&args);
     stack = connect_to(args.host);
     apdu = createrequest(&args, out_odr);
-    if (1) 
+    if (1)
         dumpapdu(apdu);
-    sendrequest(apdu, out_odr, stack ); 
+    sendrequest(apdu, out_odr, stack );
     resp = getresponse(stack, in_odr );
-    if (1) 
+    if (1)
         dumpapdu(resp);
     staterr=getstaterr(resp, in_odr);
     checkerr(staterr);
@@ -679,6 +700,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