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