Main Page | Data Structures | Directories | File List | Data Fields | Globals

mrss_download.c File Reference

#include "mrss.h"
#include "mrss_internal.h"

Include dependency graph for mrss_download.c:

Go to the source code of this file.

Functions

static size_t __mrss_memorize_file (void *ptr, size_t size, size_t nmemb, void *data)
__mrss_download_t__mrss_download_file (char *fl)


Function Documentation

__mrss_download_t* __mrss_download_file char *  fl  ) 
 

Definition at line 53 of file mrss_download.c.

References __mrss_memorize_file(), __mrss_download_t__::mm, and __mrss_download_t__::size.

Referenced by mrss_parse_url().

00054 {
00055   __mrss_download_t *chunk;
00056   CURL *curl;
00057 
00058   if (!(chunk = (__mrss_download_t *) malloc (sizeof (__mrss_download_t))))
00059     return NULL;
00060 
00061   chunk->mm = NULL;
00062   chunk->size = 0;
00063 
00064   curl_global_init (CURL_GLOBAL_DEFAULT);
00065   if (!(curl = curl_easy_init ()))
00066     {
00067       free (chunk);
00068       return NULL;
00069     }
00070 
00071   curl_easy_setopt (curl, CURLOPT_URL, fl);
00072   curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, __mrss_memorize_file);
00073   curl_easy_setopt (curl, CURLOPT_FILE, (void *) chunk);
00074   curl_easy_setopt (curl, CURLOPT_TIMEOUT, 10);
00075 
00076   if (curl_easy_perform (curl))
00077     {
00078       if (chunk->mm)
00079         free (chunk->mm);
00080 
00081       free (chunk);
00082 
00083       curl_easy_cleanup (curl);
00084       curl_global_cleanup ();
00085 
00086       return NULL;
00087     }
00088 
00089   curl_easy_cleanup (curl);
00090   curl_global_cleanup ();
00091 
00092   return chunk;
00093 }

Here is the call graph for this function:

static size_t __mrss_memorize_file void *  ptr,
size_t  size,
size_t  nmemb,
void *  data
[static]
 

Definition at line 29 of file mrss_download.c.

References __mrss_download_t__::mm, and __mrss_download_t__::size.

Referenced by __mrss_download_file().

00030 {
00031   register int realsize = size * nmemb;
00032   __mrss_download_t *mem = (__mrss_download_t *) data;
00033 
00034   if (!mem->mm)
00035     {
00036       if (!(mem->mm = (char *) malloc (realsize + 1)))
00037         return -1;
00038     }
00039   else
00040     {
00041       if (!(mem->mm = (char *) realloc (mem->mm, mem->size + realsize + 1)))
00042         return -1;
00043     }
00044 
00045   memcpy (&(mem->mm[mem->size]), ptr, realsize);
00046   mem->size += realsize;
00047   mem->mm[mem->size] = 0;
00048 
00049   return realsize;
00050 }


Generated on Thu Jul 28 12:15:06 2005 for libmrss by  doxygen 1.4.3-20050530