]> granicus.if.org Git - php/commitdiff
convert to use new parameter parsing API.
authorAndrei Zmievski <andrei@php.net>
Fri, 19 Oct 2001 19:48:35 +0000 (19:48 +0000)
committerAndrei Zmievski <andrei@php.net>
Fri, 19 Oct 2001 19:48:35 +0000 (19:48 +0000)
ext/standard/head.c

index 7fe5bd4ce8038944b8d639011fd88c5462a58ff0..8794411af575cb83be5fa925d81deb66ef56826c 100644 (file)
    Sends a raw HTTP header */
 PHP_FUNCTION(header)
 {
-       pval **arg1, **arg2;
+       char *header;
+       int header_len;
        zend_bool replace = 1;
        
-       if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 
-                       || zend_get_parameters_ex(ZEND_NUM_ARGS(), &arg1, &arg2) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &header,
+                                                         &header_len, &replace) == FAILURE) {
+               return;
        }
-       switch (ZEND_NUM_ARGS()) {
-               case 2:
-                       convert_to_boolean_ex(arg2);
-                       replace = Z_BVAL_PP(arg2);
-               case 1:
-                       convert_to_string_ex(arg1);
-       }
-       sapi_add_header_ex(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1), 1, replace TSRMLS_CC);
+       sapi_add_header_ex(header, header_len, 1, replace TSRMLS_CC);
 }
 /* }}} */
 
@@ -71,67 +65,40 @@ PHPAPI int php_header()
 
 
 /* php_set_cookie(name, value, expires, path, domain, secure) */
-/* {{{ proto bool setcookie(string name [, string value [, int expires [, string path [, string domain [, string secure]]]]])
-   Sends a cookie */
+/* {{{ proto bool setcookie(string name [, string value [, int expires [, string path [, string domain [, bool secure]]]]])
+   Send a cookie */
 PHP_FUNCTION(setcookie)
 {
        char *cookie, *encoded_value = NULL;
+       char *name, *value = NULL, *path = NULL, *domain = NULL;
        int len=sizeof("Set-Cookie: ");
        time_t t;
        char *dt;
        time_t expires = 0;
-       int secure = 0;
-       pval **arg[6];
-       int arg_count;
-       zval **z_name=NULL, **z_value=NULL, **z_path=NULL, **z_domain=NULL;
-
-       arg_count = ZEND_NUM_ARGS();
-       if (arg_count < 1 || arg_count > 6 || zend_get_parameters_array_ex(arg_count, arg) == FAILURE) {
-               WRONG_PARAM_COUNT;
-       }
-       switch (arg_count) {
-               case 6:
-                       convert_to_boolean_ex(arg[5]);
-                       secure = Z_LVAL_PP(arg[5]);
-                       /* break missing intentionally */
-               case 5:
-                       convert_to_string_ex(arg[4]);
-                       z_domain = arg[4];
-                       /* break missing intentionally */
-               case 4:
-                       convert_to_string_ex(arg[3]);
-                       z_path = arg[3];
-                       /* break missing intentionally */
-               case 3:
-                       convert_to_long_ex(arg[2]);
-                       expires = Z_LVAL_PP(arg[2]);
-                       /* break missing intentionally */
-               case 2:
-                       convert_to_string_ex(arg[1]);
-                       z_value = arg[1];
-                       /* break missing intentionally */
-               case 1:
-                       convert_to_string_ex(arg[0]);
-                       z_name = arg[0];
-                       break;
-       }
-       if (z_name) {
-               len += Z_STRLEN_PP(z_name);
+       zend_bool secure = 0;
+       int name_len, value_len, path_len, domain_len;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|slssb", &name,
+                                                         &name_len, &value, &value_len, &expires, &path,
+                                                         &path_len, &domain, &domain_len, &secure) == FAILURE) {
+               return;
        }
-       if (z_value) {
+
+       len += name_len;
+       if (value) {
                int encoded_value_len;
 
-               encoded_value = php_url_encode(Z_STRVAL_PP(z_value), Z_STRLEN_PP(z_value), &encoded_value_len);
+               encoded_value = php_url_encode(value, value_len, &encoded_value_len);
                len += encoded_value_len;
        }
-       if (z_path) {
-               len += Z_STRLEN_PP(z_path);
+       if (path) {
+               len += path_len;
        }
-       if (z_domain) {
-               len += Z_STRLEN_PP(z_domain);
+       if (domain) {
+               len += domain_len;
        }
        cookie = emalloc(len + 100);
-       if (z_value && Z_STRLEN_PP(z_value)==0) {
+       if (value && value_len == 0) {
                /* 
                 * MSIE doesn't delete a cookie when you set it to a null value
                 * so in order to force cookies to be deleted, even on MSIE, we
@@ -139,10 +106,10 @@ PHP_FUNCTION(setcookie)
                 */
                t = time(NULL) - 31536001;
                dt = php_std_date(t);
-               sprintf(cookie, "Set-Cookie: %s=deleted; expires=%s", Z_STRVAL_PP(z_name), dt);
+               sprintf(cookie, "Set-Cookie: %s=deleted; expires=%s", name, dt);
                efree(dt);
        } else {
-               sprintf(cookie, "Set-Cookie: %s=%s", Z_STRVAL_PP(z_name), (z_value && Z_STRVAL_PP(z_value)) ? encoded_value : "");
+               sprintf(cookie, "Set-Cookie: %s=%s", name, value ? encoded_value : "");
                if (expires > 0) {
                        strcat(cookie, "; expires=");
                        dt = php_std_date(expires);
@@ -155,13 +122,13 @@ PHP_FUNCTION(setcookie)
                efree(encoded_value);
        }
 
-       if (z_path && Z_STRLEN_PP(z_path)>0) {
+       if (path && path_len > 0) {
                strcat(cookie, "; path=");
-               strcat(cookie, Z_STRVAL_PP(z_path));
+               strcat(cookie, path);
        }
-       if (z_domain && Z_STRLEN_PP(z_domain)>0) {
+       if (domain && domain_len > 0) {
                strcat(cookie, "; domain=");
-               strcat(cookie, Z_STRVAL_PP(z_domain));
+               strcat(cookie, domain);
        }
        if (secure) {
                strcat(cookie, "; secure");
@@ -181,7 +148,9 @@ PHP_FUNCTION(setcookie)
 PHP_FUNCTION(headers_sent)
 {
        if (ZEND_NUM_ARGS() != 0) {
-               WRONG_PARAM_COUNT;
+               php_error(E_WARNING, "%s() expects no parameters, %d given",
+                                 get_active_function_name(TSRMLS_C), ZEND_NUM_ARGS());
+               return;
        }
 
        if (SG(headers_sent)) {