Changeset 427:3d9f300f3b49 in freeDiameter
- Timestamp:
- Jul 26, 2010, 9:39:27 PM (14 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- extensions
- Files:
-
- 5 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/app_sip/CMakeLists.txt
r420 r427 21 21 multimediaauth.c 22 22 registrationtermination.c 23 userauthorization.c 23 24 pushprofile.c 25 serverassignment.c 24 26 locationinfo.c 25 27 locationinfosl.c -
extensions/app_sip/TODO
r420 r427 38 38 TODO List 39 39 * add in malloc the size of char 40 * when getting results from mysql, check lenght 41 * sort capabilities in LIR/LIA 42 * remove warnings in SIP plugin for gateway 43 * make functions for database access in MAR/MAA 44 * order diamsip.h because it's becoming a mess ^^ 45 * replace password in MAR/MAA and libdiamsip from table to malloc char! 46 * display errors of mysql 47 * check that all user data inserted in requests are purified 48 * add accounting server uri in database and diamsip 49 * add mutex on mysql writing 50 * check multithreading of mysql! 51 52 53 54 55 56 -
extensions/app_sip/diamsip.c
r420 r427 126 126 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Application-Id", &sip_dict.Auth_Application_Id, ENOENT) ); 127 127 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Host", &sip_dict.Destination_Host, ENOENT) ); 128 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Realm", &sip_dict.Destination_Realm, ENOENT) ); 128 129 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &sip_dict.Session_Id, ENOENT) ); 129 130 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Redirect-Host", &sip_dict.Redirect_Host, ENOENT) ); … … 136 137 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authentication-Info", &sip_dict.SIP_Authentication_Info, ENOENT) ); 137 138 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Server-URI", &sip_dict.SIP_Server_URI, ENOENT) ); 139 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Server-Capabilities", &sip_dict.SIP_Server_Capabilities, ENOENT) ); 140 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Mandatory-Capability", &sip_dict.SIP_Mandatory_Capability, ENOENT) ); 141 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Optional-Capability", &sip_dict.SIP_Optional_Capability, ENOENT) ); 138 142 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Method", &sip_dict.SIP_Method, ENOENT) ); 139 143 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-AOR", &sip_dict.SIP_AOR, ENOENT) ); … … 141 145 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Reason-Code", &sip_dict.SIP_Reason_Code, ENOENT) ); 142 146 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Reason-Info", &sip_dict.SIP_Reason_Info, ENOENT) ); 147 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Accounting-Information", &sip_dict.SIP_Accounting_Information, ENOENT) ); 148 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) ); 149 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) ); 150 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) ); 151 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Item-Number", &sip_dict.SIP_Item_Number, ENOENT) ); 152 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) ); 153 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) ); 154 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Data", &sip_dict.SIP_User_Data, ENOENT) ); 155 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) ); 156 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) ); 157 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) ); 158 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) ); 143 159 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Realm", &sip_dict.Digest_Realm, ENOENT) ); 144 160 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-URI", &sip_dict.Digest_URI, ENOENT) ); … … 176 192 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Location-Info-Request", &data.command, ENOENT) ); 177 193 CHECK_FCT( fd_disp_register( diamsip_LIR_cb, DISP_HOW_CC, &data, &diamsip_LIR_hdl ) ); 194 //UAR 195 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "User-Authorization-Request", &data.command, ENOENT) ); 196 CHECK_FCT( fd_disp_register( diamsip_UAR_cb, DISP_HOW_CC, &data, &diamsip_UAR_hdl ) ); 197 //SAR 198 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Server-Assignment-Request", &data.command, ENOENT) ); 199 CHECK_FCT( fd_disp_register( diamsip_SAR_cb, DISP_HOW_CC, &data, &diamsip_SAR_hdl ) ); 178 200 } 179 201 if(as_conf->mode==2) … … 205 227 return EINVAL; 206 228 } 207 208 209 210 211 229 212 230 -
extensions/app_sip/diamsip.h
r420 r427 88 88 void close_mysql_connection(); 89 89 int get_diameter_uri(const unsigned char *sip_aor, const size_t sipaorlen, char ** diameter_uri, size_t *diameterurilen); 90 int exist_username(const unsigned char *sip_aor, const size_t sipaorlen); 91 int get_sipserver_cap(const unsigned char *sip_aor, const size_t sipaorlen, struct avp **capabilities); 92 int get_password(const unsigned char *username, const size_t usernamelen, char *password); 93 int check_sipaor(const unsigned char *username, const size_t usernamelen, const char * sip_aor,const size_t sipaorlen); 94 int get_user_datatype(const unsigned char *username, const size_t usernamelen,char **table_supported, const int num_elements, struct avp **groupedavp); 95 int set_pending_flag(const unsigned char *username, const size_t usernamelen); 96 int clear_pending_flag(const unsigned char *username, const size_t usernamelen); 97 int set_real_sipserver_uri(const unsigned char *username, const size_t usernamelen, const unsigned char *sipserver_uri,const size_t sipserverurilen); 98 int set_sipserver_uri(const unsigned char *username, const size_t usernamelen, const unsigned char *sipserver_uri,const size_t sipserverurilen); 99 100 //count functions 101 int count_supporteddatatype(const struct msg * message); 102 int count_sipaor(const struct msg * message); 90 103 91 104 … … 130 143 int diamsip_PPA_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); 131 144 int diamsip_LIR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); 145 int diamsip_UAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); 146 int diamsip_SAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); 132 147 133 148 //Suscriber Locator … … 138 153 #define SQL_GETPASSWORD_LEN 52 139 154 155 //username by SIP-AOR 156 #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`" 157 #define SQL_GETUSERNAME_LEN 113 158 159 //sip server uri by username 140 160 #define SQL_GETSIPURI "SELECT `sip_server_uri` FROM ds_users WHERE `username` ='%s'" 141 161 #define SQL_GETSIPURI_LEN 60 142 162 163 //sip server uri by SIP-AOR 164 #define SQL_GETSIPSERURI "SELECT `sip_server_uri` FROM ds_users, ds_sip_aor WHERE `sip_aor` ='%s' AND `ds_sip_aor`.`id_user` = `ds_users`.`id_user`" 165 #define SQL_GETSIPSERURI_LEN 119 166 167 //sip capabilities for a SIP-AOR 168 #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`" 169 #define SQL_GETSIPSERCAP_LEN 144 170 171 //user data for a user data supported 172 #define SQL_GETUSEDATA "SELECT `data_type`,`data` FROM ds_users, ds_user_data, ds_data_types WHERE `username` ='%s' AND `ds_users`.`id_user` = `ds_user_data`.`id_user` AND `ds_data_types`.`id_data_type`=`ds_user_data`.`id_data_type`" 173 #define SQL_GETUSEDATA_LEN 206 174 143 175 #define SQL_GETDIAMURI "SELECT `diameter_uri` FROM sl_sip_aor_map WHERE `sip_aor` ='%s'" 144 176 #define SQL_GETDIAMURI_LEN 61 145 177 146 #define SQL_SETSIPURI "UPDATE ds_users SET `sip_server_uri`='%s', `flag`=1 WHERE `username` ='%s'" 147 #define SQL_SETSIPURI_LEN 74 178 //networks for this user 179 #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`" 180 #define SQL_GETUSERNET_LEN 220 181 182 #define SQL_SETSIPURI "UPDATE ds_users SET `temp_sip_server_uri`='%s' WHERE `username` ='%s'" 183 #define SQL_SETSIPURI_LEN 65 184 185 //TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO 186 #define SQL_RMSIPURI "UPDATE ds_users SET `temp_sip_server_uri`='', `sip_server_uri`='' WHERE `id_user` ='%s'" 187 #define SQL_RMSIPURI_LEN 65 188 //TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO 189 190 #define SQL_SETREALSIPURI "UPDATE ds_users SET `sip_server_uri`='%s' WHERE `username` ='%s'" 191 #define SQL_SETREALSIPURI_LEN 65 192 193 #define SQL_SETFLAG "UPDATE ds_users SET `authentication_pending`=1 WHERE `username` ='%s'" 194 #define SQL_SETFLAG_LEN 67 195 196 #define SQL_CLEARFLAG "UPDATE ds_users SET `authentication_pending`=0, `registrated`=1 WHERE `username` ='%s'" 197 #define SQL_CLEARFLAG_LEN 84 148 198 149 199 #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'" 150 200 #define SQL_GETSIPAOR_LEN 131 151 201 152 #define SQL_CLEARFLAG "UPDATE ds_users SET `flag`=0 WHERE `username` ='%s'"153 #define SQL_CLEARFLAG_LEN 74 202 //#define SQL_CLEARFLAG "UPDATE ds_users SET `authentication_pending`=0 WHERE `username` ='%s'" 203 //#define SQL_CLEARFLAG_LEN 67 154 204 155 205 extern struct session_handler * ds_sess_hdl; … … 167 217 struct dict_object * Auth_Application_Id; 168 218 struct dict_object * Destination_Host; 219 struct dict_object * Destination_Realm; 169 220 struct dict_object * User_Name; 170 221 struct dict_object * Session_Id; … … 172 223 struct dict_object * Redirect_Host_Usage; 173 224 struct dict_object * SIP_Auth_Data_Item; 225 struct dict_object * SIP_Accounting_Information; 226 struct dict_object * SIP_Accounting_Server_URI; 227 struct dict_object * SIP_Credit_Control_Server_URI; 228 struct dict_object * SIP_Server_Assignment_Type; 229 struct dict_object * SIP_Item_Number; 230 struct dict_object * SIP_User_Authorization_Type; 231 struct dict_object * SIP_Supported_User_Data_Type; 232 struct dict_object * SIP_User_Data; 233 struct dict_object * SIP_User_Data_Type; 234 struct dict_object * SIP_User_Data_Contents; 235 struct dict_object * SIP_User_Data_Already_Available; 236 struct dict_object * SIP_Visited_Network_Id; 174 237 struct dict_object * SIP_Authorization; 175 238 struct dict_object * SIP_Authenticate; … … 178 241 struct dict_object * SIP_Authentication_Info; 179 242 struct dict_object * SIP_Server_URI; 243 struct dict_object * SIP_Server_Capabilities; 244 struct dict_object * SIP_Mandatory_Capability; 245 struct dict_object * SIP_Optional_Capability; 180 246 struct dict_object * SIP_Method; 181 247 struct dict_object * SIP_AOR; -
extensions/app_sip/libdiamsip.c
r420 r427 166 166 } 167 167 168 //You must free ""result"" after using this function 168 169 169 void request_mysql(char *query) 170 170 { … … 186 186 } 187 187 188 //If password is null, we just verify this user exist 189 //We don't need the password length because it is a table' 190 int get_password(const unsigned char *username, const size_t usernamelen, char *password) 191 { 192 CHECK_PARAMS(username && usernamelen); 193 194 int not_found=2; 195 size_t querylen, usernamepurelen; 196 char *query, *username_pure; 197 198 switch(as_conf->datasource) 199 { 200 //MySQL 201 case ASMYSQL: 202 //We allocate the double size of username because at worst it can be all quotes 203 username_pure=malloc(usernamelen*2+1); 204 //We purify username not to have forbidden characters 205 usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); 206 207 //We copy username in query 208 querylen=SQL_GETPASSWORD_LEN + usernamepurelen; 209 query = malloc(querylen+2); 210 snprintf(query, querylen+1, SQL_GETPASSWORD, username_pure); 211 212 MYSQL_RES *res; 213 MYSQL_ROW row; 214 215 //We make the query 216 request_mysql(query); 217 res=mysql_use_result(conn); 218 if(res==NULL) 219 { 220 if(password!=NULL) 221 password[0]='\0'; 222 free(query); 223 return 2; 224 } 225 226 227 228 while ((row = mysql_fetch_row(res)) != NULL) 229 { 230 if(strlen(row[0])>0) 231 { 232 if(password!=NULL) 233 strcpy(password,row[0]); 234 235 not_found=0; 236 break; 237 } 238 } 239 mysql_free_result(res); 240 free(query); 241 break; 242 } 243 return not_found; 244 } 245 246 int check_sipaor(const unsigned char *username, const size_t usernamelen, const char * sip_aor,const size_t sipaorlen) 247 { 248 CHECK_PARAMS(username && usernamelen && sip_aor && sipaorlen); 249 250 int not_found=2; 251 size_t querylen, usernamepurelen; 252 char *query, *username_pure; 253 254 switch(as_conf->datasource) 255 { 256 //MySQL 257 case ASMYSQL: 258 //We allocate the double size of username because at worst it can be all quotes 259 username_pure=malloc(usernamelen*2+1); 260 //We purify username not to have forbidden characters 261 usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); 262 263 //We get the list of AOR owned by this user 264 querylen=SQL_GETSIPAOR_LEN + usernamepurelen; 265 query = malloc(querylen+2); 266 snprintf(query, querylen+1, SQL_GETSIPAOR, username_pure); 267 268 MYSQL_RES *res; 269 MYSQL_ROW row; 270 271 //We make the query 272 request_mysql(query); 273 res=mysql_use_result(conn); 274 if(res==NULL) 275 { 276 free(query); 277 return 2; 278 } 279 280 281 not_found=1; 282 while ((row = mysql_fetch_row(res)) != NULL) 283 { 284 if(strncmp((const char *)sip_aor,row[0],sipaorlen)==0) 285 { 286 not_found=0; 287 break; 288 } 289 } 290 mysql_free_result(res); 291 free(query); 292 break; 293 } 294 return not_found; 295 } 296 188 297 int get_diameter_uri(const unsigned char *sip_aor, const size_t sipaorlen, char ** diameter_uri, size_t *diameterurilen) 189 298 { 190 CHECK_PARAMS(sip_aor && sipaorlen); 191 192 size_t querylen, sipaorpurelen; 193 char *query, *sipaor_pure; 194 int not_found=1; 195 196 197 198 199 //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars 200 if(sipaorlen<5) 201 return 2; 202 203 //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security 204 205 switch(as_conf->datasource) 206 { 207 //MySQL 208 case ASMYSQL: 209 210 querylen=SQL_GETDIAMURI_LEN + sipaorlen; 211 212 213 //We allocate the double size of SIP-URI because at worst it can be all quotes 214 CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); 215 //We purify SIP-URI not to have forbidden characters 216 sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); 217 218 219 query = malloc(querylen+sipaorpurelen+ 2); 220 snprintf(query, querylen+1, SQL_GETDIAMURI, sipaor_pure); 221 222 MYSQL_RES *res; 223 MYSQL_ROW row; 224 225 226 //We make the query 227 request_mysql(query); 228 res=mysql_use_result(conn); 229 if(res==NULL) 230 { 231 //We couldn't make the request 232 diameter_uri=NULL; 299 CHECK_PARAMS(sip_aor && sipaorlen); 300 301 size_t querylen, sipaorpurelen; 302 char *query, *sipaor_pure; 303 int not_found=2; 304 305 306 307 308 //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars 309 if(sipaorlen<5) 233 310 return 2; 234 } 235 TRACE_DEBUG(INFO,"***********%d|%d****************\n%s\n*********************************",sipaorlen,sipaorpurelen,query); 236 while ((row = mysql_fetch_row(res)) != NULL) 237 { 238 *diameterurilen=strlen(row[0]); 239 if(*diameterurilen>0) 240 { 241 CHECK_MALLOC(*diameter_uri=malloc(*diameterurilen+1)); 242 strcpy(*diameter_uri,row[0]); 243 not_found=0; 244 break; 245 } 246 } 247 mysql_free_result(res); 248 free(query); 249 free(sipaor_pure); 250 break; 311 312 //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security 313 switch(as_conf->datasource) 314 { 315 //MySQL 316 case ASMYSQL: 317 318 querylen=SQL_GETDIAMURI_LEN + sipaorlen; 319 320 321 //We allocate the double size of SIP-URI because at worst it can be all quotes 322 CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); 323 //We purify SIP-URI not to have forbidden characters 324 sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); 325 326 327 query = malloc(querylen+sipaorpurelen+ 2); 328 snprintf(query, querylen+1, SQL_GETDIAMURI, sipaor_pure); 329 330 MYSQL_RES *res; 331 MYSQL_ROW row; 332 333 334 //We make the query 335 request_mysql(query); 336 res=mysql_use_result(conn); 337 if(res==NULL) 338 { 339 //We couldn't make the request 340 diameter_uri=NULL; 341 return 2; 342 } 343 344 while ((row = mysql_fetch_row(res)) != NULL) 345 { 346 *diameterurilen=strlen(row[0]); 347 if(*diameterurilen>0) 348 { 349 CHECK_MALLOC(*diameter_uri=malloc(*diameterurilen+1)); 350 strcpy(*diameter_uri,row[0]); 351 not_found=0; 352 break; 353 } 354 } 355 mysql_free_result(res); 356 free(query); 357 free(sipaor_pure); 358 break; 251 359 252 360 default: … … 265 373 266 374 375 int exist_username(const unsigned char *sip_aor, const size_t sipaorlen) 376 { 377 CHECK_PARAMS(sip_aor && sipaorlen); 378 379 size_t querylen, sipaorpurelen; 380 char *query, *sipaor_pure; 381 int not_found=1; 382 383 //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars 384 if(sipaorlen<5) 385 return 2; 386 387 //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security 388 389 switch(as_conf->datasource) 390 { 391 //MySQL 392 case ASMYSQL: 393 394 querylen=SQL_GETUSERNAME_LEN + sipaorlen; 395 396 397 //We allocate the double size of SIP-URI because at worst it can be all quotes 398 CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); 399 //We purify SIP-URI not to have forbidden characters 400 sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); 401 402 403 query = malloc(querylen+sipaorpurelen+ 2); 404 snprintf(query, querylen+1, SQL_GETUSERNAME, sipaor_pure); 405 406 MYSQL_RES *res; 407 MYSQL_ROW row; 408 409 410 //We make the query 411 request_mysql(query); 412 res=mysql_use_result(conn); 413 if(res==NULL) 414 { 415 //We couldn't make the request 416 return 2; 417 } 418 419 while ((row = mysql_fetch_row(res)) != NULL) 420 { 421 if(strlen(row[0])>0) 422 { 423 not_found=0; 424 break; 425 } 426 } 427 mysql_free_result(res); 428 free(query); 429 free(sipaor_pure); 430 break; 431 432 default: 433 434 //We must never go here, if so, we must stop diameter_sip 435 TRACE_DEBUG(INFO,"FATAL ERROR: the datasource is unknown, please check your config file!"); 436 return 2; 437 438 break; 439 } 440 441 //0 if it was found 442 return not_found; 443 444 } 445 446 //We check if this user can go in the given network 447 int allow_roaming(const unsigned char *username, const size_t usernamelen, const char * network,const size_t networklen) 448 { 449 CHECK_PARAMS(username && usernamelen && network && networklen); 450 451 int not_found=2; 452 size_t querylen, usernamepurelen; 453 char *query, *username_pure; 454 455 switch(as_conf->datasource) 456 { 457 //MySQL 458 case ASMYSQL: 459 //We allocate the double size of username because at worst it can be all quotes 460 username_pure=malloc(usernamelen*2+1); 461 //We purify username not to have forbidden characters 462 usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); 463 464 //We get the list of AOR owned by this user 465 querylen=SQL_GETUSERNET_LEN + usernamepurelen; 466 query = malloc(querylen+2); 467 snprintf(query, querylen+1, SQL_GETUSERNET, username_pure); 468 469 470 MYSQL_RES *res; 471 MYSQL_ROW row; 472 473 474 //We make the query 475 request_mysql(query); 476 res=mysql_use_result(conn); 477 if(res==NULL) 478 { 479 free(query); 480 return 2; 481 } 482 483 484 not_found=1; 485 while ((row = mysql_fetch_row(res)) != NULL) 486 { 487 if(strncmp((const char *)network,row[0],networklen)==0) 488 { 489 not_found=0; 490 break; 491 } 492 } 493 mysql_free_result(res); 494 free(query); 495 break; 496 } 497 return not_found; 498 } 499 500 //SIP-Server-Capabilities for the SIP-AOR 501 int get_sipserver_cap(const unsigned char *sip_aor, const size_t sipaorlen, struct avp **capabilities) 502 { 503 CHECK_PARAMS(sip_aor && sipaorlen && capabilities); 504 505 size_t querylen, sipaorpurelen; 506 char *query, *sipaor_pure; 507 int not_found=2; 508 union avp_value value; 509 struct avp *avp; 510 511 //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars 512 if(sipaorlen<5) 513 return 2; 514 515 //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security 516 switch(as_conf->datasource) 517 { 518 //MySQL 519 case ASMYSQL: 520 521 querylen=SQL_GETSIPSERCAP_LEN + sipaorlen; 522 523 524 //We allocate the double size of SIP-URI because at worst it can be all quotes 525 CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); 526 //We purify SIP-URI not to have forbidden characters 527 sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); 528 529 530 query = malloc(querylen+sipaorpurelen+ 2); 531 snprintf(query, querylen+1, SQL_GETSIPSERCAP, sipaor_pure); 532 533 MYSQL_RES *res; 534 MYSQL_ROW row; 535 536 //We make the query 537 request_mysql(query); 538 res=mysql_use_result(conn); 539 if(res==NULL) 540 { 541 //We couldn't make the request 542 return 2; 543 } 544 not_found=1; 545 while ((row = mysql_fetch_row(res)) != NULL) 546 { 547 if(atoi(row[0])==1) 548 {//mandatory 549 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Mandatory_Capability, 0, &avp ) ); 550 value.i32=(uint32_t)atoi(row[1]); 551 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 552 CHECK_FCT( fd_msg_avp_add ( *capabilities, MSG_BRW_LAST_CHILD, avp) ); 553 554 } 555 else 556 {//optional 557 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Optional_Capability, 0, &avp ) ); 558 value.i32=(uint32_t)atoi(row[1]); 559 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 560 CHECK_FCT( fd_msg_avp_add ( *capabilities, MSG_BRW_LAST_CHILD, avp) ); 561 } 562 not_found=0; 563 } 564 565 mysql_free_result(res); 566 free(query); 567 free(sipaor_pure); 568 break; 569 570 default: 571 572 //We must never go here, if so, we must stop diameter_sip 573 TRACE_DEBUG(INFO,"FATAL ERROR: the datasource is unknown, please check your config file!"); 574 return 2; 575 576 break; 577 } 578 579 //0 if it was found 580 return not_found; 581 582 } 583 584 585 //We retrieve datatype 586 int get_user_datatype(const unsigned char *username, const size_t usernamelen, char **table_supported, const int num_elements, struct avp **groupedavp) 587 { 588 CHECK_PARAMS(table_supported && num_elements && username && usernamelen && groupedavp); 589 590 591 int counter=0, not_found=1; 592 union avp_value value; 593 struct avp *avp, *rootavp; 594 size_t querylen, usernamepurelen; 595 char *query, *username_pure; 596 597 if(num_elements<1) 598 return 1; 599 600 //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security 601 switch(as_conf->datasource) 602 { 603 //MySQL 604 case ASMYSQL: 605 606 querylen=SQL_GETUSEDATA_LEN + usernamelen; 607 608 609 //We allocate the double size of username because at worst it can be all quotes 610 username_pure=malloc(usernamelen*2+1); 611 //We purify username not to have forbidden characters 612 usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); 613 614 615 query = malloc(querylen+usernamelen+ 2); 616 snprintf(query, querylen+1, SQL_GETUSEDATA, username_pure); 617 618 MYSQL_RES *res; 619 MYSQL_ROW row; 620 621 //We make the query 622 request_mysql(query); 623 res=mysql_use_result(conn); 624 if(res==NULL) 625 { 626 //We couldn't make the request 627 return 2; 628 } 629 not_found=1; 630 631 counter=0; 632 unsigned long *length=0; 633 634 //int index=0;//current field number 635 636 while ((row = mysql_fetch_row(res)) != NULL) 637 { 638 length=mysql_fetch_lengths(res); 639 640 for(counter=0;counter<num_elements; counter++) 641 { 642 //TODO: check length 643 if(strcmp(table_supported[counter],row[0])) 644 { 645 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data, 0, &rootavp ) ); 646 647 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data_Type, 0, &avp ) ); 648 value.os.data=(unsigned char *)table_supported[counter]; 649 value.os.len=strlen(table_supported[counter]); 650 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 651 CHECK_FCT( fd_msg_avp_add ( rootavp, MSG_BRW_LAST_CHILD, avp) ); 652 //This was used 653 table_supported[counter]=NULL; 654 655 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data_Contents, 0, &avp ) ); 656 CHECK_MALLOC(value.os.data=malloc((length[1])*sizeof(unsigned char))); 657 memcpy(value.os.data,row[1],length[1]); 658 value.os.len=(size_t)(length[1]*sizeof(unsigned char)); 659 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 660 CHECK_FCT( fd_msg_avp_add ( rootavp, MSG_BRW_LAST_CHILD, avp) ); 661 662 CHECK_FCT( fd_msg_avp_add ( *groupedavp, MSG_BRW_LAST_CHILD, rootavp) ); 663 not_found=0; 664 } 665 } 666 //index++; 667 } 668 669 mysql_free_result(res); 670 free(query); 671 free(username_pure); 672 break; 673 674 default: 675 676 //We must never go here, if so, we must stop diameter_sip 677 TRACE_DEBUG(INFO,"FATAL ERROR: the datasource is unknown, please check your config file!"); 678 return 2; 679 680 break; 681 } 682 683 //0 if it was found 684 return not_found; 685 686 } 687 688 int set_pending_flag(const unsigned char *username, const size_t usernamelen) 689 { 690 CHECK_PARAMS(username && usernamelen); 691 692 int not_found=2; 693 size_t querylen, usernamepurelen; 694 char *query, *username_pure; 695 696 switch(as_conf->datasource) 697 { 698 //MySQL 699 case ASMYSQL: 700 //We allocate the double size of username because at worst it can be all quotes 701 username_pure=malloc(usernamelen*2+1); 702 //We purify username not to have forbidden characters 703 usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); 704 705 706 707 //We clear the flag "authentication pending" 708 querylen=SQL_SETFLAG_LEN + usernamepurelen; 709 query = malloc(querylen+2); 710 snprintf(query, querylen+1, SQL_SETFLAG, username_pure); 711 712 if (mysql_query(conn, query)) 713 { 714 TRACE_DEBUG(INFO,"Query %s failed", query); 715 free(query); 716 return 2; 717 } 718 719 free(query); 720 break; 721 } 722 return 0; 723 } 724 int clear_pending_flag(const unsigned char *username, const size_t usernamelen) 725 { 726 CHECK_PARAMS(username && usernamelen); 727 728 int not_found=2; 729 size_t querylen, usernamepurelen; 730 char *query, *username_pure; 731 732 switch(as_conf->datasource) 733 { 734 //MySQL 735 case ASMYSQL: 736 //We allocate the double size of username because at worst it can be all quotes 737 username_pure=malloc(usernamelen*2+1); 738 //We purify username not to have forbidden characters 739 usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); 740 741 742 743 //We clear the flag "authentication pending" 744 querylen=SQL_CLEARFLAG_LEN + usernamepurelen; 745 query = malloc(querylen+2); 746 snprintf(query, querylen+1, SQL_CLEARFLAG, username_pure); 747 748 if (mysql_query(conn, query)) 749 { 750 TRACE_DEBUG(INFO,"Query %s failed", query); 751 free(query); 752 return 2; 753 } 754 755 free(query); 756 break; 757 } 758 return 0; 759 } 760 761 762 763 int set_sipserver_uri(const unsigned char *username, const size_t usernamelen, const unsigned char *sipserver_uri,const size_t sipserverurilen) 764 { 765 CHECK_PARAMS(username && usernamelen && sipserver_uri && sipserverurilen); 766 767 int not_found=2; 768 size_t querylen, usernamepurelen, sipserveruripurelen; 769 char *query, *username_pure, *sipserveruri_pure; 770 771 switch(as_conf->datasource) 772 { 773 //MySQL 774 case ASMYSQL: 775 //We allocate the double size of username because at worst it can be all quotes 776 username_pure=malloc(usernamelen*2+1); 777 //We purify username not to have forbidden characters 778 usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); 779 780 //We allocate the double size of username because at worst it can be all quotes 781 sipserveruri_pure=malloc(sipserverurilen*2+1); 782 //We purify username not to have forbidden characters 783 sipserveruripurelen=mysql_real_escape_string(conn, sipserveruri_pure, (const char *)sipserver_uri, sipserverurilen); 784 785 //We clear the flag "authentication pending" 786 querylen=SQL_SETSIPURI_LEN + usernamepurelen + sipserveruripurelen; 787 query = malloc(querylen+2); 788 snprintf(query, querylen+1, SQL_SETSIPURI, sipserveruri_pure,username_pure); 789 790 if (mysql_query(conn, query)) 791 { 792 TRACE_DEBUG(INFO,"Query %s failed", query); 793 free(query); 794 return 2; 795 } 796 797 free(query); 798 break; 799 } 800 return 0; 801 } 802 int remove_sipserver_uri(const unsigned char *sipserver_uri,const size_t sipserverurilen) 803 { 804 CHECK_PARAMS(sipserver_uri && sipserverurilen); 805 806 int not_found=2; 807 size_t querylen, sipserveruripurelen; 808 char *query, *sipserveruri_pure; 809 810 switch(as_conf->datasource) 811 { 812 //MySQL 813 case ASMYSQL: 814 //We allocate the double size of username because at worst it can be all quotes 815 sipserveruri_pure=malloc(sipserverurilen*2+1); 816 //We purify username not to have forbidden characters 817 sipserveruripurelen=mysql_real_escape_string(conn, sipserveruri_pure, (const char *)sipserver_uri, sipserverurilen); 818 819 //We clear the flag "authentication pending" 820 querylen=SQL_RMSIPURI_LEN + sipserveruripurelen; 821 query = malloc(querylen+2); 822 snprintf(query, querylen+1, SQL_RMSIPURI, sipserveruri_pure); 823 824 if (mysql_query(conn, query)) 825 { 826 TRACE_DEBUG(INFO,"Query %s failed", query); 827 free(query); 828 return 2; 829 } 830 831 free(query); 832 break; 833 } 834 return 0; 835 } 836 int set_real_sipserver_uri(const unsigned char *username, const size_t usernamelen, const unsigned char *sipserver_uri,const size_t sipserverurilen) 837 { 838 CHECK_PARAMS(username && usernamelen && sipserver_uri && sipserverurilen); 839 840 int not_found=2; 841 size_t querylen, usernamepurelen, sipserveruripurelen; 842 char *query, *username_pure, *sipserveruri_pure; 843 844 switch(as_conf->datasource) 845 { 846 //MySQL 847 case ASMYSQL: 848 //We allocate the double size of username because at worst it can be all quotes 849 username_pure=malloc(usernamelen*2+1); 850 //We purify username not to have forbidden characters 851 usernamepurelen=mysql_real_escape_string(conn, username_pure, (const char *)username, usernamelen); 852 853 //We allocate the double size of username because at worst it can be all quotes 854 sipserveruri_pure=malloc(sipserverurilen*2+1); 855 //We purify username not to have forbidden characters 856 sipserveruripurelen=mysql_real_escape_string(conn, sipserveruri_pure, (const char *)sipserver_uri, sipserverurilen); 857 858 //We clear the flag "authentication pending" 859 querylen=SQL_SETREALSIPURI_LEN + usernamepurelen + sipserveruripurelen; 860 query = malloc(querylen+2); 861 snprintf(query, querylen+1, SQL_SETREALSIPURI, sipserveruri_pure,username_pure); 862 863 if (mysql_query(conn, query)) 864 { 865 TRACE_DEBUG(INFO,"Query %s failed", query); 866 free(query); 867 return 2; 868 } 869 870 free(query); 871 break; 872 } 873 return 0; 874 } 875 876 int get_sipserver_uri(const unsigned char *sip_aor, const size_t sipaorlen, char ** sipserver_uri, size_t *sipserverurilen) 877 { 878 CHECK_PARAMS(sip_aor && sipaorlen && sipserver_uri && sipserverurilen ); 879 880 size_t querylen, sipaorpurelen; 881 char *query, *sipaor_pure; 882 int not_found=2; 883 884 885 886 887 //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars 888 if(sipaorlen<5) 889 return 2; 890 891 //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security 892 893 switch(as_conf->datasource) 894 { 895 //MySQL 896 case ASMYSQL: 897 898 querylen=SQL_GETSIPSERURI_LEN + sipaorlen; 899 900 //We allocate the double size of SIP-URI because at worst it can be all quotes 901 CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); 902 //We purify SIP-URI not to have forbidden characters 903 sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); 904 905 906 query = malloc(querylen+sipaorpurelen+ 2); 907 snprintf(query, querylen+1, SQL_GETSIPSERURI, sipaor_pure); 908 909 MYSQL_RES *res; 910 MYSQL_ROW row; 911 912 //We make the query 913 request_mysql(query); 914 res=mysql_use_result(conn); 915 if(res==NULL) 916 { 917 //We couldn't make the request 918 sipserver_uri=NULL; 919 return 2; 920 } 921 922 not_found=1; 923 while ((row = mysql_fetch_row(res)) != NULL) 924 { 925 *sipserverurilen=strlen(row[0]); 926 if(*sipserverurilen>4) 927 { 928 CHECK_MALLOC(*sipserver_uri=malloc(*sipserverurilen+1)); 929 strcpy(*sipserver_uri,row[0]); 930 not_found=0; 931 break; 932 } 933 } 934 mysql_free_result(res); 935 free(query); 936 free(sipaor_pure); 937 break; 938 939 default: 940 941 //We must never go here, if so, we must stop diameter_sip 942 TRACE_DEBUG(INFO,"FATAL ERROR: the datasource is unknown, please check your config file!"); 943 sipserver_uri=NULL; 944 return 2; 945 946 break; 947 } 948 949 //0 if it was found 950 return not_found; 951 952 } 953 954 int count_sipaor(const struct msg * message) 955 { 956 CHECK_PARAMS(message); 957 958 struct avp_hdr *temphdr; 959 struct avp *avp; 960 int counter=0; 961 962 CHECK_FCT(fd_msg_browse ( &message, MSG_BRW_WALK, &avp, NULL)); 963 964 while(avp!=NULL) 965 { 966 967 CHECK_FCT( fd_msg_avp_hdr( avp,&temphdr )); 968 969 if(temphdr->avp_code==122 && temphdr->avp_vendor==0) 970 { 971 counter++; 972 } 973 974 CHECK_FCT(fd_msg_browse ( &message, MSG_BRW_WALK, &avp, NULL)); 975 } 976 return counter; 977 } 978 int count_supporteddatatype(const struct msg * message) 979 { 980 CHECK_PARAMS(message); 981 982 struct avp_hdr *temphdr; 983 struct avp *avp; 984 int counter=0; 985 986 CHECK_FCT(fd_msg_browse ( &message, MSG_BRW_WALK, &avp, NULL)); 987 988 while(avp!=NULL) 989 { 990 991 CHECK_FCT( fd_msg_avp_hdr( avp,&temphdr )); 992 993 if(temphdr->avp_code==388 && temphdr->avp_vendor==0) 994 { 995 counter++; 996 } 997 998 CHECK_FCT(fd_msg_browse ( &message, MSG_BRW_WALK, &avp, NULL)); 999 } 1000 return counter; 1001 } 267 1002 /* 268 1003 void nonce_add_element(char * nonce) -
extensions/app_sip/locationinfo.c
r420 r427 45 45 struct avp_hdr *avphdr; 46 46 union avp_value value; 47 int ret=0; 47 48 48 49 //Result_Code to return in the answer … … 58 59 ans = *msg; 59 60 61 //Add the Auth-Application-Id 62 { 63 CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Application_Id, 0, &avp ) ); 64 value.i32 = 6; 65 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 66 CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, avp) ); 67 } 60 68 // Add the Auth-Session-State AVP 61 69 { … … 69 77 } 70 78 71 //TODO: wait for answer from authors to clear how to find SIP server!79 72 80 //Add a SIP_Server_URI 73 81 { … … 75 83 CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr ) ); 76 84 77 //We extract Realm from SIP_AOR 78 char *realm=NULL; 79 80 81 realm = strtok( (char *)(avphdr->avp_value->os.data), "@" ); 82 realm = strtok( NULL, "@" ); 83 84 if(realm!=NULL) 85 86 87 88 89 ret=exist_username(avphdr->avp_value->os.data, avphdr->avp_value->os.len); 90 91 92 if(ret==2) 93 {//error 94 /* 95 If the Diameter server cannot process the Diameter LIR command, e.g., 96 due to a database error, the Diameter server MUST set the Result-Code 97 AVP value to DIAMETER_UNABLE_TO_COMPLY and return it in a Diameter 98 LIA message. 99 */ 100 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 101 goto out; 102 } 103 else if(ret==1) 104 {//not found 105 /* 106 One of the errors that the Diameter server may find is that the 107 SIP-AOR AVP value is not a valid user in the realm. In such cases, 108 the Diameter server MUST set the Result-Code AVP value to 109 DIAMETER_ERROR_USER_UNKNOWN and return it in a Diameter LIA message. 110 111 */ 112 strcpy(result,"DIAMETER_ERROR_USER_UNKNOWN"); 113 goto out; 114 } 115 116 //If we arrive here, the user is known 117 int sipserverurilen; 118 char * sipserver_uri=NULL; 119 120 ret=get_sipserver_uri(avphdr->avp_value->os.data, avphdr->avp_value->os.len, &sipserver_uri, &sipserverurilen); 121 122 123 if(ret==0) 124 {//found 125 if(sipserver_uri==NULL) 126 { 127 //There is a problem because we must get a Diameter_URI here 128 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 129 goto out; 130 } 131 else 132 { 133 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Server_URI, 0, &avp ) ); 134 value.os.data=(unsigned char *)sipserver_uri; 135 value.os.len=sipserverurilen; 136 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 137 CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, avp) ); 138 139 strcpy(result,"DIAMETER_SUCCESS"); 140 } 141 } 142 else if(ret==1) 143 {//not found 144 //We don't know this SIP_AOR in SL, that means 145 strcpy(result,"DIAMETER_ERROR_USER_UNKNOWN"); 146 goto out; 147 } 148 else 149 {// returned 2, impossible to make request 150 //We couldn't make the request, we must stop process! 151 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 152 goto out; 153 } 154 155 //Adding SIP-Server-Capabilities 156 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Server_Capabilities, 0, &groupedavp ) ); 157 //We add mandatory and optional capabilities 158 ret=get_sipserver_cap(avphdr->avp_value->os.data, avphdr->avp_value->os.len, &groupedavp); 159 160 161 if(ret==0) 162 {//found 163 if(sipserver_uri==NULL) 85 164 { 86 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Server_URI, 0, &avp ) ); 87 value.os.data=(unsigned char *)realm; 88 value.os.len=strlen(realm); 89 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 90 CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, avp) ); 165 //There is a problem because we must get a Diameter_URI here 166 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 167 CHECK_FCT( fd_msg_free( groupedavp ) ); 168 goto out; 91 169 } 92 170 else 93 171 { 94 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 95 goto out; 96 } 172 173 CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, groupedavp) ); 174 175 strcpy(result,"DIAMETER_SUCCESS"); 176 } 177 } 178 else if(ret==1) 179 {//not found 180 //We don't know this SIP_AOR in SL, that means 181 strcpy(result,"DIAMETER_ERROR_IDENTITY_NOT_REGISTERED"); 182 CHECK_FCT( fd_msg_free( groupedavp ) ); 183 goto out; 184 } 185 else 186 {// returned 2, impossible to make request 187 //We couldn't make the request, we must stop process! 188 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 189 CHECK_FCT( fd_msg_free( groupedavp ) ); 190 goto out; 191 } 192 193 194 97 195 } 98 196 -
extensions/app_sip/locationinfosl.c
r420 r427 61 61 ans = *msg; 62 62 63 //DEBUG64 fd_msg_dump_walk(INFO,qry);65 63 66 64 //Add the Auth-Application-Id … … 91 89 char * diameter_uri=NULL; 92 90 93 TRACE_DEBUG(INFO,"***********%d*********************************************",avphdr->avp_value->os.len);91 94 92 95 93 ret=get_diameter_uri(avphdr->avp_value->os.data, avphdr->avp_value->os.len, &diameter_uri, &diameterurilen); … … 108 106 CHECK_FCT( fd_msg_avp_new ( sip_dict.Redirect_Host, 0, &avp ) ); 109 107 value.os.data=diameter_uri; 110 value.os.len= strlen(diameter_uri);108 value.os.len=diameterurilen; 111 109 CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) ); 112 110 CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, avp ) ); … … 121 119 else if(ret==1) 122 120 {//not found 123 //We don't know this SIP_AOR in SL , that means121 //We don't know this SIP_AOR in SL 124 122 strcpy(result,"DIAMETER_ERROR_USER_UNKNOWN"); 125 123 goto out; … … 132 130 } 133 131 } 134 135 /*136 //TODO: wait for answer from authors to clear how to find SIP server!137 //Add a SIP_Server_URI138 {139 CHECK_FCT( fd_msg_search_avp ( qry, sip_dict.SIP_AOR, &avp) );140 CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr ) );141 142 //We extract Realm from SIP_AOR143 char *realm=NULL;144 145 146 realm = strtok( (char *)(avphdr->avp_value->os.data), "@" );147 realm = strtok( NULL, "@" );148 149 if(realm!=NULL)150 {151 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Server_URI, 0, &avp ) );152 value.os.data=(unsigned char *)realm;153 value.os.len=strlen(realm);154 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );155 CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, avp) );156 }157 else158 {159 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");160 goto out;161 }162 }163 164 */165 132 166 133 -
extensions/app_sip/multimediaauth.c
r420 r427 48 48 char * result; 49 49 char password[51]; 50 int idx=0, number_of_auth_items=0,i=0 ;50 int idx=0, number_of_auth_items=0,i=0, ret=0; 51 51 //Flags and variables for Database 52 52 int sipurinotstored=0, authenticationpending=0, querylen=0, usernamelen=0; … … 122 122 CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr ) ); 123 123 124 //We allocate the double size of username because at worst it can be all quotes 125 username=malloc(avphdr->avp_value->os.len*2+1); 126 //We purify username not to have forbidden characters 127 usernamelen=mysql_real_escape_string(conn, username, (const char *)avphdr->avp_value->os.data, avphdr->avp_value->os.len); 124 128 125 129 126 … … 132 129 not_found=1; 133 130 134 //We copy username in query 135 querylen=SQL_GETPASSWORD_LEN + usernamelen; 136 query = malloc(querylen+2); 137 snprintf(query, querylen+1, SQL_GETPASSWORD, username); 138 139 140 141 //We make the query 142 request_mysql(query); 143 res=mysql_use_result(conn); 144 if(res==NULL) 131 //TODO TODO TODO TODO TODO TODO TODO: maybe doesn't work!!' 132 ret=get_password(avphdr->avp_value->os.data, avphdr->avp_value->os.len, (char *)&password); 133 134 if(ret>1) 145 135 { 146 136 //We couldn't make the request … … 148 138 goto out; 149 139 } 150 151 152 153 while ((row = mysql_fetch_row(res)) != NULL) 154 { 155 if(strlen(row[0])>0) 156 { 157 strcpy(password,row[0]); 158 not_found=0; 159 break; 160 } 161 } 162 mysql_free_result(res); 163 free(query); 164 165 if(not_found) 140 not_found=ret; 141 142 if(not_found) 166 143 { 167 144 TRACE_DEBUG(FULL,"The user %s doesn't exist!",username); … … 172 149 173 150 174 151 //We allocate the double size of username because at worst it can be all quotes 152 username=malloc(avphdr->avp_value->os.len*2+1); 153 //We purify username not to have forbidden characters 154 usernamelen=mysql_real_escape_string(conn, username, (const char *)avphdr->avp_value->os.data, avphdr->avp_value->os.len); 155 175 156 //Now that we know the user exist, we get the list of AOR owned by this user 176 157 querylen=SQL_GETSIPAOR_LEN + usernamelen; … … 194 175 not_found=1; 195 176 while ((row = mysql_fetch_row(res)) != NULL) 196 197 198 199 200 201 202 203 204 177 { 178 if(strncmp((const char *)avphdr->avp_value->os.data,row[0],avphdr->avp_value->os.len)==0) 179 { 180 not_found=0; 181 break; 182 } 183 } 184 mysql_free_result(res); 185 free(query); 205 186 206 187 if(not_found) 207 188 { 208 189 TRACE_DEBUG(FULL,"The user %s can't use this SIP-AOR!",username); … … 244 225 not_found=1; 245 226 while ((row = mysql_fetch_row(res)) != NULL) 246 { 247 if(strncmp((const char *)avphdr->avp_value->os.data,row[0],avphdr->avp_value->os.len)==0) 248 { 249 not_found=0; 250 break; 251 } 252 } 253 mysql_free_result(res); 254 free(query); 255 256 if(not_found) 257 { 258 //We update the SIP_URI for the user and we flag "authentication in progress" 259 querylen=SQL_SETSIPURI_LEN + usernamelen + sipurilen; 260 query = malloc(querylen+2); 261 snprintf(query, querylen+1, SQL_SETSIPURI, sipuri, username); 262 263 //We make the query 264 request_mysql(query); 227 { 228 if(strncmp((const char *)avphdr->avp_value->os.data,row[0],avphdr->avp_value->os.len)==0) 229 { 230 not_found=0; 231 break; 232 } 233 } 234 mysql_free_result(res); 235 free(query); 236 237 if(not_found) 238 { 239 //Temporary 240 set_sipserver_uri(username, usernamelen, sipuri,sipurilen); 265 241 266 free(query); 267 authenticationpending=1; 268 } 269 free(sipuri); 242 243 set_pending_flag(username, usernamelen); 244 245 246 authenticationpending=1; 247 } 248 free(sipuri); 270 249 271 250 } … … 715 694 if(username!=NULL && authenticationpending) 716 695 { 717 //We clear the flag "authentication pending" 718 querylen=SQL_CLEARFLAG_LEN + usernamelen; 719 query = malloc(querylen+2); 720 snprintf(query, querylen+1, SQL_CLEARFLAG, username); 721 722 //We make the query 723 request_mysql(query); 724 725 free(query); 696 //We clear the pending flag 697 clear_pending_flag(username, usernamelen); 726 698 } 727 699 -
extensions/test_sip/CMakeLists.txt
r420 r427 11 11 multimediaauth.c 12 12 locationinfo.c 13 locationinfosl.c 13 14 registrationtermination.c 15 userauthorization.c 16 serverassignment.c 14 17 ) 15 18 -
extensions/test_sip/locationinfo.c
r420 r427 50 50 char *destination_realm="tera.ics.keio.ac.jp"; 51 51 size_t destination_realmlen=strlen(destination_realm); 52 char *destination_host=" biwa.tera.ics.keio.ac.jp";52 char *destination_host="suika.tera.ics.keio.ac.jp"; 53 53 size_t destination_hostlen=strlen(destination_host); 54 54 //Fake values STOP … … 108 108 } 109 109 110 111 112 110 //SIP_AOR 113 111 { -
extensions/test_sip/test_sip.c
r420 r427 130 130 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Realm", &sip_dict.Destination_Realm, ENOENT) ); 131 131 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &sip_dict.Session_Id, ENOENT) ); 132 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Redirect-Host", &sip_dict.Redirect_Host, ENOENT) ); 133 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Redirect-Host-Usage", &sip_dict.Redirect_Host_Usage, ENOENT) ); 132 134 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) ); 133 135 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authorization", &sip_dict.SIP_Authorization, ENOENT) ); … … 137 139 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authentication-Info", &sip_dict.SIP_Authentication_Info, ENOENT) ); 138 140 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Server-URI", &sip_dict.SIP_Server_URI, ENOENT) ); 141 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Server-Capabilities", &sip_dict.SIP_Server_Capabilities, ENOENT) ); 142 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Mandatory-Capability", &sip_dict.SIP_Mandatory_Capability, ENOENT) ); 143 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Optional-Capability", &sip_dict.SIP_Optional_Capability, ENOENT) ); 139 144 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Method", &sip_dict.SIP_Method, ENOENT) ); 140 145 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-AOR", &sip_dict.SIP_AOR, ENOENT) ); … … 142 147 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Reason-Code", &sip_dict.SIP_Reason_Code, ENOENT) ); 143 148 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Reason-Info", &sip_dict.SIP_Reason_Info, ENOENT) ); 149 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Accounting-Information", &sip_dict.SIP_Accounting_Information, ENOENT) ); 150 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) ); 151 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) ); 152 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) ); 153 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Item-Number", &sip_dict.SIP_Item_Number, ENOENT) ); 154 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) ); 155 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) ); 156 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-User-Data", &sip_dict.SIP_User_Data, ENOENT) ); 157 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) ); 158 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) ); 159 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) ); 160 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) ); 144 161 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Realm", &sip_dict.Digest_Realm, ENOENT) ); 145 162 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-URI", &sip_dict.Digest_URI, ENOENT) ); … … 155 172 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-QoP", &sip_dict.Digest_QOP, ENOENT) ); 156 173 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "User-Name", &sip_dict.User_Name, ENOENT) ); 157 158 174 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-HA1", &sip_dict.Digest_HA1, ENOENT) ); 159 175 … … 166 182 //**Command Codes 167 183 /**/ 168 //MA R184 //MAA 169 185 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Multimedia-Auth-Answer", &data.command, ENOENT) ); 170 186 CHECK_FCT( fd_disp_register( test_sip_MAA_cb, DISP_HOW_CC, &data, &test_sip_MAA_hdl ) ); 187 188 //UAA 189 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "User-Authorization-Answer", &data.command, ENOENT) ); 190 CHECK_FCT( fd_disp_register( test_sip_UAA_cb, DISP_HOW_CC, &data, &test_sip_UAA_hdl ) ); 171 191 172 192 //RTR … … 178 198 CHECK_FCT( fd_disp_register( test_sip_LIA_cb, DISP_HOW_CC, &data, &test_sip_LIA_hdl ) ); 179 199 200 //LIA 201 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Server-Assignment-Answer", &data.command, ENOENT) ); 202 CHECK_FCT( fd_disp_register( test_sip_SAA_cb, DISP_HOW_CC, &data, &test_sip_SAA_hdl ) ); 180 203 181 204 //Callback for unexpected messages … … 189 212 190 213 CHECK_FCT(fd_sess_handler_create(&ts_sess_hdl, free)); 191 CHECK_FCT( fd_sig_register(30, "test_sip", (void *)test_sip_LIR_cb ) ); 214 //CHECK_FCT( fd_sig_register(30, "test_sip", (void *)test_sipSL_LIR_cb ) ); 215 CHECK_FCT( fd_sig_register(30, "test_sip", (void *)test_sip_SAR_cb ) ); 216 CHECK_FCT( fd_sig_register(31, "test_sip", (void *)test_sip_LIR_cb ) ); 192 217 193 218 return 0; -
extensions/test_sip/test_sip.h
r420 r427 58 58 struct dict_object * Auth_Application_Id; 59 59 struct dict_object * Destination_Host; 60 struct dict_object * Destination_Realm;61 60 struct dict_object * User_Name; 62 61 struct dict_object * Session_Id; 62 struct dict_object * Redirect_Host; 63 struct dict_object * Redirect_Host_Usage; 63 64 struct dict_object * SIP_Auth_Data_Item; 65 struct dict_object * SIP_Accounting_Information; 66 struct dict_object * SIP_Accounting_Server_URI; 67 struct dict_object * SIP_Credit_Control_Server_URI; 68 struct dict_object * SIP_Server_Assignment_Type; 69 struct dict_object * SIP_Item_Number; 70 struct dict_object * SIP_User_Authorization_Type; 71 struct dict_object * SIP_Supported_User_Data_Type; 72 struct dict_object * SIP_User_Data; 73 struct dict_object * SIP_User_Data_Type; 74 struct dict_object * SIP_User_Data_Contents; 75 struct dict_object * SIP_User_Data_Already_Available; 76 struct dict_object * SIP_Visited_Network_Id; 64 77 struct dict_object * SIP_Authorization; 65 78 struct dict_object * SIP_Authenticate; … … 68 81 struct dict_object * SIP_Authentication_Info; 69 82 struct dict_object * SIP_Server_URI; 83 struct dict_object * SIP_Server_Capabilities; 84 struct dict_object * SIP_Mandatory_Capability; 85 struct dict_object * SIP_Optional_Capability; 70 86 struct dict_object * SIP_Method; 71 87 struct dict_object * SIP_AOR; … … 85 101 struct dict_object * Digest_Algorithm; 86 102 struct dict_object * Digest_HA1; 103 struct dict_object * Destination_Realm; 87 104 }; 88 105 … … 94 111 95 112 int test_sip_LIR_cb(); 113 int test_sip_UAR_cb(); 114 int test_sip_SAR_cb(); 115 int test_sipSL_LIR_cb(); 96 116 97 117 int test_sip_default_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); 98 118 int test_sip_MAA_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); 99 119 int test_sip_RTR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); 120 int test_sip_UAA_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); 100 121 int test_sip_LIA_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); 101 122 int test_sip_SAA_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act); 123 int test_sipSL_LIA_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act);
Note: See TracChangeset
for help on using the changeset viewer.