]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-tcl/tcl_util.c
#include <ac/string.h> to get strcasecmp().
[openldap] / servers / slapd / back-tcl / tcl_util.c
index cdff332fc3d95a2a4fb41fc440674ed4acec9179..6fff035276788b91e66dc7d95a4be5e3b089c763 100644 (file)
@@ -1,6 +1,5 @@
+/* $OpenLDAP$ */
 /* result.c - tcl backend utility functions
- *
- * $Id: tcl_util.c,v 1.5 1999/02/28 04:55:49 bcollins Exp $
  *
  * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved.
  *
 
 int
 interp_send_results (
-       Backend * be,
-       Connection * conn,
        Operation * op,
-       char *result,
-       char **attrs,
-       int attrsonly
+       SlapReply * rs,
+       char *result
 )
 {
-       int bsize, len, argcPtr, i, err, code;
-       char *buf, *bp, **argvPtr, *line, *matched, *info;
-       Entry *e;
-       struct tclinfo *ti = (struct tclinfo *) be->be_private;
+       int bsize, len, argcPtr, i, code;
+       char *buf, *bp, **argvPtr, *line;
+       struct tclinfo *ti = (struct tclinfo *) op->o_bd->be_private;
 
        /*
         * read in the result and send it along 
@@ -46,8 +41,8 @@ interp_send_results (
        code = Tcl_SplitList (ti->ti_ii->interp, result, &argcPtr, &argvPtr);
        if (code != TCL_OK) {
                argcPtr = 0;
-               send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
-                       "internal backend error");
+               send_ldap_error (op, rs, LDAP_UNWILLING_TO_PERFORM,
+                       "internal backend error" );
                return -1;
        }
        for (i = 0; i < argcPtr; i++) {
@@ -74,32 +69,32 @@ interp_send_results (
                        if (strncasecmp (buf, "RESULT", 6) == 0) {
                                break;
                        }
-                       if ((e = str2entry (buf)) == NULL) {
+                       if ((rs->sr_entry = str2entry (buf)) == NULL) {
                                Debug (LDAP_DEBUG_SHELL,
                                        "str2entry(%s) failed\n",
                                        buf, 0, 0);
                        } else {
-                               send_search_entry (be, conn, op, e, attrs,
-                                       attrsonly, 0 );
-                               entry_free (e);
+                               rs->sr_attrs = op->oq_search.rs_attrs;
+                               send_search_entry (op, rs);
+                               entry_free (rs->sr_entry);
                        }
 
                        bp = buf;
                }
        }
 
-       (void) str2result (buf, &err, &matched, &info);
+       (void) str2result (buf, &rs->sr_err, (char **)&rs->sr_matched, (char **)&rs->sr_text);
 
        /*
         * otherwise, front end will send this result 
         */
-       if (err != 0 || op->o_tag != LDAP_REQ_BIND) {
-               send_ldap_result (conn, op, err, matched, info);
+       if (rs->sr_err != 0 || op->o_tag != LDAP_REQ_BIND) {
+               send_ldap_result (op, rs);
        }
 
        free (buf);
        Tcl_Free ((char *) argvPtr);
-       return (err);
+       return (rs->sr_err);
 }
 
 char *
@@ -110,9 +105,8 @@ tcl_clean_entry (
        char *entrystr, *mark1, *mark2, *buf, *bp, *dup;
        int len, bsize;
 
-       pthread_mutex_lock (&entry2str_mutex);
-       entrystr = entry2str (e, &len, 0);
-       pthread_mutex_unlock (&entry2str_mutex);
+       ldap_pvt_thread_mutex_lock(&entry2str_mutex);
+       entrystr = entry2str (e, &len);
 
        buf = (char *) ch_malloc (BUFSIZ);
        buf[0] = '\0';
@@ -147,6 +141,8 @@ tcl_clean_entry (
                }
                free (dup);
        } while ((mark1 = (char *) strchr (mark1, '\n')) != NULL);
+
+       ldap_pvt_thread_mutex_unlock (&entry2str_mutex);
        return buf;
 }
 
@@ -188,3 +184,48 @@ readtclscript (
                return;
        }
 }
+
+
+struct berval *
+tcl_merge_bvlist(
+       BerVarray bvlist, struct berval *out)
+{
+       struct berval *ret = NULL;
+       int i;
+
+       if (bvlist == NULL)
+               return NULL;
+
+       if (out == NULL) {
+               ret = (struct berval *)ch_malloc(sizeof(struct berval));
+               if (ret == NULL) {
+                       return NULL;
+               }
+       } else {
+               ret = out;
+       }
+
+       ret->bv_len = 0;
+       ret->bv_val = NULL;
+
+       for (i = 0; bvlist[i].bv_val != NULL; i++);
+
+       if (i) {
+               char **strlist = ch_malloc ((i + 1) * sizeof(char *));
+               if (strlist == NULL) {
+                       if (out == NULL)
+                               ch_free (ret);
+                       return NULL;
+               }
+               for (i = 0; bvlist[i].bv_val != NULL; i++) {
+                       strlist[i] = bvlist[i].bv_val;
+               }
+               strlist[i] = NULL;
+               ret->bv_val = Tcl_Merge(i, strlist);
+               ret->bv_len = ret->bv_val ? strlen(ret->bv_val) : 0;
+               ch_free (strlist);
+       }
+
+       return ret;
+}
+