indeyets                Tue Nov 18 19:09:15 2008 UTC

  Modified files:              
    /php-src/sapi/apache_hooks  php_apache.c 
  Log:
  MFB: new parameter-parsing api
  
http://cvs.php.net/viewvc.cgi/php-src/sapi/apache_hooks/php_apache.c?r1=1.36&r2=1.37&diff_format=u
Index: php-src/sapi/apache_hooks/php_apache.c
diff -u php-src/sapi/apache_hooks/php_apache.c:1.36 
php-src/sapi/apache_hooks/php_apache.c:1.37
--- php-src/sapi/apache_hooks/php_apache.c:1.36 Mon Nov 17 11:26:25 2008
+++ php-src/sapi/apache_hooks/php_apache.c      Tue Nov 18 19:09:15 2008
@@ -17,7 +17,7 @@
    |          David Sklar <[EMAIL PROTECTED]>                             |
    +----------------------------------------------------------------------+
  */
-/* $Id: php_apache.c,v 1.36 2008/11/17 11:26:25 felipe Exp $ */
+/* $Id: php_apache.c,v 1.37 2008/11/18 19:09:15 indeyets Exp $ */
 
 #include "php_apache_http.h"
 
@@ -220,11 +220,16 @@
  */
 static void apache_request_string_slot(int offset, 
INTERNAL_FUNCTION_PARAMETERS)
 {
-       zval *id, **new_value;
+       zval *id;
        request_rec *r;
-       char *old_value;
+       char *old_value, *new_value;
+       int new_value_len;
        char **target;
 
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &new_value, 
&new_value_len) == FAILURE) {
+               return;
+       }
+
        APREQ_GET_REQUEST(id, r);
 
        target = (char **)((char*)r + offset);
@@ -234,11 +239,7 @@
                case 0:
                        break;
                case 1:
-                       if (zend_get_parameters_ex(1, &new_value) == FAILURE) {
-                               RETURN_FALSE;
-                       }
-                       convert_to_string_ex(new_value);
-                       *target = ap_pstrdup(r->pool, Z_STRVAL_PP(new_value));
+                       *target = ap_pstrdup(r->pool, new_value);
                        break;
                default:
                        WRONG_PARAM_COUNT;
@@ -276,11 +277,15 @@
  */
 static void apache_request_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
 {
-       zval *id, **new_value;
+       zval *id;
        request_rec *r;
-       long old_value;
+       long old_value, new_value;
        long *target;
 
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &new_value) 
== FAILURE) {
+               return;
+       }
+
        APREQ_GET_REQUEST(id, r);
 
        target = (long *)((char*)r + offset);
@@ -290,11 +295,7 @@
                case 0:
                        break;
                case 1:
-                       if (zend_get_parameters_ex(1, &new_value) == FAILURE) {
-                               RETURN_FALSE;
-                       }
-                       convert_to_long_ex(new_value);
-                       *target = Z_LVAL_PP(new_value);
+                       *target = new_value;
                        break;
                default:
                        WRONG_PARAM_COUNT;
@@ -521,24 +522,20 @@
  */
 PHP_FUNCTION(apache_request_content_length)
 {
-       zval *id, **zlen;
+       zval *id;
+       long zlen;
        request_rec *r;
 
-       if (ZEND_NUM_ARGS() == 0) {
-               apache_request_read_int_slot(offsetof(request_rec, clength), 
INTERNAL_FUNCTION_PARAM_PASSTHRU);
-       }
-       else if (ZEND_NUM_ARGS() > 1) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &zlen) == 
FAILURE) {
+               return;
        }
-       else {
-               if (zend_get_parameters_ex(1, &zlen) == FAILURE) {
-                       RETURN_FALSE;
-               }
 
+       if (ZEND_NUM_ARGS() == 0) {
+               apache_request_read_int_slot(offsetof(request_rec, clength), 
INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       } else {
                APREQ_GET_REQUEST(id, r);
 
-               convert_to_long_ex(zlen);
-               (void)ap_set_content_length(r, Z_LVAL_PP(zlen));
+               (void)ap_set_content_length(r, zlen);
                RETURN_TRUE;
        }
 }
@@ -733,23 +730,21 @@
  */
 PHP_FUNCTION(apache_request_remote_host)
 {
-       zval *id, **ztype;
+       zval *id;
+       long ztype;
        request_rec *r;
        char *res;
        int type = REMOTE_NAME;
 
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &ztype) == 
FAILURE) {
+               return;
+       }
+
        switch (ZEND_NUM_ARGS()) {
                case 0:
                        break;
                case 1:
-                       if (zend_get_parameters_ex(1, &ztype) == FAILURE) {
-                               RETURN_FALSE;
-                       }
-                       convert_to_long_ex(ztype);
-                       type = Z_LVAL_PP(ztype);
-                       break;
-               default:
-                       WRONG_PARAM_COUNT;
+                       type = ztype;
                        break;
        }
 
