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