+static const char *
+uclient_split_host(const char *base, int *host_len)
+{
+ char *next, *location;
+
+ next = strchr(base, '/');
+ if (next) {
+ location = next;
+ *host_len = next - base;
+ } else {
+ location = "/";
+ *host_len = strlen(base);
+ }
+
+ return location;
+}
+
+struct uclient_url __hidden *
+uclient_get_url(const char *url_str, const char *auth_str)
+{
+ static const struct uclient_backend *backends[] = {
+ &uclient_backend_http,
+ };
+
+ const struct uclient_backend *backend;
+ const char * const *prefix = NULL;
+ struct uclient_url *url;
+ const char *location;
+ int host_len;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(backends); i++) {
+ int prefix_len = 0;
+
+ for (prefix = backends[i]->prefix; *prefix; prefix++) {
+ prefix_len = strlen(*prefix);
+
+ if (!strncmp(url_str, *prefix, prefix_len))
+ break;
+ }
+
+ if (!*prefix)
+ continue;
+
+ url_str += prefix_len;
+ backend = backends[i];
+ break;
+ }
+
+ if (!*prefix)
+ return NULL;
+
+ location = uclient_split_host(url_str, &host_len);
+ url = __uclient_get_url(backend, url_str, host_len, location, auth_str);
+ if (!url)
+ return NULL;
+
+ url->prefix = prefix - backend->prefix;
+ return url;
+}
+
+static void uclient_connection_timeout(struct uloop_timeout *timeout)
+{
+ struct uclient *cl = container_of(timeout, struct uclient, connection_timeout);
+
+ if (cl->backend->disconnect)
+ cl->backend->disconnect(cl);
+
+ uclient_backend_set_error(cl, UCLIENT_ERROR_TIMEDOUT);
+}
+
+struct uclient *uclient_new(const char *url_str, const char *auth_str, const struct uclient_cb *cb)