varnish-cache/lib/libvmod_directors/shard_parse_vcc_enums.c
1
/*
2
 * for the time being, this code is auto-generated outside the varnishd source
3
 * tree, see
4
 * https://code.uplex.de/uplex-varnish/libvmod-vslp/blob/shard/src/gen_enum_parse.pl
5
 *
6
 * TODO: integrate in vmodtool.py or replace with something else
7
 */
8
9
/*lint -e801 */
10
11
#include "shard_parse_vcc_enums.h"
12
#define term(c) ((c) == '\0')
13
14
15
16 124
enum alg_e parse_alg_e (const char *m) {
17
        enum alg_e r;
18
19 124
        switch (m[0]) {
20 36
        case 'C':       goto _0C;       // CRC32
21 8
        case 'R':       goto _0R;       // RS
22 80
        case 'S':       goto _0S;       // SHA256
23 0
        default:        goto invalid;
24
        }
25
         _0C:
26
        //CRC32
27 36
        if ((m[1] == 'R') && (m[2] == 'C') && (m[3] == '3') && (m[4] == '2') && (term(m[5]))) {
28 36
            r = CRC32;
29 36
            goto ok;
30
        }
31 0
        goto invalid;
32
         _0R:
33
        //RS
34 8
        if ((m[1] == 'S') && (term(m[2]))) {
35 8
            r = RS;
36 8
            goto ok;
37
        }
38 0
        goto invalid;
39
         _0S:
40
        //SHA256
41 80
        if ((m[1] == 'H') && (m[2] == 'A') && (m[3] == '2') && (m[4] == '5') && (m[5] == '6') && (term(m[6]))) {
42 80
            r = SHA256;
43 80
            goto ok;
44
        }
45 0
        goto invalid;
46
  ok:
47 124
        return r;
48
  invalid:
49 0
    return _ALG_E_INVALID;
50
}
51
52
53 74
enum by_e parse_by_e (const char *m) {
54
        enum by_e r;
55
56 74
        switch (m[0]) {
57 0
        case 'B':       goto _0B;       // BLOB
58 18
        case 'H':       goto _0H;       // HASH
59 56
        case 'K':       goto _0K;       // KEY
60 0
        case 'U':       goto _0U;       // URL
61 0
        default:        goto invalid;
62
        }
63
         _0B:
64
        //BLOB
65 0
        if ((m[1] == 'L') && (m[2] == 'O') && (m[3] == 'B') && (term(m[4]))) {
66 0
            r = BY_BLOB;
67 0
            goto ok;
68
        }
69 0
        goto invalid;
70
         _0H:
71
        //HASH
72 18
        if ((m[1] == 'A') && (m[2] == 'S') && (m[3] == 'H') && (term(m[4]))) {
73 18
            r = BY_HASH;
74 18
            goto ok;
75
        }
76 0
        goto invalid;
77
         _0K:
78
        //KEY
79 56
        if ((m[1] == 'E') && (m[2] == 'Y') && (term(m[3]))) {
80 56
            r = BY_KEY;
81 56
            goto ok;
82
        }
83 0
        goto invalid;
84
         _0U:
85
        //URL
86 0
        if ((m[1] == 'R') && (m[2] == 'L') && (term(m[3]))) {
87 0
            r = BY_URL;
88 0
            goto ok;
89
        }
90 0
        goto invalid;
91
  ok:
92 74
        return r;
93
  invalid:
94 0
    return _BY_E_INVALID;
95
}
96
97
98 74
enum healthy_e parse_healthy_e (const char *m) {
99
        enum healthy_e r;
100
101 74
        switch (m[0]) {
102 12
        case 'A':       goto _0A;       // ALL
103 62
        case 'C':       goto _0C;       // CHOSEN
104 0
        case 'I':       goto _0I;       // IGNORE
105 0
        default:        goto invalid;
106
        }
107
         _0A:
108
        //ALL
109 12
        if ((m[1] == 'L') && (m[2] == 'L') && (term(m[3]))) {
110 12
            r = ALL;
111 12
            goto ok;
112
        }
113 0
        goto invalid;
114
         _0C:
115
        //CHOSEN
116 62
        if ((m[1] == 'H') && (m[2] == 'O') && (m[3] == 'S') && (m[4] == 'E') && (m[5] == 'N') && (term(m[6]))) {
117 62
            r = CHOSEN;
118 62
            goto ok;
119
        }
120 0
        goto invalid;
121
         _0I:
122
        //IGNORE
123 0
        if ((m[1] == 'G') && (m[2] == 'N') && (m[3] == 'O') && (m[4] == 'R') && (m[5] == 'E') && (term(m[6]))) {
124 0
            r = IGNORE;
125 0
            goto ok;
126
        }
127 0
        goto invalid;
128
  ok:
129 74
        return r;
130
  invalid:
131 0
    return _HEALTHY_E_INVALID;
132
}