@@ -757,6 +752,7 @@
        APREQ_GET_REQUEST(id, r);
 
        res = (char *)ap_get_remote_host(r->connection, r->per_dir_config, 
type);
+
        if (res)
                RETURN_STRING(res, 1);
 
@@ -768,26 +764,14 @@
  */
 PHP_FUNCTION(apache_request_update_mtime)
 {
-       zval *id, **zmtime;
+       zval *id;
        request_rec *r;
        int mtime = 0;
 
-       switch (ZEND_NUM_ARGS()) {
-               case 0:
-                       break;
-               case 1:
-                       if (zend_get_parameters_ex(1, &zmtime) == FAILURE) {
-                               RETURN_FALSE;
-                       }
-                       convert_to_long_ex(zmtime);
-                       mtime = Z_LVAL_PP(zmtime);
-                       break;
-               default:
-                       WRONG_PARAM_COUNT;
-                       break;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &mtime) == 
FAILURE) {
+               return;
        }
 
-
        APREQ_GET_REQUEST(id, r);
 
        RETURN_LONG(ap_update_mtime(r, mtime));
@@ -1060,25 +1044,14 @@
 
 PHP_FUNCTION(apache_request_send_error_response)
 {
-    zval **recursive;
     zval *id;
     request_rec *r;
-    int rec;
+    int rec = 0;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &rec) == 
FAILURE) {
+               return;
+       }
 
-    switch(ZEND_NUM_ARGS()) {
-        case 0:
-            rec = 0;
-            break;
-        case 1:
-            if(zend_get_parameters_ex(1, &recursive) == FAILURE) {
-                RETURN_FALSE;
-            }
-            convert_to_long_ex(recursive);
-            rec = Z_LVAL_PP(recursive);
-            break;
-        default:
-            WRONG_PARAM_COUNT;
-    }
     APREQ_GET_REQUEST(id, r);
     ap_send_error_response(r, rec);
     RETURN_TRUE;
@@ -1086,17 +1059,17 @@
 
 PHP_FUNCTION(apache_request_set_content_length)
 {
-    zval **length;
+    int length;
     zval *id;
     request_rec *r;
 
-    if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &length) == FAILURE) {
-        WRONG_PARAM_COUNT;
-    }
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &length) == 
FAILURE) {
+               return;
+       }
+
     APREQ_GET_REQUEST(id, r);
 
-    convert_to_long_ex(length);
-    ap_set_content_length(r, Z_LVAL_PP(length)); 
+    ap_set_content_length(r, length);
     RETURN_TRUE;
 }
 
@@ -1123,16 +1096,17 @@
 /* These are for overriding default output behaviour */
 PHP_FUNCTION(apache_request_rputs)
 {
-    zval **buffer;
+    char *buffer;
+       int buffer_len;
     zval *id;
     request_rec *r;
 
-    if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &buffer) == FAILURE) {
-        WRONG_PARAM_COUNT;
-    }
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buffer, 
&buffer_len) == FAILURE) {
+               return;
+       }
+
     APREQ_GET_REQUEST(id, r);
-    convert_to_string_ex(buffer);
-    ap_rwrite(Z_STRVAL_PP(buffer), Z_STRLEN_PP(buffer), 
(request_rec*)SG(server_context));
+    ap_rwrite(buffer, buffer_len, (request_rec*)SG(server_context));
 }
 
 /* This stuff would be useful for custom POST handlers, 
@@ -1166,30 +1140,17 @@
 PHP_FUNCTION(apache_request_log_error)
 {
     zval *id;
-    zval **z_errstr, **z_facility;
-    request_rec *r;
+       char *z_errstr;
+       int z_errstr_len;
     int facility = APLOG_ERR;
+    request_rec *r;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &z_errstr, 
&z_errstr_len, &facility) == FAILURE) {
+               return;
+       }
 
-    switch(ZEND_NUM_ARGS()) {
-        case 1:
-            if(zend_get_parameters_ex(1, &z_errstr) == FAILURE) {
-                RETURN_FALSE;
-            }
-            break;
-        case 2:
-            if(zend_get_parameters_ex(1, &z_errstr, &z_facility) == FAILURE) {
-                RETURN_FALSE;
-            }
-            convert_to_long_ex(z_facility);
-            facility = Z_LVAL_PP(z_facility);
-            break;
-        default:
-            WRONG_PARAM_COUNT;
-            break;
-    }
     APREQ_GET_REQUEST(id, r);
-    convert_to_string_ex(z_errstr);
-    ap_log_error(APLOG_MARK, facility, r->server, "%s", Z_STRVAL_PP(z_errstr));
+    ap_log_error(APLOG_MARK, facility, r->server, "%s", z_errstr);
     RETURN_TRUE;
 }
 /* }}} */
