a4c5df0b3690997c9f7a00dfcab08c25b56176c4
[m6w6/ext-http] / php_http_url_api.h
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2006, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id$ */
14
15 #ifndef PHP_HTTP_URL_API_H
16 #define PHP_HTTP_URL_API_H
17
18 #include "ext/standard/url.h"
19
20 extern PHP_MINIT_FUNCTION(http_url);
21
22 #define http_absolute_url(u) _http_absolute_url((u) TSRMLS_CC)
23 PHP_HTTP_API char *_http_absolute_url(const char *url TSRMLS_DC);
24
25 #define HTTP_URL_REPLACE 0x000
26 #define HTTP_URL_JOIN_PATH 0x001
27 #define HTTP_URL_JOIN_QUERY 0x002
28 #define HTTP_URL_STRIP_USER 0x004
29 #define HTTP_URL_STRIP_PASS 0x008
30 #define HTTP_URL_STRIP_AUTH 0x010
31 #define HTTP_URL_STRIP_PORT 0x020
32 #define HTTP_URL_STRIP_PATH 0x040
33 #define HTTP_URL_STRIP_QUERY 0x080
34 #define HTTP_URL_STRIP_FRAGMENT 0x100
35
36 #define http_build_url(f, o, n, p, s, l) _http_build_url((f), (o), (n), (p), (s), (l) TSRMLS_CC)
37 PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_url *new_url, php_url **url_ptr, char **url_str, size_t *url_len TSRMLS_DC);
38
39 #define http_urlencode_hash(h, q) _http_urlencode_hash_ex((h), 1, NULL, 0, (q), NULL TSRMLS_CC)
40 #define http_urlencode_hash_ex(h, o, p, pl, q, ql) _http_urlencode_hash_ex((h), (o), (p), (pl), (q), (ql) TSRMLS_CC)
41 PHP_HTTP_API STATUS _http_urlencode_hash_ex(HashTable *hash, zend_bool override_argsep, char *pre_encoded_data, size_t pre_encoded_len, char **encoded_data, size_t *encoded_len TSRMLS_DC);
42
43 #define http_urlencode_hash_recursive(ht, s, as, al, pr, pl) _http_urlencode_hash_recursive((ht), (s), (as), (al), (pr), (pl) TSRMLS_CC)
44 PHP_HTTP_API STATUS _http_urlencode_hash_recursive(HashTable *ht, phpstr *str, const char *arg_sep, size_t arg_sep_len, const char *prefix, size_t prefix_len TSRMLS_DC);
45
46 #define array2url(ht) _array2url((ht) TSRMLS_CC)
47 static inline php_url *_array2url(HashTable *ht TSRMLS_DC)
48 {
49 zval **e;
50 php_url *url = ecalloc(1, sizeof(php_url));
51
52 if ((SUCCESS == zend_hash_find(ht, "scheme", sizeof("scheme"), (void *) &e))
53 && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
54 url->scheme = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
55 }
56 if ((SUCCESS == zend_hash_find(ht, "user", sizeof("user"), (void *) &e))
57 && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
58 url->user = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
59 }
60 if ((SUCCESS == zend_hash_find(ht, "pass", sizeof("pass"), (void *) &e))
61 && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
62 url->pass = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
63 }
64 if ((SUCCESS == zend_hash_find(ht, "host", sizeof("host"), (void *) &e))
65 && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
66 url->host = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
67 }
68 if ((SUCCESS == zend_hash_find(ht, "path", sizeof("path"), (void *) &e))
69 && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
70 url->path = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
71 }
72 if ((SUCCESS == zend_hash_find(ht, "query", sizeof("query"), (void *) &e))
73 && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
74 url->query = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
75 }
76 if ((SUCCESS == zend_hash_find(ht, "fragment", sizeof("fragment"), (void *) &e))
77 && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
78 url->fragment = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
79 }
80 if (SUCCESS == zend_hash_find(ht, "port", sizeof("port"), (void *) &e)) {
81 if (Z_TYPE_PP(e) == IS_LONG) {
82 url->port = (unsigned short) Z_LVAL_PP(e);
83 } else {
84 zval *o = *e;
85
86 convert_to_long_ex(e);
87 url->port = (unsigned short) Z_LVAL_PP(e);
88 if (o != *e) zval_ptr_dtor(e);
89 }
90 }
91
92 return url;
93 }
94
95 #endif
96
97 /*
98 * Local variables:
99 * tab-width: 4
100 * c-basic-offset: 4
101 * End:
102 * vim600: noet sw=4 ts=4 fdm=marker
103 * vim<600: noet sw=4 ts=4
104 */
105