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
data/ext/esi/parser.h CHANGED
@@ -7,7 +7,8 @@
7
7
  #include <sys/types.h>
8
8
 
9
9
  /* how much output to hold in memory before sending out */
10
- #define ESI_OUTPUT_BUFFER_SIZE 1024
10
+ #define ESI_OUTPUT_BUFFER_SIZE 4096
11
+ #define ESI_ECHOBUFFER_SIZE 128
11
12
 
12
13
  char *esi_strndup( const char *str, size_t len );
13
14
 
@@ -28,8 +29,10 @@ char *esi_strndup( const char *str, size_t len );
28
29
  *
29
30
  * */
30
31
  typedef struct _ESIAttr {
31
- char *name;
32
- char *value;
32
+ const char *name;
33
+ const char *value;
34
+ size_t name_length;
35
+ size_t value_length;
33
36
  struct _ESIAttr *next;
34
37
  }ESIAttribute;
35
38
 
@@ -59,8 +62,10 @@ typedef struct _ESIParser {
59
62
  void *user_data;
60
63
 
61
64
  const char *mark;
62
- size_t overflow_data_size; /* current size of the overflow data buffer */
65
+ size_t overflow_data_size; /* amount of the overflow buffer being used */
66
+ size_t overflow_data_allocated; /* amount of memory allocated to use for the overflow buffer */
63
67
  char *overflow_data; /* overflow buffer if execute finishes and we are not in a final state store the parse data */
68
+ unsigned using_overflow:1; /* if this is 1, overflow data is in use. */
64
69
 
65
70
  size_t echobuffer_allocated; /* amount of memory allocated for the echobuffer */
66
71
  size_t echobuffer_index; /* current write position of the last echo'ed character */
data/ext/esi/parser.rl CHANGED
@@ -64,6 +64,21 @@ static void esi_parser_echo_char( ESIParser *parser, char ch )
64
64
  esi_parser_flush_output( parser );
65
65
  }
66
66
  }
67
+ static void esi_parser_send_buffer( ESIParser *parser, const char *seq, size_t len )
68
+ {
69
+ const char *nseq = seq + len;
70
+ size_t nlen = parser->output_buffer_size + len;
71
+
72
+ if( nlen < ESI_OUTPUT_BUFFER_SIZE ) {
73
+ memcpy( parser->output_buffer + parser->output_buffer_size, seq, len );
74
+ parser->output_buffer_size += len;
75
+ }
76
+ else if( nlen > ESI_OUTPUT_BUFFER_SIZE ) {
77
+ while( seq != nseq ) {
78
+ esi_parser_echo_char( parser, *seq++ );
79
+ }
80
+ }
81
+ }
67
82
  /* send any buffered characters to the output handler.
68
83
  * This happens when we enter a case such as <em> where the
69
84
  * first two characters < and e match the <esi: expression
@@ -99,6 +114,7 @@ static void esi_parser_concat_to_echobuffer( ESIParser *parser, char ch )
99
114
  /* double the echobuffer size
100
115
  * we're getting some crazy input if this case ever happens
101
116
  */
117
+ printf( "increase echobuffer: %d, %s\n", parser->echobuffer_allocated, parser->echobuffer );
102
118
  parser->echobuffer_allocated *= 2;
103
119
  parser->echobuffer = (char*)realloc( parser->echobuffer, parser->echobuffer_allocated );
104
120
  }
@@ -165,9 +181,8 @@ static void rtrim_pointer( const char **ptr, const char *bounds, size_t *len )
165
181
  /* send the start tag and end tag message */
166
182
  esi_parser_flush_output( parser );
167
183
  parser->start_tag_handler( data, parser->tag_text, parser->tag_text_length, parser->attributes, parser->user_data );
168
- esi_parser_flush_output( parser );
169
184
  parser->end_tag_handler( data, parser->tag_text, parser->tag_text_length, parser->user_data );
170
- esi_parser_flush_output( parser );
185
+ //printf("\t[see inline tag]\n");
171
186
 
172
187
  /* mark the position */
173
188
  parser->tag_text = NULL;
@@ -187,7 +202,7 @@ static void rtrim_pointer( const char **ptr, const char *bounds, size_t *len )
187
202
  /* send the start and end tag message */
188
203
  esi_parser_flush_output( parser );
189
204
  parser->start_tag_handler( data, parser->tag_text, parser->tag_text_length, parser->attributes, parser->user_data );
