mike Fri May 19 09:54:57 2006 UTC
Modified files:
/pecl/http http_url_api.c php_http_url_api.h
Log:
- add HTTP_URL_STRIP_ALL constant
- recognize HTTPS server variable
- simplify building urls where path is based on SG(request_).request_uri
http://cvs.php.net/viewcvs.cgi/pecl/http/http_url_api.c?r1=1.43&r2=1.44&diff_format=u
Index: pecl/http/http_url_api.c
diff -u pecl/http/http_url_api.c:1.43 pecl/http/http_url_api.c:1.44
--- pecl/http/http_url_api.c:1.43 Sat Apr 22 21:04:37 2006
+++ pecl/http/http_url_api.c Fri May 19 09:54:57 2006
@@ -10,7 +10,7 @@
+--------------------------------------------------------------------+
*/
-/* $Id: http_url_api.c,v 1.43 2006/04/22 21:04:37 mike Exp $ */
+/* $Id: http_url_api.c,v 1.44 2006/05/19 09:54:57 mike Exp $ */
#define HTTP_WANT_SAPI
#define HTTP_WANT_NETDB
@@ -62,6 +62,7 @@
HTTP_LONG_CONSTANT("HTTP_URL_STRIP_PATH", HTTP_URL_STRIP_PATH);
HTTP_LONG_CONSTANT("HTTP_URL_STRIP_QUERY", HTTP_URL_STRIP_QUERY);
HTTP_LONG_CONSTANT("HTTP_URL_STRIP_FRAGMENT", HTTP_URL_STRIP_FRAGMENT);
+ HTTP_LONG_CONSTANT("HTTP_URL_STRIP_ALL", HTTP_URL_STRIP_ALL);
return SUCCESS;
}
@@ -156,6 +157,10 @@
}
if (!url->scheme) {
+ zval *https = http_get_server_var("HTTPS");
+ if (https && !strcasecmp(Z_STRVAL_P(https), "ON")) {
+ url->scheme = estrndup("https", lenof("https"));
+ } else
switch (url->port)
{
case 443:
@@ -193,7 +198,7 @@
}
if (!url->path) {
- if (SG(request_info).request_uri &&
*SG(request_info).request_uri) {
+ if (SG(request_info).request_uri &&
SG(request_info).request_uri[0]) {
const char *q = strchr(SG(request_info).request_uri,
'?');
if (q) {
@@ -204,30 +209,23 @@
} else {
url->path = estrndup("/", 1);
}
- } else if (*url->path != '/') {
- if (SG(request_info).request_uri &&
*SG(request_info).request_uri) {
- const char *q = strchr(SG(request_info).request_uri,
'?');
- char *uri, *path;
- size_t len;
-
- if (q) {
- uri = estrndup(SG(request_info).request_uri,
len = q - SG(request_info).request_uri);
- } else {
- uri = estrndup(SG(request_info).request_uri,
len = strlen(SG(request_info).request_uri));
- }
-
- php_dirname(uri, len);
- spprintf(&path, 0, "%s/%s", uri, url->path);
- efree(uri);
- STR_SET(url->path, path);
- } else {
- char *uri;
-
- spprintf(&uri, 0, "/%s", url->path);
- STR_SET(url->path, uri);
- }
+ } else if (url->path[0] != '/' && SG(request_info).request_uri &&
SG(request_info).request_uri[0]) {
+ size_t ulen = strlen(SG(request_info).request_uri);
+ size_t plen = strlen(url->path);
+ char *path;
+
+ if (SG(request_info).request_uri[ulen-1] != '/') {
+ for (--ulen; ulen && SG(request_info).request_uri[ulen
- 1] != '/'; --ulen);
+ }
+
+ path = emalloc(ulen + plen + 1);
+ memcpy(path, SG(request_info).request_uri, ulen);
+ memcpy(path + ulen, url->path, plen);
+ path[ulen + plen] = '\0';
+ STR_SET(url->path, path);
}
- if (url->path) {
+ /* replace directory references if path is not a single slash */
+ if (url->path[0] && (url->path[0] != '/' || url->path[1])) {
char *ptr, *end = url->path + strlen(url->path) + 1;
for (ptr = strstr(url->path, "/."); ptr; ptr = strstr(ptr,
"/.")) {
http://cvs.php.net/viewcvs.cgi/pecl/http/php_http_url_api.h?r1=1.9&r2=1.10&diff_format=u
Index: pecl/http/php_http_url_api.h
diff -u pecl/http/php_http_url_api.h:1.9 pecl/http/php_http_url_api.h:1.10
--- pecl/http/php_http_url_api.h:1.9 Sat Apr 29 18:54:46 2006
+++ pecl/http/php_http_url_api.h Fri May 19 09:54:57 2006
@@ -10,7 +10,7 @@
+--------------------------------------------------------------------+
*/
-/* $Id: php_http_url_api.h,v 1.9 2006/04/29 18:54:46 mike Exp $ */
+/* $Id: php_http_url_api.h,v 1.10 2006/05/19 09:54:57 mike Exp $ */
#ifndef PHP_HTTP_URL_API_H
#define PHP_HTTP_URL_API_H
@@ -32,6 +32,13 @@
#define HTTP_URL_STRIP_PATH 0x040
#define HTTP_URL_STRIP_QUERY 0x080
#define HTTP_URL_STRIP_FRAGMENT 0x100
+#define HTTP_URL_STRIP_ALL ( \
+ HTTP_URL_STRIP_AUTH | \
+ HTTP_URL_STRIP_PORT | \
+ HTTP_URL_STRIP_PATH | \
+ HTTP_URL_STRIP_QUERY | \
+ HTTP_URL_STRIP_FRAGMENT \
+)
#define http_build_url(f, o, n, p, s, l) _http_build_url((f), (o), (n), (p),
(s), (l) TSRMLS_CC)
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);