1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
/* --- BEGIN COPYRIGHT BLOCK ---
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* --- END COPYRIGHT BLOCK --- */
/**
* Simple Http Client API broker plugin
*/
#include <stdio.h>
#include <string.h>
#include "portable.h"
#include "nspr.h"
#include "slapi-plugin.h"
#include "slapi-private.h"
#include "dirlite_strings.h"
#include "dirver.h"
#include "http_client.h"
#include "http_impl.h"
/* get file mode flags for unix */
#ifndef _WIN32
#include <sys/stat.h>
#endif
/*** from proto-slap.h ***/
int slapd_log_error_proc( char *subsystem, char *fmt, ... );
/*** from ldaplog.h ***/
/* edited ldaplog.h for LDAPDebug()*/
#ifndef _LDAPLOG_H
#define _LDAPLOG_H
#ifdef __cplusplus
extern "C" {
#endif
#define LDAP_DEBUG_TRACE 0x00001 /* 1 */
#define LDAP_DEBUG_ANY 0x04000 /* 16384 */
#define LDAP_DEBUG_PLUGIN 0x10000 /* 65536 */
/* debugging stuff */
# ifdef _WIN32
extern int *module_ldap_debug;
# define LDAPDebug( level, fmt, arg1, arg2, arg3 ) \
{ \
if ( *module_ldap_debug & level ) { \
slapd_log_error_proc( NULL, fmt, arg1, arg2, arg3 ); \
} \
}
# else /* _WIN32 */
extern int slapd_ldap_debug;
# define LDAPDebug( level, fmt, arg1, arg2, arg3 ) \
{ \
if ( slapd_ldap_debug & level ) { \
slapd_log_error_proc( NULL, fmt, arg1, arg2, arg3 ); \
} \
}
# endif /* Win32 */
#ifdef __cplusplus
}
#endif
#endif /* _LDAP_H */
#define HTTP_PLUGIN_SUBSYSTEM "http-client-plugin" /* used for logging */
#define HTTP_PLUGIN_VERSION 0x00050050
#define HTTP_SUCCESS 0
#define HTTP_FAILURE -1
/**
* Implementation functions
*/
static void *api[7];
/**
* Plugin identifiers
*/
static Slapi_PluginDesc pdesc = { "http-client",
PLUGIN_MAGIC_VENDOR_STR,
PRODUCTTEXT,
"HTTP Client plugin" };
static Slapi_ComponentId *plugin_id = NULL;
/**
**
** Http plug-in management functions
**
**/
int http_client_init(Slapi_PBlock *pb);
static int http_client_start(Slapi_PBlock *pb);
static int http_client_close(Slapi_PBlock *pb);
/**
* our functions
*/
static void _http_init(Slapi_ComponentId *plugin_id);
static int _http_get_text(char *url, char **data, int *bytesRead);
static int _http_get_binary(char *url, char **data, int *bytesRead);
static int _http_get_redirected_uri(char *url, char **data, int *bytesRead);
static int _http_post(char *url, httpheader **httpheaderArray, char *body, char **data, int *bytesRead);
static void _http_shutdown( void );
#ifdef _WIN32
int *module_ldap_debug = 0;
void plugin_init_debug_level(int *level_ptr)
{
module_ldap_debug = level_ptr;
}
#endif
/**
*
* Get the presence plug-in version
*
*/
int http_client_version()
{
return HTTP_PLUGIN_VERSION;
}
int http_client_init(Slapi_PBlock *pb)
{
int status = HTTP_SUCCESS;
LDAPDebug( LDAP_DEBUG_PLUGIN, "--> http_client_init -- BEGIN\n",0,0,0);
if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
SLAPI_PLUGIN_VERSION_01 ) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN,
(void *) http_client_start ) != 0 ||
slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN,
(void *) http_client_close ) != 0 ||
slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
(void *)&pdesc ) != 0 )
{
slapi_log_error( SLAPI_LOG_FATAL, HTTP_PLUGIN_SUBSYSTEM,
"http_client_init: failed to register plugin\n" );
status = HTTP_FAILURE;
}
/* Retrieve and save the plugin identity to later pass to
internal operations */
if (slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &plugin_id) != 0) {
slapi_log_error(SLAPI_LOG_FATAL, HTTP_PLUGIN_SUBSYSTEM,
"http_client_init: Failed to retrieve SLAPI_PLUGIN_IDENTITY\n");
return HTTP_FAILURE;
}
LDAPDebug( LDAP_DEBUG_PLUGIN, "<-- http_client_init -- END\n",0,0,0);
return status;
}
static int http_client_start(Slapi_PBlock *pb)
{
int status = HTTP_SUCCESS;
/**
* do some init work here
*/
LDAPDebug( LDAP_DEBUG_PLUGIN, "--> http_client_start -- BEGIN\n",0,0,0);
api[0] = 0; /* reserved for api broker use, must be zero */
api[1] = (void *)_http_init;
api[2] = (void *)_http_get_text;
api[3] = (void *)_http_get_binary;
api[4] = (void *)_http_get_redirected_uri;
api[5] = (void *)_http_shutdown;
api[6] = (void *)_http_post;
if( slapi_apib_register(HTTP_v1_0_GUID, api) ) {
slapi_log_error( SLAPI_LOG_FATAL, HTTP_PLUGIN_SUBSYSTEM,
"http_client_start: failed to register functions\n" );
status = HTTP_FAILURE;
}
_http_init(plugin_id);
LDAPDebug( LDAP_DEBUG_PLUGIN, "<-- http_client_start -- END\n",0,0,0);
return status;
}
static int http_client_close(Slapi_PBlock *pb)
{
int status = HTTP_SUCCESS;
/**
* do cleanup
*/
LDAPDebug( LDAP_DEBUG_PLUGIN, "--> http_client_close -- BEGIN\n",0,0,0);
slapi_apib_unregister(HTTP_v1_0_GUID);
LDAPDebug( LDAP_DEBUG_PLUGIN, "<-- http_client_close -- END\n",0,0,0);
return status;
}
/**
* perform http initialization here
*/
static void _http_init(Slapi_ComponentId *plugin_id)
{
LDAPDebug( LDAP_DEBUG_PLUGIN, "--> _http_init -- BEGIN\n",0,0,0);
http_impl_init(plugin_id);
LDAPDebug( LDAP_DEBUG_PLUGIN, "<-- _http_init -- END\n",0,0,0);
}
/**
* This method gets the data in a text format based on the
* URL send.
*/
static int _http_get_text(char *url, char **data, int *bytesRead)
{
int status = HTTP_SUCCESS;
LDAPDebug( LDAP_DEBUG_PLUGIN, "--> _http_get_text -- BEGIN\n",0,0,0);
status = http_impl_get_text(url, data, bytesRead);
LDAPDebug( LDAP_DEBUG_PLUGIN, "<-- _http_get_text -- END\n",0,0,0);
return status;
}
/**
* This method gets the data in a binary format based on the
* URL send.
*/
static int _http_get_binary(char *url, char **data, int *bytesRead)
{
int status = HTTP_SUCCESS;
LDAPDebug( LDAP_DEBUG_PLUGIN, "--> _http_get_binary -- BEGIN\n",0,0,0);
status = http_impl_get_binary(url, data, bytesRead);
LDAPDebug( LDAP_DEBUG_PLUGIN, "<-- _http_get_binary -- END\n",0,0,0);
return status;
}
/**
* This method intercepts the redirected URI and returns the location
* information.
*/
static int _http_get_redirected_uri(char *url, char **data, int *bytesRead)
{
int status = HTTP_SUCCESS;
LDAPDebug( LDAP_DEBUG_PLUGIN, "--> _http_get_redirected_uri -- BEGIN\n",0,0,0);
status = http_impl_get_redirected_uri(url, data, bytesRead);
LDAPDebug( LDAP_DEBUG_PLUGIN, "<-- _http_get_redirected_uri -- END\n",0,0,0);
return status;
}
/**
* This method posts the data based on the URL send.
*/
static int _http_post(char *url, httpheader ** httpheaderArray, char *body, char **data, int *bytesRead)
{
int status = HTTP_SUCCESS;
LDAPDebug( LDAP_DEBUG_PLUGIN, "--> _http_post -- BEGIN\n",0,0,0);
status = http_impl_post(url, httpheaderArray, body, data, bytesRead);
LDAPDebug( LDAP_DEBUG_PLUGIN, "<-- _http_post -- END\n",0,0,0);
return status;
}
/**
* perform http shutdown here
*/
static void _http_shutdown( void )
{
LDAPDebug( LDAP_DEBUG_PLUGIN, "--> _http_shutdown -- BEGIN\n",0,0,0);
http_impl_shutdown();
LDAPDebug( LDAP_DEBUG_PLUGIN, "<-- _http_shutdown -- END\n",0,0,0);
}
|