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