190
- esi_parser_flush_output( parser );
205
+ //printf("\t[see start tag with attributes]\n");
191
206
 
192
207
  parser->tag_text = NULL;
193
208
  parser->tag_text_length = 0;
@@ -253,7 +268,7 @@ static void rtrim_pointer( const char **ptr, const char *bounds, size_t *len )
253
268
 
254
269
  esi_parser_flush_output( parser );
255
270
  parser->start_tag_handler( data, parser->tag_text, parser->tag_text_length, NULL, parser->user_data );
256
- esi_parser_flush_output( parser );
271
+ //printf("\t[see start tag]\n");
257
272
 
258
273
  esi_parser_echobuffer_clear( parser );
259
274
  }
@@ -271,7 +286,7 @@ static void rtrim_pointer( const char **ptr, const char *bounds, size_t *len )
271
286
 
272
287
  esi_parser_flush_output( parser );
273
288
  parser->end_tag_handler( data, parser->tag_text, parser->tag_text_length, parser->user_data );
274
- esi_parser_flush_output( parser );
289
+ //printf("\t[see end tag]\n");
275
290
 
276
291
  esi_parser_echobuffer_clear( parser );
277
292
  }
@@ -319,8 +334,10 @@ char *esi_strndup( const char *str, size_t len )
319
334
  ESIAttribute *esi_attribute_new( const char *name, size_t name_length, const char *value, size_t value_length )
320
335
  {
321
336
  ESIAttribute *attr = (ESIAttribute*)malloc(sizeof(ESIAttribute));
322
- attr->name = esi_strndup(name, name_length);
323
- attr->value = esi_strndup(value, value_length);
337
+ attr->name = name;//esi_strndup(name, name_length);
338
+ attr->value = value;//esi_strndup(value, value_length);
339
+ attr->name_length = name_length;
340
+ attr->value_length = value_length;
324
341
  attr->next = NULL;
325
342
  return attr;
326
343
  }
@@ -331,16 +348,16 @@ ESIAttribute *esi_attribute_copy( ESIAttribute *attribute )
331
348
  if( !attribute ){ return NULL; }
332
349
 
333
350
  // copy the first attribute
334
- nattr = esi_attribute_new( attribute->name, strlen( attribute->name ),
335
- attribute->value, strlen( attribute->value ) );
351
+ nattr = esi_attribute_new( attribute->name, attribute->name_length,
352
+ attribute->value, attribute->value_length );
336
353
  // save a pointer for return
337
354
  head = nattr;
338
355
  // copy next attributes
339
356
  attribute = attribute->next;
