mongrel_esi 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. data/README +10 -9
  2. data/doc/rdoc/classes/ESI/Cache.html +10 -10
  3. data/doc/rdoc/classes/ESI/Cache.src/{M000085.html → M000087.html} +0 -0
  4. data/doc/rdoc/classes/ESI/Cache.src/{M000086.html → M000088.html} +0 -0
  5. data/doc/rdoc/classes/ESI/Config.html +43 -62
  6. data/doc/rdoc/classes/ESI/Config.src/M000049.html +18 -0
  7. data/doc/rdoc/classes/ESI/Config.src/{M000059.html → M000050.html} +5 -5
  8. data/doc/rdoc/classes/ESI/Config.src/M000051.html +35 -0
  9. data/doc/rdoc/classes/ESI/Config.src/M000052.html +27 -5
  10. data/doc/rdoc/classes/ESI/Config.src/M000053.html +10 -5
  11. data/doc/rdoc/classes/ESI/Config.src/M000054.html +5 -22
  12. data/doc/rdoc/classes/ESI/Config.src/M000055.html +7 -25
  13. data/doc/rdoc/classes/ESI/Config.src/M000056.html +11 -10
  14. data/doc/rdoc/classes/ESI/Config/CacheConfig.html +25 -25
  15. data/doc/rdoc/classes/ESI/Config/CacheConfig.src/{M000068.html → M000060.html} +6 -5
  16. data/doc/rdoc/classes/ESI/Config/CacheConfig.src/{M000065.html → M000061.html} +5 -5
  17. data/doc/rdoc/classes/ESI/Config/CacheConfig.src/{M000066.html → M000062.html} +4 -4
  18. data/doc/rdoc/classes/ESI/Config/CacheConfig.src/{M000067.html → M000063.html} +4 -4
  19. data/doc/rdoc/classes/ESI/Config/CacheConfig.src/M000064.html +5 -6
  20. data/doc/rdoc/classes/ESI/Config/ConfigRouter.html +15 -15
  21. data/doc/rdoc/classes/ESI/Config/ConfigRouter.src/{M000061.html → M000057.html} +5 -5
  22. data/doc/rdoc/classes/ESI/Config/ConfigRouter.src/{M000062.html → M000058.html} +7 -7
  23. data/doc/rdoc/classes/ESI/Config/ConfigRouter.src/{M000063.html → M000059.html} +7 -7
  24. data/doc/rdoc/classes/ESI/Dispatcher.html +17 -15
  25. data/doc/rdoc/classes/ESI/Dispatcher.src/{M000087.html → M000092.html} +4 -7
  26. data/doc/rdoc/classes/ESI/Dispatcher.src/M000093.html +27 -0
  27. data/doc/rdoc/classes/ESI/Fragment.html +15 -15
  28. data/doc/rdoc/classes/ESI/Fragment.src/{M000100.html → M000111.html} +0 -0
  29. data/doc/rdoc/classes/ESI/Fragment.src/{M000101.html → M000112.html} +0 -0
  30. data/doc/rdoc/classes/ESI/Fragment.src/{M000102.html → M000113.html} +0 -0
  31. data/doc/rdoc/classes/ESI/MemcachedCache.html +46 -46
  32. data/doc/rdoc/classes/ESI/MemcachedCache.src/M000037.html +24 -0
  33. data/doc/rdoc/classes/ESI/MemcachedCache.src/M000038.html +22 -0
  34. data/doc/rdoc/classes/ESI/MemcachedCache.src/M000039.html +19 -0
  35. data/doc/rdoc/classes/ESI/MemcachedCache.src/M000040.html +10 -11
  36. data/doc/rdoc/classes/ESI/MemcachedCache.src/M000041.html +5 -9
  37. data/doc/rdoc/classes/ESI/MemcachedCache.src/M000042.html +6 -6
  38. data/doc/rdoc/classes/ESI/MemcachedCache.src/M000043.html +5 -10
  39. data/doc/rdoc/classes/ESI/MemcachedCache.src/M000044.html +5 -5
  40. data/doc/rdoc/classes/ESI/MemcachedCache.src/M000045.html +4 -6
  41. data/doc/rdoc/classes/ESI/OutputAdapter.html +204 -0
  42. data/doc/rdoc/classes/ESI/OutputAdapter.src/M000094.html +37 -0
  43. data/doc/rdoc/classes/ESI/OutputAdapter.src/M000095.html +18 -0
  44. data/doc/rdoc/classes/ESI/OutputAdapter.src/M000096.html +18 -0
  45. data/doc/rdoc/classes/ESI/OutputAdapter.src/M000097.html +18 -0
  46. data/doc/rdoc/classes/ESI/Parser.html +15 -15
  47. data/doc/rdoc/classes/ESI/Parser.src/{M000049.html → M000065.html} +0 -0
  48. data/doc/rdoc/classes/ESI/Parser.src/{M000050.html → M000066.html} +0 -0
  49. data/doc/rdoc/classes/ESI/Parser.src/{M000051.html → M000067.html} +0 -0
  50. data/doc/rdoc/classes/ESI/Processor.html +15 -15
  51. data/doc/rdoc/classes/ESI/Processor.src/{M000037.html → M000046.html} +0 -0
  52. data/doc/rdoc/classes/ESI/Processor.src/{M000038.html → M000047.html} +1 -1
  53. data/doc/rdoc/classes/ESI/Processor.src/{M000039.html → M000048.html} +0 -0
  54. data/doc/rdoc/classes/ESI/Proxy.html +48 -48
  55. data/doc/rdoc/classes/ESI/Proxy.src/M000071.html +7 -40
  56. data/doc/rdoc/classes/ESI/Proxy.src/M000072.html +50 -12
  57. data/doc/rdoc/classes/ESI/Proxy.src/M000073.html +49 -6
  58. data/doc/rdoc/classes/ESI/Proxy.src/M000074.html +11 -14
  59. data/doc/rdoc/classes/ESI/Proxy.src/M000075.html +6 -5
  60. data/doc/rdoc/classes/ESI/Proxy.src/M000076.html +9 -15
  61. data/doc/rdoc/classes/ESI/Proxy.src/M000077.html +5 -16
  62. data/doc/rdoc/classes/ESI/Proxy.src/M000078.html +28 -0
  63. data/doc/rdoc/classes/ESI/Proxy.src/M000079.html +29 -0
  64. data/doc/rdoc/classes/ESI/RackAdapter.html +214 -0
  65. data/doc/rdoc/classes/ESI/RackAdapter.src/M000068.html +18 -0
  66. data/doc/rdoc/classes/ESI/RackAdapter.src/M000069.html +34 -0
  67. data/doc/rdoc/classes/ESI/{MemcachedCache.src/M000048.html → RackAdapter.src/M000070.html} +4 -4
  68. data/doc/rdoc/classes/ESI/RackConfig.html +173 -0
  69. data/doc/rdoc/classes/ESI/RackConfig.src/M000089.html +28 -0
  70. data/doc/rdoc/classes/ESI/RackConfig.src/M000090.html +18 -0
  71. data/doc/rdoc/classes/ESI/RackConfig.src/M000091.html +20 -0
  72. data/doc/rdoc/classes/ESI/Request.html +158 -0
  73. data/doc/rdoc/classes/ESI/{MemcachedCache.src/M000046.html → Request.src/M000098.html} +5 -5
  74. data/doc/rdoc/classes/ESI/Request.src/M000099.html +18 -0
  75. data/doc/rdoc/classes/ESI/Response.html +36 -36
  76. data/doc/rdoc/classes/ESI/Response.src/M000080.html +10 -8
  77. data/doc/rdoc/classes/ESI/Response.src/M000081.html +5 -7
  78. data/doc/rdoc/classes/ESI/Response.src/M000082.html +8 -12
  79. data/doc/rdoc/classes/ESI/Response.src/M000083.html +7 -5
  80. data/doc/rdoc/classes/ESI/Response.src/M000084.html +12 -20
  81. data/doc/rdoc/classes/ESI/Response.src/{M000079.html → M000085.html} +5 -5
  82. data/doc/rdoc/classes/ESI/Response.src/M000086.html +33 -0
  83. data/doc/rdoc/classes/ESI/Router.html +10 -10
  84. data/doc/rdoc/classes/ESI/Router.src/{M000098.html → M000109.html} +0 -0
  85. data/doc/rdoc/classes/ESI/Router.src/{M000099.html → M000110.html} +0 -0
  86. data/doc/rdoc/classes/ESI/RubyCache.html +45 -45
  87. data/doc/rdoc/classes/ESI/RubyCache.src/{M000089.html → M000100.html} +6 -6
  88. data/doc/rdoc/classes/ESI/RubyCache.src/{M000090.html → M000101.html} +6 -6
  89. data/doc/rdoc/classes/ESI/RubyCache.src/{M000091.html → M000102.html} +6 -6
  90. data/doc/rdoc/classes/ESI/RubyCache.src/{M000092.html → M000103.html} +8 -8
  91. data/doc/rdoc/classes/ESI/RubyCache.src/{M000093.html → M000104.html} +4 -4
  92. data/doc/rdoc/classes/ESI/RubyCache.src/{M000094.html → M000105.html} +8 -8
  93. data/doc/rdoc/classes/ESI/RubyCache.src/{M000095.html → M000106.html} +4 -4
  94. data/doc/rdoc/classes/ESI/RubyCache.src/{M000096.html → M000107.html} +4 -4
  95. data/doc/rdoc/classes/ESI/RubyCache.src/{M000097.html → M000108.html} +4 -4
  96. data/doc/rdoc/classes/ESI/Tag.html +8 -8
  97. data/doc/rdoc/created.rid +1 -1
  98. data/doc/rdoc/files/COPYING.html +1 -1
  99. data/doc/rdoc/files/LICENSE.html +1 -1
  100. data/doc/rdoc/files/README.html +12 -10
  101. data/doc/rdoc/files/ext/esi/common_rl.html +1 -1
  102. data/doc/rdoc/files/ext/esi/esi_parser_c.html +1 -1
  103. data/doc/rdoc/files/ext/esi/parser_c.html +1 -1
  104. data/doc/rdoc/files/ext/esi/parser_h.html +1 -1
  105. data/doc/rdoc/files/ext/esi/parser_rl.html +122 -82
  106. data/doc/rdoc/files/ext/esi/test/test_c.html +1 -1
  107. data/doc/rdoc/files/lib/esi/cache_rb.html +2 -1
  108. data/doc/rdoc/files/lib/esi/config_rb.html +2 -1
  109. data/doc/rdoc/files/lib/esi/dispatcher_rb.html +3 -1
  110. data/doc/rdoc/files/lib/esi/invalidator_rb.html +1 -1
  111. data/doc/rdoc/files/lib/esi/logger_rb.html +1 -1
  112. data/doc/rdoc/files/lib/esi/parser_rb.html +1 -1
  113. data/doc/rdoc/files/lib/esi/processor_rb.html +1 -1
  114. data/doc/rdoc/files/lib/esi/proxy_rb.html +2 -2
  115. data/doc/rdoc/files/{ext/esi/test/parser_c.html → lib/esi/rack_adapter_rb.html} +21 -5
  116. data/doc/rdoc/files/lib/esi/response_rb.html +1 -1
  117. data/doc/rdoc/files/lib/esi/router_rb.html +1 -1
  118. data/doc/rdoc/files/lib/esi/tag/attempt_rb.html +1 -1
  119. data/doc/rdoc/files/lib/esi/tag/base_rb.html +1 -1
  120. data/doc/rdoc/files/lib/esi/tag/container_rb.html +1 -1
  121. data/doc/rdoc/files/lib/esi/tag/except_rb.html +1 -1
  122. data/doc/rdoc/files/lib/esi/tag/include_rb.html +1 -1
  123. data/doc/rdoc/files/lib/esi/tag/invalidate_rb.html +1 -1
  124. data/doc/rdoc/files/lib/esi/tag/try_rb.html +1 -1
  125. data/doc/rdoc/files/lib/esi/version_rb.html +1 -1
  126. data/doc/rdoc/files/lib/multi_dirhandler_rb.html +1 -1
  127. data/doc/rdoc/fr_class_index.html +4 -0
  128. data/doc/rdoc/fr_file_index.html +1 -5
  129. data/doc/rdoc/fr_method_index.html +87 -76
  130. data/ext/esi/esi_parser.c +2 -2
  131. data/ext/esi/parser.c +133 -107
  132. data/ext/esi/parser.h +9 -4
  133. data/ext/esi/parser.rl +99 -73
  134. data/ext/esi/test/test.c +11 -6
  135. data/lib/esi/cache.rb +7 -3
  136. data/lib/esi/config.rb +4 -8
  137. data/lib/esi/dispatcher.rb +14 -5
  138. data/lib/esi/processor.rb +1 -1
  139. data/lib/esi/proxy.rb +58 -48
  140. data/lib/esi/rack_adapter.rb +97 -0
  141. data/lib/esi/response.rb +30 -1
  142. data/lib/esi/version.rb +1 -1
  143. data/test/bench-plot.rb +31 -0
  144. data/test/benchmarks/csv-perf-serial0.4 +101 -0
  145. data/test/benchmarks/csv-perf-trunk +101 -0
  146. data/test/benchmarks/perf-serial0.4-n1000-c1.csv +101 -0
  147. data/test/benchmarks/perf-serial0.4-n1000-c2.csv +101 -0
  148. data/test/benchmarks/perf-serial0.4-n1000-c3.csv +101 -0
  149. data/test/benchmarks/perf-serial0.4-n1000-c4.csv +101 -0
  150. data/test/benchmarks/perf-serial0.4-n1000-c5.csv +101 -0
  151. data/test/benchmarks/perf-serial0.4-n1000-c6.csv +101 -0
  152. data/test/benchmarks/perf-serial0.4-n1000-c7.csv +101 -0
  153. data/test/benchmarks/perf-trunk-n1000-c1.csv +101 -0
  154. data/test/benchmarks/perf-trunk-n1000-c2.csv +101 -0
  155. data/test/benchmarks/perf-trunk-n1000-c3.csv +101 -0
  156. data/test/benchmarks/perf-trunk-n1000-c4.csv +101 -0
  157. data/test/benchmarks/perf-trunk-n1000-c5.csv +101 -0
  158. data/test/benchmarks/perf-trunk-n1000-c6.csv +101 -0
  159. data/test/benchmarks/perf-trunk-n1000-c7.csv +101 -0
  160. data/test/load_test.rb +5 -2
  161. data/test/load_test_ab.rb +9 -4
  162. metadata +261 -227
  163. data/doc/rdoc/classes/ESI/Config.src/M000057.html +0 -18
  164. data/doc/rdoc/classes/ESI/Config.src/M000058.html +0 -20
  165. data/doc/rdoc/classes/ESI/Config.src/M000060.html +0 -24
  166. data/doc/rdoc/classes/ESI/Dispatcher.src/M000088.html +0 -18
  167. data/doc/rdoc/classes/ESI/MemcachedCache.src/M000047.html +0 -18
  168. data/doc/rdoc/classes/ESI/Proxy.src/M000069.html +0 -20
  169. data/doc/rdoc/classes/ESI/Proxy.src/M000070.html +0 -55
  170. data/doc/rdoc/classes/ESI/Response.src/M000078.html +0 -23
  171. data/doc/rdoc/files/ext/esi/test/common_rl.html +0 -160
  172. data/doc/rdoc/files/ext/esi/test/parser_h.html +0 -101
  173. data/doc/rdoc/files/ext/esi/test/parser_rl.html +0 -827
  174. data/doc/rdoc/files/ext/esi/test/sp_c.html +0 -101
  175. data/ext/esi/test/common.rl +0 -46
  176. data/ext/esi/test/parser.c +0 -1875
  177. data/ext/esi/test/parser.h +0 -120
  178. data/ext/esi/test/parser.rl +0 -585
  179. data/ext/esi/test/sp.c +0 -125
