File: zoomtst9.c

package info (click to toggle)
yaz 2.1.18-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 11,988 kB
  • ctags: 11,045
  • sloc: xml: 109,719; ansic: 41,566; sh: 10,625; makefile: 1,115; tcl: 380; yacc: 288
file content (100 lines) | stat: -rw-r--r-- 2,793 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* $Id: zoomtst9.c,v 1.2 2006/04/21 10:28:08 adam Exp $  */

/** \file zoomtst9.c
    \brief Extended Service Update
*/

#include <stdio.h>
#include <string.h>

#include <yaz/nmem.h>
#include <yaz/xmalloc.h>
#include <yaz/zoom.h>

static void usage()
{
    fprintf(stderr, "usage:\n"
            "zoomtst9 target [insert|delete|replace|update] id1 rec1 "
            "id2 rec2 ..\n");

    fprintf(stderr, "\nThis program illustrates the usage of"
            " extended services Update from ZOOM.\n");
    fprintf(stderr, "\nid "
            "is optional opaque record Id and is omitted if empty.\n");
    fprintf(stderr, "\nrec "
            "is optional record data and is omitted if empty.\n");
    exit (1);
}

int main(int argc, char **argv)
{
    ZOOM_connection z;
    ZOOM_options o = ZOOM_options_create ();
    int error;
    const char *errmsg, *addinfo;
    
    if (argc < 3)
        usage();

    z = ZOOM_connection_create (o);
    
    /* connect and init */
    ZOOM_connection_connect (z, argv[1], 0);
    
    if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
    {
        fprintf(stderr, "%s error: %s (%d) %s\n",
                ZOOM_connection_option_get(z, "host"),
                errmsg, error, addinfo);
    }
    else
    {
        ZOOM_package pkg = ZOOM_connection_package(z, 0);
        const char *cmd = argv[2];
        int i;

        if (!strcmp(cmd, "insert"))
            ZOOM_package_option_set(pkg, "action", "recordInsert");
        else if (!strcmp(cmd, "update"))
            ZOOM_package_option_set(pkg, "action", "specialUpdate");
        else if (!strcmp(cmd, "replace"))
            ZOOM_package_option_set(pkg, "action", "recordReplace");
        else if (!strcmp(cmd, "delete"))
            ZOOM_package_option_set(pkg, "action", "recordDelete");
        else
        {
            fprintf(stderr, "Bad action %s\n", cmd);
            usage();
        }

        i = 3;
        while (i < argc-1)
        {
            ZOOM_package_option_set(pkg, "recordIdOpaque",
                                    argv[i][0] ? argv[i] : 0);
            i++;
            ZOOM_package_option_set(pkg, "record",
                                    argv[i][0] ? argv[i] : 0);
            i++;
            ZOOM_package_send(pkg, "update"); /* Update EXT service */

            if ((error = ZOOM_connection_error(z, &errmsg, &addinfo)))
            {
                fprintf(stderr, "%s error: %s (%d) %s\n",
                        ZOOM_connection_option_get(z, "host"),
                        errmsg, error, addinfo);
            }
        }
    }
    ZOOM_connection_destroy (z);
    ZOOM_options_destroy(o);
    exit (0);
}
/*
 * Local variables:
 * c-basic-offset: 4
 * indent-tabs-mode: nil
 * End:
 * vim: shiftwidth=4 tabstop=8 expandtab
 */