40 return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb,
"@frconfig"));
45 return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb,
"@request"));
50 return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb,
"@reply"));
55 return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb,
"@control"));
60 return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb,
"@session_state"));
65 struct RClass *request;
67 request = mrb_define_class_under(mrb,
parent,
"Request", mrb->object_class);
82 .struct_name =
"Inst",
87 .struct_name =
"Request",
92 .struct_name =
"DictAttr",
97 .struct_name =
"ValuePair",
102 .struct_name =
"RubyPair",
116 return mrb_obj_value(Data_Wrap_Struct(mrb, klass, &
mruby_request_type, (
void *)request));
153 mrb_get_args(mrb,
"dddid|d",
196 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
198 keys = mrb_ary_new(mrb);
199 if (!pair->
vp)
return keys;
201 key = mrb_str_new(mrb,
vp->
da->name, strlen(
vp->
da->name));
202 mrb_ary_push(mrb, keys, key);
215 return mrb_str_new(mrb,
vp->vp_ptr,
vp->vp_length);
218 return vp->vp_bool ? mrb_obj_value(mrb->true_class) : mrb_obj_value(mrb->false_class);
221 return mrb_int_value(mrb,
vp->vp_uint8);
223 return mrb_int_value(mrb,
vp->vp_uint16);
225 return mrb_int_value(mrb,
vp->vp_uint32);
227 return mrb_int_value(mrb,
vp->vp_uint64);
229 return mrb_int_value(mrb,
vp->vp_int8);
231 return mrb_int_value(mrb,
vp->vp_int16);
233 return mrb_int_value(mrb,
vp->vp_int32);
235 return mrb_int_value(mrb,
vp->vp_int64);
237 return mrb_int_value(mrb,
vp->vp_size);
240 return mrb_float_value(mrb,
vp->vp_float32);
242 return mrb_float_value(mrb,
vp->vp_float64);
261 if (len < 0)
return mrb_nil_value();
262 value = mrb_str_new(mrb,
in, len);
272 return mrb_nil_value();
287 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
290 if (mrb_get_argc(mrb) > 0) {
291 if (mrb_get_args(mrb,
"|i", &idx) < 1) mrb_raise(mrb, E_ARGUMENT_ERROR,
"Invalid argument");
294 if (idx == pair->
idx)
vp = pair->
vp;
297 if (!
vp)
return mrb_nil_value();
312 if (count < pair->idx) mrb_raisef(mrb, E_ARGUMENT_ERROR,
313 "Attempt to set instance %d when only %d exist", pair->
idx,
count);
317 mrb_raisef(mrb, E_RUNTIME_ERROR,
"Failed adding %s", pair->
da->name);
331 switch (mrb_type(*
value)) {
334 vb.vb_int64 = mrb_integer(*
value);
339 vb.vb_float64 = mrb_float(*
value);
358 mrb_raise(mrb, E_ARGUMENT_ERROR,
"Unsupported value type");
366 mrb_raisef(mrb, E_ARGUMENT_ERROR,
"Failed casting ruby value to %s",
fr_type_to_str(
vp->vp_type));
385 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
392 mrb_get_args(mrb,
"o|i", &
value, &idx);
396 if (idx == pair->
idx)
vp = pair->
vp;
401 if (
count < idx) mrb_raisef(mrb, E_ARGUMENT_ERROR,
402 "Attempt to set instance %d when only %d exist", idx,
count);
406 mrb_raisef(mrb, E_RUNTIME_ERROR,
"Failed adding %s", pair->
da->name);
413 return mrb_nil_value();
428 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
432 mrb_get_args(mrb,
"o", &
value);
437 mrb_raisef(mrb, E_RUNTIME_ERROR,
"Failed adding %s", pair->
da->name);
443 return mrb_nil_value();
457 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
459 mrb_get_args(mrb,
"|i", &idx);
461 if (!pair->
parent->
vp)
return mrb_nil_value();
463 if (idx == pair->
idx)
vp = pair->
vp;
465 if (!
vp)
return mrb_nil_value();
468 if (idx == pair->
idx) pair->
vp = NULL;
469 return mrb_nil_value();
480 mrb_value *
args = NULL, mruby_pair, pair_args[6], argv;
481 mrb_int argc = 0, len;
483 size_t idx = 0, child_idx = 0;
484 char *attr_name, *child_attr_name = NULL;
489 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
492 if (
fr_type_is_leaf(pair->
da->type)) mrb_raisef(mrb, E_RUNTIME_ERROR,
"%s is a leaf attribute so has no children",
494 mrb_get_args(mrb,
"n|*!", &attr, &
args, &argc);
496 if (argc > 3) mrb_raise(mrb, E_ARGUMENT_ERROR,
"Maximum three arguments allowed");
511 for (i = 0; i < argc; i++) {
513 switch (mrb_type(argv)) {
516 idx = mrb_integer(argv);
518 if (!child_attr_name) mrb_raise(mrb, E_ARGUMENT_ERROR,
"Child attribute instance must follow attribute name");
519 child_idx = mrb_integer(argv);
524 if (child_attr_name) mrb_raise(mrb, E_ARGUMENT_ERROR,
"Only one child attribute name allowed");
525 child_attr_name = mrb_str_to_cstr(mrb, argv);
529 mrb_raise(mrb, E_ARGUMENT_ERROR,
"Arguments can only be integer (attribute instance), or string (attribute name)");
533 attr_name =
talloc_strdup(request, mrb_sym_name_len(mrb, attr, &len));
534 for (i = 0; i < len; i++) {
535 if (attr_name[i] ==
'_') attr_name[i] =
'-';
547 if (!da) mrb_raisef(mrb, E_ARGUMENT_ERROR,
"Unknown or invalid attriubte name \"%s\"", attr_name);
554 pair_args[3] = mrb_int_value(mrb, idx);
564 if (!child_attr_name)
return mruby_pair;
566 for (i = 0; i < (int)strlen(child_attr_name); i++) {
567 if (child_attr_name[i] ==
'_') child_attr_name[i] =
'-';
576 if (!child_da) mrb_raisef(mrb, E_ARGUMENT_ERROR,
"Unknown or invalid attriubte name \"%s\"", attr_name);
582 pair_args[3] = mrb_boxing_int_value(mrb, child_idx);
595 pair_list = mrb_define_class_under(mrb,
parent,
"PairList", mrb->object_class);
596 MRB_SET_INSTANCE_TT(
pair_list, MRB_TT_DATA);
609 pair = mrb_define_class_under(mrb,
parent,
"Pair", mrb->object_class);
610 MRB_SET_INSTANCE_TT(pair, MRB_TT_DATA);
612 mrb_define_method(mrb, pair,
"initialize",
mruby_pair_init, MRB_ARGS_ARG(5,1));
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *attr))
Locate a fr_dict_attr_t by its name.
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
fr_dict_t const * fr_dict_internal(void)
TALLOC_CTX * unlang_interpret_frame_talloc_ctx(request_t *request)
Get a talloc_ctx which is valid only for this frame.
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
@ FR_TYPE_FLOAT32
Single precision floating point.
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_INT8
8 Bit signed integer.
@ FR_TYPE_ETHERNET
48 Bit Mac-Address.
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_INT64
64 Bit signed integer.
@ FR_TYPE_INT16
16 Bit signed integer.
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
@ FR_TYPE_COMBO_IP_PREFIX
IPv4 or IPv6 address prefix depending on length.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
@ FR_TYPE_IPV4_PREFIX
IPv4 Prefix.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_SIZE
Unsigned integer capable of representing any memory address on the local system.
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
@ FR_TYPE_IFID
Interface ID.
@ FR_TYPE_OCTETS
Raw octets.
@ FR_TYPE_FLOAT64
Double precision floating point.
struct RClass * mruby_request_class(mrb_state *mrb, struct RClass *parent)
static mrb_value mruby_value_pair_append(mrb_state *mrb, mrb_value self)
Append an instance of a value pair from mruby.
mrb_value mruby_request_object(mrb_state *mrb, struct RClass *klass, request_t *request)
static const struct mrb_data_type mruby_value_pair_type
static mrb_value mruby_value_pair_del(mrb_state *mrb, mrb_value self)
Delete a value pair from mruby.
mruby_pair_t * parent
Parent pair.
static mrb_value mruby_pair_init(mrb_state *mrb, mrb_value self)
Associate C structure with Ruby object representing a pair.
mrb_value mruby_value_pair_object(mrb_state *mrb, struct RClass *klass, fr_pair_t *vp)
static const struct mrb_data_type mruby_ruby_pair_type
static mrb_value mruby_request_reply(mrb_state *mrb, mrb_value self)
rlm_mruby_t const * inst
Module instance. Needed for access to classes.
static mrb_value mruby_value_pair_get(mrb_state *mrb, mrb_value self)
Get a pair value from mruby.
unsigned int idx
Instance index.
static mrb_value mruby_pair_list_keys(mrb_state *mrb, mrb_value self)
Fetch the list of children of a list.
static const struct mrb_data_type mruby_dict_attr_type
struct mruby_pair_s mruby_pair_t
static const struct mrb_data_type mruby_inst_type
static mrb_value mruby_pair_value_to_ruby(mrb_state *mrb, request_t *request, fr_pair_t *vp)
Convert a pair value to a suitable mruby value type.
static void mruby_ruby_to_pair_value(mrb_state *mrb, mrb_value *value, fr_pair_t *vp)
Convert a ruby value to a fr_pair_t value.
mrb_value mruby_dict_attr_object(mrb_state *mrb, struct RClass *klass, fr_dict_attr_t const *da)
static mrb_value mruby_request_control(mrb_state *mrb, mrb_value self)
struct RClass * mruby_pair_list_class(mrb_state *mrb, struct RClass *parent)
request_t * request
Current request.
static mrb_value mruby_value_pair_set(mrb_state *mrb, mrb_value self)
Set a value pair from mruby.
static void mruby_pair_parent_build(mrb_state *mrb, mruby_pair_t *pair)
Build parent structural pairs needed when a leaf node is set.
struct RClass * mruby_pair_class(mrb_state *mrb, struct RClass *parent)
static mrb_value mruby_pair_list_missing(mrb_state *mrb, mrb_value self)
Implement mruby method_missing functionality to find child pairs.
mrb_value mruby_inst_object(mrb_state *mrb, struct RClass *klass, rlm_mruby_t const *inst)
static mrb_value mruby_request_session_state(mrb_state *mrb, mrb_value self)
fr_pair_t * vp
Real pair if it exists.
static const struct mrb_data_type mruby_request_type
static mrb_value mruby_request_frconfig(mrb_state *mrb, mrb_value self)
fr_dict_attr_t const * da
Dictionary attribute for this pair.
static mrb_value mruby_request_request(mrb_state *mrb, mrb_value self)
static mrb_value mruby_ruby_pair_object(mrb_state *mrb, struct RClass *klass, mruby_pair_t *pair)
unsigned int fr_pair_count_by_da(fr_pair_list_t const *list, fr_dict_attr_t const *da)
Return the number of instances of a given da in the specified list.
int fr_pair_append_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da)
Alloc a new fr_pair_t (and append)
fr_pair_t * fr_pair_find_by_da_idx(fr_pair_list_t const *list, fr_dict_attr_t const *da, unsigned int idx)
Find a pair with a matching da at a given index.
void fr_pair_value_clear(fr_pair_t *vp)
Free/zero out value (or children) of a given VP.
int fr_pair_delete(fr_pair_list_t *list, fr_pair_t *vp)
Remove fr_pair_t from a list and free.
Translates requests between the server an an mruby interpreter.
struct RClass * mruby_pair_list
struct RClass * mruby_pair
struct RClass * mruby_ptr
eap_aka_sim_process_conf_t * inst
Stores an attribute, a value and various bits of other data.
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
#define talloc_strdup(_ctx, _str)
fr_pair_t * fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item))
Get the next item in a valuepair list after a specific entry.
fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair list.
#define fr_type_is_group(_x)
@ FR_TYPE_ATTR
A contains an attribute reference.
#define fr_type_is_leaf(_x)
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_value_box_t const *src)
Convert one type of fr_value_box_t to another.
void fr_value_box_bstrndup_shallow(fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, size_t len, bool tainted)
Assign a string to to a fr_value_box_t.
static fr_slen_t fr_value_box_aprint(TALLOC_CTX *ctx, char **out, fr_value_box_t const *data, fr_sbuff_escape_rules_t const *e_rules) 1(fr_value_box_print
#define fr_value_box_init(_vb, _type, _enumv, _tainted)
Initialise a fr_value_box_t.