/* send buffer size */
#define PHP_HTTP_SENDBUF_SIZE 40960
+/* allowed characters of header field names */
+#define PHP_HTTP_HEADER_NAME_CHARS "!#$%&'*+-.^_`|~1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+
/* SLEEP */
#define PHP_HTTP_DIFFSEC (0.001)
/* STRING UTILITIES */
-#ifndef STR_SET
-# define STR_SET(STR, SET) \
+#ifndef PTR_SET
+# define PTR_SET(STR, SET) \
{ \
- STR_FREE(STR); \
+ PTR_FREE(STR); \
STR = SET; \
}
#endif
#define PHP_HTTP_MATCH_STRICT (PHP_HTTP_MATCH_CASE|PHP_HTTP_MATCH_FULL)
int php_http_match(const char *haystack, const char *needle, int flags);
-char *php_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen);
+char *php_http_pretty_key(register char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen);
size_t php_http_boundary(char *buf, size_t len TSRMLS_DC);
int php_http_select_str(const char *cmp, int argc, ...);
-static inline const char *php_http_locate_str(const char *h, size_t h_len, const char *n, size_t n_len)
+/* See "A Reusable Duff Device" By Ralf Holly, August 01, 2005 */
+#define PHP_HTTP_DUFF_BREAK() times_=1
+#define PHP_HTTP_DUFF(c, a) do { \
+ size_t count_ = (c); \
+ size_t times_ = (count_ + 7) >> 3; \
+ switch (count_ & 7){ \
+ case 0: do { \
+ a; \
+ case 7: \
+ a; \
+ case 6: \
+ a; \
+ case 5: \
+ a; \
+ case 4: \
+ a; \
+ case 3: \
+ a; \
+ case 2: \
+ a; \
+ case 1: \
+ a; \
+ } while (--times_ > 0); \
+ } \
+} while (0)
+
+static inline const char *php_http_locate_str(register const char *h, size_t h_len, const char *n, size_t n_len)
{
- const char *p, *e;
-
- if (n_len && h_len) {
- e = h + h_len;
- do {
- if (*h == *n) {
- for (p = n; *p == h[p-n]; ++p) {
- if (p == n+n_len-1) {
- return h;
- }
- }
- }
- } while (h++ != e);
+ if (!n_len || !h_len || h_len < n_len) {
+ return NULL;
}
+ PHP_HTTP_DUFF(h_len - n_len + 1,
+ if (*h == *n && !strncmp(h + 1, n + 1, n_len - 1)) {
+ return h;
+ }
+ ++h;
+ );
+
return NULL;
}
static inline const char *php_http_locate_bin_eol(const char *bin, size_t len, int *eol_len)
{
- const char *eol;
+ register const char *eol = bin;
- for (eol = bin; eol - bin < len; ++eol) {
- if (*eol == '\r' || *eol == '\n') {
- if (eol_len) {
- *eol_len = ((eol[0] == '\r' && eol[1] == '\n') ? 2 : 1);
+ if (len > 0) {
+ PHP_HTTP_DUFF(len,
+ if (*eol == '\r' || *eol == '\n') {
+ if (eol_len) {
+ *eol_len = ((eol[0] == '\r' && eol[1] == '\n') ? 2 : 1);
+ }
+ return eol;
}
- return eol;
- }
+ ++eol;
+ );
}
-
return NULL;
}
# define PHP_HTTP_ZEND_LITERAL_CCN , NULL
#endif
+#if PHP_VERSION_ID < 50500
+#undef SUCCESS
+#undef FAILURE
+typedef enum {
+ SUCCESS = 0,
+ FAILURE = -1
+} ZEND_RESULT_CODE;
+#endif
+
#if PHP_VERSION_ID < 50700
# define z_is_true zend_is_true
#else
}
}
-static inline STATUS php_http_ini_entry(const char *name_str, size_t name_len, const char **value_str, size_t *value_len, zend_bool orig TSRMLS_DC)
+static inline ZEND_RESULT_CODE php_http_ini_entry(const char *name_str, size_t name_len, const char **value_str, size_t *value_len, zend_bool orig TSRMLS_DC)
{
zend_ini_entry *ini_entry;
static inline void php_http_array_hashkey_stringfree(php_http_array_hashkey_t *key)
{
if (key->type != HASH_KEY_IS_STRING || key->dup) {
- STR_FREE(key->str);
+ PTR_FREE(key->str);
}
}