Mercurial > hg > waaad
view extensions/app_test/atst_serv.c @ 289:6537213b55b5
Simpified dispatch callbacks prototype and behavior
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Mon, 22 Dec 2008 12:29:49 +0900 |
parents | a51b0c820c5b |
children | 088ef7db9e52 |
line wrap: on
line source
/********************************************************************************************************* * Software License Agreement (BSD License) * * Author: Sebastien Decugis <sdecugis@nict.go.jp> * * * * Copyright (c) 2008, 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. * *********************************************************************************************************/ /* Install the dispatch callbacks */ #include "app_test.h" static disp_cb_hdl_t * hdl_fb = NULL; /* handler for fallback cb */ static disp_cb_hdl_t * hdl_tr = NULL; /* handler for Test-Request req cb */ /* Default callback for the application. */ static int fb_cb( msg_t ** msg, msg_avp_t * avp ) { /* This CB should never be called */ TRACE_ENTRY("%p %p", msg, avp); log_error("Unexpected message received!\n"); return ENOTSUP; } /* Callback for incoming Test-Request messages */ static int tr_cb( msg_t ** msg, msg_avp_t * avp ) { msg_t * ans; TRACE_ENTRY("%p %p", msg, avp); if (msg == NULL) return EINVAL; ans = *msg; /* Create answer header */ CHECK( msg_new_answ(&ans, MSGFL_FROM_TEMPLATE) ); /* Set the Session-Id AVP */ { msg_avp_t * src = NULL; msg_avp_t * dst = NULL; msg_avp_data_t * data = NULL; CHECK( msg_search_avp(*msg, sess_id, &src) ); CHECK( msg_search_avp(ans, sess_id, &dst) ); CHECK( msg_avp_data( src, &data ) ); CHECK( msg_avp_setvalue( dst, data->avp_data) ); } /* Set the Test-AVP AVP */ { msg_avp_t * src = NULL; msg_avp_t * dst = NULL; msg_avp_data_t * data = NULL; CHECK( msg_search_avp(*msg, atst_avp, &src) ); CHECK( msg_search_avp(ans, atst_avp, &dst) ); CHECK( msg_avp_data( src, &data ) ); CHECK( msg_avp_setvalue( dst, data->avp_data) ); } /* Set the Origin-Host AVP */ { msg_avp_t * dst = NULL; avp_value_t data; data.os.data = (unsigned char *)(g_pconf->diameter_identity); data.os.len = strlen(g_pconf->diameter_identity); CHECK( msg_search_avp(ans, origin_host, &dst) ); CHECK( msg_avp_setvalue( dst, &data) ); } /* Set the Origin-Realm AVP */ { msg_avp_t * dst = NULL; avp_value_t data; data.os.data = (unsigned char *)(g_pconf->diameter_realm); data.os.len = strlen(g_pconf->diameter_realm); CHECK( msg_search_avp(ans, origin_realm, &dst) ); CHECK( msg_avp_setvalue( dst, &data) ); } /* Set the Result-Code AVP */ { msg_avp_t * dst = NULL; avp_value_t data; data.u32 = 2001; /* Success */ CHECK( msg_search_avp(ans, res_code, &dst) ); CHECK( msg_avp_setvalue( dst, &data) ); } /* Send the answer */ CHECK( msg_send( &ans, NULL, NULL ) ); *msg = NULL; return 0; } int serv_init(void) { disp_reg_val_t data; TRACE_DEBUG(FULL, "Initializing dispatch callbacks for test"); data.flags = 3; data.app_id = atst_appli; data.command = atst_cmd_r; /* fallback CB if command != Test-Request received */ CHECK( disp_register( fb_cb, DISP_REG_APPID, &data, &hdl_fb ) ); /* Now specific handler for Test-Request */ CHECK( disp_register( tr_cb, DISP_REG_CC, &data, &hdl_tr ) ); return 0; } void serv_fini(void) { if (hdl_fb) { (void) disp_unregister(hdl_fb); } if (hdl_tr) { (void) disp_unregister(hdl_tr); } return; }