1 /* result.c - tcl backend utility functions
3 * $Id: tcl_util.c,v 1.4 1999/02/19 06:55:20 bcollins Exp $
5 * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved.
7 * Redistribution and use in source and binary forms are permitted only
8 * as authorized by the OpenLDAP Public License. A copy of this
9 * license is available at http://www.OpenLDAP.org/license.html or
10 * in file LICENSE in the top-level directory of the distribution.
17 #include <ac/string.h>
18 #include <ac/socket.h>
19 #include <ac/unistd.h>
34 int bsize, len, argcPtr, i, err, code;
35 char *buf, *bp, **argvPtr, *line, *matched, *info;
37 struct tclinfo *ti = (struct tclinfo *) be->be_private;
40 * read in the result and send it along
42 buf = (char *) ch_malloc (BUFSIZ);
46 code = Tcl_SplitList (ti->ti_ii->interp, result, &argcPtr, &argvPtr);
49 send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
50 "internal backend error");
53 for (i = 0; i < argcPtr; i++) {
57 * ignore lines beginning with DEBUG:
59 if (strncasecmp (line, "DEBUG:", 6) == 0) {
62 len = strlen (line) + 1;
63 while (bp + len - buf > bsize) {
65 buf = (char *) ch_realloc (buf, bsize);
67 sprintf (bp, "%s\n", line);
71 * line marked the end of an entry or result
73 if (line[0] == '\0') {
74 if (strncasecmp (buf, "RESULT", 6) == 0) {
77 if ((e = str2entry (buf)) == NULL) {
78 Debug (LDAP_DEBUG_SHELL,
79 "str2entry(%s) failed\n",
82 send_search_entry (be, conn, op, e, attrs,
91 (void) str2result (buf, &err, &matched, &info);
94 * otherwise, front end will send this result
96 if (err != 0 || op->o_tag != LDAP_REQ_BIND) {
97 send_ldap_result (conn, op, err, matched, info);
101 Tcl_Free ((char *) argvPtr);
110 char *entrystr, *mark1, *mark2, *buf, *bp, *dup;
113 pthread_mutex_lock (&entry2str_mutex);
114 entrystr = entry2str (e, &len, 0);
115 pthread_mutex_unlock (&entry2str_mutex);
117 buf = (char *) ch_malloc (BUFSIZ);
125 if (mark1[0] == '\n') {
128 dup = (char *) ch_strdup (mark1);
129 if (dup[0] != '\0') {
130 if ((mark2 = (char *) strchr (dup, '\n')) != NULL) {
133 len = strlen (dup) + 3;
134 while (bp + len - buf > bsize) {
136 buf = (char *) ch_realloc (buf, bsize);
138 if (mark1[0] == '\0') {
141 sprintf (bp, "{%s} ", dup);
149 } while ((mark1 = (char *) strchr (mark1, '\n')) != NULL);
155 ClientData clientData,
161 if (argv[1] != NULL) {
162 Debug (LDAP_DEBUG_SHELL, "tcl_debug: %s\n", argv[1], 0, 0);
175 f = fopen (script, "r");
177 Debug (LDAP_DEBUG_SHELL, "Could not open scriptpath %s\n", script,
182 code = Tcl_EvalFile (my_tcl, script);
183 if (code != TCL_OK) {
184 Debug (LDAP_DEBUG_SHELL, "%s: %s\n", script,
185 Tcl_GetVar (my_tcl, "errorInfo", TCL_GLOBAL_ONLY), 0);
186 Debug (LDAP_DEBUG_SHELL, "%s: error at line\n", script,
187 my_tcl->errorLine, 0);