search.c revision 1.1 1 1.1 lukem /* search.c - sock backend search function */
2 1.1 lukem /* $OpenLDAP: pkg/ldap/servers/slapd/back-sock/search.c,v 1.3.2.1 2008/02/09 00:46:09 quanah Exp $ */
3 1.1 lukem /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 1.1 lukem *
5 1.1 lukem * Copyright 2007-2008 The OpenLDAP Foundation.
6 1.1 lukem * All rights reserved.
7 1.1 lukem *
8 1.1 lukem * Redistribution and use in source and binary forms, with or without
9 1.1 lukem * modification, are permitted only as authorized by the OpenLDAP
10 1.1 lukem * Public License.
11 1.1 lukem *
12 1.1 lukem * A copy of this license is available in the file LICENSE in the
13 1.1 lukem * top-level directory of the distribution or, alternatively, at
14 1.1 lukem * <http://www.OpenLDAP.org/license.html>.
15 1.1 lukem */
16 1.1 lukem /* ACKNOWLEDGEMENTS:
17 1.1 lukem * This work was initially developed by Brian Candler for inclusion
18 1.1 lukem * in OpenLDAP Software.
19 1.1 lukem */
20 1.1 lukem
21 1.1 lukem #include "portable.h"
22 1.1 lukem
23 1.1 lukem #include <stdio.h>
24 1.1 lukem
25 1.1 lukem #include <ac/socket.h>
26 1.1 lukem #include <ac/string.h>
27 1.1 lukem
28 1.1 lukem #include "slap.h"
29 1.1 lukem #include "back-sock.h"
30 1.1 lukem
31 1.1 lukem /*
32 1.1 lukem * FIXME: add a filterSearchResults option like back-perl has
33 1.1 lukem */
34 1.1 lukem
35 1.1 lukem int
36 1.1 lukem sock_back_search(
37 1.1 lukem Operation *op,
38 1.1 lukem SlapReply *rs )
39 1.1 lukem {
40 1.1 lukem struct sockinfo *si = (struct sockinfo *) op->o_bd->be_private;
41 1.1 lukem FILE *fp;
42 1.1 lukem AttributeName *an;
43 1.1 lukem
44 1.1 lukem if ( (fp = opensock( si->si_sockpath )) == NULL ) {
45 1.1 lukem send_ldap_error( op, rs, LDAP_OTHER,
46 1.1 lukem "could not open socket" );
47 1.1 lukem return( -1 );
48 1.1 lukem }
49 1.1 lukem
50 1.1 lukem /* write out the request to the search process */
51 1.1 lukem fprintf( fp, "SEARCH\n" );
52 1.1 lukem fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
53 1.1 lukem sock_print_conn( fp, op->o_conn, si );
54 1.1 lukem sock_print_suffixes( fp, op->o_bd );
55 1.1 lukem fprintf( fp, "base: %s\n", op->o_req_dn.bv_val );
56 1.1 lukem fprintf( fp, "scope: %d\n", op->oq_search.rs_scope );
57 1.1 lukem fprintf( fp, "deref: %d\n", op->oq_search.rs_deref );
58 1.1 lukem fprintf( fp, "sizelimit: %d\n", op->oq_search.rs_slimit );
59 1.1 lukem fprintf( fp, "timelimit: %d\n", op->oq_search.rs_tlimit );
60 1.1 lukem fprintf( fp, "filter: %s\n", op->oq_search.rs_filterstr.bv_val );
61 1.1 lukem fprintf( fp, "attrsonly: %d\n", op->oq_search.rs_attrsonly ? 1 : 0 );
62 1.1 lukem fprintf( fp, "attrs:%s", op->oq_search.rs_attrs == NULL ? " all" : "" );
63 1.1 lukem for ( an = op->oq_search.rs_attrs; an && an->an_name.bv_val; an++ ) {
64 1.1 lukem fprintf( fp, " %s", an->an_name.bv_val );
65 1.1 lukem }
66 1.1 lukem fprintf( fp, "\n\n" ); /* end of attr line plus blank line */
67 1.1 lukem
68 1.1 lukem /* read in the results and send them along */
69 1.1 lukem rs->sr_attrs = op->oq_search.rs_attrs;
70 1.1 lukem sock_read_and_send_results( op, rs, fp );
71 1.1 lukem
72 1.1 lukem fclose( fp );
73 1.1 lukem return( 0 );
74 1.1 lukem }
75