[Groonga-commit] groonga/groonga [master] Move JSONP formatting code under GRN_CONTENT_JSON

Back to archive index

null+****@clear***** null+****@clear*****
2012年 6月 19日 (火) 14:34:04 JST


Ryo Onodera	2012-06-19 14:34:04 +0900 (Tue, 19 Jun 2012)

  New Revision: 64b18e0131d56570ce26f4c1a99ec8927e04ef42
  https://github.com/groonga/groonga/commit/64b18e0131d56570ce26f4c1a99ec8927e04ef42

  Log:
    Move JSONP formatting code under GRN_CONTENT_JSON

  Modified files:
    lib/output.c

  Modified: lib/output.c (+14 -15)
===================================================================
--- lib/output.c    2012-06-19 13:57:32 +0900 (5f4ae65)
+++ lib/output.c    2012-06-19 14:34:04 +0900 (bd02267)
@@ -1311,6 +1311,8 @@ grn_output_envelope(grn_ctx *ctx,
 
 {
   double started, finished, elapsed;
+  grn_obj *expr = NULL;
+  grn_obj *jsonp_func = NULL;
 
   grn_timeval tv_now;
   grn_timeval_now(ctx, &tv_now);
@@ -1320,19 +1322,17 @@ grn_output_envelope(grn_ctx *ctx,
   finished += tv_now.tv_nsec / GRN_TIME_NSEC_PER_SEC_F;
   elapsed = finished - started;
 
-  grn_obj *expr = ctx->impl->curr_expr;
-  grn_obj *jsonp_func = NULL;
-  if (expr) {
-    jsonp_func = grn_expr_get_var(ctx, expr, JSON_CALLBACK_PARAM,
-                                  strlen(JSON_CALLBACK_PARAM));
-  }
-  if (jsonp_func && GRN_TEXT_LEN(jsonp_func)) {
-    GRN_TEXT_PUT(ctx, head, GRN_TEXT_VALUE(jsonp_func), GRN_TEXT_LEN(jsonp_func));
-    GRN_TEXT_PUTC(ctx, head, '(');
-  }
-
   switch (ctx->impl->output_type) {
   case GRN_CONTENT_JSON:
+    expr = ctx->impl->curr_expr;
+    if (expr) {
+      jsonp_func = grn_expr_get_var(ctx, expr, JSON_CALLBACK_PARAM,
+                                    strlen(JSON_CALLBACK_PARAM));
+    }
+    if (jsonp_func && GRN_TEXT_LEN(jsonp_func)) {
+      GRN_TEXT_PUT(ctx, head, GRN_TEXT_VALUE(jsonp_func), GRN_TEXT_LEN(jsonp_func));
+      GRN_TEXT_PUTC(ctx, head, '(');
+    }
     GRN_TEXT_PUTS(ctx, head, "[[");
     grn_text_itoa(ctx, head, rc);
     GRN_TEXT_PUTC(ctx, head, ',');
@@ -1365,6 +1365,9 @@ grn_output_envelope(grn_ctx *ctx,
     GRN_TEXT_PUTC(ctx, head, ']');
     if (GRN_TEXT_LEN(body)) { GRN_TEXT_PUTC(ctx, head, ','); }
     GRN_TEXT_PUTC(ctx, foot, ']');
+    if (jsonp_func && GRN_TEXT_LEN(jsonp_func)) {
+      GRN_TEXT_PUTS(ctx, foot, ");");
+    }
     break;
   case GRN_CONTENT_TSV:
     grn_text_itoa(ctx, head, rc);
@@ -1511,8 +1514,4 @@ grn_output_envelope(grn_ctx *ctx,
   case GRN_CONTENT_NONE:
     break;
   }
-
-  if (jsonp_func && GRN_TEXT_LEN(jsonp_func)) {
-    GRN_TEXT_PUTS(ctx, foot, ");");
-  }
 }
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Download 



Groonga-commit メーリングリストの案内
Back to archive index