@@ -1202,15 +1163,18 @@
 PHP_FUNCTION(apache_request_sub_req_lookup_uri)
 {
     zval *id;
-    zval **file;
+       char *file;
+       int file_len;
     request_rec *r, *sub_r;
-    if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
-        WRONG_PARAM_COUNT;
-    }
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, 
&file_len) == FAILURE) {
+               return;
+       }
+
     APREQ_GET_REQUEST(id, r);
-    convert_to_string_ex(file);
-    sub_r = ap_sub_req_lookup_uri(Z_STRVAL_PP(file), r);
-    if(!sub_r) {
+    sub_r = ap_sub_req_lookup_uri(file, r);
+
+    if (!sub_r) {
         RETURN_FALSE;
     }
     return_value = php_apache_request_new(sub_r);
@@ -1224,16 +1188,19 @@
 PHP_FUNCTION(apache_request_sub_req_lookup_file)
 {
     zval *id;
-    zval **file;
+       char *file;
+       int file_len;
     request_rec *r, *sub_r;
 
-    if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
-        WRONG_PARAM_COUNT;
-    }
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, 
&file_len) == FAILURE) {
+               return;
+       }
+
     APREQ_GET_REQUEST(id, r);
-    convert_to_string_ex(file);
-    sub_r = ap_sub_req_lookup_file(Z_STRVAL_PP(file), r);
-    if(!sub_r) {
+
+    sub_r = ap_sub_req_lookup_file(file, r);
+
+    if (!sub_r) {
         RETURN_FALSE;
     }
     return_value = php_apache_request_new(sub_r);
@@ -1247,17 +1214,19 @@
 PHP_FUNCTION(apache_request_sub_req_method_uri)
 {
     zval *id;
-    zval **file, **method;
+       char *file, *method;
+       int file_len, method_len;
     request_rec *r, *sub_r;
 
-    if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &method, &file) == 
FAILURE) {
-        WRONG_PARAM_COUNT;
-    }
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &method, 
&method_len, &file, &file_len) == FAILURE) {
+               return;
+       }
+
     APREQ_GET_REQUEST(id, r);
-    convert_to_string_ex(method);
-    convert_to_string_ex(file);
-    sub_r = ap_sub_req_method_uri(Z_STRVAL_PP(method),Z_STRVAL_PP(file), r);
-    if(!sub_r) {
+
+    sub_r = ap_sub_req_method_uri(method, file, r);
+
+    if (!sub_r) {
         RETURN_FALSE;
     }
     return_value = php_apache_request_new(sub_r);
@@ -1286,32 +1255,33 @@
 PHP_FUNCTION(apache_request_internal_redirect)
 {
     zval *id;
-    zval **new_uri;
+       char *new_uri;
+       int new_uri_len;
     request_rec *r;
 
-    if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_uri) == FAILURE) 
{
-        WRONG_PARAM_COUNT;
-    }
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &new_uri, 
&new_uri_len) == FAILURE) {
+               return;
+       }
+
     APREQ_GET_REQUEST(id, r);
-    convert_to_string_ex(new_uri);
-    ap_internal_redirect(Z_STRVAL_PP(new_uri), r);
+
+    ap_internal_redirect(new_uri, r);
 }
 
 PHP_FUNCTION(apache_request_send_header_field)
 {
-    zval **fieldname;
-    zval **fieldval;
+       char *fieldname, *fieldval;
+       int fieldname_len, fieldval_len;
     zval *id;
     request_rec *r;
 
-    if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fieldname, 
&fieldval) == FAILURE) {
-        WRONG_PARAM_COUNT;
-    }
-    convert_to_string_ex(fieldname);
-    convert_to_string_ex(fieldval);
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &fieldname, 
&fieldname_len, &fieldval, &fieldval_len) == FAILURE) {
+               return;
+       }
+
     APREQ_GET_REQUEST(id, r);
 
-    ap_send_header_field(r, Z_STRVAL_PP(fieldname), Z_STRVAL_PP(fieldval));
+    ap_send_header_field(r, fieldname, fieldval);
     SG(headers_sent) = 1;
     AP(headers_sent) = 1;
 }
