~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to sapi/apache_hooks/php_apache.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   +----------------------------------------------------------------------+
 
3
   | PHP Version 5                                                        |
 
4
   +----------------------------------------------------------------------+
 
5
   | Copyright (c) 1997-2004 The PHP Group                                |
 
6
   +----------------------------------------------------------------------+
 
7
   | This source file is subject to version 3.0 of the PHP license,       |
 
8
   | that is bundled with this package in the file LICENSE, and is        |
 
9
   | available through the world-wide-web at the following url:           |
 
10
   | http://www.php.net/license/3_0.txt.                                  |
 
11
   | If you did not receive a copy of the PHP license and are unable to   |
 
12
   | obtain it through the world-wide-web, please send a note to          |
 
13
   | license@php.net so we can mail you a copy immediately.               |
 
14
   +----------------------------------------------------------------------+
 
15
   | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca>                       |
 
16
   |          Stig Sļæ½ther Bakken <ssb@php.net>                            |
 
17
   |          David Sklar <sklar@student.net>                             |
 
18
   +----------------------------------------------------------------------+
 
19
 */
 
20
/* $Id: php_apache.c,v 1.17.2.1 2005/01/14 20:45:11 sniper Exp $ */
 
21
 
 
22
#include "php_apache_http.h"
 
23
 
 
24
#if defined(PHP_WIN32) || defined(NETWARE)
 
25
#include "zend.h"
 
26
#include "ap_compat.h"
 
27
#else
 
28
#include <build-defs.h>
 
29
#endif
 
30
 
 
31
#ifdef ZTS
 
32
int php_apache_info_id;
 
33
#else
 
34
php_apache_info_struct php_apache_info;
 
35
#endif
 
36
 
 
37
#define SECTION(name)  PUTS("<H2 align=\"center\">" name "</H2>\n")
 
38
 
 
39
#undef offsetof
 
40
#define offsetof(s_type,field) ((size_t)&(((s_type*)0)->field))
 
41
 
 
42
extern module *top_module;
 
43
extern module **ap_loaded_modules;
 
44
static int le_apachereq;
 
45
static zend_class_entry *apacherequest_class_entry;
 
46
 
 
47
static void apache_table_to_zval(table *, int safe_mode, zval *return_value);
 
48
 
 
49
PHP_FUNCTION(virtual);
 
50
PHP_FUNCTION(apache_request_headers);
 
51
PHP_FUNCTION(apache_response_headers);
 
52
PHP_FUNCTION(apachelog);
 
53
PHP_FUNCTION(apache_note);
 
54
PHP_FUNCTION(apache_lookup_uri);
 
55
PHP_FUNCTION(apache_child_terminate);
 
56
PHP_FUNCTION(apache_setenv);
 
57
PHP_FUNCTION(apache_get_version);
 
58
PHP_FUNCTION(apache_get_modules);
 
59
 
 
60
PHP_MINFO_FUNCTION(apache);
 
61
 
 
62
 
 
63
function_entry apache_functions[] = {
 
64
        PHP_FE(virtual,                                                                 NULL)
 
65
        PHP_FE(apache_request_headers,                                  NULL)
 
66
        PHP_FE(apache_note,                                                             NULL)
 
67
        PHP_FE(apache_lookup_uri,                                               NULL)
 
68
        PHP_FE(apache_child_terminate,                                  NULL)
 
69
        PHP_FE(apache_setenv,                                                   NULL)
 
70
        PHP_FE(apache_response_headers,                                 NULL)
 
71
        PHP_FE(apache_get_version,                                      NULL)
 
72
        PHP_FE(apache_get_modules,                                      NULL)
 
73
        PHP_FALIAS(getallheaders, apache_request_headers, NULL)
 
74
        {NULL, NULL, NULL}
 
75
};
 
76
 
 
77
/* {{{ php_apache ini entries
 
78
 */
 
79
PHP_INI_BEGIN()
 
80
        STD_PHP_INI_ENTRY("xbithack",                   "0",                            PHP_INI_ALL,            OnUpdateLong,           xbithack, php_apache_info_struct, php_apache_info)
 
81
        STD_PHP_INI_ENTRY("engine",                             "1",                            PHP_INI_ALL,            OnUpdateLong,           engine, php_apache_info_struct, php_apache_info)
 
82
        STD_PHP_INI_ENTRY("last_modified",              "0",                            PHP_INI_ALL,            OnUpdateLong,           last_modified, php_apache_info_struct, php_apache_info)
 
83
        STD_PHP_INI_ENTRY("child_terminate",    "0",                            PHP_INI_ALL,            OnUpdateLong,           terminate_child, php_apache_info_struct, php_apache_info)
 
84
PHP_INI_END()
 
85
/* }}} */
 
86
 
 
87
static void php_apache_globals_ctor(php_apache_info_struct *apache_globals TSRMLS_DC)
 
88
{
 
89
        apache_globals->in_request = 0;
 
90
}
 
91
 
 
92
 
 
93
#define APREQ_GET_THIS(ZVAL)            if (NULL == (ZVAL = getThis())) { \
 
94
                                                                                php_error(E_WARNING, "%s(): underlying ApacheRequest object missing", \
 
95
                                                                                        get_active_function_name(TSRMLS_C)); \
 
96
                                                                                RETURN_FALSE; \
 
97
                                                                        }
 
98
#define APREQ_GET_REQUEST(ZVAL, R)      APREQ_GET_THIS(ZVAL); \
 
99
                                                                        R = get_apache_request(ZVAL TSRMLS_CC)
 
100
 
 
101
static void php_apache_request_free(zend_rsrc_list_entry *rsrc TSRMLS_DC)
 
102
{
 
103
        zval *z = (zval *)rsrc->ptr;
 
104
/*      fprintf(stderr, "%s() %p\n", __FUNCTION__, z); */
 
105
        zval_ptr_dtor(&z);
 
106
}
 
107
 
 
108
static request_rec *get_apache_request(pval *z TSRMLS_DC)
 
109
{
 
110
        request_rec *r;
 
111
        zval **addr;
 
112
 
 
113
        if (NULL == z) {
 
114
                php_error(E_WARNING, "get_apache_request() invalid wrapper passed");
 
115
                return NULL;
 
116
        }
 
117
 
 
118
        if (Z_TYPE_P(z) != IS_OBJECT) {
 
119
                php_error(E_WARNING, "%s(): wrapper is not an object", get_active_function_name(TSRMLS_C));
 
120
                return NULL;
 
121
        }
 
122
 
 
123
        if (zend_hash_index_find(Z_OBJPROP_P(z), 0, (void **)&addr) == FAILURE) {
 
124
                php_error(E_WARNING, "%s(): underlying object missing", get_active_function_name(TSRMLS_C));
 
125
                return NULL;
 
126
        }
 
127
 
 
128
        r = (request_rec *)Z_LVAL_PP(addr);
 
129
        if (!r) {
 
130
                php_error(E_WARNING, "%s(): request_rec invalid", get_active_function_name(TSRMLS_C));
 
131
                return NULL;
 
132
        }
 
133
 
 
134
        return r;
 
135
}
 
136
 
 
137
/* {{{ php_apache_request_new(request_rec *r)
 
138
 * create a new zval-instance for ApacheRequest that wraps request_rec
 
139
 */
 
140
zval *php_apache_request_new(request_rec *r)
 
141
{
 
142
        zval *req;
 
143
        zval *addr;
 
144
        
 
145
        TSRMLS_FETCH();
 
146
 
 
147
        MAKE_STD_ZVAL(addr);
 
148
        Z_TYPE_P(addr) = IS_LONG;
 
149
        Z_LVAL_P(addr) = (int) r;
 
150
 
 
151
        MAKE_STD_ZVAL(req);
 
152
        object_init_ex(req, apacherequest_class_entry);
 
153
        zend_hash_index_update(Z_OBJPROP_P(req), 0, &addr, sizeof(zval *), NULL);
 
154
 
 
155
        return req;
 
156
}
 
157
/* }}} */
 
158
 
 
159
/* {{{ apache_request_read_string_slot()
 
160
 */
 
161
static void apache_request_read_string_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
 
162
{
 
163
        zval *id;
 
164
        request_rec *r;
 
165
        char *s;
 
166
 
 
167
        if (ZEND_NUM_ARGS() > 0) {
 
168
                WRONG_PARAM_COUNT;
 
169
        }
 
170
 
 
171
        APREQ_GET_REQUEST(id, r);
 
172
 
 
173
        s = *(char **)((char*)r + offset);
 
174
 
 
175
        if (s)
 
176
                RETURN_STRING(s, 1);
 
177
 
 
178
        RETURN_EMPTY_STRING();
 
179
}
 
180
/* }}} */
 
181
 
 
182
 
 
183
/* {{{ apache_request_string_slot()
 
184
 */
 
185
static void apache_request_string_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
 
186
{
 
187
        zval *id, **new_value;
 
188
        request_rec *r;
 
189
        char *old_value;
 
190
        char **target;
 
191
 
 
192
        APREQ_GET_REQUEST(id, r);
 
193
 
 
194
        target = (char **)((char*)r + offset);
 
195
        old_value = *target;
 
196
 
 
197
        switch (ZEND_NUM_ARGS()) {
 
198
                case 0:
 
199
                        break;
 
200
                case 1:
 
201
                        if (zend_get_parameters_ex(1, &new_value) == FAILURE) {
 
202
                                RETURN_FALSE;
 
203
                        }
 
204
                        convert_to_string_ex(new_value);
 
205
                        *target = ap_pstrdup(r->pool, Z_STRVAL_PP(new_value));
 
206
                        break;
 
207
                default:
 
208
                        WRONG_PARAM_COUNT;
 
209
                        break;
 
210
        }
 
211
 
 
212
        if (old_value)
 
213
                RETURN_STRING(old_value, 1);
 
214
 
 
215
        RETURN_EMPTY_STRING();
 
216
}
 
217
/* }}} */
 
218
 
 
219
/* {{{ apache_request_read_int_slot()
 
220
 */
 
221
static void apache_request_read_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
 
222
{
 
223
        zval *id;
 
224
        request_rec *r;
 
225
        long l;
 
226
 
 
227
        if (ZEND_NUM_ARGS() > 0) {
 
228
                WRONG_PARAM_COUNT;
 
229
        }
 
230
 
 
231
        APREQ_GET_REQUEST(id, r);
 
232
 
 
233
        l = *(long *)((char*)r + offset);
 
234
 
 
235
        RETURN_LONG(l);
 
236
}
 
237
/* }}} */
 
238
 
 
239
/* {{{ apache_request_int_slot()
 
240
 */
 
241
static void apache_request_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
 
242
{
 
243
        zval *id, **new_value;
 
244
        request_rec *r;
 
245
        long old_value;
 
246
        long *target;
 
247
 
 
248
        APREQ_GET_REQUEST(id, r);
 
249
 
 
250
        target = (long *)((char*)r + offset);
 
251
        old_value = *target;
 
252
 
 
253
        switch (ZEND_NUM_ARGS()) {
 
254
                case 0:
 
255
                        break;
 
256
                case 1:
 
257
                        if (zend_get_parameters_ex(1, &new_value) == FAILURE) {
 
258
                                RETURN_FALSE;
 
259
                        }
 
260
                        convert_to_long_ex(new_value);
 
261
                        *target = Z_LVAL_PP(new_value);
 
262
                        break;
 
263
                default:
 
264
                        WRONG_PARAM_COUNT;
 
265
                        break;
 
266
        }
 
267
 
 
268
        RETURN_LONG(old_value);
 
269
}
 
270
/* }}} */
 
271
 
 
272
 
 
273
/* {{{ access string slots of request rec
 
274
 */
 
275
 
 
276
/* {{{ proto string ApacheRequest::filename([string new_filename])
 
277
 */
 
