ZOO-Project
Functions
caching.c File Reference
#include "caching.h"
#include "service.h"
#include "service_internal.h"
#include "response_print.h"
#include <openssl/md5.h>
#include <openssl/hmac.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>

Functions

char * getMd5 (char *url)
 Compute md5. More...
 
void addToCache (maps *conf, char *request, char *content, char *mimeType, int length, char *filepath, size_t max_path)
 Cache a file for a given request. More...
 
char * isInCache (maps *conf, char *request)
 Verify if a url is available in the cache. More...
 
int readCurrentInput (maps **m, maps **in, int *index, HINTERNET *hInternet, map **error)
 Read the downloaded file for a specific input. More...
 
int runHttpRequests (maps **m, maps **inputs, HINTERNET *hInternet, map **error)
 Effectively run all the HTTP requests in the queue. More...
 
void addRequestToQueue (maps **m, HINTERNET *hInternet, const char *url, bool req)
 Add a request in the download queue. More...
 
int loadRemoteFile (maps **m, map **content, HINTERNET *hInternet, char *url)
 Try to load file from cache or download a remote file if not in cache. More...
 

Function Documentation

void addRequestToQueue ( maps **  m,
HINTERNET hInternet,
const char *  url,
bool  req 
)

Add a request in the download queue.

Parameters
mthe maps containing the settings of the main.cfg file
urlthe url to add to the queue
void addToCache ( maps conf,
char *  request,
char *  content,
char *  mimeType,
int  length,
char *  filepath,
size_t  max_path 
)

Cache a file for a given request.

For each cached file, the are two files stored, a .zca and a .zcm containing the downloaded content and the mimeType respectively.

Parameters
confthe maps containing the settings of the main.cfg file
requestthe url used too fetch the content
contentthe downloaded content
mimeTypethe content mimeType
lengththe content size
filepatha buffer for storing the path of the cached file; may be NULL
max_paththe size of the allocated filepath buffer
char* getMd5 ( char *  url)

Compute md5.

Parameters
urlthe char*
Returns
a char* representing the md5 of the url
Warning
make sure to free resources returned by this function
char* isInCache ( maps conf,
char *  request 
)

Verify if a url is available in the cache.

Parameters
confthe maps containing the settings of the main.cfg file
requestthe url
Returns
the full name of the cached file if any, NULL in other case
Warning
make sure to free resources returned by this function (if not NULL)
int loadRemoteFile ( maps **  m,
map **  content,
HINTERNET hInternet,
char *  url 
)

Try to load file from cache or download a remote file if not in cache.

Parameters
mthe maps containing the settings of the main.cfg file
contentthe map to update
hInternetthe HINTERNET pointer
urlthe url to fetch
Returns
0
int readCurrentInput ( maps **  m,
maps **  in,
int *  index,
HINTERNET hInternet,
map **  error 
)

Read the downloaded file for a specific input.

Parameters
mthe maps containing the settings of the main.cfg file
inthe input
indexthe input index
hInternetthe internet connection
errorthe error map pointer
Returns
0 in case of success, -1 in case of failure
int runHttpRequests ( maps **  m,
maps **  inputs,
HINTERNET hInternet,
map **  error 
)

Effectively run all the HTTP requests in the queue.

Parameters
mthe maps containing the settings of the main.cfg file
inputsthe maps containing the inputs (defined in the requests+added per default based on the zcfg file)
hInternetthe HINTERNET pointer
errorthe error map pointer
Returns
0 on success, -1 on failure