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);
259 value = mrb_str_new(mrb,
in, len);
268 return mrb_nil_value();
283 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
286 if (mrb_get_argc(mrb) > 0) {
287 if (mrb_get_args(mrb,
"|i", &idx) < 1) mrb_raise(mrb, E_ARGUMENT_ERROR,
"Invalid argument");
290 if (idx == pair->
idx)
vp = pair->
vp;
293 if (!
vp)
return mrb_nil_value();
308 if (count < pair->idx) mrb_raisef(mrb, E_ARGUMENT_ERROR,
309 "Attempt to set instance %d when only %d exist", pair->
idx,
count);
313 mrb_raisef(mrb, E_RUNTIME_ERROR,
"Failed adding %s", pair->
da->name);
322 switch (
vp->vp_type) {
335#define RUBYSETINT(_size) case FR_TYPE_INT ## _size: \
336 if (mrb_type(*value) != MRB_TT_INTEGER) mrb_raise(mrb, E_ARGUMENT_ERROR, "Integer value required"); \
337 vp->vp_int ## _size = mrb_integer(*value); \
344#define RUBYSETUINT(_size) case FR_TYPE_UINT ## _size: \
345 if (mrb_type(*value) != MRB_TT_INTEGER) mrb_raise(mrb, E_ARGUMENT_ERROR, "Integer value required"); \
346 vp->vp_uint ## _size = mrb_integer(*value); \
353#define RUBYSETFLOAT(_size) case FR_TYPE_FLOAT ## _size: \
354 switch (mrb_type(*value)) { \
356 vp->vp_float ## _size = mrb_float(*value); \
358 case MRB_TT_INTEGER: \
359 vp->vp_float ## _size = mrb_integer(*value); \
362 mrb_raise(mrb, E_ARGUMENT_ERROR, "Float or integer value required"); \
380 mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed populating pair");
405 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
412 mrb_get_args(mrb,
"o|i", &
value, &idx);
416 if (idx == pair->
idx)
vp = pair->
vp;
421 if (
count < idx) mrb_raisef(mrb, E_ARGUMENT_ERROR,
422 "Attempt to set instance %d when only %d exist", idx,
count);
426 mrb_raisef(mrb, E_RUNTIME_ERROR,
"Failed adding %s", pair->
da->name);
433 return mrb_nil_value();
448 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
452 mrb_get_args(mrb,
"o", &
value);
457 mrb_raisef(mrb, E_RUNTIME_ERROR,
"Failed adding %s", pair->
da->name);
463 return mrb_nil_value();
477 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
479 mrb_get_args(mrb,
"|i", &idx);
481 if (!pair->
parent->
vp)
return mrb_nil_value();
483 if (idx == pair->
idx)
vp = pair->
vp;
485 if (!
vp)
return mrb_nil_value();
488 if (idx == pair->
idx) pair->
vp = NULL;
489 return mrb_nil_value();
500 mrb_value *
args = NULL, mruby_pair, pair_args[6], argv;
501 mrb_int argc = 0, len;
503 size_t idx = 0, child_idx = 0;
504 char *attr_name, *child_attr_name = NULL;
509 if (!pair) mrb_raise(mrb, E_RUNTIME_ERROR,
"Failed to retrieve C data");
512 if (
fr_type_is_leaf(pair->
da->type)) mrb_raisef(mrb, E_RUNTIME_ERROR,
"%s is a leaf attribute so has no children",
514 mrb_get_args(mrb,
"n|*!", &attr, &
args, &argc);
516 if (argc > 3) mrb_raise(mrb, E_ARGUMENT_ERROR,
"Maximum three arguments allowed");
531 for (i = 0; i < argc; i++) {
533 switch (mrb_type(argv)) {
536 idx = mrb_integer(argv);
538 if (!child_attr_name) mrb_raise(mrb, E_ARGUMENT_ERROR,
"Child attribute instance must follow attribute name");
539 child_idx = mrb_integer(argv);
544 if (child_attr_name) mrb_raise(mrb, E_ARGUMENT_ERROR,
"Only one child attribute name allowed");
545 child_attr_name = mrb_str_to_cstr(mrb, argv);
549 mrb_raise(mrb, E_ARGUMENT_ERROR,
"Arguments can only be integer (attribute instance), or string (attribute name)");
553 attr_name = talloc_strdup(request, mrb_sym_name_len(mrb, attr, &len));
554 for (i = 0; i < len; i++) {
555 if (attr_name[i] ==
'_') attr_name[i] =
'-';
567 if (!da) mrb_raisef(mrb, E_ARGUMENT_ERROR,
"Unknown or invalid attriubte name \"%s\"", attr_name);
574 pair_args[3] = mrb_int_value(mrb, idx);
584 if (!child_attr_name)
return mruby_pair;
586 for (i = 0; i < (int)strlen(child_attr_name); i++) {
587 if (child_attr_name[i] ==
'_') child_attr_name[i] =
'-';
596 if (!child_da) mrb_raisef(mrb, E_ARGUMENT_ERROR,
"Unknown or invalid attriubte name \"%s\"", attr_name);
602 pair_args[3] = mrb_boxing_int_value(mrb, child_idx);
615 pair_list = mrb_define_class_under(mrb,
parent,
"PairList", mrb->object_class);
616 MRB_SET_INSTANCE_TT(
pair_list, MRB_TT_DATA);
629 pair = mrb_define_class_under(mrb,
parent,
"Pair", mrb->object_class);
630 MRB_SET_INSTANCE_TT(pair, MRB_TT_DATA);
632 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.
#define RUBYSETINT(_size)
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
#define RUBYSETUINT(_size)
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.
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 void mruby_roby_to_pair_value(mrb_state *mrb, mrb_value *value, fr_pair_t *vp)
Convert a ruby value to a fr_pair_t value.
static mrb_value mruby_ruby_pair_object(mrb_state *mrb, struct RClass *klass, mruby_pair_t *pair)
#define RUBYSETFLOAT(_size)
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)
int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted)
Copy data into an "octets" data type.
int fr_pair_value_from_str(fr_pair_t *vp, char const *value, size_t inlen, fr_sbuff_unescape_rules_t const *uerules, UNUSED bool tainted)
Convert string value to native attribute value.
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.
int fr_pair_value_bstrndup(fr_pair_t *vp, char const *src, size_t len, bool tainted)
Copy data into a "string" type value pair.
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)
#define fr_type_is_leaf(_x)
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