- 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;
-
- if (!url) {
- url = emalloc(sizeof(*url));
- }
- memset(url, 0, sizeof(*url));
-
- if (SUCCESS == zend_hash_find(ht, "scheme", sizeof("scheme"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_STRING, *e);
- url->scheme = estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy));
- zval_ptr_dtor(&cpy);
- }
- if (SUCCESS == zend_hash_find(ht, "user", sizeof("user"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_STRING, *e);
- url->user = estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy));
- zval_ptr_dtor(&cpy);
- }
- if (SUCCESS == zend_hash_find(ht, "pass", sizeof("pass"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_STRING, *e);
- url->pass = estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy));
- zval_ptr_dtor(&cpy);
- }
- if (SUCCESS == zend_hash_find(ht, "host", sizeof("host"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_STRING, *e);
- url->host = estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy));
- zval_ptr_dtor(&cpy);
- }
- if (SUCCESS == zend_hash_find(ht, "path", sizeof("path"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_STRING, *e);
- url->path = estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy));
- zval_ptr_dtor(&cpy);
- }
- if (SUCCESS == zend_hash_find(ht, "query", sizeof("query"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_STRING, *e);
- url->query = estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy));
- zval_ptr_dtor(&cpy);
- }
- if (SUCCESS == zend_hash_find(ht, "fragment", sizeof("fragment"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_STRING, *e);
- url->fragment = estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy));
- zval_ptr_dtor(&cpy);
- }
- if (SUCCESS == zend_hash_find(ht, "port", sizeof("port"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_LONG, *e);
- url->port = (unsigned short) Z_LVAL_P(cpy);
- zval_ptr_dtor(&cpy);
- }
-
- return url;