Old Z39.50 codecs gone. Added ZOOM. WRBUF MARC display util.
[yaz-moved-to-github.git] / zoom / zoomtst4.c
1 /*
2  * $Id: zoomtst4.c,v 1.1 2001-10-23 21:00:20 adam Exp $
3  *
4  * Asynchronous multi-target going through proxy doing search and retrieve
5  * using present.
6  */
7
8 #include <stdio.h>
9 #include <yaz/xmalloc.h>
10
11 #include <yaz/zoom.h>
12
13 const char *my_callback (void *handle, const char *name)
14 {
15     if (!strcmp (name, "async"))
16         return "1";
17     return 0;
18 }
19
20 int main(int argc, char **argv)
21 {
22     int i;
23     int no = argc-3;
24     Z3950_connection z[500]; /* allow at most 500 connections */
25     Z3950_resultset r[500];  /* and result sets .. */
26     Z3950_search s;
27     Z3950_options o = Z3950_options_create ();
28
29     if (argc < 4)
30     {
31         fprintf (stderr, "usage:\n%s proxy target1 .. targetN query\n",
32                  *argv);
33         exit (2);
34     }
35     if (no > 500)
36         no = 500;
37
38     /* function my_callback called when reading options .. */
39     Z3950_options_set_callback (o, my_callback, 0);
40
41     /* get 20 (at most) records from offset 5 */
42     Z3950_options_set (o, "start", "5");
43     Z3950_options_set (o, "count", "20");
44
45     /* set proxy */
46     Z3950_options_set (o, "proxy", argv[1]);
47     
48     /* create query */
49     s = Z3950_search_create ();
50     if (Z3950_search_prefix (s, argv[argc-1]))
51     {
52         printf ("bad PQF: %s\n", argv[argc-1]);
53         exit (1);
54     }
55     /* connect - and search all */
56     for (i = 0; i<no; i++)
57     {
58         z[i] = Z3950_connection_create (o);
59         Z3950_connection_connect (z[i], argv[i+2], 0);
60         r[i] = Z3950_connection_search (z[i], s);
61     }
62
63     /* network I/O */
64     while (Z3950_event (no, z))
65         ;
66
67     /* handle errors */
68     for (i = 0; i<no; i++)
69     {
70         int error;
71         const char *errmsg, *addinfo;
72         if ((error = Z3950_connection_error(z[i], &errmsg, &addinfo)))
73             fprintf (stderr, "%s error: %s (%d) %s\n",
74                      Z3950_connection_host(z[i]), errmsg, error, addinfo);
75     }
76
77     /* destroy stuff and exit */
78     Z3950_search_destroy (s);
79     for (i = 0; i<no; i++)
80     {
81         Z3950_resultset_destroy (r[i]);
82         Z3950_connection_destroy (z[i]);
83     }
84     Z3950_options_destroy(o);
85     exit (0);
86 }