-/*
- * Begin an HTTP fetch (returns number of bytes actually fetched, or -1 for error) using libcurl.
- */
-int fetch_http(StrBuf *url, StrBuf **target_buf)
-{
- StrBuf *ReplyBuf;
- CURL *curl;
- CURLcode result;
- char *effective_url = NULL;
- char errmsg[1024] = "";
-
- if (StrLength(url) <=0 ) return(-1);
- ReplyBuf = *target_buf = NewStrBuf ();
- if (ReplyBuf == 0) return(-1);
-
- curl = ctdl_openid_curl_easy_init(errmsg);
- if (!curl) return(-1);
-
- curl_easy_setopt(curl, CURLOPT_URL, ChrPtr(url));
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, ReplyBuf);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlFillStrBuf_callback);
-
- result = curl_easy_perform(curl);
- if (result) {
- syslog(LOG_DEBUG, "libcurl error %d: %s", result, errmsg);
- }
- curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective_url);
- StrBufPlain(url, effective_url, -1);
-
- curl_easy_cleanup(curl);
- return StrLength(ReplyBuf);
-}
-
-
-