2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2003-2012 Match Grun and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * Functions to perform searches for LDAP entries.
26 #include "claws-features.h"
32 #include "addrquery.h"
33 #include "ldapserver.h"
34 #include "ldapquery.h"
36 void ldapsvr_add_query( LdapServer
*server
, LdapQuery
*qry
);
37 void ldapsvr_execute_query( LdapServer
*server
, LdapQuery
*qry
);
39 * Setup the search that will be performed and registered with the query
42 * \param server LDAP server object.
43 * \param searchTerm Search term to locate.
44 * \param callBackEntry Function to call when each attribute is returned.
45 * \param callBackEnd Function to call when search is complete.
46 * \return Query ID allocated to query that will be executed.
48 gint
ldaplocate_search_setup(
49 LdapServer
*server
, const gchar
*searchTerm
, void *callBackEntry
,
58 name
= g_strdup_printf( "Locate '%s'", searchTerm
);
60 /* Set up a generic address query */
61 req
= qrymgr_add_request( searchTerm
, callBackEnd
, callBackEntry
);
62 qryreq_set_search_type( req
, ADDRSEARCH_LOCATE
);
63 queryID
= req
->queryID
;
65 /* Construct a query */
66 qry
= ldapqry_create();
67 ldapqry_set_query_id( qry
, queryID
);
68 ldapqry_set_name( qry
, name
);
69 ldapqry_set_search_value( qry
, searchTerm
);
70 ldapqry_set_search_type( qry
, ADDRSEARCH_LOCATE
);
71 ldapqry_set_callback_end( qry
, callBackEnd
);
72 ldapqry_set_callback_entry( qry
, callBackEntry
);
75 ldapsvr_add_query( server
, qry
);
77 /* Set up query request */
78 qryreq_add_query( req
, ADDRQUERY_OBJECT(qry
) );
86 * Perform the previously registered search.
87 * \param queryID ID of search query to be executed.
88 * \return <i>TRUE</i> if search started successfully, or <i>FALSE</i> if
91 gboolean
ldaplocate_search_start( const gint queryID
) {
99 req
= qrymgr_find_request( queryID
);
104 /* Note: there should only be one query in the list */
105 aqo
= req
->queryList
->data
;
106 if( aqo
->queryType
== ADDRQUERY_LDAP
) {
107 qry
= ( LdapQuery
* ) aqo
;
108 server
= qry
->server
;
110 /* Retire any aged queries */
111 ldapsvr_retire_query( server
);
113 /* Start the search */
115 ldapsvr_execute_query( server
, qry
);
121 * Notify search to stop execution.
122 * \param queryID Query to terminate.
124 void ldaplocate_search_stop( const gint queryID
) {
126 AddrQueryObject
*aqo
;
129 req
= qrymgr_find_request( queryID
);
134 aqo
= req
->queryList
->data
;
135 if( aqo
->queryType
== ADDRQUERY_LDAP
) {
136 /* Notify query to stop */
137 qry
= ( LdapQuery
* ) aqo
;
138 ldapqry_set_stop_flag( qry
, TRUE
);
140 req
->queryList
->data
= NULL
;
143 qrymgr_delete_request( queryID
);
146 #endif /* USE_LDAP */