340
357
  while( attribute ) {
341
358
  // set the next attribute
342
- nattr->next = esi_attribute_new( attribute->name, strlen( attribute->name ),
343
- attribute->value, strlen( attribute->value ) );
359
+ nattr->next = esi_attribute_new( attribute->name, attribute->name_length,
360
+ attribute->value, attribute->value_length );
344
361
  // next attribute
345
362
  nattr = nattr->next;
346
363
  attribute = attribute->next;
@@ -352,8 +369,8 @@ void esi_attribute_free( ESIAttribute *attribute )
352
369
  {
353
370
  ESIAttribute *ptr;
354
371
  while( attribute ){
355
- free( attribute->name );
356
- free( attribute->value );
372
+ // free( attribute->name );
373
+ // free( attribute->value );
357
374
  ptr = attribute->next;
358
375
  free( attribute );
359
376
  attribute = ptr;
@@ -370,9 +387,11 @@ ESIParser *esi_parser_new()
370
387
  parser->attr_value = NULL;
371
388
  parser->overflow_data_size = 0;
372
389
  parser->overflow_data = NULL;
390
+ parser->overflow_data_allocated = 0;
391
+ parser->using_overflow = 0;
373
392
 
374
393
  /* allocate ESI_OUTPUT_BUFFER_SIZE bytes for the echobuffer */
375
- parser->echobuffer_allocated = ESI_OUTPUT_BUFFER_SIZE;
394
+ parser->echobuffer_allocated = ESI_ECHOBUFFER_SIZE;
376
395
  parser->echobuffer_index = -1;
377
396
  parser->echobuffer = (char*)malloc(sizeof(char)*parser->echobuffer_allocated);
378
397
 
@@ -393,6 +412,7 @@ void esi_parser_free( ESIParser *parser )
393
412
  if( parser->overflow_data ){ free( parser->overflow_data ); }
394
413
 
395
414
  free( parser->echobuffer );
415
+
396
416
  esi_attribute_free( parser->attributes );
397
417
 
398
418
  free( parser );
@@ -465,6 +485,54 @@ esi_parser_scan_for_start( ESIParser *parser, const char *data, size_t length )
465
485
  }
466
486
  }
467
487
 
488
+ static void
489
+ esi_parser_append_data_to_overflow_data( ESIParser *parser, const char *data, size_t length )
490
+ {
491
+ int mark_offset = 0;
492
+ int tag_text_offset = 0;
493
+ int attr_key_offset = 0;
494
+ int attr_value_offset = 0;
495
+
496
+ if( parser->using_overflow ) {
497
+ // recompute mark, tag_text, attr_key, and attr_value as they all exist within overflow_data
498
+ mark_offset = compute_offset( parser->mark, parser->overflow_data );
499
+ tag_text_offset = compute_offset( parser->tag_text, parser->overflow_data );
500
+ attr_key_offset = compute_offset( parser->attr_key, parser->overflow_data );
501
+ attr_value_offset = compute_offset( parser->attr_value, parser->overflow_data );
502
+ }
503
+ else {
504
+ // recompute mark, tag_text, attr_key, and attr_value as they all exist within data
505
+ mark_offset = compute_offset( parser->mark, data );
506
+ tag_text_offset = compute_offset( parser->tag_text, data );
507
+ attr_key_offset = compute_offset( parser->attr_key, data );
508
+ attr_value_offset = compute_offset( parser->attr_value, data );
509
+ }
510
+
511
+ if( parser->overflow_data ) {
512
+ // check if we need to resize or grow the buffer
513
+ if( (parser->overflow_data_size + length) > parser->overflow_data_allocated ) {
514
+ parser->overflow_data_allocated += length;
515
+ // printf( "realloc: %d bytes, using %d\n", (int)parser->overflow_data_allocated, (int)(parser->overflow_data_size+length) );
516
+ parser->overflow_data = (char*)realloc( parser->overflow_data, sizeof(char)*(parser->overflow_data_allocated) );
517
+ }
518
+ memcpy( parser->overflow_data+parser->overflow_data_size, data, length );
519
+ parser->overflow_data_size += length;
520
+ }
521
+ else {
522
+ parser->overflow_data_allocated = ESI_OUTPUT_BUFFER_SIZE > length ? ESI_OUTPUT_BUFFER_SIZE : length;
523
+ parser->overflow_data = (char*)malloc( sizeof( char ) * parser->overflow_data_allocated );
524
+ memcpy( parser->overflow_data, data, length );
525
+ parser->overflow_data_size = length;
526
+ // printf( "malloc: %d for %d bytes\n", (int)parser->overflow_data_allocated, (int)length );
527
+ }
528
+
529
+ // in our new memory space mark will now be
530
+ parser->mark = ( mark_offset >= 0 ) ? parser->overflow_data + mark_offset : NULL;
531
+ parser->tag_text = ( tag_text_offset >= 0 ) ? parser->overflow_data + tag_text_offset : NULL;
532
+ parser->attr_key = ( attr_key_offset >= 0 ) ? parser->overflow_data + attr_key_offset : NULL;
533
+ parser->attr_value = ( attr_value_offset >= 0 ) ? parser->overflow_data + attr_value_offset : NULL;
534
+ }
535
+
468
536
  /* accept an arbitrary length string buffer
469
537
  * when this methods exits it determines if an end state was reached
470
538
  * if no end state was reached it saves the full input into an internal buffer
@@ -482,49 +550,31 @@ int esi_parser_execute( ESIParser *parser, const char *data, size_t length )
482
550
  if( length == 0 ){ return cs; }
483
551
 
484
552
  /* scan data for any '<esi:' start sequences, /<$/, /<e$/, /<es$/, /<esi$/, /<esi:$/ */
485
- if( cs == esi_start ) {
553
+ if( cs == esi_start || cs == 0 ) {
486
554
  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;
555
+ if( pindex == -1 ) { /* this means there are no start sequences in the buffer we recieved */
556
+ esi_parser_send_buffer( parser, data, length );
557
+ return cs; /* no esi start sequences send it all out and break out early */
492
558
  }
493
559
  }
494
560
 
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 );
561
+ /* there's an existing overflow buffer and it's being used, append the new data */
562
+ //if( parser->overflow_data && parser->overflow_data_size > 0 ) {
563
+ if( parser->using_overflow ) {
564
+ int prev_overflow_size = parser->overflow_data_size; // save the current overflow size
565
+ esi_parser_append_data_to_overflow_data( parser, data, length );
506
566
 
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
-
567
+ /* set parser variables */
568
+ p = parser->overflow_data + prev_overflow_size;
515
569
  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 );
570
+ length = parser->overflow_data_size;
518
571
  pe = data + length;
519
-
520
572
  }
