<div dir="ltr">Some time ago I wrote C++ module for freeradius (to interact with billing interface) with next approach:<div><br></div><div>1. write special c file where freeradius API is imported, and API which is callable from "C++" for access to radius struct </div>
<div><br></div><div style>2. and special .h "freeradius_cpp_api.h" file where prototypes with this "accessors from C++" is defined with external "C" linkage.</div><div style><br></div><div style>
3. import in c++ "freeradius_cpp_api.h" instead freeradius headers.</div><div style><br></div><div style>and at least with gcc - all works fine after linking with right libraries.</div><div> </div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 11, 2013 at 3:58 PM, Patrick Ko <span dir="ltr"><<a href="mailto:patrick0585@googlemail.com" target="_blank">patrick0585@googlemail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello everybody,<br>here are my Steps how i created an C++ Module for FreeRadius.<br><br><ul><li><b>Adaptions in the radiusd.conf</b></li>
</ul> Create an new Module Section like:<br><br>
<p class="MsoNormal" style="margin-left:35.4pt">modules {<span> </span><span style="color:blue"><br></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span> </span>cpp
{</p>
<p class="MsoNormal" style="margin-left:35.4pt"><span> </span>…</p>
<p class="MsoNormal" style="margin-left:35.4pt"><span> </span><span> </span>}</p>
<p class="MsoNormal" style="margin-left:35.4pt"><span> </span><span> </span>}</p>
<br><br><ul><li>Creating an new Directory in the modules Directory <br></li></ul> I created an new Directory named "<b>rlm_cpp</b>" where I putted an Makefile and my <b>rlm_cpp.cpp</b> File<br><br><br>
<b>Makefile:</b><br><br> <i>TARGET = rlm_cpp<br></i><div style="margin-left:40px"><i>SRCS = rlm_cpp.cpp <br></i></div><div style="margin-left:40px"><i>HEADERS = <br>RLM_CFLAGS = -I/usr/include<br>
RLM_LIBS = -lc<br>RLM_INSTALL = install-example<br><br>## this uses the RLM_CFLAGS and RLM_LIBS and SRCS defs to make TARGET.<br>include ../rules.mak<br><br>$(LT_OBJS): $(HEADERS)<br><br>## the rule that RLM_INSTALL tells the parent rules.mak to use.<br>
install-example:<br> touch .</i><br><br><br></div><div style="margin-left:40px">My outgoing rlm_cpp.cpp File was the *.c File I took.<br>Then I need to change every function of this file like this:<br><br><b>extern "C"</b> {<br>
<div style="margin-left:40px">static int cpp_authorize(void *instance, REQUEST *request)<br>{<br><div style="margin-left:40px">...<br></div>}<br></div>}<br><br>Then I added two DEFINES at the TOP of my rlm_cpp.cpp File, because the two words are reserved names in in C.<br>
<br><b>#define operator op3578000<br>#define template tem34123</b><br><br>At the end I needed to change the the struct. First I changed the struct in radiusd.conf<br><br>struct auth_req {<br><div style="margin-left:40px">
...<br>home_server<b>_t </b> *home_server<br>...<br></div>}<br><br>typedef struct radclient {<br>...<br><div style="margin-left:40px">home_server<b>_t </b> *coa_server;<br></div>...<br>} RADCLIENT;<br>
<br>Also change the Typedef to:<br><br><span style="font-size:12.0pt;font-family:"Times New Roman"" lang="EN-GB">typedef struct
home_server {<br>...<br>}</span><span style="font-size:12.0pt;font-family:"Times New Roman"" lang="EN-GB">home_server<b><span style="color:red">_t;</span></b></span><br><br>Every struct in the Source of FreeRadius need to be changed to <font size="4"><b>home_server_t</b></font>!<br>
<br><br>now you should made finallay the main make and see the all should be fine compiled! at the end run "make install " and implement the new C++ Module in an Section in the radiusd.conf and it will run!<br>
<br>
<br></div>Greetz<span class="HOEnZb"><font color="#888888"><br>Patrick<br><br>
</font></span><br>-<br>
List info/subscribe/unsubscribe? See <a href="http://www.freeradius.org/list/devel.html" target="_blank">http://www.freeradius.org/list/devel.html</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Ruslan Shevchenko<br>
Software Engineer.<br><a href="http://ua.linkedin.com/in/ruslanshevchenko" target="_blank">http://ua.linkedin.com/in/ruslanshevchenko</a>
</div>