view extensions/radius_gw/sub_sample.c @ 376:98806d0e175f

Unified debug messages when loading extensions
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 26 May 2009 16:06:03 +0900
parents ea7c8e975662
children 03b512313cc1
line wrap: on
line source

/*********************************************************************************************************
* Software License Agreement (BSD License)                                                               *
* Author: Sebastien Decugis <sdecugis@nict.go.jp>							 *
*													 *
* Copyright (c) 2009, WIDE Project and NICT								 *
* All rights reserved.											 *
* 													 *
* Redistribution and use of this software in source and binary forms, with or without modification, are  *
* permitted provided that the following conditions are met:						 *
* 													 *
* * Redistributions of source code must retain the above 						 *
*   copyright notice, this list of conditions and the 							 *
*   following disclaimer.										 *
*    													 *
* * Redistributions in binary form must reproduce the above 						 *
*   copyright notice, this list of conditions and the 							 *
*   following disclaimer in the documentation and/or other						 *
*   materials provided with the distribution.								 *
* 													 *
* * Neither the name of the WIDE Project or NICT nor the 						 *
*   names of its contributors may be used to endorse or 						 *
*   promote products derived from this software without 						 *
*   specific prior written permission of WIDE Project and 						 *
*   NICT.												 *
* 													 *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
*********************************************************************************************************/

/* Sample sub extension for debug */

#define IN_EXTENSION
#define DEFINE_DEBUG_MACRO	sub_sample
#define DECLARE_API_POINTERS
#include <waaad/waaad.h>

#include "rg_common.h"

int sub_sample_verbosity = 2;

struct rga_conf_state {
	char * conffile;
};

static struct rga_conf_state * sample_conf_parse(char * conffile)
{
	struct rga_conf_state * ret = NULL;
	
	TRACE_ENTRY("%p", conffile);
	
	CHECK_MALLOC_DO( ret = malloc(sizeof(struct rga_conf_state)), return NULL );
	
	ret->conffile = conffile ?: "(NULL)";
	
	TRACE_DEBUG(INFO, "Sub extension Sample initialized");
	return ret;
}

static void sample_conf_free(struct rga_conf_state * cs)
{
	TRACE_ENTRY("%p", cs);
	CHECK_PARAMS_DO( cs, );
	free(cs);
	return;
}

static int sample_rad_req(struct rga_conf_state * cs, sess_id_t ** session, struct radius_msg * rad_req, struct radius_msg ** rad_ans, msg_t ** diam_fw )
{
	TRACE_ENTRY("%p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw);
	CHECK_PARAMS(cs);
	TRACE_DEBUG(INFO, "sample(%s): in rga_rad_req_cb...", cs->conffile);
	return 0;
}

static int sample_diam_ans(struct rga_conf_state * cs, sess_id_t ** session, msg_t ** diam_ans, struct radius_msg ** rad_fw )
{
	TRACE_ENTRY("%p %p %p %p", cs, session, diam_ans, rad_fw);
	CHECK_PARAMS(cs);
	TRACE_DEBUG(INFO, "sample(%s): in rga_diam_ans_cb...", cs->conffile);
	return 0;
}

int rga_register(int version, waaad_api_t * waaad_api, struct radius_gw_api * api)
{
	TRACE_ENTRY("%d %p %p", version, waaad_api, api);
	CHECK_PARAMS( waaad_api && api );
	
	if (version != RADIUS_GW_API_VER) {
		log_error("ABI version mismatch, please recompile this extension (%s)\n", __FILE__);
		return EINVAL;
	}
	
	/* Required to use the waaad api from this sub-extension: */
	EXTENSION_API_INIT_INTERN( API_MODULE_ALL, "sub_sample", waaad_api );
	
	/* Initialize the radius_gw api callbacks */
	api->rga_conf_parse_cb = sample_conf_parse;
	api->rga_conf_free_cb  = sample_conf_free;
	api->rga_rad_req_cb    = sample_rad_req;
	api->rga_diam_ans_cb   = sample_diam_ans;
	
	/* We're done, we must not initialize any state here since the extension must be re-entrant, but in sample_conf_parse */
	return 0;
}
"Welcome to our mercurial repository"