]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/result.c
Add copyright notices
[openldap] / servers / slapd / back-shell / result.c
1 /* result.c - shell backend result reading function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/string.h>
13 #include <ac/socket.h>
14 #include <ac/unistd.h>
15
16 #include "slap.h"
17 #include "shell.h"
18
19 int
20 read_and_send_results(
21     Backend     *be,
22     Connection  *conn,
23     Operation   *op,
24     FILE        *fp,
25     char        **attrs,
26     int         attrsonly
27 )
28 {
29         int     bsize, len;
30         char    *buf, *bp;
31         char    line[BUFSIZ];
32         Entry   *e;
33         int     err;
34         char    *matched, *info;
35
36         /* read in the result and send it along */
37         buf = (char *) ch_malloc( BUFSIZ );
38         buf[0] = '\0';
39         bsize = BUFSIZ;
40         bp = buf;
41         while ( fgets( line, sizeof(line), fp ) != NULL ) {
42                 Debug( LDAP_DEBUG_SHELL, "shell search reading line (%s)\n",
43                     line, 0, 0 );
44                 /* ignore lines beginning with DEBUG: */
45                 if ( strncasecmp( line, "DEBUG:", 6 ) == 0 ) {
46                         continue;
47                 }
48                 len = strlen( line );
49                 while ( bp + len - buf > bsize ) {
50                         size_t offset = bp - buf;
51                         bsize += BUFSIZ;
52                         buf = (char *) ch_realloc( buf, bsize );
53                         bp = &buf[offset];
54                 }
55                 strcpy( bp, line );
56                 bp += len;
57
58                 /* line marked the end of an entry or result */
59                 if ( *line == '\n' ) {
60                         if ( strncasecmp( buf, "RESULT", 6 ) == 0 ) {
61                                 break;
62                         }
63
64                         if ( (e = str2entry( buf )) == NULL ) {
65                                 Debug( LDAP_DEBUG_ANY, "str2entry(%s) failed\n",
66                                     buf, 0, 0 );
67                         } else {
68                                 send_search_entry( be, conn, op, e, attrs,
69                                     attrsonly, NULL );
70                                 entry_free( e );
71                         }
72
73                         bp = buf;
74                 }
75         }
76         (void) str2result( buf, &err, &matched, &info );
77
78         /* otherwise, front end will send this result */
79         if ( err != 0 || op->o_tag != LDAP_REQ_BIND ) {
80                 send_ldap_result( conn, op, err, matched, info, NULL, NULL );
81         }
82
83         free( buf );
84
85         return( err );
86 }
87
88 void
89 print_suffixes(
90     FILE        *fp,
91     Backend     *be
92 )
93 {
94         int     i;
95
96         for ( i = 0; be->be_suffix[i] != NULL; i++ ) {
97                 fprintf( fp, "suffix: %s\n", be->be_suffix[i] );
98         }
99 }