1/*
2 * aolstub.cpp --
3 *
4 * Adds interface for loading the extension into the AOLserver.
5 *
6 * See the file "LICENSE" for information on usage and redistribution
7 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
8 *
9 * Rcsid: @(#)$Id: aolstub.cpp,v 1.7 2007/08/10 22:46:45 rolf Exp $
10 * ---------------------------------------------------------------------------
11 */
12
13#if defined (NS_AOLSERVER)
14#include <ns.h>
15
16int Ns_ModuleVersion = 1;
17
18/*
19 * Structure to pass to NsThread_Init. This holds the module
20 * and virtual server name for proper interp initializations.
21 * This is valid only for AOLservers 4.x or later.
22 */
23
24struct mydata {
25    char *modname;
26    char *server;
27};
28
29/*
30 *----------------------------------------------------------------------------
31 *
32 * NsTdom_Init --
33 *
34 *    Loads the package in the Tcl interpreter.
35 *
36 * Results:
37 *    Standard Tcl result
38 *
39 * Side effects:
40 *    Package initialized. Tcl commands created.
41 *
42 *----------------------------------------------------------------------------
43 */
44
45static int
46NsTdom_Init (Tcl_Interp *interp, void *cd)
47{
48    struct mydata *md = (struct mydata*)cd;
49    int ret = Tdom_Init(interp);
50
51    if (ret != TCL_OK) {
52        Ns_Log(Warning, "can't load module %s: %s", md->modname,
53               Tcl_GetStringResult(interp));
54    }
55    Tcl_SetAssocData(interp, "tdom:nsd", NULL, (ClientData)md);
56
57    return TCL_OK;
58}
59
60/*
61 *----------------------------------------------------------------------------
62 *
63 * Ns_ModuleInit --
64 *
65 *    Called by the AOLserver when loading shared object file.
66 *
67 * Results:
68 *    Standard AOLserver result
69 *
70 * Side effects:
71 *    Many. Depends on the package.
72 *
73 *----------------------------------------------------------------------------
74 */
75
76int
77Ns_ModuleInit(char *srv, char *mod)
78{
79    struct mydata *md = NULL;
80
81    md = (struct mydata*)ns_malloc(sizeof(struct mydata));
82    md->modname = strcpy(ns_malloc(strlen(mod)+1), mod);
83    md->server  = strcpy(ns_malloc(strlen(srv)+1), srv);
84
85    return (Ns_TclInitInterps(srv, NsTdom_Init, (void*)md) == TCL_OK)
86        ? NS_OK : NS_ERROR;
87}
88
89#endif /* NS_AOLSERVER */
90
91/* EOF $RCSfile: aolstub.cpp,v $ */
92
93/* Emacs Setup Variables */
94/* Local Variables:      */
95/* mode: C               */
96/* indent-tabs-mode: nil */
97/* c-basic-offset: 4     */
98/* End:                  */
99