[Groonga-commit] groonga/groonga at 24ca9b0 [master] Treat all HTTP requests under /d/ path is API request

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Apr 30 12:56:49 JST 2014


Kouhei Sutou	2014-04-30 12:56:49 +0900 (Wed, 30 Apr 2014)

  New Revision: 24ca9b035ef69f289ca6faa5220633529e636226
  https://github.com/groonga/groonga/commit/24ca9b035ef69f289ca6faa5220633529e636226

  Message:
    Treat all HTTP requests under /d/ path is API request
    
    Before:
    
    /d/nonexistent-command returns a file content at
    ${DOCUMENT_ROOT}/d/nonexistent-command.
    
    After:
    
    /d/nonexistent-command returns '[[-22, 0.0, 0.0], "invalid command
    name: nonexistent-command"]'.
    
    Both groonga --protocol http and groonga-httpd are changed.

  Modified files:
    lib/ctx.c

  Modified: lib/ctx.c (+9 -3)
===================================================================
--- lib/ctx.c    2014-04-29 13:37:04 +0900 (93ae008)
+++ lib/ctx.c    2014-04-30 12:56:49 +0900 (50cfad5)
@@ -1651,9 +1651,11 @@ grn_ctx_qe_exec_uri(grn_ctx *ctx, const char *path, uint32_t path_len)
   if (!GRN_TEXT_LEN(&buf)) { GRN_TEXT_SETS(ctx, &buf, INDEX_HTML); }
   v = GRN_TEXT_VALUE(&buf);
   grn_str_get_mime_type(ctx, v, GRN_BULK_CURR(&buf), &key_end, &filename_end);
-  if ((GRN_TEXT_LEN(&buf) >= 2 && v[0] == 'd' && v[1] == '/') &&
-      (expr = grn_ctx_get(ctx, v + 2, key_end - (v + 2))) &&
-      command_proc_p(expr)) {
+  if ((GRN_TEXT_LEN(&buf) >= 2 && v[0] == 'd' && v[1] == '/')) {
+    const char *command_name = v + 2;
+    int command_name_size = key_end - command_name;
+    expr = grn_ctx_get(ctx, command_name, command_name_size);
+    if (expr && command_proc_p(expr)) {
     while (p < e) {
       int l;
       GRN_BULK_REWIND(&buf);
@@ -1681,6 +1683,10 @@ grn_ctx_qe_exec_uri(grn_ctx *ctx, const char *path, uint32_t path_len)
     }
     ctx->impl->curr_expr = expr;
     grn_expr_exec(ctx, expr, 0);
+    } else {
+      ERR(GRN_INVALID_ARGUMENT, "invalid command name: %.*s",
+          command_name_size, command_name);
+    }
   } else if ((expr = grn_ctx_get(ctx, GRN_EXPR_MISSING_NAME,
                                  strlen(GRN_EXPR_MISSING_NAME)))) {
     if ((val = grn_expr_get_var_by_offset(ctx, expr, 0))) {
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index