[Groonga-commit] groonga/groonga at f0b0f86 [master] Add conf_get, conf_set and conf_delete

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jan 13 16:46:14 JST 2016


Kouhei Sutou	2016-01-13 16:46:14 +0900 (Wed, 13 Jan 2016)

  New Revision: f0b0f861c690cbfd0df218377fc22115cc9f121d
  https://github.com/groonga/groonga/commit/f0b0f861c690cbfd0df218377fc22115cc9f121d

  Message:
    Add conf_get, conf_set and conf_delete

  Added files:
    lib/proc/proc_conf.c
    test/command/suite/conf_delete/existent.expected
    test/command/suite/conf_delete/existent.test
    test/command/suite/conf_delete/no_key.expected
    test/command/suite/conf_delete/no_key.test
    test/command/suite/conf_delete/nonexistent.expected
    test/command/suite/conf_delete/nonexistent.test
    test/command/suite/conf_get/existent.expected
    test/command/suite/conf_get/existent.test
    test/command/suite/conf_get/no_key.expected
    test/command/suite/conf_get/no_key.test
    test/command/suite/conf_get/nonexistent.expected
    test/command/suite/conf_get/nonexistent.test
    test/command/suite/conf_set/no_key.expected
    test/command/suite/conf_set/no_key.test
    test/command/suite/conf_set/no_value.expected
    test/command/suite/conf_set/no_value.test
    test/command/suite/conf_set/value.expected
    test/command/suite/conf_set/value.test
  Modified files:
    lib/grn_proc.h
    lib/proc.c
    lib/proc/sources.am

  Modified: lib/grn_proc.h (+3 -0)
===================================================================
--- lib/grn_proc.h    2016-01-13 16:27:21 +0900 (c3dfe33)
+++ lib/grn_proc.h    2016-01-13 16:46:14 +0900 (28a6208)
@@ -30,6 +30,9 @@ GRN_VAR const char *grn_document_root;
 void grn_db_init_builtin_query(grn_ctx *ctx);
 
 void grn_proc_init_schema(grn_ctx *ctx);
+void grn_proc_init_conf_get(grn_ctx *ctx);
+void grn_proc_init_conf_set(grn_ctx *ctx);
+void grn_proc_init_conf_delete(grn_ctx *ctx);
 
 #ifdef __cplusplus
 }

  Modified: lib/proc.c (+4 -0)
===================================================================
--- lib/proc.c    2016-01-13 16:27:21 +0900 (816e8d9)
+++ lib/proc.c    2016-01-13 16:46:14 +0900 (d3fe09a)
@@ -7523,4 +7523,8 @@ grn_db_init_builtin_query(grn_ctx *ctx)
                                     NULL, NULL, NULL, 0, NULL);
     grn_proc_set_selector(ctx, selector_proc, selector_prefix_rk_search);
   }
+
+  grn_proc_init_conf_get(ctx);
+  grn_proc_init_conf_set(ctx);
+  grn_proc_init_conf_delete(ctx);
 }

  Added: lib/proc/proc_conf.c (+139 -0) 100644
