Commit 30d8181e authored by Sebastien Decugis's avatar Sebastien Decugis
Browse files

Added new opaque pointer to fd_sess_handler_create and fd_disp_register for...

Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
parent a6c1c1ed
......@@ -14,7 +14,7 @@ SET(FD_PROJECT_VERSION_MINOR 0)
SET(FD_PROJECT_VERSION_REV 3)
# Version of the API with the library
SET(FD_PROJECT_VERSION_API 1)
SET(FD_PROJECT_VERSION_API 2)
# The test framework, using CTest and CDash.
INCLUDE(CTest)
......
freediameter (1.0.3) UNRELEASED; urgency=low
* Added parameters to fd_disp_register and fd_sess_handler_create,
Bumped API version number accordingly.
* Fixed a couple of issues for portability (#21, #22, #23)
* Fixed issue with ListenOn bit ordering (#20)
* Added dictionary support for MIPv6 application objects.
......
......@@ -621,7 +621,7 @@ np.config.pic_flags.pro4 = 1 # 1 for TCP, for some reason PI_P4_TCP is not def
# Add this peer into the framework.
np.add()
# It is possible to specify a callback for when the connection completes or fails to this peer.
# It is possible to specify a callback for when the connection completes or fails with this peer.
# The prototype is as follow:
def add_cb(peer):
if peer:
......
......@@ -45,7 +45,7 @@ static struct {
/* Callback for incoming Base Accounting Accounting-Request messages */
static int acct_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act)
static int acct_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act)
{
struct msg * m;
struct avp * a = NULL;
......@@ -134,7 +134,7 @@ static int acct_entry(char * conffile)
memset(&data, 0, sizeof(data));
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Base Accounting", &data.app, ENOENT) );
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Accounting-Request", &data.command, ENOENT) );
CHECK_FCT( fd_disp_register( acct_cb, DISP_HOW_CC, &data, NULL ) );
CHECK_FCT( fd_disp_register( acct_cb, DISP_HOW_CC, &data, NULL, NULL ) );
/* Advertise the support for the Diameter Base Accounting application in the peer */
CHECK_FCT( fd_disp_app_support ( data.app, NULL, 0, 1 ) );
......
......@@ -84,7 +84,7 @@ struct avp_max_occurences auth_avps[] =
void diameap_cli_sess_cleanup(void * arg, char * sid)
void diameap_cli_sess_cleanup(void * arg, char * sid, void * opaque)
{
struct diameap_sess_data_sm * diameap_sess_data =
......@@ -3059,7 +3059,7 @@ static int diameap_add_eap_reissued_payload(struct msg * ans, struct msg * req)
static int diameap_server_callback(struct msg ** rmsg, struct avp * ravp,
struct session * sess, enum disp_action * action)
struct session * sess, void * opaque, enum disp_action * action)
{
TRACE_ENTRY("%p %p %p %p", rmsg, ravp, sess, action);
......@@ -3388,7 +3388,7 @@ int diameap_start_server(void)
struct disp_when when;
/*create handler for sessions */
CHECK_FCT(fd_sess_handler_create(&diameap_server_reg, diameap_cli_sess_cleanup));
CHECK_FCT(fd_sess_handler_create(&diameap_server_reg, diameap_cli_sess_cleanup, NULL));
/* Register the callback */
memset(&when, 0, sizeof(when));
......@@ -3396,7 +3396,7 @@ int diameap_start_server(void)
when.app = dataobj_diameap_app;
/* Register the callback for EAP Application */
CHECK_FCT(fd_disp_register(diameap_server_callback, DISP_HOW_CC, &when,
CHECK_FCT(fd_disp_register(diameap_server_callback, DISP_HOW_CC, &when, NULL,
&handle));
if (handle == NULL)
......@@ -3409,8 +3409,8 @@ int diameap_start_server(void)
int diameap_stop_server(void)
{
CHECK_FCT(fd_sess_handler_destroy(&diameap_server_reg));
CHECK_FCT(fd_disp_unregister(&handle));
CHECK_FCT(fd_sess_handler_destroy(&diameap_server_reg, NULL));
CHECK_FCT(fd_disp_unregister(&handle, NULL));
return 0;
}
......@@ -172,7 +172,7 @@ static int acct_conf_parse(char * conffile, struct rgwp_config ** state)
CHECK_MALLOC( new = malloc(sizeof(struct rgwp_config)) );
memset(new, 0, sizeof(struct rgwp_config));
CHECK_FCT( fd_sess_handler_create( &new->sess_hdl, free ) );
CHECK_FCT( fd_sess_handler_create( &new->sess_hdl, free, NULL ) );
new->confstr = conffile;
if (conffile && strstr(conffile, "nonai"))
......@@ -283,7 +283,7 @@ static void acct_conf_free(struct rgwp_config * state)
{
TRACE_ENTRY("%p", state);
CHECK_PARAMS_DO( state, return );
CHECK_FCT_DO( fd_sess_handler_destroy( &state->sess_hdl ), );
CHECK_FCT_DO( fd_sess_handler_destroy( &state->sess_hdl, NULL ), );
free(state);
return;
}
......
......@@ -138,7 +138,7 @@ static int auth_conf_parse(char * confstr, struct rgwp_config ** state)
CHECK_MALLOC( new = malloc(sizeof(struct rgwp_config)) );
memset(new, 0, sizeof(struct rgwp_config));
CHECK_FCT( fd_sess_handler_create( &new->sess_hdl, free ) );
CHECK_FCT( fd_sess_handler_create( &new->sess_hdl, free, NULL ) );
new->confstr = confstr;
if (confstr && strstr(confstr, "nonai"))
......@@ -224,7 +224,7 @@ static void auth_conf_free(struct rgwp_config * state)
{
TRACE_ENTRY("%p", state);
CHECK_PARAMS_DO( state, return );
CHECK_FCT_DO( fd_sess_handler_destroy( &state->sess_hdl ), );
CHECK_FCT_DO( fd_sess_handler_destroy( &state->sess_hdl, NULL ), );
free(state);
return;
}
......
......@@ -38,7 +38,7 @@
#include "rgwx_echodrop.h"
/* If a session is destroyed, empty the list of ed_saved_attribute */
static void state_delete(void * arg, char * sid) {
static void state_delete(void * arg, char * sid, void * opaque) {
struct fd_list * list = (struct fd_list *)arg;
CHECK_PARAMS_DO( list, return );
......@@ -68,7 +68,7 @@ static int ed_conf_parse(char * conffile, struct rgwp_config ** state)
fd_list_init(&new->attributes, NULL);
/* Create the session handler */
CHECK_FCT( fd_sess_handler_create( &new->sess_hdl, state_delete ) );
CHECK_FCT( fd_sess_handler_create( &new->sess_hdl, state_delete, NULL ) );
/* Parse the configuration file */
CHECK_FCT( ed_conffile_parse(conffile, new) );
......@@ -106,7 +106,7 @@ static void ed_conf_free(struct rgwp_config * state)
{
TRACE_ENTRY("%p", state);
CHECK_PARAMS_DO( state, return );
CHECK_FCT_DO( fd_sess_handler_destroy( &state->sess_hdl ), );
CHECK_FCT_DO( fd_sess_handler_destroy( &state->sess_hdl, NULL ), );
while (! FD_IS_LIST_EMPTY(&state->attributes) ) {
struct fd_list * li = state->attributes.next;
fd_list_unlink(li);
......
......@@ -261,7 +261,7 @@ static int sip_conf_parse(char * conffile, struct rgwp_config ** state)
CHECK_MALLOC( new = malloc(sizeof(struct rgwp_config)) );
memset(new, 0, sizeof(struct rgwp_config));
CHECK_FCT( fd_sess_handler_create( &new->sess_hdl, free ) );
CHECK_FCT( fd_sess_handler_create( &new->sess_hdl, free, NULL ) );
new->confstr = conffile;
/* Resolve all dictionary objects we use */
......@@ -315,7 +315,7 @@ static void sip_conf_free(struct rgwp_config * state)
TRACE_ENTRY("%p", state);
CHECK_PARAMS_DO( state, return );
CHECK_FCT_DO( fd_sess_handler_destroy( &state->sess_hdl ), );
CHECK_FCT_DO( fd_sess_handler_destroy( &state->sess_hdl, NULL ), );
nonce_deletelistnonce(state);
CHECK_POSIX_DO(pthread_mutex_destroy(&state->nonce_mutex), /*continue*/);
......
......@@ -58,9 +58,9 @@ static struct as_conf app_sip_conf;
//dictionary of SIP
struct app_sip_dict sip_dict;
int app_sip_default_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act)
int app_sip_default_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act)
{
TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act);
TRACE_ENTRY("%p %p %p %p %p", msg, avp, sess, opaque, act);
return 0;
}
......@@ -178,41 +178,41 @@ int as_entry(char * conffile)
if(as_conf->mode==1)
{
//**Command Codes
// **Command Codes
//MAR
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Multimedia-Auth-Request", &data.command, ENOENT) );
CHECK_FCT( fd_disp_register( app_sip_MAR_cb, DISP_HOW_CC, &data, &app_sip_MAR_hdl ) );
CHECK_FCT( fd_disp_register( app_sip_MAR_cb, DISP_HOW_CC, &data, NULL, &app_sip_MAR_hdl ) );
//RTA
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Registration-Termination-Answer", &data.command, ENOENT) );
CHECK_FCT( fd_disp_register( app_sip_RTA_cb, DISP_HOW_CC, &data, &app_sip_RTA_hdl ) );
CHECK_FCT( fd_disp_register( app_sip_RTA_cb, DISP_HOW_CC, &data, NULL, &app_sip_RTA_hdl ) );
//PPA
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Push-Profile-Answer", &data.command, ENOENT) );
CHECK_FCT( fd_disp_register( app_sip_PPA_cb, DISP_HOW_CC, &data, &app_sip_PPA_hdl ) );
CHECK_FCT( fd_disp_register( app_sip_PPA_cb, DISP_HOW_CC, &data, NULL, &app_sip_PPA_hdl ) );
//LIR
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Location-Info-Request", &data.command, ENOENT) );
CHECK_FCT( fd_disp_register( app_sip_LIR_cb, DISP_HOW_CC, &data, &app_sip_LIR_hdl ) );
CHECK_FCT( fd_disp_register( app_sip_LIR_cb, DISP_HOW_CC, &data, NULL, &app_sip_LIR_hdl ) );
//UAR
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "User-Authorization-Request", &data.command, ENOENT) );
CHECK_FCT( fd_disp_register( app_sip_UAR_cb, DISP_HOW_CC, &data, &app_sip_UAR_hdl ) );
CHECK_FCT( fd_disp_register( app_sip_UAR_cb, DISP_HOW_CC, &data, NULL, &app_sip_UAR_hdl ) );
//SAR
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Server-Assignment-Request", &data.command, ENOENT) );
CHECK_FCT( fd_disp_register( app_sip_SAR_cb, DISP_HOW_CC, &data, &app_sip_SAR_hdl ) );
CHECK_FCT( fd_disp_register( app_sip_SAR_cb, DISP_HOW_CC, &data, NULL, &app_sip_SAR_hdl ) );
}
if(as_conf->mode==2)
{
//LIR
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Location-Info-Request", &data.command, ENOENT) );
CHECK_FCT( fd_disp_register( app_sip_SL_LIR_cb, DISP_HOW_CC, &data, &app_sip_SL_LIR_hdl ) );
CHECK_FCT( fd_disp_register( app_sip_SL_LIR_cb, DISP_HOW_CC, &data, NULL, &app_sip_SL_LIR_hdl ) );
}
//Callback for unexpected messages
CHECK_FCT( fd_disp_register( app_sip_default_cb, DISP_HOW_APPID, &data, &app_sip_default_hdl ) );
CHECK_FCT( fd_disp_register( app_sip_default_cb, DISP_HOW_APPID, &data, NULL, &app_sip_default_hdl ) );
//We start database connection
if(start_mysql_connection())
return EINVAL;
CHECK_FCT(fd_sess_handler_create(&ds_sess_hdl, free));
CHECK_FCT(fd_sess_handler_create(&ds_sess_hdl, free, NULL));
//Creation of thread for Registration Termination
if(pthread_create(&rtr_thread, NULL,rtr_socket, NULL))
......@@ -236,8 +236,8 @@ void fd_ext_fini(void)
{
//TODO:unregister other callbacks
(void) fd_disp_unregister(&app_sip_MAR_hdl);
CHECK_FCT_DO( fd_sess_handler_destroy(&ds_sess_hdl),return);
(void) fd_disp_unregister(&app_sip_MAR_hdl, NULL);
CHECK_FCT_DO( fd_sess_handler_destroy(&ds_sess_hdl, NULL),return);
//We close database connection
......
......@@ -139,17 +139,17 @@ int app_sip_PPR_cb(struct pprsipaor structure);
int ds_entry();
void fd_ext_fini(void);
int app_sip_default_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act);
int app_sip_MAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act);
int app_sip_RTA_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act);
int app_sip_PPA_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act);
int app_sip_LIR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act);
int app_sip_UAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act);
int app_sip_SAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act);
int app_sip_default_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
int app_sip_MAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
int app_sip_RTA_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
int app_sip_PPA_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
int app_sip_LIR_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
int app_sip_UAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
int app_sip_SAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
//Suscriber Locator
int app_sip_SL_LIR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act);
//int app_sip_SL_SAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act);
int app_sip_SL_LIR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act);
//int app_sip_SL_SAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act);
#define SQL_GETPASSWORD "SELECT `password` FROM ds_users WHERE `username` ='%s'"
#define SQL_GETPASSWORD_LEN sizeof(SQL_GETPASSWORD)-2
......
......@@ -36,7 +36,7 @@
#include "app_sip.h"
int app_sip_LIR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act)
int app_sip_LIR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act)
{
TRACE_ENTRY("%p %p %p %p", msg, paramavp, sess, act);
......
......@@ -36,7 +36,7 @@
#include "app_sip.h"
//This callback is specific to SUSCRIBER LOCATOR. We must look for the "serving" SIP server
int app_sip_SL_LIR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act)
int app_sip_SL_LIR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act)
{
TRACE_ENTRY("%p %p %p %p", msg, paramavp, sess, act);
......
......@@ -36,7 +36,7 @@
#include "app_sip.h"
int app_sip_MAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act)
int app_sip_MAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act)
{
struct msg *ans, *qry;
struct avp *avp, *a2, *authdataitem;
......
......@@ -254,7 +254,7 @@ int app_sip_PPR_cb(struct pprsipaor structure)
}
//Called when an PPA arrive
int app_sip_PPA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act)
int app_sip_PPA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act)
{
//TODO: PPA reception
/*
......
......@@ -257,7 +257,7 @@ int app_sip_RTR_cb(struct rtrsipaor structure)
}
//Called when an RTA arrive
int app_sip_RTA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act)
int app_sip_RTA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act)
{
//TODO: RTA reception
/*
......
......@@ -36,7 +36,7 @@
#include "app_sip.h"
int app_sip_SAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act)
int app_sip_SAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act)
{
TRACE_ENTRY("%p %p %p %p", msg, paramavp, sess, act);
......
......@@ -36,7 +36,7 @@
#include "app_sip.h"
int app_sip_UAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act)
int app_sip_UAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, void * opaque, enum disp_action * act)
{
TRACE_ENTRY("%p %p %p %p", msg, paramavp, sess, act);
......
......@@ -66,8 +66,10 @@ static void * myinterp (void * arg)
Py_Main(arg ? 2 : 1, dum);
end:
/* Upon exit, issue the order of terminating to fD */
CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), );
/* Upon exit, issue the order of terminating to fD, if the interpreter was started without a file */
if (!arg) {
CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), );
}
return NULL;
}
......
......@@ -39,17 +39,17 @@
%{
/* store the python callback function here */
static PyObject * py_dispatch_cb = NULL;
static int py_dispatch_cb_n = 0;
/* call it (will be called from a different thread than the interpreter, when message arrives) */
static int call_the_python_dispatch_callback(struct msg **msg, struct avp *avp, struct session *session, enum disp_action *action) {
static int call_the_python_dispatch_callback(struct msg **msg, struct avp *avp, struct session *session, void * pycb, enum disp_action *action) {
PyObject *PyMsg, *PyAvp, *PySess;
PyObject *result = NULL;
PyObject *cb, *result = NULL;
int ret = 0;
if (!py_dispatch_cb)
if (!pycb) {
fd_log_debug("Internal error: missing the callback!\n");
return ENOTSUP;
}
cb = pycb;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
/* Convert the arguments */
......@@ -58,7 +58,7 @@ static int call_the_python_dispatch_callback(struct msg **msg, struct avp *avp,
PySess = SWIG_NewPointerObj((void *) session, SWIGTYPE_p_session, 0 );
/* Call the function */
result = PyEval_CallFunction(py_dispatch_cb, "(OOO)", PyMsg, PyAvp, PySess);
result = PyEval_CallFunction(cb, "(OOO)", PyMsg, PyAvp, PySess);
/* The result is supposedly composed of: [ ret, *msg, *action ] */
if ((result == NULL) || (!PyList_Check(result)) || (PyList_Size(result) != 3)) {
......@@ -107,15 +107,10 @@ struct disp_hdl {
disp_hdl(PyObject * PyCb, enum disp_how how, struct disp_when * when) {
struct disp_hdl * hdl = NULL;
int ret;
if (py_dispatch_cb && (py_dispatch_cb != PyCb)) {
DI_ERROR(EINVAL, PyExc_SyntaxError, "Only one dispatch callback is supported at the moment in this extension\n.");
return NULL;
}
py_dispatch_cb = PyCb;
py_dispatch_cb_n += 1;
Py_XINCREF(py_dispatch_cb);
ret = fd_disp_register ( call_the_python_dispatch_callback, how, when, &hdl );
Py_XINCREF(PyCb);
ret = fd_disp_register ( call_the_python_dispatch_callback, how, when, PyCb, &hdl );
if (ret != 0) {
DI_ERROR(ret, NULL, NULL);
return NULL;
......@@ -124,15 +119,12 @@ struct disp_hdl {
}
~disp_hdl() {
struct disp_hdl * hdl = self;
int ret = fd_disp_unregister(&hdl);
PyObject * cb = NULL;
int ret = fd_disp_unregister(&hdl, (void *)&cb);
if (ret != 0) {
DI_ERROR(ret, NULL, NULL);
}
/* Now free the callback */
Py_XDECREF(py_dispatch_cb);
py_dispatch_cb_n -= 1;
if (!py_dispatch_cb_n)
py_dispatch_cb = NULL;
Py_XDECREF(cb);
return;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment