1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 Index Data
3 * See the file LICENSE for details.
13 #include <yaz/proto.h>
19 static void *create_session(struct cs_session *ses)
21 struct my_info *my = xmalloc(sizeof(*my));
23 yaz_log(YLOG_LOG, "create_session");
27 static void gdu_handler(yaz_pkg_t pkg, void *user)
29 struct my_info *my = user;
30 Z_GDU **gdu = yaz_pkg_get_gdu(pkg);
31 ODR o = odr_createmem(ODR_PRINT);
33 yaz_log(YLOG_LOG, "gdu_handler");
34 YAZ_CHECK_EQ(my->x, 42);
39 if ((*gdu)->which == Z_GDU_Z3950)
41 ODR encode = odr_createmem(ODR_ENCODE);
42 Z_APDU *apdu_req = (*gdu)->u.z3950;
46 if (apdu_req->which == Z_APDU_close)
48 apdu_res = zget_APDU(encode, Z_APDU_close);
49 *apdu_res->u.close->closeReason = Z_Close_finished;
52 else if (apdu_req->which == Z_APDU_initRequest)
54 apdu_res = zget_APDU(encode, Z_APDU_initResponse);
58 apdu_res = zget_APDU(encode, Z_APDU_close);
60 *apdu_res->u.close->closeReason = Z_Close_unspecified;
65 yaz_pkg_t pkg_res = yaz_pkg_create(pkg);
66 *yaz_pkg_get_gdu(pkg) = zget_wrap_APDU(encode, apdu_res);
67 yaz_pkg_send(pkg_res);
71 yaz_pkg_stop_server(pkg);
75 static void tst_srv(void)
77 const char *listeners[] = {"unix:socket", 0};
79 yaz_srv_t srv = yaz_srv_create(listeners);
84 yaz_srv_run(srv, create_session, gdu_handler);
88 int main (int argc, char **argv)
90 YAZ_CHECK_INIT(argc, argv);
99 * c-file-style: "Stroustrup"
100 * indent-tabs-mode: nil
102 * vim: shiftwidth=4 tabstop=8 expandtab