===================================================================
--- /dev/null
+++ lib/proc/proc_conf.c    2016-01-13 16:46:14 +0900 (c3dbf6c)
@@ -0,0 +1,139 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2016 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "grn_proc.h"
+
+#include <groonga/plugin.h>
+
+static grn_obj *
+command_conf_get(grn_ctx *ctx,
+                 int nargs,
+                 grn_obj **args,
+                 grn_user_data *user_data)
+{
+  grn_obj *key;
+  const char *value;
+  uint32_t value_size;
+
+  key = grn_plugin_proc_get_var(ctx, user_data, "key", -1);
+  if (GRN_TEXT_LEN(key) == 0) {
+    GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
+                     "[conf][get] key is missing");
+    return NULL;
+  }
+
+  grn_conf_get(ctx,
+               GRN_TEXT_VALUE(key), GRN_TEXT_LEN(key),
+               &value, &value_size);
+  if (ctx->rc) {
+    return NULL;
+  }
+
+  grn_ctx_output_str(ctx, value, value_size);
+
+  return NULL;
+}
+
+static grn_obj *
+command_conf_set(grn_ctx *ctx,
+                 int nargs,
+                 grn_obj **args,
+                 grn_user_data *user_data)
+{
+  grn_obj *key;
+  grn_obj *value;
+
+  key = grn_plugin_proc_get_var(ctx, user_data, "key", -1);
+  if (GRN_TEXT_LEN(key) == 0) {
+    GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
+                     "[conf][set] key is missing");
+    return NULL;
+  }
+
+  value = grn_plugin_proc_get_var(ctx, user_data, "value", -1);
+  grn_conf_set(ctx,
+               GRN_TEXT_VALUE(key), GRN_TEXT_LEN(key),
+               GRN_TEXT_VALUE(value), GRN_TEXT_LEN(value));
+
+  grn_ctx_output_bool(ctx, ctx->rc == GRN_SUCCESS);
+
+  return NULL;
+}
+
+static grn_obj *
+command_conf_delete(grn_ctx *ctx,
+                    int nargs,
+                    grn_obj **args,
+                    grn_user_data *user_data)
+{
+  grn_obj *key;
+
+  key = grn_plugin_proc_get_var(ctx, user_data, "key", -1);
+  if (GRN_TEXT_LEN(key) == 0) {
+    GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
+                     "[conf][delete] key is missing");
+    return NULL;
+  }
+
+  grn_conf_delete(ctx,
+                  GRN_TEXT_VALUE(key), GRN_TEXT_LEN(key));
+
+  grn_ctx_output_bool(ctx, ctx->rc == GRN_SUCCESS);
+
+  return NULL;
+}
+
+void
+grn_proc_init_conf_get(grn_ctx *ctx)
+{
+  grn_expr_var vars[1];
+
+  grn_plugin_expr_var_init(ctx, &(vars[0]), "key", -1);
+  grn_plugin_command_create(ctx,
+                            "conf_get", -1,
+                            command_conf_get,
+                            1,
+                            vars);
+}
+
+void
+grn_proc_init_conf_set(grn_ctx *ctx)
+{
+  grn_expr_var vars[2];
+
+  grn_plugin_expr_var_init(ctx, &(vars[0]), "key", -1);
+  grn_plugin_expr_var_init(ctx, &(vars[1]), "value", -1);
+  grn_plugin_command_create(ctx,
+                            "conf_set", -1,
+                            command_conf_set,
+                            2,
+                            vars);
+}
+
+void
+grn_proc_init_conf_delete(grn_ctx *ctx)
+{
+  grn_expr_var vars[1];
+
+  grn_plugin_expr_var_init(ctx, &(vars[0]), "key", -1);
+  grn_plugin_command_create(ctx,
+                            "conf_delete", -1,
+                            command_conf_delete,
+                            1,
+                            vars);
+}

  Modified: lib/proc/sources.am (+1 -0)
===================================================================
--- lib/proc/sources.am    2016-01-13 16:27:21 +0900 (7ac96bc)
+++ lib/proc/sources.am    2016-01-13 16:46:14 +0900 (f4717bb)
@@ -1,2 +1,3 @@
 libgrnproc_la_SOURCES =				\
