- we have const APIs in 5.4+ and do not care about warnings in 5.3
[m6w6/ext-http] / php_http_url.h
index 65a764e6c1f899394298184b3c471a8a7aef4c06..30f7780e92a548c30f92d3f7b08d89d24a03cc41 100644 (file)
@@ -48,6 +48,66 @@ static inline void php_http_url_argsep(const char **str, size_t *len TSRMLS_DC)
        }
 }
 
+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;