Permalink
Browse files

fixed bugs in process_more_field_data and output_more_field_data.

  • Loading branch information...
1 parent d3156eb commit 9a0fa5eb4fb210148e8c895325b3cdf52bae0ff7 @agentzh agentzh committed Jan 24, 2010
Showing with 75 additions and 25 deletions.
  1. +31 −7 src/ngx_http_rds_json_output.c
  2. +7 −5 src/ngx_http_rds_json_processor.c
  3. +0 −1 src/ngx_http_rds_json_util.c
  4. +35 −10 test/t/openresty.t
  5. +2 −2 util/build.sh
@@ -4,7 +4,7 @@
*/
-#define DDEBUG 0
+#define DDEBUG 1
#include "ddebug.h"
#include "ngx_http_rds_json_filter_module.h"
@@ -398,8 +398,11 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r,
b->last = (u_char *) ngx_http_rds_json_escape_json_str(b->last,
data, len);
- dd("escaped value \"%*.s\" (len %d)", len + val_escape,
- p, (int) len + val_escape);
+ dd("escaped value \"%.*s\" (len %d, escape %d, escape2 %d)",
+ len + val_escape,
+ p, (int) len + val_escape,
+ (int) val_escape,
+ (int) (b->last - p) - len);
}
if (ctx->field_data_rest == 0) {
@@ -413,7 +416,7 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r,
if (ctx->field_data_rest == 0
&& ctx->cur_col == ctx->col_count - 1)
{
- /* last column in the row */
+ dd("last column in the row");
*b->last++ = '}';
}
@@ -474,13 +477,19 @@ ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r,
size += len;
break;
+ case rds_rough_col_type_bool:
+ break;
+
default:
/* string */
escape = ngx_http_rds_json_escape_json_str(NULL, data, len);
size = len + escape;
+
if (ctx->field_data_rest == 0) {
size += sizeof("\"") - 1;
}
+
+ break;
}
if (ctx->field_data_rest == 0
@@ -515,16 +524,30 @@ ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r,
/* string */
if (escape == 0) {
b->last = ngx_copy(b->last, data, len);
+
} else {
- dd("col name: string value escape non-zero: %d", (int) escape);
+ dd("more field data: string value escape non-zero: %d", (int) escape);
+
+#if DDEBUG
+ p = b->last;
+#endif
b->last = (u_char *) ngx_http_rds_json_escape_json_str(b->last,
data, len);
+
+ dd("escaped value \"%.*s\" (len %d, escape %d, escape2 %d)",
+ len + escape,
+ p, (int) len + escape,
+ (int) escape,
+ (int) (b->last - p) - len);
+
}
if (ctx->field_data_rest == 0) {
*b->last++ = '"';
}
+
+ break;
} /* switch */
if (ctx->field_data_rest == 0 &&
@@ -534,9 +557,10 @@ ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r,
*b->last++ = '}';
}
- if (b->pos != b->last) {
+ if (b->last != b->end) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "rds_json: output more field data: buffer error");
+ "rds_json: output more field data: buffer error "
+ "(%d left)", (int) (b->end - b->last));
return NGX_ERROR;
}
@@ -331,31 +331,33 @@ ngx_http_rds_json_process_more_field_data(ngx_http_request_t *r,
return rc;
}
+ b->pos += len;
+
if (b->pos == b->last) {
if (b->temporary) {
ngx_pfree(r->pool, b->start);
}
in = in->next;
}
- if (len < ctx->field_data_rest) {
- /* still some data remaining */
+ if (ctx->field_data_rest) {
+ dd("process more field data: still some data remaining");
continue;
}
- /* reached the end of the current field */
+ dd("process more field data: reached the end of the current field");
ctx->cur_col++;
if (ctx->cur_col >= ctx->col_count) {
- dd("reached the end of the current row");
+ dd("process more field data: reached the end of the current row");
ctx->state = state_expect_row;
return ngx_http_rds_json_process_row(r, in, ctx);
}
- /* read the next field */
+ dd("proces more field data: read the next field");
ctx->state = state_expect_field;
@@ -92,7 +92,6 @@ ngx_http_rds_json_escape_json_str(u_char *dst, u_char *src, size_t size)
*dst++ = '0';
*dst++ = hex[*src >> 4];
*dst++ = hex[*src & 0x0f];
- src++;
} else {
*dst++ = *src;
}
View
@@ -71,9 +71,8 @@ order by created asc";
"select comments.id as id, post, sender, title
from posts, comments
where post = posts.id
-order by comments.id dec
-offset $arg_offset
-limit $arg_limit";
+order by comments.id desc
+limit $arg_offset, $arg_limit";
drizzle_pass backend;
}
@@ -190,11 +189,11 @@ limit $arg_count";
drizzle_pass backend;
}
- location = '/=/batch/GetSideBar/~/~' {
+ location = '/=/batch/GetSidebar/~/~' {
if ($arg_year !~ '^(?:19|20)\d{2}$') {
rds_json_ret 400 'Bad "year" argument';
}
- if ($arg_month !~ '^\d{2}$') {
+ if ($arg_month !~ '^\d{1,2}$') {
rds_json_ret 400 'Bad "month" argument';
}
@@ -204,6 +203,8 @@ limit $arg_count";
echo ',';
echo_location_async '/=/view/RecentPosts/~/~' "offset=0&limit=6";
echo ',';
+ echo_location_async '/=/view/RecentComments/~/~' "offset=0&limit=6";
+ echo ',';
echo_location_async '/=/view/PostCountByMonths/~/~' "offset=0&limit=12";
echo ']';
}
@@ -215,11 +216,11 @@ limit $arg_count";
default_type 'application/json';
echo '[';
- echo_location "/=/model/Post/id/$arg_id";
+ echo_location_async "/=/model/Post/id/$arg_id";
echo ',';
- echo_location "/=/view/PrevNextPost/~/~" "current=$arg_id";
+ echo_location_async "/=/view/PrevNextPost/~/~" "current=$arg_id";
echo ',';
- echo_location "/=/model/Comment/post/$arg_id" "_order_by=id:desc";
+ echo_location_async "/=/model/Comment/post/$arg_id" "_order_by=id:desc";
echo ']';
}
@@ -337,13 +338,14 @@ foo([{"id":117,"title":"Major updates to ngx_chunkin: lots of bug fixes and begi
--- http_config eval: $::http_config
--- config eval: $::config
--- request
-GET /=/batch/GetSideBar/~/~?year=2009&month=10&_callback=foo
+GET /=/batch/GetSidebar/~/~?year=2009&month=10&_callback=foo
--- response_headers
Content-Type: application/x-javascript
--- response_body chop
foo([
[{"id":114,"title":"Hacking on the Nginx echo module","day":15}],
[{"id":119,"title":"Test::Nginx::LWP and Test::Nginx::Socket are now on CPAN"},{"id":118,"title":"ngx_memc: an extended version of ngx_memcached that supports set, add, delete, and many more commands"},{"id":117,"title":"Major updates to ngx_chunkin: lots of bug fixes and beginning of keep-alive support"},{"id":116,"title":"The \"headers more\" module: scripting input and output filters in your Nginx config file"},{"id":115,"title":"The \"chunkin\" module: Experimental chunked input support for Nginx"},{"id":114,"title":"Hacking on the Nginx echo module"}],
+[{"id":179,"post":101,"sender":"agentzh","title":"生活搜基于 Firefox 3.1 的 List Hunter 集群"},{"id":178,"post":101,"sender":"Winter","title":"生活搜基于 Firefox 3.1 的 List Hunter 集群"},{"id":177,"post":100,"sender":"Mountain","title":"漂在北京"},{"id":176,"post":106,"sender":"agentzh","title":"Text::SmartLinks: The Perl 6 love for Perl 5"},{"id":175,"post":106,"sender":"gosber","title":"Text::SmartLinks: The Perl 6 love for Perl 5"},{"id":174,"post":105,"sender":"cnangel","title":"SSH::Batch: Treating clusters as maths sets and intervals"}],
[{"year_month":"2009-12-01","count":3},{"year_month":"2009-11-01","count":2},{"year_month":"2009-10-01","count":1},{"year_month":"2009-09-01","count":5},{"year_month":"2009-05-01","count":2},{"year_month":"2009-04-01","count":3},{"year_month":"2009-02-01","count":2},{"year_month":"2008-12-01","count":3},{"year_month":"2008-11-01","count":2},{"year_month":"2008-10-01","count":2},{"year_month":"2008-09-01","count":4},{"year_month":"2008-08-01","count":2}]]
);
@@ -357,7 +359,8 @@ GET /=/batch/GetFullPost/~/~?id=116&_user=agentzh.Public&_callback=OpenResty.cal
--- response_headers
Content-Type: application/x-javascript
--- response_body chop
---- ONLY
+--- SKIP
+
=== TEST 8: RowCount
@@ -370,3 +373,25 @@ Content-Type: application/x-javascript
--- response_body chop
foo([{"count":118}]);
+
+
+=== TEST 9: GetFullPost bug
+--- http_config eval: $::http_config
+--- config eval: $::config
+--- request
+GET /=/model/Comment/post/67
+--- response_headers
+Content-Type: application/json
+--- response_body_like: laser
+--- error_code: 200
+
+=== TEST 10: more field data error
+--- http_config eval: $::http_config
+--- config eval: $::config
+--- request
+GET /=/model/Post/~/~?_limit=5&_order_by=id%3Adesc&_offset=100
+--- response_headers
+Content-Type: application/json
+--- response_body_like: 测试
+--- error_code: 200
+
View
@@ -15,8 +15,8 @@ if [[ "$BUILD_CLEAN" -eq 1 || ! -f Makefile || "$root/config" -nt Makefile || "$
--add-module=$home/git/echo-nginx-module \
--add-module=$home/git/xss-nginx-module \
--add-module=$root $opts \
- --add-module=$home/git/drizzle-nginx-module \
- --with-debug
+ --add-module=$home/git/drizzle-nginx-module #\
+ #--with-debug
#--with-cc-opt="-g3 -O0"
#--add-module=$root/../echo-nginx-module \
#--without-http_ssi_module # we cannot disable ssi because echo_location_async depends on it (i dunno why?!)

0 comments on commit 9a0fa5e

Please sign in to comment.