comparison extensions/test_cc/test_cc.c @ 1346:25f86f4cdde8

test_cc: new extension that auto-replies to Credit-Control-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:21 +0200
parents
children 0d951a67648b
comparison
equal deleted inserted replaced
1345:51a0521cd065 1346:25f86f4cdde8
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 CCR and sends CCA after displaying the content, but does not store any data */
33
34 #include <freeDiameter/extension.h>
35
36 struct disp_hdl *ccr_handler_hdl;
37
38 static int ccr_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 /* TODO copy/fill in AVPs in the answer */
58 /* TODO make result configurable (depending on an AVP?) */
59 CHECK_FCT(fd_msg_rescode_set(answer, "DIAMETER_SUCCESS", NULL, NULL, 1));
60
61 fd_log_notice("--------------Received the following Credit Control Request:--------------");
62
63 CHECK_FCT(fd_sess_getsid(sess, &s, &sl));
64 fd_log_notice("Session: %.*s",(int)sl, s);
65
66 fd_log_notice("----------------------------------------------------------------------");
67
68 /* Send the answer */
69 CHECK_FCT(fd_msg_send(msg, NULL, NULL));
70
71 } else {
72 /* We received an answer message, just discard it */
73 CHECK_FCT(fd_msg_free(*msg));
74 *msg = NULL;
75 }
76
77 return 0;
78 }
79
80 /* entry hook: register callback */
81 static int cc_entry(char * conffile)
82 {
83 struct disp_when data;
84
85 TRACE_ENTRY("%p", conffile);
86
87 memset(&data, 0, sizeof(data));
88
89 /* Advertise the support for the Diameter Credit Control application in the peer */
90 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Credit Control Application", &data.app, ENOENT) );
91 CHECK_FCT( fd_disp_app_support ( data.app, NULL, 1, 0 ) );
92
93 /* register handler for CCR */
94 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Credit-Control-Request", &data.command, ENOENT) );
95 CHECK_FCT( fd_disp_register( ccr_handler, DISP_HOW_CC, &data, NULL, &ccr_handler_hdl ) );
96
97 return 0;
98 }
99
100 EXTENSION_ENTRY("test_cc", cc_entry);
"Welcome to our mercurial repository"