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