-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhttp_cache.c
More file actions
68 lines (59 loc) · 1.51 KB
/
Copy pathhttp_cache.c
File metadata and controls
68 lines (59 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (C) 2021 Edward LEI <edward_lei72@hotmail.com>
*
* license: MIT license
*/
#include <stdlib.h>
#include <string.h>
#include "linkedlist.h"
#include "http_cache.h"
//#define DEBUG
#include "debug.h"
cache_data_t *http_cache_data_new()
{
cache_data_t *data = malloc(sizeof(struct _cache_data));
return data;
}
void http_set_cache_data(cache_data_t *data,
char *path,
char *etag,
char *modified,
unsigned char *body,
const size_t len_body,
unsigned char *body_zipped,
const size_t len_zipped)
{
data->path = path;
data->etag = etag;
data->last_modified = modified;
data->body = body;
data->len_body = len_body;
data->body_zipped = body_zipped;
data->len_zipped = len_zipped;
}
void http_cache_data_destroy(cache_data_t *data)
{
if (data) {
if (data->path) free(data->path);
if (data->etag) free(data->etag);
if (data->last_modified) free(data->last_modified);
if (data->body) free(data->body);
if (data->body_zipped) free(data->body_zipped);
free(data);
}
}
cache_data_t *http_cache_data(list_t *cache,
const char *path)
{
node_t *node = list_first(cache);
if (node) {
do {
cache_data_t *data = node->data;
if (strcmp(path, data->path) == 0) {
return data;
}
node = list_next(cache);
} while (node);
}
return NULL;
}