Jumbo patch: Incorporate extraArgs in memcached key YAZ-747
[yaz-moved-to-github.git] / zoom / zoomtst4.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5
6 #include <stdio.h>
7 #include <string.h>
8 #include <yaz/xmalloc.h>
9
10 #include <yaz/zoom.h>
11
12 const char *my_callback (void *handle, const char *name)
13 {
14     if (!strcmp (name, "async"))
15         return "1";
16     return 0;
17 }
18
19 int main(int argc, char **argv)
20 {
21     int i;
22     int no = argc-3;
23     ZOOM_connection z[500]; /* allow at most 500 connections */
24     ZOOM_resultset r[500];  /* and result sets .. */
25     ZOOM_query q;
26     ZOOM_options o = ZOOM_options_create ();
27
28     if (argc < 4)
29     {
30         fprintf (stderr, "usage:\n%s proxy target1 .. targetN query\n",
31                  *argv);
32         exit (2);
33     }
34     if (no > 500)
35         no = 500;
36
37     /* function my_callback called when reading options .. */
38     ZOOM_options_set_callback (o, my_callback, 0);
39
40     /* get 20 (at most) records from offset 5 */
41     ZOOM_options_set (o, "start", "5");
42     ZOOM_options_set (o, "count", "20");
43     ZOOM_options_set (o, "schema", "gils-schema");
44     ZOOM_options_set (o, "elementSetName", "F");
45
46     /* set proxy */
47     ZOOM_options_set (o, "proxy", argv[1]);
48
49     /* create query */
50     q = ZOOM_query_create ();
51     if (ZOOM_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] = ZOOM_connection_create (o);
60         ZOOM_connection_connect (z[i], argv[i+2], 0);
61         r[i] = ZOOM_connection_search (z[i], q);
62     }
63
64     /* network I/O */
65     while (ZOOM_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 = ZOOM_connection_error(z[i], &errmsg, &addinfo)))
74             fprintf (stderr, "%s error: %s (%d) %s\n",
75                      ZOOM_connection_option_get(z[i], "host"),
76                      errmsg, error, addinfo);
77         else
78             printf ("%s: %ld hits\n", ZOOM_connection_option_get(z[i], "host"),
79                     (long) ZOOM_resultset_size(r[i]));
80     }
81
82     /* destroy stuff and exit */
83     ZOOM_query_destroy (q);
84     for (i = 0; i<no; i++)
85     {
86         ZOOM_resultset_destroy (r[i]);
87         ZOOM_connection_destroy (z[i]);
88     }
89     ZOOM_options_destroy(o);
90     exit (0);
91 }
92 /*
93  * Local variables:
94  * c-basic-offset: 4
95  * c-file-style: "Stroustrup"
96  * indent-tabs-mode: nil
97  * End:
98  * vim: shiftwidth=4 tabstop=8 expandtab
99  */
100