278
PHP_FUNCTION(apache_request_filename)
 
279
{
 
280
        apache_request_string_slot(offsetof(request_rec, filename), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
281
}
 
282
/* }}} */
 
283
 
 
284
/* {{{ proto string ApacheRequest::uri([string new_uri])
 
285
 */
 
286
PHP_FUNCTION(apache_request_uri)
 
287
{
 
288
        apache_request_string_slot(offsetof(request_rec, uri), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
289
}
 
290
/* }}} */
 
291
 
 
292
/* {{{ proto string ApacheRequest::unparsed_uri([string new_unparsed_uri])
 
293
 */
 
294
PHP_FUNCTION(apache_request_unparsed_uri)
 
295
{
 
296
        apache_request_string_slot(offsetof(request_rec, unparsed_uri), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
297
}
 
298
/* }}} */
 
299
 
 
300
/* {{{ proto string ApacheRequest::path_info([string new_path_info])
 
301
 */
 
302
PHP_FUNCTION(apache_request_path_info)
 
303
{
 
304
        apache_request_string_slot(offsetof(request_rec, path_info), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
305
}
 
306
/* }}} */
 
307
 
 
308
/* {{{ proto string ApacheRequest::args([string new_args])
 
309
 */
 
310
PHP_FUNCTION(apache_request_args)
 
311
{
 
312
        apache_request_string_slot(offsetof(request_rec, args), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
313
}
 
314
/* }}} */
 
315
 
 
316
/* {{{ proto string ApacheRequest::boundary()
 
317
 */
 
318
PHP_FUNCTION(apache_request_boundary)
 
319
{
 
320
        apache_request_read_string_slot(offsetof(request_rec, boundary), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
321
}
 
322
/* }}} */
 
323
 
 
324
 
 
325
/* {{{ proto string ApacheRequest::content_type([string new_type])
 
326
 */
 
327
PHP_FUNCTION(apache_request_content_type)
 
328
{
 
329
        apache_request_string_slot(offsetof(request_rec, content_type), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
330
}
 
331
/* }}} */
 
332
 
 
333
/* {{{ proto string ApacheRequest::content_encoding([string new_encoding])
 
334
 */
 
335
PHP_FUNCTION(apache_request_content_encoding)
 
336
{
 
337
        apache_request_string_slot(offsetof(request_rec, content_encoding), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
338
}
 
339
/* }}} */
 
340
 
 
341
/* {{{ proto string ApacheRequest::handler([string new_handler])
 
342
 */
 
343
PHP_FUNCTION(apache_request_handler)
 
344
{
 
345
        apache_request_string_slot(offsetof(request_rec, handler), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
346
}
 
347
/* }}} */
 
348
 
 
349
/* {{{ proto string ApacheRequest::the_request()
 
350
 */
 
351
PHP_FUNCTION(apache_request_the_request)
 
352
{
 
353
        apache_request_read_string_slot(offsetof(request_rec, the_request), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
354
}
 
355
/* }}} */
 
356
 
 
357
/* {{{ proto string ApacheRequest::protocol()
 
358
 */
 
359
PHP_FUNCTION(apache_request_protocol)
 
360
{
 
361
        apache_request_read_string_slot(offsetof(request_rec, protocol), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
362
}
 
363
/* }}} */
 
364
 
 
365
/* {{{ proto string ApacheRequest::hostname()
 
366
 */
 
367
PHP_FUNCTION(apache_request_hostname)
 
368
{
 
369
        apache_request_read_string_slot(offsetof(request_rec, hostname), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
370
}
 
371
/* }}} */
 
372
 
 
373
/* {{{ proto string ApacheRequest::status_line([string new_status_line])
 
374
 */
 
375
PHP_FUNCTION(apache_request_status_line)
 
376
{
 
377
        apache_request_string_slot(offsetof(request_rec, status_line), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
378
}
 
379
/* }}} */
 
380
 
 
381
/* {{{ proto string ApacheRequest::method()
 
382
 */
 
383
PHP_FUNCTION(apache_request_method)
 
384
{
 
385
        apache_request_read_string_slot(offsetof(request_rec, method), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
386
}
 
387
/* }}} */
 
388
 
 
389
/* }}} access string slots of request rec */
 
390
 
 
391
/* {{{ access int slots of request_rec
 
392
 */
 
393
 
 
394
/* {{{ proto int ApacheRequest::proto_num()
 
395
 */
 
396
PHP_FUNCTION(apache_request_proto_num)
 
397
{
 
398
        apache_request_read_int_slot(offsetof(request_rec, proto_num), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
399
}
 
400
/* }}} */
 
401
 
 
402
/* {{{ proto int ApacheRequest::assbackwards()
 
403
 */
 
404
PHP_FUNCTION(apache_request_assbackwards)
 
405
{
 
406
        apache_request_read_int_slot(offsetof(request_rec, assbackwards), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
407
}
 
408
/* }}} */
 
409
 
 
410
 
 
411
/* {{{ proto int ApacheRequest::proxyreq([int new_proxyreq])
 
412
 */
 
413
PHP_FUNCTION(apache_request_proxyreq)
 
414
{
 
415
        apache_request_int_slot(offsetof(request_rec, proxyreq), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
416
}
 
417
/* }}} */
 
418
 
 
419
/* {{{ proto int ApacheRequest::chunked()
 
420
 */
 
421
PHP_FUNCTION(apache_request_chunked)
 
422
{
 
423
        apache_request_read_int_slot(offsetof(request_rec, chunked), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
424
}
 
425
/* }}} */
 
426
 
 
427
 
 
428
/* {{{ proto int ApacheRequest::header_only()
 
429
 */
 
430
PHP_FUNCTION(apache_request_header_only)
 
431
{
 
432
        apache_request_read_int_slot(offsetof(request_rec, header_only), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
433
}
 
434
/* }}} */
 
435
 
 
436
/* {{{ proto int ApacheRequest::request_time()
 
437
 */
 
438
PHP_FUNCTION(apache_request_request_time)
 
439
{
 
440
        apache_request_read_int_slot(offsetof(request_rec, request_time), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
441
}
 
442
/* }}} */
 
443
 
 
444
/* {{{ proto int ApacheRequest::status([int new_status])
 
445
 */
 
446
PHP_FUNCTION(apache_request_status)
 
447
{
 
448
        apache_request_int_slot(offsetof(request_rec, status), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
449
}
 
450
/* }}} */
 
451
 
 
452
/* {{{ proto int ApacheRequest::method_number([int method_number])
 
453
 */
 
454
PHP_FUNCTION(apache_request_method_number)
 
455
{
 
456
        apache_request_read_int_slot(offsetof(request_rec, method_number), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
457
}
 
458
/* }}} */
 
459
 
 
460
/* {{{ proto int ApacheRequest::allowed([int allowed])
 
461
 */
 
462
PHP_FUNCTION(apache_request_allowed)
 
463
{
 
464
        apache_request_int_slot(offsetof(request_rec, allowed), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
465
}
 
466
/* }}} */
 
467
 
 
468
/* {{{ proto int ApacheRequest::bytes_sent()
 
469
 */
 
470
PHP_FUNCTION(apache_request_bytes_sent)
 
471
{
 
472
        apache_request_read_int_slot(offsetof(request_rec, bytes_sent), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
473
}
 
474
/* }}} */
 
475
 
 
476
/* {{{ proto int ApacheRequest::mtime()
 
477
 */
 
478
PHP_FUNCTION(apache_request_mtime)
 
479
{
 
480
        apache_request_read_int_slot(offsetof(request_rec, mtime), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
481
}
 
482
/* }}} */
 
483
 
 
484
/* {{{ proto int ApacheRequest::content_length([int new_content_length])
 
485
 */
 
486
PHP_FUNCTION(apache_request_content_length)
 
487
{
 
488
        zval *id, **zlen;
 
489
        request_rec *r;
 
490
 
 
491
        if (ZEND_NUM_ARGS() == 0) {
 
492
                apache_request_read_int_slot(offsetof(request_rec, clength), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
493
        }
 
494
        else if (ZEND_NUM_ARGS() > 1) {
 
495
                WRONG_PARAM_COUNT;
 
496
        }
 
497
        else {
 
498
                if (zend_get_parameters_ex(1, &zlen) == FAILURE) {
 
499
                        RETURN_FALSE;
 
500
                }
 
501
 
 
502
                APREQ_GET_REQUEST(id, r);
 
503
 
 
504
                convert_to_long_ex(zlen);
 
505
                (void)ap_set_content_length(r, Z_LVAL_PP(zlen));
 
506
                RETURN_TRUE;
 
507
        }
 
508
}
 
509
/* }}} */
 
510
 
 
511
/* {{{ proto int ApacheRequest::remaining()
 
512
 */
 
513
PHP_FUNCTION(apache_request_remaining)
 
514
{
 
515
        apache_request_read_int_slot(offsetof(request_rec, remaining), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
516
}
 
517
/* }}} */
 
518
 
 
519
/* {{{ proto int ApacheRequest::no_cache()
 
520
 */
 
521
PHP_FUNCTION(apache_request_no_cache)
 
522
{
 
523
        apache_request_int_slot(offsetof(request_rec, no_cache), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
524
}
 
525
/* }}} */
 
526
 
 
527
/* {{{ proto int ApacheRequest::no_local_copy()
 
528
 */
 
529
PHP_FUNCTION(apache_request_no_local_copy)
 
530
{
 
531
        apache_request_int_slot(offsetof(request_rec, no_local_copy), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
532
}
 
533
/* }}} */
 
534
 
 
535
/* {{{ proto int ApacheRequest::read_body()
 
536
 */
 
537
PHP_FUNCTION(apache_request_read_body)
 
538
{
 
539
        apache_request_int_slot(offsetof(request_rec, read_body), INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
540
}
 
541
/* }}} */
 
542
 
 
543
 
 
544
/* }}} access int slots of request_rec */
 
545
 
 
546
 
 
547
/* {{{ proto array apache_request_headers_in()
 
548
 * fetch all incoming request headers
 
549
 */
 
550
PHP_FUNCTION(apache_request_headers_in)
 
551
{
 
552
        zval *id;
 
553
        request_rec *r;
 
554
        
 
555
        APREQ_GET_REQUEST(id, r);
 
556
 
 
557
        apache_table_to_zval(r->headers_in, 0, return_value);
 
558
}
 
559
/* }}} */
 
560
 
 
561
 
 
562
/* {{{ add_header_to_table
 
563
*/
 
564
static void add_header_to_table(table *t, INTERNAL_FUNCTION_PARAMETERS)
 
565
{
 
566
        zval *first = NULL;
 
567
        zval *second = NULL;
 
568
        zval **entry, **value;
 
569
        char *string_key;
 
570
        uint string_key_len;
 
571
        ulong num_key;
 
572
        
 
573
        zend_bool replace = 0;
 
574
        HashPosition pos;
 
575
 
 
576
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zb", &first, &second, &replace) == FAILURE)
 
577
                RETURN_FALSE;
 
578
 
 
579
        if (Z_TYPE_P(first) == IS_ARRAY) {
 
580
                switch(ZEND_NUM_ARGS()) {
 
581
                        case 1:
 
582
                        case 3:
 
583
                                zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(first), &pos);
 
584
                                while (zend_hash_get_current_data_ex(Z_ARRVAL_P(first), (void **)&entry, &pos) == SUCCESS) {
 
585
                                        switch(zend_hash_get_current_key_ex(Z_ARRVAL_P(first), &string_key, &string_key_len, &num_key, 0, &pos)) {
 
586
                                                case HASH_KEY_IS_STRING:
 
587
                                                        if (zend_hash_find(Z_ARRVAL_P(first), string_key, string_key_len, (void **)&value) == FAILURE) {
 
588
                                                                zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos);
 
589
                                                                continue;
 
590
                                                        }
 
591
                                                        if (!value) {
 
592
                                                                zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos);
 
593
                                                                continue;
 
594
                                                        }
 
595
 
 
596
                                                        convert_to_string_ex(value);
 
597
                                                        if (replace)
 
598
                                                                ap_table_set(t, string_key, Z_STRVAL_PP(value));
 
599
                                                        else
 
600
                                                                ap_table_merge(t, string_key, Z_STRVAL_PP(value));
 
601
                                                        
 
602
                                                        break;
 
603
                                                case HASH_KEY_IS_LONG:
 
604
                                                default:
 
605
                                                        php_error(E_WARNING, "%s(): Can only add STRING keys to headers!", get_active_function_name(TSRMLS_C));
 
606
                                                        break;
 
607
                                        }
 
608
 
 
609
                                        zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos);
 
610
                                }
 
611
                                break;
 
612
                        default:
 
613
                                WRONG_PARAM_COUNT;
 
614
                                break;
 
615
                }
 
616
        }
 
617
        else if (Z_TYPE_P(first) == IS_STRING) {
 
618
                switch(ZEND_NUM_ARGS()) {
 
619
                        case 2:
 
620
                        case 3:
 
621
                                convert_to_string_ex(&second);
 
622
                                if (replace)
 
623
                                        ap_table_set(t, Z_STRVAL_P(first), Z_STRVAL_P(second));
 
624
                                else
 
625
                                        ap_table_merge(t, Z_STRVAL_P(first), Z_STRVAL_P(second));
 
626
                                break;
 
627
                        default:
 
628
                                WRONG_PARAM_COUNT;
 
629
                                break;
 
630
                }
 
631
        }
 
632
        else {
 
633
                RETURN_FALSE;
 
634
        }
 
635
}
 
636
 
 
637
/* }}} */
 
638
 
 
639
 
 
640
/* {{{ proto array apache_request_headers_out([{string name|array list} [, string value [, bool replace = false]]])
 
641
 * fetch all outgoing request headers
 
642
 */
 
643
PHP_FUNCTION(apache_request_headers_out)
 
644
{
 
645
        zval *id;
 
646
        request_rec *r;
 
647
        
 
648
        APREQ_GET_REQUEST(id, r);
 
649
 
 
650
        if (ZEND_NUM_ARGS() > 0)
 
651
                add_header_to_table(r->headers_out, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
652
 
 
653
        apache_table_to_zval(r->headers_out, 0, return_value);
 
654
}
 
655
/* }}} */
 
656
 
 
657
 
 
658
/* {{{ proto array apache_request_err_headers_out([{string name|array list} [, string value [, bool replace = false]]])
 
659
 * fetch all headers that go out in case of an error or a subrequest
 
660
 */
 
661
PHP_FUNCTION(apache_request_err_headers_out)
 
662
{
 
663
        zval *id;
 
664
        request_rec *r;
 
665
        
 
666
        APREQ_GET_REQUEST(id, r);
 
667
 
 
668
        if (ZEND_NUM_ARGS() > 0)
 
669
                add_header_to_table(r->err_headers_out, INTERNAL_FUNCTION_PARAM_PASSTHRU);
 
670
 
 
671
        apache_table_to_zval(r->err_headers_out, 0, return_value);
 
672
}
 
673
/* }}} */
 
674
 
 
675
 
 
676
/* {{{ proxy functions for the ap_* functions family
 
677
 */
 
678
 
 
679
/* {{{ proto int apache_request_server_port()
 
680
 */
 
681
PHP_FUNCTION(apache_request_server_port)
 
682
{
 
683
        zval *id;
 
684
        request_rec *r;
 
685
 
 
686
        if (ZEND_NUM_ARGS() > 0) {
 
687
                WRONG_PARAM_COUNT;
 
688
        }
 
689
 
 
690
        APREQ_GET_REQUEST(id, r);
 
691
 
 
692
        RETURN_LONG(ap_get_server_port(r));
 
693
}
 
694
/* }}} */
 
695
 
 
696
/* {{{ proto int apache_request_remote_host([int type])
 
697
 */
 
698
PHP_FUNCTION(apache_request_remote_host)
 
699
{
 
700
        zval *id, **ztype;
 
701
        request_rec *r;
 
702
        char *res;
 
703
        int type = REMOTE_NAME;
 
704
 
 
705
        switch (ZEND_NUM_ARGS()) {
 
706
                case 0:
 
707
                        break;
 
708
                case 1:
 
709
                        if (zend_get_parameters_ex(1, &ztype) == FAILURE) {
 
710
                                RETURN_FALSE;
 
711
                        }
 
712
                        convert_to_long_ex(ztype);
 
713
                        type = Z_LVAL_PP(ztype);
 
714
                        break;
 
715
                default:
 
716
                        WRONG_PARAM_COUNT;
 
717
                        break;
 
718
        }
 
719
 
 
720
 
 
721
        APREQ_GET_REQUEST(id, r);
 
722
 
 
723
        res = (char *)ap_get_remote_host(r->connection, r->per_dir_config, type);
 
724
        if (res)
 
725
                RETURN_STRING(res, 1);
 
726
 
 
727
        RETURN_EMPTY_STRING();
 
728
}
 
729
/* }}} */
 
730
 
 
731
/* {{{ proto long apache_request_update_mtime([int dependency_mtime])
 
732
 */
 
733
PHP_FUNCTION(apache_request_update_mtime)
 
734
{
 
735
        zval *id, **zmtime;
 
736
        request_rec *r;
 
737
        int mtime = 0;
 
738
 
 
739
        switch (ZEND_NUM_ARGS()) {
 
740
                case 0:
 
741
                        break;
 
742
                case 1:
 
743
                        if (zend_get_parameters_ex(1, &zmtime) == FAILURE) {
 
744
                                RETURN_FALSE;
 
745
                        }
 
746
                        convert_to_long_ex(zmtime);
 
747
                        mtime = Z_LVAL_PP(zmtime);
 
748
                        break;
 
749
                default:
 
750
                        WRONG_PARAM_COUNT;
 
751
                        break;
 
752
        }
 
753
 
 
754
 
 
755
        APREQ_GET_REQUEST(id, r);
 
756
 
 
757
        RETURN_LONG(ap_update_mtime(r, mtime));
 
758
}
 
759
/* }}} */
 
760
 
 
761
 
 
762
/* {{{ proto void apache_request_set_etag()
 
763
 */
 
764
PHP_FUNCTION(apache_request_set_etag)
 
765
{
 
766
        zval *id;
 
767
        request_rec *r;
 
768
 
 
769
        if (ZEND_NUM_ARGS() > 0) {
 
770
                WRONG_PARAM_COUNT;
 
771
        }
 
772
 
 
773
        APREQ_GET_REQUEST(id, r);
 
774
 
 
775
        ap_set_etag(r);
 
776
        RETURN_TRUE;
 
777
}
 
778
/* }}} */
 
779
 
 
780
/* {{{ proto void apache_request_set_last_modified()
 
781
 */
 
782
PHP_FUNCTION(apache_request_set_last_modified)
 
783
{
 
784
        zval *id;
 
785
        request_rec *r;
 
786
 
 
787
        if (ZEND_NUM_ARGS() > 0) {
 
788
                WRONG_PARAM_COUNT;
 
789
        }
 
790
 
 
791
        APREQ_GET_REQUEST(id, r);
 
792
 
 
793
        ap_set_last_modified(r);
 
794
        RETURN_TRUE;
 
795
}
 
796
/* }}} */
 
797
 
 
798
/* {{{ proto long apache_request_meets_conditions()
 
799
 */
 
800
PHP_FUNCTION(apache_request_meets_conditions)
 
801
{
 
802
        zval *id;
 
803
        request_rec *r;
 
804
 
 
805
        if (ZEND_NUM_ARGS() > 0) {
 
806
                WRONG_PARAM_COUNT;
 
807
        }
 
808
 
 
809
        APREQ_GET_REQUEST(id, r);
 
810
 
 
811
        RETURN_LONG(ap_meets_conditions(r));
 
812
}
 
813
/* }}} */
 
814
 
 
815
/* {{{ proto long apache_request_discard_request_body()
 
816
 */
 
817
PHP_FUNCTION(apache_request_discard_request_body)
 
818
{
 
819
        zval *id;
 
820
        request_rec *r;
 
821
 
 
822
        if (ZEND_NUM_ARGS() > 0) {
 
823
                WRONG_PARAM_COUNT;
 
824
        }
 
825
 
 
826
        APREQ_GET_REQUEST(id, r);
 
827
 
 
828
        RETURN_LONG(ap_discard_request_body(r));
 
829
}
 
830
/* }}} */
 
831
 
 
832
/* {{{ proto long apache_request_satisfies()
 
833
 */
 
834
PHP_FUNCTION(apache_request_satisfies)
 
835
{
 
836
        zval *id;
 
837
        request_rec *r;
 
838
 
 
839
        if (ZEND_NUM_ARGS() > 0) {
 
840
                WRONG_PARAM_COUNT;
 
841
        }
 
842
 
 
843
        APREQ_GET_REQUEST(id, r);
 
844
 
 
845
        RETURN_LONG(ap_satisfies(r));
 
846
}
 
847
/* }}} */
 
848
 
 
849
 
 
850
/* {{{ proto bool apache_request_is_initial_req()
 
851
 */
 
852
PHP_FUNCTION(apache_request_is_initial_req)
 
853
{
 
854
        zval *id;
 
855
        request_rec *r;
 
856
 
 
857
        if (ZEND_NUM_ARGS() > 0) {
 
858
                WRONG_PARAM_COUNT;
 
859
        }
 
860
 
 
861
        APREQ_GET_REQUEST(id, r);
 
862
 
 
863
        RETURN_BOOL(ap_is_initial_req(r));
 
864
}
 
865
/* }}} */
 
866
 
 
867
/* {{{ proto bool apache_request_some_auth_required()
 
868
 */
 
869
PHP_FUNCTION(apache_request_some_auth_required)
 
870
{
 
871
        zval *id;
 
872
        request_rec *r;
 
873
 
 
874
        if (ZEND_NUM_ARGS() > 0) {
 
875
                WRONG_PARAM_COUNT;
 
876
        }
 
877
 
 
878
        APREQ_GET_REQUEST(id, r);
 
879
 
 
880
        RETURN_BOOL(ap_some_auth_required(r));
 
881
}
 
882
/* }}} */
 
883
 
 
884
/* {{{ proto string apache_request_auth_type()
 
885
 */
 
886
PHP_FUNCTION(apache_request_auth_type)
 
887
{
 
888
        zval *id;
 
889
        request_rec *r;
 
890
        char *t;
 
891
 
 
892
        if (ZEND_NUM_ARGS() > 0) {
 
893
                WRONG_PARAM_COUNT;
 
894
        }
 
895
 
 
896
        APREQ_GET_REQUEST(id, r);
 
897
 
 
898
        t = (char *)ap_auth_type(r);
 
899
        if (!t)
 
900
                RETURN_NULL();
 
901
 
 
902
        RETURN_STRING(t, 1);
 
903
}
 
904
/* }}} */
 
905
 
 
906
/* {{{ proto string apache_request_auth_name()
 
907
 */
 
908
PHP_FUNCTION(apache_request_auth_name)
 
909
{
 
910
        zval *id;
 
911
        request_rec *r;
 
912
        char *t;
 
913
 
 
914
        if (ZEND_NUM_ARGS() > 0) {
 
915
                WRONG_PARAM_COUNT;
 
916
        }
 
917
 
 
918
        APREQ_GET_REQUEST(id, r);
 
919
 
 
920
        t = (char *)ap_auth_name(r);
 
921
        if (!t)
 
922
                RETURN_NULL();
 
923
 
 
924
        RETURN_STRING(t, 1);
 
925
}
 
926
/* }}} */
 
927
 
 
928
/* {{{ proto apache_request_basic_auth_pw()
 
929
 */
 
930
PHP_FUNCTION(apache_request_basic_auth_pw)
 
931
{
 
932
        zval *id, *zpw;
 
933
        request_rec *r;
 
934
        const char *pw;
 
935
        long status;
 
936
 
 
937
        if (ZEND_NUM_ARGS() != 1) {
 
938
                WRONG_PARAM_COUNT;
 
939
        }
 
940
 
 
941
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zpw) == FAILURE) {
 
942
            RETURN_NULL();
 
943
        }
 
944
 
 
945
        if (!PZVAL_IS_REF(zpw)) {
 
946
            zend_error(E_WARNING, "Parameter wasn't passed by reference");
 
947
            RETURN_NULL();
 
948
        }
 
949
 
 
950
 
 
951
        APREQ_GET_REQUEST(id, r);
 
952
 
 
953
        pw = NULL;
 
954
        status = ap_get_basic_auth_pw(r, &pw);
 
955
        if (status == OK && pw) {
 
956
                ZVAL_STRING(zpw, (char *)pw, 1);
 
957
        }
 
958
        else
 
959
                ZVAL_NULL(zpw);
 
960
        RETURN_LONG(status);
 
961
}
 
962
/* }}} */
 
963
 
 
964
 
 
965
/* http_protocol.h */
 
966
 
 
967
PHP_FUNCTION(apache_request_send_http_header)
 
968
{
 
969
    zval *id;
 
970
    request_rec *r;
 
971
    char *type = NULL;
 
972
    int typelen;
 
973
 
 
974
    if (zend_parse_parameters(ZEND_NUM_ARGS()  TSRMLS_CC, "|s", &type, &typelen) == FAILURE) 
 
975
        return;
 
976
    APREQ_GET_REQUEST(id, r);
 
977
    if(type) {
 
978
        r->content_type = pstrdup(r->pool, type);
 
979
    }
 
980
    ap_send_http_header(r);
 
981
    SG(headers_sent) = 1;
 
982
    AP(headers_sent) = 1;
 
983
    RETURN_TRUE;
 
984
}
 
985
 
 
986
PHP_FUNCTION(apache_request_basic_http_header)
 
987
{
 
988
    zval *id;
 
989
    request_rec *r;
 
990
 
 
991
    APREQ_GET_REQUEST(id, r);
 
992
 
 
993
    ap_basic_http_header((request_rec *)SG(server_context));
 
994
    SG(headers_sent) = 1;
 
995
    AP(headers_sent) = 1;
 
996
    RETURN_TRUE;
 
997
}
 
998
 
 
999
PHP_FUNCTION(apache_request_send_http_trace)
 
1000
{
 
1001
    zval *id;
 
1002
    request_rec *r;
 
1003
 
 
1004
    APREQ_GET_REQUEST(id, r);
 
1005
 
 
1006
    ap_send_http_trace((request_rec *)SG(server_context));
 
1007
    SG(headers_sent) = 1;
 
1008
    AP(headers_sent) = 1;
 
1009
    RETURN_TRUE;
 
1010
}
 
1011
 
 
1012
PHP_FUNCTION(apache_request_send_http_options)
 
1013
{
 
1014
    zval *id;
 
1015
    request_rec *r;
 
1016
 
 
1017
    APREQ_GET_REQUEST(id, r);
 
1018
 
 
1019
    ap_send_http_options((request_rec *)SG(server_context));
 
1020
    SG(headers_sent) = 1;
 
1021
    AP(headers_sent) = 1;
 
1022
    RETURN_TRUE;
 
1023
}
 
1024
 
 
1025
PHP_FUNCTION(apache_request_send_error_response)
 
1026
{
 
1027
    zval **recursive;
 
1028
    zval *id;
 
1029
    request_rec *r;
 
1030
    int rec;
 
1031
 
 
1032
    switch(ZEND_NUM_ARGS()) {
 
1033
        case 0:
 
1034
            rec = 0;
 
1035
            break;
 
1036
        case 1:
 
1037
            if(zend_get_parameters_ex(1, &recursive) == FAILURE) {
 
1038
                RETURN_FALSE;
 
1039
            }
 
1040
            convert_to_long_ex(recursive);
 
1041
            rec = Z_LVAL_PP(recursive);
 
1042
            break;
 
1043
        default:
 
1044
            WRONG_PARAM_COUNT;
 
1045
    }
 
1046
    APREQ_GET_REQUEST(id, r);
 
1047
    ap_send_error_response(r, rec);
 
1048
    RETURN_TRUE;
 
1049
}
 
1050
 
 
1051
PHP_FUNCTION(apache_request_set_content_length)
 
1052
{
 
1053
    zval **length;
 
1054
    zval *id;
 
1055
    request_rec *r;
 
1056
 
 
1057
    if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &length) == FAILURE) {
 
1058
        WRONG_PARAM_COUNT;
 
1059
    }
 
1060
    APREQ_GET_REQUEST(id, r);
 
1061
 
 
1062
    convert_to_long_ex(length);
 
1063
    ap_set_content_length(r, Z_LVAL_PP(length)); 
 
1064
    RETURN_TRUE;
 
1065
}
 
1066
 
 
1067
PHP_FUNCTION(apache_request_set_keepalive)
 
1068
{
 
1069
    zval *id;
 
1070
    request_rec *r;
 
1071
    APREQ_GET_REQUEST(id, r);
 
1072
    ap_set_keepalive(r);
 
1073
    RETURN_TRUE;
 
1074
}
 
1075
 
 
1076
/* This stuff should use streams or however this is implemented now
 
1077
 
 
1078
PHP_FUNCTION(apache_request_send_fd) 
 
1079
{
 
1080
}
 
1081
 
 
1082
PHP_FUNCTION(apache_request_send_fd_length)
 
1083
{
 
1084
}
 
1085
*/
 
1086
 
 
1087
/* These are for overriding default output behaviour */
 
1088
PHP_FUNCTION(apache_request_rputs)
 
1089
{
 
1090
    zval **buffer;
 
1091
    zval *id;
 
1092
    request_rec *r;
 
1093
 
 
1094
    if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &buffer) == FAILURE) {
 
1095
        WRONG_PARAM_COUNT;
 
1096
    }
 
1097
    APREQ_GET_REQUEST(id, r);
 
1098
    convert_to_string_ex(buffer);
 
1099
    ap_rwrite(Z_STRVAL_PP(buffer), Z_STRLEN_PP(buffer), (request_rec*)SG(server_context));
 
1100
}
 
1101
 
 
1102
/* This stuff would be useful for custom POST handlers, 
 
1103
   which should be supported.  Probably by not using
 
1104
   sapi_activate at all inside a phpResponseHandler
 
1105
   and instead using a builtin composed of the below
 
1106
   calls as a apache_read_request_body() and allow
 
1107
   people to custom craft their own.
 
1108
    
 
1109
PHP_FUNCTION(apache_request_setup_client_block)
 
1110
{
 
1111
}
 
1112
 
 
1113
PHP_FUNCTION(apache_request_should_client_block)
 
1114
{
 
1115
}
 
1116
 
 
1117
PHP_FUNCTION(apache_request_get_client_block)
 
1118
{
 
1119
}
 
1120
 
 
1121
PHP_FUNCTION(apache_request_discard_request_body)
 
1122
{
 
1123
}
 
1124
*/
 
1125
 
 
1126
/* http_log.h */
 
1127
 
 
1128
/* {{{ proto boolean apache_request_log_error(string message, [long facility])
 
1129
 */
 
1130
PHP_FUNCTION(apache_request_log_error)
 
1131
{
 
1132
    zval *id;
 
1133
    zval **z_errstr, **z_facility;
 
1134
    request_rec *r;
 
1135
    int facility = APLOG_ERR;
 
1136
 
 
1137
    switch(ZEND_NUM_ARGS()) {
 
1138
        case 1:
 
1139
            if(zend_get_parameters_ex(1, &z_errstr) == FAILURE) {
 
1140
                RETURN_FALSE;
 
1141
            }
 
1142
            break;
 
1143
        case 2:
 
1144
            if(zend_get_parameters_ex(1, &z_errstr, &z_facility) == FAILURE) {
 
1145
                RETURN_FALSE;
 
1146
            }
 
1147
            convert_to_long_ex(z_facility);
 
1148
            facility = Z_LVAL_PP(z_facility);
 
1149
            break;
 
1150
        default:
 
1151
            WRONG_PARAM_COUNT;
 
1152
            break;
 
1153
    }
 
1154
    APREQ_GET_REQUEST(id, r);
 
1155
    convert_to_string_ex(z_errstr);
 
1156
    ap_log_error(APLOG_MARK, facility, r->server, "%s", Z_STRVAL_PP(z_errstr));
 
1157
    RETURN_TRUE;
 
1158
}
 
1159
/* }}} */
 
1160
/* http_main.h */
 
1161
 
 
1162
/* {{{ proto object apache_request_sub_req_lookup_uri(string uri)
 
1163
    Returns sub-request for the specified uri.  You would
 
1164
    need to run it yourself with run()
 
1165
*/
 
1166
PHP_FUNCTION(apache_request_sub_req_lookup_uri)
 
1167
{
 
1168
    zval *id;
 
1169
    zval **file;
 
1170
    request_rec *r, *sub_r;
 
1171
    if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
 
1172
        WRONG_PARAM_COUNT;
 
1173
    }
 
1174
    APREQ_GET_REQUEST(id, r);
 
1175
    convert_to_string_ex(file);
 
1176
    sub_r = ap_sub_req_lookup_uri(Z_STRVAL_PP(file), r);
 
1177
    if(!sub_r) {
 
1178
        RETURN_FALSE;
 
1179
    }
 
1180
    return_value = php_apache_request_new(sub_r);
 
1181
}
 
1182
/* }}} */
 
1183
 
 
1184
/* {{{ proto object apache_request_sub_req_lookup_file(string file)
 
1185
    Returns sub-request for the specified file.  You would
 
1186
    need to run it yourself with run().
 
1187
*/
 
1188
PHP_FUNCTION(apache_request_sub_req_lookup_file)
 
1189
{
 
1190
    zval *id;
 
1191
    zval **file;
 
1192
    request_rec *r, *sub_r;
 
1193
 
 
1194
    if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
 
1195
        WRONG_PARAM_COUNT;
 
1196
    }
 
1197
    APREQ_GET_REQUEST(id, r);
 
1198
    convert_to_string_ex(file);
 
1199
    sub_r = ap_sub_req_lookup_file(Z_STRVAL_PP(file), r);
 
1200
    if(!sub_r) {
 
1201
        RETURN_FALSE;
 
1202
    }
 
1203
    return_value = php_apache_request_new(sub_r);
 
1204
}
 
1205
/* }}} */
 
1206
 
 
1207
/* {{{ proto object apache_request_sub_req_method_uri(string method, string uri)
 
1208
    Returns sub-request for the specified file.  You would
 
1209
    need to run it yourself with run().
 
1210
*/
 
1211
PHP_FUNCTION(apache_request_sub_req_method_uri)
 
1212
{
 
1213
    zval *id;
 
1214
    zval **file, **method;
 
1215
    request_rec *r, *sub_r;
 
1216
 
 
1217
    if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &method, &file) == FAILURE) {
 
1218
        WRONG_PARAM_COUNT;
 
1219
    }
 
1220
    APREQ_GET_REQUEST(id, r);
 
1221
    convert_to_string_ex(method);
 
1222
    convert_to_string_ex(file);
 
1223
    sub_r = ap_sub_req_method_uri(Z_STRVAL_PP(method),Z_STRVAL_PP(file), r);
 
1224
    if(!sub_r) {
 
1225
        RETURN_FALSE;
 
1226
    }
 
1227
    return_value = php_apache_request_new(sub_r);
 
1228
}
 
1229
/* }}} */
 
1230
 
 
1231
/* {{{ proto long apache_request_run()
 
1232
    This is a wrapper for ap_sub_run_req and ap_destory_sub_req.  It takes 
 
1233
    sub_request, runs it, destroys it, and returns it's status.
 
1234
*/
 
1235
PHP_FUNCTION(apache_request_run)
 
1236
{
 
1237
    zval *id;
 
1238
    request_rec *r;
 
1239
    int status;
 
1240
 
 
1241
    APREQ_GET_REQUEST(id, r);
 
1242
    if(!r || ap_is_initial_req(r))
 
1243
        RETURN_FALSE;
 
1244
    status = ap_run_sub_req(r);
 
1245
    ap_destroy_sub_req(r);
 
1246
    RETURN_LONG(status);
 
1247
}
 
1248
/* }}} */
 
1249
 
 
1250
PHP_FUNCTION(apache_request_internal_redirect)
 
1251
{
 
1252
    zval *id;
 
1253
    zval **new_uri;
 
1254
    request_rec *r;
 
1255
 
 
1256
    if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_uri) == FAILURE) {
 
1257
        WRONG_PARAM_COUNT;
 
1258
    }
 
1259
    APREQ_GET_REQUEST(id, r);
 
1260
    convert_to_string_ex(new_uri);
 
1261
    ap_internal_redirect(Z_STRVAL_PP(new_uri), r);
 
1262
}
 
1263
 
 
1264
PHP_FUNCTION(apache_request_send_header_field)
 
1265
{
 
1266
    zval **fieldname;
 
1267
    zval **fieldval;
 
1268
    zval *id;
 
1269
    request_rec *r;
 
1270
 
 
1271
    if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fieldname, &fieldval) == FAILURE) {
 
1272
        WRONG_PARAM_COUNT;
 
1273
    }
 
1274
    convert_to_string_ex(fieldname);
 
1275
    convert_to_string_ex(fieldval);
 
1276
    APREQ_GET_REQUEST(id, r);
 
1277
 
 
1278
    ap_send_header_field(r, Z_STRVAL_PP(fieldname), Z_STRVAL_PP(fieldval));
 
1279
    SG(headers_sent) = 1;
 
1280
    AP(headers_sent) = 1;
 
1281
}
 
1282
 
 
1283
 
 
1284
 
 
1285
/* }}} */
 
1286
 
 
1287
/* {{{ php_apache_request_class_functions
 
1288
 */
 
1289
static function_entry php_apache_request_class_functions[] = {
 
1290
        /* string slots */
 
1291
        PHP_FALIAS(args,                                                apache_request_args,                            NULL)
 
1292
        PHP_FALIAS(boundary,                                    apache_request_boundary,                        NULL)
 
1293
        PHP_FALIAS(content_encoding,                    apache_request_content_encoding,        NULL)
 
1294
        PHP_FALIAS(content_type,                                apache_request_content_type,            NULL)
 
1295
        PHP_FALIAS(filename,                                    apache_request_filename,                        NULL)
 
1296
        PHP_FALIAS(handler,                                             apache_request_handler,                         NULL)
 
1297
        PHP_FALIAS(hostname,                                    apache_request_hostname,                        NULL)
 
1298
        PHP_FALIAS(method,                                              apache_request_method,                          NULL)
 
1299
        PHP_FALIAS(path_info,                                   apache_request_path_info,                       NULL)
 
1300
        PHP_FALIAS(protocol,                                    apache_request_protocol,                        NULL)
 
1301
        PHP_FALIAS(status_line,                                 apache_request_status_line,                     NULL)
 
1302
        PHP_FALIAS(the_request,                                 apache_request_the_request,                     NULL)
 
1303
        PHP_FALIAS(unparsed_uri,                                apache_request_unparsed_uri,            NULL)
 
1304
        PHP_FALIAS(uri,                                                 apache_request_uri,                                     NULL)
 
1305
 
 
1306
        /* int slots */
 
1307
        PHP_FALIAS(allowed,                                             apache_request_allowed,                         NULL)
 
1308
        PHP_FALIAS(bytes_sent,                                  apache_request_bytes_sent,                      NULL)
 
1309
        PHP_FALIAS(chunked,                                             apache_request_chunked,                         NULL)
 
1310
        PHP_FALIAS(content_length,                              apache_request_content_length,          NULL)
 
1311
        PHP_FALIAS(header_only,                                 apache_request_header_only,                     NULL)
 
1312
        PHP_FALIAS(method_number,                               apache_request_method_number,           NULL)
 
1313
        PHP_FALIAS(mtime,                                               apache_request_mtime,                           NULL)
 
1314
        PHP_FALIAS(no_cache,                                    apache_request_no_cache,                        NULL)
 
1315
        PHP_FALIAS(no_local_copy,                               apache_request_no_local_copy,           NULL)
 
1316
        PHP_FALIAS(proto_num,                                   apache_request_proto_num,                       NULL)
 
1317
        PHP_FALIAS(proxyreq,                                    apache_request_proxyreq,                        NULL)
 
1318
        PHP_FALIAS(read_body,                                   apache_request_read_body,                       NULL)
 
1319
        PHP_FALIAS(remaining,                                   apache_request_remaining,                       NULL)
 
1320
        PHP_FALIAS(request_time,                                apache_request_request_time,            NULL)
 
1321
        PHP_FALIAS(status,                                              apache_request_status,                          NULL)
 
1322
 
 
1323
        /* tables & arrays */
 
1324
        PHP_FALIAS(headers_in,                                  apache_request_headers_in,                      NULL)
 
1325
        PHP_FALIAS(headers_out,                                 apache_request_headers_out,                     NULL)
 
1326
        PHP_FALIAS(err_headers_out,                             apache_request_err_headers_out,                 NULL)
 
1327
 
 
1328
 
 
1329
        /* proxy functions for the ap_* functions family */
 
1330
#undef auth_name
 
1331
#undef auth_type
 
1332
#undef discard_request_body
 
1333
#undef is_initial_req
 
1334
#undef meets_conditions
 
1335
#undef satisfies
 
1336
#undef set_etag
 
1337
#undef set_last_modified
 
1338
#undef some_auth_required
 
1339
#undef update_mtime
 
1340
#undef send_http_header
 
1341
#undef send_header_field
 
1342
#undef basic_http_header
 
1343
#undef send_http_trace
 
1344
#undef send_http_options
 
1345
#undef send_error_response
 
1346
#undef set_content_length
 
1347
#undef set_keepalive
 
1348
#undef rputs
 
1349
#undef log_error
 
1350
#undef lookup_uri
 
1351
#undef lookup_file
 
1352
#undef method_uri
 
1353
#undef run
 
1354
#undef internal_redirect
 
1355
        PHP_FALIAS(auth_name,                                   apache_request_auth_name,                               NULL)
 
1356
        PHP_FALIAS(auth_type,                                   apache_request_auth_type,                               NULL)
 
1357
        PHP_FALIAS(basic_auth_pw,                               apache_request_basic_auth_pw,                   NULL)
 
1358
        PHP_FALIAS(discard_request_body,                apache_request_discard_request_body,    NULL)
 
1359
        PHP_FALIAS(is_initial_req,                              apache_request_is_initial_req,                  NULL)
 
1360
        PHP_FALIAS(meets_conditions,                    apache_request_meets_conditions,                NULL)
 
1361
        PHP_FALIAS(remote_host,                                 apache_request_remote_host,                             NULL)
 
1362
        PHP_FALIAS(satisfies,                                   apache_request_satisfies,                               NULL)
 
1363
        PHP_FALIAS(server_port,                                 apache_request_server_port,                             NULL)
 
1364
        PHP_FALIAS(set_etag,                                    apache_request_set_etag,                                NULL)
 
1365
        PHP_FALIAS(set_last_modified,                   apache_request_set_last_modified,               NULL)
 
1366
        PHP_FALIAS(some_auth_required,                  apache_request_some_auth_required,              NULL)
 
1367
        PHP_FALIAS(update_mtime,                                apache_request_update_mtime,                    NULL)
 
1368
        PHP_FALIAS(send_http_header,                    apache_request_send_http_header,                NULL)
 
1369
        PHP_FALIAS(basic_http_header,                   apache_request_basic_http_header,               NULL)
 
1370
    PHP_FALIAS(send_header_field,           apache_request_send_header_field,       NULL)
 
1371
        PHP_FALIAS(send_http_trace,                         apache_request_send_http_trace,                 NULL)
 
1372
        PHP_FALIAS(send_http_options,                   apache_request_send_http_trace,             NULL)
 
1373
        PHP_FALIAS(send_error_response,                 apache_request_send_error_response,         NULL)
 
1374
    PHP_FALIAS(set_content_length,          apache_request_set_content_length,      NULL)
 
1375
    PHP_FALIAS(set_keepalive,               apache_request_set_keepalive,           NULL)
 
1376
    PHP_FALIAS(rputs,                       apache_request_rputs,                   NULL)
 
1377
    PHP_FALIAS(log_error,                   apache_request_log_error,               NULL)
 
1378
    PHP_FALIAS(lookup_uri,                  apache_request_sub_req_lookup_uri,      NULL)
 
1379
    PHP_FALIAS(lookup_file,                 apache_request_sub_req_lookup_file,     NULL)
 
1380
    PHP_FALIAS(method_uri,                  apache_request_sub_req_method_uri,      NULL)
 
1381
    PHP_FALIAS(run,                         apache_request_run,                     NULL)
 
1382
    PHP_FALIAS(internal_redirect,           apache_request_internal_redirect,       NULL)
 
1383
        { NULL, NULL, NULL }
 
1384
};
 
1385
/* }}} */
 
1386
 
 
1387
 
 
1388
static PHP_MINIT_FUNCTION(apache)
 
1389
{
 
1390
        zend_class_entry ce;
 
1391
 
 
1392
#ifdef ZTS
 
1393
        ts_allocate_id(&php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL);
 
1394
#else
 
1395
        php_apache_globals_ctor(&php_apache_info TSRMLS_CC);
 
1396
#endif
 
1397
        REGISTER_INI_ENTRIES();
 
1398
 
 
1399
 
 
1400
        le_apachereq = zend_register_list_destructors_ex(php_apache_request_free, NULL, "ApacheRequest", module_number);
 
1401
        INIT_OVERLOADED_CLASS_ENTRY(ce, "ApacheRequest", php_apache_request_class_functions, NULL, NULL, NULL);
 
1402
        apacherequest_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
 
1403
 
 
1404
        REGISTER_LONG_CONSTANT("OK",                            OK,                                     CONST_CS | CONST_PERSISTENT);
 
1405
        REGISTER_LONG_CONSTANT("DECLINED",                      DECLINED,                       CONST_CS | CONST_PERSISTENT);
 
1406
        REGISTER_LONG_CONSTANT("FORBIDDEN",                     FORBIDDEN,                      CONST_CS | CONST_PERSISTENT);
 
1407
        REGISTER_LONG_CONSTANT("AUTH_REQUIRED",         AUTH_REQUIRED,          CONST_CS | CONST_PERSISTENT);
 
1408
        REGISTER_LONG_CONSTANT("DONE",                          DONE,                           CONST_CS | CONST_PERSISTENT);
 
1409
        REGISTER_LONG_CONSTANT("SERVER_ERROR",          SERVER_ERROR,           CONST_CS | CONST_PERSISTENT);
 
1410
        REGISTER_LONG_CONSTANT("REDIRECT",                      REDIRECT,                       CONST_CS | CONST_PERSISTENT);
 
1411
        REGISTER_LONG_CONSTANT("BAD_REQUEST",           BAD_REQUEST,            CONST_CS | CONST_PERSISTENT);
 
1412
        REGISTER_LONG_CONSTANT("NOT_FOUND",                     NOT_FOUND,                      CONST_CS | CONST_PERSISTENT);
 
1413
    REGISTER_LONG_CONSTANT("HTTP_CONTINUE",     HTTP_CONTINUE,   CONST_CS | CONST_PERSISTENT);
 
1414
    REGISTER_LONG_CONSTANT("HTTP_SWITCHING_PROTOCOLS",     HTTP_SWITCHING_PROTOCOLS,   CONST_CS | CONST_PERSISTENT);
 
1415
    REGISTER_LONG_CONSTANT("HTTP_PROCESSING",     HTTP_PROCESSING,   CONST_CS | CONST_PERSISTENT);
 
1416
    REGISTER_LONG_CONSTANT("HTTP_OK",     HTTP_OK,   CONST_CS | CONST_PERSISTENT);
 
1417
    REGISTER_LONG_CONSTANT("HTTP_CREATED",     HTTP_CREATED,   CONST_CS | CONST_PERSISTENT);
 
1418
    REGISTER_LONG_CONSTANT("HTTP_ACCEPTED",     HTTP_ACCEPTED,   CONST_CS | CONST_PERSISTENT);
 
1419
    REGISTER_LONG_CONSTANT("HTTP_NON_AUTHORITATIVE",     HTTP_NON_AUTHORITATIVE,   CONST_CS | CONST_PERSISTENT);
 
1420
    REGISTER_LONG_CONSTANT("HTTP_NO_CONTENT",     HTTP_NO_CONTENT,   CONST_CS | CONST_PERSISTENT);
 
1421
    REGISTER_LONG_CONSTANT("HTTP_RESET_CONTENT",     HTTP_RESET_CONTENT,   CONST_CS | CONST_PERSISTENT);
 
1422
    REGISTER_LONG_CONSTANT("HTTP_PARTIAL_CONTENT",     HTTP_PARTIAL_CONTENT,   CONST_CS | CONST_PERSISTENT);
 
1423
    REGISTER_LONG_CONSTANT("HTTP_MULTI_STATUS",     HTTP_MULTI_STATUS,   CONST_CS | CONST_PERSISTENT);
 
1424
    REGISTER_LONG_CONSTANT("HTTP_MULTIPLE_CHOICES",     HTTP_MULTIPLE_CHOICES,   CONST_CS | CONST_PERSISTENT);
 
1425
    REGISTER_LONG_CONSTANT("HTTP_MOVED_PERMANENTLY",     HTTP_MOVED_PERMANENTLY,   CONST_CS | CONST_PERSISTENT);
 
1426
    REGISTER_LONG_CONSTANT("HTTP_MOVED_TEMPORARILY",     HTTP_MOVED_TEMPORARILY,   CONST_CS | CONST_PERSISTENT);
 
1427
    REGISTER_LONG_CONSTANT("HTTP_SEE_OTHER",     HTTP_SEE_OTHER,   CONST_CS | CONST_PERSISTENT);
 
1428
    REGISTER_LONG_CONSTANT("HTTP_NOT_MODIFIED",     HTTP_NOT_MODIFIED,   CONST_CS | CONST_PERSISTENT);
 
1429
    REGISTER_LONG_CONSTANT("HTTP_USE_PROXY",     HTTP_USE_PROXY,   CONST_CS | CONST_PERSISTENT);
 
1430
    REGISTER_LONG_CONSTANT("HTTP_TEMPORARY_REDIRECT",     HTTP_TEMPORARY_REDIRECT,   CONST_CS | CONST_PERSISTENT);
 
1431
    REGISTER_LONG_CONSTANT("HTTP_BAD_REQUEST",     HTTP_BAD_REQUEST,   CONST_CS | CONST_PERSISTENT);
 
1432
    REGISTER_LONG_CONSTANT("HTTP_UNAUTHORIZED",     HTTP_UNAUTHORIZED,   CONST_CS | CONST_PERSISTENT);
 
1433
    REGISTER_LONG_CONSTANT("HTTP_PAYMENT_REQUIRED",     HTTP_PAYMENT_REQUIRED,   CONST_CS | CONST_PERSISTENT);
 
1434
    REGISTER_LONG_CONSTANT("HTTP_FORBIDDEN",     HTTP_FORBIDDEN,   CONST_CS | CONST_PERSISTENT);
 
1435
    REGISTER_LONG_CONSTANT("HTTP_NOT_FOUND",     HTTP_NOT_FOUND,   CONST_CS | CONST_PERSISTENT);
 
1436
    REGISTER_LONG_CONSTANT("HTTP_METHOD_NOT_ALLOWED",     HTTP_METHOD_NOT_ALLOWED,   CONST_CS | CONST_PERSISTENT);
 
1437
    REGISTER_LONG_CONSTANT("HTTP_NOT_ACCEPTABLE",     HTTP_NOT_ACCEPTABLE,   CONST_CS | CONST_PERSISTENT);
 
1438
    REGISTER_LONG_CONSTANT("HTTP_PROXY_AUTHENTICATION_REQUIRED",     HTTP_PROXY_AUTHENTICATION_REQUIRED,   CONST_CS | CONST_PERSISTENT);
 
1439
    REGISTER_LONG_CONSTANT("HTTP_REQUEST_TIME_OUT",     HTTP_REQUEST_TIME_OUT,   CONST_CS | CONST_PERSISTENT);
 
1440
    REGISTER_LONG_CONSTANT("HTTP_CONFLICT",     HTTP_CONFLICT,   CONST_CS | CONST_PERSISTENT);
 
1441
    REGISTER_LONG_CONSTANT("HTTP_GONE",     HTTP_GONE,   CONST_CS | CONST_PERSISTENT);REGISTER_LONG_CONSTANT("HTTP_LENGTH_REQUIRED",     HTTP_LENGTH_REQUIRED,   CONST_CS | CONST_PERSISTENT);
 
1442
    REGISTER_LONG_CONSTANT("HTTP_PRECONDITION_FAILED",     HTTP_PRECONDITION_FAILED,   CONST_CS | CONST_PERSISTENT);
 
1443
    REGISTER_LONG_CONSTANT("HTTP_REQUEST_ENTITY_TOO_LARGE",     HTTP_REQUEST_ENTITY_TOO_LARGE,   CONST_CS | CONST_PERSISTENT);
 
1444
    REGISTER_LONG_CONSTANT("HTTP_REQUEST_URI_TOO_LARGE",     HTTP_REQUEST_URI_TOO_LARGE,   CONST_CS | CONST_PERSISTENT);
 
1445
    REGISTER_LONG_CONSTANT("HTTP_UNSUPPORTED_MEDIA_TYPE",     HTTP_UNSUPPORTED_MEDIA_TYPE,   CONST_CS | CONST_PERSISTENT);
 
1446
    REGISTER_LONG_CONSTANT("HTTP_RANGE_NOT_SATISFIABLE",     HTTP_RANGE_NOT_SATISFIABLE,   CONST_CS | CONST_PERSISTENT);
 
1447
    REGISTER_LONG_CONSTANT("HTTP_EXPECTATION_FAILED",     HTTP_EXPECTATION_FAILED,   CONST_CS | CONST_PERSISTENT);
 
1448
    REGISTER_LONG_CONSTANT("HTTP_UNPROCESSABLE_ENTITY",     HTTP_UNPROCESSABLE_ENTITY,   CONST_CS | CONST_PERSISTENT);
 
1449
    REGISTER_LONG_CONSTANT("HTTP_LOCKED",     HTTP_LOCKED,   CONST_CS | CONST_PERSISTENT);
 
1450
    REGISTER_LONG_CONSTANT("HTTP_FAILED_DEPENDENCY",     HTTP_FAILED_DEPENDENCY,   CONST_CS | CONST_PERSISTENT);
 
1451
    REGISTER_LONG_CONSTANT("HTTP_INTERNAL_SERVER_ERROR",     HTTP_INTERNAL_SERVER_ERROR,   CONST_CS | CONST_PERSISTENT);
 
1452
    REGISTER_LONG_CONSTANT("HTTP_NOT_IMPLEMENTED",     HTTP_NOT_IMPLEMENTED,   CONST_CS | CONST_PERSISTENT);
 
1453
    REGISTER_LONG_CONSTANT("HTTP_BAD_GATEWAY",     HTTP_BAD_GATEWAY,   CONST_CS | CONST_PERSISTENT);
 
1454
    REGISTER_LONG_CONSTANT("HTTP_SERVICE_UNAVAILABLE",     HTTP_SERVICE_UNAVAILABLE,   CONST_CS | CONST_PERSISTENT);
 
1455
    REGISTER_LONG_CONSTANT("HTTP_GATEWAY_TIME_OUT",     HTTP_GATEWAY_TIME_OUT,   CONST_CS | CONST_PERSISTENT);
 
1456
    REGISTER_LONG_CONSTANT("HTTP_VERSION_NOT_SUPPORTED",     HTTP_VERSION_NOT_SUPPORTED,   CONST_CS | CONST_PERSISTENT);
 
1457
    REGISTER_LONG_CONSTANT("HTTP_VARIANT_ALSO_VARIES",     HTTP_VARIANT_ALSO_VARIES,   CONST_CS | CONST_PERSISTENT);
 
1458
    REGISTER_LONG_CONSTANT("HTTP_INSUFFICIENT_STORAGE",     HTTP_INSUFFICIENT_STORAGE,   CONST_CS | CONST_PERSISTENT);
 
1459
    REGISTER_LONG_CONSTANT("HTTP_NOT_EXTENDED",     HTTP_NOT_EXTENDED,   CONST_CS | CONST_PERSISTENT);
 
1460
        REGISTER_LONG_CONSTANT("APLOG_EMERG",           APLOG_EMERG,            CONST_CS | CONST_PERSISTENT);
 
1461
        REGISTER_LONG_CONSTANT("APLOG_ALERT",           APLOG_ALERT,            CONST_CS | CONST_PERSISTENT);
 
1462
        REGISTER_LONG_CONSTANT("APLOG_CRIT",            APLOG_CRIT,                     CONST_CS | CONST_PERSISTENT);
 
1463
        REGISTER_LONG_CONSTANT("APLOG_ERR",                     APLOG_ERR,              CONST_CS | CONST_PERSISTENT);
 
1464
        REGISTER_LONG_CONSTANT("APLOG_WARNING",         APLOG_WARNING,          CONST_CS | CONST_PERSISTENT);
 
1465
        REGISTER_LONG_CONSTANT("APLOG_NOTICE",          APLOG_NOTICE,           CONST_CS | CONST_PERSISTENT);
 
1466
        REGISTER_LONG_CONSTANT("APLOG_INFO",            APLOG_INFO,                     CONST_CS | CONST_PERSISTENT);
 
1467
        REGISTER_LONG_CONSTANT("APLOG_DEBUG",           APLOG_DEBUG,            CONST_CS | CONST_PERSISTENT);
 
1468
        REGISTER_LONG_CONSTANT("M_GET",                         M_GET,                          CONST_CS | CONST_PERSISTENT);
 
1469
        REGISTER_LONG_CONSTANT("M_PUT",                         M_PUT,                          CONST_CS | CONST_PERSISTENT);
 
1470
        REGISTER_LONG_CONSTANT("M_POST",                        M_POST,                         CONST_CS | CONST_PERSISTENT);
 
1471
        REGISTER_LONG_CONSTANT("M_DELETE",                      M_DELETE,                       CONST_CS | CONST_PERSISTENT);
 
1472
        REGISTER_LONG_CONSTANT("M_CONNECT",                     M_CONNECT,                      CONST_CS | CONST_PERSISTENT);
 
1473
        REGISTER_LONG_CONSTANT("M_OPTIONS",                     M_OPTIONS,                      CONST_CS | CONST_PERSISTENT);
 
1474
        REGISTER_LONG_CONSTANT("M_TRACE",                       M_TRACE,                        CONST_CS | CONST_PERSISTENT);
 
1475
        REGISTER_LONG_CONSTANT("M_PATCH",                       M_PATCH,                        CONST_CS | CONST_PERSISTENT);
 
1476
        REGISTER_LONG_CONSTANT("M_PROPFIND",            M_PROPFIND,                     CONST_CS | CONST_PERSISTENT);
 
1477
        REGISTER_LONG_CONSTANT("M_PROPPATCH",           M_PROPPATCH,            CONST_CS | CONST_PERSISTENT);
 
1478
        REGISTER_LONG_CONSTANT("M_MKCOL",                       M_MKCOL,                        CONST_CS | CONST_PERSISTENT);
 
1479
        REGISTER_LONG_CONSTANT("M_COPY",                        M_COPY,                         CONST_CS | CONST_PERSISTENT);
 
1480
        REGISTER_LONG_CONSTANT("M_MOVE",                        M_MOVE,                         CONST_CS | CONST_PERSISTENT);
 
1481
        REGISTER_LONG_CONSTANT("M_LOCK",                        M_LOCK,                         CONST_CS | CONST_PERSISTENT);
 
1482
        REGISTER_LONG_CONSTANT("M_UNLOCK",                      M_UNLOCK,                       CONST_CS | CONST_PERSISTENT);
 
1483
        REGISTER_LONG_CONSTANT("M_INVALID",                     M_INVALID,                      CONST_CS | CONST_PERSISTENT);
 
1484
 
 
1485
        /* Possible values for request_rec.read_body (set by handling module):
 
1486
         *    REQUEST_NO_BODY          Send 413 error if message has any body
 
1487
         *    REQUEST_CHUNKED_ERROR    Send 411 error if body without Content-Length
 
1488
         *    REQUEST_CHUNKED_DECHUNK  If chunked, remove the chunks for me.
 
1489
         *    REQUEST_CHUNKED_PASS     Pass the chunks to me without removal.
 
1490
         */
 
1491
        REGISTER_LONG_CONSTANT("REQUEST_NO_BODY",                       REQUEST_NO_BODY,                        CONST_CS | CONST_PERSISTENT);
 
1492
        REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_ERROR",         REQUEST_CHUNKED_ERROR,          CONST_CS | CONST_PERSISTENT);
 
1493
        REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_DECHUNK",       REQUEST_CHUNKED_DECHUNK,        CONST_CS | CONST_PERSISTENT);
 
1494
        REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_PASS",          REQUEST_CHUNKED_PASS,           CONST_CS | CONST_PERSISTENT);
 
1495
        
 
1496
        /* resolve types for remote_host() */
 
1497
        REGISTER_LONG_CONSTANT("REMOTE_HOST",                   REMOTE_HOST,                    CONST_CS | CONST_PERSISTENT);
 
1498
        REGISTER_LONG_CONSTANT("REMOTE_NAME",                   REMOTE_NAME,                    CONST_CS | CONST_PERSISTENT);
 
1499
        REGISTER_LONG_CONSTANT("REMOTE_NOLOOKUP",               REMOTE_NOLOOKUP,                CONST_CS | CONST_PERSISTENT);
 
1500
        REGISTER_LONG_CONSTANT("REMOTE_DOUBLE_REV",             REMOTE_DOUBLE_REV,              CONST_CS | CONST_PERSISTENT);
 
1501
        
 
1502
        return SUCCESS;
 
1503
}
 
1504
 
 
1505
 
 
1506
static PHP_MSHUTDOWN_FUNCTION(apache)
 
1507
{
 
1508
        UNREGISTER_INI_ENTRIES();
 
1509
        return SUCCESS;
 
1510
}
 
1511
 
 
1512
zend_module_entry apache_module_entry = {
 
1513
        STANDARD_MODULE_HEADER,
 
1514
        "apache", 
 
1515
        apache_functions, 
 
1516
        PHP_MINIT(apache), 
 
1517
        PHP_MSHUTDOWN(apache), 
 
1518
        NULL, 
 
1519
        NULL, 
 
1520
        PHP_MINFO(apache), 
 
1521
        NO_VERSION_YET,
 
1522
        STANDARD_MODULE_PROPERTIES
 
1523
};
 
1524
 
 
1525
/* {{{ proto bool apache_child_terminate(void)
 
1526
   Terminate apache process after this request */
 
1527
PHP_FUNCTION(apache_child_terminate)
 
1528
{
 
1529
#ifndef MULTITHREAD
 
1530
        if (AP(terminate_child)) {
 
1531
                ap_child_terminate( ((request_rec *)SG(server_context)) );
 
1532
                RETURN_TRUE;
 
1533
        } else { /* tell them to get lost! */
 
1534
                php_error(E_WARNING, "apache.child_terminate is disabled");
 
1535
                RETURN_FALSE;
 
1536
        }
 
1537
#else
 
1538
                php_error(E_WARNING, "apache_child_terminate() is not supported in this build");
 
1539
                RETURN_FALSE;
 
1540
#endif
 
1541
}
 
1542
/* }}} */
 
1543
 
 
1544
/* {{{ proto string apache_note(string note_name [, string note_value])
 
1545
   Get and set Apache request notes */
 
1546
PHP_FUNCTION(apache_note)
 
1547
{
 
1548
        zval **arg_name, **arg_val;
 
1549
        char *note_val;
 
1550
        int arg_count = ZEND_NUM_ARGS();
 
1551
 
 
1552
        if (arg_count<1 || arg_count>2 ||
 
1553
                zend_get_parameters_ex(arg_count, &arg_name, &arg_val) ==FAILURE ) {
 
1554
                WRONG_PARAM_COUNT;
 
1555
        }
 
1556
        
 
1557
        convert_to_string_ex(arg_name);
 
1558
        note_val = (char *) table_get(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val);
 
1559
        
 
1560
        if (arg_count == 2) {
 
1561
                convert_to_string_ex(arg_val);
 
1562
                table_set(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val, (*arg_val)->value.str.val);
 
1563
        }
 
1564
 
 
1565
        if (note_val) {
 
1566
                RETURN_STRING(note_val, 1);
 
1567
        } else {
 
1568
                RETURN_FALSE;
 
1569
        }
 
1570
}
 
1571
/* }}} */
 
1572
 
 
1573
/* {{{ PHP_MINFO_FUNCTION
 
1574
 */
 
1575
PHP_MINFO_FUNCTION(apache)
 
1576
{
 
1577
        module *modp = NULL;
 
1578
        char output_buf[128];
 
1579
#if !defined(WIN32) && !defined(WINNT)
 
1580
        char name[64];
 
1581
        char modulenames[1024];
 
1582
        char *p;
 
1583
#endif
 
1584
        server_rec *serv;
 
1585
        extern char server_root[MAX_STRING_LEN];
 
1586
        extern uid_t user_id;
 
1587
        extern char *user_name;
 
1588
        extern gid_t group_id;
 
1589
        extern int max_requests_per_child;
 
1590
 
 
1591
        serv = ((request_rec *) SG(server_context))->server;
 
1592
 
 
1593
 
 
1594
        php_info_print_table_start();
 
1595
 
 
1596
#ifdef PHP_WIN32
 
1597
        php_info_print_table_row(1, "Apache for Windows 95/NT");
 
1598
        php_info_print_table_end();
 
1599
        php_info_print_table_start();
 
1600
#elif defined(NETWARE)
 
1601
        php_info_print_table_row(1, "Apache for NetWare");
 
1602
        php_info_print_table_end();
 
1603
        php_info_print_table_start();
 
1604
#else
 
1605
        php_info_print_table_row(2, "APACHE_INCLUDE", PHP_APACHE_INCLUDE);
 
1606
        php_info_print_table_row(2, "APACHE_TARGET", PHP_APACHE_TARGET);
 
1607
#endif
 
1608
 
 
1609
        php_info_print_table_row(2, "Apache Version", SERVER_VERSION);
 
1610
 
 
1611
#ifdef APACHE_RELEASE
 
1612
        sprintf(output_buf, "%d", APACHE_RELEASE);
 
1613
        php_info_print_table_row(2, "Apache Release", output_buf);
 
1614
#endif
 
1615
        sprintf(output_buf, "%d", MODULE_MAGIC_NUMBER);
 
1616
        php_info_print_table_row(2, "Apache API Version", output_buf);
 
1617
        sprintf(output_buf, "%s:%u", serv->server_hostname, serv->port);
 
1618
        php_info_print_table_row(2, "Hostname:Port", output_buf);
 
1619
#if !defined(WIN32) && !defined(WINNT)
 
1620
        sprintf(output_buf, "%s(%d)/%d", user_name, (int)user_id, (int)group_id);
 
1621
        php_info_print_table_row(2, "User/Group", output_buf);
 
1622
        sprintf(output_buf, "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests_per_child, serv->keep_alive ? "on":"off", serv->keep_alive_max);
 
1623
        php_info_print_table_row(2, "Max Requests", output_buf);
 
1624
#endif
 
1625
        sprintf(output_buf, "Connection: %d - Keep-Alive: %d", serv->timeout, serv->keep_alive_timeout);
 
1626
        php_info_print_table_row(2, "Timeouts", output_buf);
 
1627
#if !defined(WIN32) && !defined(WINNT)
 
1628
/*
 
1629
        This block seems to be working on NetWare; But it seems to be showing
 
1630
        all modules instead of just the loaded ones
 
1631
*/
 
1632
        php_info_print_table_row(2, "Server Root", server_root);
 
1633
 
 
1634
        strcpy(modulenames, "");
 
1635
        for(modp = top_module; modp; modp = modp->next) {
 
1636
                strlcpy(name, modp->name, sizeof(name));
 
1637
                if ((p = strrchr(name, '.'))) {
 
1638
                        *p='\0'; /* Cut off ugly .c extensions on module names */
 
1639
                }
 
1640
                strcat(modulenames, name);
 
1641
                if (modp->next) {
 
1642
                        strcat(modulenames, ", ");
 
1643
                }
 
1644
        }
 
1645
        php_info_print_table_row(2, "Loaded Modules", modulenames);
 
1646
#endif
 
1647
 
 
1648
        php_info_print_table_end();
 
1649
 
 
1650
        DISPLAY_INI_ENTRIES();
 
1651
 
 
1652
        {
 
1653
                register int i;
 
1654
                array_header *arr;
 
1655
                table_entry *elts;
 
1656
                request_rec *r;
 
1657
 
 
1658
                r = ((request_rec *) SG(server_context));
 
1659
                arr = table_elts(r->subprocess_env);
 
1660
                elts = (table_entry *)arr->elts;
 
1661
                
 
1662
                SECTION("Apache Environment");
 
1663
                php_info_print_table_start();   
 
1664
                php_info_print_table_header(2, "Variable", "Value");
 
1665
                for (i=0; i < arr->nelts; i++) {
 
1666
                        php_info_print_table_row(2, elts[i].key, elts[i].val);
 
1667
                }
 
1668
                php_info_print_table_end();     
 
1669
        }
 
1670
 
 
1671
        {
 
1672
                array_header *env_arr;
 
1673
                table_entry *env;
 
1674
                int i;
 
1675
                request_rec *r;
 
1676
                
 
1677
                r = ((request_rec *) SG(server_context));
 
1678
                SECTION("HTTP Headers Information");
 
1679
                php_info_print_table_start();
 
1680
                php_info_print_table_colspan_header(2, "HTTP Request Headers");
 
1681
                php_info_print_table_row(2, "HTTP Request", r->the_request);
 
1682
                env_arr = table_elts(r->headers_in);
 
1683
                env = (table_entry *)env_arr->elts;
 
1684
                for (i = 0; i < env_arr->nelts; ++i) {
 
1685
                        if (env[i].key && (!PG(safe_mode) || (PG(safe_mode) && strncasecmp(env[i].key, "authorization", 13)))) {
 
1686
                                php_info_print_table_row(2, env[i].key, env[i].val);
 
1687
                        }
 
1688
                }
 
1689
                php_info_print_table_colspan_header(2, "HTTP Response Headers");
 
1690
                env_arr = table_elts(r->headers_out);
 
1691
                env = (table_entry *)env_arr->elts;
 
1692
                for(i = 0; i < env_arr->nelts; ++i) {
 
1693
                        if (env[i].key) {
 
1694
                                php_info_print_table_row(2, env[i].key, env[i].val);
 
1695
                        }
 
1696
                }
 
1697
                php_info_print_table_end();
 
1698
        }
 
1699
}
 
1700
/* }}} */
 
1701
 
 
1702
/* {{{ proto bool virtual(string filename)
 
1703
   Perform an Apache sub-request */
 
1704
/* This function is equivalent to <!--#include virtual...-->
 
1705
 * in mod_include. It does an Apache sub-request. It is useful
 
1706
 * for including CGI scripts or .shtml files, or anything else
 
1707
 * that you'd parse through Apache (for .phtml files, you'd probably
 
1708
 * want to use <?Include>. This only works when PHP is compiled
 
1709
 * as an Apache module, since it uses the Apache API for doing
 
1710
 * sub requests.
 
1711
 */
 
1712
PHP_FUNCTION(virtual)
 
1713
{
 
1714
        pval **filename;
 
1715
        request_rec *rr = NULL;
 
1716
 
 
1717
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
 
1718
                WRONG_PARAM_COUNT;
 
1719
        }
 
1720
        convert_to_string_ex(filename);
 
1721
        
 
1722
        if (!(rr = sub_req_lookup_uri ((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
 
1723
                php_error(E_WARNING, "Unable to include '%s' - URI lookup failed", (*filename)->value.str.val);
 
1724
                if (rr) destroy_sub_req (rr);
 
1725
                RETURN_FALSE;
 
1726
        }
 
1727
 
 
1728
        if (rr->status != 200) {
 
1729
                php_error(E_WARNING, "Unable to include '%s' - error finding URI", (*filename)->value.str.val);
 
1730
                if (rr) destroy_sub_req (rr);
 
1731
                RETURN_FALSE;
 
1732
        }
 
1733
 
 
1734
        php_end_ob_buffers(1 TSRMLS_CC);
 
1735
        php_header(TSRMLS_C);
 
1736
 
 
1737
        if (run_sub_req(rr)) {
 
1738
                php_error(E_WARNING, "Unable to include '%s' - request execution failed", (*filename)->value.str.val);
 
1739
                if (rr) destroy_sub_req (rr);
 
1740
                RETURN_FALSE;
 
1741
        } else {
 
1742
                if (rr) destroy_sub_req (rr);
 
1743
                RETURN_TRUE;
 
1744
        }
 
1745
}
 
1746
/* }}} */
 
1747
 
 
1748
 
 
1749
/* {{{ apache_table_to_zval(table *, int safe_mode, zval *return_value)
 
1750
   Fetch all HTTP request headers */
 
1751
static void apache_table_to_zval(table *t, int safe_mode, zval *return_value)
 
1752
{
 
1753
    array_header *env_arr;
 
1754
    table_entry *tenv;
 
1755
    int i;
 
1756
        
 
1757
    array_init(return_value);
 
1758
    env_arr = table_elts(t);
 
1759
    tenv = (table_entry *)env_arr->elts;
 
1760
    for (i = 0; i < env_arr->nelts; ++i) {
 
1761
                if (!tenv[i].key ||
 
1762
                        (safe_mode && !strncasecmp(tenv[i].key, "authorization", 13))) {
 
1763
                        continue;
 
1764
                }
 
1765
                if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) {
 
1766
                        RETURN_FALSE;
 
1767
                }
 
1768
    }
 
1769
 
 
1770
}
 
1771
/* }}} */
 
1772
 
 
1773
 
 
1774
/* {{{ proto array getallheaders(void)
 
1775
*/
 
1776
/*  Alias for apache_request_headers() */
 
1777
/* }}} */
 
1778
 
 
1779
/* {{{ proto array apache_request_headers(void)
 
1780
   Fetch all HTTP request headers */
 
1781
PHP_FUNCTION(apache_request_headers)
 
1782
{
 
1783
        apache_table_to_zval(((request_rec *)SG(server_context))->headers_in, PG(safe_mode), return_value);
 
1784
}
 
1785
/* }}} */
 
1786
 
 
1787
/* {{{ proto array apache_response_headers(void)
 
1788
   Fetch all HTTP response headers */
 
1789
PHP_FUNCTION(apache_response_headers)
 
1790
{
 
1791
        apache_table_to_zval(((request_rec *) SG(server_context))->headers_out, 0, return_value);
 
1792
}
 
1793
/* }}} */
 
1794
 
 
1795
/* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top])
 
1796
   Set an Apache subprocess_env variable */
 
1797
PHP_FUNCTION(apache_setenv)
 
1798
{
 
1799
        int var_len, val_len, top=0;
 
1800
        char *var = NULL, *val = NULL;
 
1801
        request_rec *r = (request_rec *) SG(server_context);
 
1802
 
 
1803
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) {
 
1804
        RETURN_FALSE;
 
1805
        }
 
1806
 
 
1807
        while(top) {
 
1808
                if(r->prev) r = r->prev;
 
1809
                else break;
 
1810
        }
 
1811
 
 
1812
        ap_table_setn(r->subprocess_env, ap_pstrndup(r->pool, var, var_len), ap_pstrndup(r->pool, val, val_len));
 
1813
        RETURN_TRUE;
 
1814
}
 
1815
/* }}} */
 
1816
 
 
1817
/* {{{ proto object apache_lookup_uri(string URI)
 
1818
   Perform a partial request of the given URI to obtain information about it */
 
1819
PHP_FUNCTION(apache_lookup_uri)
 
1820
{
 
1821
        pval **filename;
 
1822
        request_rec *rr=NULL;
 
1823
 
 
1824
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
 
1825
                WRONG_PARAM_COUNT;
 
1826
        }
 
1827
        convert_to_string_ex(filename);
 
1828
 
 
1829
        if(!(rr = sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
 
1830
                php_error(E_WARNING, "URI lookup failed", (*filename)->value.str.val);
 
1831
                RETURN_FALSE;
 
1832
        }
 
1833
        object_init(return_value);
 
1834
        add_property_long(return_value,"status", rr->status);
 
1835
        if (rr->the_request) {
 
1836
                add_property_string(return_value,"the_request", rr->the_request, 1);
 
1837
        }
 
1838
        if (rr->status_line) {
 
1839
                add_property_string(return_value,"status_line", (char *)rr->status_line, 1);            
 
1840
        }
 
1841
        if (rr->method) {
 
1842
                add_property_string(return_value,"method", (char *)rr->method, 1);              
 
1843
        }
 
1844
        if (rr->content_type) {
 
1845
                add_property_string(return_value,"content_type", (char *)rr->content_type, 1);
 
1846
        }
 
1847
        if (rr->handler) {
 
1848
                add_property_string(return_value,"handler", (char *)rr->handler, 1);            
 
1849
        }
 
1850
        if (rr->uri) {
 
1851
                add_property_string(return_value,"uri", rr->uri, 1);
 
1852
        }
 
1853
        if (rr->filename) {
 
1854
                add_property_string(return_value,"filename", rr->filename, 1);
 
1855
        }
 
1856
        if (rr->path_info) {
 
1857
                add_property_string(return_value,"path_info", rr->path_info, 1);
 
1858
        }
 
1859
        if (rr->args) {
 
1860
                add_property_string(return_value,"args", rr->args, 1);
 
1861
        }
 
1862
        if (rr->boundary) {
 
1863
                add_property_string(return_value,"boundary", rr->boundary, 1);
 
1864
        }
 
1865
        add_property_long(return_value,"no_cache", rr->no_cache);
 
1866
        add_property_long(return_value,"no_local_copy", rr->no_local_copy);
 
1867
        add_property_long(return_value,"allowed", rr->allowed);
 
1868
        add_property_long(return_value,"sent_bodyct", rr->sent_bodyct);
 
1869
        add_property_long(return_value,"bytes_sent", rr->bytes_sent);
 
1870
        add_property_long(return_value,"byterange", rr->byterange);
 
1871
        add_property_long(return_value,"clength", rr->clength);
 
1872
 
 
1873
#if MODULE_MAGIC_NUMBER >= 19980324
 
1874
        if (rr->unparsed_uri) {
 
1875
                add_property_string(return_value,"unparsed_uri", rr->unparsed_uri, 1);
 
1876
        }
 
1877
        if(rr->mtime) {
 
1878
                add_property_long(return_value,"mtime", rr->mtime);
 
1879
        }
 
1880
#endif
 
1881
        if(rr->request_time) {
 
1882
                add_property_long(return_value,"request_time", rr->request_time);
 
1883
        }
 
1884
 
 
1885
        destroy_sub_req(rr);
 
1886
}
 
1887
/* }}} */
 
1888
 
 
1889
 
 
1890
#if 0
 
1891
This function is most likely a bad idea.  Just playing with it for now.
 
1892
 
 
1893
PHP_FUNCTION(apache_exec_uri)
 
1894
{
 
1895
        pval **filename;
 
1896
        request_rec *rr=NULL;
 
1897
        TSRMLS_FETCH();
 
1898
 
 
1899
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
 
1900
                WRONG_PARAM_COUNT;
 
1901
        }
 
1902
        convert_to_string_ex(filename);
 
1903
 
 
1904
        if(!(rr = ap_sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
 
1905
                php_error(E_WARNING, "URI lookup failed", (*filename)->value.str.val);
 
1906
                RETURN_FALSE;
 
1907
        }
 
1908
        RETVAL_LONG(ap_run_sub_req(rr));
 
1909
        ap_destroy_sub_req(rr);
 
1910
}
 
1911
#endif
 
1912
 
 
1913
/* {{{ proto string apache_get_version(void)
 
1914
   Fetch Apache version */
 
1915
PHP_FUNCTION(apache_get_version)
 
1916
{
 
1917
        char *apv = (char *) ap_get_server_version();
 
1918
 
 
1919
        if (apv && *apv) {
 
1920
                RETURN_STRING(apv, 1);
 
1921
        } else {
 
1922
                RETURN_FALSE;
 
1923
        }
 
1924
}
 
1925
/* }}} */
 
1926
 
 
1927
/* {{{ proto array apache_get_modules(void)
 
1928
   Get a list of loaded Apache modules */
 
1929
PHP_FUNCTION(apache_get_modules)
 
1930
{
 
1931
        int n;
 
1932
        char *p;
 
1933
        
 
1934
        array_init(return_value);
 
1935
        
 
1936
        for (n = 0; ap_loaded_modules[n]; ++n) {
 
1937
                char *s = (char *) ap_loaded_modules[n]->name;
 
1938
                if ((p = strchr(s, '.'))) {
 
1939
                        add_next_index_stringl(return_value, s, (p - s), 1);
 
1940
                } else {
 
1941
                        add_next_index_string(return_value, s, 1);
 
1942
                }       
 
1943
        }
 
1944
}
 
1945
/* }}} */
 
1946
 
 
1947
/*
 
1948
 * Local variables:
 
1949
 * tab-width: 4
 
1950
 * c-basic-offset: 4
 
1951
 * End:
 
1952
 * vim600: sw=4 ts=4 fdm=marker
 
1953
 * vim<600: sw=4 ts=4
 
1954
 */