Fix error creation and warning
[claws.git] / src / ldaplocate.c
blob1dc3e7f54da94a334aa065271d511ffed85e4d5b
1 /*
2 * Claws Mail -- 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.
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #include "claws-features.h"
27 #endif
29 #ifdef USE_LDAP
31 #include <glib.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 );
38 /**
39 * Setup the search that will be performed and registered with the query
40 * manager.
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,
50 void *callBackEnd )
52 QueryRequest *req;
53 LdapQuery *qry;
54 gint queryID;
55 gchar *name;
57 /* Name the query */
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 );
74 /* Setup server */
75 ldapsvr_add_query( server, qry );
77 /* Set up query request */
78 qryreq_add_query( req, ADDRQUERY_OBJECT(qry) );
80 g_free( name );
82 return queryID;
85 /**
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
89 * failed.
91 gboolean ldaplocate_search_start( const gint queryID ) {
92 gboolean retVal;
93 LdapServer *server;
94 LdapQuery *qry;
95 QueryRequest *req;
96 AddrQueryObject *aqo;
98 retVal = FALSE;
99 req = qrymgr_find_request( queryID );
100 if( req == NULL ) {
101 return retVal;
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 */
114 retVal = TRUE;
115 ldapsvr_execute_query( server, qry );
117 return retVal;
121 * Notify search to stop execution.
122 * \param queryID Query to terminate.
124 void ldaplocate_search_stop( const gint queryID ) {
125 QueryRequest *req;
126 AddrQueryObject *aqo;
127 LdapQuery *qry;
129 req = qrymgr_find_request( queryID );
130 if( req == NULL ) {
131 return;
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;
142 /* Delete query */
143 qrymgr_delete_request( queryID );
146 #endif /* USE_LDAP */
149 * End of Source.