]> git.sur5r.net Git - openldap/blob - servers/slapd/back-tcl/tcl_close.c
7f9726f684e23a11abffd5a2302efd40786d5059
[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: tcl_close.c,v 1.2 1999/02/17 00:55:03 bcollins Exp $
12  *
13  * $Log: tcl_close.c,v $
14  * Revision 1.2  1999/02/17 00:55:03  bcollins
15  * Implemented all of the (db_)destroy and (db_)close functions
16  *
17  */
18
19 #include "portable.h"
20
21 #include <stdio.h>
22
23 #include "slap.h"
24 #include "tcl_back.h"
25
26 int
27 tcl_back_close (
28         BackendInfo * bi
29 )
30 {
31         Tcl_DeleteInterp(global_i->interp);
32
33         return( 0 );
34 }
35
36 int
37 tcl_back_destroy(
38                 BackendInfo *bi
39 )
40 {
41         Tcl_Free(global_i->interp);
42         free(global_i);
43         ldap_pvt_thread_mutex_destroy( &tcl_interpreter_mutex );
44
45         return( 0 );
46 }
47
48 int
49 tcl_back_db_close(
50                 BackendDB *bd
51 )
52 {
53         struct tclinfo *ti = (struct tclinfo *) bd->be_private;
54         struct i_info *ti_tmp;
55
56         /* Disable the interp and associated struct */
57         ti->ti_ii->count--;
58         if (!ti->ti_ii->count && strcasecmp("default", ti->ti_ii->name)) {
59                 /* no more db's using this and it's not the default */
60                 for(ti_tmp = global_i; ti_tmp->next != ti->ti_ii; ti_tmp = ti_tmp->next)
61                         ;
62                 /* This bypasses this interp struct in the global hash */
63                 ti_tmp->next = ti->ti_ii->next;
64                 Tcl_DeleteInterp(ti->ti_ii->interp);
65         }
66         return( 0 );
67 }
68
69 int
70 tcl_back_db_destroy(
71                 BackendDB *bd
72 )
73 {
74         struct tclinfo *ti = (struct tclinfo *) bd->be_private;
75
76        /*
77         * Now free up the allocated memory used
78         */
79         ti->ti_ii->count--;
80         if (!ti->ti_ii->count && strcasecmp("default", ti->ti_ii->name)) {
81                 Tcl_Free(ti->ti_ii->interp);
82                 free(ti->ti_ii);
83                 free(ti);
84         }
85         free( bd->be_private );
86         bd->be_private = NULL;
87
88         return( 0 );
89 }