1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data
3 * See the file LICENSE for details.
11 #include <yaz/xmalloc.h>
14 static void usage(void)
16 fprintf(stderr, "usage:\n"
17 "zoomtst9 target [insert|delete|replace|update] id1 rec1 "
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");
29 int main(int argc, char **argv)
32 ZOOM_options o = ZOOM_options_create ();
34 const char *errmsg, *addinfo;
39 z = ZOOM_connection_create (o);
41 /* connect and init */
42 ZOOM_connection_connect (z, argv[1], 0);
44 if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
46 fprintf(stderr, "%s error: %s (%d) %s\n",
47 ZOOM_connection_option_get(z, "host"),
48 errmsg, error, addinfo);
52 ZOOM_package pkg = ZOOM_connection_package(z, 0);
53 const char *cmd = argv[2];
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");
66 fprintf(stderr, "Bad action %s\n", cmd);
73 ZOOM_package_option_set(pkg, "recordIdOpaque",
74 argv[i][0] ? argv[i] : 0);
76 if (!strcmp(argv[i], "-"))
78 /* For -, read record buffer from stdin */
79 WRBUF w = wrbuf_alloc();
81 while ((ch = getchar()) != EOF)
84 ZOOM_package_option_set(pkg, "record", wrbuf_buf(w));
88 ZOOM_package_option_set(pkg, "record",
89 argv[i][0] ? argv[i] : 0);
92 ZOOM_package_send(pkg, "update"); /* Update EXT service */
94 if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
96 fprintf(stderr, "%s error: %s (%d) %s\n",
97 ZOOM_connection_option_get(z, "host"),
98 errmsg, error, addinfo);
102 ZOOM_connection_destroy (z);
103 ZOOM_options_destroy(o);
109 * indent-tabs-mode: nil
111 * vim: shiftwidth=4 tabstop=8 expandtab