#include "php_http_api.h"
#include "php_http_url_api.h"
+static inline char *localhostname(void)
+{
+ char hostname[1024] = {0};
+
+#ifdef PHP_WIN32
+ if (SUCCESS == gethostname(hostname, lenof(hostname))) {
+ return estrdup(hostname);
+ }
+#elif defined(HAVE_UNISTD_H)
+ if (SUCCESS == gethostname(hostname, lenof(hostname))) {
+ size_t hlen = strlen(hostname);
+
+ if (hlen <= lenof(hostname) - lenof("(none)")) {
+ hostname[hlen++] = '.';
+ if (SUCCESS == getdomainname(&hostname[hlen], lenof(hostname) - hlen)) {
+ if (!strcmp(&hostname[hlen], "(none)")) {
+ hostname[hlen - 1] = '\0';
+ }
+ return estrdup(hostname);
+ }
+ }
+ }
+#endif
+ return estrdup("localhost");
+}
+
PHP_MINIT_FUNCTION(http_url)
{
HTTP_LONG_CONSTANT("HTTP_URL_REPLACE", HTTP_URL_REPLACE);
(zhost = http_get_server_var("SERVER_NAME")))) && Z_STRLEN_P(zhost)) {
url->host = estrndup(Z_STRVAL_P(zhost), Z_STRLEN_P(zhost));
} else {
- url->host = estrndup("localhost", lenof("localhost"));
+ url->host = localhostname();
}
}
memmove(&ptr[1], pos, end - pos);
}
break;
+
+ default:
+ /* something else */
+ ++ptr;
+ break;
}
}
}
strlcat(*url_str, url->host, HTTP_URL_MAXLEN);
if (url->port) {
- char port_str[6] = {0};
+ char port_str[8] = {0};
- snprintf(port_str, 5, "%d", (int) url->port);
+ snprintf(port_str, lenof(port_str), "%d", (int) url->port);
strlcat(*url_str, ":", HTTP_URL_MAXLEN);
strlcat(*url_str, port_str, HTTP_URL_MAXLEN);
}
phpstr new_prefix;
if (!data || !*data) {
+ phpstr_dtor(str);
return FAILURE;
}
phpstr_init(&new_prefix);
if (prefix && prefix_len) {
phpstr_append(&new_prefix, prefix, prefix_len);
- phpstr_appends(&new_prefix, "[");
+ phpstr_appends(&new_prefix, "%5B");
}
phpstr_append(&new_prefix, encoded_key, encoded_len);
efree(encoded_key);
if (prefix && prefix_len) {
- phpstr_appends(&new_prefix, "]");
+ phpstr_appends(&new_prefix, "%5D");
}
phpstr_fix(&new_prefix);
}
--ht->nApplyCount;
if (SUCCESS != status) {
phpstr_dtor(&new_prefix);
+ phpstr_dtor(str);
return FAILURE;
}
} else {