The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
mruby.c
Go to the documentation of this file.
1/*
2 * This program is is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: 6da6d896f5309ff932d9f2f4a2a53bc4b90cdff0 $
19 * @file rlm_mruby.c
20 * @brief Translates requests between the server an an mruby interpreter.
21 *
22 * @copyright 2016 Herwin Weststrate (freeradius@herwinw.nl)
23 * @copyright 2016 The FreeRADIUS server project
24 */
25
26#include "rlm_mruby.h"
27
28static mrb_value mruby_request_frconfig(mrb_state *mrb, mrb_value self)
29{
30 return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb, "@frconfig"));
31}
32
33static mrb_value mruby_request_request(mrb_state *mrb, mrb_value self)
34{
35 return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb, "@request"));
36}
37
38static mrb_value mruby_request_reply(mrb_state *mrb, mrb_value self)
39{
40 return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb, "@reply"));
41}
42
43static mrb_value mruby_request_control(mrb_state *mrb, mrb_value self)
44{
45 return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb, "@control"));
46}
47
48static mrb_value mruby_request_session_state(mrb_state *mrb, mrb_value self)
49{
50 return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb, "@session_state"));
51}
52
53static mrb_value mruby_request_proxy_request(mrb_state *mrb, mrb_value self)
54{
55 mrb_sym sym = mrb_intern_cstr(mrb, "@proxy_request");
56 if (mrb_iv_defined(mrb, self, sym)) {
57 return mrb_iv_get(mrb, self, sym);
58 } else {
59 return mrb_ary_new_capa(mrb, 0);
60 }
61}
62
63static mrb_value mruby_request_proxy_reply(mrb_state *mrb, mrb_value self)
64{
65 mrb_sym sym = mrb_intern_cstr(mrb, "@proxy_reply");
66 if (mrb_iv_defined(mrb, self, sym)) {
67 return mrb_iv_get(mrb, self, sym);
68 } else {
69 return mrb_ary_new_capa(mrb, 0);
70 }
71}
72
73struct RClass *mruby_request_class(mrb_state *mrb, struct RClass *parent)
74{
75 struct RClass *request;
76
77 request = mrb_define_class_under(mrb, parent, "Request", mrb->object_class);
78
79 /* FIXME: Use attr_reader (if available) */
80 mrb_define_method(mrb, request, "frconfig", mruby_request_frconfig, MRB_ARGS_NONE());
81 mrb_define_method(mrb, request, "request", mruby_request_request, MRB_ARGS_NONE());
82 mrb_define_method(mrb, request, "reply", mruby_request_reply, MRB_ARGS_NONE());
83 mrb_define_method(mrb, request, "control", mruby_request_control, MRB_ARGS_NONE());
84 mrb_define_method(mrb, request, "session_state", mruby_request_session_state, MRB_ARGS_NONE());
85 mrb_define_method(mrb, request, "proxy_request", mruby_request_proxy_request, MRB_ARGS_NONE());
86 mrb_define_method(mrb, request, "proxy_reply", mruby_request_proxy_reply, MRB_ARGS_NONE());
87
88 return request;
89}
struct RClass * mruby_request_class(mrb_state *mrb, struct RClass *parent)
Definition mruby.c:73
static mrb_value mruby_request_reply(mrb_state *mrb, mrb_value self)
Definition mruby.c:38
static mrb_value mruby_request_proxy_request(mrb_state *mrb, mrb_value self)
Definition mruby.c:53
static mrb_value mruby_request_control(mrb_state *mrb, mrb_value self)
Definition mruby.c:43
static mrb_value mruby_request_session_state(mrb_state *mrb, mrb_value self)
Definition mruby.c:48
static mrb_value mruby_request_frconfig(mrb_state *mrb, mrb_value self)
Definition mruby.c:28
static mrb_value mruby_request_request(mrb_state *mrb, mrb_value self)
Definition mruby.c:33
static mrb_value mruby_request_proxy_reply(mrb_state *mrb, mrb_value self)
Definition mruby.c:63
Translates requests between the server an an mruby interpreter.
static fr_slen_t parent
Definition pair.h:851