1 /* $Id: zoomtst9.c,v 1.4 2006-10-04 16:59:35 mike Exp $ */
4 \brief Extended Service Update
12 #include <yaz/xmalloc.h>
15 static void usage(void)
17 fprintf(stderr, "usage:\n"
18 "zoomtst9 target [insert|delete|replace|update] id1 rec1 "
21 fprintf(stderr, "\nThis program illustrates the usage of"
22 " extended services Update from ZOOM.\n");
23 fprintf(stderr, "\nid "
24 "is optional opaque record Id and is omitted if empty.\n");
25 fprintf(stderr, "\nrec "
26 "is optional record data and is omitted if empty.\n");
30 int main(int argc, char **argv)
33 ZOOM_options o = ZOOM_options_create ();
35 const char *errmsg, *addinfo;
40 z = ZOOM_connection_create (o);
42 /* connect and init */
43 ZOOM_connection_connect (z, argv[1], 0);
45 if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
47 fprintf(stderr, "%s error: %s (%d) %s\n",
48 ZOOM_connection_option_get(z, "host"),
49 errmsg, error, addinfo);
53 ZOOM_package pkg = ZOOM_connection_package(z, 0);
54 const char *cmd = argv[2];
57 if (!strcmp(cmd, "insert"))
58 ZOOM_package_option_set(pkg, "action", "recordInsert");
59 else if (!strcmp(cmd, "update"))
60 ZOOM_package_option_set(pkg, "action", "specialUpdate");
61 else if (!strcmp(cmd, "replace"))
62 ZOOM_package_option_set(pkg, "action", "recordReplace");
63 else if (!strcmp(cmd, "delete"))
64 ZOOM_package_option_set(pkg, "action", "recordDelete");
67 fprintf(stderr, "Bad action %s\n", cmd);
74 ZOOM_package_option_set(pkg, "recordIdOpaque",
75 argv[i][0] ? argv[i] : 0);
77 if (!strcmp(argv[i], "-"))
79 /* For -, read record buffer from stdin */
80 WRBUF w = wrbuf_alloc();
82 while ((ch = getchar()) != EOF)
85 ZOOM_package_option_set(pkg, "record", wrbuf_buf(w));
89 ZOOM_package_option_set(pkg, "record",
90 argv[i][0] ? argv[i] : 0);
93 ZOOM_package_send(pkg, "update"); /* Update EXT service */
95 if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
97 fprintf(stderr, "%s error: %s (%d) %s\n",
98 ZOOM_connection_option_get(z, "host"),
99 errmsg, error, addinfo);
103 ZOOM_connection_destroy (z);
104 ZOOM_options_destroy(o);
110 * indent-tabs-mode: nil
112 * vim: shiftwidth=4 tabstop=8 expandtab