/* * Sets a configuration key and value pair. * * @overload config[]=(key, value) * @param [String] key The key. * @param [String] value The value to be assigned. * @return [String] `value`. */ static VALUE rb_grn_config_set (VALUE self, VALUE rb_key, VALUE rb_value) { VALUE rb_value_original = rb_value; VALUE rb_context; grn_ctx *context; const char *key; int key_size; const char *value; int value_size; rb_context = rb_iv_get(self, "@context"); context = rb_grn_context_ensure(&rb_context); rb_key = rb_grn_convert_to_string(rb_key); key = RSTRING_PTR(rb_key); key_size = RSTRING_LEN(rb_key); rb_value = rb_grn_convert_to_string(rb_value); value = RSTRING_PTR(rb_value); value_size = RSTRING_LEN(rb_value); { grn_rc rc; rc = grn_config_set(context, key, key_size, value, value_size); rb_grn_context_check(context, self); rb_grn_rc_check(rc, self); } return rb_value_original; }
/* * @overload register(event_source_name, options={}) * * Registers Windows Event Log based logger that uses * `event_source_name` as event source name. * * @param event_source_name [String] The event source name. * @param options [::Hash] * @option options :context [Groonga::Context] (Groonga::Context.default) * The context to be set logger. * * @return [void] * * @since 5.0.5 */ static VALUE rb_grn_windows_event_logger_s_register (int argc, VALUE *argv, VALUE klass) { VALUE rb_event_source_name; VALUE rb_options; VALUE rb_context; const char *event_source_name; grn_ctx *context; grn_rc rc; rb_scan_args(argc, argv, "11", &rb_event_source_name, &rb_options); rb_event_source_name = rb_grn_convert_to_string(rb_event_source_name); event_source_name = StringValueCStr(rb_event_source_name); rb_grn_scan_options(rb_options, "context", &rb_context, NULL); context = rb_grn_context_ensure(&rb_context); rc = grn_windows_event_logger_set(context, event_source_name); rb_grn_context_check(context, rb_event_source_name); rb_grn_rc_check(rc, rb_event_source_name); return Qnil; }
static int rb_grn_hash_from_ruby_hash_body (VALUE rb_key, VALUE rb_value, VALUE user_data) { RbGrnHashFromRubyHashData *data = (RbGrnHashFromRubyHashData *)user_data; grn_obj *value; int added; rb_key = rb_grn_convert_to_string(rb_key); grn_hash_add(data->context, data->hash, RSTRING_PTR(rb_key), RSTRING_LEN(rb_key), (void **)&value, &added); rb_grn_context_check(data->context, data->rb_hash); if (added) { GRN_VOID_INIT(value); } RVAL2GRNBULK(rb_value, data->context, value); return ST_CONTINUE; }
/* * Gets a configuration value for key. * * @overload config[](key) * @param [String] key The key. * @return [String, nil] The value associated with `key`. * * @since 5.0.9 */ static VALUE rb_grn_config_get (VALUE self, VALUE rb_key) { VALUE rb_context; VALUE rb_value; grn_ctx *context; const char *key; int key_size; const char *value; uint32_t value_size; rb_context = rb_iv_get(self, "@context"); context = rb_grn_context_ensure(&rb_context); rb_key = rb_grn_convert_to_string(rb_key); key = RSTRING_PTR(rb_key); key_size = RSTRING_LEN(rb_key); { grn_rc rc; rc = grn_config_get(context, key, key_size, &value, &value_size); rb_grn_context_check(context, self); rb_grn_rc_check(rc, self); } if (value_size == 0) { rb_value = Qnil; } else { rb_value = rb_grn_context_rb_string_new(context, value, value_size); } return rb_value; }