]> git.sur5r.net Git - openldap/blob - servers/slapd/back-tcl/tcl_close.c
Implemented the open, init functions correctly
[openldap] / servers / slapd / back-tcl / tcl_close.c
1 /*
2  * close.c - tcl close routines
3  *
4  * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted only
7  * as authorized by the OpenLDAP Public License.  A copy of this
8  * license is available at http://www.OpenLDAP.org/license.html or
9  * in file LICENSE in the top-level directory of the distribution.
10  *
11  * $Id$
12  *
13  * $Log$
14  */
15
16 #include "portable.h"
17
18 #include <stdio.h>
19
20 #include "slap.h"
21 #include "tcl_back.h"
22
23 int
24 tcl_back_close (
25         BackendInfo * bi
26 )
27 {
28         Tcl_DeleteInterp(global_i->interp);
29         Tcl_Free(global_i->interp);
30         free(global_i);
31
32         return( 0 );
33 }
34
35 int
36 tcl_back_destroy(
37                 BackendInfo *bi
38 )
39 {
40         ldap_pvt_thread_mutex_destroy( &tcl_interpreter_mutex );
41
42         return( 0 );
43 }
44
45 int
46 tcl_back_db_close(
47                 BackendDB *bd
48 )
49 {
50         struct tclinfo *ti = (struct tclinfo *) bd->be_private;
51         struct i_info *ti_tmp;
52
53         /* Disable the interp and associated struct */
54         ti->ti_ii->count--;
55         if (!ti->ti_ii->count && strcasecmp("default", ti->ti_ii->name)) {
56                 /* no more db's using this and it's not the default */
57                 for(ti_tmp = global_i; ti_tmp->next != ti->ti_ii; ti_tmp = ti_tmp->next)
58                         ;
59                 /* This bypasses this interp struct in the global hash */
60                 ti_tmp->next = ti->ti_ii->next;
61                 Tcl_DeleteInterp(ti->ti_ii->interp);
62         }
63         return( 0 );
64 }
65
66 int
67 tcl_back_db_destroy(
68                 BackendDB *bd
69 )
70 {
71         struct tclinfo *ti = (struct tclinfo *) bd->be_private;
72
73        /*
74         * Now free up the allocated memory used
75         */
76         ti->ti_ii->count--;
77         if (!ti->ti_ii->count && strcasecmp("default", ti->ti_ii->name)) {
78                 Tcl_Free(ti->ti_ii->interp);
79                 free(ti->ti_ii);
80                 free(ti);
81         }
82         free( bd->be_private );
83         bd->be_private = NULL;
84
85         return( 0 );
86 }