521
573
 
522
574
  if( !parser->mark ) {
523
575
  parser->mark = p;
524
576
  }
525
577
 
526
- // printf( "cs: %d, ", cs );
527
-
528
578
  %% write exec;
529
579
 
530
580
  parser->cs = cs;
@@ -532,37 +582,13 @@ int esi_parser_execute( ESIParser *parser, const char *data, size_t length )
532
582
  if( cs != esi_start && cs != 0 ) {
533
583
 
534
584
  /* 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" ); }
585
+ if( !parser->using_overflow ) {
586
+ esi_parser_append_data_to_overflow_data( parser, data, length );
587
+ parser->using_overflow = 1;
560
588
  }
561
589
 
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;
590
+ } else if ( parser->using_overflow ) {
591
+ parser->using_overflow = 0;
566
592
  parser->overflow_data_size = 0;
567
593
  }
568
594
 
data/ext/esi/test/test.c CHANGED
@@ -38,11 +38,16 @@ TagInfo* tag_info_new( const char *name, size_t len, ESIAttribute *attributes )
38
38
  static
39
39
  void tag_info_show( TagInfo *ti )
40
40
  {
41
+ char buffer1[1024], buffer2[1024];
41
42
  ESIAttribute *attrs = ti->attributes;
42
43
  if( attrs ) {
43
44
  printf("%s{", ti->name );
44
45
  while( attrs ) {
45
- printf( "(%s=>%s),", attrs->name, attrs->value );
46
+ memcpy( buffer1, attrs->name, attrs->name_length );
47
+ buffer1[attrs->name_length] = '\0';
48
+ memcpy( buffer2, attrs->value, attrs->value_length );
49
+ buffer2[attrs->value_length] = '\0';
50
+ printf( "(%s=>%s),", buffer1, buffer2 );
46
51
  attrs = attrs->next;
47
52
  }
48
53
  printf("}\n");
@@ -198,7 +203,7 @@ static void feed_data( ESIParser *parser, const char *data )
198
203
  #define TEST_WITH_FILE(file)\
199
204
  int size = 0;\
200
205
  FILE *input = NULL;\
201
- char buffer[1024]; /* intentially using a small buffer size */\
206
+ char buffer[4096]; \
202
207
  TEST_INIT\
203
208
  \
204
209
  input = fopen( file, "r" );\
@@ -207,7 +212,7 @@ static void feed_data( ESIParser *parser, const char *data )
207
212
  return;\
208
213
  }\
209
214
  \
