File: GHTTP.xs

package info (click to toggle)
libhttp-ghttp-perl 1.07-10
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 96 kB
  • ctags: 11
  • sloc: perl: 143; makefile: 56
file content (358 lines) | stat: -rw-r--r-- 6,302 bytes parent folder | download | duplicates (2)
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/* $Id: GHTTP.xs,v 1.8 2002/03/25 09:24:54 matt Exp $ */

#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ghttp.h"
#ifdef __cplusplus
}
#endif

MODULE = HTTP::GHTTP         PACKAGE = HTTP::GHTTP

ghttp_request *
_new(CLASS)
        char * CLASS
    CODE:
        RETVAL = ghttp_request_new();
        if (RETVAL == NULL) {
            warn("Unable to allocate ghttp_request");
            XSRETURN_UNDEF;
        }
        /* sv_bless(RETVAL, gv_stash_pv(CLASS, 1)); */
    OUTPUT:
        RETVAL

void
DESTROY(self)
        ghttp_request *self
    CODE:
        ghttp_request_destroy(self);

int
set_uri(self, uri)
        ghttp_request *self
        char *uri
    CODE:
        if(ghttp_set_uri(self, uri) == ghttp_error) {
            XSRETURN_UNDEF;
        }
        RETVAL = 1;
    OUTPUT:
        RETVAL

int
set_proxy(self, proxy)
        ghttp_request *self
        char *proxy
    CODE:
        RETVAL = ghttp_set_proxy(self, proxy);
    OUTPUT:
        RETVAL

void
set_header(self, hdr, val)
        ghttp_request *self
        const char *hdr
        const char *val
    CODE:
        ghttp_set_header(self, hdr, val);

void
process_request(self)
        ghttp_request *self
    CODE:
        ghttp_prepare(self);
        ghttp_process(self);

void
clean(self)
       ghttp_request *self
    CODE:
       ghttp_clean(self);

int
prepare(self)
        ghttp_request *self
    CODE:
        RETVAL = ghttp_prepare(self);
    OUTPUT:
        RETVAL

int
process(self)
        ghttp_request *self
    PREINIT:
        ghttp_status process_status;
    CODE:
        process_status = ghttp_process(self);
        if (process_status == ghttp_error) {
            XSRETURN_UNDEF;
        }
        RETVAL = !process_status;
    OUTPUT:
        RETVAL

const char*
get_header(self, hdr)
        ghttp_request *self
        const char *hdr
    CODE:
        RETVAL = ghttp_get_header(self, hdr);
    OUTPUT:
        RETVAL

#ifdef HAVE_GHTTP_GET_HEADER_NAMES

void
get_headers(self)
        ghttp_request *self
    PREINIT:
        char **hdrs;
        int num_hdrs;
        int i;
    PPCODE:
        if (ghttp_get_header_names(self, &hdrs, &num_hdrs) == -1) {
            XSRETURN_UNDEF;
        }
        
        EXTEND(SP, num_hdrs);
        
        for (i = 0; i < num_hdrs; i++) {
            PUSHs(sv_2mortal(newSVpv(hdrs[i], 0)));
            free(hdrs[i]);
        }

#endif

int
close(self)
        ghttp_request *self
    CODE:
        RETVAL = ghttp_close(self);
    OUTPUT:
        RETVAL

SV *
get_body(self)
        ghttp_request *self
    PREINIT:
        SV* buffer;
    CODE:
        buffer = newSVpvn("",0);
        sv_catpvn(buffer, ghttp_get_body(self), ghttp_get_body_len(self));
        RETVAL = buffer;
    OUTPUT:
        RETVAL

const char *
get_error(self)
        ghttp_request *self
    CODE:
        RETVAL = ghttp_get_error(self);
    OUTPUT:
        RETVAL

int
set_authinfo(self, user, pass)
        ghttp_request *self
        const char *user
        const char *pass
    CODE:
        RETVAL = ghttp_set_authinfo(self, user, pass);
    OUTPUT:
        RETVAL

