SHARE
TWEET

Untitled

a guest Jun 27th, 2008 199 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*****************************************************************************
  2.  *                                  _   _ ____  _
  3.  *  Project                     ___| | | |  _ \| |
  4.  *                             / __| | | | |_) | |
  5.  *                            | (__| |_| |  _ <| |___
  6.  *                             \___|\___/|_| \_\_____|
  7.  *
  8.  * $Id: sepheaders.c,v 1.10 2008/05/22 21:20:09 danf Exp $
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <unistd.h>
  14.  
  15. #include <curl/curl.h>
  16. #include <curl/types.h>
  17. #include <curl/easy.h>
  18.  
  19. static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
  20. {
  21.   int written = fwrite(ptr, size, nmemb, (FILE *)stream);
  22.   return written;
  23. }
  24.  
  25. int main(int argc, char **argv)
  26. {
  27.   CURL *curl_handle;
  28.   static const char *headerfilename = "head.out";
  29.   FILE *headerfile;
  30.  
  31.   curl_global_init(CURL_GLOBAL_ALL);
  32.  
  33.   /* init the curl session */
  34.   curl_handle = curl_easy_init();
  35.  
  36.   /* set URL to get */
  37.   /* curl_easy_setopt(curl_handle, CURLOPT_URL, "http://curl.haxx.se"); */
  38.   curl_easy_setopt(curl_handle, CURLOPT_URL, "http://85.17.176.134:8020");
  39.  
  40.   /* no progress meter please */
  41.   curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
  42.  
  43.   /* no body */
  44.   curl_easy_setopt( curl_handle, CURLOPT_NOBODY, 1);
  45.  
  46.   /* add header strings **/
  47.   struct curl_slist *slist=NULL;
  48.   slist = curl_slist_append(slist, "ICY 200 OK");
  49.  
  50.   curl_easy_setopt( curl_handle, CURLOPT_HTTP200ALIASES, slist);
  51.  
  52.   /* tried : no change :(
  53.    *
  54.    * struct curl_slist *header_list=NULL;
  55.    * header_list = curl_slist_append(header_list, "icy-metadata: 1");
  56.    * curl_easy_setopt( curl_handle, CURLOPT_HTTPHEADER, header_list);
  57.    */
  58.  
  59.   //curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "winamp");
  60.   curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
  61.   curl_easy_setopt(curl_handle, CURLOPT_AUTOREFERER, 1);
  62.  
  63.   /* send all data to this function  */
  64.   curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
  65.  
  66.   /* open the files */
  67.   headerfile = fopen(headerfilename,"w");
  68.   if (headerfile == NULL) {
  69.     curl_easy_cleanup(curl_handle);
  70.     return -1;
  71.   }
  72.  
  73.   /* we want the headers to this file handle */
  74.   curl_easy_setopt(curl_handle,   CURLOPT_WRITEHEADER, headerfile);
  75.  
  76.   /*
  77.    * Notice here that if you want the actual data sent anywhere else but
  78.    * stdout, you should consider using the CURLOPT_WRITEDATA option.  */
  79.  
  80.   /* get it! */
  81.   curl_easy_perform(curl_handle);
  82.  
  83.   /* close the header file */
  84.   fclose(headerfile);
  85.  
  86.   /* free the list */
  87.    curl_slist_free_all(slist);
  88.  
  89.   /* cleanup curl stuff */
  90.   curl_easy_cleanup(curl_handle);
  91.  
  92.   return 0;
  93. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top