210
- while( (size = fread( buffer, sizeof(char), 1023, input )) > 0 ){\
215
+ while( (size = fread( buffer, sizeof(char), 4095, input )) > 0 ){\
211
216
  esi_parser_execute( parser, buffer, size );\
212
217
  }\
213
218
  \
@@ -281,13 +286,13 @@ static void test_small_buffer( ESIParser *parser )
281
286
  int i, len = strlen(input);
282
287
 
283
288
  TEST_INIT
289
+ // printf("\n");
284
290
 
285
291
  for( i = 0; i < len; i += input_size ) {
286
292
  if( i + input_size <= len ) {
287
293
  esi_parser_execute( parser, (input+i), input_size );
288
294
  }
289
295
  else {
290
- printf("using: %d\n", len - i );
291
296
  esi_parser_execute( parser, (input+i), len - i );
292
297
  }
293
298
  }
@@ -545,10 +550,10 @@ static void test_large_chunked_file( ESIParser *parser )
545
550
  buffer_end = buffer + size;
546
551
 
547
552
  for( chunk_start = buffer; chunk_start != buffer_end; ) {
548
- while( *chunk_start != '{' && chunk_start != buffer_end ) { ++chunk_start; }
553
+ while( chunk_start != buffer_end && *chunk_start != '{' ) { ++chunk_start; }
549
554
  if( chunk_start == buffer_end ){ break; }
550
555
  chunk_end = chunk_start;
551
- while( *chunk_end != '}' && chunk_end != buffer_end ) { ++chunk_end; }
556
+ while( chunk_end != buffer_end && *chunk_end != '}' ) { ++chunk_end; }
552
557
  ++chunk_start;
553
558
  if( chunk_start > buffer_end ){ break; }
554
559
 
data/lib/esi/cache.rb CHANGED
@@ -92,8 +92,12 @@ module ESI
92
92
  #
93
93
  class MemcachedCache < Cache
94
94
  require 'rubygems'
95
- gem 'memcache-client' if respond_to? :gem
96
- require 'memcache'
95
+ begin
96
+ require 'memcached'
97
+ rescue => e
98
+ puts "using memcache client"
99
+ require 'memcache'
100
+ end
97
101
  include ESI::Log
98
102
 
99
103
  def initialize( options )
@@ -175,7 +179,7 @@ module ESI
175
179
  def get( uri, params )
176
180
  key = cache_key(uri,params)
177
181
  fragment = @semaphore.synchronize { @cache[key] }
178
- fragment.dup if fragment and fragment.respond_to?(:dup)
182
+ fragment.dup if fragment and fragment.valid? and fragment.respond_to?(:dup)
179
183
  end
180
184
 
181
185
  def put( uri, params, max_age, body )
data/lib/esi/config.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # Copyright (c) 2008 Todd A. Fisher
2
2
  # see LICENSE
3
3
  require 'ostruct'
4
+ require 'esi/router'
4
5
 
5
6
  module ESI
6
7
  # This file provides configuration options to mongrel-esi
@@ -108,6 +109,8 @@ module ESI
108
109
  yield cache_options
109
110
  if cache_options.memcached?
110
111
  @config[:cache] = 'memcached'
112
+ else
113
+ @config[:cache] = 'ruby'
111
114
  end
112
115
  @config[:cache_options] = cache_options.options
113
116
  else
@@ -135,7 +138,7 @@ module ESI
135
138
  end
136
139
 
137
140
  def router
138
- Router.new( @config[:routing] )
141
+ ESI::Router.new( @config[:routing] )
139
142
  end
140
143
 
141
144
  class ConfigRouter
@@ -169,13 +172,6 @@ module ESI
169
172
  @config[:routing] = config_router.routes
170
173
  end
171
174
 
172
- # return true/false depending on the value of
173
- # invalidator: on/off
174
- # within in config/esi.yml
175
- def start_invalidator?
176
- @config[:invalidator]
177
- end
178
-
179
175
  def self.define( listeners )
180
176
  listeners.each do|host,server|
181
177
  esi_handlers = server.classifier.handler_map.select do|uri,handler|
@@ -1,22 +1,31 @@
1
+ require 'mongrel'
1
2
  require 'esi/proxy'
3
+ require 'esi/logger'
2
4
 
3
5
  module ESI
4
6
 
5
7
  class Dispatcher < Mongrel::HttpHandler
6
- attr_reader :config, :router
8
+ attr_reader :config
9
+ include ESI::Log
7
10
 
8
11
  Thread.abort_on_exception = false
9
12
 
10
13
  def initialize( options )
11
14
  super()
12
15
  @config = ESI::Config.new( options )
13
- if @config.start_invalidator?
14
- ESI::Invalidator.start( self )
15
- end
16
16
  end
17
17
 
18
18
  def process(request, response)
19
- ESI::Proxy.new(@config).process(request,response)
19
+ start = Time.now
20
+
21
+ url = @config.router.url_for(request.params["REQUEST_URI"])
22
+
23
+ chunk_count, bytes_sent, status, sent_from_cache = ESI::Proxy.new(@config).process(url, request,response)
24
+
25
+ rescue => e
26
+ log_error "\n#{e.message}: error at #{e.backtrace.first} msg at #{__FILE__}:#{__LINE__}\n"
27
+ ensure
28
+ log_request "\n#{url}, #{Time.now - start} seconds with status #{status} #{sent_from_cache ? "from cache" : ''} and #{chunk_count} chunks, #{bytes_sent} bytes\n"
20
29
  end
21
30
 
22
31
  end