Added print of status or Error Report from xml ES
[yaz-moved-to-github.git] / client / client.c
index 1c0a752..811d957 100644 (file)
@@ -1925,16 +1925,30 @@ void process_ESResponse(Z_ExtendedServicesResponse *res)
         if (ext->which == Z_External_itemOrder)
         {
             Z_IOTaskPackage *otp = ext->u.itemOrder->u.taskPackage;
-            if (otp && otp->targetPart && otp->targetPart->itemRequest)
+
+            if (otp && otp->targetPart ) 
             {
-                Z_External *ext = otp->targetPart->itemRequest;
-                if (ext->which == Z_External_octet)
+                if (otp->targetPart->itemRequest) 
                 {
-                    Odr_oct *doc = ext->u.octet_aligned;
-                    printf("Got itemRequest doc %.*s\n",
-                           doc->len, doc->buf);
+                    Z_External *ext = otp->targetPart->itemRequest;                    
+                    if (ext->which == Z_External_octet)
+                    {
+                        Odr_oct *doc = ext->u.octet_aligned;
+                        printf("Got itemRequest doc %.*s\n",
+                               doc->len, doc->buf);
+                    }
                 }
-            }
+                else if (otp->targetPart->statusOrErrorReport) 
+                {
+                    Z_External *ext = otp->targetPart->statusOrErrorReport;
+                    if (ext->which == Z_External_octet)
+                    {
+                        Odr_oct *doc = ext->u.octet_aligned;
+                        printf("Got Status or Error Report doc %.*s\n",
+                               doc->len, doc->buf);
+                    }
+                }
+            } 
         }
     }
     if (res->taskPackage && res->taskPackage->which == Z_External_octet)
@@ -2055,7 +2069,9 @@ static Z_External *create_external_ILL_APDU(int which)
 }
 
 
-static Z_External *create_ItemOrderExternal(const char *type, int itemno, const char* document_name)
+static Z_External *create_ItemOrderExternal(const char *type, int itemno,
+                                            const char *xml_buf,
+                                            int xml_len)
 {
     Z_External *r = (Z_External *) odr_malloc(out, sizeof(Z_External));
     r->direct_reference = odr_oiddup(out, yaz_oid_extserv_item_order);
@@ -2106,29 +2122,18 @@ static Z_External *create_ItemOrderExternal(const char *type, int itemno, const
     }
     else if (!strcmp(type, "xml") || !strcmp(type, "3"))
     {
-        printf("xml found \n");
-                    
-        if( !document_name ) 
-        {
-            printf("no ducoument added \n");
-            r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
-            return r;
-        };
+        printf("using XML ILL-request\n");
 
-        char *xml_buf = NULL;
-        int xml_len = 0;
-
-        printf("reading from -%s-\n", document_name );
-        if (parse_cmd_doc(&document_name, out, &xml_buf, &xml_len) == 0 )
+        if (!xml_buf)
         {
-            printf("Unable to read document\n");
+            printf("no docoument added\n");
             r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
-            return r;
-        };
-
-        r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
-            z_ext_record_oid(out, yaz_oid_recsyn_xml, xml_buf, xml_len);
-            
+        }
+        else
+        {
+            r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
+                z_ext_record_oid(out, yaz_oid_recsyn_xml, xml_buf, xml_len);
+        }
     }
     else
         r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
@@ -2136,7 +2141,8 @@ static Z_External *create_ItemOrderExternal(const char *type, int itemno, const
     return r;
 }
 
-static int send_itemorder(const char *type, int itemno, const char* document_name)
+static int send_itemorder(const char *type, int itemno,
+                          const char *xml_buf, int xml_len)
 {
     Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest);
     Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
@@ -2146,8 +2152,8 @@ static int send_itemorder(const char *type, int itemno, const char* document_nam
     req->packageType = odr_oiddup(out, yaz_oid_extserv_item_order);
     req->packageName = esPackageName;
 
-    req->taskSpecificParameters = create_ItemOrderExternal(type, itemno, document_name);
-
+    req->taskSpecificParameters = create_ItemOrderExternal(type, itemno,
+                                                           xml_buf, xml_len);
     send_apdu(apdu);
     return 0;
 }
@@ -2472,20 +2478,19 @@ static int cmd_itemorder(const char *arg)
 {
     char type[12];
     int itemno;
-    const char* filename = arg;
+    char *xml_buf = 0;
+    int xml_len = 0;
+    int no_read = 0;
    
     if (only_z3950())
         return 1;
-    if (sscanf (arg, "%10s %d", type, &itemno) != 2)
+    if (sscanf(arg, "%10s %d%n", type, &itemno, &no_read) < 2)
         return 0;
+    arg += no_read;
+    parse_cmd_doc(&arg, out, &xml_buf, &xml_len);
 
-
-    filename+=strlen(type) + 1; 
-    while( *filename && *filename !=' ' ) filename++;
-
-    printf("Item order request\n");
     fflush(stdout);
-    send_itemorder(type, itemno, filename);
+    send_itemorder(type, itemno, xml_buf, xml_len);
     return 2;
 }