peering.c

Go to the documentation of this file.
00001 /* 
00002  * Radius based peering module
00003  *
00004  * Copyright (C) 2008 Juha Heinanen
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00040 #include "../../sr_module.h"
00041 #include "../../mem/mem.h"
00042 #include "../../config.h"
00043 #include "../../lib/kcore/radius.h"
00044 #include "verify.h"
00045 
00046 MODULE_VERSION
00047 
00048 struct attr attrs[A_MAX];
00049 struct val vals[V_MAX];
00050 void *rh;
00051 
00052 static int mod_init(void);         /* Module initialization function */
00053 
00054 
00055 /*
00056  * Module parameter variables
00057  */
00058 static char* radius_config = DEFAULT_RADIUSCLIENT_CONF;
00059 int verify_destination_service_type = -1;
00060 int verify_source_service_type = -1;
00061 
00062 /*
00063  * Exported functions
00064  */
00065 static cmd_export_t cmds[] = {
00066     {"verify_destination", (cmd_function)verify_destination, 0, 0, 0,
00067      REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
00068     {"verify_source", (cmd_function)verify_source, 0, 0, 0,
00069      REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
00070     {0, 0, 0, 0, 0, 0}
00071 };
00072 
00073 
00074 /*
00075  * Exported parameters
00076  */
00077 static param_export_t params[] = {
00078     {"radius_config", STR_PARAM, &radius_config},
00079     {"verify_destination_service_type", INT_PARAM,
00080      &verify_destination_service_type},
00081     {"verify_source_service_type", INT_PARAM,
00082      &verify_source_service_type},
00083     {0, 0, 0}
00084 };
00085 
00086 
00087 /*
00088  * Module interface
00089  */
00090 struct module_exports exports = {
00091     "peering", 
00092     DEFAULT_DLFLAGS, /* dlopen flags */
00093     cmds,       /* Exported functions */
00094     params,     /* Exported parameters */
00095     0,          /* exported statistics */
00096     0,          /* exported MI functions */
00097     0,          /* exported pseudo-variables */
00098     0,          /* extra processes */
00099     mod_init,   /* module initialization function */
00100     0,          /* response function */
00101     0,          /* destroy function */
00102     0           /* child initialization function */
00103 };
00104 
00105 
00106 /*
00107  * Module initialization function
00108  */
00109 static int mod_init(void)
00110 {
00111     memset(attrs, 0, sizeof(attrs));
00112     memset(vals, 0, sizeof(vals));
00113     attrs[A_USER_NAME].n = "User-Name";
00114     attrs[A_SIP_URI_USER].n = "SIP-URI-User";
00115     attrs[A_SIP_FROM_TAG].n = "SIP-From-Tag";
00116     attrs[A_SIP_CALL_ID].n = "SIP-Call-Id";
00117     attrs[A_SIP_REQUEST_HASH].n = "SIP-Request-Hash";
00118     attrs[A_SIP_AVP].n = "SIP-AVP";
00119     attrs[A_SERVICE_TYPE].n = "Service-Type";
00120     vals[V_SIP_VERIFY_DESTINATION].n = "Sip-Verify-Destination";
00121     vals[V_SIP_VERIFY_SOURCE].n = "Sip-Verify-Source";
00122 
00123     if ((rh = rc_read_config(radius_config)) == NULL) {
00124         LM_ERR("error opening configuration file\n");
00125         return -1;
00126     }
00127 
00128     if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary")) != 0) {
00129         LM_ERR("error opening dictionary file\n");
00130         return -2;
00131     }
00132 
00133     INIT_AV(rh, attrs, A_MAX, vals, V_MAX, "peering", -3, -4);
00134 
00135     if (verify_destination_service_type != -1) {
00136         vals[V_SIP_VERIFY_DESTINATION].v = 
00137                 verify_destination_service_type;
00138     }
00139 
00140     if (verify_source_service_type != -1) {
00141         vals[V_SIP_VERIFY_SOURCE].v = verify_source_service_type;
00142     }
00143 
00144     return 0;
00145 }