static zend_class_entry *php_http_client_factory_find_class_entry(zval *this_ptr, const char *for_str, size_t for_len TSRMLS_DC)
{
/* stupid non-const api */
- char *sc = estrndup(for_str, for_len);
- zval *cn = zend_read_property(Z_OBJCE_P(getThis()), getThis(), sc, for_len, 0 TSRMLS_CC);
+ zval *cn = zend_read_property(Z_OBJCE_P(getThis()), getThis(), for_str, for_len, 0 TSRMLS_CC);
- efree(sc);
if (Z_TYPE_P(cn) == IS_STRING && Z_STRLEN_P(cn)) {
return zend_fetch_class(Z_STRVAL_P(cn), Z_STRLEN_P(cn), 0 TSRMLS_CC);
}
static void set_option(zval *options, const char *name_str, size_t name_len, int type, void *value_ptr, size_t value_len TSRMLS_DC)
{
if (Z_TYPE_P(options) == IS_OBJECT) {
- /* stupid non-const api */
- char *name = estrndup(name_str, name_len);
if (value_ptr) {
switch (type) {
case IS_DOUBLE:
- zend_update_property_double(Z_OBJCE_P(options), options, name, name_len, *(double *)value_ptr TSRMLS_CC);
+ zend_update_property_double(Z_OBJCE_P(options), options, name_str, name_len, *(double *)value_ptr TSRMLS_CC);
break;
case IS_LONG:
- zend_update_property_long(Z_OBJCE_P(options), options, name, name_len, *(long *)value_ptr TSRMLS_CC);
+ zend_update_property_long(Z_OBJCE_P(options), options, name_str, name_len, *(long *)value_ptr TSRMLS_CC);
break;
case IS_STRING:
- zend_update_property_stringl(Z_OBJCE_P(options), options, name, name_len, value_ptr, value_len TSRMLS_CC);
+ zend_update_property_stringl(Z_OBJCE_P(options), options, name_str, name_len, value_ptr, value_len TSRMLS_CC);
break;
case IS_OBJECT:
- zend_update_property(Z_OBJCE_P(options), options, name, name_len, value_ptr TSRMLS_CC);
+ zend_update_property(Z_OBJCE_P(options), options, name_str, name_len, value_ptr TSRMLS_CC);
break;
}
} else {
- zend_update_property_null(Z_OBJCE_P(options), options, name, name_len TSRMLS_CC);
+ zend_update_property_null(Z_OBJCE_P(options), options, name_str, name_len TSRMLS_CC);
}
- efree(name);
} else {
convert_to_array(options);
if (value_ptr) {
zval *val, **valptr;
if (Z_TYPE_P(options) == IS_OBJECT) {
- char *name = estrndup(name_str, name_len);
- val = zend_read_property(Z_OBJCE_P(options), options, name, name_len, 0 TSRMLS_CC);
- efree(name);
+ val = zend_read_property(Z_OBJCE_P(options), options, name_str, name_len, 0 TSRMLS_CC);
} else {
if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(options), name_str, name_len + 1, (void *) &valptr)) {
val = *valptr;
}
if (url_str) {
- size_t len;
-
- *url_str = emalloc(PHP_HTTP_URL_MAXLEN + 1);
-
- **url_str = '\0';
- strlcat(*url_str, url->scheme, PHP_HTTP_URL_MAXLEN);
- strlcat(*url_str, "://", PHP_HTTP_URL_MAXLEN);
-
- if (url->user && *url->user) {
- strlcat(*url_str, url->user, PHP_HTTP_URL_MAXLEN);
- if (url->pass && *url->pass) {
- strlcat(*url_str, ":", PHP_HTTP_URL_MAXLEN);
- strlcat(*url_str, url->pass, PHP_HTTP_URL_MAXLEN);
- }
- strlcat(*url_str, "@", PHP_HTTP_URL_MAXLEN);
- }
-
- strlcat(*url_str, url->host, PHP_HTTP_URL_MAXLEN);
-
- if (url->port) {
- char port_str[8];
-
- snprintf(port_str, sizeof(port_str), "%d", (int) url->port);
- strlcat(*url_str, ":", PHP_HTTP_URL_MAXLEN);
- strlcat(*url_str, port_str, PHP_HTTP_URL_MAXLEN);
- }
-
- strlcat(*url_str, url->path, PHP_HTTP_URL_MAXLEN);
-
- if (url->query && *url->query) {
- strlcat(*url_str, "?", PHP_HTTP_URL_MAXLEN);
- strlcat(*url_str, url->query, PHP_HTTP_URL_MAXLEN);
- }
-
- if (url->fragment && *url->fragment) {
- strlcat(*url_str, "#", PHP_HTTP_URL_MAXLEN);
- strlcat(*url_str, url->fragment, PHP_HTTP_URL_MAXLEN);
- }
-
- if (PHP_HTTP_URL_MAXLEN == (len = strlen(*url_str))) {
- php_http_error(HE_NOTICE, PHP_HTTP_E_URL, "Length of URL exceeds PHP_HTTP_URL_MAXLEN");
- }
- if (url_len) {
- *url_len = len;
- }
+ php_http_url_to_string(url, url_str, url_len TSRMLS_CC);
}
if (url_ptr) {
}
}
+static inline void php_http_url_to_string(php_url *url, char **url_str, size_t *url_len TSRMLS_DC)
+{
+ php_http_buffer_t buf;
+
+ php_http_buffer_init(&buf);
+
+ if (url->scheme && *url->scheme) {
+ php_http_buffer_appendl(&buf, url->scheme);
+ php_http_buffer_appends(&buf, "://");
+ } else {
+ php_http_buffer_appends(&buf, "//");
+ }
+
+ if (url->user && *url->user) {
+ php_http_buffer_appendl(&buf, url->user);
+ if (url->pass && *url->pass) {
+ php_http_buffer_appends(&buf, ":");
+ php_http_buffer_appendl(&buf, url->pass);
+ }
+ php_http_buffer_appends(&buf, "@");
+ }
+
+ if (url->host && *url->host) {
+ php_http_buffer_appendl(&buf, url->host);
+ } else {
+ php_http_buffer_appends(&buf, "localhost");
+ }
+
+ if (url->port) {
+ php_http_buffer_appendf(&buf, ":%hu", url->port);
+ }
+
+ if (url->path && *url->path) {
+ php_http_buffer_appendl(&buf, url->path);
+ }
+
+ if (url->query && *url->query) {
+ php_http_buffer_appends(&buf, "?");
+ php_http_buffer_appendl(&buf, url->query);
+ }
+
+ if (url->fragment && *url->fragment) {
+ php_http_buffer_appends(&buf, "#");
+ php_http_buffer_appendl(&buf, url->fragment);
+ }
+
+ php_http_buffer_shrink(&buf);
+ php_http_buffer_fix(&buf);
+
+ if (url_len) {
+ *url_len = buf.used;
+ }
+
+ if (url_str) {
+ *url_str = buf.data;
+ } else {
+ php_http_buffer_dtor(&buf);
+ }
+}
+
static inline php_url *php_http_url_from_struct(php_url *url, HashTable *ht TSRMLS_DC)
{
zval **e;