# HG changeset patch # User Alexandre Westfahl # Date 1280295288 -32400 # Node ID 0d08a9ab22125108fc5ff37eaec917e4964ae759 # Parent 533188d2e6cca278bf0cc01fda28f0042b96f299 Corrected name mistakes on app_sip diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/CMakeLists.txt --- a/extensions/app_sip/CMakeLists.txt Wed Jul 28 03:14:11 2010 +0900 +++ b/extensions/app_sip/CMakeLists.txt Wed Jul 28 14:34:48 2010 +0900 @@ -5,18 +5,18 @@ INCLUDE_DIRECTORIES(${MySQL_INCLUDE_DIR}) # Parser files -BISON_FILE(diamsip.y) -FLEX_FILE(diamsip.l) -SET_SOURCE_FILES_PROPERTIES(lex.diamsip.c diamsip.tab.c PROPERTIES COMPILE_FLAGS "-I ${CMAKE_CURRENT_SOURCE_DIR}") +BISON_FILE(app_sip.y) +FLEX_FILE(app_sip.l) +SET_SOURCE_FILES_PROPERTIES(lex.app_sip.c app_sip.tab.c PROPERTIES COMPILE_FLAGS "-I ${CMAKE_CURRENT_SOURCE_DIR}") # List of source files SET( DIAM_SIP_SRC - lex.diamsip.c - diamsip.tab.c - diamsip.tab.h - diamsip.c - diamsip.h - libdiamsip.c + lex.app_sip.c + app_sip.tab.c + app_sip.tab.h + app_sip.c + app_sip.h + libapp_sip.c md5.c multimediaauth.c registrationtermination.c diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/app_sip.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/app_sip/app_sip.c Wed Jul 28 14:34:48 2010 +0900 @@ -0,0 +1,252 @@ +/********************************************************************************************************* +* Software License Agreement (BSD License) * +* Author: Alexandre Westfahl * +* * +* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * +* * +* All rights reserved. * +* * +* Redistribution and use of this software in source and binary forms, with or without modification, are * +* permitted provided that the following conditions are met: * +* * +* * Redistributions of source code must retain the above * +* copyright notice, this list of conditions and the * +* following disclaimer. * +* * +* * Redistributions in binary form must reproduce the above * +* copyright notice, this list of conditions and the * +* following disclaimer in the documentation and/or other * +* materials provided with the distribution. * +* * +* * Neither the name of the Teraoka Laboratory nor the * +* names of its contributors may be used to endorse or * +* promote products derived from this software without * +* specific prior written permission of Teraoka Laboratory * +* * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * +* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * +* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +*********************************************************************************************************/ +#include "app_sip.h" + +//Diameter-SIP server +struct disp_hdl * app_sip_MAR_hdl=NULL; +struct disp_hdl * app_sip_LIR_hdl=NULL; +struct disp_hdl * app_sip_UAR_hdl=NULL; +struct disp_hdl * app_sip_SAR_hdl=NULL; +struct disp_hdl * app_sip_PPA_hdl=NULL; +struct disp_hdl * app_sip_RTA_hdl=NULL; + +//Suscriber Locator +struct disp_hdl * app_sip_SL_LIR_hdl=NULL; + + + +struct disp_hdl * app_sip_default_hdl=NULL; +struct session_handler * ds_sess_hdl; + +//configuration stucture +struct as_conf * as_conf=NULL; +static struct as_conf app_sip_conf; + +//dictionary of SIP +struct app_sip_dict sip_dict; + +int app_sip_default_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act) +{ + TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act); + + return 0; +} + +void dump_config() +{ + TRACE_DEBUG(FULL,"***Configuration of Diameter-SIP extension***"); + TRACE_DEBUG(FULL,"# mode: *%d*",as_conf->mode); + TRACE_DEBUG(FULL,"# datasource: *%d*",as_conf->datasource); + TRACE_DEBUG(FULL,"# mysql_login: *%s*",as_conf->mysql_login); + TRACE_DEBUG(FULL,"# mysql_password: *%s*",as_conf->mysql_password); + TRACE_DEBUG(FULL,"# mysql_database: *%s*",as_conf->mysql_database); + TRACE_DEBUG(FULL,"# mysql_server: *%s*",as_conf->mysql_server); + TRACE_DEBUG(FULL,"# mysql_port: *%d*",as_conf->mysql_port); + TRACE_DEBUG(FULL,"# mysql_port: *%d*",as_conf->mysql_prefix); + TRACE_DEBUG(FULL,"***End of Diameter-SIP configuration extension***"); +} + +static int as_conf_init(void) +{ + as_conf=&app_sip_conf; + //memset(app_sip_conf, 0, sizeof(struct as_conf)); + + + return 0; +} + +/* entry point */ +int as_entry(char * conffile) +{ + TRACE_ENTRY("%p", conffile); + + struct dict_object * app=NULL; + struct disp_when data; + pthread_t rtr_thread, ppr_thread; + + /* Initialize configuration */ + CHECK_FCT( as_conf_init() ); + + + //We parse the configuration file + if (conffile != NULL) { + CHECK_FCT( as_conf_handle(conffile) ); + } + else + { + TRACE_DEBUG(INFO, "We need a configuration file for Diameter-SIP extension. See doc/ for an example."); + } + + //TODO: replace by configuration file!! + strcpy(as_conf->mysql_prefix,"as_"); + + //We can dump the configuration extracted from app_sip.conf + //dump_config(); + + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Session Initiation Protocol (SIP) Application", &app, ENOENT) ); + CHECK_FCT( fd_disp_app_support ( app, NULL, 1, 0 ) ); + + + + //We set usefull AVPs + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Session-State", &sip_dict.Auth_Session_State, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Application-Id", &sip_dict.Auth_Application_Id, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Host", &sip_dict.Destination_Host, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Realm", &sip_dict.Destination_Realm, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &sip_dict.Session_Id, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Redirect-Host", &sip_dict.Redirect_Host, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Redirect-Host-Usage", &sip_dict.Redirect_Host_Usage, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Auth-Data-Item", &sip_dict.SIP_Auth_Data_Item, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authorization", &sip_dict.SIP_Authorization, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authenticate", &sip_dict.SIP_Authenticate, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Number-Auth-Items", &sip_dict.SIP_Number_Auth_Items, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authentication-Scheme", &sip_dict.SIP_Authentication_Scheme, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authentication-Info", &sip_dict.SIP_Authentication_Info, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Server-URI", &sip_dict.SIP_Server_URI, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Server-Capabilities", &sip_dict.SIP_Server_Capabilities, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Mandatory-Capability", &sip_dict.SIP_Mandatory_Capability, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Optional-Capability", &sip_dict.SIP_Optional_Capability, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Method", &sip_dict.SIP_Method, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-AOR", &sip_dict.SIP_AOR, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Deregistration-Reason", &sip_dict.SIP_Deregistration_Reason, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Reason-Code", &sip_dict.SIP_Reason_Code, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Reason-Info", &sip_dict.SIP_Reason_Info, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Accounting-Information", &sip_dict.SIP_Accounting_Information, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Accounting-Server-URI", &sip_dict.SIP_Accounting_Server_URI, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Credit-Control-Server-URI", &sip_dict.SIP_Credit_Control_Server_URI, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Server-Assignment-Type", &sip_dict.SIP_Server_Assignment_Type, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Item-Number", &sip_dict.SIP_Item_Number, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Authorization-Type", &sip_dict.SIP_User_Authorization_Type, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Supported-User-Data-Type", &sip_dict.SIP_Supported_User_Data_Type, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Data", &sip_dict.SIP_User_Data, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Data-Type", &sip_dict.SIP_User_Data_Type, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Data-Contents", &sip_dict.SIP_User_Data_Contents, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Data-Already-Available", &sip_dict.SIP_User_Data_Already_Available, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Visited-Network-Id", &sip_dict.SIP_Visited_Network_Id, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Realm", &sip_dict.Digest_Realm, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-URI", &sip_dict.Digest_URI, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Nonce", &sip_dict.Digest_Nonce, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-CNonce", &sip_dict.Digest_CNonce, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Method", &sip_dict.Digest_Method, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Nonce-Count", &sip_dict.Digest_Nonce_Count, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Realm", &sip_dict.Digest_Realm, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Response", &sip_dict.Digest_Response, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Response-Auth", &sip_dict.Digest_Response_Auth, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Username", &sip_dict.Digest_Username, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Algorithm", &sip_dict.Digest_Algorithm, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-QoP", &sip_dict.Digest_QOP, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "User-Name", &sip_dict.User_Name, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-HA1", &sip_dict.Digest_HA1, ENOENT) ); + + + //Register Application + memset(&data, 0, sizeof(data)); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Session Initiation Protocol (SIP) Application", &data.app, ENOENT) ); + + if(as_conf->mode==1) + { + //**Command Codes + //MAR + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Multimedia-Auth-Request", &data.command, ENOENT) ); + CHECK_FCT( fd_disp_register( app_sip_MAR_cb, DISP_HOW_CC, &data, &app_sip_MAR_hdl ) ); + //RTA + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Registration-Termination-Answer", &data.command, ENOENT) ); + CHECK_FCT( fd_disp_register( app_sip_RTA_cb, DISP_HOW_CC, &data, &app_sip_RTA_hdl ) ); + //PPA + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Push-Profile-Answer", &data.command, ENOENT) ); + CHECK_FCT( fd_disp_register( app_sip_PPA_cb, DISP_HOW_CC, &data, &app_sip_PPA_hdl ) ); + //LIR + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Location-Info-Request", &data.command, ENOENT) ); + CHECK_FCT( fd_disp_register( app_sip_LIR_cb, DISP_HOW_CC, &data, &app_sip_LIR_hdl ) ); + //UAR + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "User-Authorization-Request", &data.command, ENOENT) ); + CHECK_FCT( fd_disp_register( app_sip_UAR_cb, DISP_HOW_CC, &data, &app_sip_UAR_hdl ) ); + //SAR + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Server-Assignment-Request", &data.command, ENOENT) ); + CHECK_FCT( fd_disp_register( app_sip_SAR_cb, DISP_HOW_CC, &data, &app_sip_SAR_hdl ) ); + } + if(as_conf->mode==2) + { + //LIR + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Location-Info-Request", &data.command, ENOENT) ); + CHECK_FCT( fd_disp_register( app_sip_SL_LIR_cb, DISP_HOW_CC, &data, &app_sip_SL_LIR_hdl ) ); + } + //Callback for unexpected messages + CHECK_FCT( fd_disp_register( app_sip_default_cb, DISP_HOW_APPID, &data, &app_sip_default_hdl ) ); + + + //We start database connection + if(start_mysql_connection()) + return EINVAL; + + CHECK_FCT(fd_sess_handler_create(&ds_sess_hdl, free)); + + //Creation of thread for Registration Termination + if(pthread_create(&rtr_thread, NULL,rtr_socket, NULL)) + { + TRACE_DEBUG(INFO,"Creation of thread failed, abort!"); + return EINVAL; + } + //Creation of thread for Push Profile + if(pthread_create(&ppr_thread, NULL,ppr_socket, NULL)) + { + TRACE_DEBUG(INFO,"Creation of thread failed, abort!"); + return EINVAL; + } + + + return 0; +} + +//Cleanup callback +void fd_ext_fini(void) +{ + //TODO:unregister other callbacks + + (void) fd_disp_unregister(&app_sip_MAR_hdl); + CHECK_FCT_DO( fd_sess_handler_destroy(&ds_sess_hdl),return); + + + //We close database connection + close_mysql_connection(); + + + + TRACE_ENTRY(); + return ; +} + +EXTENSION_ENTRY("app_sip", as_entry); diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/app_sip.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/app_sip/app_sip.h Wed Jul 28 14:34:48 2010 +0900 @@ -0,0 +1,268 @@ +/********************************************************************************************************* +* Software License Agreement (BSD License) * +* Author: Alexandre Westfahl * +* * +* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * +* * +* All rights reserved. * +* * +* Redistribution and use of this software in source and binary forms, with or without modification, are * +* permitted provided that the following conditions are met: * +* * +* * Redistributions of source code must retain the above * +* copyright notice, this list of conditions and the * +* following disclaimer. * +* * +* * Redistributions in binary form must reproduce the above * +* copyright notice, this list of conditions and the * +* following disclaimer in the documentation and/or other * +* materials provided with the distribution. * +* * +* * Neither the name of the Teraoka Laboratory nor the * +* names of its contributors may be used to endorse or * +* promote products derived from this software without * +* specific prior written permission of Teraoka Laboratory * +* * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * +* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * +* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +*********************************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include "md5.h" + + +#define NONCE_SIZE 16 +#define DIGEST_LEN 16 + + +/* Mode for the extension */ +#define MODE_DSSERVER 0x1 +#define MODE_SL 0x2 + +//Redirect_Host_Usage +#define ALL_USER 6 + +/* The module configuration */ +struct as_conf { + int mode; /* default MODE_DSSERVER | MODE_SL */ + enum {ASMYSQL} datasource; + char * mysql_login; + char * mysql_password; + char * mysql_database; + char * mysql_server; + char mysql_prefix[10]; //default: as_ + uint16_t mysql_port; //if 0, default port will be used + +}; +extern struct as_conf * as_conf; + +/* Parse the configuration file */ +int as_conf_handle(char * conffile); + + +extern MYSQL *conn; + + + +void calc_md5(char *buffer, char * data); +void clear_digest(uint8_t * digest, char * readable_digest, int digestlength); +struct avp_hdr * walk_digest(struct avp *avp, int avp_code); + + +//MySQL part +int start_mysql_connection(); +void request_mysql(char *query); +void close_mysql_connection(); +int get_sipserver_uri(const unsigned char *sip_aor, const size_t sipaorlen, unsigned char ** sipserver_uri, size_t *sipserverurilen); +int exist_username(const unsigned char *sip_aor, const size_t sipaorlen); +int get_sipserver_cap(const unsigned char *sip_aor, const size_t sipaorlen, struct avp **capabilities); +int get_password(const unsigned char *username, const size_t usernamelen, char *password); +int check_sipaor(const unsigned char *username, const size_t usernamelen, const char * sip_aor,const size_t sipaorlen); +int add_user_datatype(const unsigned char *sip_aor, const size_t sipaorlen,struct msg *message); +int set_pending_flag(const unsigned char *username, const size_t usernamelen); +int clear_pending_flag(const unsigned char *username, const size_t usernamelen); +int set_real_sipserver_uri(const unsigned char *username, const size_t usernamelen, const unsigned char *sipserver_uri,const size_t sipserverurilen); +int set_sipserver_uri(const unsigned char *username, const size_t usernamelen, const unsigned char *sipserver_uri,const size_t sipserverurilen); +//int get_sipserver_uri(const unsigned char *sip_aor, const size_t sipaorlen, unsigned char ** sipserver_uri, size_t *sipserverurilen); +int allow_roaming(const unsigned char *username, const size_t usernamelen, const char * network,const size_t networklen); +int get_diameter_uri(const unsigned char *sip_aor, const size_t sipaorlen, char ** diameter_uri, size_t *diameterurilen); +//count functions +int count_avp(struct msg * message, int code, int vendor); + + +void DigestCalcHA1(char * pszAlg,char * pszUserName,char * pszRealm,char * pszPassword,char * pszNonce,char * pszCNonce,HASHHEX SessionKey); +void DigestCalcResponse(HASHHEX HA1,char * pszNonce,char * pszNonceCount,char * pszCNonce,char * pszQop,char * pszMethod,char * pszDigestUri,HASHHEX HEntity,HASHHEX Response); +void DigestCalcResponseAuth(HASHHEX HA1,char * pszNonce,char * pszNonceCount,char * pszCNonce,char * pszQop,char * pszMethod,char * pszDigestUri,HASHHEX HEntity,HASHHEX Response); + +int fd_avp_search_avp ( struct avp * groupedavp, struct dict_object * what, struct avp ** avp ); + +//thread procedure +void *rtr_socket(void *); +void *ppr_socket(void *); + +struct rtrsipaor +{ + char username[200]; + char sip_aor1[200]; + char sip_aor2[200]; + char sip_aor3[200]; + char strreason[200]; + char desthost[200]; + int reason; +}; +struct pprsipaor +{ + char username[200]; + char label1[200]; + char value1[200]; + char label2[200]; + char value2[200]; + char desthost[200]; +}; +int app_sip_RTR_cb(struct rtrsipaor structure); +int app_sip_PPR_cb(struct pprsipaor structure); +#define PORT 666 //TODO:put in conf file + +int ds_entry(); +void fd_ext_fini(void); +int app_sip_default_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); +int app_sip_MAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); +int app_sip_RTA_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); +int app_sip_PPA_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); +int app_sip_LIR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); +int app_sip_UAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); +int app_sip_SAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); + +//Suscriber Locator +int app_sip_SL_LIR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act); +//int app_sip_SL_SAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act); + +#define SQL_GETPASSWORD "SELECT `password` FROM ds_users WHERE `username` ='%s'" +#define SQL_GETPASSWORD_LEN 52 + +//username by SIP-AOR +#define SQL_GETUSERNAME "SELECT `username` FROM ds_users, ds_sip_aor WHERE `sip_aor` ='%s' AND `ds_sip_aor`.`id_user` = `ds_users`.`id_user`" +#define SQL_GETUSERNAME_LEN 113 + +//sip server uri by username +#define SQL_GETSIPURI "SELECT `sip_server_uri` FROM ds_users WHERE `username` ='%s'" +#define SQL_GETSIPURI_LEN 60 + +//sip server uri by SIP-AOR +#define SQL_GETSIPSERURI "SELECT `ds_sip_aor`.`sip_server_uri` FROM ds_users, ds_sip_aor WHERE `sip_aor` ='%s' AND `ds_sip_aor`.`id_user` = `ds_users`.`id_user`" +#define SQL_GETSIPSERURI_LEN 132 + +//sip capabilities for a SIP-AOR +#define SQL_GETSIPSERCAP "SELECT `compulsory`,`id_service` FROM ds_user_services, ds_sip_aor WHERE `sip_aor` ='%s' AND `ds_sip_aor`.`id_user` = `ds_user_services`.`id_user`" +#define SQL_GETSIPSERCAP_LEN 144 + +//user data for a user data supported +#define SQL_GETSIPDATA "SELECT `label_type`,`data` FROM ds_sip_aor, ds_user_data, ds_data_types WHERE `sip_aor` ='%s' AND `ds_sip_aor`.`id_sip_aor` = `ds_user_data`.`id_sip_aor` AND `ds_data_types`.`id_data_type`=`ds_user_data`.`id_data_type`" +#define SQL_GETSIPDATA_LEN 216 + +#define SQL_GETDIAMURI "SELECT `sipserver_uri` FROM ds_sip_aor_map WHERE `sip_aor` ='%s'" +#define SQL_GETDIAMURI_LEN 61 + +//networks for this user +#define SQL_GETUSERNET "SELECT `label_network` FROM ds_users, ds_user_networks, ds_networks WHERE `ds_users`.`username` ='%s' AND `ds_user_networks`.`id_user` = `ds_users`.`id_user` AND `ds_user_networks`.`id_network` = `ds_networks`.`id_network`" +#define SQL_GETUSERNET_LEN 220 + +#define SQL_SETSIPURI "UPDATE ds_users SET `temp_sip_server_uri`='%s' WHERE `username` ='%s'" +#define SQL_SETSIPURI_LEN 65 + +//TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO +#define SQL_RMSIPURI "UPDATE ds_users SET `temp_sip_server_uri`='', `sip_server_uri`='' WHERE `id_user` ='%s'" +#define SQL_RMSIPURI_LEN 65 +//TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO + +#define SQL_SETREALSIPURI "UPDATE ds_users SET `sip_server_uri`='%s' WHERE `username` ='%s'" +#define SQL_SETREALSIPURI_LEN 65 + +#define SQL_SETFLAG "UPDATE ds_users SET `authentication_pending`=1 WHERE `username` ='%s'" +#define SQL_SETFLAG_LEN 67 + +#define SQL_CLEARFLAG "UPDATE ds_users SET `authentication_pending`=0, `registrated`=1 WHERE `username` ='%s'" +#define SQL_CLEARFLAG_LEN 84 + +#define SQL_GETSIPAOR "SELECT `sip_aor` FROM `ds_sip_aor`, `ds_users` WHERE `ds_sip_aor`.`id_user` = `ds_users`.`id_user` AND `ds_users`.`username` = '%s'" +#define SQL_GETSIPAOR_LEN 131 + +//#define SQL_CLEARFLAG "UPDATE ds_users SET `authentication_pending`=0 WHERE `username` ='%s'" +//#define SQL_CLEARFLAG_LEN 67 + +extern struct session_handler * ds_sess_hdl; + +//AVP code +#define CODE_SIP_USER_DATA_TYPE 388 +#define CODE_SIP_AOR 122 + +struct ds_nonce +{ + char *nonce; +}; + +//Storage for some usefull AVPs +struct app_sip_dict{ + struct dict_object * Auth_Session_State; + struct dict_object * Auth_Application_Id; + struct dict_object * Destination_Host; + struct dict_object * Destination_Realm; + struct dict_object * User_Name; + struct dict_object * Session_Id; + struct dict_object * Redirect_Host; + struct dict_object * Redirect_Host_Usage; + struct dict_object * SIP_Auth_Data_Item; + struct dict_object * SIP_Accounting_Information; + struct dict_object * SIP_Accounting_Server_URI; + struct dict_object * SIP_Credit_Control_Server_URI; + struct dict_object * SIP_Server_Assignment_Type; + struct dict_object * SIP_Item_Number; + struct dict_object * SIP_User_Authorization_Type; + struct dict_object * SIP_Supported_User_Data_Type; + struct dict_object * SIP_User_Data; + struct dict_object * SIP_User_Data_Type; + struct dict_object * SIP_User_Data_Contents; + struct dict_object * SIP_User_Data_Already_Available; + struct dict_object * SIP_Visited_Network_Id; + struct dict_object * SIP_Authorization; + struct dict_object * SIP_Authenticate; + struct dict_object * SIP_Number_Auth_Items; + struct dict_object * SIP_Authentication_Scheme; + struct dict_object * SIP_Authentication_Info; + struct dict_object * SIP_Server_URI; + struct dict_object * SIP_Server_Capabilities; + struct dict_object * SIP_Mandatory_Capability; + struct dict_object * SIP_Optional_Capability; + struct dict_object * SIP_Method; + struct dict_object * SIP_AOR; + struct dict_object * SIP_Deregistration_Reason; + struct dict_object * SIP_Reason_Code; + struct dict_object * SIP_Reason_Info; + struct dict_object * Digest_URI; + struct dict_object * Digest_Nonce; + struct dict_object * Digest_Nonce_Count; + struct dict_object * Digest_CNonce; + struct dict_object * Digest_Realm; + struct dict_object * Digest_Response; + struct dict_object * Digest_Response_Auth; + struct dict_object * Digest_Username; + struct dict_object * Digest_Method; + struct dict_object * Digest_QOP; + struct dict_object * Digest_Algorithm; + struct dict_object * Digest_HA1; +}; + +extern struct app_sip_dict sip_dict; diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/app_sip.l --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/app_sip/app_sip.l Wed Jul 28 14:34:48 2010 +0900 @@ -0,0 +1,157 @@ +/********************************************************************************************************* +* Software License Agreement (BSD License) * +* Author: Alexandre Westfahl * +* * +* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * +* * +* All rights reserved. * +* Based on ta_conf.l (Sebastien Decugis ) * +* * +* Redistribution and use of this software in source and binary forms, with or without modification, are * +* permitted provided that the following conditions are met: * +* * +* * Redistributions of source code must retain the above * +* copyright notice, this list of conditions and the * +* following disclaimer. * +* * +* * Redistributions in binary form must reproduce the above * +* copyright notice, this list of conditions and the * +* following disclaimer in the documentation and/or other * +* materials provided with the distribution. * +* * +* * Neither the name of the Teraoka Laboratory nor the * +* names of its contributors may be used to endorse or * +* promote products derived from this software without * +* specific prior written permission of Teraoka Laboratory * +* * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * +* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * +* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +*********************************************************************************************************/ + + + +%{ +#include "app_sip.h" +/* Include yacc tokens definitions */ +#include "app_sip.tab.h" + +/* Update the column information */ +#define YY_USER_ACTION { \ + yylloc->first_column = yylloc->last_column + 1; \ + yylloc->last_column = yylloc->first_column + yyleng - 1; \ +} + +/* Avoid warning with newer flex */ +#define YY_NO_INPUT + +%} + +%option bison-bridge bison-locations +%option noyywrap +%option nounput + +%% + + /* Update the line count */ +\n { + yylloc->first_line++; + yylloc->last_line++; + yylloc->last_column=0; + } + + /* Eat all spaces but not new lines */ +([[:space:]]{-}[\n])+ ; + /* Eat all comments */ +#.*$ ; + + /* Recognize any integer */ +[-]?[[:digit:]]+ { + /* Convert this to an integer value */ + int ret=0; + ret = sscanf(yytext, "%i", &yylval->integer); + if (ret != 1) { + /* No matching: an error occurred */ + fd_log_debug("Unable to convert the value '%s' to a valid number: %s\n", yytext, strerror(errno)); + return LEX_ERROR; /* trig an error in yacc parser */ + /* Maybe we could REJECT instead of failing here? */ + } + return INTEGER; + } + + /* Recognize quoted strings -- we do not support escaped \" in the string currently. */ +\"[^\"]+\" { + /* Match a quoted string. Let's be very permissive. */ + yylval->string = strdup(yytext+1); + if (!yylval->string) { + fd_log_debug("Unable to copy the string '%s': %s\n", yytext, strerror(errno)); + TRACE_DEBUG(INFO, "strdup failed"); + return LEX_ERROR; /* trig an error in yacc parser */ + } + yylval->string[strlen(yytext) - 2] = '\0'; + return QSTRING; + } + + + + /* Recognize the tokens */ +(?i:"mysql_login") { + return ASMYSQL_LOGIN; + } + +(?i:"mysql_password") { + return ASMYSQL_PASSWORD; + } + +(?i:"mysql_database") { + return ASMYSQL_DATABASE; + } + +(?i:"mysql_server") { + return ASMYSQL_SERVER; + } + +(?i:"mysql_port") { + return ASMYSQL_PORT; + } + +(?i:"mode") { + return MODE; + } + +(?i:"datasource") { + return DATASOURCE; + } + +(?i:"mysql") { + yylval->integer = ASMYSQL; + return INTEGER; + } +(?i:"dsserver") { + yylval->integer = MODE_DSSERVER; + return INTEGER; + } + +(?i:"sl") { + yylval->integer = MODE_SL; + return INTEGER; + } + + + + /* Valid single characters for yyparse */ +[=;] { return yytext[0]; } + + /* Unrecognized sequence, if it did not match any previous pattern */ +[^[:space:]"*=>;\n]+ { + fd_log_debug("Unrecognized text on line %d col %d: '%s'.\n", yylloc->first_line, yylloc->first_column, yytext); + return LEX_ERROR; + } + +%% diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/app_sip.y --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/app_sip/app_sip.y Wed Jul 28 14:34:48 2010 +0900 @@ -0,0 +1,194 @@ +/********************************************************************************************************* +* Software License Agreement (BSD License) * +* Author: Alexandre Westfahl * +* * +* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * +* * +* All rights reserved. * +* Based on ta_conf.y (Sebastien Decugis ) * +* * +* Redistribution and use of this software in source and binary forms, with or without modification, are * +* permitted provided that the following conditions are met: * +* * +* * Redistributions of source code must retain the above * +* copyright notice, this list of conditions and the * +* following disclaimer. * +* * +* * Redistributions in binary form must reproduce the above * +* copyright notice, this list of conditions and the * +* following disclaimer in the documentation and/or other * +* materials provided with the distribution. * +* * +* * Neither the name of the Teraoka Laboratory nor the * +* names of its contributors may be used to endorse or * +* promote products derived from this software without * +* specific prior written permission of Teraoka Laboratory * +* * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * +* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * +* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +*********************************************************************************************************/ + + + +/* For development only : */ +%debug +%error-verbose + +/* The parser receives the configuration file filename as parameter */ +%parse-param {char * conffile} + +/* Keep track of location */ +%locations +%pure-parser + +%{ +#include "app_sip.h" +#include "app_sip.tab.h" /* bison is not smart enough to define the YYLTYPE before including this code, so... */ + +#include +#include + +/* Forward declaration */ +int yyparse(char * conffile); + +/* Parse the configuration file */ +int as_conf_handle(char * conffile) +{ + extern FILE * app_sipin; + int ret; + + TRACE_ENTRY("%p", conffile); + + TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile); + + app_sipin = fopen(conffile, "r"); + if (app_sipin == NULL) { + ret = errno; + fd_log_debug("Unable to open extension configuration file %s for reading: %s\n", conffile, strerror(ret)); + TRACE_DEBUG (INFO, "Error occurred, message logged -- configuration file."); + return ret; + } + + ret = yyparse(conffile); + + fclose(app_sipin); + + if (ret != 0) { + TRACE_DEBUG (INFO, "Unable to parse the configuration file."); + return EINVAL; + } + + return 0; +} + +/* The Lex parser prototype */ +int app_siplex(YYSTYPE *lvalp, YYLTYPE *llocp); + +/* Function to report the errors */ +void yyerror (YYLTYPE *ploc, char * conffile, char const *s) +{ + TRACE_DEBUG(INFO, "Error in configuration parsing"); + + if (ploc->first_line != ploc->last_line) + fd_log_debug("%s:%d.%d-%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s); + else if (ploc->first_column != ploc->last_column) + fd_log_debug("%s:%d.%d-%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s); + else + fd_log_debug("%s:%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, s); +} + +%} + +/* Values returned by lex for token */ +%union { + char *string; /* The string is allocated by strdup in lex.*/ + int integer; /* Store integer values */ +} + +/* In case of error in the lexical analysis */ +%token LEX_ERROR + +/* Key words */ +%token MODE +%token DATASOURCE +%token ASMYSQL_LOGIN +%token ASMYSQL_PASSWORD +%token ASMYSQL_DATABASE +%token ASMYSQL_SERVER +%token ASMYSQL_PORT + +/* Tokens and types for routing table definition */ +/* A (de)quoted string (malloc'd in lex parser; it must be freed after use) */ +%token QSTRING + +/* An integer value */ +%token INTEGER + + + +/* -------------------------------------- */ +%% + + /* The grammar definition */ +conffile: /* empty grammar is OK */ + | conffile mode + | conffile datasource + | conffile mysql_login + | conffile mysql_password + | conffile mysql_database + | conffile mysql_server + | conffile mysql_port + ; + +mode: MODE '=' INTEGER ';' + { + as_conf->mode = $3; + } + ; + +datasource: DATASOURCE '=' INTEGER ';' + { + as_conf->datasource = $3; + } + ; + +mysql_login: ASMYSQL_LOGIN '=' QSTRING ';' + { + free(as_conf->mysql_login); + as_conf->mysql_login = $3; + } + ; + +mysql_password: ASMYSQL_PASSWORD '=' QSTRING ';' + { + free(as_conf->mysql_password); + as_conf->mysql_password = $3; + } + ; + +mysql_database: ASMYSQL_DATABASE '=' QSTRING ';' + { + free(as_conf->mysql_database); + as_conf->mysql_database = $3; + } + ; + +mysql_server: ASMYSQL_SERVER '=' QSTRING ';' + { + free(as_conf->mysql_server); + as_conf->mysql_server = $3; + } + ; + +mysql_port: ASMYSQL_PORT '=' INTEGER ';' + { + as_conf->mysql_port = (uint16_t)$3; + } + ; diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/diamsip.c --- a/extensions/app_sip/diamsip.c Wed Jul 28 03:14:11 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,252 +0,0 @@ -/********************************************************************************************************* -* Software License Agreement (BSD License) * -* Author: Alexandre Westfahl * -* * -* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * -* * -* All rights reserved. * -* * -* Redistribution and use of this software in source and binary forms, with or without modification, are * -* permitted provided that the following conditions are met: * -* * -* * Redistributions of source code must retain the above * -* copyright notice, this list of conditions and the * -* following disclaimer. * -* * -* * Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the * -* following disclaimer in the documentation and/or other * -* materials provided with the distribution. * -* * -* * Neither the name of the Teraoka Laboratory nor the * -* names of its contributors may be used to endorse or * -* promote products derived from this software without * -* specific prior written permission of Teraoka Laboratory * -* * -* * -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * -* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * -* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * -* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * -*********************************************************************************************************/ -#include "diamsip.h" - -//Diameter-SIP server -struct disp_hdl * diamsip_MAR_hdl=NULL; -struct disp_hdl * diamsip_LIR_hdl=NULL; -struct disp_hdl * diamsip_UAR_hdl=NULL; -struct disp_hdl * diamsip_SAR_hdl=NULL; -struct disp_hdl * diamsip_PPA_hdl=NULL; -struct disp_hdl * diamsip_RTA_hdl=NULL; - -//Suscriber Locator -struct disp_hdl * diamsipSL_LIR_hdl=NULL; - - - -struct disp_hdl * diamsip_default_hdl=NULL; -struct session_handler * ds_sess_hdl; - -//configuration stucture -struct as_conf * as_conf=NULL; -static struct as_conf app_sip_conf; - -//dictionary of SIP -struct diamsip_dict sip_dict; - -int diamsip_default_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act) -{ - TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act); - - return 0; -} - -void dump_config() -{ - TRACE_DEBUG(FULL,"***Configuration of Diameter-SIP extension***"); - TRACE_DEBUG(FULL,"# mode: *%d*",as_conf->mode); - TRACE_DEBUG(FULL,"# datasource: *%d*",as_conf->datasource); - TRACE_DEBUG(FULL,"# mysql_login: *%s*",as_conf->mysql_login); - TRACE_DEBUG(FULL,"# mysql_password: *%s*",as_conf->mysql_password); - TRACE_DEBUG(FULL,"# mysql_database: *%s*",as_conf->mysql_database); - TRACE_DEBUG(FULL,"# mysql_server: *%s*",as_conf->mysql_server); - TRACE_DEBUG(FULL,"# mysql_port: *%d*",as_conf->mysql_port); - TRACE_DEBUG(FULL,"# mysql_port: *%d*",as_conf->mysql_prefix); - TRACE_DEBUG(FULL,"***End of Diameter-SIP configuration extension***"); -} - -static int as_conf_init(void) -{ - as_conf=&app_sip_conf; - //memset(app_sip_conf, 0, sizeof(struct as_conf)); - - - return 0; -} - -/* entry point */ -int as_entry(char * conffile) -{ - TRACE_ENTRY("%p", conffile); - - struct dict_object * app=NULL; - struct disp_when data; - pthread_t rtr_thread, ppr_thread; - - /* Initialize configuration */ - CHECK_FCT( as_conf_init() ); - - - //We parse the configuration file - if (conffile != NULL) { - CHECK_FCT( as_conf_handle(conffile) ); - } - else - { - TRACE_DEBUG(INFO, "We need a configuration file for Diameter-SIP extension. See doc/ for an example."); - } - - //TODO: replace by configuration file!! - strcpy(as_conf->mysql_prefix,"as_"); - - //We can dump the configuration extracted from app_sip.conf - //dump_config(); - - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Session Initiation Protocol (SIP) Application", &app, ENOENT) ); - CHECK_FCT( fd_disp_app_support ( app, NULL, 1, 0 ) ); - - - - //We set usefull AVPs - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Session-State", &sip_dict.Auth_Session_State, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Application-Id", &sip_dict.Auth_Application_Id, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Host", &sip_dict.Destination_Host, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Realm", &sip_dict.Destination_Realm, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &sip_dict.Session_Id, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Redirect-Host", &sip_dict.Redirect_Host, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Redirect-Host-Usage", &sip_dict.Redirect_Host_Usage, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Auth-Data-Item", &sip_dict.SIP_Auth_Data_Item, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authorization", &sip_dict.SIP_Authorization, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authenticate", &sip_dict.SIP_Authenticate, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Number-Auth-Items", &sip_dict.SIP_Number_Auth_Items, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authentication-Scheme", &sip_dict.SIP_Authentication_Scheme, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authentication-Info", &sip_dict.SIP_Authentication_Info, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Server-URI", &sip_dict.SIP_Server_URI, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Server-Capabilities", &sip_dict.SIP_Server_Capabilities, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Mandatory-Capability", &sip_dict.SIP_Mandatory_Capability, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Optional-Capability", &sip_dict.SIP_Optional_Capability, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Method", &sip_dict.SIP_Method, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-AOR", &sip_dict.SIP_AOR, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Deregistration-Reason", &sip_dict.SIP_Deregistration_Reason, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Reason-Code", &sip_dict.SIP_Reason_Code, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Reason-Info", &sip_dict.SIP_Reason_Info, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Accounting-Information", &sip_dict.SIP_Accounting_Information, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Accounting-Server-URI", &sip_dict.SIP_Accounting_Server_URI, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Credit-Control-Server-URI", &sip_dict.SIP_Credit_Control_Server_URI, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Server-Assignment-Type", &sip_dict.SIP_Server_Assignment_Type, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Item-Number", &sip_dict.SIP_Item_Number, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Authorization-Type", &sip_dict.SIP_User_Authorization_Type, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Supported-User-Data-Type", &sip_dict.SIP_Supported_User_Data_Type, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Data", &sip_dict.SIP_User_Data, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Data-Type", &sip_dict.SIP_User_Data_Type, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Data-Contents", &sip_dict.SIP_User_Data_Contents, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Data-Already-Available", &sip_dict.SIP_User_Data_Already_Available, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Visited-Network-Id", &sip_dict.SIP_Visited_Network_Id, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Realm", &sip_dict.Digest_Realm, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-URI", &sip_dict.Digest_URI, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Nonce", &sip_dict.Digest_Nonce, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-CNonce", &sip_dict.Digest_CNonce, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Method", &sip_dict.Digest_Method, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Nonce-Count", &sip_dict.Digest_Nonce_Count, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Realm", &sip_dict.Digest_Realm, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Response", &sip_dict.Digest_Response, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Response-Auth", &sip_dict.Digest_Response_Auth, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Username", &sip_dict.Digest_Username, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Algorithm", &sip_dict.Digest_Algorithm, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-QoP", &sip_dict.Digest_QOP, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "User-Name", &sip_dict.User_Name, ENOENT) ); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-HA1", &sip_dict.Digest_HA1, ENOENT) ); - - - //Register Application - memset(&data, 0, sizeof(data)); - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Session Initiation Protocol (SIP) Application", &data.app, ENOENT) ); - - if(as_conf->mode==1) - { - //**Command Codes - //MAR - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Multimedia-Auth-Request", &data.command, ENOENT) ); - CHECK_FCT( fd_disp_register( diamsip_MAR_cb, DISP_HOW_CC, &data, &diamsip_MAR_hdl ) ); - //RTA - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Registration-Termination-Answer", &data.command, ENOENT) ); - CHECK_FCT( fd_disp_register( diamsip_RTA_cb, DISP_HOW_CC, &data, &diamsip_RTA_hdl ) ); - //PPA - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Push-Profile-Answer", &data.command, ENOENT) ); - CHECK_FCT( fd_disp_register( diamsip_PPA_cb, DISP_HOW_CC, &data, &diamsip_PPA_hdl ) ); - //LIR - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Location-Info-Request", &data.command, ENOENT) ); - CHECK_FCT( fd_disp_register( diamsip_LIR_cb, DISP_HOW_CC, &data, &diamsip_LIR_hdl ) ); - //UAR - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "User-Authorization-Request", &data.command, ENOENT) ); - CHECK_FCT( fd_disp_register( diamsip_UAR_cb, DISP_HOW_CC, &data, &diamsip_UAR_hdl ) ); - //SAR - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Server-Assignment-Request", &data.command, ENOENT) ); - CHECK_FCT( fd_disp_register( diamsip_SAR_cb, DISP_HOW_CC, &data, &diamsip_SAR_hdl ) ); - } - if(as_conf->mode==2) - { - //LIR - CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Location-Info-Request", &data.command, ENOENT) ); - CHECK_FCT( fd_disp_register( diamsipSL_LIR_cb, DISP_HOW_CC, &data, &diamsipSL_LIR_hdl ) ); - } - //Callback for unexpected messages - CHECK_FCT( fd_disp_register( diamsip_default_cb, DISP_HOW_APPID, &data, &diamsip_default_hdl ) ); - - - //We start database connection - if(start_mysql_connection()) - return EINVAL; - - CHECK_FCT(fd_sess_handler_create(&ds_sess_hdl, free)); - - //Creation of thread for Registration Termination - if(pthread_create(&rtr_thread, NULL,rtr_socket, NULL)) - { - TRACE_DEBUG(INFO,"Creation of thread failed, abort!"); - return EINVAL; - } - //Creation of thread for Push Profile - if(pthread_create(&ppr_thread, NULL,ppr_socket, NULL)) - { - TRACE_DEBUG(INFO,"Creation of thread failed, abort!"); - return EINVAL; - } - - - return 0; -} - -//Cleanup callback -void fd_ext_fini(void) -{ - //TODO:unregister other callbacks - - (void) fd_disp_unregister(&diamsip_MAR_hdl); - CHECK_FCT_DO( fd_sess_handler_destroy(&ds_sess_hdl),return); - - - //We close database connection - close_mysql_connection(); - - - - TRACE_ENTRY(); - return ; -} - -EXTENSION_ENTRY("app_sip", as_entry); diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/diamsip.h --- a/extensions/app_sip/diamsip.h Wed Jul 28 03:14:11 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,268 +0,0 @@ -/********************************************************************************************************* -* Software License Agreement (BSD License) * -* Author: Alexandre Westfahl * -* * -* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * -* * -* All rights reserved. * -* * -* Redistribution and use of this software in source and binary forms, with or without modification, are * -* permitted provided that the following conditions are met: * -* * -* * Redistributions of source code must retain the above * -* copyright notice, this list of conditions and the * -* following disclaimer. * -* * -* * Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the * -* following disclaimer in the documentation and/or other * -* materials provided with the distribution. * -* * -* * Neither the name of the Teraoka Laboratory nor the * -* names of its contributors may be used to endorse or * -* promote products derived from this software without * -* specific prior written permission of Teraoka Laboratory * -* * -* * -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * -* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * -* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * -* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * -*********************************************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include "md5.h" - - -#define NONCE_SIZE 16 -#define DIGEST_LEN 16 - - -/* Mode for the extension */ -#define MODE_DSSERVER 0x1 -#define MODE_SL 0x2 - -//Redirect_Host_Usage -#define ALL_USER 6 - -/* The module configuration */ -struct as_conf { - int mode; /* default MODE_DSSERVER | MODE_SL */ - enum {ASMYSQL} datasource; - char * mysql_login; - char * mysql_password; - char * mysql_database; - char * mysql_server; - char mysql_prefix[10]; //default: as_ - uint16_t mysql_port; //if 0, default port will be used - -}; -extern struct as_conf * as_conf; - -/* Parse the configuration file */ -int as_conf_handle(char * conffile); - - -extern MYSQL *conn; - - - -void calc_md5(char *buffer, char * data); -void clear_digest(uint8_t * digest, char * readable_digest, int digestlength); -struct avp_hdr * walk_digest(struct avp *avp, int avp_code); - - -//MySQL part -int start_mysql_connection(); -void request_mysql(char *query); -void close_mysql_connection(); -int get_diameter_uri(const unsigned char *sip_aor, const size_t sipaorlen, char ** diameter_uri, size_t *diameterurilen); -int exist_username(const unsigned char *sip_aor, const size_t sipaorlen); -int get_sipserver_cap(const unsigned char *sip_aor, const size_t sipaorlen, struct avp **capabilities); -int get_password(const unsigned char *username, const size_t usernamelen, char *password); -int check_sipaor(const unsigned char *username, const size_t usernamelen, const char * sip_aor,const size_t sipaorlen); -int add_user_datatype(const unsigned char *sip_aor, const size_t sipaorlen,struct msg *message); -int set_pending_flag(const unsigned char *username, const size_t usernamelen); -int clear_pending_flag(const unsigned char *username, const size_t usernamelen); -int set_real_sipserver_uri(const unsigned char *username, const size_t usernamelen, const unsigned char *sipserver_uri,const size_t sipserverurilen); -int set_sipserver_uri(const unsigned char *username, const size_t usernamelen, const unsigned char *sipserver_uri,const size_t sipserverurilen); -int get_sipserver_uri(const unsigned char *sip_aor, const size_t sipaorlen, unsigned char ** sipserver_uri, size_t *sipserverurilen); -int allow_roaming(const unsigned char *username, const size_t usernamelen, const char * network,const size_t networklen); - -//count functions -int count_avp(struct msg * message, int code, int vendor); - - -void DigestCalcHA1(char * pszAlg,char * pszUserName,char * pszRealm,char * pszPassword,char * pszNonce,char * pszCNonce,HASHHEX SessionKey); -void DigestCalcResponse(HASHHEX HA1,char * pszNonce,char * pszNonceCount,char * pszCNonce,char * pszQop,char * pszMethod,char * pszDigestUri,HASHHEX HEntity,HASHHEX Response); -void DigestCalcResponseAuth(HASHHEX HA1,char * pszNonce,char * pszNonceCount,char * pszCNonce,char * pszQop,char * pszMethod,char * pszDigestUri,HASHHEX HEntity,HASHHEX Response); - -int fd_avp_search_avp ( struct avp * groupedavp, struct dict_object * what, struct avp ** avp ); - -//thread procedure -void *rtr_socket(void *); -void *ppr_socket(void *); - -struct rtrsipaor -{ - char username[200]; - char sip_aor1[200]; - char sip_aor2[200]; - char sip_aor3[200]; - char strreason[200]; - char desthost[200]; - int reason; -}; -struct pprsipaor -{ - char username[200]; - char label1[200]; - char value1[200]; - char label2[200]; - char value2[200]; - char desthost[200]; -}; -int diamsip_RTR_cb(struct rtrsipaor structure); -int diamsip_PPR_cb(struct pprsipaor structure); -#define PORT 666 //TODO:put in conf file - -int ds_entry(); -void fd_ext_fini(void); -int diamsip_default_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); -int diamsip_MAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); -int diamsip_RTA_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); -int diamsip_PPA_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); -int diamsip_LIR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); -int diamsip_UAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); -int diamsip_SAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); - -//Suscriber Locator -int diamsipSL_LIR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act); -//int diamsipSL_SAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act); - -#define SQL_GETPASSWORD "SELECT `password` FROM ds_users WHERE `username` ='%s'" -#define SQL_GETPASSWORD_LEN 52 - -//username by SIP-AOR -#define SQL_GETUSERNAME "SELECT `username` FROM ds_users, ds_sip_aor WHERE `sip_aor` ='%s' AND `ds_sip_aor`.`id_user` = `ds_users`.`id_user`" -#define SQL_GETUSERNAME_LEN 113 - -//sip server uri by username -#define SQL_GETSIPURI "SELECT `sip_server_uri` FROM ds_users WHERE `username` ='%s'" -#define SQL_GETSIPURI_LEN 60 - -//sip server uri by SIP-AOR -#define SQL_GETSIPSERURI "SELECT `ds_sip_aor`.`sip_server_uri` FROM ds_users, ds_sip_aor WHERE `sip_aor` ='%s' AND `ds_sip_aor`.`id_user` = `ds_users`.`id_user`" -#define SQL_GETSIPSERURI_LEN 132 - -//sip capabilities for a SIP-AOR -#define SQL_GETSIPSERCAP "SELECT `compulsory`,`id_service` FROM ds_user_services, ds_sip_aor WHERE `sip_aor` ='%s' AND `ds_sip_aor`.`id_user` = `ds_user_services`.`id_user`" -#define SQL_GETSIPSERCAP_LEN 144 - -//user data for a user data supported -#define SQL_GETSIPDATA "SELECT `label_type`,`data` FROM ds_sip_aor, ds_user_data, ds_data_types WHERE `sip_aor` ='%s' AND `ds_sip_aor`.`id_sip_aor` = `ds_user_data`.`id_sip_aor` AND `ds_data_types`.`id_data_type`=`ds_user_data`.`id_data_type`" -#define SQL_GETSIPDATA_LEN 216 - -#define SQL_GETDIAMURI "SELECT `diameter_uri` FROM ds_sip_aor_map WHERE `sip_aor` ='%s'" -#define SQL_GETDIAMURI_LEN 61 - -//networks for this user -#define SQL_GETUSERNET "SELECT `label_network` FROM ds_users, ds_user_networks, ds_networks WHERE `ds_users`.`username` ='%s' AND `ds_user_networks`.`id_user` = `ds_users`.`id_user` AND `ds_user_networks`.`id_network` = `ds_networks`.`id_network`" -#define SQL_GETUSERNET_LEN 220 - -#define SQL_SETSIPURI "UPDATE ds_users SET `temp_sip_server_uri`='%s' WHERE `username` ='%s'" -#define SQL_SETSIPURI_LEN 65 - -//TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO -#define SQL_RMSIPURI "UPDATE ds_users SET `temp_sip_server_uri`='', `sip_server_uri`='' WHERE `id_user` ='%s'" -#define SQL_RMSIPURI_LEN 65 -//TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO - -#define SQL_SETREALSIPURI "UPDATE ds_users SET `sip_server_uri`='%s' WHERE `username` ='%s'" -#define SQL_SETREALSIPURI_LEN 65 - -#define SQL_SETFLAG "UPDATE ds_users SET `authentication_pending`=1 WHERE `username` ='%s'" -#define SQL_SETFLAG_LEN 67 - -#define SQL_CLEARFLAG "UPDATE ds_users SET `authentication_pending`=0, `registrated`=1 WHERE `username` ='%s'" -#define SQL_CLEARFLAG_LEN 84 - -#define SQL_GETSIPAOR "SELECT `sip_aor` FROM `ds_sip_aor`, `ds_users` WHERE `ds_sip_aor`.`id_user` = `ds_users`.`id_user` AND `ds_users`.`username` = '%s'" -#define SQL_GETSIPAOR_LEN 131 - -//#define SQL_CLEARFLAG "UPDATE ds_users SET `authentication_pending`=0 WHERE `username` ='%s'" -//#define SQL_CLEARFLAG_LEN 67 - -extern struct session_handler * ds_sess_hdl; - -//AVP code -#define CODE_SIP_USER_DATA_TYPE 388 -#define CODE_SIP_AOR 122 - -struct ds_nonce -{ - char *nonce; -}; - -//Storage for some usefull AVPs -struct diamsip_dict{ - struct dict_object * Auth_Session_State; - struct dict_object * Auth_Application_Id; - struct dict_object * Destination_Host; - struct dict_object * Destination_Realm; - struct dict_object * User_Name; - struct dict_object * Session_Id; - struct dict_object * Redirect_Host; - struct dict_object * Redirect_Host_Usage; - struct dict_object * SIP_Auth_Data_Item; - struct dict_object * SIP_Accounting_Information; - struct dict_object * SIP_Accounting_Server_URI; - struct dict_object * SIP_Credit_Control_Server_URI; - struct dict_object * SIP_Server_Assignment_Type; - struct dict_object * SIP_Item_Number; - struct dict_object * SIP_User_Authorization_Type; - struct dict_object * SIP_Supported_User_Data_Type; - struct dict_object * SIP_User_Data; - struct dict_object * SIP_User_Data_Type; - struct dict_object * SIP_User_Data_Contents; - struct dict_object * SIP_User_Data_Already_Available; - struct dict_object * SIP_Visited_Network_Id; - struct dict_object * SIP_Authorization; - struct dict_object * SIP_Authenticate; - struct dict_object * SIP_Number_Auth_Items; - struct dict_object * SIP_Authentication_Scheme; - struct dict_object * SIP_Authentication_Info; - struct dict_object * SIP_Server_URI; - struct dict_object * SIP_Server_Capabilities; - struct dict_object * SIP_Mandatory_Capability; - struct dict_object * SIP_Optional_Capability; - struct dict_object * SIP_Method; - struct dict_object * SIP_AOR; - struct dict_object * SIP_Deregistration_Reason; - struct dict_object * SIP_Reason_Code; - struct dict_object * SIP_Reason_Info; - struct dict_object * Digest_URI; - struct dict_object * Digest_Nonce; - struct dict_object * Digest_Nonce_Count; - struct dict_object * Digest_CNonce; - struct dict_object * Digest_Realm; - struct dict_object * Digest_Response; - struct dict_object * Digest_Response_Auth; - struct dict_object * Digest_Username; - struct dict_object * Digest_Method; - struct dict_object * Digest_QOP; - struct dict_object * Digest_Algorithm; - struct dict_object * Digest_HA1; -}; - -extern struct diamsip_dict sip_dict; diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/diamsip.l --- a/extensions/app_sip/diamsip.l Wed Jul 28 03:14:11 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,157 +0,0 @@ -/********************************************************************************************************* -* Software License Agreement (BSD License) * -* Author: Alexandre Westfahl * -* * -* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * -* * -* All rights reserved. * -* Based on ta_conf.l (Sebastien Decugis ) * -* * -* Redistribution and use of this software in source and binary forms, with or without modification, are * -* permitted provided that the following conditions are met: * -* * -* * Redistributions of source code must retain the above * -* copyright notice, this list of conditions and the * -* following disclaimer. * -* * -* * Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the * -* following disclaimer in the documentation and/or other * -* materials provided with the distribution. * -* * -* * Neither the name of the Teraoka Laboratory nor the * -* names of its contributors may be used to endorse or * -* promote products derived from this software without * -* specific prior written permission of Teraoka Laboratory * -* * -* * -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * -* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * -* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * -* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * -*********************************************************************************************************/ - - - -%{ -#include "diamsip.h" -/* Include yacc tokens definitions */ -#include "diamsip.tab.h" - -/* Update the column information */ -#define YY_USER_ACTION { \ - yylloc->first_column = yylloc->last_column + 1; \ - yylloc->last_column = yylloc->first_column + yyleng - 1; \ -} - -/* Avoid warning with newer flex */ -#define YY_NO_INPUT - -%} - -%option bison-bridge bison-locations -%option noyywrap -%option nounput - -%% - - /* Update the line count */ -\n { - yylloc->first_line++; - yylloc->last_line++; - yylloc->last_column=0; - } - - /* Eat all spaces but not new lines */ -([[:space:]]{-}[\n])+ ; - /* Eat all comments */ -#.*$ ; - - /* Recognize any integer */ -[-]?[[:digit:]]+ { - /* Convert this to an integer value */ - int ret=0; - ret = sscanf(yytext, "%i", &yylval->integer); - if (ret != 1) { - /* No matching: an error occurred */ - fd_log_debug("Unable to convert the value '%s' to a valid number: %s\n", yytext, strerror(errno)); - return LEX_ERROR; /* trig an error in yacc parser */ - /* Maybe we could REJECT instead of failing here? */ - } - return INTEGER; - } - - /* Recognize quoted strings -- we do not support escaped \" in the string currently. */ -\"[^\"]+\" { - /* Match a quoted string. Let's be very permissive. */ - yylval->string = strdup(yytext+1); - if (!yylval->string) { - fd_log_debug("Unable to copy the string '%s': %s\n", yytext, strerror(errno)); - TRACE_DEBUG(INFO, "strdup failed"); - return LEX_ERROR; /* trig an error in yacc parser */ - } - yylval->string[strlen(yytext) - 2] = '\0'; - return QSTRING; - } - - - - /* Recognize the tokens */ -(?i:"mysql_login") { - return ASMYSQL_LOGIN; - } - -(?i:"mysql_password") { - return ASMYSQL_PASSWORD; - } - -(?i:"mysql_database") { - return ASMYSQL_DATABASE; - } - -(?i:"mysql_server") { - return ASMYSQL_SERVER; - } - -(?i:"mysql_port") { - return ASMYSQL_PORT; - } - -(?i:"mode") { - return MODE; - } - -(?i:"datasource") { - return DATASOURCE; - } - -(?i:"mysql") { - yylval->integer = ASMYSQL; - return INTEGER; - } -(?i:"dsserver") { - yylval->integer = MODE_DSSERVER; - return INTEGER; - } - -(?i:"sl") { - yylval->integer = MODE_SL; - return INTEGER; - } - - - - /* Valid single characters for yyparse */ -[=;] { return yytext[0]; } - - /* Unrecognized sequence, if it did not match any previous pattern */ -[^[:space:]"*=>;\n]+ { - fd_log_debug("Unrecognized text on line %d col %d: '%s'.\n", yylloc->first_line, yylloc->first_column, yytext); - return LEX_ERROR; - } - -%% diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/diamsip.y --- a/extensions/app_sip/diamsip.y Wed Jul 28 03:14:11 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,194 +0,0 @@ -/********************************************************************************************************* -* Software License Agreement (BSD License) * -* Author: Alexandre Westfahl * -* * -* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * -* * -* All rights reserved. * -* Based on ta_conf.y (Sebastien Decugis ) * -* * -* Redistribution and use of this software in source and binary forms, with or without modification, are * -* permitted provided that the following conditions are met: * -* * -* * Redistributions of source code must retain the above * -* copyright notice, this list of conditions and the * -* following disclaimer. * -* * -* * Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the * -* following disclaimer in the documentation and/or other * -* materials provided with the distribution. * -* * -* * Neither the name of the Teraoka Laboratory nor the * -* names of its contributors may be used to endorse or * -* promote products derived from this software without * -* specific prior written permission of Teraoka Laboratory * -* * -* * -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * -* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * -* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * -* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * -*********************************************************************************************************/ - - - -/* For development only : */ -%debug -%error-verbose - -/* The parser receives the configuration file filename as parameter */ -%parse-param {char * conffile} - -/* Keep track of location */ -%locations -%pure-parser - -%{ -#include "diamsip.h" -#include "diamsip.tab.h" /* bison is not smart enough to define the YYLTYPE before including this code, so... */ - -#include -#include - -/* Forward declaration */ -int yyparse(char * conffile); - -/* Parse the configuration file */ -int as_conf_handle(char * conffile) -{ - extern FILE * diamsipin; - int ret; - - TRACE_ENTRY("%p", conffile); - - TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile); - - diamsipin = fopen(conffile, "r"); - if (diamsipin == NULL) { - ret = errno; - fd_log_debug("Unable to open extension configuration file %s for reading: %s\n", conffile, strerror(ret)); - TRACE_DEBUG (INFO, "Error occurred, message logged -- configuration file."); - return ret; - } - - ret = yyparse(conffile); - - fclose(diamsipin); - - if (ret != 0) { - TRACE_DEBUG (INFO, "Unable to parse the configuration file."); - return EINVAL; - } - - return 0; -} - -/* The Lex parser prototype */ -int diamsiplex(YYSTYPE *lvalp, YYLTYPE *llocp); - -/* Function to report the errors */ -void yyerror (YYLTYPE *ploc, char * conffile, char const *s) -{ - TRACE_DEBUG(INFO, "Error in configuration parsing"); - - if (ploc->first_line != ploc->last_line) - fd_log_debug("%s:%d.%d-%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_line, ploc->last_column, s); - else if (ploc->first_column != ploc->last_column) - fd_log_debug("%s:%d.%d-%d : %s\n", conffile, ploc->first_line, ploc->first_column, ploc->last_column, s); - else - fd_log_debug("%s:%d.%d : %s\n", conffile, ploc->first_line, ploc->first_column, s); -} - -%} - -/* Values returned by lex for token */ -%union { - char *string; /* The string is allocated by strdup in lex.*/ - int integer; /* Store integer values */ -} - -/* In case of error in the lexical analysis */ -%token LEX_ERROR - -/* Key words */ -%token MODE -%token DATASOURCE -%token ASMYSQL_LOGIN -%token ASMYSQL_PASSWORD -%token ASMYSQL_DATABASE -%token ASMYSQL_SERVER -%token ASMYSQL_PORT - -/* Tokens and types for routing table definition */ -/* A (de)quoted string (malloc'd in lex parser; it must be freed after use) */ -%token QSTRING - -/* An integer value */ -%token INTEGER - - - -/* -------------------------------------- */ -%% - - /* The grammar definition */ -conffile: /* empty grammar is OK */ - | conffile mode - | conffile datasource - | conffile mysql_login - | conffile mysql_password - | conffile mysql_database - | conffile mysql_server - | conffile mysql_port - ; - -mode: MODE '=' INTEGER ';' - { - as_conf->mode = $3; - } - ; - -datasource: DATASOURCE '=' INTEGER ';' - { - as_conf->datasource = $3; - } - ; - -mysql_login: ASMYSQL_LOGIN '=' QSTRING ';' - { - free(as_conf->mysql_login); - as_conf->mysql_login = $3; - } - ; - -mysql_password: ASMYSQL_PASSWORD '=' QSTRING ';' - { - free(as_conf->mysql_password); - as_conf->mysql_password = $3; - } - ; - -mysql_database: ASMYSQL_DATABASE '=' QSTRING ';' - { - free(as_conf->mysql_database); - as_conf->mysql_database = $3; - } - ; - -mysql_server: ASMYSQL_SERVER '=' QSTRING ';' - { - free(as_conf->mysql_server); - as_conf->mysql_server = $3; - } - ; - -mysql_port: ASMYSQL_PORT '=' INTEGER ';' - { - as_conf->mysql_port = (uint16_t)$3; - } - ; diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/libapp_sip.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/app_sip/libapp_sip.c Wed Jul 28 14:34:48 2010 +0900 @@ -0,0 +1,1078 @@ +/********************************************************************************************************* +* Software License Agreement (BSD License) * +* Author: Alexandre Westfahl * +* * +* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * +* * +* All rights reserved. * +* * +* Redistribution and use of this software in source and binary forms, with or without modification, are * +* permitted provided that the following conditions are met: * +* * +* * Redistributions of source code must retain the above * +* copyright notice, this list of conditions and the * +* following disclaimer. * +* * +* * Redistributions in binary form must reproduce the above * +* copyright notice, this list of conditions and the * +* following disclaimer in the documentation and/or other * +* materials provided with the distribution. * +* * +* * Neither the name of the Teraoka Laboratory nor the * +* names of its contributors may be used to endorse or * +* promote products derived from this software without * +* specific prior written permission of Teraoka Laboratory * +* * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * +* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * +* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +*********************************************************************************************************/ +//#include +#include "app_sip.h" + +MYSQL *conn; + +void clear_digest(uint8_t * digest, char * readable_digest, int digestlength) +{ + int i=0; + for(i=0;iavp_code == dictdata.avp_code) && (nextavphdr->avp_vendor == dictdata.avp_vendor) ) // always 0 if no Vendor flag + { + break; + } + + // Otherwise move to next AVP in the grouped AVP + CHECK_FCT( fd_msg_browse(nextavp, MSG_BRW_NEXT, (void *)&nextavp, NULL) ); + + if(nextavp!=NULL) + { + CHECK_FCT( fd_msg_avp_hdr( nextavp, &nextavphdr ) ); + } + else + nextavphdr=NULL; + } + if (avp) + *avp = nextavp; + + if (avp && nextavp) { + struct dictionary * dict; + CHECK_FCT( fd_dict_getdict( what, &dict) ); + CHECK_FCT_DO( fd_msg_parse_dict( nextavp, dict, NULL ), ); + } + + if (avp || nextavp) + return 0; + else + return ENOENT; +} +struct avp_hdr *walk_digest(struct avp *avp, int avp_code) +{ + struct avp_hdr *temphdr=NULL; + CHECK_FCT_DO(fd_msg_browse ( avp, MSG_BRW_WALK, &avp, NULL),return NULL); + + while(avp!=NULL) + { + + CHECK_FCT_DO( fd_msg_avp_hdr( avp,&temphdr ),return NULL); + + if(temphdr->avp_code==avp_code) + { + //We found the AVP so we set avp to NULL to exit the loop + avp=NULL; + return temphdr; + + } + else if(temphdr->avp_code==380)//SIP-Authorization AVP + { + //We didn't found the AVP but we finished browsing the Authentication AVP + avp=NULL; + temphdr=NULL; + + return temphdr; + } + else + { + CHECK_FCT_DO(fd_msg_browse ( avp, MSG_BRW_WALK, &avp, NULL),return NULL); + temphdr=NULL; + + } + } + + return temphdr; +} + +int start_mysql_connection() +{ + conn = mysql_init(NULL); + + mysql_options(conn, MYSQL_OPT_RECONNECT, "true"); + + if (!mysql_real_connect(conn, as_conf->mysql_server,as_conf->mysql_login, as_conf->mysql_password, as_conf->mysql_database, as_conf->mysql_port, NULL, 0)) + {//TODO: display error from mysql + TRACE_DEBUG(INFO,"Unable to connect to database (%s) with login:%s",as_conf->mysql_database,as_conf->mysql_login); + return 1; + } + return 0; + +} + + +void request_mysql(char *query) +{ + //We check if the connection is still up + mysql_ping(conn); + + if (mysql_query(conn, query)) + { + TRACE_DEBUG(INFO,"Query %s failed", query); + + } + +} + +void close_mysql_connection() +{ + mysql_close(conn); + +} + +//If password is null, we just verify this user exist +//We don't need the password length because it is a table' +int get_password(const unsigned char *username, const size_t usernamelen, char *password) +{ + CHECK_PARAMS(username && usernamelen); + + int not_found=2; + size_t querylen, usernamepurelen; + char *query, *username_pure; + + switch(as_conf->datasource) + { + //MySQL + case ASMYSQL: + //We allocate the double size of username because at worst it can be all quotes + username_pure=malloc(usernamelen*2+1); + //We purify username not to have forbidden characters + usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); + + //We copy username in query + querylen=SQL_GETPASSWORD_LEN + usernamepurelen; + query = malloc(querylen+2); + snprintf(query, querylen+1, SQL_GETPASSWORD, username_pure); + + MYSQL_RES *res; + MYSQL_ROW row; + + //We make the query + request_mysql(query); + res=mysql_use_result(conn); + if(res==NULL) + { + if(password!=NULL) + password[0]='\0'; + free(query); + return 2; + } + + + + while ((row = mysql_fetch_row(res)) != NULL) + { + if(strlen(row[0])>0) + { + if(password!=NULL) + strcpy(password,row[0]); + + not_found=0; + break; + } + } + mysql_free_result(res); + free(query); + break; + } + return not_found; +} + +int check_sipaor(const unsigned char *username, const size_t usernamelen, const char * sip_aor,const size_t sipaorlen) +{ + CHECK_PARAMS(username && usernamelen && sip_aor && sipaorlen); + + int not_found=2; + size_t querylen, usernamepurelen; + char *query, *username_pure; + + switch(as_conf->datasource) + { + //MySQL + case ASMYSQL: + //We allocate the double size of username because at worst it can be all quotes + username_pure=malloc(usernamelen*2+1); + //We purify username not to have forbidden characters + usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); + + //We get the list of AOR owned by this user + querylen=SQL_GETSIPAOR_LEN + usernamepurelen; + query = malloc(querylen+2); + snprintf(query, querylen+1, SQL_GETSIPAOR, username_pure); + + MYSQL_RES *res; + MYSQL_ROW row; + + //We make the query + request_mysql(query); + res=mysql_use_result(conn); + if(res==NULL) + { + free(query); + return 2; + } + + + not_found=1; + while ((row = mysql_fetch_row(res)) != NULL) + { + if(strncmp((const char *)sip_aor,row[0],sipaorlen)==0) + { + not_found=0; + break; + } + } + mysql_free_result(res); + free(query); + break; + } + return not_found; +} + +int get_diameter_uri(const unsigned char *sip_aor, const size_t sipaorlen, char ** diameter_uri, size_t *diameterurilen) +{ + CHECK_PARAMS(sip_aor && sipaorlen); + + size_t querylen, sipaorpurelen; + char *query, *sipaor_pure; + int not_found=2; + + + + + //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars + if(sipaorlen<5) + return 2; + + //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security + switch(as_conf->datasource) + { + //MySQL + case ASMYSQL: + + querylen=SQL_GETDIAMURI_LEN + sipaorlen; + + + //We allocate the double size of SIP-URI because at worst it can be all quotes + CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); + //We purify SIP-URI not to have forbidden characters + sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); + + + query = malloc(querylen+sipaorpurelen+ 2); + snprintf(query, querylen+1, SQL_GETDIAMURI, sipaor_pure); + + MYSQL_RES *res; + MYSQL_ROW row; + + + //We make the query + request_mysql(query); + res=mysql_use_result(conn); + if(res==NULL) + { + //We couldn't make the request + diameter_uri=NULL; + return 2; + } + + while ((row = mysql_fetch_row(res)) != NULL) + { + *diameterurilen=strlen(row[0]); + if(*diameterurilen>0) + { + CHECK_MALLOC(*diameter_uri=malloc(*diameterurilen+1)); + strcpy(*diameter_uri,row[0]); + not_found=0; + break; + } + } + mysql_free_result(res); + free(query); + free(sipaor_pure); + break; + + default: + + //We must never go here, if so, we must stop diameter_sip + diameter_uri=NULL; + return 2; + + break; + } + + //0 if it was found + return not_found; + +} + + +int exist_username(const unsigned char *sip_aor, const size_t sipaorlen) +{ + CHECK_PARAMS(sip_aor && sipaorlen); + + size_t querylen, sipaorpurelen; + char *query, *sipaor_pure; + int not_found=1; + + //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars + if(sipaorlen<5) + return 2; + + //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security + + switch(as_conf->datasource) + { + //MySQL + case ASMYSQL: + + querylen=SQL_GETUSERNAME_LEN + sipaorlen; + + + //We allocate the double size of SIP-URI because at worst it can be all quotes + CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); + //We purify SIP-URI not to have forbidden characters + sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); + + + query = malloc(querylen+sipaorpurelen+ 2); + snprintf(query, querylen+1, SQL_GETUSERNAME, sipaor_pure); + + MYSQL_RES *res; + MYSQL_ROW row; + + + //We make the query + request_mysql(query); + res=mysql_use_result(conn); + if(res==NULL) + { + //We couldn't make the request + return 2; + } + + while ((row = mysql_fetch_row(res)) != NULL) + { + if(strlen(row[0])>0) + { + not_found=0; + break; + } + } + mysql_free_result(res); + free(query); + free(sipaor_pure); + break; + + default: + + //We must never go here, if so, we must stop diameter_sip + TRACE_DEBUG(INFO,"FATAL ERROR: the datasource is unknown, please check your config file!"); + return 2; + + break; + } + + //0 if it was found + return not_found; + +} + +//We check if this user can go in the given network +int allow_roaming(const unsigned char *username, const size_t usernamelen, const char * network,const size_t networklen) +{ + CHECK_PARAMS(username && usernamelen && network && networklen); + + int not_found=2; + size_t querylen, usernamepurelen; + char *query, *username_pure; + + switch(as_conf->datasource) + { + //MySQL + case ASMYSQL: + //We allocate the double size of username because at worst it can be all quotes + username_pure=malloc(usernamelen*2+1); + //We purify username not to have forbidden characters + usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); + + //We get the list of AOR owned by this user + querylen=SQL_GETUSERNET_LEN + usernamepurelen; + query = malloc(querylen+2); + snprintf(query, querylen+1, SQL_GETUSERNET, username_pure); + + + MYSQL_RES *res; + MYSQL_ROW row; + + + //We make the query + request_mysql(query); + res=mysql_use_result(conn); + if(res==NULL) + { + free(query); + return 2; + } + + + not_found=1; + while ((row = mysql_fetch_row(res)) != NULL) + { + if(strncmp((const char *)network,row[0],networklen)==0) + { + not_found=0; + break; + } + } + mysql_free_result(res); + free(query); + break; + } + return not_found; +} + +//SIP-Server-Capabilities for the SIP-AOR +int get_sipserver_cap(const unsigned char *sip_aor, const size_t sipaorlen, struct avp **capabilities) +{ + CHECK_PARAMS(sip_aor && sipaorlen && capabilities); + + size_t querylen, sipaorpurelen; + char *query, *sipaor_pure; + int not_found=2; + union avp_value value; + struct avp *avp; + + //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars + if(sipaorlen<5) + return 2; + + //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security + switch(as_conf->datasource) + { + //MySQL + case ASMYSQL: + + querylen=SQL_GETSIPSERCAP_LEN + sipaorlen; + + + //We allocate the double size of SIP-URI because at worst it can be all quotes + CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); + //We purify SIP-URI not to have forbidden characters + sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); + + + query = malloc(querylen+sipaorpurelen+ 2); + snprintf(query, querylen+1, SQL_GETSIPSERCAP, sipaor_pure); + + MYSQL_RES *res; + MYSQL_ROW row; + + //We make the query + request_mysql(query); + res=mysql_use_result(conn); + if(res==NULL) + { + //We couldn't make the request + return 2; + } + not_found=1; + while ((row = mysql_fetch_row(res)) != NULL) + { + if(atoi(row[0])==1) + {//mandatory + CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Mandatory_Capability, 0, &avp ) ); + value.i32=(uint32_t)atoi(row[1]); + CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); + CHECK_FCT( fd_msg_avp_add ( *capabilities, MSG_BRW_LAST_CHILD, avp) ); + + } + else + {//optional + CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Optional_Capability, 0, &avp ) ); + value.i32=(uint32_t)atoi(row[1]); + CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); + CHECK_FCT( fd_msg_avp_add ( *capabilities, MSG_BRW_LAST_CHILD, avp) ); + } + not_found=0; + } + + mysql_free_result(res); + free(query); + free(sipaor_pure); + break; + + default: + + //We must never go here, if so, we must stop diameter_sip + TRACE_DEBUG(INFO,"FATAL ERROR: the datasource is unknown, please check your config file!"); + return 2; + + break; + } + + //0 if it was found + return not_found; + +} + + +//We retrieve datatype +int add_user_datatype(const unsigned char *sip_aor, const size_t sipaorlen,struct msg *message) +{ + CHECK_PARAMS(sip_aor && sipaorlen && message ); + + size_t querylen, sipaorpurelen; + char *query, *sipaor_pure; + int not_found=2; + union avp_value value; + struct avp *avp, *rootavp; + unsigned long *length; + + //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars + if(sipaorlen<5) + return 2; + + //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security + switch(as_conf->datasource) + { + //MySQL + case ASMYSQL: + + querylen=SQL_GETSIPDATA_LEN + sipaorlen; + + + //We allocate the double size of SIP-URI because at worst it can be all quotes + CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); + //We purify SIP-URI not to have forbidden characters + sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); + + + query = malloc(querylen+sipaorpurelen+ 2); + snprintf(query, querylen+1, SQL_GETSIPDATA, sipaor_pure); + + MYSQL_RES *res; + MYSQL_ROW row; + + //We make the query + request_mysql(query); + res=mysql_use_result(conn); + if(res==NULL) + { + //We couldn't make the request + return 2; + } + not_found=1; + while ((row = mysql_fetch_row(res)) != NULL) + { + length=mysql_fetch_lengths(res); + + if(strlen(row[0])>1) + { + CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data, 0, &rootavp ) ); + + CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data_Type, 0, &avp ) ); + CHECK_MALLOC(value.os.data=malloc(length[0]*sizeof(unsigned char))); + strncpy((char *)value.os.data,(char *)row[0],length[0]); + value.os.len=(size_t)length[0]; + CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); + CHECK_FCT( fd_msg_avp_add ( rootavp, MSG_BRW_LAST_CHILD, avp) ); + + + + CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data_Contents, 0, &avp ) ); + CHECK_MALLOC(value.os.data=malloc(length[1]*sizeof(unsigned char))); + memcpy(value.os.data,row[1],length[1]); + value.os.len=(size_t)length[1]; + CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); + CHECK_FCT( fd_msg_avp_add ( rootavp, MSG_BRW_LAST_CHILD, avp) ); + + //We add SIP_User_Data to message + CHECK_FCT( fd_msg_avp_add ( message, MSG_BRW_LAST_CHILD, rootavp) ); + not_found=0; + } + + } + + mysql_free_result(res); + free(query); + free(sipaor_pure); + break; + + default: + + //We must never go here, if so, we must stop diameter_sip + TRACE_DEBUG(INFO,"FATAL ERROR: the datasource is unknown, please check your config file!"); + return 2; + + break; + } + + //0 if it was found + return not_found; + + + +} + +int set_pending_flag(const unsigned char *username, const size_t usernamelen) +{ + CHECK_PARAMS(username && usernamelen); + + + size_t querylen, usernamepurelen; + char *query, *username_pure; + + switch(as_conf->datasource) + { + //MySQL + case ASMYSQL: + //We allocate the double size of username because at worst it can be all quotes + username_pure=malloc(usernamelen*2+1); + //We purify username not to have forbidden characters + usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); + + + + //We clear the flag "authentication pending" + querylen=SQL_SETFLAG_LEN + usernamepurelen; + query = malloc(querylen+2); + snprintf(query, querylen+1, SQL_SETFLAG, username_pure); + + if (mysql_query(conn, query)) + { + TRACE_DEBUG(INFO,"Query %s failed", query); + free(query); + return 2; + } + + free(query); + break; + } + return 0; +} +int clear_pending_flag(const unsigned char *username, const size_t usernamelen) +{ + CHECK_PARAMS(username && usernamelen); + + + size_t querylen, usernamepurelen; + char *query, *username_pure; + + switch(as_conf->datasource) + { + //MySQL + case ASMYSQL: + //We allocate the double size of username because at worst it can be all quotes + username_pure=malloc(usernamelen*2+1); + //We purify username not to have forbidden characters + usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); + + + + //We clear the flag "authentication pending" + querylen=SQL_CLEARFLAG_LEN + usernamepurelen; + query = malloc(querylen+2); + snprintf(query, querylen+1, SQL_CLEARFLAG, username_pure); + + if (mysql_query(conn, query)) + { + TRACE_DEBUG(INFO,"Query %s failed", query); + free(query); + return 2; + } + + free(query); + break; + } + return 0; +} + + + +int set_sipserver_uri(const unsigned char *username, const size_t usernamelen, const unsigned char *sipserver_uri,const size_t sipserverurilen) +{ + CHECK_PARAMS(username && usernamelen && sipserver_uri && sipserverurilen); + + + size_t querylen, usernamepurelen, sipserveruripurelen; + char *query, *username_pure, *sipserveruri_pure; + + switch(as_conf->datasource) + { + //MySQL + case ASMYSQL: + //We allocate the double size of username because at worst it can be all quotes + username_pure=malloc(usernamelen*2+1); + //We purify username not to have forbidden characters + usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); + + //We allocate the double size of username because at worst it can be all quotes + sipserveruri_pure=malloc(sipserverurilen*2+1); + //We purify username not to have forbidden characters + sipserveruripurelen=mysql_real_escape_string(conn, sipserveruri_pure, (const char *)sipserver_uri, sipserverurilen); + + //We clear the flag "authentication pending" + querylen=SQL_SETSIPURI_LEN + usernamepurelen + sipserveruripurelen; + query = malloc(querylen+2); + snprintf(query, querylen+1, SQL_SETSIPURI, sipserveruri_pure,username_pure); + + if (mysql_query(conn, query)) + { + TRACE_DEBUG(INFO,"Query %s failed", query); + free(query); + return 2; + } + + free(query); + break; + } + return 0; +} +int remove_sipserver_uri(const unsigned char *sipserver_uri,const size_t sipserverurilen) +{ + CHECK_PARAMS(sipserver_uri && sipserverurilen); + + + size_t querylen, sipserveruripurelen; + char *query, *sipserveruri_pure; + + switch(as_conf->datasource) + { + //MySQL + case ASMYSQL: + //We allocate the double size of username because at worst it can be all quotes + sipserveruri_pure=malloc(sipserverurilen*2+1); + //We purify username not to have forbidden characters + sipserveruripurelen=mysql_real_escape_string(conn, sipserveruri_pure, (const char *)sipserver_uri, sipserverurilen); + + //We clear the flag "authentication pending" + querylen=SQL_RMSIPURI_LEN + sipserveruripurelen; + query = malloc(querylen+2); + snprintf(query, querylen+1, SQL_RMSIPURI, sipserveruri_pure); + + if (mysql_query(conn, query)) + { + TRACE_DEBUG(INFO,"Query %s failed", query); + free(query); + return 2; + } + + free(query); + break; + } + return 0; +} +int set_real_sipserver_uri(const unsigned char *username, const size_t usernamelen, const unsigned char *sipserver_uri,const size_t sipserverurilen) +{ + CHECK_PARAMS(username && usernamelen && sipserver_uri && sipserverurilen); + + + size_t querylen, usernamepurelen, sipserveruripurelen; + char *query, *username_pure, *sipserveruri_pure; + + switch(as_conf->datasource) + { + //MySQL + case ASMYSQL: + //We allocate the double size of username because at worst it can be all quotes + username_pure=malloc(usernamelen*2+1); + //We purify username not to have forbidden characters + usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); + + //We allocate the double size of username because at worst it can be all quotes + sipserveruri_pure=malloc(sipserverurilen*2+1); + //We purify username not to have forbidden characters + sipserveruripurelen=mysql_real_escape_string(conn, sipserveruri_pure, (const char *)sipserver_uri, sipserverurilen); + + //We clear the flag "authentication pending" + querylen=SQL_SETREALSIPURI_LEN + usernamepurelen + sipserveruripurelen; + query = malloc(querylen+2); + snprintf(query, querylen+1, SQL_SETREALSIPURI, sipserveruri_pure,username_pure); + + if (mysql_query(conn, query)) + { + TRACE_DEBUG(INFO,"Query %s failed", query); + free(query); + return 2; + } + + free(query); + break; + } + return 0; +} + +int get_sipserver_uri(const unsigned char *sip_aor, const size_t sipaorlen, unsigned char ** sipserver_uri, size_t *sipserverurilen) +{ + CHECK_PARAMS(sip_aor && sipaorlen && sipserver_uri && sipserverurilen ); + + size_t querylen, sipaorpurelen; + char *query, *sipaor_pure; + int not_found=2; + + + + + //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars + if(sipaorlen<5) + return 2; + + //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security + + switch(as_conf->datasource) + { + //MySQL + case ASMYSQL: + + querylen=SQL_GETSIPSERURI_LEN + sipaorlen; + + //We allocate the double size of SIP-URI because at worst it can be all quotes + CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); + //We purify SIP-URI not to have forbidden characters + sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); + + + query = malloc(querylen+sipaorpurelen+ 2); + snprintf(query, querylen+1, SQL_GETSIPSERURI, sipaor_pure); + + MYSQL_RES *res; + MYSQL_ROW row; + + //We make the query + request_mysql(query); + res=mysql_use_result(conn); + if(res==NULL) + { + //We couldn't make the request + sipserver_uri=NULL; + return 2; + } + + not_found=1; + while ((row = mysql_fetch_row(res)) != NULL) + { + *sipserverurilen=strlen(row[0]); + if(*sipserverurilen>4) + { + CHECK_MALLOC(*sipserver_uri=malloc(*sipserverurilen+1)); + strcpy((char *)*sipserver_uri,row[0]); + not_found=0; + break; + } + } + mysql_free_result(res); + free(query); + free(sipaor_pure); + break; + + default: + + //We must never go here, if so, we must stop diameter_sip + TRACE_DEBUG(INFO,"FATAL ERROR: the datasource is unknown, please check your config file!"); + sipserver_uri=NULL; + return 2; + + break; + } + + //0 if it was found + return not_found; + +} + + +int count_avp(struct msg * message, int code, int vendor) +{ + CHECK_PARAMS(message); + + struct avp_hdr *temphdr; + struct avp *avp; + int counter=0; + + CHECK_FCT(fd_msg_browse (message, MSG_BRW_WALK, &avp, NULL)); + + while(avp!=NULL) + { + + CHECK_FCT( fd_msg_avp_hdr( avp,&temphdr )); + + if(temphdr->avp_code==code && temphdr->avp_vendor==vendor) + { + counter++; + } + + CHECK_FCT(fd_msg_browse (avp, MSG_BRW_WALK, &avp, NULL)); + } + return counter; +} +/* +void nonce_add_element(char * nonce) +{ + noncechain *newelt=malloc(sizeof(noncechain)); + + newelt->nonce=nonce; + + newelt->timestamp=(int)time(NULL); + newelt->next=NULL; + + if(listnonce==NULL) + { + listnonce=newelt; + } + else + { + noncechain* temp=listnonce; + + while(temp->next != NULL) + { + if(temp->timestamp < ((int)time(NULL)-300)) + { + listnonce=temp->next; + free(temp); + temp=listnonce; + } + temp = temp->next; + } + temp->next = newelt; + } + +} +void nonce_del_element(char * nonce) +{ + if(listnonce!=NULL) + { + noncechain *temp=listnonce, *tempbefore=NULL; + + if(listnonce->next==NULL && strcmp(listnonce->nonce,nonce)==0) + { + free(listnonce); + listnonce=NULL; + return; + } + while(temp->next != NULL) + { + if(strcmp(temp->nonce,nonce)==0) + { + if(tempbefore==NULL) + { + listnonce=temp->next; + free(temp); + return; + } + tempbefore->next=temp->next; + free(temp); + break; + } + tempbefore=temp; + temp = temp->next; + } + + } + +} +int nonce_check_element(char * nonce) +{ + if(listnonce==NULL) + { + //Not found + return 0; + } + else + { + noncechain* temp=listnonce; + + while(temp->next != NULL) + { + if(strcmp(temp->nonce,nonce)==0) + return 1; + else + temp = temp->next; + } + } + return 0; +} + +void nonce_deletelistnonce() +{ + if(listnonce !=NULL) + { + noncechain* temp=listnonce; + + while(listnonce->next != NULL) + { + temp = listnonce->next; + + free(listnonce); + + listnonce=temp; + } + free(listnonce); + } +} +*/ diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/libdiamsip.c --- a/extensions/app_sip/libdiamsip.c Wed Jul 28 03:14:11 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1078 +0,0 @@ -/********************************************************************************************************* -* Software License Agreement (BSD License) * -* Author: Alexandre Westfahl * -* * -* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * -* * -* All rights reserved. * -* * -* Redistribution and use of this software in source and binary forms, with or without modification, are * -* permitted provided that the following conditions are met: * -* * -* * Redistributions of source code must retain the above * -* copyright notice, this list of conditions and the * -* following disclaimer. * -* * -* * Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the * -* following disclaimer in the documentation and/or other * -* materials provided with the distribution. * -* * -* * Neither the name of the Teraoka Laboratory nor the * -* names of its contributors may be used to endorse or * -* promote products derived from this software without * -* specific prior written permission of Teraoka Laboratory * -* * -* * -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * -* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * -* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * -* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * -*********************************************************************************************************/ -//#include -#include "diamsip.h" - -MYSQL *conn; - -void clear_digest(uint8_t * digest, char * readable_digest, int digestlength) -{ - int i=0; - for(i=0;iavp_code == dictdata.avp_code) && (nextavphdr->avp_vendor == dictdata.avp_vendor) ) // always 0 if no Vendor flag - { - break; - } - - // Otherwise move to next AVP in the grouped AVP - CHECK_FCT( fd_msg_browse(nextavp, MSG_BRW_NEXT, (void *)&nextavp, NULL) ); - - if(nextavp!=NULL) - { - CHECK_FCT( fd_msg_avp_hdr( nextavp, &nextavphdr ) ); - } - else - nextavphdr=NULL; - } - if (avp) - *avp = nextavp; - - if (avp && nextavp) { - struct dictionary * dict; - CHECK_FCT( fd_dict_getdict( what, &dict) ); - CHECK_FCT_DO( fd_msg_parse_dict( nextavp, dict, NULL ), ); - } - - if (avp || nextavp) - return 0; - else - return ENOENT; -} -struct avp_hdr *walk_digest(struct avp *avp, int avp_code) -{ - struct avp_hdr *temphdr=NULL; - CHECK_FCT_DO(fd_msg_browse ( avp, MSG_BRW_WALK, &avp, NULL),return NULL); - - while(avp!=NULL) - { - - CHECK_FCT_DO( fd_msg_avp_hdr( avp,&temphdr ),return NULL); - - if(temphdr->avp_code==avp_code) - { - //We found the AVP so we set avp to NULL to exit the loop - avp=NULL; - return temphdr; - - } - else if(temphdr->avp_code==380)//SIP-Authorization AVP - { - //We didn't found the AVP but we finished browsing the Authentication AVP - avp=NULL; - temphdr=NULL; - - return temphdr; - } - else - { - CHECK_FCT_DO(fd_msg_browse ( avp, MSG_BRW_WALK, &avp, NULL),return NULL); - temphdr=NULL; - - } - } - - return temphdr; -} - -int start_mysql_connection() -{ - conn = mysql_init(NULL); - - mysql_options(conn, MYSQL_OPT_RECONNECT, "true"); - - if (!mysql_real_connect(conn, as_conf->mysql_server,as_conf->mysql_login, as_conf->mysql_password, as_conf->mysql_database, as_conf->mysql_port, NULL, 0)) - {//TODO: display error from mysql - TRACE_DEBUG(INFO,"Unable to connect to database (%s) with login:%s",as_conf->mysql_database,as_conf->mysql_login); - return 1; - } - return 0; - -} - - -void request_mysql(char *query) -{ - //We check if the connection is still up - mysql_ping(conn); - - if (mysql_query(conn, query)) - { - TRACE_DEBUG(INFO,"Query %s failed", query); - - } - -} - -void close_mysql_connection() -{ - mysql_close(conn); - -} - -//If password is null, we just verify this user exist -//We don't need the password length because it is a table' -int get_password(const unsigned char *username, const size_t usernamelen, char *password) -{ - CHECK_PARAMS(username && usernamelen); - - int not_found=2; - size_t querylen, usernamepurelen; - char *query, *username_pure; - - switch(as_conf->datasource) - { - //MySQL - case ASMYSQL: - //We allocate the double size of username because at worst it can be all quotes - username_pure=malloc(usernamelen*2+1); - //We purify username not to have forbidden characters - usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); - - //We copy username in query - querylen=SQL_GETPASSWORD_LEN + usernamepurelen; - query = malloc(querylen+2); - snprintf(query, querylen+1, SQL_GETPASSWORD, username_pure); - - MYSQL_RES *res; - MYSQL_ROW row; - - //We make the query - request_mysql(query); - res=mysql_use_result(conn); - if(res==NULL) - { - if(password!=NULL) - password[0]='\0'; - free(query); - return 2; - } - - - - while ((row = mysql_fetch_row(res)) != NULL) - { - if(strlen(row[0])>0) - { - if(password!=NULL) - strcpy(password,row[0]); - - not_found=0; - break; - } - } - mysql_free_result(res); - free(query); - break; - } - return not_found; -} - -int check_sipaor(const unsigned char *username, const size_t usernamelen, const char * sip_aor,const size_t sipaorlen) -{ - CHECK_PARAMS(username && usernamelen && sip_aor && sipaorlen); - - int not_found=2; - size_t querylen, usernamepurelen; - char *query, *username_pure; - - switch(as_conf->datasource) - { - //MySQL - case ASMYSQL: - //We allocate the double size of username because at worst it can be all quotes - username_pure=malloc(usernamelen*2+1); - //We purify username not to have forbidden characters - usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); - - //We get the list of AOR owned by this user - querylen=SQL_GETSIPAOR_LEN + usernamepurelen; - query = malloc(querylen+2); - snprintf(query, querylen+1, SQL_GETSIPAOR, username_pure); - - MYSQL_RES *res; - MYSQL_ROW row; - - //We make the query - request_mysql(query); - res=mysql_use_result(conn); - if(res==NULL) - { - free(query); - return 2; - } - - - not_found=1; - while ((row = mysql_fetch_row(res)) != NULL) - { - if(strncmp((const char *)sip_aor,row[0],sipaorlen)==0) - { - not_found=0; - break; - } - } - mysql_free_result(res); - free(query); - break; - } - return not_found; -} - -int get_diameter_uri(const unsigned char *sip_aor, const size_t sipaorlen, char ** diameter_uri, size_t *diameterurilen) -{ - CHECK_PARAMS(sip_aor && sipaorlen); - - size_t querylen, sipaorpurelen; - char *query, *sipaor_pure; - int not_found=2; - - - - - //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars - if(sipaorlen<5) - return 2; - - //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security - switch(as_conf->datasource) - { - //MySQL - case ASMYSQL: - - querylen=SQL_GETDIAMURI_LEN + sipaorlen; - - - //We allocate the double size of SIP-URI because at worst it can be all quotes - CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); - //We purify SIP-URI not to have forbidden characters - sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); - - - query = malloc(querylen+sipaorpurelen+ 2); - snprintf(query, querylen+1, SQL_GETDIAMURI, sipaor_pure); - - MYSQL_RES *res; - MYSQL_ROW row; - - - //We make the query - request_mysql(query); - res=mysql_use_result(conn); - if(res==NULL) - { - //We couldn't make the request - diameter_uri=NULL; - return 2; - } - - while ((row = mysql_fetch_row(res)) != NULL) - { - *diameterurilen=strlen(row[0]); - if(*diameterurilen>0) - { - CHECK_MALLOC(*diameter_uri=malloc(*diameterurilen+1)); - strcpy(*diameter_uri,row[0]); - not_found=0; - break; - } - } - mysql_free_result(res); - free(query); - free(sipaor_pure); - break; - - default: - - //We must never go here, if so, we must stop diameter_sip - diameter_uri=NULL; - return 2; - - break; - } - - //0 if it was found - return not_found; - -} - - -int exist_username(const unsigned char *sip_aor, const size_t sipaorlen) -{ - CHECK_PARAMS(sip_aor && sipaorlen); - - size_t querylen, sipaorpurelen; - char *query, *sipaor_pure; - int not_found=1; - - //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars - if(sipaorlen<5) - return 2; - - //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security - - switch(as_conf->datasource) - { - //MySQL - case ASMYSQL: - - querylen=SQL_GETUSERNAME_LEN + sipaorlen; - - - //We allocate the double size of SIP-URI because at worst it can be all quotes - CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); - //We purify SIP-URI not to have forbidden characters - sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); - - - query = malloc(querylen+sipaorpurelen+ 2); - snprintf(query, querylen+1, SQL_GETUSERNAME, sipaor_pure); - - MYSQL_RES *res; - MYSQL_ROW row; - - - //We make the query - request_mysql(query); - res=mysql_use_result(conn); - if(res==NULL) - { - //We couldn't make the request - return 2; - } - - while ((row = mysql_fetch_row(res)) != NULL) - { - if(strlen(row[0])>0) - { - not_found=0; - break; - } - } - mysql_free_result(res); - free(query); - free(sipaor_pure); - break; - - default: - - //We must never go here, if so, we must stop diameter_sip - TRACE_DEBUG(INFO,"FATAL ERROR: the datasource is unknown, please check your config file!"); - return 2; - - break; - } - - //0 if it was found - return not_found; - -} - -//We check if this user can go in the given network -int allow_roaming(const unsigned char *username, const size_t usernamelen, const char * network,const size_t networklen) -{ - CHECK_PARAMS(username && usernamelen && network && networklen); - - int not_found=2; - size_t querylen, usernamepurelen; - char *query, *username_pure; - - switch(as_conf->datasource) - { - //MySQL - case ASMYSQL: - //We allocate the double size of username because at worst it can be all quotes - username_pure=malloc(usernamelen*2+1); - //We purify username not to have forbidden characters - usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); - - //We get the list of AOR owned by this user - querylen=SQL_GETUSERNET_LEN + usernamepurelen; - query = malloc(querylen+2); - snprintf(query, querylen+1, SQL_GETUSERNET, username_pure); - - - MYSQL_RES *res; - MYSQL_ROW row; - - - //We make the query - request_mysql(query); - res=mysql_use_result(conn); - if(res==NULL) - { - free(query); - return 2; - } - - - not_found=1; - while ((row = mysql_fetch_row(res)) != NULL) - { - if(strncmp((const char *)network,row[0],networklen)==0) - { - not_found=0; - break; - } - } - mysql_free_result(res); - free(query); - break; - } - return not_found; -} - -//SIP-Server-Capabilities for the SIP-AOR -int get_sipserver_cap(const unsigned char *sip_aor, const size_t sipaorlen, struct avp **capabilities) -{ - CHECK_PARAMS(sip_aor && sipaorlen && capabilities); - - size_t querylen, sipaorpurelen; - char *query, *sipaor_pure; - int not_found=2; - union avp_value value; - struct avp *avp; - - //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars - if(sipaorlen<5) - return 2; - - //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security - switch(as_conf->datasource) - { - //MySQL - case ASMYSQL: - - querylen=SQL_GETSIPSERCAP_LEN + sipaorlen; - - - //We allocate the double size of SIP-URI because at worst it can be all quotes - CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); - //We purify SIP-URI not to have forbidden characters - sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); - - - query = malloc(querylen+sipaorpurelen+ 2); - snprintf(query, querylen+1, SQL_GETSIPSERCAP, sipaor_pure); - - MYSQL_RES *res; - MYSQL_ROW row; - - //We make the query - request_mysql(query); - res=mysql_use_result(conn); - if(res==NULL) - { - //We couldn't make the request - return 2; - } - not_found=1; - while ((row = mysql_fetch_row(res)) != NULL) - { - if(atoi(row[0])==1) - {//mandatory - CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Mandatory_Capability, 0, &avp ) ); - value.i32=(uint32_t)atoi(row[1]); - CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); - CHECK_FCT( fd_msg_avp_add ( *capabilities, MSG_BRW_LAST_CHILD, avp) ); - - } - else - {//optional - CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Optional_Capability, 0, &avp ) ); - value.i32=(uint32_t)atoi(row[1]); - CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); - CHECK_FCT( fd_msg_avp_add ( *capabilities, MSG_BRW_LAST_CHILD, avp) ); - } - not_found=0; - } - - mysql_free_result(res); - free(query); - free(sipaor_pure); - break; - - default: - - //We must never go here, if so, we must stop diameter_sip - TRACE_DEBUG(INFO,"FATAL ERROR: the datasource is unknown, please check your config file!"); - return 2; - - break; - } - - //0 if it was found - return not_found; - -} - - -//We retrieve datatype -int add_user_datatype(const unsigned char *sip_aor, const size_t sipaorlen,struct msg *message) -{ - CHECK_PARAMS(sip_aor && sipaorlen && message ); - - size_t querylen, sipaorpurelen; - char *query, *sipaor_pure; - int not_found=2; - union avp_value value; - struct avp *avp, *rootavp; - unsigned long *length; - - //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars - if(sipaorlen<5) - return 2; - - //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security - switch(as_conf->datasource) - { - //MySQL - case ASMYSQL: - - querylen=SQL_GETSIPDATA_LEN + sipaorlen; - - - //We allocate the double size of SIP-URI because at worst it can be all quotes - CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); - //We purify SIP-URI not to have forbidden characters - sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); - - - query = malloc(querylen+sipaorpurelen+ 2); - snprintf(query, querylen+1, SQL_GETSIPDATA, sipaor_pure); - - MYSQL_RES *res; - MYSQL_ROW row; - - //We make the query - request_mysql(query); - res=mysql_use_result(conn); - if(res==NULL) - { - //We couldn't make the request - return 2; - } - not_found=1; - while ((row = mysql_fetch_row(res)) != NULL) - { - length=mysql_fetch_lengths(res); - - if(strlen(row[0])>1) - { - CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data, 0, &rootavp ) ); - - CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data_Type, 0, &avp ) ); - CHECK_MALLOC(value.os.data=malloc(length[0]*sizeof(unsigned char))); - strncpy((char *)value.os.data,(char *)row[0],length[0]); - value.os.len=(size_t)length[0]; - CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); - CHECK_FCT( fd_msg_avp_add ( rootavp, MSG_BRW_LAST_CHILD, avp) ); - - - - CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data_Contents, 0, &avp ) ); - CHECK_MALLOC(value.os.data=malloc(length[1]*sizeof(unsigned char))); - memcpy(value.os.data,row[1],length[1]); - value.os.len=(size_t)length[1]; - CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); - CHECK_FCT( fd_msg_avp_add ( rootavp, MSG_BRW_LAST_CHILD, avp) ); - - //We add SIP_User_Data to message - CHECK_FCT( fd_msg_avp_add ( message, MSG_BRW_LAST_CHILD, rootavp) ); - not_found=0; - } - - } - - mysql_free_result(res); - free(query); - free(sipaor_pure); - break; - - default: - - //We must never go here, if so, we must stop diameter_sip - TRACE_DEBUG(INFO,"FATAL ERROR: the datasource is unknown, please check your config file!"); - return 2; - - break; - } - - //0 if it was found - return not_found; - - - -} - -int set_pending_flag(const unsigned char *username, const size_t usernamelen) -{ - CHECK_PARAMS(username && usernamelen); - - - size_t querylen, usernamepurelen; - char *query, *username_pure; - - switch(as_conf->datasource) - { - //MySQL - case ASMYSQL: - //We allocate the double size of username because at worst it can be all quotes - username_pure=malloc(usernamelen*2+1); - //We purify username not to have forbidden characters - usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); - - - - //We clear the flag "authentication pending" - querylen=SQL_SETFLAG_LEN + usernamepurelen; - query = malloc(querylen+2); - snprintf(query, querylen+1, SQL_SETFLAG, username_pure); - - if (mysql_query(conn, query)) - { - TRACE_DEBUG(INFO,"Query %s failed", query); - free(query); - return 2; - } - - free(query); - break; - } - return 0; -} -int clear_pending_flag(const unsigned char *username, const size_t usernamelen) -{ - CHECK_PARAMS(username && usernamelen); - - - size_t querylen, usernamepurelen; - char *query, *username_pure; - - switch(as_conf->datasource) - { - //MySQL - case ASMYSQL: - //We allocate the double size of username because at worst it can be all quotes - username_pure=malloc(usernamelen*2+1); - //We purify username not to have forbidden characters - usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); - - - - //We clear the flag "authentication pending" - querylen=SQL_CLEARFLAG_LEN + usernamepurelen; - query = malloc(querylen+2); - snprintf(query, querylen+1, SQL_CLEARFLAG, username_pure); - - if (mysql_query(conn, query)) - { - TRACE_DEBUG(INFO,"Query %s failed", query); - free(query); - return 2; - } - - free(query); - break; - } - return 0; -} - - - -int set_sipserver_uri(const unsigned char *username, const size_t usernamelen, const unsigned char *sipserver_uri,const size_t sipserverurilen) -{ - CHECK_PARAMS(username && usernamelen && sipserver_uri && sipserverurilen); - - - size_t querylen, usernamepurelen, sipserveruripurelen; - char *query, *username_pure, *sipserveruri_pure; - - switch(as_conf->datasource) - { - //MySQL - case ASMYSQL: - //We allocate the double size of username because at worst it can be all quotes - username_pure=malloc(usernamelen*2+1); - //We purify username not to have forbidden characters - usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); - - //We allocate the double size of username because at worst it can be all quotes - sipserveruri_pure=malloc(sipserverurilen*2+1); - //We purify username not to have forbidden characters - sipserveruripurelen=mysql_real_escape_string(conn, sipserveruri_pure, (const char *)sipserver_uri, sipserverurilen); - - //We clear the flag "authentication pending" - querylen=SQL_SETSIPURI_LEN + usernamepurelen + sipserveruripurelen; - query = malloc(querylen+2); - snprintf(query, querylen+1, SQL_SETSIPURI, sipserveruri_pure,username_pure); - - if (mysql_query(conn, query)) - { - TRACE_DEBUG(INFO,"Query %s failed", query); - free(query); - return 2; - } - - free(query); - break; - } - return 0; -} -int remove_sipserver_uri(const unsigned char *sipserver_uri,const size_t sipserverurilen) -{ - CHECK_PARAMS(sipserver_uri && sipserverurilen); - - - size_t querylen, sipserveruripurelen; - char *query, *sipserveruri_pure; - - switch(as_conf->datasource) - { - //MySQL - case ASMYSQL: - //We allocate the double size of username because at worst it can be all quotes - sipserveruri_pure=malloc(sipserverurilen*2+1); - //We purify username not to have forbidden characters - sipserveruripurelen=mysql_real_escape_string(conn, sipserveruri_pure, (const char *)sipserver_uri, sipserverurilen); - - //We clear the flag "authentication pending" - querylen=SQL_RMSIPURI_LEN + sipserveruripurelen; - query = malloc(querylen+2); - snprintf(query, querylen+1, SQL_RMSIPURI, sipserveruri_pure); - - if (mysql_query(conn, query)) - { - TRACE_DEBUG(INFO,"Query %s failed", query); - free(query); - return 2; - } - - free(query); - break; - } - return 0; -} -int set_real_sipserver_uri(const unsigned char *username, const size_t usernamelen, const unsigned char *sipserver_uri,const size_t sipserverurilen) -{ - CHECK_PARAMS(username && usernamelen && sipserver_uri && sipserverurilen); - - - size_t querylen, usernamepurelen, sipserveruripurelen; - char *query, *username_pure, *sipserveruri_pure; - - switch(as_conf->datasource) - { - //MySQL - case ASMYSQL: - //We allocate the double size of username because at worst it can be all quotes - username_pure=malloc(usernamelen*2+1); - //We purify username not to have forbidden characters - usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); - - //We allocate the double size of username because at worst it can be all quotes - sipserveruri_pure=malloc(sipserverurilen*2+1); - //We purify username not to have forbidden characters - sipserveruripurelen=mysql_real_escape_string(conn, sipserveruri_pure, (const char *)sipserver_uri, sipserverurilen); - - //We clear the flag "authentication pending" - querylen=SQL_SETREALSIPURI_LEN + usernamepurelen + sipserveruripurelen; - query = malloc(querylen+2); - snprintf(query, querylen+1, SQL_SETREALSIPURI, sipserveruri_pure,username_pure); - - if (mysql_query(conn, query)) - { - TRACE_DEBUG(INFO,"Query %s failed", query); - free(query); - return 2; - } - - free(query); - break; - } - return 0; -} - -int get_sipserver_uri(const unsigned char *sip_aor, const size_t sipaorlen, unsigned char ** sipserver_uri, size_t *sipserverurilen) -{ - CHECK_PARAMS(sip_aor && sipaorlen && sipserver_uri && sipserverurilen ); - - size_t querylen, sipaorpurelen; - char *query, *sipaor_pure; - int not_found=2; - - - - - //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars - if(sipaorlen<5) - return 2; - - //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security - - switch(as_conf->datasource) - { - //MySQL - case ASMYSQL: - - querylen=SQL_GETSIPSERURI_LEN + sipaorlen; - - //We allocate the double size of SIP-URI because at worst it can be all quotes - CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); - //We purify SIP-URI not to have forbidden characters - sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); - - - query = malloc(querylen+sipaorpurelen+ 2); - snprintf(query, querylen+1, SQL_GETSIPSERURI, sipaor_pure); - - MYSQL_RES *res; - MYSQL_ROW row; - - //We make the query - request_mysql(query); - res=mysql_use_result(conn); - if(res==NULL) - { - //We couldn't make the request - sipserver_uri=NULL; - return 2; - } - - not_found=1; - while ((row = mysql_fetch_row(res)) != NULL) - { - *sipserverurilen=strlen(row[0]); - if(*sipserverurilen>4) - { - CHECK_MALLOC(*sipserver_uri=malloc(*sipserverurilen+1)); - strcpy((char *)*sipserver_uri,row[0]); - not_found=0; - break; - } - } - mysql_free_result(res); - free(query); - free(sipaor_pure); - break; - - default: - - //We must never go here, if so, we must stop diameter_sip - TRACE_DEBUG(INFO,"FATAL ERROR: the datasource is unknown, please check your config file!"); - sipserver_uri=NULL; - return 2; - - break; - } - - //0 if it was found - return not_found; - -} - - -int count_avp(struct msg * message, int code, int vendor) -{ - CHECK_PARAMS(message); - - struct avp_hdr *temphdr; - struct avp *avp; - int counter=0; - - CHECK_FCT(fd_msg_browse (message, MSG_BRW_WALK, &avp, NULL)); - - while(avp!=NULL) - { - - CHECK_FCT( fd_msg_avp_hdr( avp,&temphdr )); - - if(temphdr->avp_code==code && temphdr->avp_vendor==vendor) - { - counter++; - } - - CHECK_FCT(fd_msg_browse (avp, MSG_BRW_WALK, &avp, NULL)); - } - return counter; -} -/* -void nonce_add_element(char * nonce) -{ - noncechain *newelt=malloc(sizeof(noncechain)); - - newelt->nonce=nonce; - - newelt->timestamp=(int)time(NULL); - newelt->next=NULL; - - if(listnonce==NULL) - { - listnonce=newelt; - } - else - { - noncechain* temp=listnonce; - - while(temp->next != NULL) - { - if(temp->timestamp < ((int)time(NULL)-300)) - { - listnonce=temp->next; - free(temp); - temp=listnonce; - } - temp = temp->next; - } - temp->next = newelt; - } - -} -void nonce_del_element(char * nonce) -{ - if(listnonce!=NULL) - { - noncechain *temp=listnonce, *tempbefore=NULL; - - if(listnonce->next==NULL && strcmp(listnonce->nonce,nonce)==0) - { - free(listnonce); - listnonce=NULL; - return; - } - while(temp->next != NULL) - { - if(strcmp(temp->nonce,nonce)==0) - { - if(tempbefore==NULL) - { - listnonce=temp->next; - free(temp); - return; - } - tempbefore->next=temp->next; - free(temp); - break; - } - tempbefore=temp; - temp = temp->next; - } - - } - -} -int nonce_check_element(char * nonce) -{ - if(listnonce==NULL) - { - //Not found - return 0; - } - else - { - noncechain* temp=listnonce; - - while(temp->next != NULL) - { - if(strcmp(temp->nonce,nonce)==0) - return 1; - else - temp = temp->next; - } - } - return 0; -} - -void nonce_deletelistnonce() -{ - if(listnonce !=NULL) - { - noncechain* temp=listnonce; - - while(listnonce->next != NULL) - { - temp = listnonce->next; - - free(listnonce); - - listnonce=temp; - } - free(listnonce); - } -} -*/ diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/locationinfo.c --- a/extensions/app_sip/locationinfo.c Wed Jul 28 03:14:11 2010 +0900 +++ b/extensions/app_sip/locationinfo.c Wed Jul 28 14:34:48 2010 +0900 @@ -33,10 +33,10 @@ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *********************************************************************************************************/ -#include "diamsip.h" +#include "app_sip.h" -int diamsip_LIR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act) +int app_sip_LIR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act) { TRACE_ENTRY("%p %p %p %p", msg, paramavp, sess, act); diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/locationinfosl.c --- a/extensions/app_sip/locationinfosl.c Wed Jul 28 03:14:11 2010 +0900 +++ b/extensions/app_sip/locationinfosl.c Wed Jul 28 14:34:48 2010 +0900 @@ -33,10 +33,10 @@ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *********************************************************************************************************/ -#include "diamsip.h" +#include "app_sip.h" //This callback is specific to SUSCRIBER LOCATOR. We must look for the "serving" SIP server -int diamsipSL_LIR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act) +int app_sip_SL_LIR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act) { TRACE_ENTRY("%p %p %p %p", msg, paramavp, sess, act); diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/md5.c --- a/extensions/app_sip/md5.c Wed Jul 28 03:14:11 2010 +0900 +++ b/extensions/app_sip/md5.c Wed Jul 28 14:34:48 2010 +0900 @@ -7,7 +7,7 @@ */ /*********************************************************************************/ -#include"diamsip.h" +#include"app_sip.h" /* * MD5 hash implementation and interface functions diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/multimediaauth.c --- a/extensions/app_sip/multimediaauth.c Wed Jul 28 03:14:11 2010 +0900 +++ b/extensions/app_sip/multimediaauth.c Wed Jul 28 14:34:48 2010 +0900 @@ -33,10 +33,10 @@ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *********************************************************************************************************/ -#include "diamsip.h" +#include "app_sip.h" -int diamsip_MAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act) +int app_sip_MAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act) { struct msg *ans, *qry; struct avp *avp, *a2, *authdataitem; diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/pushprofile.c --- a/extensions/app_sip/pushprofile.c Wed Jul 28 03:14:11 2010 +0900 +++ b/extensions/app_sip/pushprofile.c Wed Jul 28 14:34:48 2010 +0900 @@ -33,7 +33,7 @@ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *********************************************************************************************************/ -#include "diamsip.h" +#include "app_sip.h" #include #include #include @@ -76,7 +76,7 @@ if(rcvbytes>-1) { //We received something, we can send an PPR - diamsip_PPR_cb(pprsip); + app_sip_PPR_cb(pprsip); } } } @@ -91,7 +91,7 @@ } //Called to send a PPR -int diamsip_PPR_cb(struct pprsipaor structure) +int app_sip_PPR_cb(struct pprsipaor structure) { /* TRACE_ENTRY("%p", structure); @@ -254,7 +254,7 @@ } //Called when an PPA arrive -int diamsip_PPA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act) +int app_sip_PPA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act) { //TODO: PPA reception /* diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/registrationtermination.c --- a/extensions/app_sip/registrationtermination.c Wed Jul 28 03:14:11 2010 +0900 +++ b/extensions/app_sip/registrationtermination.c Wed Jul 28 14:34:48 2010 +0900 @@ -33,7 +33,7 @@ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *********************************************************************************************************/ -#include "diamsip.h" +#include "app_sip.h" #include #include #include @@ -74,7 +74,7 @@ if(rcvbytes>-1) { //We received something, we can send an RTR - diamsip_RTR_cb(rtrsip); + app_sip_RTR_cb(rtrsip); } } } @@ -87,7 +87,7 @@ } //Called to send a RTR -int diamsip_RTR_cb(struct rtrsipaor structure) +int app_sip_RTR_cb(struct rtrsipaor structure) { TRACE_ENTRY("%p", structure); @@ -257,7 +257,7 @@ } //Called when an RTA arrive -int diamsip_RTA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act) +int app_sip_RTA_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act) { //TODO: RTA reception /* diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/serverassignment.c --- a/extensions/app_sip/serverassignment.c Wed Jul 28 03:14:11 2010 +0900 +++ b/extensions/app_sip/serverassignment.c Wed Jul 28 14:34:48 2010 +0900 @@ -33,10 +33,10 @@ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *********************************************************************************************************/ -#include "diamsip.h" +#include "app_sip.h" -int diamsip_SAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act) +int app_sip_SAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act) { TRACE_ENTRY("%p %p %p %p", msg, paramavp, sess, act); diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/tools/app_sip_rtr.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/app_sip/tools/app_sip_rtr.c Wed Jul 28 14:34:48 2010 +0900 @@ -0,0 +1,290 @@ +/********************************************************************************************************* +* Software License Agreement (BSD License) * +* Author: Alexandre Westfahl * +* * +* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * +* * +* All rights reserved. * +* * +* Redistribution and use of this software in source and binary forms, with or without modification, are * +* permitted provided that the following conditions are met: * +* * +* * Redistributions of source code must retain the above * +* copyright notice, this list of conditions and the * +* following disclaimer. * +* * +* * Redistributions in binary form must reproduce the above * +* copyright notice, this list of conditions and the * +* following disclaimer in the documentation and/or other * +* materials provided with the distribution. * +* * +* * Neither the name of the Teraoka Laboratory nor the * +* names of its contributors may be used to endorse or * +* promote products derived from this software without * +* specific prior written permission of Teraoka Laboratory * +* * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * +* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * +* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +*********************************************************************************************************/ + + +// This file is separated from the source code because it is a separate command which will call registration termination function in Diameter-SIP +#include +#include +#include +#include +#include +typedef int SOCKET; +typedef struct sockaddr_in SOCKADDR_IN; +typedef struct sockaddr SOCKADDR; +#include +#include +#include +#define PORT 666 +#include + +struct rtrsipaor +{ + char username[200]; + char sip_aor1[200]; + char sip_aor2[200]; + char sip_aor3[200]; + char strreason[200]; + char desthost[200]; + int reason; +}; + +int main (int argc, char **argv) +{ + SOCKET sock; + SOCKADDR_IN sin; + struct rtrsipaor rtrsip; + int numaor=0,i=0; + + sock = socket(AF_INET, SOCK_STREAM, 0); + sin.sin_addr.s_addr = inet_addr("127.0.0.1"); + sin.sin_family = AF_INET; + sin.sin_port = htons(PORT); + + //We initialize the structure + rtrsip.username[0]='\0'; + rtrsip.sip_aor1[0]='\0'; + rtrsip.sip_aor2[0]='\0'; + rtrsip.sip_aor3[0]='\0'; + rtrsip.strreason[0]='\0'; + rtrsip.desthost[0]='\0'; + rtrsip.reason=-1; + + + //Start of arguments check + if(argc<3) + { + fprintf(stderr,"Missing arguments! You must at least provide a username.\n"); + return 1; + } + + + for (i=1;i199) + { + fprintf(stderr,"SIP-AOR is too long!\n"); + } + else if(strncmp(argv[i],"sip",3)!=0) + { + //Bad format of SIP-AOR + fprintf(stderr,"A SIP-AOR must start by 'sip:' or 'sips:'. Aborting...\n"); + return 1; + } + else + { + if(numaor<3) + { + switch(numaor) + { + case 0: + strcpy(rtrsip.sip_aor1,argv[i]); + break; + case 1: + strcpy(rtrsip.sip_aor2,argv[i]); + break; + case 2: + strcpy(rtrsip.sip_aor3,argv[i]); + break; + } + numaor++; + } + else + { + fprintf(stderr,"You can not provide more than 3 SIP-AOR at the same time!\n"); + break; + } + } + i=j+1; + } + else + { + //We have a new argument + i--; + break; + } + } + } + else if(strcmp(argv[i],"-r")==0) + { + + if(strlen(argv[i+1])>199) + { + fprintf(stderr,"Deregistration reason is too long!\n"); + } + else + { + strcpy(rtrsip.strreason,argv[i+1]); + } + i++; + } + else if(strcmp(argv[i],"-h")==0) + { + //Remote SIP Server + if(strlen(argv[i+1])>199) + { + fprintf(stderr,"Host is too long!\n"); + } + else if(strlen(argv[i+1])<5) + { + fprintf(stderr,"Host is too short!\n"); + } + else + { + strcpy(rtrsip.desthost,argv[i+1]); + } + i++; + } + else if(strcmp(argv[i],"-pt")==0) + { + //Permanent Termination + rtrsip.reason=0; + } + else if(strcmp(argv[i],"-nssa")==0) + { + //New SIP Server Assigned + rtrsip.reason=1; + } + else if(strcmp(argv[i],"-ssc")==0) + { + //SIP Server Change + rtrsip.reason=2; + } + else if(strcmp(argv[i],"-rss")==0) + { + //Remote SIP Server + rtrsip.reason=3; + } + else + { + fprintf(stderr,"Unknown argument: %s\n",argv[i]); + } + } + else + { + fprintf(stderr,"Unknown argument: %s\n",argv[i]); + i++; + } + + } + + //If no SIP-AOR provided, we remove all + if(numaor<1) + { + fprintf(stderr,"All SIP-AOR of %s will be deregistrated.\n",rtrsip.username); + } + + //We want a username + if(strlen(rtrsip.username)==0) + { + fprintf(stderr,"You must provide a username!\n"); + return 1; + } + + if(rtrsip.desthost[0]=='\0') + { + fprintf(stderr,"You must provide the hostname of SIP-Server!\n"); + return 1; + } + + + + + /* + fprintf(stderr,"*%s*\n",rtrsip.username); + fprintf(stderr,"*%s*\n",rtrsip.sip_aor1); + fprintf(stderr,"*%s*\n",rtrsip.sip_aor2); + fprintf(stderr,"*%s*\n",rtrsip.sip_aor3); + fprintf(stderr,"*%d*\n",rtrsip.reason); + fprintf(stderr,"*%s*\n",rtrsip.strreason); + + //return 0; + */ + + + //TODO: check args + if(!connect(sock, (SOCKADDR*)&sin, sizeof(sin))) + { + fprintf(stderr,"Connexion succeed!\n"); + + + if(send(sock, &rtrsip, sizeof(struct rtrsipaor), 0)) + fprintf(stderr,"sent OK!\n"); + else + fprintf(stderr,"not sent\n"); + + } + else + { + fprintf(stderr,"Unable to connect\n"); + } + + close(sock); + + return 0; +} + + + + + + diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/tools/rtrsipaor Binary file extensions/app_sip/tools/rtrsipaor has changed diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/tools/rtrsipaor.c --- a/extensions/app_sip/tools/rtrsipaor.c Wed Jul 28 03:14:11 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,290 +0,0 @@ -/********************************************************************************************************* -* Software License Agreement (BSD License) * -* Author: Alexandre Westfahl * -* * -* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * -* * -* All rights reserved. * -* * -* Redistribution and use of this software in source and binary forms, with or without modification, are * -* permitted provided that the following conditions are met: * -* * -* * Redistributions of source code must retain the above * -* copyright notice, this list of conditions and the * -* following disclaimer. * -* * -* * Redistributions in binary form must reproduce the above * -* copyright notice, this list of conditions and the * -* following disclaimer in the documentation and/or other * -* materials provided with the distribution. * -* * -* * Neither the name of the Teraoka Laboratory nor the * -* names of its contributors may be used to endorse or * -* promote products derived from this software without * -* specific prior written permission of Teraoka Laboratory * -* * -* * -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * -* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * -* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * -* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * -* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * -* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * -*********************************************************************************************************/ - - -// This file is separated from the source code because it is a separate command which will call registration termination function in Diameter-SIP -#include -#include -#include -#include -#include -typedef int SOCKET; -typedef struct sockaddr_in SOCKADDR_IN; -typedef struct sockaddr SOCKADDR; -#include -#include -#include -#define PORT 666 -#include - -struct rtrsipaor -{ - char username[200]; - char sip_aor1[200]; - char sip_aor2[200]; - char sip_aor3[200]; - char strreason[200]; - char desthost[200]; - int reason; -}; - -int main (int argc, char **argv) -{ - SOCKET sock; - SOCKADDR_IN sin; - struct rtrsipaor rtrsip; - int numaor=0,i=0; - - sock = socket(AF_INET, SOCK_STREAM, 0); - sin.sin_addr.s_addr = inet_addr("127.0.0.1"); - sin.sin_family = AF_INET; - sin.sin_port = htons(PORT); - - //We initialize the structure - rtrsip.username[0]='\0'; - rtrsip.sip_aor1[0]='\0'; - rtrsip.sip_aor2[0]='\0'; - rtrsip.sip_aor3[0]='\0'; - rtrsip.strreason[0]='\0'; - rtrsip.desthost[0]='\0'; - rtrsip.reason=-1; - - - //Start of arguments check - if(argc<3) - { - fprintf(stderr,"Missing arguments! You must at least provide a username.\n"); - return 1; - } - - - for (i=1;i199) - { - fprintf(stderr,"SIP-AOR is too long!\n"); - } - else if(strncmp(argv[i],"sip",3)!=0) - { - //Bad format of SIP-AOR - fprintf(stderr,"A SIP-AOR must start by 'sip:' or 'sips:'. Aborting...\n"); - return 1; - } - else - { - if(numaor<3) - { - switch(numaor) - { - case 0: - strcpy(rtrsip.sip_aor1,argv[i]); - break; - case 1: - strcpy(rtrsip.sip_aor2,argv[i]); - break; - case 2: - strcpy(rtrsip.sip_aor3,argv[i]); - break; - } - numaor++; - } - else - { - fprintf(stderr,"You can not provide more than 3 SIP-AOR at the same time!\n"); - break; - } - } - i=j+1; - } - else - { - //We have a new argument - i--; - break; - } - } - } - else if(strcmp(argv[i],"-r")==0) - { - - if(strlen(argv[i+1])>199) - { - fprintf(stderr,"Deregistration reason is too long!\n"); - } - else - { - strcpy(rtrsip.strreason,argv[i+1]); - } - i++; - } - else if(strcmp(argv[i],"-h")==0) - { - //Remote SIP Server - if(strlen(argv[i+1])>199) - { - fprintf(stderr,"Host is too long!\n"); - } - else if(strlen(argv[i+1])<5) - { - fprintf(stderr,"Host is too short!\n"); - } - else - { - strcpy(rtrsip.desthost,argv[i+1]); - } - i++; - } - else if(strcmp(argv[i],"-pt")==0) - { - //Permanent Termination - rtrsip.reason=0; - } - else if(strcmp(argv[i],"-nssa")==0) - { - //New SIP Server Assigned - rtrsip.reason=1; - } - else if(strcmp(argv[i],"-ssc")==0) - { - //SIP Server Change - rtrsip.reason=2; - } - else if(strcmp(argv[i],"-rss")==0) - { - //Remote SIP Server - rtrsip.reason=3; - } - else - { - fprintf(stderr,"Unknown argument: %s\n",argv[i]); - } - } - else - { - fprintf(stderr,"Unknown argument: %s\n",argv[i]); - i++; - } - - } - - //If no SIP-AOR provided, we remove all - if(numaor<1) - { - fprintf(stderr,"All SIP-AOR of %s will be deregistrated.\n",rtrsip.username); - } - - //We want a username - if(strlen(rtrsip.username)==0) - { - fprintf(stderr,"You must provide a username!\n"); - return 1; - } - - if(rtrsip.desthost[0]=='\0') - { - fprintf(stderr,"You must provide the hostname of SIP-Server!\n"); - return 1; - } - - - - - /* - fprintf(stderr,"*%s*\n",rtrsip.username); - fprintf(stderr,"*%s*\n",rtrsip.sip_aor1); - fprintf(stderr,"*%s*\n",rtrsip.sip_aor2); - fprintf(stderr,"*%s*\n",rtrsip.sip_aor3); - fprintf(stderr,"*%d*\n",rtrsip.reason); - fprintf(stderr,"*%s*\n",rtrsip.strreason); - - //return 0; - */ - - - //TODO: check args - if(!connect(sock, (SOCKADDR*)&sin, sizeof(sin))) - { - fprintf(stderr,"Connexion succeed!\n"); - - - if(send(sock, &rtrsip, sizeof(struct rtrsipaor), 0)) - fprintf(stderr,"sent OK!\n"); - else - fprintf(stderr,"not sent\n"); - - } - else - { - fprintf(stderr,"Unable to connect\n"); - } - - close(sock); - - return 0; -} - - - - - - diff -r 533188d2e6cc -r 0d08a9ab2212 extensions/app_sip/userauthorization.c --- a/extensions/app_sip/userauthorization.c Wed Jul 28 03:14:11 2010 +0900 +++ b/extensions/app_sip/userauthorization.c Wed Jul 28 14:34:48 2010 +0900 @@ -33,10 +33,10 @@ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *********************************************************************************************************/ -#include "diamsip.h" +#include "app_sip.h" -int diamsip_UAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act) +int app_sip_UAR_cb( struct msg ** msg, struct avp * paramavp, struct session * sess, enum disp_action * act) { TRACE_ENTRY("%p %p %p %p", msg, paramavp, sess, act);