remove strlist api
authorMichael Wallner <mike@php.net>
Tue, 17 Feb 2015 19:21:43 +0000 (20:21 +0100)
committerMichael Wallner <mike@php.net>
Tue, 17 Feb 2015 19:21:43 +0000 (20:21 +0100)
config9.m4
php_http_api.h
php_http_env.c
php_http_response_codes.h [new file with mode: 0644]
php_http_strlist.c [deleted file]
php_http_strlist.h [deleted file]

index 20e7d6c..af3d55f 100644 (file)
@@ -547,7 +547,6 @@ dnl ----
                php_http_options.c \
                php_http_params.c \
                php_http_querystring.c \
-               php_http_strlist.c \
                php_http_url.c \
                php_http_version.c \
        "
@@ -599,8 +598,9 @@ dnl ----
                php_http_options.h \
                php_http_params.h \
                php_http_querystring.h \
-               php_http_strlist.h \
+               php_http_response_codes.h \
                php_http_url.h \
+               php_http_utf8.h \
                php_http_version.h \
        "
        PHP_INSTALL_HEADERS(ext/http, $PHP_HTTP_HEADERS)
index 5bddb0c..712c8cb 100644 (file)
@@ -79,7 +79,6 @@ typedef int STATUS;
 #include "php_http.h"
 
 #include "php_http_buffer.h"
-#include "php_http_strlist.h"
 #include "php_http_misc.h"
 #include "php_http_options.h"
 
index 25759a6..6de5ecb 100644 (file)
@@ -580,100 +580,15 @@ STATUS php_http_env_set_response_header_value(long http_code, const char *name_s
        }
 }
 
-static PHP_HTTP_STRLIST(php_http_env_response_status) =
-       PHP_HTTP_STRLIST_ITEM("Continue")
-       PHP_HTTP_STRLIST_ITEM("Switching Protocols")
-       PHP_HTTP_STRLIST_ITEM("Processing")
-       PHP_HTTP_STRLIST_NEXT
-       PHP_HTTP_STRLIST_ITEM("OK")
-       PHP_HTTP_STRLIST_ITEM("Created")
-       PHP_HTTP_STRLIST_ITEM("Accepted")
-       PHP_HTTP_STRLIST_ITEM("Non-Authoritative Information")
-       PHP_HTTP_STRLIST_ITEM("No Content")
-       PHP_HTTP_STRLIST_ITEM("Reset Content")
-       PHP_HTTP_STRLIST_ITEM("Partial Content")
-       PHP_HTTP_STRLIST_ITEM("Multi-Status")
-       PHP_HTTP_STRLIST_ITEM("Already Reported")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("IM Used")
-       PHP_HTTP_STRLIST_NEXT
-       PHP_HTTP_STRLIST_ITEM("Multiple Choices")
-       PHP_HTTP_STRLIST_ITEM("Moved Permanently")
-       PHP_HTTP_STRLIST_ITEM("Found")
-       PHP_HTTP_STRLIST_ITEM("See Other")
-       PHP_HTTP_STRLIST_ITEM("Not Modified")
-       PHP_HTTP_STRLIST_ITEM("Use Proxy")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("Temporary Redirect")
-       PHP_HTTP_STRLIST_ITEM("Permanent Redirect")
-       PHP_HTTP_STRLIST_NEXT
-       PHP_HTTP_STRLIST_ITEM("Bad Request")
-       PHP_HTTP_STRLIST_ITEM("Unauthorized")
-       PHP_HTTP_STRLIST_ITEM("Payment Required")
-       PHP_HTTP_STRLIST_ITEM("Forbidden")
-       PHP_HTTP_STRLIST_ITEM("Not Found")
-       PHP_HTTP_STRLIST_ITEM("Method Not Allowed")
-       PHP_HTTP_STRLIST_ITEM("Not Acceptable")
-       PHP_HTTP_STRLIST_ITEM("Proxy Authentication Required")
-       PHP_HTTP_STRLIST_ITEM("Request Timeout")
-       PHP_HTTP_STRLIST_ITEM("Conflict")
-       PHP_HTTP_STRLIST_ITEM("Gone")
-       PHP_HTTP_STRLIST_ITEM("Length Required")
-       PHP_HTTP_STRLIST_ITEM("Precondition Failed")
-       PHP_HTTP_STRLIST_ITEM("Request Entity Too Large")
-       PHP_HTTP_STRLIST_ITEM("Request URI Too Long")
-       PHP_HTTP_STRLIST_ITEM("Unsupported Media Type")
-       PHP_HTTP_STRLIST_ITEM("Requested Range Not Satisfiable")
-       PHP_HTTP_STRLIST_ITEM("Expectation Failed")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("Unprocessible Entity")
-       PHP_HTTP_STRLIST_ITEM("Locked")
-       PHP_HTTP_STRLIST_ITEM("Failed Dependency")
-       PHP_HTTP_STRLIST_ITEM("(Reserved)")
-       PHP_HTTP_STRLIST_ITEM("Upgrade Required")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("Precondition Required")
-       PHP_HTTP_STRLIST_ITEM("Too Many Requests")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("Request Header Fields Too Large")
-       PHP_HTTP_STRLIST_NEXT
-       PHP_HTTP_STRLIST_ITEM("Internal Server Error")
-       PHP_HTTP_STRLIST_ITEM("Not Implemented")
-       PHP_HTTP_STRLIST_ITEM("Bad Gateway")
-       PHP_HTTP_STRLIST_ITEM("Service Unavailable")
-       PHP_HTTP_STRLIST_ITEM("Gateway Timeout")
-       PHP_HTTP_STRLIST_ITEM("HTTP Version Not Supported")
-       PHP_HTTP_STRLIST_ITEM("Variant Also Negotiates")
-       PHP_HTTP_STRLIST_ITEM("Insufficient Storage")
-       PHP_HTTP_STRLIST_ITEM("Loop Detected")
-       PHP_HTTP_STRLIST_ITEM("(Unused)")
-       PHP_HTTP_STRLIST_ITEM("Not Extended")
-       PHP_HTTP_STRLIST_ITEM("Network Authentication Required")
-       PHP_HTTP_STRLIST_STOP
-;
-
 const char *php_http_env_get_response_status_for_code(unsigned code)
 {
-       return php_http_strlist_find(php_http_env_response_status, 100, code);
+       switch (code) {
+#define PHP_HTTP_RESPONSE_CODE(c, s) case c: return s;
+#include "php_http_response_codes.h"
+#undef PHP_HTTP_RESPONSE_CODE
+       default:
+               return NULL;
+       }
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getRequestHeader, 0, 0, 0)
@@ -724,32 +639,29 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnv, getResponseStatusForCode)
 {
        long code;
+       const char *status;
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
                return;
        }