+	proc_conf.c				\
 	proc_schema.c

  Added: test/command/suite/conf_delete/existent.expected (+8 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_delete/existent.expected    2016-01-13 16:46:14 +0900 (1b42abe)
@@ -0,0 +1,8 @@
+conf_set key value
+[[0,0.0,0.0],true]
+conf_get key
+[[0,0.0,0.0],"value"]
+conf_delete key
+[[0,0.0,0.0],true]
+conf_get key
+[[0,0.0,0.0],""]

  Added: test/command/suite/conf_delete/existent.test (+4 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_delete/existent.test    2016-01-13 16:46:14 +0900 (8e5ce01)
@@ -0,0 +1,4 @@
+conf_set key value
+conf_get key
+conf_delete key
+conf_get key

  Added: test/command/suite/conf_delete/no_key.expected (+3 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_delete/no_key.expected    2016-01-13 16:46:14 +0900 (81c6232)
@@ -0,0 +1,3 @@
+conf_delete
+[[[-22,0.0,0.0],"[conf][delete] key is missing"]]
+#|e| [conf][delete] key is missing

  Added: test/command/suite/conf_delete/no_key.test (+1 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_delete/no_key.test    2016-01-13 16:46:14 +0900 (2f0e6f0)
@@ -0,0 +1 @@
+conf_delete

  Added: test/command/suite/conf_delete/nonexistent.expected (+3 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_delete/nonexistent.expected    2016-01-13 16:46:14 +0900 (375ca45)
@@ -0,0 +1,3 @@
+conf_delete key
+[[[-22,0.0,0.0],"[conf][delete] failed to delete"],false]
+#|e| [conf][delete] failed to delete

  Added: test/command/suite/conf_delete/nonexistent.test (+1 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_delete/nonexistent.test    2016-01-13 16:46:14 +0900 (238fa13)
@@ -0,0 +1 @@
+conf_delete key

  Added: test/command/suite/conf_get/existent.expected (+4 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_get/existent.expected    2016-01-13 16:46:14 +0900 (ca684d9)
@@ -0,0 +1,4 @@
+conf_set key value
+[[0,0.0,0.0],true]
+conf_get key
+[[0,0.0,0.0],"value"]

  Added: test/command/suite/conf_get/existent.test (+2 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_get/existent.test    2016-01-13 16:46:14 +0900 (0c1df32)
@@ -0,0 +1,2 @@
+conf_set key value
+conf_get key

  Added: test/command/suite/conf_get/no_key.expected (+3 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_get/no_key.expected    2016-01-13 16:46:14 +0900 (68b0606)
@@ -0,0 +1,3 @@
+conf_get
+[[[-22,0.0,0.0],"[conf][get] key is missing"]]
+#|e| [conf][get] key is missing

  Added: test/command/suite/conf_get/no_key.test (+1 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_get/no_key.test    2016-01-13 16:46:14 +0900 (8e16d7f)
@@ -0,0 +1 @@
+conf_get

  Added: test/command/suite/conf_get/nonexistent.expected (+2 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_get/nonexistent.expected    2016-01-13 16:46:14 +0900 (0e4d446)
@@ -0,0 +1,2 @@
+conf_get key
+[[0,0.0,0.0],""]

  Added: test/command/suite/conf_get/nonexistent.test (+1 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_get/nonexistent.test    2016-01-13 16:46:14 +0900 (efcef18)
@@ -0,0 +1 @@
+conf_get key

  Added: test/command/suite/conf_set/no_key.expected (+3 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_set/no_key.expected    2016-01-13 16:46:14 +0900 (814947b)
@@ -0,0 +1,3 @@
+conf_set
+[[[-22,0.0,0.0],"[conf][set] key is missing"]]
+#|e| [conf][set] key is missing

  Added: test/command/suite/conf_set/no_key.test (+1 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_set/no_key.test    2016-01-13 16:46:14 +0900 (1be2128)
@@ -0,0 +1 @@
+conf_set

  Added: test/command/suite/conf_set/no_value.expected (+4 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_set/no_value.expected    2016-01-13 16:46:14 +0900 (8d18d31)
@@ -0,0 +1,4 @@
+conf_set key
+[[0,0.0,0.0],true]
+conf_get key
+[[0,0.0,0.0],""]

  Added: test/command/suite/conf_set/no_value.test (+2 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_set/no_value.test    2016-01-13 16:46:14 +0900 (b3ea624)
@@ -0,0 +1,2 @@
+conf_set key
+conf_get key

  Added: test/command/suite/conf_set/value.expected (+4 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_set/value.expected    2016-01-13 16:46:14 +0900 (ca684d9)
@@ -0,0 +1,4 @@
+conf_set key value
+[[0,0.0,0.0],true]
+conf_get key
+[[0,0.0,0.0],"value"]

  Added: test/command/suite/conf_set/value.test (+2 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/conf_set/value.test    2016-01-13 16:46:14 +0900 (0c1df32)
@@ -0,0 +1,2 @@
+conf_set key value
+conf_get key
-------------- next part --------------
HTML����������������������������...
Download 



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