@@ -1,120 +0,0 @@
1
- /**
2
- * Copyright (c) 2007 Todd A. Fisher
3
- * You can redistribute it and/or modify it under the same terms as Mozilla Public License 1.1.
4
- */
5
- #ifndef ESI_PARSER_H
6
- #define ESI_PARSER_H
7
- #include <sys/types.h>
8
-
9
- /* how much output to hold in memory before sending out */
10
- #define ESI_OUTPUT_BUFFER_SIZE 1024
11
-
12
- char *esi_strndup( const char *str, size_t len );
13
-
14
- /*
15
- * ESI Attribute is a single attribute with name and value
16
- *
17
- * e.g. for an esi include tag:
18
- *
19
- * <esi:include src='/foo/bar/' timeout='10'/>
20
- *
21
- * 2 attributes would be allocated
22
- *
23
- * attrs[0]->name => 'src'
24
- * attrs[0]->value => '/foo/bar/'
25
- *
26
- * attrs[1]->name => 'timeout'
27
- * attrs[1]->value => '10'
28
- *
29
- * */
30
- typedef struct _ESIAttr {
31
- char *name;
32
- char *value;
33
- struct _ESIAttr *next;
34
- }ESIAttribute;
35
-
36
- ESIAttribute *esi_attribute_new( const char *name, size_t name_length, const char *value, size_t value_length );
37
- ESIAttribute *esi_attribute_copy( ESIAttribute *attribute );
38
- void esi_attribute_free( ESIAttribute *attribute );
39
-
40
- typedef void (*start_tag_cb)(const void *data,
41
- const char *name_start,
42
- size_t name_length,
43
- ESIAttribute *attributes,
44
- void *user_data);
45
-
46
- typedef void (*end_tag_cb)(const void *data,
47
- const char *name_start,
48
- size_t name_length,
49
- void *user_data);
50
-
51
- typedef void (*output_cb)(const void *data,
52
- size_t length,
53
- void *user_data);
54
-
55
- typedef struct _ESIParser {
56
- int cs;
57
- int prev_state;
58
-
59
- void *user_data;
60
-
61
- const char *mark;
62
- size_t overflow_data_size; /* current size of the overflow data buffer */
63
- char *overflow_data; /* overflow buffer if execute finishes and we are not in a final state store the parse data */
64
-
65
- size_t echobuffer_allocated; /* amount of memory allocated for the echobuffer */
66
- size_t echobuffer_index; /* current write position of the last echo'ed character */
67
- char *echobuffer; /* echo buffer if the parse state is not 0 we store the characters here */
68
-
69
- const char *tag_text; /* start pointer in data */
70
- size_t tag_text_length; /* length from tag_text within data */
71
-
72
- const char *attr_key; /* start pointer in data */
73
- size_t attr_key_length;
74
-
75
- const char *attr_value; /* start pointer in data */
76
- size_t attr_value_length;
77
-
78
- ESIAttribute *attributes, *last;
79
-
80
- /* this memory will be pass to the output_cb when either it's full
81
- * or eof is encountered */
82
- char output_buffer[ESI_OUTPUT_BUFFER_SIZE+1];
83
- size_t output_buffer_size;
84
-
85
- start_tag_cb start_tag_handler;
86
- end_tag_cb end_tag_handler;
87
- output_cb output_handler;
88
-
89
- } ESIParser;
90
-
91
- /* create a new Edge Side Include Parser */
92
- ESIParser *esi_parser_new();
93
- void esi_parser_free( ESIParser *parser );
94
-
95
- /* initialize the parser */
96
- int esi_parser_init( ESIParser *parser );
97
-
98
- /*
99
- * send a chunk of data to the parser, the internal parser state is returned
100
- */
101
- int esi_parser_execute( ESIParser *parser, const char *data, size_t length );
102
- /*
103
- * let the parser no that it has reached the end and it should flush any remaining data to the desired output device
104
- */
105
- int esi_parser_finish( ESIParser *parser );
106
-
107
- /*
108
- * setup a callback to execute when a new esi: start tag is encountered
109
- * this is will fire for all block tags e.g. <esi:try>, <esi:attempt> and also
110
- * inline tags <esi:inline src='cache-key'/> <esi:include src='dest'/>
111
- */
112
- void esi_parser_start_tag_handler( ESIParser *parser, start_tag_cb callback );
113
-
114
- void esi_parser_end_tag_handler( ESIParser *parser, end_tag_cb callback );
115
-
116
- /* setup a callback to recieve data ready for output */
117
- void esi_parser_output_handler( ESIParser *parser, output_cb output_handler );
118
-
119
-
120
- #endif
@@ -1,585 +0,0 @@
1
- /**
2
- * Copyright (c) 2008 Todd A. Fisher
3
- * see LICENSE
4
- */
5
- #include <stdio.h>
6
- #include <stdlib.h>
7
- #include <string.h>
8
- #include <ctype.h>
9
- #include "parser.h"
10
-
11
- #ifdef DEBUG
12
- static void debug_string( const char *msg, const char *str, size_t len )
13
- {
14
- char *pstr = esi_strndup( str, len );
15
- printf( "%s :'%s'\n", msg, pstr );
16
- free( pstr );
17
- }
18
- #else
19
- #define debug_string(m,s,l)
20
- #endif
21
-
22
- /* define default callbacks */
23
- static void
24
- esi_parser_default_start_cb( const void *data,
25
- const char *name_start,
26
- size_t name_length,
27
- ESIAttribute *attributes,
28
- void *user_data )
29
- {
30
- }
31
- static void
32
- esi_parser_default_end_cb( const void *data,
33
- const char *name_start,
34
- size_t name_length,
35
- void *user_data )
36
- {
37
- }
38
- static void
39
- esi_parser_default_output_cp(const void *data,
40
- size_t length,
41
- void *user_data)
42
- {
43
- }
44
-
45
- /*
46
- * flush output buffer
47
- */
48
- static void esi_parser_flush_output( ESIParser *parser )
49
- {
50
- if( parser->output_buffer_size > 0 ) {
51
- //debug_string( "esi_parser_flush_output:", parser->output_buffer, parser->output_buffer_size );
52
- parser->output_handler( (void*)parser->output_buffer, parser->output_buffer_size, parser->user_data );
53
- parser->output_buffer_size = 0;
54
- }
55
- }
56
- /* send the character to the output handler marking it
57
- * as ready for consumption, e.g. not an esi tag
58
- */
59
- static void esi_parser_echo_char( ESIParser *parser, char ch )
60
- {
61
- parser->output_buffer[parser->output_buffer_size++] = ch;
62
- if( parser->output_buffer_size == ESI_OUTPUT_BUFFER_SIZE ) {
63
- // flush the buffer to the consumer
64
- esi_parser_flush_output( parser );
65
- }
66
- }
67
- /* send any buffered characters to the output handler.
68
- * This happens when we enter a case such as <em> where the
69
- * first two characters < and e match the <esi: expression
70
- */
71
- static void esi_parser_echo_buffer( ESIParser *parser )
72
- {
73
- size_t i = 0, len = parser->echobuffer_index + 1;;
74
- //debug_string( "echobuffer", parser->echobuffer, parser->echobuffer_index+1 );
75
- //parser->output_handler( parser->echobuffer, parser->echobuffer_index+1, parser->user_data );
76
- for( ; i < len; ++i ) {
77
- esi_parser_echo_char( parser, parser->echobuffer[i] );
78
- }
79
- }
80
- /*
81
- * clear the buffer, no buffered characters should be emitted .
82
- * e.g. we matched an esi tag completely and all buffered characters can be tossed out
83
- */
84
- static void esi_parser_echobuffer_clear( ESIParser *parser )
85
- {
86
- parser->echobuffer_index = -1;
87
- }
88
-
89
- /*
90
- * add a character to the echobuffer.
91
- * this happens when we can't determine if the character is allowed to be sent to the client device
92
- * e.g. matching <e it's not yet determined if these characters are safe to send or not
93
- */
94
- static void esi_parser_concat_to_echobuffer( ESIParser *parser, char ch )
95
- {
96
- parser->echobuffer_index++;
97
-
98
- if( parser->echobuffer_allocated <= parser->echobuffer_index ) {
99
- /* double the echobuffer size
100
- * we're getting some crazy input if this case ever happens
101
- */
102
- parser->echobuffer_allocated *= 2;
103
- parser->echobuffer = (char*)realloc( parser->echobuffer, parser->echobuffer_allocated );
104
- }
105
- parser->echobuffer[parser->echobuffer_index] = ch;
106
- // debug_string( "echo buffer", parser->echobuffer, parser->echobuffer_index+1 );
107
- }
108
- /*
109
- * the mark boundary is not always going to be exactly on the attribute or tag name boundary
110
- * this trims characters from the left to right, advancing *ptr and reducing *len
111
- */
112
- static void ltrim_pointer( const char **ptr, const char *bounds, size_t *len )
113
- {
114
- // remove any spaces or = at the before the value
115
- while( (isspace( **ptr ) ||
116
- **ptr == '=' ||
117
- **ptr == '"' ||
118
- **ptr == '<' ||
119
- **ptr == '\'' ) && (*len > 0) && (*ptr != bounds) ) {
120
- (*ptr)++;
121
- (*len)--;
122
- }
123
- }
124
- /*
125
- * similar to ltrim_pointer, this walks from bounds to *ptr, reducing *len
126
- */
127
- static void rtrim_pointer( const char **ptr, const char *bounds, size_t *len )
128
- {
129
- bounds = (*ptr+(*len-1));
130
- // remove any spaces or = at the before the value
131
- while( (isspace( *bounds ) ||
132
- *bounds == '=' ||
133
- *bounds == '"' ||
134
- *bounds == '>' ||
135
- *bounds == '\'') && (*len > 0) && (*ptr != bounds) ){
136
- bounds--;
137
- (*len)--;
138
- }
139
- }
140
-
141
- %%{
142
- machine esi;
143
-
144
- action begin {
145
- parser->mark = p;
146
- //debug_string( "begin", p, 1 );
147
- }
148
- action finish {
149
- // printf( "finish\n" );
150
- }
151
-
152
- # record the position of the start tag
153
- action see_start_tag {
154
- parser->tag_text = parser->mark+1;
155
- parser->tag_text_length = p - (parser->mark+1);
156
- parser->mark = p;
157
- }
158
-
159
- # detected an inline tag end, sends the start tag and end tag callback
160
- action see_end_tag {
161
- /* trim the tag text */
162
- ltrim_pointer( &(parser->tag_text), p, &(parser->tag_text_length) );
163
- rtrim_pointer( &(parser->tag_text), p, &(parser->tag_text_length) );
164
-
165
- /* send the start tag and end tag message */
166
- esi_parser_flush_output( parser );
167
- parser->start_tag_handler( data, parser->tag_text, parser->tag_text_length, parser->attributes, parser->user_data );
168
- esi_parser_flush_output( parser );
169
- parser->end_tag_handler( data, parser->tag_text, parser->tag_text_length, parser->user_data );
170
- esi_parser_flush_output( parser );
171
-
172
- /* mark the position */
173
- parser->tag_text = NULL;
174
- parser->tag_text_length = 0;
175
- parser->mark = p;
176
-
177
- /* clear out the echo buffer */
178
- esi_parser_echobuffer_clear( parser );
179
- }
180
-
181
- # block tag start, with attributes
182
- action see_block_start_with_attributes {
183
- /* trim tag text */
184
- ltrim_pointer( &(parser->tag_text), p, &(parser->tag_text_length) );
185
- rtrim_pointer( &(parser->tag_text), p, &(parser->tag_text_length) );
186
-
187
- /* send the start and end tag message */
188
- esi_parser_flush_output( parser );
189
- parser->start_tag_handler( data, parser->tag_text, parser->tag_text_length, parser->attributes, parser->user_data );
190
- esi_parser_flush_output( parser );
191
-
192
- parser->tag_text = NULL;
193
- parser->tag_text_length = 0;
194
- parser->mark = p;
195
-
196
- /* clear out the echo buffer */
197
- esi_parser_echobuffer_clear( parser );
198
- }
199
-
200
- # see an attribute key, /foo\s*=/
201
- action see_attribute_key {
202
- /* save the attribute key start */
203
- parser->attr_key = parser->mark;
204
- /* compute the length of the key */
205
- parser->attr_key_length = p - parser->mark;
206
- /* save the position following the key */
207
- parser->mark = p;
208
-
209
- /* trim the attribute key */
210
- ltrim_pointer( &(parser->attr_key), p, &(parser->attr_key_length) );
211
- rtrim_pointer( &(parser->attr_key), p, &(parser->attr_key_length) );
212
- }
213
-
214
- # see an attribute value, aprox ~= /['"].*['"]/
215
- action see_attribute_value {
216
- ESIAttribute *attr;
217
-
218
- /* save the attribute value start */
219
- parser->attr_value = parser->mark;
220
- /* compute the length of the value */
221
- parser->attr_value_length = p - parser->mark;
222
- /* svae the position following the value */
223
- parser->mark = p;
224
-
225
- /* trim the attribute value */
226
- ltrim_pointer( &(parser->attr_value), p, &(parser->attr_value_length) );
227
- rtrim_pointer( &(parser->attr_value), p, &(parser->attr_value_length) );
228
-
229
- /* using the attr_key and attr_value, allocate a new attribute object */
230
- attr = esi_attribute_new( parser->attr_key, parser->attr_key_length,
231
- parser->attr_value, parser->attr_value_length );
232
-
233
- /* add the new attribute to the list of attributes */
234
- if( parser->attributes ) {
235
- parser->last->next = attr;
236
- parser->last = attr;
237
- }
238
- else {
239
- parser->last = parser->attributes = attr;
240
- }
241
- }
242
-
243
- # simple block start tag detected, e.g. <esi:try> no attributes
244
- action block_start_tag {
245
-
246
- parser->tag_text = parser->mark;
247
- parser->tag_text_length = p - parser->mark;
248
-
249
- parser->mark = p;
250
-
251
- ltrim_pointer( &(parser->tag_text), p, &(parser->tag_text_length) );
252
- rtrim_pointer( &(parser->tag_text), p, &(parser->tag_text_length) );
253
-
254
- esi_parser_flush_output( parser );
255
- parser->start_tag_handler( data, parser->tag_text, parser->tag_text_length, NULL, parser->user_data );
256
- esi_parser_flush_output( parser );
257
-
258
- esi_parser_echobuffer_clear( parser );
259
- }
260
-
261
- # block end tag detected, e.g. </esi:try>
262
- action block_end_tag {
263
- /* offset by 2 to account for the </ characters */
264
- parser->tag_text = parser->mark+2;
265
- parser->tag_text_length = p - (parser->mark+2);
266
-
267
- parser->mark = p;
268
-
269
- ltrim_pointer( &(parser->tag_text), p, &(parser->tag_text_length) );
270
- rtrim_pointer( &(parser->tag_text), p, &(parser->tag_text_length) );
271
-
272
- esi_parser_flush_output( parser );
273
- parser->end_tag_handler( data, parser->tag_text, parser->tag_text_length, parser->user_data );
274
- esi_parser_flush_output( parser );
275
-
276
- esi_parser_echobuffer_clear( parser );
277
- }
278
-
279
- # process each character in the input stream for output
280
- action echo {
281
- //printf( "[%c:%d],", *p, cs );
282
- switch( cs ) {
283
- case 0: /* non matching state */
284
- if( parser->prev_state != 12 && parser->prev_state != 7 ){ /* states following a possible end state for a tag */
285
- if( parser->echobuffer && parser->echobuffer_index != -1 ){
286
- /* send the echo buffer */
287
- esi_parser_echo_buffer( parser );
288
- }
289
- /* send the current character */
290
- esi_parser_echo_char( parser, *p );
291
- }
292
- /* clear the echo buffer */
293
- esi_parser_echobuffer_clear( parser );
294
- break;
295
- default:
296
- /* append to the echo buffer */
297
- esi_parser_concat_to_echobuffer( parser, *p );
298
- }
299
- /* save the previous state, necessary for end case detection such as /> and </esi:try> the trailing > character
300
- is state 12 and 7
301
- */
302
- parser->prev_state = cs;
303
- }
304
-
305
- include esi_common_parser "common.rl";
306
- }%%
307
-
308
- %%write data;
309
-
310
- /* dup the string up to len */
311
- char *esi_strndup( const char *str, size_t len )
312
- {
313
- char *s = (char*)malloc(sizeof(char)*(len+1));
314
- memcpy( s, str, len );
315
- s[len] = '\0';
316
- return s;
317
- }
318
-
319
- ESIAttribute *esi_attribute_new( const char *name, size_t name_length, const char *value, size_t value_length )
320
- {
321
- ESIAttribute *attr = (ESIAttribute*)malloc(sizeof(ESIAttribute));
322
- attr->name = esi_strndup(name, name_length);
323
- attr->value = esi_strndup(value, value_length);
324
- attr->next = NULL;
325
- return attr;
326
- }
327
-
328
- ESIAttribute *esi_attribute_copy( ESIAttribute *attribute )
329
- {
330
- ESIAttribute *head, *nattr;
331
- if( !attribute ){ return NULL; }
332
-
333
- // copy the first attribute
334
- nattr = esi_attribute_new( attribute->name, strlen( attribute->name ),
335
- attribute->value, strlen( attribute->value ) );
336
- // save a pointer for return
337
- head = nattr;
338
- // copy next attributes
339
- attribute = attribute->next;
340
- while( attribute ) {
341
- // set the next attribute
342
- nattr->next = esi_attribute_new( attribute->name, strlen( attribute->name ),
343
- attribute->value, strlen( attribute->value ) );
344
- // next attribute
345
- nattr = nattr->next;
346
- attribute = attribute->next;
347
- }
348
- return head;
349
- }
350
-
351
- void esi_attribute_free( ESIAttribute *attribute )
352
- {
353
- ESIAttribute *ptr;
354
- while( attribute ){
355
- free( attribute->name );
356
- free( attribute->value );
357
- ptr = attribute->next;
358
- free( attribute );
359
- attribute = ptr;
360
- }
361
- }
362
-
363
- ESIParser *esi_parser_new()
364
- {
365
- ESIParser *parser = (ESIParser*)malloc(sizeof(ESIParser));
366
- parser->cs = esi_start;
367
- parser->mark = NULL;
368
- parser->tag_text = NULL;
369
- parser->attr_key = NULL;
370
- parser->attr_value = NULL;
371
- parser->overflow_data_size = 0;
372
- parser->overflow_data = NULL;
373
-
374
- /* allocate ESI_OUTPUT_BUFFER_SIZE bytes for the echobuffer */
375
- parser->echobuffer_allocated = ESI_OUTPUT_BUFFER_SIZE;
376
- parser->echobuffer_index = -1;
377
- parser->echobuffer = (char*)malloc(sizeof(char)*parser->echobuffer_allocated);
378
-
379
- parser->attributes = NULL;
380
- parser->last = NULL;
381
-
382
- parser->start_tag_handler = esi_parser_default_start_cb;
383
- parser->end_tag_handler = esi_parser_default_end_cb;
384
- parser->output_handler = esi_parser_default_output_cp;
385
-
386
- parser->output_buffer_size = 0;
387
- memset( parser->output_buffer, 0, ESI_OUTPUT_BUFFER_SIZE );
388
-
389
- return parser;
390
- }
391
- void esi_parser_free( ESIParser *parser )
392
- {
393
- if( parser->overflow_data ){ free( parser->overflow_data ); }
394
-
395
- free( parser->echobuffer );
396
- esi_attribute_free( parser->attributes );
397
-
398
- free( parser );
399
- }
400
-
401
- void esi_parser_output_handler( ESIParser *parser, output_cb output_handler )
402
- {
403
- parser->output_handler = output_handler;
404
- }
405
-
406
- int esi_parser_init( ESIParser *parser )
407
- {
408
- int cs;
409
- %% write init;
410
- parser->prev_state = parser->cs = cs;
411
- return 0;
412
- }
413
-
414
- static int compute_offset( const char *mark, const char *data )
415
- {
416
- if( mark ) {
417
- return mark - data;
418
- }
419
- return -1;
420
- }
421
-
422
- /*
423
- * scans the data buffer for a start sequence /<$/, /<e$/, /<es$/, /<esi$/, /<esi:$/
424
- * returns index of if start sequence found else returns -1
425
- */
426
- static int
427
- esi_parser_scan_for_start( ESIParser *parser, const char *data, size_t length )
428
- {
429
- size_t i, f = -2, s = -2;
430
- char ch;
431
-
432
- for( i = 0; i < length; ++i ) {
433
- ch = data[i];
434
- switch( ch ) {
435
- case '<':
436
- f = s = i;
437
- break;
438
- case '/':
439
- if( s == (i-1) && f != -2 ) { s = i; }
440
- break;
441
- case 'e':
442
- if( s == (i-1) && f != -2 ) { s = i; }
443
- break;
444
- case 's':
445
- if( s == (i-1) && f != -2 ) { s = i; }
446
- break;
447
- case 'i':
448
- if( s == (i-1) && f != -2 ) { s = i; }
449
- break;
450
- case ':':
451
- if( s == (i-1) && f != -2 ) { s = i; return f; }
452
- break;
453
- default:
454
- f = s = -2;
455
- break;
456
- }
457
- }
458
-
459
- // if s and f are still valid at end of input return f
460
- if( f != -2 && s != -2 ) {
461
- return f;
462
- }
463
- else {
464
- return -1;
465
- }
466
- }
467
-
468
- /* accept an arbitrary length string buffer
469
- * when this methods exits it determines if an end state was reached
470
- * if no end state was reached it saves the full input into an internal buffer
471
- * when invoked next, it reuses that internable buffer copying all pointers into the
472
- * newly allocated buffer. if it exits in a terminal state, e.g. 0 then it will dump these buffers
473
- */
474
- int esi_parser_execute( ESIParser *parser, const char *data, size_t length )
475
- {
476
- int cs = parser->cs;
477
- const char *p = data;
478
- const char *eof = NULL; // ragel 6.x compat
479
- const char *pe = data + length;
480
- int pindex;
481
-
482
- if( length == 0 ){ return cs; }
483
-
484
- /* scan data for any '<esi:' start sequences, /<$/, /<e$/, /<es$/, /<esi$/, /<esi:$/ */
485
- if( cs == esi_start ) {
486
- pindex = esi_parser_scan_for_start( parser, data, length );
487
- if( pindex == -1 ) {
488
- for( pindex = 0; pindex < length; ++pindex ) {
489
- esi_parser_echo_char( parser, data[pindex] );
490
- }
491
- return cs;
492
- }
493
- }
494
-
495
- /* there's an existing overflow buffer data append the new data to the existing data */
496
- if( parser->overflow_data && parser->overflow_data_size > 0 ) {
497
-
498
- // recompute mark, tag_text, attr_key, and attr_value since they all exist within overflow_data
499
- int mark_offset = compute_offset( parser->mark, parser->overflow_data );
500
- int tag_text_offset = compute_offset( parser->tag_text, parser->overflow_data );
501
- int attr_key_offset = compute_offset( parser->attr_key, parser->overflow_data );
502
- int attr_value_offset = compute_offset( parser->attr_value, parser->overflow_data );
503
-
504
- parser->overflow_data = (char*)realloc( parser->overflow_data, sizeof(char)*(parser->overflow_data_size+length) );
505
- memcpy( parser->overflow_data+parser->overflow_data_size, data, length );
506
-
507
- p = parser->overflow_data + parser->overflow_data_size;
508
-
509
- // in our new memory space mark will now be
510
- parser->mark = ( mark_offset >= 0 ) ? parser->overflow_data + mark_offset : NULL;
511
- parser->tag_text = ( tag_text_offset >= 0 ) ? parser->overflow_data + tag_text_offset : NULL;
512
- parser->attr_key = ( attr_key_offset >= 0 ) ? parser->overflow_data + attr_key_offset : NULL;
513
- parser->attr_value = ( attr_value_offset >= 0 ) ? parser->overflow_data + attr_value_offset : NULL;
514
-
515
- data = parser->overflow_data;
516
- parser->overflow_data_size = length = length + parser->overflow_data_size;
517
- // printf( "grow overflow data: %ld\n", parser->overflow_data_size );
518
- pe = data + length;
519
-
520
- }
521
-
522
- if( !parser->mark ) {
523
- parser->mark = p;
524
- }
525
-
526
- // printf( "cs: %d, ", cs );
527
-
528
- %% write exec;
529
-
530
- parser->cs = cs;
531
-
532
- if( cs != esi_start && cs != 0 ) {
533
-
534
- /* reached the end and we're not at a termination point save the buffer as overflow */
535
- if( !parser->overflow_data ){
536
- // recompute mark, tag_text, attr_key, and attr_value since they all exist within overflow_data
537
- int mark_offset = compute_offset( parser->mark, data );
538
- int tag_text_offset = compute_offset( parser->tag_text, data );
539
- int attr_key_offset = compute_offset( parser->attr_key, data );
540
- int attr_value_offset = compute_offset( parser->attr_value, data );
541
- //debug_string( "mark before move", parser->mark, 1 );
542
-
543
- if( ESI_OUTPUT_BUFFER_SIZE > length ) {
544
- parser->echobuffer_allocated = ESI_OUTPUT_BUFFER_SIZE;
545
- }
546
- else {
547
- parser->echobuffer_allocated = length;
548
- }
549
- parser->overflow_data = (char*)malloc( sizeof( char ) * parser->echobuffer_allocated );
550
- memcpy( parser->overflow_data, data, length );
551
- parser->overflow_data_size = length;
552
- //printf( "allocate overflow data: %ld\n", parser->echobuffer_allocated );
553
-
554
- // in our new memory space mark will now be
555
- parser->mark = ( mark_offset >= 0 ) ? parser->overflow_data + mark_offset : NULL;
556
- parser->tag_text = ( tag_text_offset >= 0 ) ? parser->overflow_data + tag_text_offset : NULL;
557
- parser->attr_key = ( attr_key_offset >= 0 ) ? parser->overflow_data + attr_key_offset : NULL;
558
- parser->attr_value = ( attr_value_offset >= 0 ) ? parser->overflow_data + attr_value_offset : NULL;
559
- //if( parser->mark ){ debug_string( "mark after move", parser->mark, 1 ); } else { printf( "mark is now empty\n" ); }
560
- }
561
-
562
- }else if( parser->overflow_data ) {
563
- /* dump the overflow buffer execution ended at a final state */
564
- free( parser->overflow_data );
565
- parser->overflow_data = NULL;
566
- parser->overflow_data_size = 0;
567
- }
568
-
569
- return cs;
570
- }
571
- int esi_parser_finish( ESIParser *parser )
572
- {
573
- esi_parser_flush_output( parser );
574
- return 0;
575
- }
576
-
577
- void esi_parser_start_tag_handler( ESIParser *parser, start_tag_cb callback )
578
- {
579
- parser->start_tag_handler = callback;
580
- }
581
-
582
- void esi_parser_end_tag_handler( ESIParser *parser, end_tag_cb callback )
583
- {
584
- parser->end_tag_handler = callback;
585
- }