-       RETURN_STRING(php_http_env_get_response_status_for_code(code), 1);
+
+       if ((status = php_http_env_get_response_status_for_code(code))) {
+               RETURN_STRING(status, 1);
+       }
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseStatusForAllCodes, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnv, getResponseStatusForAllCodes)
 {
-       const char *s;
-       unsigned c;
-       php_http_strlist_iterator_t i;
-
        if (SUCCESS != zend_parse_parameters_none()) {
                return;
        }
 
        array_init(return_value);
-       for (   php_http_strlist_iterator_init(&i, php_http_env_response_status, 100);
-                       *(s = php_http_strlist_iterator_this(&i, &c));
-                       php_http_strlist_iterator_next(&i)
-       ) {
-               add_index_string(return_value, c, s, 1);
-       }
+#define PHP_HTTP_RESPONSE_CODE(code, status) add_index_string(return_value, code, status, 1);
+#include "php_http_response_codes.h"
+#undef PHP_HTTP_RESPONSE_CODE
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseHeader, 0, 0, 0)
diff --git a/php_http_response_codes.h b/php_http_response_codes.h
new file mode 100644 (file)
index 0000000..82157f9
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+    +--------------------------------------------------------------------+
+    | PECL :: http                                                       |
+    +--------------------------------------------------------------------+
+    | Redistribution and use in source and binary forms, with or without |
+    | modification, are permitted provided that the conditions mentioned |
+    | in the accompanying LICENSE file are met.                          |
+    +--------------------------------------------------------------------+
+    | Copyright (c) 2004-2015, Michael Wallner <mike@php.net>            |
+    +--------------------------------------------------------------------+
+*/
+
+#ifndef PHP_HTTP_RESPONSE_CODE
+#      define PHP_HTTP_RESPONSE_CODE(code, status)
+#endif
+
+PHP_HTTP_RESPONSE_CODE(100, "Continue")
+PHP_HTTP_RESPONSE_CODE(101, "Switching Protocols")
+PHP_HTTP_RESPONSE_CODE(102, "Processing")
+PHP_HTTP_RESPONSE_CODE(200, "OK")
+PHP_HTTP_RESPONSE_CODE(201, "Created")
+PHP_HTTP_RESPONSE_CODE(202, "Accepted")
+PHP_HTTP_RESPONSE_CODE(203, "Non-Authoritative Information")
+PHP_HTTP_RESPONSE_CODE(204, "No Content")
+PHP_HTTP_RESPONSE_CODE(205, "Reset Content")
+PHP_HTTP_RESPONSE_CODE(206, "Partial Content")
+PHP_HTTP_RESPONSE_CODE(207, "Multi-Status")
+PHP_HTTP_RESPONSE_CODE(208, "Already Reported")
+PHP_HTTP_RESPONSE_CODE(226, "IM Used")
+PHP_HTTP_RESPONSE_CODE(300, "Multiple Choices")
+PHP_HTTP_RESPONSE_CODE(301, "Moved Permanently")
+PHP_HTTP_RESPONSE_CODE(302, "Found")
+PHP_HTTP_RESPONSE_CODE(303, "See Other")
+PHP_HTTP_RESPONSE_CODE(304, "Not Modified")
+PHP_HTTP_RESPONSE_CODE(305, "Use Proxy")
+PHP_HTTP_RESPONSE_CODE(307, "Temporary Redirect")
+PHP_HTTP_RESPONSE_CODE(308, "Permanent Redirect")
+PHP_HTTP_RESPONSE_CODE(400, "Bad Request")
+PHP_HTTP_RESPONSE_CODE(401, "Unauthorized")
+PHP_HTTP_RESPONSE_CODE(402, "Payment Required")
+PHP_HTTP_RESPONSE_CODE(403, "Forbidden")
+PHP_HTTP_RESPONSE_CODE(404, "Not Found")
+PHP_HTTP_RESPONSE_CODE(405, "Method Not Allowed")
+PHP_HTTP_RESPONSE_CODE(406, "Not Acceptable")
+PHP_HTTP_RESPONSE_CODE(407, "Proxy Authentication Required")
+PHP_HTTP_RESPONSE_CODE(408, "Request Timeout")
+PHP_HTTP_RESPONSE_CODE(409, "Conflict")
+PHP_HTTP_RESPONSE_CODE(410, "Gone")
+PHP_HTTP_RESPONSE_CODE(411, "Length Required")
+PHP_HTTP_RESPONSE_CODE(412, "Precondition Failed")
+PHP_HTTP_RESPONSE_CODE(413, "Request Entity Too Large")
+PHP_HTTP_RESPONSE_CODE(414, "Request URI Too Long")
+PHP_HTTP_RESPONSE_CODE(415, "Unsupported Media Type")
+PHP_HTTP_RESPONSE_CODE(416, "Requested Range Not Satisfiable")
+PHP_HTTP_RESPONSE_CODE(417, "Expectation Failed")
+PHP_HTTP_RESPONSE_CODE(422, "Unprocessible Entity")
+PHP_HTTP_RESPONSE_CODE(423, "Locked")
+PHP_HTTP_RESPONSE_CODE(424, "Failed Dependency")
+PHP_HTTP_RESPONSE_CODE(426, "Upgrade Required")
+PHP_HTTP_RESPONSE_CODE(428, "Precondition Required")
+PHP_HTTP_RESPONSE_CODE(429, "Too Many Requests")
+PHP_HTTP_RESPONSE_CODE(431, "Request Header Fields Too Large")
+PHP_HTTP_RESPONSE_CODE(500, "Internal Server Error")
+PHP_HTTP_RESPONSE_CODE(501, "Not Implemented")
+PHP_HTTP_RESPONSE_CODE(502, "Bad Gateway")
+PHP_HTTP_RESPONSE_CODE(503, "Service Unavailable")
+PHP_HTTP_RESPONSE_CODE(504, "Gateway Timeout")
+PHP_HTTP_RESPONSE_CODE(505, "HTTP Version Not Supported")
+PHP_HTTP_RESPONSE_CODE(506, "Variant Also Negotiates")
+PHP_HTTP_RESPONSE_CODE(507, "Insufficient Storage")
+PHP_HTTP_RESPONSE_CODE(508, "Loop Detected")
+PHP_HTTP_RESPONSE_CODE(510, "Not Extended")
+PHP_HTTP_RESPONSE_CODE(511, "Network Authentication Required")
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
diff --git a/php_http_strlist.c b/php_http_strlist.c
deleted file mode 100644 (file)
index f457178..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
-    +--------------------------------------------------------------------+
-    | PECL :: http                                                       |
-    +--------------------------------------------------------------------+
-    | Redistribution and use in source and binary forms, with or without |
-    | modification, are permitted provided that the conditions mentioned |
-    | in the accompanying LICENSE file are met.                          |
-    +--------------------------------------------------------------------+
-    | Copyright (c) 2004-2014, Michael Wallner <mike@php.net>            |
-    +--------------------------------------------------------------------+
-*/
-
-#include "php_http_api.h"
-
-php_http_strlist_iterator_t *php_http_strlist_iterator_init(php_http_strlist_iterator_t *iter, const char list[], unsigned factor)
-{
-       if (!iter) {
-               iter = emalloc(sizeof(*iter));
-       }
-       memset(iter, 0, sizeof(*iter));
-
-       iter->p = &list[0];
-       iter->factor = factor;
-
-       return iter;
-}
-
-const char *php_http_strlist_iterator_this(php_http_strlist_iterator_t *iter, unsigned *id)
-{
-       if (id) {
-               *id = (iter->major + 1) * iter->factor + iter->minor;
-       }
-
-       return iter->p;
-}
-
-const char *php_http_strlist_iterator_next(php_http_strlist_iterator_t *iter)
-{
-       if (*iter->p) {
-               while (*iter->p) {
-                       ++iter->p;
-               }
-               ++iter->p;
-               ++iter->minor;
-
-               if (!*iter->p) {
-                       ++iter->p;
-                       ++iter->major;
-                       iter->minor = 0;
-               }
-       }
-
-    return iter->p;
-}
-
-void php_http_strlist_iterator_dtor(php_http_strlist_iterator_t *iter)
-{
-
-}
-
-void php_http_strlist_iterator_free(php_http_strlist_iterator_t **iter)
-{
-       if (*iter) {
-               efree(*iter);
-               *iter = NULL;
-       }
-}
-
-const char *php_http_strlist_find(const char list[], unsigned factor, unsigned item)
-{
-       unsigned M = 0, m = 0, major, minor;
-       const char *p = &list[0];
-
-       if (factor) {
-               major = (item / factor) - 1;
-               minor = item % factor;
-       } else {
-               major = 0;
-               minor = item;
-       }
-    while (*p && major != M++) {
-        while (*p) {
-            while (*p) {
-                ++p;
-            }
-            ++p;
-        }
-        ++p;
-    }
-
-    while (*p && minor != m++) {
-        while (*p) {
-            ++p;
-        }
-        ++p;
-    }
-
-    return p;
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: noet sw=4 ts=4 fdm=marker
- * vim<600: noet sw=4 ts=4
- */
-
diff --git a/php_http_strlist.h b/php_http_strlist.h
deleted file mode 100644 (file)
index 2685423..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-    +--------------------------------------------------------------------+
-    | PECL :: http                                                       |
-    +--------------------------------------------------------------------+
-    | Redistribution and use in source and binary forms, with or without |
-    | modification, are permitted provided that the conditions mentioned |
-    | in the accompanying LICENSE file are met.                          |
-    +--------------------------------------------------------------------+
-    | Copyright (c) 2004-2014, Michael Wallner <mike@php.net>            |
-    +--------------------------------------------------------------------+
-*/
-
-#ifndef PHP_HTTP_STRLIST_H
-#define PHP_HTTP_STRLIST_H
-
-#ifdef NUL
-#      undef NUL
-#endif
-#define NUL "\0"
-
-#define PHP_HTTP_STRLIST(name)                 const char name[]
-#define PHP_HTTP_STRLIST_ITEM(item)            item NUL
-#define PHP_HTTP_STRLIST_NEXT                  NUL
-#define PHP_HTTP_STRLIST_STOP                  NUL NUL
-
-PHP_HTTP_API const char *php_http_strlist_find(const char list[], unsigned factor, unsigned item);
-
-typedef struct php_http_strlist_iterator {
-       const char *p;
-       unsigned factor, major, minor;
-} php_http_strlist_iterator_t;
-
-PHP_HTTP_API php_http_strlist_iterator_t *php_http_strlist_iterator_init(php_http_strlist_iterator_t *iter, const char list[], unsigned factor);
-PHP_HTTP_API const char *php_http_strlist_iterator_this(php_http_strlist_iterator_t *iter, unsigned *id);
-PHP_HTTP_API const char *php_http_strlist_iterator_next(php_http_strlist_iterator_t *iter);
-PHP_HTTP_API void php_http_strlist_iterator_dtor(php_http_strlist_iterator_t *iter);
-PHP_HTTP_API void php_http_strlist_iterator_free(php_http_strlist_iterator_t **iter);
-
-#endif /* PHP_HTTP_STRLIST_H */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: noet sw=4 ts=4 fdm=marker
- * vim<600: noet sw=4 ts=4
- */
-