Skip to content

Commit 0045cb3

Browse files
committed
updated to the new parameter-parsing api
1 parent 4776dfb commit 0045cb3

File tree

1 file changed

+69
-62
lines changed

1 file changed

+69
-62
lines changed

sapi/apache/php_apache.c

+69-62
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,26 @@ PHP_FUNCTION(apache_child_terminate)
141141
Get and set Apache request notes */
142142
PHP_FUNCTION(apache_note)
143143
{
144-
zval **arg_name, **arg_val;
145-
char *note_val;
144+
char *note_name, *note_val;
145+
long note_name_len, note_val_len;
146+
char *old_val;
146147
int arg_count = ZEND_NUM_ARGS();
147148

148-
if (arg_count<1 || arg_count>2 ||
149-
zend_get_parameters_ex(arg_count, &arg_name, &arg_val) ==FAILURE ) {
150-
WRONG_PARAM_COUNT;
149+
if (zend_parse_parameters(arg_count TSRMLS_CC, "s|s", &note_name, &note_name_len, &note_val, &note_val_len) == FAILURE) {
150+
return;
151151
}
152-
153-
convert_to_string_ex(arg_name);
154-
note_val = (char *) table_get(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val);
155-
152+
153+
old_val = (char *) table_get(((request_rec *)SG(server_context))->notes, note_name);
154+
156155
if (arg_count == 2) {
157-
convert_to_string_ex(arg_val);
158-
table_set(((request_rec *)SG(server_context))->notes, (*arg_name)->value.str.val, (*arg_val)->value.str.val);
156+
table_set(((request_rec *)SG(server_context))->notes, note_name, note_val);
159157
}
160158

161-
if (note_val) {
162-
RETURN_STRING(note_val, 1);
163-
} else {
164-
RETURN_FALSE;
159+
if (old_val) {
160+
RETURN_STRING(old_val, 1);
165161
}
162+
163+
RETURN_FALSE;
166164
}
167165
/* }}} */
168166

@@ -310,37 +308,42 @@ PHP_MINFO_FUNCTION(apache)
310308
*/
311309
PHP_FUNCTION(virtual)
312310
{
313-
zval **filename;
311+
char *filename;
312+
long filename_len;
314313
request_rec *rr = NULL;
315314

316-
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
317-
WRONG_PARAM_COUNT;
315+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
316+
return;
318317
}
319-
convert_to_string_ex(filename);
320318

321-
if (!(rr = sub_req_lookup_uri ((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
322-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", (*filename)->value.str.val);
323-
if (rr) destroy_sub_req (rr);
319+
if (!(rr = sub_req_lookup_uri (filename, ((request_rec *) SG(server_context))))) {
320+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", filename);
321+
if (rr)
322+
destroy_sub_req (rr);
324323
RETURN_FALSE;
325324
}
326325

327326
if (rr->status != 200) {
328-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", (*filename)->value.str.val);
329-
if (rr) destroy_sub_req (rr);
327+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", filename);
328+
if (rr)
329+
destroy_sub_req (rr);
330330
RETURN_FALSE;
331331
}
332332

333333
php_end_ob_buffers(1 TSRMLS_CC);
334334
php_header(TSRMLS_C);
335335

336336
if (run_sub_req(rr)) {
337-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", (*filename)->value.str.val);
338-
if (rr) destroy_sub_req (rr);
337+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", filename);
338+
if (rr)
339+
destroy_sub_req (rr);
339340
RETURN_FALSE;
340-
} else {
341-
if (rr) destroy_sub_req (rr);
342-
RETURN_TRUE;
343341
}
342+
343+
if (rr)
344+
destroy_sub_req (rr);
345+
346+
RETURN_TRUE;
344347
}
345348
/* }}} */
346349

@@ -351,14 +354,14 @@ PHP_FUNCTION(virtual)
351354
Fetch all HTTP request headers */
352355
PHP_FUNCTION(apache_request_headers)
353356
{
354-
array_header *env_arr;
355-
table_entry *tenv;
356-
int i;
357-
358-
array_init(return_value);
359-
env_arr = table_elts(((request_rec *) SG(server_context))->headers_in);
360-
tenv = (table_entry *)env_arr->elts;
361-
for (i = 0; i < env_arr->nelts; ++i) {
357+
array_header *env_arr;
358+
table_entry *tenv;
359+
int i;
360+
361+
array_init(return_value);
362+
env_arr = table_elts(((request_rec *) SG(server_context))->headers_in);
363+
tenv = (table_entry *)env_arr->elts;
364+
for (i = 0; i < env_arr->nelts; ++i) {
362365
if (!tenv[i].key ||
363366
(PG(safe_mode) &&
364367
!strncasecmp(tenv[i].key, "authorization", 13))) {
@@ -375,14 +378,14 @@ PHP_FUNCTION(apache_request_headers)
375378
Fetch all HTTP response headers */
376379
PHP_FUNCTION(apache_response_headers)
377380
{
378-
array_header *env_arr;
379-
table_entry *tenv;
380-
int i;
381-
382-
array_init(return_value);
383-
env_arr = table_elts(((request_rec *) SG(server_context))->headers_out);
384-
tenv = (table_entry *)env_arr->elts;
385-
for (i = 0; i < env_arr->nelts; ++i) {
381+
array_header *env_arr;
382+
table_entry *tenv;
383+
int i;
384+
385+
array_init(return_value);
386+
env_arr = table_elts(((request_rec *) SG(server_context))->headers_out);
387+
tenv = (table_entry *)env_arr->elts;
388+
for (i = 0; i < env_arr->nelts; ++i) {
386389
if (!tenv[i].key) continue;
387390
if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) {
388391
RETURN_FALSE;
@@ -395,13 +398,13 @@ PHP_FUNCTION(apache_response_headers)
395398
Set an Apache subprocess_env variable */
396399
PHP_FUNCTION(apache_setenv)
397400
{
398-
int var_len, val_len;
401+
long var_len, val_len;
399402
zend_bool top=0;
400403
char *var = NULL, *val = NULL;
401404
request_rec *r = (request_rec *) SG(server_context);
402405

403-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) {
404-
RETURN_FALSE;
406+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) {
407+
return;
405408
}
406409

407410
while(top) {
@@ -418,20 +421,22 @@ PHP_FUNCTION(apache_setenv)
418421
Perform a partial request of the given URI to obtain information about it */
419422
PHP_FUNCTION(apache_lookup_uri)
420423
{
421-
zval **filename;
424+
char *filename;
425+
long filename_len;
422426
request_rec *rr=NULL;
423427

424-
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
425-
WRONG_PARAM_COUNT;
428+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
429+
return;
426430
}
427-
convert_to_string_ex(filename);
428431

429-
if(!(rr = sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
430-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed '%s'", (*filename)->value.str.val);
432+
if (!(rr = sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) {
433+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed '%s'", filename);
431434
RETURN_FALSE;
432435
}
436+
433437
object_init(return_value);
434438
add_property_long(return_value,"status", rr->status);
439+
435440
if (rr->the_request) {
436441
add_property_string(return_value,"the_request", rr->the_request, 1);
437442
}
@@ -462,6 +467,7 @@ PHP_FUNCTION(apache_lookup_uri)
462467
if (rr->boundary) {
463468
add_property_string(return_value,"boundary", rr->boundary, 1);
464469
}
470+
465471
add_property_long(return_value,"no_cache", rr->no_cache);
466472
add_property_long(return_value,"no_local_copy", rr->no_local_copy);
467473
add_property_long(return_value,"allowed", rr->allowed);
@@ -492,19 +498,20 @@ This function is most likely a bad idea. Just playing with it for now.
492498

493499
PHP_FUNCTION(apache_exec_uri)
494500
{
495-
zval **filename;
501+
char *filename;
502+
long filename_len;
496503
request_rec *rr=NULL;
497504
TSRMLS_FETCH();
498505

499-
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
500-
WRONG_PARAM_COUNT;
506+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
507+
return;
501508
}
502-
convert_to_string_ex(filename);
503509

504-
if(!(rr = ap_sub_req_lookup_uri((*filename)->value.str.val, ((request_rec *) SG(server_context))))) {
505-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed", (*filename)->value.str.val);
510+
if(!(rr = ap_sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) {
511+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed", filename);
506512
RETURN_FALSE;
507513
}
514+
508515
RETVAL_LONG(ap_run_sub_req(rr));
509516
ap_destroy_sub_req(rr);
510517
}
@@ -518,9 +525,9 @@ PHP_FUNCTION(apache_get_version)
518525

519526
if (apv && *apv) {
520527
RETURN_STRING(apv, 1);
521-
} else {
522-
RETURN_FALSE;
523528
}
529+
530+
RETURN_FALSE;
524531
}
525532
/* }}} */
526533

0 commit comments

Comments
 (0)