comparison extensions/test_as/test_as.c @ 1347:2119c8c0c219

test_as: new extension that auto-replies to Abort-Session-Requests Does not fill in any relevant data, just returns a success.
author Thomas Klausner <tk@giga.or.at>
date Sun, 12 May 2019 10:36:39 +0200
parents
children
comparison
equal deleted inserted replaced
1346:25f86f4cdde8 1347:2119c8c0c219
1 /**********************************************************************************************************
2 * Software License Agreement(BSD License) *
3 * Author: Thomas Klausner <tk@giga.or.at> *
4 * *
5 * Copyright(c) 2019, Thomas Klausner *
6 * All rights reserved. *
7 * *
8 * Written under contract by Effortel Technologies SA, http://effortel.com/ *
9 * *
10 * Redistribution and use of this software in source and binary forms, with or without modification, are *
11 * permitted provided that the following conditions are met: *
12 * *
13 * * Redistributions of source code must retain the above *
14 * copyright notice, this list of conditions and the *
15 * following disclaimer. *
16 * *
17 * * Redistributions in binary form must reproduce the above *
18 * copyright notice, this list of conditions and the *
19 * following disclaimer in the documentation and/or other *
20 * materials provided with the distribution. *
21 * *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
24 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
25 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT *
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
28 * TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
30 **********************************************************************************************************/
31
32 /* This extension simply receives ASR and sends ASA after displaying the content, but does not store any data */
33
34 #include <freeDiameter/extension.h>
35
36 struct disp_hdl *asr_handler_hdl;
37
38 static int asr_handler(struct msg ** msg, struct avp * avp, struct session * sess, void * data, enum disp_action * act)
39 {
40 struct msg_hdr *hdr = NULL;
41
42 TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act);
43
44 if(msg == NULL)
45 return EINVAL;
46
47 CHECK_FCT(fd_msg_hdr(*msg, &hdr));
48 if(hdr->msg_flags & CMD_FLAG_REQUEST) {
49 /* Request received, answer it */
50 struct msg *answer;
51 os0_t s;
52 size_t sl;
53
54 /* Create the answer message */
55 CHECK_FCT(fd_msg_new_answer_from_req(fd_g_config->cnf_dict, msg, 0));
56 answer = *msg;
57
58 /* TODO copy/fill in AVPs into the answer */
59 /* TODO make result code configurable, depending on an AVP value? */
60 CHECK_FCT(fd_msg_rescode_set(answer, "DIAMETER_SUCCESS", NULL, NULL, 1));
61
62 fd_log_notice("--------------Received the following Abort Session Request:--------------");
63
64 CHECK_FCT(fd_sess_getsid(sess, &s, &sl));
65 fd_log_notice("Session: %.*s",(int)sl, s);
66
67 fd_log_notice("----------------------------------------------------------------------");
68
69 /* Send the answer */
70 CHECK_FCT(fd_msg_send(msg, NULL, NULL));
71
72 } else {
73 /* We received an answer message, just discard it */
74 CHECK_FCT(fd_msg_free(*msg));
75 *msg = NULL;
76 }
77
78 return 0;
79 }
80
81 /* entry hook: register callback */
82 static int as_entry(char * conffile)
83 {
84 struct disp_when data;
85
86 TRACE_ENTRY("%p", conffile);
87
88 memset(&data, 0, sizeof(data));
89
90 /* Advertise the support for the Diameter Abort Session application in the peer */
91 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Credit Control Application", &data.app, ENOENT) );
92 CHECK_FCT( fd_disp_app_support ( data.app, NULL, 1, 0 ) );
93
94 /* register handler for ASR */
95 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Abort-Session-Request", &data.command, ENOENT) );
96 CHECK_FCT( fd_disp_register( asr_handler, DISP_HOW_CC, &data, NULL, &asr_handler_hdl ) );
97
98 return 0;
99 }
100
101 EXTENSION_ENTRY("test_as", as_entry);
"Welcome to our mercurial repository"