/*{{{ application_set_url*/ gboolean application_set_url (Application *app, const gchar *url) { if (app->uri) evhttp_uri_free (app->uri); // check if URL contains HTTP or HTTPS if (strlen (url) < 4 || !strcasestr (url, "http") || strcasestr (url, "http") != url) { // XXX: check config and decide HTTP or HTTPS ? gchar *tmp; tmp = g_strdup_printf ("http://%s", url); app->uri = evhttp_uri_parse (tmp); g_free (tmp); } else app->uri = evhttp_uri_parse (url); if (!app->uri) { LOG_err (APP_LOG, " URL (%s) is not valid!", url); application_exit (app); return FALSE; } conf_set_string (app->conf, "s3.host", evhttp_uri_get_host (app->uri)); conf_set_int (app->conf, "s3.port", uri_get_port (app->uri)); conf_set_boolean (app->conf, "s3.ssl", uri_is_https (app->uri)); return TRUE; }
gint uri_get_port (const struct evhttp_uri *uri) { gint port; port = evhttp_uri_get_port (uri); // if no port is specified, libevent returns -1 if (port == -1) { if (uri_is_https (uri)) port = 443; else port = 80; } return port; }