Added several type casts due to no portable way of doing printf of
[yaz-moved-to-github.git] / zoom / zoomtst9.c
1 /* $Id: zoomtst9.c,v 1.2 2006-04-21 10:28:08 adam Exp $  */
2
3 /** \file zoomtst9.c
4     \brief Extended Service Update
5 */
6
7 #include <stdio.h>
8 #include <string.h>
9
10 #include <yaz/nmem.h>
11 #include <yaz/xmalloc.h>
12 #include <yaz/zoom.h>
13
14 static void usage()
15 {
16     fprintf(stderr, "usage:\n"
17             "zoomtst9 target [insert|delete|replace|update] id1 rec1 "
18             "id2 rec2 ..\n");
19
20     fprintf(stderr, "\nThis program illustrates the usage of"
21             " extended services Update from ZOOM.\n");
22     fprintf(stderr, "\nid "
23             "is optional opaque record Id and is omitted if empty.\n");
24     fprintf(stderr, "\nrec "
25             "is optional record data and is omitted if empty.\n");
26     exit (1);
27 }
28
29 int main(int argc, char **argv)
30 {
31     ZOOM_connection z;
32     ZOOM_options o = ZOOM_options_create ();
33     int error;
34     const char *errmsg, *addinfo;
35     
36     if (argc < 3)
37         usage();
38
39     z = ZOOM_connection_create (o);
40     
41     /* connect and init */
42     ZOOM_connection_connect (z, argv[1], 0);
43     
44     if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
45     {
46         fprintf(stderr, "%s error: %s (%d) %s\n",
47                 ZOOM_connection_option_get(z, "host"),
48                 errmsg, error, addinfo);
49     }
50     else
51     {
52         ZOOM_package pkg = ZOOM_connection_package(z, 0);
53         const char *cmd = argv[2];
54         int i;
55
56         if (!strcmp(cmd, "insert"))
57             ZOOM_package_option_set(pkg, "action", "recordInsert");
58         else if (!strcmp(cmd, "update"))
59             ZOOM_package_option_set(pkg, "action", "specialUpdate");
60         else if (!strcmp(cmd, "replace"))
61             ZOOM_package_option_set(pkg, "action", "recordReplace");
62         else if (!strcmp(cmd, "delete"))
63             ZOOM_package_option_set(pkg, "action", "recordDelete");
64         else
65         {
66             fprintf(stderr, "Bad action %s\n", cmd);
67             usage();
68         }
69
70         i = 3;
71         while (i < argc-1)
72         {
73             ZOOM_package_option_set(pkg, "recordIdOpaque",
74                                     argv[i][0] ? argv[i] : 0);
75             i++;
76             ZOOM_package_option_set(pkg, "record",
77                                     argv[i][0] ? argv[i] : 0);
78             i++;
79             ZOOM_package_send(pkg, "update"); /* Update EXT service */
80
81             if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
82             {
83                 fprintf(stderr, "%s error: %s (%d) %s\n",
84                         ZOOM_connection_option_get(z, "host"),
85                         errmsg, error, addinfo);
86             }
87         }
88     }
89     ZOOM_connection_destroy (z);
90     ZOOM_options_destroy(o);
91     exit (0);
92 }
93 /*
94  * Local variables:
95  * c-basic-offset: 4
96  * indent-tabs-mode: nil
97  * End:
98  * vim: shiftwidth=4 tabstop=8 expandtab
99  */
100