More type casts. Modify CQL tree - bool is C++ reserved name.
[yaz-moved-to-github.git] / zutil / srwtst.c
1 /*
2  * Copyright (c) 2002-2003, Index Data.
3  * See the file LICENSE for details.
4  *
5  * $Id: srwtst.c,v 1.1 2003-02-14 18:49:24 adam Exp $
6  */
7
8 #include <yaz/srw.h>
9
10 #if HAVE_XSLT
11 Z_SOAP_Handler h[2] = {
12     {"http://www.loc.gov/zing/srw/v1.0/", 0, (Z_SOAP_fun) yaz_srw_codec},
13     {0, 0, 0}
14 };
15
16 int main(int argc, char **argv)
17 {
18     char buf[163840];
19     char *content_buf = buf;
20     int content_len;
21     int ret;
22     size_t no;
23     Z_SOAP *soap_package = 0;
24     ODR decode, encode;
25     int debug = 0;
26
27     if (argc == 2 && !strcmp(argv[1], "debug"))
28         debug = 1;
29     no = fread(buf, 1, sizeof(buf), stdin);
30     if (no < 1 || no == sizeof(buf))
31     {
32         fprintf(stderr, "Bad file or too big\n");
33         exit (1);
34     }
35     decode = odr_createmem(ODR_DECODE);
36     encode = odr_createmem(ODR_ENCODE);
37     content_len = no;
38     ret = z_soap_codec(decode, &soap_package, 
39                        &content_buf, &content_len, h);
40     if (!soap_package)
41     {
42         fprintf(stderr, "Decoding seriously failed\n");
43         exit(1);
44     }
45     if (debug)
46     {
47         fprintf(stderr, "got NS = %s\n", soap_package->ns);
48         if (soap_package->which == Z_SOAP_generic &&
49             soap_package->u.generic->no == 0)
50         {
51             Z_SRW_searchRetrieve *sr = soap_package->u.generic->p;
52             if (sr->which == Z_SRW_searchRetrieve_request)
53             { 
54                 Z_SRW_searchRetrieveRequest *req = sr->u.request;
55             }
56             else if (sr->which == Z_SRW_searchRetrieve_response)
57             {
58                 Z_SRW_searchRetrieveResponse *res = sr->u.response;
59                 if (res->records && res->num_records)
60                 {
61                     int i;
62                     for (i = 0; i<res->num_records; i++)
63                     {
64                         fprintf (stderr, "%d\n", i);
65                         if (res->records[i].recordData_buf)
66                             fwrite(res->records[i].recordData_buf, 1,
67                                    res->records[i].recordData_len, stderr);
68                     }
69                 }
70             }
71
72         }
73     }
74     ret = z_soap_codec(encode, &soap_package,
75                        &content_buf, &content_len, h);
76     if (content_buf && content_len)
77         fwrite (content_buf, content_len, 1, stdout);
78     else
79     {
80         fprintf(stderr, "No output!\n");
81         exit(1);
82     }
83     exit(0);
84 }
85 #else
86 int main(int argc, char **argv)
87 {
88     fprintf(stderr, "SOAP disabled\n");
89     exit(1);
90 }
91 #endif