2 * result.c - tcl backend utility functions
4 * Copyright 1999, Ben Collins <bcollins@debian.org>, All rights reserved.
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.
16 #include <ac/string.h>
17 #include <ac/socket.h>
18 #include <ac/unistd.h>
33 int bsize, len, argcPtr, i, err, code;
34 char *buf, *bp, **argvPtr, *line, *matched, *info;
36 struct tclinfo *ti = (struct tclinfo *) be->be_private;
37 /* read in the result and send it along */
38 buf = (char *) ch_malloc( BUFSIZ );
42 code = Tcl_SplitList(ti->ti_ii->interp, result, &argcPtr, &argvPtr);
45 send_ldap_result (conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
46 "internal backend error");
49 for ( i = 0 ; i < argcPtr ; i++ ) {
51 Debug( LDAP_DEBUG_ANY, "tcl search reading line (%s)\n",
53 /* ignore lines beginning with DEBUG: */
54 if ( strncasecmp( line, "DEBUG:", 6 ) == 0 ) {
57 len = strlen( line ) + 1;
58 while ( bp + len - buf > bsize ) {
60 buf = (char *) ch_realloc( buf, bsize );
62 sprintf( bp, "%s\n", line );
65 /* line marked the end of an entry or result */
66 if ( line[0] == '\0' ) {
67 if ( strncasecmp( buf, "RESULT", 6 ) == 0 ) {
70 if ( (e = str2entry( buf )) == NULL ) {
71 Debug( LDAP_DEBUG_ANY, "str2entry(%s) failed\n",
74 send_search_entry( be, conn, op, e, attrs,
83 (void) str2result( buf, &err, &matched, &info );
85 /* otherwise, front end will send this result */
86 if ( err != 0 || op->o_tag != LDAP_REQ_BIND ) {
87 send_ldap_result( conn, op, err, matched, info );
92 Tcl_Free( (char *) argvPtr );
96 char *tcl_clean_entry (Entry *e)
98 char *entrystr, *mark1, *mark2, *buf, *bp, *dup;
101 pthread_mutex_lock( &entry2str_mutex );
102 entrystr = entry2str( e, &len, 0 );
103 pthread_mutex_unlock( &entry2str_mutex );
105 buf = (char *) ch_malloc( BUFSIZ );
113 if (mark1[0] == '\n') {
116 dup = (char *) strdup(mark1);
117 if (dup[0] != '\0') {
118 if ((mark2 = (char *) strchr (dup, '\n')) != NULL) {
121 len = strlen( dup ) + 3;
122 while ( bp + len - buf > bsize ) {
124 buf = (char *) ch_realloc( buf, bsize );
126 if (mark1[0] == '\0') {
129 sprintf(bp, "{%s} ", dup);
137 } while ((mark1 = (char *) strchr (mark1, '\n')) != NULL);
142 ClientData clientData,
148 if (argv[1] != NULL) {
149 Debug(LDAP_DEBUG_ANY, "tcl_debug: %s\n", argv[1], 0, 0);