* add a real separator vs. a type juggler
authorMichael Wallner <mike@php.net>
Sat, 21 May 2011 15:25:40 +0000 (15:25 +0000)
committerMichael Wallner <mike@php.net>
Sat, 21 May 2011 15:25:40 +0000 (15:25 +0000)
* there's only http\Exception, saves a lot of useless exception classes

php_http_exception.c
php_http_exception.h
php_http_misc.c
php_http_misc.h

index e132df7480d853dd14a69e9f0ce5a81b03989c16..8b5800e2d4a08862a6599ee541407fa4f2115b0b 100644 (file)
 #      define PHP_HTTP_DBG_EXCEPTIONS 0
 #endif
 
-zend_class_entry *PHP_HTTP_EX_DEF_CE;
-zend_class_entry *PHP_HTTP_EX_CE(runtime);
-zend_class_entry *PHP_HTTP_EX_CE(header);
-zend_class_entry *PHP_HTTP_EX_CE(malformed_headers);
-zend_class_entry *PHP_HTTP_EX_CE(request_method);
-zend_class_entry *PHP_HTTP_EX_CE(message);
-zend_class_entry *PHP_HTTP_EX_CE(message_type);
-zend_class_entry *PHP_HTTP_EX_CE(message_body);
-zend_class_entry *PHP_HTTP_EX_CE(invalid_param);
-zend_class_entry *PHP_HTTP_EX_CE(encoding);
-zend_class_entry *PHP_HTTP_EX_CE(request);
-zend_class_entry *PHP_HTTP_EX_CE(request_pool);
-zend_class_entry *PHP_HTTP_EX_CE(request_datashare);
-zend_class_entry *PHP_HTTP_EX_CE(request_factory);
-zend_class_entry *PHP_HTTP_EX_CE(socket);
-zend_class_entry *PHP_HTTP_EX_CE(response);
-zend_class_entry *PHP_HTTP_EX_CE(url);
-zend_class_entry *PHP_HTTP_EX_CE(querystring);
-zend_class_entry *PHP_HTTP_EX_CE(cookie);
+zend_class_entry *php_http_exception_class_entry;
 
 zend_function_entry php_http_exception_method_entry[] = {
        EMPTY_FUNCTION_ENTRY
@@ -58,29 +40,27 @@ static void php_http_exception_hook(zval *ex TSRMLS_DC)
 
 PHP_MINIT_FUNCTION(http_exception)
 {
-       PHP_HTTP_REGISTER_EXCEPTION(Exception, PHP_HTTP_EX_DEF_CE, zend_exception_get_default(TSRMLS_C));
+       PHP_HTTP_REGISTER_EXCEPTION(Exception, php_http_exception_class_entry, zend_exception_get_default(TSRMLS_C));
        
-       PHP_HTTP_REGISTER_EXCEPTION(RuntimeException, PHP_HTTP_EX_CE(runtime), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(InvalidParamException, PHP_HTTP_EX_CE(invalid_param), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(HeaderException, PHP_HTTP_EX_CE(header), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(MalformedHeadersException, PHP_HTTP_EX_CE(malformed_headers), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(RequestMethodException, PHP_HTTP_EX_CE(request_method), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(MessageException, PHP_HTTP_EX_CE(message), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(MessageTypeException, PHP_HTTP_EX_CE(message_type), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(MessageBodyException, PHP_HTTP_EX_CE(message_body), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(EncodingException, PHP_HTTP_EX_CE(encoding), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(RequestException, PHP_HTTP_EX_CE(request), PHP_HTTP_EX_DEF_CE);
-
-       zend_declare_property_long(PHP_HTTP_EX_CE(request), "curlCode", lenof("curlCode"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
-
-       PHP_HTTP_REGISTER_EXCEPTION(RequestPoolException, PHP_HTTP_EX_CE(request_pool), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(RequestDataShareException, PHP_HTTP_EX_CE(request_datashare), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(RequestFactoryException, PHP_HTTP_EX_CE(request_factory), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(SocketException, PHP_HTTP_EX_CE(socket), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(ResponseException, PHP_HTTP_EX_CE(response), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(UrlException, PHP_HTTP_EX_CE(url), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(QueryStringException, PHP_HTTP_EX_CE(querystring), PHP_HTTP_EX_DEF_CE);
-       PHP_HTTP_REGISTER_EXCEPTION(CookieException, PHP_HTTP_EX_CE(cookie), PHP_HTTP_EX_DEF_CE);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_UNKNOWN"), PHP_HTTP_E_UNKNOWN TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_RUNTIME"), PHP_HTTP_E_RUNTIME TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_INVALID_PARAM"), PHP_HTTP_E_INVALID_PARAM TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_HEADER"), PHP_HTTP_E_HEADER TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_MALFORMED_HEADERS"), PHP_HTTP_E_MALFORMED_HEADERS TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_MESSAGE"), PHP_HTTP_E_MESSAGE TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_MESSAGE_TYPE"), PHP_HTTP_E_MESSAGE_TYPE TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_MESSAGE_BODY"), PHP_HTTP_E_MESSAGE_BODY TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_ENCODING"), PHP_HTTP_E_ENCODING TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_REQUEST"), PHP_HTTP_E_REQUEST TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_REQUEST_POOL"), PHP_HTTP_E_REQUEST_POOL TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_REQUEST_DATASHARE"), PHP_HTTP_E_REQUEST_DATASHARE TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_REQUEST_FACTORY"), PHP_HTTP_E_REQUEST_FACTORY TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_REQUEST_METHOD"), PHP_HTTP_E_REQUEST_METHOD TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_SOCKET"), PHP_HTTP_E_SOCKET TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_RESPONSE"), PHP_HTTP_E_RESPONSE TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_URL"), PHP_HTTP_E_URL TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_QUERYSTRING"), PHP_HTTP_E_QUERYSTRING TSRMLS_CC);
+       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_COOKIE"), PHP_HTTP_E_COOKIE TSRMLS_CC);
        
 #if PHP_HTTP_DBG_EXCEPTIONS
        zend_throw_exception_hook = php_http_exception_hook;
@@ -89,39 +69,6 @@ PHP_MINIT_FUNCTION(http_exception)
        return SUCCESS;
 }
 
-zend_class_entry *php_http_exception_get_default(void)
-{
-       return PHP_HTTP_EX_DEF_CE;
-}
-
-zend_class_entry *php_http_exception_get_for_code(long code)
-{
-       zend_class_entry *ex = PHP_HTTP_EX_DEF_CE;
-
-       switch (code) {
-               case PHP_HTTP_E_RUNTIME:                                        ex = PHP_HTTP_EX_CE(runtime);                                   break;
-               case PHP_HTTP_E_INVALID_PARAM:                          ex = PHP_HTTP_EX_CE(invalid_param);                             break;
-               case PHP_HTTP_E_HEADER:                                         ex = PHP_HTTP_EX_CE(header);                                    break;
-               case PHP_HTTP_E_MALFORMED_HEADERS:                      ex = PHP_HTTP_EX_CE(malformed_headers);                 break;
-               case PHP_HTTP_E_REQUEST_METHOD:                         ex = PHP_HTTP_EX_CE(request_method);                    break;
-               case PHP_HTTP_E_MESSAGE:                                        ex = PHP_HTTP_EX_CE(message);                                   break;
-               case PHP_HTTP_E_MESSAGE_TYPE:                           ex = PHP_HTTP_EX_CE(message_type);                              break;
-               case PHP_HTTP_E_MESSAGE_BODY:                           ex = PHP_HTTP_EX_CE(message_body);                              break;
-               case PHP_HTTP_E_ENCODING:                                       ex = PHP_HTTP_EX_CE(encoding);                                  break;
-               case PHP_HTTP_E_REQUEST:                                        ex = PHP_HTTP_EX_CE(request);                                   break;
-               case PHP_HTTP_E_REQUEST_POOL:                           ex = PHP_HTTP_EX_CE(request_pool);                              break;
-               case PHP_HTTP_E_REQUEST_DATASHARE:                      ex = PHP_HTTP_EX_CE(request_datashare);                 break;
-               case PHP_HTTP_E_REQUEST_FACTORY:                        ex = PHP_HTTP_EX_CE(request_factory);                   break;
-               case PHP_HTTP_E_SOCKET:                                         ex = PHP_HTTP_EX_CE(socket);                                    break;
-               case PHP_HTTP_E_RESPONSE:                                       ex = PHP_HTTP_EX_CE(response);                                  break;
-               case PHP_HTTP_E_URL:                                            ex = PHP_HTTP_EX_CE(url);                                               break;
-               case PHP_HTTP_E_QUERYSTRING:                            ex = PHP_HTTP_EX_CE(querystring);                               break;
-               case PHP_HTTP_E_COOKIE:                                         ex = PHP_HTTP_EX_CE(cookie);                                    break;
-       }
-
-       return ex;
-}
-
 /*
  * Local variables:
  * tab-width: 4
index 73c7c6d1800b142fcbabdb4df604e1f7044880e3..c461b1919070010770fc6ecebb9c080c4ed36f91 100644 (file)
 
 PHP_MINIT_FUNCTION(http_exception_object);
 
-#define PHP_HTTP_EX_DEF_CE php_http_exception_class_entry
-#define PHP_HTTP_EX_CE(name) php_http_ ##name## _exception_class_entry
-
-extern zend_class_entry *PHP_HTTP_EX_DEF_CE;
-extern zend_class_entry *PHP_HTTP_EX_CE(runtime);
-extern zend_class_entry *PHP_HTTP_EX_CE(header);
-extern zend_class_entry *PHP_HTTP_EX_CE(malformed_headers);
-extern zend_class_entry *PHP_HTTP_EX_CE(request_method);
-extern zend_class_entry *PHP_HTTP_EX_CE(message);
-extern zend_class_entry *PHP_HTTP_EX_CE(message_type);
-extern zend_class_entry *PHP_HTTP_EX_CE(invalid_param);
-extern zend_class_entry *PHP_HTTP_EX_CE(encoding);
-extern zend_class_entry *PHP_HTTP_EX_CE(request);
-extern zend_class_entry *PHP_HTTP_EX_CE(request_pool);
-extern zend_class_entry *PHP_HTTP_EX_CE(request_datashare);
-extern zend_class_entry *PHP_HTTP_EX_CE(request_factory);
-extern zend_class_entry *PHP_HTTP_EX_CE(socket);
-extern zend_class_entry *PHP_HTTP_EX_CE(response);
-extern zend_class_entry *PHP_HTTP_EX_CE(url);
-extern zend_class_entry *PHP_HTTP_EX_CE(querystring);
-extern zend_class_entry *PHP_HTTP_EX_CE(cookie);
+extern zend_class_entry *php_http_exception_class_entry;
 extern zend_function_entry php_http_exception_method_entry[];
 
-PHP_HTTP_API zend_class_entry *php_http_exception_get_default(void);
-PHP_HTTP_API zend_class_entry *php_http_exception_get_for_code(long code);
-
 PHP_MINIT_FUNCTION(http_exception);
 
 #endif
index b345eff6e20800e290a9d597101ffb760928c072..f52c9d6348b3b7839cf90105e1805baaba01adcf 100644 (file)
@@ -210,12 +210,10 @@ void php_http_error(long type TSRMLS_DC, long code, const char *format, ...)
        switch (scope_error_handling(type TSRMLS_CC)) {
                case EH_THROW: {
                        char *message;
-                       zend_class_entry *ce;
+                       zend_class_entry *ce = php_http_exception_class_entry;
 
                        if (0&& EG(exception_class) && instanceof_function(EG(exception_class), php_http_exception_class_entry)) {
                                ce = EG(exception_class);
-                       } else {
-                               ce = php_http_exception_get_for_code(code);
                        }
 
                        vspprintf(&message, 0, format, args);
index 7e5953031dffffc4e09db91a2c01eb79e03ebef0..a07f32fc83b835ccd6971088cc3837a9a8329a57 100644 (file)
@@ -158,7 +158,7 @@ static inline const char *php_http_locate_bin_eol(const char *bin, size_t len, i
                Z_ARRVAL_P(zv) = (ht); \
        }
 
-static inline zval *php_http_zsep(int type, zval *z)
+static inline zval *php_http_ztyp(int type, zval *z)
 {
        SEPARATE_ARG_IF_REF(z);
        if (Z_TYPE_P(z) != type) {
@@ -175,6 +175,26 @@ static inline zval *php_http_zsep(int type, zval *z)
        return z;
 }
 
+static inline zval *php_http_zsep(zend_bool add_ref, int type, zval *z) {
+       if (add_ref) {
+               Z_ADDREF_P(z);
+       }
+       if (Z_TYPE_P(z) != type) {
+               switch (type) {
+                       case IS_NULL:   convert_to_null_ex(&z);         break;
+                       case IS_BOOL:   convert_to_boolean_ex(&z);      break;
+                       case IS_LONG:   convert_to_long_ex(&z);         break;
+                       case IS_DOUBLE: convert_to_double_ex(&z);       break;
+                       case IS_STRING: convert_to_string_ex(&z);       break;
+                       case IS_ARRAY:  convert_to_array_ex(&z);        break;
+                       case IS_OBJECT: convert_to_object_ex(&z);       break;
+               }
+       } else {
+               SEPARATE_ZVAL_IF_NOT_REF(&z);
+       }
+       return z;
+}
+
 
 /* return bool (v == SUCCESS) */
 #define RETVAL_SUCCESS(v) RETVAL_BOOL(SUCCESS == (v))
@@ -332,6 +352,12 @@ static inline zval *php_http_zsep(int type, zval *z)
                                ZEND_ARG_PASS_INFO(0) \
                                ZEND_ARG_PASS_INFO(1) \
                        ZEND_END_ARG_INFO(); \
+\
+                       ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_3, 0) \
+                       ZEND_ARG_PASS_INFO(0) \
+                       ZEND_ARG_PASS_INFO(0) \
+                       ZEND_ARG_PASS_INFO(1) \
+                       ZEND_END_ARG_INFO(); \
 \
                        ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_4, 0) \
                                ZEND_ARG_PASS_INFO(0) \
@@ -413,6 +439,7 @@ extern void php_http_error(long type TSRMLS_DC, long code, const char *format, .
 #define HE_ERROR       E_ERROR TSRMLS_CC
 
 typedef enum php_http_error {
+       PHP_HTTP_E_UNKNOWN = 0,
        PHP_HTTP_E_RUNTIME,
        PHP_HTTP_E_INVALID_PARAM,
        PHP_HTTP_E_HEADER,