static GString * _curl_url_prefix (const char *ns, enum _prefix_e which) { if (!ns) { GRID_WARN ("BUG No namespace configured!"); return NULL; } gchar *s = NULL; if (which == PREFIX_CONSCIENCE) s = oio_cfg_get_proxy_conscience (ns); else if (which == PREFIX_CONTAINER) s = oio_cfg_get_proxy_containers (ns); else if (which == PREFIX_REFERENCE) s = oio_cfg_get_proxy_directory (ns); if (!s) s = oio_cfg_get_proxy (ns); if (!s) { GRID_WARN ("No proxy configured!"); return NULL; } GString *hu = g_string_new("http://"); g_string_append (hu, s); g_free (s); return hu; }
static const char * _check_ns (const char *ns) { static char errbuf[1024]; const char *errmsg = NULL; struct curl_slist *headers = NULL; gchar *proxy = NULL, *url = NULL; CURL *h = NULL; int rc; if (!(proxy = oio_cfg_get_proxy_conscience (ns))) { errmsg = "no proxy configured"; goto out; } if (!(url = g_strdup_printf ("http://%s/"PROXYD_PREFIX2"/cs/%s", proxy, ns))) { errmsg = "memory allocation failure"; goto out; } /* XXX JFS: the proxy has a simplistic HTTP management and doesn't honor Expect */ headers = curl_slist_append (headers, "Expect: "); headers = curl_slist_append (headers, "Connection: close"); if (!(h = curl_easy_init ())) { errmsg = "CURL init failure"; goto out; } curl_easy_setopt (h, CURLOPT_USERAGENT, "OpenIO-SDS/SDK-2.0/test"); curl_easy_setopt (h, CURLOPT_NOPROGRESS, 1L); curl_easy_setopt (h, CURLOPT_CUSTOMREQUEST, "HEAD"); curl_easy_setopt (h, CURLOPT_URL, url); curl_easy_setopt (h, CURLOPT_HTTPHEADER, headers); if (CURLE_OK != (rc = curl_easy_perform (h))) { errmsg = curl_easy_strerror (rc); goto out; } long code = 0; if (CURLE_OK != (rc = curl_easy_getinfo (h, CURLINFO_RESPONSE_CODE, &code))) { errmsg = curl_easy_strerror (rc); goto out; } if ((code/100) != 2) { g_snprintf (errbuf, sizeof(errbuf), "HTTP status %ld", code); errmsg = errbuf; goto out; } out: if (h) curl_easy_cleanup (h); if (headers) curl_slist_free_all (headers); if (proxy) g_free (proxy); if (url) g_free (url); return errmsg; }