1999-02-18 10:18:39 +08:00
|
|
|
/* tcl_init.c - tcl backend initialization
|
|
|
|
*
|
1999-07-05 14:26:26 +08:00
|
|
|
* $Id: tcl_init.c,v 1.8 1999/06/24 15:06:42 bastiaan Exp $
|
1999-02-15 03:20:14 +08:00
|
|
|
*
|
|
|
|
* Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted only
|
|
|
|
* as authorized by the OpenLDAP Public License. A copy of this
|
|
|
|
* license is available at http://www.OpenLDAP.org/license.html or
|
|
|
|
* in file LICENSE in the top-level directory of the distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "tcl_back.h"
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_t tcl_interpreter_mutex;
|
|
|
|
|
1999-06-25 01:06:34 +08:00
|
|
|
#ifdef SLAPD_TCL_DYNAMIC
|
|
|
|
#include <gmodule.h>
|
|
|
|
|
|
|
|
G_MODULE_EXPORT void init_module(int argc, char *argv[]) {
|
|
|
|
BackendInfo bi;
|
|
|
|
|
|
|
|
bi.bi_type = "tcl";
|
|
|
|
bi.bi_init = tcl_back_initialize;
|
|
|
|
|
|
|
|
backend_add(&bi);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SLAPD_TCL_DYNAMIC */
|
|
|
|
|
1999-02-15 03:20:14 +08:00
|
|
|
int
|
1999-02-18 10:18:39 +08:00
|
|
|
tcl_back_initialize (
|
|
|
|
BackendInfo * bi
|
1999-02-15 03:20:14 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
/* Initialize the global interpreter array */
|
|
|
|
global_i = (struct i_info *) ch_malloc (sizeof (struct i_info));
|
1999-02-18 10:18:39 +08:00
|
|
|
|
1999-02-15 03:20:14 +08:00
|
|
|
global_i->count = 0;
|
|
|
|
global_i->name = "default";
|
|
|
|
global_i->next = NULL;
|
|
|
|
global_i->interp = Tcl_CreateInterp ();
|
|
|
|
Tcl_Init (global_i->interp);
|
|
|
|
|
|
|
|
/* Initialize the global interpreter lock */
|
1999-02-18 10:18:39 +08:00
|
|
|
ldap_pvt_thread_mutex_init (&tcl_interpreter_mutex);
|
1999-02-17 09:55:54 +08:00
|
|
|
|
|
|
|
bi->bi_open = tcl_back_open;
|
1999-03-04 01:02:10 +08:00
|
|
|
bi->bi_config = 0;
|
1999-02-17 09:55:54 +08:00
|
|
|
bi->bi_close = tcl_back_close;
|
|
|
|
bi->bi_destroy = tcl_back_destroy;
|
1999-02-15 03:20:14 +08:00
|
|
|
|
|
|
|
bi->bi_db_init = tcl_back_db_init;
|
|
|
|
bi->bi_db_config = tcl_back_db_config;
|
|
|
|
bi->bi_db_open = tcl_back_db_open;
|
1999-02-17 09:55:54 +08:00
|
|
|
bi->bi_db_close = tcl_back_db_close;
|
1999-02-15 03:20:14 +08:00
|
|
|
bi->bi_db_destroy = tcl_back_db_destroy;
|
|
|
|
|
|
|
|
bi->bi_op_bind = tcl_back_bind;
|
|
|
|
bi->bi_op_unbind = tcl_back_unbind;
|
|
|
|
bi->bi_op_search = tcl_back_search;
|
|
|
|
bi->bi_op_compare = tcl_back_compare;
|
|
|
|
bi->bi_op_modify = tcl_back_modify;
|
|
|
|
bi->bi_op_modrdn = tcl_back_modrdn;
|
|
|
|
bi->bi_op_add = tcl_back_add;
|
|
|
|
bi->bi_op_delete = tcl_back_delete;
|
|
|
|
bi->bi_op_abandon = tcl_back_abandon;
|
|
|
|
|
1999-03-04 01:02:10 +08:00
|
|
|
bi->bi_acl_group = 0;
|
1999-02-15 03:20:14 +08:00
|
|
|
|
1999-06-23 20:31:35 +08:00
|
|
|
bi->bi_connection_init = 0;
|
|
|
|
bi->bi_connection_destroy = 0;
|
|
|
|
|
1999-02-15 03:20:14 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-02-17 10:02:11 +08:00
|
|
|
int
|
1999-02-18 10:18:39 +08:00
|
|
|
tcl_back_open (
|
|
|
|
BackendInfo * bi
|
1999-02-17 10:02:11 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
/* Initialize the global interpreter array */
|
|
|
|
global_i = (struct i_info *) ch_malloc (sizeof (struct i_info));
|
1999-02-18 10:18:39 +08:00
|
|
|
|
1999-02-17 10:02:11 +08:00
|
|
|
global_i->count = 0;
|
|
|
|
global_i->name = "default";
|
|
|
|
global_i->next = NULL;
|
|
|
|
global_i->interp = Tcl_CreateInterp ();
|
|
|
|
Tcl_Init (global_i->interp);
|
|
|
|
|
|
|
|
/* Initialize the global interpreter lock */
|
1999-02-18 10:18:39 +08:00
|
|
|
ldap_pvt_thread_mutex_init (&tcl_interpreter_mutex);
|
1999-02-17 10:02:11 +08:00
|
|
|
|
1999-02-18 10:18:39 +08:00
|
|
|
return (0);
|
1999-02-17 10:02:11 +08:00
|
|
|
}
|
|
|
|
|
1999-02-15 03:20:14 +08:00
|
|
|
int
|
1999-02-18 10:18:39 +08:00
|
|
|
tcl_back_db_init (
|
|
|
|
Backend * be
|
1999-02-15 03:20:14 +08:00
|
|
|
)
|
|
|
|
{
|
1999-02-18 10:18:39 +08:00
|
|
|
struct tclinfo *ti;
|
1999-02-15 03:20:14 +08:00
|
|
|
|
1999-02-18 10:18:39 +08:00
|
|
|
ti = (struct tclinfo *) ch_calloc (1, sizeof (struct tclinfo));
|
1999-02-15 03:20:14 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For some reason this causes problems
|
|
|
|
* specifically set to NULL
|
|
|
|
*/
|
|
|
|
ti->ti_bind = NULL;
|
|
|
|
ti->ti_unbind = NULL;
|
|
|
|
ti->ti_search = NULL;
|
|
|
|
ti->ti_compare = NULL;
|
|
|
|
ti->ti_modify = NULL;
|
|
|
|
ti->ti_modrdn = NULL;
|
|
|
|
ti->ti_add = NULL;
|
|
|
|
ti->ti_delete = NULL;
|
|
|
|
ti->ti_abandon = NULL;
|
|
|
|
|
|
|
|
be->be_private = ti;
|
|
|
|
|
|
|
|
return ti == NULL;
|
|
|
|
}
|
|
|
|
|
1999-02-18 10:18:39 +08:00
|
|
|
int
|
|
|
|
tcl_back_db_open (
|
|
|
|
BackendDB * bd
|
1999-02-15 03:20:14 +08:00
|
|
|
)
|
|
|
|
{
|
1999-02-17 09:55:54 +08:00
|
|
|
struct tclinfo *ti = (struct tclinfo *) bd->be_private;
|
|
|
|
|
1999-02-18 10:18:39 +08:00
|
|
|
if (ti->ti_ii->interp == NULL) { /* we need to make a new one */
|
1999-02-17 09:55:54 +08:00
|
|
|
ti->ti_ii->interp = Tcl_CreateInterp ();
|
1999-02-18 10:18:39 +08:00
|
|
|
Tcl_Init (ti->ti_ii->interp);
|
1999-02-17 09:55:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* raise that count for the interpreter */
|
|
|
|
ti->ti_ii->count++;
|
|
|
|
|
|
|
|
/* now let's (try to) load the script */
|
|
|
|
readtclscript (ti->script_path, ti->ti_ii->interp);
|
|
|
|
|
|
|
|
/* Intall the debug command */
|
1999-02-18 10:18:39 +08:00
|
|
|
Tcl_CreateCommand (ti->ti_ii->interp, "ldap:debug", &tcl_ldap_debug,
|
1999-02-17 09:55:54 +08:00
|
|
|
NULL, NULL);
|
|
|
|
|
1999-02-15 03:20:14 +08:00
|
|
|
return 0;
|
|
|
|
}
|