summaryrefslogtreecommitdiff
path: root/src/http_decoder_string.h
blob: 9fe82e1c569e1db235e71cb2905aca872c45c9ad (plain)
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
69
70
71
72
73
74
#ifndef _HTTP_DECODER_STRING_H_
#define _HTTP_DECODER_STRING_H_

#include "http_decoder.h"

enum string_state {
    STRING_STATE_INIT,
    STRING_STATE_REFER,
    STRING_STATE_CACHE,
    STRING_STATE_COMMIT,
};

/* state transition diagram
 *       +----------+
 *       |          |
 *      \|/         |
 *    +------+      |
 *    | init |      |
 *    +------+      |
 *       |          |
 * +---->|          |
 * |    \|/         |
 * |  +-------+     |
 * |  | refer |--+  |
 * |  +-------+  |  |
 * |     |       |  |
 * |    \|/      |  |
 * |  +-------+  |  |
 * +--| cache |  |  |
 *    +-------+  |  |
 *       |       |  |
 *       |<------+  |
 *      \|/         |
 *    +--------+    |
 *    | commit |    |
 *    +--------+    |
 *       |          |
 *      \|/         |
 *    +--------+    |
 *    | reset  |----+
 *    +--------+
 */


//http decoder string
struct http_decoder_string {
    hstring refer; // shallow copy
    hstring cache; // deep copy
    hstring commit;

    enum string_state state;
    size_t max_cache_size;
};

void http_decoder_string_refer(struct http_decoder_string *rstr,
                               const char *at, size_t length);

void http_decoder_string_cache(struct http_decoder_string *rstr);

void http_decoder_string_commit(struct http_decoder_string *rstr);

void http_decoder_string_reset(struct http_decoder_string *rstr);

void http_decoder_string_init(struct http_decoder_string *rstr,
                              size_t max_cache_size);

void http_decoder_string_reinit(struct http_decoder_string *rstr);

enum string_state http_decoder_string_state(const struct http_decoder_string *rstr);

int http_decoder_string_get(const struct http_decoder_string *rstr, hstring *out);

void http_decoder_string_dump(struct http_decoder_string *rstr, const char *desc);
#endif