Skip to content

Commit

Permalink
fixed the multi-bulk parser: we did not allow zero digit in the bulk …
Browse files Browse the repository at this point in the history
…count number. sigh. and we did not allow empty multi bulk list. also applied some minor optimizations there.
  • Loading branch information
agentzh committed Feb 12, 2011
1 parent 74bc096 commit 62f5b6a
Show file tree
Hide file tree
Showing 5 changed files with 809 additions and 395 deletions.
20 changes: 15 additions & 5 deletions src/common.rl
@@ -1,7 +1,11 @@
%%{
machine common;

CRLF = "\r\n";
action read_char {
dd("reading %c", *p);
}

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

action finalize {
dd("done!");
Expand All @@ -15,14 +19,21 @@
}

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
}

Expand All @@ -32,13 +43,12 @@
chunk_data_octet = any when test_len
;

chunk_data = chunk_data_octet+
>start_reading_data
;
chunk_data = chunk_data_octet+;

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

trailer = CRLF @read_chunk
Expand Down
33 changes: 21 additions & 12 deletions src/multi_bulk_reply.rl
Expand Up @@ -4,14 +4,20 @@
include common "common.rl";

action test_chunk_count {
#if 0
fprintf(stderr, "test chunk count: %d < %d\n",
(int) ctx->chunks_read, (int) ctx->chunk_count),
#endif
ctx->chunks_read < ctx->chunk_count
}

action start_reading_chunk {
dd("start reading bulk");
ctx->chunks_read = 0;
}

action start_reading_count {
dd("start reading bulk count");
ctx->chunk_count = 0;
}

Expand All @@ -21,25 +27,28 @@
dd("chunk count: %d", (int) ctx->chunk_count);
}

protected_chunk = chunk when test_chunk_count
;

chunk_count = (digit+ -- "0"+) >start_reading_count $read_count
;

response = "*" chunk_count CRLF
(protected_chunk+ >start_reading_chunk)
;

action multi_bulk_finalize {
dd("done!");
dd("finalize multi bulks");

if (ctx->chunks_read == ctx->chunk_count) {
dd("done multi bunlk reading!");
done = 1;
}
}

protected_chunk = chunk when test_chunk_count
;

chunk_count = ([1-9] digit*) >start_reading_count $read_count
;

response = "*" "0"+ CRLF @multi_bulk_finalize
| "*" chunk_count CRLF
(protected_chunk+ >start_reading_chunk)
@multi_bulk_finalize
;

main := response @multi_bulk_finalize
main := response
;

}%%
Expand Down

0 comments on commit 62f5b6a

Please sign in to comment.