2 * Copyright (c) 1995, the EUROPAGATE consortium (see below).
4 * The EUROPAGATE consortium members are:
6 * University College Dublin
7 * Danmarks Teknologiske Videnscenter
8 * An Chomhairle Leabharlanna
9 * Consejo Superior de Investigaciones Cientificas
11 * Permission to use, copy, modify, distribute, and sell this software and
12 * its documentation, in whole or in part, for any purpose, is hereby granted,
15 * 1. This copyright and permission notice appear in all copies of the
16 * software and its documentation. Notices of copyright or attribution
17 * which appear at the beginning of any file must remain unchanged.
19 * 2. The names of EUROPAGATE or the project partners may not be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
23 * 3. Users of this software (implementors and gateway operators) agree to
24 * inform the EUROPAGATE consortium of their use of the software. This
25 * information will be used to evaluate the EUROPAGATE project and the
26 * software, and to plan further developments. The consortium may use
27 * the information in later publications.
29 * 4. Users of this software agree to make their best efforts, when
30 * documenting their use of the software, to acknowledge the EUROPAGATE
31 * consortium, and the role played by the software in their work.
33 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
34 * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
35 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
36 * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE
37 * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF
38 * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
39 * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND
40 * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
41 * USE OR PERFORMANCE OF THIS SOFTWARE.
44 * Revision 1.1 1995/10/27 15:12:08 adam
45 * IrTcl incorporated in the gateway.
46 * Better separation of script types.
47 * Z39.50 gateway scripts entered.
55 #include <sys/types.h>
57 #include <sys/select.h>
66 static void *do_create (WCLIENT wcl, void *args);
67 static int do_exec (const char *fname, char *parms, void *mydata);
69 static struct w_interp_type w_interp_t = {
75 W_Interp_Type w_interp_irtcl = &w_interp_t;
78 static char *mod = "wirtcl";
86 static void *do_create (WCLIENT wcl, void *args)
90 if (!(p = malloc (sizeof(*p))))
92 gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, mod, "malloc: irtcl_info");
95 if (!(p->w_interp = w_interp_create (w_interp_tcl, wcl, NULL)))
97 gw_log (GW_LOG_FATAL, mod, "Cannot make Tcl_Interp");
101 p->interp = w_interp_tcl_get (p->w_interp);
102 if (Irtcl_Init(p->interp) == TCL_ERROR)
104 gw_log (GW_LOG_FATAL, mod, "Cannot make Irtcl_Interp");
107 /* initialize irtcl */
111 /* select(2) callbacks */
113 void (*r_handle)(ClientData);
114 void (*w_handle)(ClientData);
115 void (*x_handle)(ClientData);
118 #define MAX_CALLBACK 200
120 static struct callback callback_table[MAX_CALLBACK];
121 static int max_fd = 3; /* don't worry: it will grow... */
123 static int do_exec (const char *fname, char *parms, void *mydata)
125 struct tcl_info *p = mydata;
126 int i, r, min_fd = 0;
128 static fd_set fdset_tcl_r;
129 static fd_set fdset_tcl_w;
130 static fd_set fdset_tcl_x;
132 for (i=0; i<MAX_CALLBACK; i++)
134 callback_table[i].r_handle = NULL;
135 callback_table[i].w_handle = NULL;
136 callback_table[i].x_handle = NULL;
138 if ((r = w_interp_exec (p->w_interp, fname, parms)))
142 FD_ZERO (&fdset_tcl_r);
143 FD_ZERO (&fdset_tcl_w);
144 FD_ZERO (&fdset_tcl_x);
145 for (r=0, i=min_fd; i<=max_fd; i++)
147 if (callback_table[i].w_handle)
149 FD_SET (i, &fdset_tcl_w);
152 if (callback_table[i].r_handle)
154 FD_SET (i, &fdset_tcl_r);
157 if (callback_table[i].x_handle)
159 FD_SET (i, &fdset_tcl_x);
165 if ((r = select(max_fd+1, &fdset_tcl_r, &fdset_tcl_w,
166 &fdset_tcl_x, 0)) < 0)
173 for (i=min_fd; i<=max_fd; i++)
175 if (FD_ISSET (i, &fdset_tcl_r))
177 assert (callback_table[i].r_handle);
178 (*callback_table[i].r_handle) (callback_table[i].obj);
180 if (FD_ISSET (i, &fdset_tcl_w))
182 assert (callback_table[i].w_handle);
183 (*callback_table[i].w_handle) (callback_table[i].obj);
185 if (FD_ISSET (i, &fdset_tcl_x))
187 assert (callback_table[i].x_handle);
188 (*callback_table[i].x_handle) (callback_table[i].obj);
191 if ((cp=Tcl_GetVar (p->interp, "sessionWait", 0)) && !strcmp (cp, "0"))
197 void ir_select_add (int fd, void *obj)
199 callback_table[fd].obj = obj;
200 callback_table[fd].r_handle = ir_select_read;
201 callback_table[fd].w_handle = NULL;
202 callback_table[fd].x_handle = NULL;
207 void ir_select_add_write (int fd, void *obj)
209 callback_table[fd].w_handle = ir_select_write;
214 void ir_select_remove_write (int fd, void *obj)
216 callback_table[fd].w_handle = NULL;
219 void ir_select_remove (int fd, void *obj)
221 callback_table[fd].r_handle = NULL;
222 callback_table[fd].w_handle = NULL;
223 callback_table[fd].x_handle = NULL;