Added customisation of xml send in command itemorder xml 1 usage
authorJacob Poulsen <ja7@dbc.dk>
Mon, 17 Mar 2008 14:08:14 +0000 (15:08 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 18 Mar 2008 09:58:40 +0000 (10:58 +0100)
itemorder xml 1 "<xml></xml>"
or
itemorder xml 1 <xmlfile

client/client.c

index ee278ee..1c0a752 100644 (file)
@@ -2055,7 +2055,7 @@ static Z_External *create_external_ILL_APDU(int which)
 }
 
 
-static Z_External *create_ItemOrderExternal(const char *type, int itemno)
+static Z_External *create_ItemOrderExternal(const char *type, int itemno, const char* document_name)
 {
     Z_External *r = (Z_External *) odr_malloc(out, sizeof(Z_External));
     r->direct_reference = odr_oiddup(out, yaz_oid_extserv_item_order);
@@ -2106,14 +2106,29 @@ static Z_External *create_ItemOrderExternal(const char *type, int itemno)
     }
     else if (!strcmp(type, "xml") || !strcmp(type, "3"))
     {
-        const char *xml_buf =
-            "<itemorder>\n"
-            "  <type>request</type>\n"
-            "  <libraryNo>000200</libraryNo>\n"
-            "  <borrowerTicketNo> 1212 </borrowerTicketNo>\n"
-            "</itemorder>";
+        printf("xml found \n");
+                    
+        if( !document_name ) 
+        {
+            printf("no ducoument added \n");
+            r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
+            return r;
+        };
+
+        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 )
+        {
+            printf("Unable to read document\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, strlen(xml_buf));
+            z_ext_record_oid(out, yaz_oid_recsyn_xml, xml_buf, xml_len);
+            
     }
     else
         r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
@@ -2121,7 +2136,7 @@ static Z_External *create_ItemOrderExternal(const char *type, int itemno)
     return r;
 }
 
-static int send_itemorder(const char *type, int itemno)
+static int send_itemorder(const char *type, int itemno, const char* document_name)
 {
     Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest);
     Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
@@ -2131,7 +2146,7 @@ static int send_itemorder(const char *type, int itemno)
     req->packageType = odr_oiddup(out, yaz_oid_extserv_item_order);
     req->packageName = esPackageName;
 
-    req->taskSpecificParameters = create_ItemOrderExternal(type, itemno);
+    req->taskSpecificParameters = create_ItemOrderExternal(type, itemno, document_name);
 
     send_apdu(apdu);
     return 0;
@@ -2457,15 +2472,20 @@ static int cmd_itemorder(const char *arg)
 {
     char type[12];
     int itemno;
+    const char* filename = arg;
    
     if (only_z3950())
         return 1;
     if (sscanf (arg, "%10s %d", type, &itemno) != 2)
         return 0;
 
+
+    filename+=strlen(type) + 1; 
+    while( *filename && *filename !=' ' ) filename++;
+
     printf("Item order request\n");
     fflush(stdout);
-    send_itemorder(type, itemno);
+    send_itemorder(type, itemno, filename);
     return 2;
 }