#include "SAPI.h"
#include "zend_ini.h"
#include "php_output.h"
+#include "ext/standard/php_string.h"
#include "php_http_api.h"
#include "php_http_url_api.h"
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
PHP_HTTP_API char *_http_absolute_url(const char *url TSRMLS_DC)
{
char *abs = estrdup(url);
}
}
- /* FIXXME: dirname(REQUEST_URI) if path is relative */
if (!url->path) {
- if (SG(request_info).request_uri) {
+ if (SG(request_info).request_uri && *SG(request_info).request_uri) {
const char *q = strchr(SG(request_info).request_uri, '?');
if (q) {
url->path = estrdup(SG(request_info).request_uri);
}
} else {
- url->path = ecalloc(1, 1);
+ 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);
}
}
return FAILURE;
}
} else {
- char *encoded_val;
- int encoded_len;
- zval *cpy, *val = convert_to_type_ex(IS_STRING, *data, &cpy);
+ zval *val;
+
+ ALLOC_ZVAL(val);
+ *val = **data;
+ INIT_PZVAL(val);
+ zval_copy_ctor(val);
+ convert_to_string(val);
if (PHPSTR_LEN(str)) {
phpstr_append(str, arg_sep, arg_sep_len);
phpstr_append(str, PHPSTR_VAL(&new_prefix), PHPSTR_LEN(&new_prefix));
phpstr_appends(str, "=");
- encoded_val = php_url_encode(Z_STRVAL_P(val), Z_STRLEN_P(val), &encoded_len);
- phpstr_append(str, encoded_val, encoded_len);
- efree(encoded_val);
-
- if (cpy) {
- zval_ptr_dtor(&cpy);
+ if (Z_STRLEN_P(val) && Z_STRVAL_P(val)) {
+ char *encoded_val;
+ int encoded_len;
+
+ encoded_val = php_url_encode(Z_STRVAL_P(val), Z_STRLEN_P(val), &encoded_len);
+ phpstr_append(str, encoded_val, encoded_len);
+ efree(encoded_val);
}
+
+ zval_ptr_dtor(&val);
}
-
phpstr_dtor(&new_prefix);
}
return SUCCESS;