1 /*
2 * Kamailio LDAP Module
3 *
4 * Copyright (C) 2007 University of North Carolina
5 *
6 * Original author: Christian Schlatter, cs@unc.edu
7 *
8 *
9 * This file is part of Kamailio, a free SIP server.
10 *
11 * Kamailio is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version
15 *
16 * Kamailio is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24 *
25 */
26 
27 
28 #ifndef LDAP_API_H
29 #define LDAP_API_H
30 
31 #include <ldap.h>
32 
33 #include "../../core/str.h"
34 #include "../../core/sr_module.h"
35 
36 /*
37 * LDAP API function types
38 */
39 typedef int (*ldap_params_search_t)(int *_ld_result_count, char *_lds_name,
40 		char *_dn, int _scope, char **_attrs, char *_filter, ...);
41 
42 typedef int (*ldap_url_search_t)(char *_ldap_url, int *_result_count);
43 
44 typedef int (*ldap_result_attr_vals_t)(str *_attr_name, struct berval ***_vals);
45 
46 typedef void (*ldap_value_free_len_t)(struct berval **_vals);
47 
48 typedef int (*ldap_result_next_t)(void);
49 
50 typedef int (*ldap_str2scope_t)(char *scope_str);
51 
52 typedef int (*get_ldap_handle_t)(char *_lds_name, LDAP **_ldap_handle);
53 
54 typedef void (*get_last_ldap_result_t)(
55 		LDAP **_last_ldap_handle, LDAPMessage **_last_ldap_result);
56 
57 typedef int (*ldap_rfc4515_escape_t)(str *sin, str *sout, int url_encode);
58 
59 /*
60 * LDAP module API
61 */
62 
63 typedef struct ldap_api
64 {
65 	ldap_params_search_t ldap_params_search;
66 	ldap_url_search_t ldap_url_search;
67 	ldap_result_attr_vals_t ldap_result_attr_vals;
68 	ldap_value_free_len_t ldap_value_free_len;
69 	ldap_result_next_t ldap_result_next;
70 	ldap_str2scope_t ldap_str2scope;
71 	ldap_rfc4515_escape_t ldap_rfc4515_escape;
72 	get_ldap_handle_t get_ldap_handle;
73 	get_last_ldap_result_t get_last_ldap_result;
74 } ldap_api_t;
75 
76 
77 typedef int (*load_ldap_t)(ldap_api_t *api);
78 
79 int load_ldap(ldap_api_t *api);
80 
load_ldap_api(ldap_api_t * api)81 static inline int load_ldap_api(ldap_api_t *api)
82 {
83 	load_ldap_t load_ldap;
84 
85 	if(!(load_ldap = (load_ldap_t)find_export("load_ldap", 0, 0))) {
86 		LM_ERR("can't import load_ldap\n");
87 		return -1;
88 	}
89 
90 	if(load_ldap(api) == -1) {
91 		return -1;
92 	}
93 
94 	return 0;
95 }
96 
97 #endif /* LDAP_API_H */
98