[Groonga-commit] groonga/groonga [master] Move jsonp formatting code to lib from src

Back to archive index

null+****@clear***** null+****@clear*****
2012年 6月 19日 (火) 13:13:07 JST


Ryo Onodera	2012-06-19 13:13:07 +0900 (Tue, 19 Jun 2012)

  New Revision: 0d246664277cf243a080b535a042abeaf445f1e5
  https://github.com/groonga/groonga/commit/0d246664277cf243a080b535a042abeaf445f1e5

  Merged 310c858: Merge pull request #16 from ryoqun/jsonp

  Log:
    Move jsonp formatting code to lib from src

  Modified files:
    lib/output.c
    src/groonga.c

  Modified: lib/output.c (+17 -0)
===================================================================
--- lib/output.c    2012-06-19 13:07:31 +0900 (25089b7)
+++ lib/output.c    2012-06-19 13:13:07 +0900 (5f4ae65)
@@ -1298,6 +1298,8 @@ msgpack_buffer_writer(void* data, const char* buf, unsigned int len)
 }
 #endif
 
+#define JSON_CALLBACK_PARAM "callback"
+
 void
 grn_output_envelope(grn_ctx *ctx,
                     grn_rc rc,
@@ -1318,6 +1320,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:
     GRN_TEXT_PUTS(ctx, head, "[[");
@@ -1498,4 +1511,8 @@ grn_output_envelope(grn_ctx *ctx,
   case GRN_CONTENT_NONE:
     break;
   }
+
+  if (jsonp_func && GRN_TEXT_LEN(jsonp_func)) {
+    GRN_TEXT_PUTS(ctx, foot, ");");
+  }
 }

  Modified: src/groonga.c (+1 -16)
===================================================================
--- src/groonga.c    2012-06-19 13:07:31 +0900 (c33582e)
+++ src/groonga.c    2012-06-19 13:13:07 +0900 (379817a)
@@ -536,8 +536,6 @@ run_server(grn_ctx *ctx, grn_obj *db, grn_com_event *ev,
   return exit_code;
 }
 
-#define JSON_CALLBACK_PARAM "callback"
-
 typedef struct {
   grn_obj body;
   grn_msg *msg;
@@ -555,20 +553,7 @@ h_output(grn_ctx *ctx, int flags, void *arg)
   GRN_TEXT_INIT(&head, 0);
   GRN_TEXT_INIT(&foot, 0);
   if (!expr_rc) {
-    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, '(');
-      output_envelope(ctx, expr_rc, &head, outbuf, &foot);
-      GRN_TEXT_PUTS(ctx, &foot, ");");
-    } else {
-      output_envelope(ctx, expr_rc, &head, outbuf, &foot);
-    }
+    output_envelope(ctx, expr_rc, &head, outbuf, &foot);
     GRN_TEXT_SETS(ctx, body, "HTTP/1.1 200 OK\r\n");
     GRN_TEXT_PUTS(ctx, body, "Connection: close\r\n");
     GRN_TEXT_PUTS(ctx, body, "Content-Type: ");
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Descargar 



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