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