1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2003-2012 Match Grun and the Claws Mail team
4  *
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.
9  *
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.
14  *
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/>.
17  *
18  */
19 
20 /*
21  * Functions necessary to define an LDAP query.
22  */
23 
24 #ifndef __LDAPQUERY_H__
25 #define __LDAPQUERY_H__
26 
27 #ifdef USE_LDAP
28 
29 #include <glib.h>
30 #include <stdio.h>
31 #include <sys/time.h>
32 #include <pthread.h>
33 
34 #ifdef G_OS_UNIX
35 #include <ldap.h>
36 #include <lber.h>
37 #else
38 #include <windows.h>
39 #include <winldap.h>
40 #endif
41 #include "addrquery.h"
42 #include "ldapctrl.h"
43 #include "addritem.h"
44 #include "addrcache.h"
45 #include "ldapserver.h"
46 
47 typedef struct _LdapQuery LdapQuery;
48 struct _LdapQuery {
49 	AddrQueryObject obj;
50 	LdapControl     *control;
51 	LdapServer      *server;	/* Reference to (parent) LDAP server */
52 	gint            entriesRead;
53 	gint            elapsedTime;
54 	gboolean        stopFlag;
55 	gboolean        busyFlag;
56 	gboolean        agedFlag;
57 	gboolean        completed;
58 	time_t          startTime;
59 	time_t          touchTime;
60 	pthread_t       *thread;
61 	pthread_mutex_t *mutexStop;
62 	pthread_mutex_t *mutexBusy;
63 	pthread_mutex_t *mutexEntry;
64 	void            (*callBackEntry)( void *, gint, void *, void * );
65 	void            (*callBackEnd)( void *, gint, gint, void * );
66 	LDAP            *ldap;
67 	gpointer        data;
68 };
69 
70 typedef struct _NameValuePair NameValuePair;
71 struct _NameValuePair {
72 	gchar *name;
73 	gchar *value;
74 };
75 
76 /* Function prototypes */
77 void ldapqry_print(LdapQuery *qry, FILE *stream);
78 void ldapqry_initialize		( void );
79 LdapQuery *ldapqry_create	( void );
80 void ldapqry_set_control	( LdapQuery *qry, LdapControl *ctl );
81 void ldapqry_set_name		( LdapQuery* qry, const gchar *value );
82 void ldapqry_set_search_value	( LdapQuery *qry, const gchar *value );
83 void ldapqry_set_search_type	( LdapQuery *qry, const AddrSearchType value );
84 void ldapqry_set_query_id	( LdapQuery* qry, const gint value );
85 void ldapqry_set_callback_start	( LdapQuery *qry, void *func );
86 void ldapqry_set_callback_entry	( LdapQuery *qry, void *func );
87 void ldapqry_set_callback_end	( LdapQuery *qry, void *func );
88 void ldapqry_free		( LdapQuery *qry );
89 void ldapqry_set_stop_flag( LdapQuery *qry, const gboolean value );
90 gboolean ldapqry_check_search	( LdapQuery *qry );
91 void ldapqry_touch		( LdapQuery *qry );
92 gint ldapqry_read_data_th	( LdapQuery *qry );
93 void ldapqry_cancel		( LdapQuery *qry );
94 void ldapqry_age		( LdapQuery *qry, gint maxAge );
95 void ldapqry_delete_folder	( LdapQuery *qry );
96 gboolean ldapquery_remove_results( LdapQuery *qry );
97 void ldapqry_free_list_name_value( GList *list );
98 void ldapqry_free_name_value( NameValuePair *nvp );
99 #endif	/* USE_LDAP */
100 
101 #endif /* __LDAPQUERY_H__ */
102