@@ -1581,28 +1551,26 @@
    Get and set Apache request notes */
 PHP_FUNCTION(apache_note)
 {
-       zval **arg_name, **arg_val;
+       char *arg_name, *arg_val;
+       int arg_name_len, arg_val_len;
        char *note_val;
        int arg_count = ZEND_NUM_ARGS();
 
-       if (arg_count<1 || arg_count>2 ||
-               zend_get_parameters_ex(arg_count, &arg_name, &arg_val) 
==FAILURE ) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &arg_name, 
&arg_name_len, &arg_val, &arg_val_len) == FAILURE) {
+               return;
        }
-       
-       convert_to_string_ex(arg_name);
-       note_val = (char *) table_get(((request_rec 
*)SG(server_context))->notes, (*arg_name)->value.str.val);
+
+       note_val = (char *) table_get(((request_rec 
*)SG(server_context))->notes, arg_name);
        
        if (arg_count == 2) {
-               convert_to_string_ex(arg_val);
-               table_set(((request_rec *)SG(server_context))->notes, 
(*arg_name)->value.str.val, (*arg_val)->value.str.val);
+               table_set(((request_rec *)SG(server_context))->notes, arg_name, 
arg_val);
        }
 
-       if (note_val) {
-               RETURN_STRING(note_val, 1);
-       } else {
+       if (!note_val) {
                RETURN_FALSE;
        }
+
+       RETURN_STRING(note_val, 1);
 }
 /* }}} */
 
@@ -1747,23 +1715,25 @@
  */
 PHP_FUNCTION(virtual)
 {
-       zval **filename;
+       char *filename;
+       int filename_len;
        request_rec *rr = NULL;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == 
FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, 
&filename_len) == FAILURE) {
+               return;
        }
-       convert_to_string_ex(filename);
-       
-       if (!(rr = sub_req_lookup_uri ((*filename)->value.str.val, 
((request_rec *) SG(server_context))))) {
-               php_error(E_WARNING, "Unable to include '%s' - URI lookup 
failed", (*filename)->value.str.val);
-               if (rr) destroy_sub_req (rr);
+
+       if (!(rr = sub_req_lookup_uri (filename, ((request_rec *) 
SG(server_context))))) {
+               php_error(E_WARNING, "Unable to include '%s' - URI lookup 
failed", filename);
+               if (rr)
+                       destroy_sub_req (rr);
                RETURN_FALSE;
        }
 
        if (rr->status != 200) {
-               php_error(E_WARNING, "Unable to include '%s' - error finding 
URI", (*filename)->value.str.val);
-               if (rr) destroy_sub_req (rr);
+               php_error(E_WARNING, "Unable to include '%s' - error finding 
URI", filename);
+               if (rr)
+                       destroy_sub_req (rr);
                RETURN_FALSE;
        }
 
@@ -1771,13 +1741,15 @@
        php_header(TSRMLS_C);
 
        if (run_sub_req(rr)) {
-               php_error(E_WARNING, "Unable to include '%s' - request 
execution failed", (*filename)->value.str.val);
-               if (rr) destroy_sub_req (rr);
+               php_error(E_WARNING, "Unable to include '%s' - request 
execution failed", filename);
+               if (rr)
+                       destroy_sub_req (rr);
                RETURN_FALSE;
-       } else {
-               if (rr) destroy_sub_req (rr);
-               RETURN_TRUE;
-       }
+       } 
+
+       if (rr)
+               destroy_sub_req (rr);
+       RETURN_TRUE;
 }
 /* }}} */
 
@@ -1852,20 +1824,23 @@
    Perform a partial request of the given URI to obtain information about it */
 PHP_FUNCTION(apache_lookup_uri)
 {
-       zval **filename;
+       char *filename;
+       int filename_len;
        request_rec *rr=NULL;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == 
FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, 
&filename_len) == FAILURE) {
+               return;
        }
-       convert_to_string_ex(filename);
 
-       if(!(rr = sub_req_lookup_uri((*filename)->value.str.val, ((request_rec 
*) SG(server_context))))) {
-               php_error(E_WARNING, "URI lookup failed", 
(*filename)->value.str.val);
+
+       if(!(rr = sub_req_lookup_uri(filename, ((request_rec *) 
SG(server_context))))) {
+               php_error(E_WARNING, "URI lookup failed", filename);
                RETURN_FALSE;
        }
+
        object_init(return_value);
        add_property_long(return_value,"status", rr->status);
+
        if (rr->the_request) {
                add_property_string(return_value,"the_request", 
rr->the_request, 1);
        }

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to