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