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-2007, Michael Wallner <mike@php.net> |
10 : +--------------------------------------------------------------------+
11 : */
12 :
13 : /* $Id: php_http_url_api.h,v 1.12 2007/02/07 11:50:27 mike Exp $ */
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 (HTTP_URL_STRIP_USER|HTTP_URL_STRIP_PASS)
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 : #define HTTP_URL_STRIP_ALL ( \
36 : HTTP_URL_STRIP_AUTH | \
37 : HTTP_URL_STRIP_PORT | \
38 : HTTP_URL_STRIP_PATH | \
39 : HTTP_URL_STRIP_QUERY | \
40 : HTTP_URL_STRIP_FRAGMENT \
41 : )
42 :
43 : #define http_build_url(f, o, n, p, s, l) _http_build_url((f), (o), (n), (p), (s), (l) TSRMLS_CC)
44 : 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);
45 :
46 : #define http_urlencode_hash(h, q) _http_urlencode_hash_ex((h), 1, NULL, 0, (q), NULL TSRMLS_CC)
47 : #define http_urlencode_hash_ex(h, o, p, pl, q, ql) _http_urlencode_hash_ex((h), (o), (p), (pl), (q), (ql) TSRMLS_CC)
48 : 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);
49 :
50 : #define http_urlencode_hash_recursive(ht, s, as, al, pr, pl) _http_urlencode_hash_recursive((ht), (s), (as), (al), (pr), (pl) TSRMLS_CC)
51 : 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);
52 :
53 : #define http_url_from_struct(u, ht) _http_url_from_struct((u), (ht) TSRMLS_CC)
54 : static inline php_url *_http_url_from_struct(php_url *url, HashTable *ht TSRMLS_DC)
55 5 : {
56 : zval **e;
57 :
58 5 : if (!url) {
59 5 : url = ecalloc(1, sizeof(php_url));
60 : }
61 :
62 5 : if ((SUCCESS == zend_hash_find(ht, "scheme", sizeof("scheme"), (void *) &e))
63 : && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
64 5 : url->scheme = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
65 : }
66 5 : if ((SUCCESS == zend_hash_find(ht, "user", sizeof("user"), (void *) &e))
67 : && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
68 0 : url->user = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
69 : }
70 5 : if ((SUCCESS == zend_hash_find(ht, "pass", sizeof("pass"), (void *) &e))
71 : && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
72 0 : url->pass = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
73 : }
74 5 : if ((SUCCESS == zend_hash_find(ht, "host", sizeof("host"), (void *) &e))
75 : && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
76 4 : url->host = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
77 : }
78 5 : if ((SUCCESS == zend_hash_find(ht, "path", sizeof("path"), (void *) &e))
79 : && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
80 2 : url->path = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
81 : }
82 5 : if ((SUCCESS == zend_hash_find(ht, "query", sizeof("query"), (void *) &e))
83 : && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
84 1 : url->query = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
85 : }
86 5 : if ((SUCCESS == zend_hash_find(ht, "fragment", sizeof("fragment"), (void *) &e))
87 : && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
88 2 : url->fragment = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
89 : }
90 5 : if (SUCCESS == zend_hash_find(ht, "port", sizeof("port"), (void *) &e)) {
91 2 : if (Z_TYPE_PP(e) == IS_LONG) {
92 2 : url->port = (unsigned short) Z_LVAL_PP(e);
93 : } else {
94 0 : zval *o = *e;
95 :
96 0 : convert_to_long_ex(e);
97 0 : url->port = (unsigned short) Z_LVAL_PP(e);
98 0 : if (o != *e) zval_ptr_dtor(e);
99 : }
100 : }
101 :
102 5 : return url;
103 : }
104 :
105 : #define http_url_tostruct(u, strct) _http_url_tostruct((u), (strct) TSRMLS_CC)
106 : static inline HashTable *_http_url_tostruct(php_url *url, zval *strct TSRMLS_DC)
107 1 : {
108 : zval arr;
109 :
110 1 : if (strct) {
111 1 : switch (Z_TYPE_P(strct)) {
112 : default:
113 1 : zval_dtor(strct);
114 1 : array_init(strct);
115 : case IS_ARRAY:
116 : case IS_OBJECT:
117 1 : INIT_ZARR(arr, HASH_OF(strct));
118 : }
119 : } else {
120 0 : INIT_PZVAL(&arr);
121 0 : array_init(&arr);
122 : }
123 :
124 1 : if (url) {
125 1 : if (url->scheme) {
126 1 : add_assoc_string(&arr, "scheme", url->scheme, 1);
127 : }
128 1 : if (url->user) {
129 0 : add_assoc_string(&arr, "user", url->user, 1);
130 : }
131 1 : if (url->pass) {
132 0 : add_assoc_string(&arr, "pass", url->pass, 1);
133 : }
134 1 : if (url->host) {
135 1 : add_assoc_string(&arr, "host", url->host, 1);
136 : }
137 1 : if (url->port) {
138 1 : add_assoc_long(&arr, "port", (long) url->port);
139 : }
140 1 : if (url->path) {
141 1 : add_assoc_string(&arr, "path", url->path, 1);
142 : }
143 1 : if (url->query) {
144 1 : add_assoc_string(&arr, "query", url->query, 1);
145 : }
146 1 : if (url->fragment) {
147 1 : add_assoc_string(&arr, "fragment", url->fragment, 1);
148 : }
149 : }
150 :
151 1 : return Z_ARRVAL(arr);
152 : }
153 :
154 : #endif
155 :
156 : /*
157 : * Local variables:
158 : * tab-width: 4
159 : * c-basic-offset: 4
160 : * End:
161 : * vim600: noet sw=4 ts=4 fdm=marker
162 : * vim<600: noet sw=4 ts=4
163 : */
164 :
|