Brian Waters | 13d9601 | 2017-12-08 16:53:31 -0600 | [diff] [blame] | 1 | /********************************************************************************************************* |
| 2 | * Software License Agreement (BSD License) * |
| 3 | * Author: Sebastien Decugis <sdecugis@freediameter.net> * |
| 4 | * * |
| 5 | * Copyright (c) 2013, WIDE Project and NICT * |
| 6 | * All rights reserved. * |
| 7 | * * |
| 8 | * Redistribution and use of this software in source and binary forms, with or without modification, are * |
| 9 | * permitted provided that the following conditions are met: * |
| 10 | * * |
| 11 | * * Redistributions of source code must retain the above * |
| 12 | * copyright notice, this list of conditions and the * |
| 13 | * following disclaimer. * |
| 14 | * * |
| 15 | * * Redistributions in binary form must reproduce the above * |
| 16 | * copyright notice, this list of conditions and the * |
| 17 | * following disclaimer in the documentation and/or other * |
| 18 | * materials provided with the distribution. * |
| 19 | * * |
| 20 | * * Neither the name of the WIDE Project or NICT nor the * |
| 21 | * names of its contributors may be used to endorse or * |
| 22 | * promote products derived from this software without * |
| 23 | * specific prior written permission of WIDE Project and * |
| 24 | * NICT. * |
| 25 | * * |
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
| 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
| 28 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
| 29 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
| 30 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
| 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
| 32 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
| 33 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
| 34 | *********************************************************************************************************/ |
| 35 | |
| 36 | /* Install the dictionary objects */ |
| 37 | |
| 38 | #include "test_app.h" |
| 39 | |
| 40 | struct dict_object * ta_vendor = NULL; |
| 41 | struct dict_object * ta_appli = NULL; |
| 42 | struct dict_object * ta_cmd_r = NULL; |
| 43 | struct dict_object * ta_cmd_a = NULL; |
| 44 | struct dict_object * ta_avp = NULL; |
| 45 | struct dict_object * ta_avp_long = NULL; |
| 46 | |
| 47 | struct dict_object * ta_sess_id = NULL; |
| 48 | struct dict_object * ta_origin_host = NULL; |
| 49 | struct dict_object * ta_origin_realm = NULL; |
| 50 | struct dict_object * ta_dest_host = NULL; |
| 51 | struct dict_object * ta_dest_realm = NULL; |
| 52 | struct dict_object * ta_user_name = NULL; |
| 53 | struct dict_object * ta_res_code = NULL; |
| 54 | |
| 55 | int ta_dict_init(void) |
| 56 | { |
| 57 | TRACE_DEBUG(FULL, "Initializing the dictionary for test"); |
| 58 | |
| 59 | /* Create the Test Vendor */ |
| 60 | { |
| 61 | struct dict_vendor_data data; |
| 62 | data.vendor_id = ta_conf->vendor_id; |
| 63 | data.vendor_name = "app_test vendor"; |
| 64 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_VENDOR, &data, NULL, &ta_vendor)); |
| 65 | } |
| 66 | |
| 67 | /* Create the Test Application */ |
| 68 | { |
| 69 | struct dict_application_data data; |
| 70 | data.application_id = ta_conf->appli_id; |
| 71 | data.application_name = "app_test application"; |
| 72 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_APPLICATION, &data, ta_vendor, &ta_appli)); |
| 73 | } |
| 74 | |
| 75 | /* Create the Test-Request & Test-Answer commands */ |
| 76 | { |
| 77 | struct dict_cmd_data data; |
| 78 | data.cmd_code = ta_conf->cmd_id; |
| 79 | data.cmd_name = "Test-Request"; |
| 80 | data.cmd_flag_mask = CMD_FLAG_PROXIABLE | CMD_FLAG_REQUEST; |
| 81 | data.cmd_flag_val = CMD_FLAG_PROXIABLE | CMD_FLAG_REQUEST; |
| 82 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_COMMAND, &data, ta_appli, &ta_cmd_r)); |
| 83 | data.cmd_name = "Test-Answer"; |
| 84 | data.cmd_flag_val = CMD_FLAG_PROXIABLE; |
| 85 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_COMMAND, &data, ta_appli, &ta_cmd_a)); |
| 86 | } |
| 87 | |
| 88 | /* Create the Test AVP */ |
| 89 | { |
| 90 | struct dict_avp_data data; |
| 91 | data.avp_code = ta_conf->avp_id; |
| 92 | data.avp_vendor = ta_conf->vendor_id; |
| 93 | data.avp_name = "Test-AVP"; |
| 94 | data.avp_flag_mask = AVP_FLAG_VENDOR; |
| 95 | data.avp_flag_val = AVP_FLAG_VENDOR; |
| 96 | data.avp_basetype = AVP_TYPE_INTEGER32; |
| 97 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_AVP, &data, NULL, &ta_avp)); |
| 98 | } |
| 99 | |
| 100 | /* Create the Test Payload AVP */ |
| 101 | if (ta_conf->long_avp_id) { |
| 102 | struct dict_avp_data data; |
| 103 | data.avp_code = ta_conf->long_avp_id; |
| 104 | data.avp_vendor = ta_conf->vendor_id; |
| 105 | data.avp_name = "Test-Payload-AVP"; |
| 106 | data.avp_flag_mask = AVP_FLAG_VENDOR; |
| 107 | data.avp_flag_val = AVP_FLAG_VENDOR; |
| 108 | data.avp_basetype = AVP_TYPE_OCTETSTRING; |
| 109 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_AVP, &data, NULL, &ta_avp_long)); |
| 110 | } |
| 111 | |
| 112 | /* Now resolve some other useful AVPs */ |
| 113 | CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &ta_sess_id, ENOENT) ); |
| 114 | CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Origin-Host", &ta_origin_host, ENOENT) ); |
| 115 | CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Origin-Realm", &ta_origin_realm, ENOENT) ); |
| 116 | CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Host", &ta_dest_host, ENOENT) ); |
| 117 | CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Realm", &ta_dest_realm, ENOENT) ); |
| 118 | CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "User-Name", &ta_user_name, ENOENT) ); |
| 119 | CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Result-Code", &ta_res_code, ENOENT) ); |
| 120 | |
| 121 | /* Create the rules for Test-Request and Test-Answer */ |
| 122 | { |
| 123 | struct dict_rule_data data; |
| 124 | data.rule_min = 1; |
| 125 | data.rule_max = 1; |
| 126 | |
| 127 | /* Session-Id is in first position */ |
| 128 | data.rule_avp = ta_sess_id; |
| 129 | data.rule_position = RULE_FIXED_HEAD; |
| 130 | data.rule_order = 1; |
| 131 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_r, NULL)); |
| 132 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_a, NULL)); |
| 133 | |
| 134 | data.rule_position = RULE_REQUIRED; |
| 135 | /* Test-AVP is mandatory */ |
| 136 | data.rule_avp = ta_avp; |
| 137 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_r, NULL)); |
| 138 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_a, NULL)); |
| 139 | |
| 140 | /* idem for Origin Host and Realm */ |
| 141 | data.rule_avp = ta_origin_host; |
| 142 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_r, NULL)); |
| 143 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_a, NULL)); |
| 144 | |
| 145 | data.rule_avp = ta_origin_realm; |
| 146 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_r, NULL)); |
| 147 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_a, NULL)); |
| 148 | |
| 149 | /* And Result-Code is mandatory for answers only */ |
| 150 | data.rule_avp = ta_res_code; |
| 151 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_a, NULL)); |
| 152 | |
| 153 | /* And Destination-Realm for requests only */ |
| 154 | data.rule_avp = ta_dest_realm; |
| 155 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_r, NULL)); |
| 156 | |
| 157 | /* And Destination-Host optional for requests only */ |
| 158 | data.rule_position = RULE_OPTIONAL; |
| 159 | data.rule_min = 0; |
| 160 | data.rule_avp = ta_dest_host; |
| 161 | CHECK_FCT(fd_dict_new( fd_g_config->cnf_dict, DICT_RULE, &data, ta_cmd_r, NULL)); |
| 162 | |
| 163 | } |
| 164 | |
| 165 | return 0; |
| 166 | } |