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);
200 key = mrb_str_new(mrb,
vp->
da->name, strlen(
vp->
da->name));
201 mrb_ary_push(mrb, keys, key);
214 return mrb_str_new(mrb,
vp->vp_ptr,
vp->vp_length);
217 return vp->vp_bool ? mrb_obj_value(mrb->true_class) : mrb_obj_value(mrb->false_class);
220 return mrb_int_value(mrb,
vp->vp_uint8);
222 return mrb_int_value(mrb,
vp->vp_uint16);
224 return mrb_int_value(mrb,
vp->vp_uint32);
226 return mrb_int_value(mrb,
vp->vp_uint64);
228 return mrb_int_value(mrb,
vp->vp_int8);
230 return mrb_int_value(mrb,
vp->vp_int16);
232 return mrb_int_value(mrb,
vp->vp_int32);
234 return mrb_int_value(mrb,
vp->vp_int64);
236 return mrb_int_value(mrb,
vp->vp_size);
239 return mrb_float_value(mrb,
vp->vp_float32);
241 return mrb_float_value(mrb,
vp->vp_float64);
260 value = mrb_str_new(mrb,
in, len);
270 return mrb_nil_value();
285 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
288 if (mrb_get_argc(mrb) > 0) {
289 if (mrb_get_args(mrb,
"|i", &idx) < 1) mrb_raise(mrb, E_ARGUMENT_ERROR,
"Invalid argument");
292 if (idx == pair->
idx)
vp = pair->
vp;
295 if (!
vp)
return mrb_nil_value();
310 if (count < pair->idx) mrb_raisef(mrb, E_ARGUMENT_ERROR,
311 "Attempt to set instance %d when only %d exist", pair->
idx,
count);
315 mrb_raisef(mrb, E_RUNTIME_ERROR,
"Failed adding %s", pair->
da->name);
329 switch (mrb_type(*
value)) {
332 vb.vb_int64 = mrb_integer(*
value);
337 vb.vb_float64 = mrb_float(*
value);
356 mrb_raise(mrb, E_ARGUMENT_ERROR,
"Unsupported value type");
364 mrb_raisef(mrb, E_ARGUMENT_ERROR,
"Failed casting ruby value to %s",
fr_type_to_str(
vp->vp_type));
383 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
390 mrb_get_args(mrb,
"o|i", &
value, &idx);
394 if (idx == pair->
idx)
vp = pair->
vp;
399 if (
count < idx) mrb_raisef(mrb, E_ARGUMENT_ERROR,
400 "Attempt to set instance %d when only %d exist", idx,
count);
404 mrb_raisef(mrb, E_RUNTIME_ERROR,
"Failed adding %s", pair->
da->name);
411 return mrb_nil_value();
426 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
430 mrb_get_args(mrb,
"o", &
value);
435 mrb_raisef(mrb, E_RUNTIME_ERROR,
"Failed adding %s", pair->
da->name);
441 return mrb_nil_value();
455 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
457 mrb_get_args(mrb,
"|i", &idx);
459 if (!pair->
parent->
vp)
return mrb_nil_value();
461 if (idx == pair->
idx)
vp = pair->
vp;
463 if (!
vp)
return mrb_nil_value();
466 if (idx == pair->
idx) pair->
vp = NULL;
467 return mrb_nil_value();
478 mrb_value *
args = NULL, mruby_pair, pair_args[6], argv;
479 mrb_int argc = 0, len;
481 size_t idx = 0, child_idx = 0;
482 char *attr_name, *child_attr_name = NULL;
487 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
490 if (
fr_type_is_leaf(pair->
da->type)) mrb_raisef(mrb, E_RUNTIME_ERROR,
"%s is a leaf attribute so has no children",
492 mrb_get_args(mrb,
"n|*!", &attr, &
args, &argc);
494 if (argc > 3) mrb_raise(mrb, E_ARGUMENT_ERROR,
"Maximum three arguments allowed");
509 for (i = 0; i < argc; i++) {
511 switch (mrb_type(argv)) {
514 idx = mrb_integer(argv);
516 if (!child_attr_name) mrb_raise(mrb, E_ARGUMENT_ERROR,
"Child attribute instance must follow attribute name");
517 child_idx = mrb_integer(argv);
522 if (child_attr_name) mrb_raise(mrb, E_ARGUMENT_ERROR,
"Only one child attribute name allowed");
523 child_attr_name = mrb_str_to_cstr(mrb, argv);
527 mrb_raise(mrb, E_ARGUMENT_ERROR,
"Arguments can only be integer (attribute instance), or string (attribute name)");
531 attr_name = talloc_strdup(request, mrb_sym_name_len(mrb, attr, &len));
532 for (i = 0; i < len; i++) {
533 if (attr_name[i] ==
'_') attr_name[i] =
'-';
545 if (!da) mrb_raisef(mrb, E_ARGUMENT_ERROR,
"Unknown or invalid attriubte name \"%s\"", attr_name);
552 pair_args[3] = mrb_int_value(mrb, idx);
562 if (!child_attr_name)
return mruby_pair;
564 for (i = 0; i < (int)strlen(child_attr_name); i++) {
565 if (child_attr_name[i] ==
'_') child_attr_name[i] =
'-';
574 if (!child_da) mrb_raisef(mrb, E_ARGUMENT_ERROR,
"Unknown or invalid attriubte name \"%s\"", attr_name);
580 pair_args[3] = mrb_boxing_int_value(mrb, child_idx);
593 pair_list = mrb_define_class_under(mrb,
parent,
"PairList", mrb->object_class);
594 MRB_SET_INSTANCE_TT(
pair_list, MRB_TT_DATA);
607 pair = mrb_define_class_under(mrb,
parent,
"Pair", mrb->object_class);
608 MRB_SET_INSTANCE_TT(pair, MRB_TT_DATA);
610 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.
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.