File: srwtst.c

package info (click to toggle)
yaz 5.27.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 16,184 kB
  • sloc: xml: 123,414; ansic: 72,530; sh: 5,007; tcl: 2,169; makefile: 1,321; yacc: 382
file content (108 lines) | stat: -rw-r--r-- 2,859 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* This file is part of the YAZ toolkit.
 * Copyright (C) Index Data
 * See the file LICENSE for details.
 */
#if HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdlib.h>
#include <yaz/srw.h>

#if YAZ_HAVE_XML2
Z_SOAP_Handler h[2] = {
    {"http://www.loc.gov/zing/srw/v1.0/", 0, (Z_SOAP_fun) yaz_srw_codec},
    {0, 0, 0}
};

int main(int argc, char **argv)
{
    char buf[163840];
    char *content_buf = buf;
    int content_len;
    size_t no;
    Z_SOAP *soap_package = 0;
    ODR decode, encode;
    int debug = 0;

    if (argc == 2 && !strcmp(argv[1], "debug"))
        debug = 1;
    no = fread(buf, 1, sizeof(buf), stdin);
    if (no < 1 || no == sizeof(buf))
    {
        fprintf(stderr, "Bad file or too big\n");
        exit (1);
    }
    decode = odr_createmem(ODR_DECODE);
    encode = odr_createmem(ODR_ENCODE);
    content_len = no;
    z_soap_codec(decode, &soap_package,
                 &content_buf, &content_len, h);
    if (!soap_package)
    {
        fprintf(stderr, "Decoding seriously failed\n");
        exit(1);
    }
    if (debug)
    {
        fprintf(stderr, "got NS = %s\n", soap_package->ns);
        if (soap_package->which == Z_SOAP_generic &&
            soap_package->u.generic->no == 0)
        {
            Z_SRW_PDU *sr = (Z_SRW_PDU *) soap_package->u.generic->p;
            if (sr->which == Z_SRW_searchRetrieve_request)
            {
                Z_SRW_searchRetrieveRequest *req = sr->u.request;
                fprintf(stderr, "%s: %s\n", req->queryType, req->query);
            }
            else if (sr->which == Z_SRW_searchRetrieve_response)
            {
                Z_SRW_searchRetrieveResponse *res = sr->u.response;
                if (res->records && res->num_records)
                {
                    int i;
                    for (i = 0; i<res->num_records; i++)
                    {
                        fprintf (stderr, "%d\n", i);
                        if (res->records[i].recordData_buf)
                        {
                            fprintf(stderr, "%.*s",
                                    res->records[i].recordData_len,
                                    res->records[i].recordData_buf);
                        }
                    }
                }
            }

        }
    }
    z_soap_codec(encode, &soap_package, &content_buf, &content_len, h);
    if (content_buf && content_len)
    {
        printf("%.*s", content_len, content_buf);
    }
    else
    {
        fprintf(stderr, "No output!\n");
        exit(1);
    }
    odr_destroy(decode);
    odr_destroy(encode);
    exit(0);
}
#else
int main(int argc, char **argv)
{
    fprintf(stderr, "SOAP disabled\n");
    exit(1);
}
#endif
/*
 * Local variables:
 * c-basic-offset: 4
 * c-file-style: "Stroustrup"
 * indent-tabs-mode: nil
 * End:
 * vim: shiftwidth=4 tabstop=8 expandtab
 */