int
set_proxy_authinfo(self, user, pass)
        ghttp_request *self
        const char *user
        const char *pass
    CODE:
        RETVAL = ghttp_set_proxy_authinfo(self, user, pass);
    OUTPUT:
        RETVAL

int
set_type(self, type)
        ghttp_request *self
        int type
    CODE:
        RETVAL = ghttp_set_type(self, type);
    OUTPUT:
        RETVAL

int
set_body(self, body)
        ghttp_request *self
        SV *body
    PREINIT:
        STRLEN len;
        char * str;
    CODE:
        str = SvPV(body, len);
        RETVAL = ghttp_set_body(self, str, len);
    OUTPUT:
        RETVAL

int
_get_socket(self)
        ghttp_request *self
    CODE:
        RETVAL = ghttp_get_socket(self);
    OUTPUT:
        RETVAL

void
get_status(self)
        ghttp_request *self
    PREINIT:
        int code;
        const char *reason;
    PPCODE:
        code = ghttp_status_code(self);
        reason = ghttp_reason_phrase(self);
        EXTEND(SP, 2);
        PUSHs(sv_2mortal(newSViv(code)));
       if (reason == NULL)
               reason="NULL";
               PUSHs(sv_2mortal(newSVpv((char*)reason, 0)));

void
current_status(self)
        ghttp_request *self
    PREINIT:
        ghttp_current_status status;
    PPCODE:
        status = ghttp_get_status(self);
        EXTEND(SP, 3);
        PUSHs(sv_2mortal(newSViv(status.proc)));
        PUSHs(sv_2mortal(newSViv(status.bytes_read)));
        PUSHs(sv_2mortal(newSViv(status.bytes_total)));

int
set_async(self)
        ghttp_request *self
    CODE:
        RETVAL = ghttp_set_sync(self, ghttp_async);
    OUTPUT:
        RETVAL

void
set_chunksize(self, size)
        ghttp_request *self
        int size
    CODE:
        ghttp_set_chunksize(self, size);

 #
 # CONSTANTS
 #

int
METHOD_GET()
    CODE:
        RETVAL = ghttp_type_get;
    OUTPUT:
        RETVAL

int
METHOD_OPTIONS()
    CODE:
        RETVAL = ghttp_type_options;
    OUTPUT:
        RETVAL

int
METHOD_HEAD()
    CODE:
        RETVAL = ghttp_type_head;
    OUTPUT:
        RETVAL

int
METHOD_POST()
    CODE:
        RETVAL = ghttp_type_post;
    OUTPUT:
        RETVAL

int
METHOD_PUT()
    CODE:
        RETVAL = ghttp_type_put;
    OUTPUT:
        RETVAL

int
METHOD_DELETE()
    CODE:
        RETVAL = ghttp_type_delete;
    OUTPUT:
        RETVAL

int
METHOD_TRACE()
    CODE:
        RETVAL = ghttp_type_trace;
    OUTPUT:
        RETVAL

int
METHOD_CONNECT()
    CODE:
        RETVAL = ghttp_type_connect;
    OUTPUT:
        RETVAL

int
METHOD_PROPFIND()
    CODE:
        RETVAL = ghttp_type_propfind;
    OUTPUT:
        RETVAL

int
METHOD_PROPPATCH()
    CODE:
        RETVAL = ghttp_type_proppatch;
    OUTPUT:
        RETVAL

int
METHOD_MKCOL()
    CODE:
        RETVAL = ghttp_type_mkcol;
    OUTPUT:
        RETVAL

int
METHOD_COPY()
    CODE:
        RETVAL = ghttp_type_copy;
    OUTPUT:
        RETVAL

int
METHOD_MOVE()
    CODE:
        RETVAL = ghttp_type_move;
    OUTPUT:
        RETVAL

int
METHOD_LOCK()
    CODE:
        RETVAL = ghttp_type_lock;
    OUTPUT:
        RETVAL

int
METHOD_UNLOCK()
    CODE:
        RETVAL = ghttp_type_unlock;
    OUTPUT:
        RETVAL