clients/c/sky-island.c
/* curl_fetch_url fetches and return url body via curl */
curl_fetch_url fetches and return url body via curl
curl_fetch_url fetches and return url body via curl
CURLcode curl_fetch_url(CURL* ch,
                        const char* url,
                        struct curl_fetch_st* fetch) {
  CURLcode ret_code;
  fetch->payload = (char*)calloc(1, sizeof(fetch->payload));
  if (fetch->payload == NULL) {
    fprintf(stderr, "ERROR: Failed to allocate payload in curl_fetch_url");
    return CURLE_FAILED_INIT;
  }
  fetch->size = 0;
  curl_easy_setopt(ch, CURLOPT_URL, url);
  curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, curl_callback);
  curl_easy_setopt(ch, CURLOPT_WRITEDATA, (void*)fetch);
  curl_easy_setopt(ch, CURLOPT_USERAGENT, "sky-island/1.0");
  curl_easy_setopt(ch, CURLOPT_TIMEOUT, 5);
  curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 0);
  ret_code = curl_easy_perform(ch);
  return ret_code;
}
CURLcode curl_fetch_url ( CURL * ch , const char * url , struct curl_fetch_st * fetch ) { CURLcode ret_code ; fetch -> payload = ( char * ) calloc ( 1 , sizeof ( fetch -> payload ) ) ; if ( fetch -> payload == NULL ) { fprintf ( stderr , " " ) ; return CURLE_FAILED_INIT ; } fetch -> size = 0 ; curl_easy_setopt ( ch , CURLOPT_URL , url ) ; curl_easy_setopt ( ch , CURLOPT_WRITEFUNCTION , curl_callback ) ; curl_easy_setopt ( ch , CURLOPT_WRITEDATA , ( void * ) fetch ) ; curl_easy_setopt ( ch , CURLOPT_USERAGENT , " " ) ; curl_easy_setopt ( ch , CURLOPT_TIMEOUT , 5 ) ; curl_easy_setopt ( ch , CURLOPT_FOLLOWLOCATION , 0 ) ; ret_code = curl_easy_perform ( ch ) ; return ret_code ; }
curl_fetch_url fetches and return url body via curl
curl_fetch_url fetches and return url body via curl