summaryrefslogtreecommitdiff
path: root/redis2-nginx-module-0.15/src/common.rl
blob: 17083dedd6e86c74575c0df93aa949e1edfa4d35 (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
75
76
%%{
    machine common;

    action read_char {
        dd("reading %c", *p);
    }

    CR = "\r";
    LF = "\n";
    CRLF = CR LF; # $read_char;

    action finalize {
        dd("done!");
        done = 1;
    }

    action read_size {
        ctx->chunk_size *= 10;
        ctx->chunk_size += *p - '0';
        dd("read chunk size: %d", (int) ctx->chunk_size);
    }

    action start_reading_size {
        dd("start reading chunk size");
        ctx->chunk_bytes_read = 0;
        ctx->chunk_size = 0;
    }

    action start_reading_data {
        dd("start reading data");
        ctx->chunk_bytes_read = 0;
    }

    action test_len {
#if 0
        fprintf(stderr, "test chunk len: %d < %d\n",
            (int) ctx->chunk_bytes_read, (int) ctx->chunk_size),
#endif
        ctx->chunk_bytes_read++ < ctx->chunk_size
    }

    chunk_size = ([1-9] digit*) >start_reading_size $read_size
               ;

    chunk_data_octet = any when test_len
                     ;

    chunk_data = chunk_data_octet+;

    action read_chunk {
        ctx->chunks_read++;
        dd("have read chunk %d, %.*s", (int) ctx->chunks_read,
            (int) (p - (signed char *) b->last), (signed char *) b->last);
    }

    action check_data_complete {
#if 0
        fprintf(stderr,
            "check_data_complete: chunk bytes read: %d, chunk size: %d\n",
            (int) ctx->chunk_bytes_read, (int) ctx->chunk_size),
#endif
        ctx->chunk_bytes_read == ctx->chunk_size + 1
    }

    trailer = CRLF @read_chunk
            ;

    chunk = "$" "0"+ CRLF trailer
          | "$-" digit+ trailer
          | "$" chunk_size CRLF chunk_data CR when check_data_complete LF @read_chunk
          ;

    single_line_reply = [:\+\-] (any* -- CRLF) CRLF;

}%%