Changeset 432:533188d2e6cc in freeDiameter
- Timestamp:
- Jul 28, 2010, 3:14:11 AM (14 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 5 added
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/app_sip.conf.sample
r392 r432 1 1 2 2 # MODE Diameter-SIP server (DSSERVER) or Subscriber Locator (SL) 3 #You must have at least in your network a Diameter SIP server and a Subscriber Locator (on different nodes) 3 4 mode = DSSERVER; 4 5 6 7 #******************# 8 #*****DATABASE*****# 9 #******************# 5 10 # DATASOURCE: MYSQL 6 11 datasource = MYSQL; … … 11 16 mysql_database = "db"; 12 17 mysql_server = "server.fr"; 18 19 #If value=0, default port for mysql will be set 13 20 mysql_port = 0; 21 22 #Prefix for tables (default is "ds") 23 mysql_prefix = "ds"; -
extensions/app_sip/diamsip.h
r430 r432 92 92 int get_password(const unsigned char *username, const size_t usernamelen, char *password); 93 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);94 int add_user_datatype(const unsigned char *sip_aor, const size_t sipaorlen,struct msg *message); 95 95 int set_pending_flag(const unsigned char *username, const size_t usernamelen); 96 96 int clear_pending_flag(const unsigned char *username, const size_t usernamelen); … … 101 101 102 102 //count functions 103 int count_supporteddatatype(const struct msg * message); 104 int count_sipaor(const struct msg * message); 103 int count_avp(struct msg * message, int code, int vendor); 105 104 106 105 … … 164 163 165 164 //sip server uri by SIP-AOR 166 #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`"167 #define SQL_GETSIPSERURI_LEN 1 19165 #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`" 166 #define SQL_GETSIPSERURI_LEN 132 168 167 169 168 //sip capabilities for a SIP-AOR … … 172 171 173 172 //user data for a user data supported 174 #define SQL_GET USEDATA "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`"175 #define SQL_GET USEDATA_LEN 206176 177 #define SQL_GETDIAMURI "SELECT `diameter_uri` FROM sl_sip_aor_map WHERE `sip_aor` ='%s'"173 #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`" 174 #define SQL_GETSIPDATA_LEN 216 175 176 #define SQL_GETDIAMURI "SELECT `diameter_uri` FROM ds_sip_aor_map WHERE `sip_aor` ='%s'" 178 177 #define SQL_GETDIAMURI_LEN 61 179 178 … … 207 206 extern struct session_handler * ds_sess_hdl; 208 207 209 208 //AVP code 209 #define CODE_SIP_USER_DATA_TYPE 388 210 #define CODE_SIP_AOR 122 210 211 211 212 struct ds_nonce -
extensions/app_sip/libdiamsip.c
r430 r432 584 584 585 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; 586 int add_user_datatype(const unsigned char *sip_aor, const size_t sipaorlen,struct msg *message) 587 { 588 CHECK_PARAMS(sip_aor && sipaorlen && message ); 589 590 size_t querylen, sipaorpurelen; 591 char *query, *sipaor_pure; 592 int not_found=2; 592 593 union avp_value value; 593 594 struct avp *avp, *rootavp; 594 size_t querylen, usernamepurelen;595 char *query, *username_pure;596 597 if( num_elements<1)598 return 1;595 unsigned long *length; 596 597 //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars 598 if(sipaorlen<5) 599 return 2; 599 600 600 601 //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security … … 604 605 case ASMYSQL: 605 606 606 querylen=SQL_GET USEDATA_LEN + usernamelen;607 608 609 //We allocate the double size of usernamebecause at worst it can be all quotes610 username_pure=malloc(usernamelen*2+1);611 //We purify usernamenot to have forbidden characters612 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_GET USEDATA, username_pure);607 querylen=SQL_GETSIPDATA_LEN + sipaorlen; 608 609 610 //We allocate the double size of SIP-URI because at worst it can be all quotes 611 CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1)); 612 //We purify SIP-URI not to have forbidden characters 613 sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen); 614 615 616 query = malloc(querylen+sipaorpurelen+ 2); 617 snprintf(query, querylen+1, SQL_GETSIPDATA, sipaor_pure); 617 618 618 619 MYSQL_RES *res; … … 628 629 } 629 630 not_found=1; 630 631 counter=0;632 unsigned long *length=0;633 634 //int index=0;//current field number635 636 631 while ((row = mysql_fetch_row(res)) != NULL) 637 632 { 638 633 length=mysql_fetch_lengths(res); 639 634 640 for(counter=0;counter<num_elements; counter++)635 if(strlen(row[0])>1) 641 636 { 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 } 637 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data, 0, &rootavp ) ); 638 639 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data_Type, 0, &avp ) ); 640 CHECK_MALLOC(value.os.data=malloc(length[0]*sizeof(unsigned char))); 641 strncpy((char *)value.os.data,(char *)row[0],length[0]); 642 value.os.len=(size_t)length[0]; 643 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 644 CHECK_FCT( fd_msg_avp_add ( rootavp, MSG_BRW_LAST_CHILD, avp) ); 645 646 647 648 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_User_Data_Contents, 0, &avp ) ); 649 CHECK_MALLOC(value.os.data=malloc(length[1]*sizeof(unsigned char))); 650 memcpy(value.os.data,row[1],length[1]); 651 value.os.len=(size_t)length[1]; 652 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 653 CHECK_FCT( fd_msg_avp_add ( rootavp, MSG_BRW_LAST_CHILD, avp) ); 654 655 //We add SIP_User_Data to message 656 CHECK_FCT( fd_msg_avp_add ( message, MSG_BRW_LAST_CHILD, rootavp) ); 657 not_found=0; 665 658 } 666 //index++;659 667 660 } 668 661 669 662 mysql_free_result(res); 670 663 free(query); 671 free( username_pure);664 free(sipaor_pure); 672 665 break; 673 666 … … 683 676 //0 if it was found 684 677 return not_found; 678 679 685 680 686 681 } … … 952 947 } 953 948 954 int count_sipaor(const struct msg * message) 949 950 int count_avp(struct msg * message, int code, int vendor) 955 951 { 956 952 CHECK_PARAMS(message); … … 960 956 int counter=0; 961 957 962 CHECK_FCT(fd_msg_browse ( &message, MSG_BRW_WALK, &avp, NULL));958 CHECK_FCT(fd_msg_browse (message, MSG_BRW_WALK, &avp, NULL)); 963 959 964 960 while(avp!=NULL) … … 967 963 CHECK_FCT( fd_msg_avp_hdr( avp,&temphdr )); 968 964 969 if(temphdr->avp_code== 122 && temphdr->avp_vendor==0)965 if(temphdr->avp_code==code && temphdr->avp_vendor==vendor) 970 966 { 971 967 counter++; 972 968 } 973 969 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)); 970 CHECK_FCT(fd_msg_browse (avp, MSG_BRW_WALK, &avp, NULL)); 999 971 } 1000 972 return counter; -
extensions/app_sip/serverassignment.c
r430 r432 42 42 43 43 struct msg *ans, *qry; 44 struct avp *avp , *groupedavp=NULL;44 struct avp *avp; 45 45 struct avp_hdr *avphdr, *sipaorhdr, *usernamehdr, *sipuserdataalreadyavailable; 46 46 union avp_value value; 47 int ret=0, assignment_type=0, supported_datatype=0, got_datatype=0;47 int ret=0, assignment_type=0, got_datatype=1; 48 48 49 49 … … 176 176 } 177 177 178 //TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO : check which assignment need data type 179 //We check if we have SIP_Supported_User_Data_Type and we make a table with all of them 180 { 181 supported_datatype=count_supporteddatatype(qry); 182 183 if(supported_datatype>0) 184 { 185 char ** table_supporteddatatype=NULL; 186 187 //TODO: maybe table doesn't work' 188 //We make a table of char * to store all supported datatypes 189 CHECK_MALLOC(table_supporteddatatype=(char**)realloc(table_supporteddatatype,supported_datatype*sizeof(char *))); 190 191 192 CHECK_FCT(fd_msg_browse ( qry, MSG_BRW_WALK, &avp, NULL)); 193 int counter=0; 194 195 while(avp!=NULL) 196 { 197 198 CHECK_FCT( fd_msg_avp_hdr( avp,&avphdr )); 199 200 //TODO: check if counter is good! 201 if(avphdr->avp_code==388 && avphdr->avp_vendor==0 && counter<supported_datatype) 202 { 203 204 CHECK_MALLOC(table_supporteddatatype[counter]=malloc(avphdr->avp_value->os.len+1)); 205 strncpy(table_supporteddatatype[counter],(const char *)avphdr->avp_value->os.data,avphdr->avp_value->os.len); 206 table_supporteddatatype[counter][avphdr->avp_value->os.len+1]='\0'; 207 208 counter++; 209 } 210 211 CHECK_FCT(fd_msg_browse ( qry, MSG_BRW_WALK, &avp, NULL)); 212 } 213 214 if(usernamehdr!=NULL) 215 { 216 ret=get_user_datatype(usernamehdr->avp_value->os.data, usernamehdr->avp_value->os.len,(char **)table_supporteddatatype, counter, &groupedavp); 217 218 //We free all unused datatypes 219 int i=0; 220 for(i=0;i<counter;i++) 221 { 222 if(table_supporteddatatype[counter]!=NULL) 223 free(table_supporteddatatype[counter]); 224 } 225 226 if(ret==0) 227 { 228 got_datatype=1; 229 230 } 231 else if(ret==1) 232 { 233 TRACE_DEBUG(INFO,"There was no link between supported and transmisted SIP-User-Data AVPs"); 234 } 235 else 236 { 237 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 238 goto out; 239 } 240 241 } 242 else 243 { 244 strcpy(result,"DIAMETER_USER_NAME_REQUIRED"); 245 int i=0; 246 for(i=0;i<counter;i++) 247 { 248 if(table_supporteddatatype[counter]!=NULL) 249 free(table_supporteddatatype[counter]); 250 } 251 goto out; 252 } 253 254 } 255 } 178 179 180 256 181 257 182 //We get SIP_User_Data_Already_Available AVP … … 263 188 if(assignment_type==1 || assignment_type==2) 264 189 {//registration & re-registration 265 if(count_sipaor(qry)==1) 190 if(count_avp(qry,CODE_SIP_AOR,0)==1) 191 { 192 193 if(sipuserdataalreadyavailable->avp_value->i32==0) 194 {//Data not available, we must provide it 195 ret=add_user_datatype(sipaorhdr->avp_value->os.data, sipaorhdr->avp_value->os.len,ans); 196 197 if(ret==0) 198 { 199 //We found and added datatype 200 got_datatype=1; 201 } 202 else if(ret==1) 203 { 204 //No data type was found 205 got_datatype=0; 206 } 207 else 208 {//error 209 //We couldn't make the request, we must stop process! 210 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 211 goto out; 212 } 213 } 214 strcpy(result,"DIAMETER_SUCCESS"); 215 goto out; 216 } 217 else 218 {//There is more than 1 SIP-AOR AVP 219 strcpy(result,"DIAMETER_AVP_OCCURS_TOO_MANY_TIMES"); 220 goto out; 221 } 222 } 223 else if(assignment_type==3) 224 {//Unregistered user 225 226 //TODO:place user unknown here! 227 if(count_avp(qry,CODE_SIP_AOR,0)==1) 266 228 { 267 229 if(sipuserdataalreadyavailable->avp_value->i32==0) … … 269 231 if(got_datatype==1) 270 232 { 271 //We provide User Data 272 CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, groupedavp) ); 273 } 274 } 275 strcpy(result,"DIAMETER_SUCCESS"); 276 goto out; 277 } 278 else 279 {//There is more than 1 SIP-AOR AVP 280 strcpy(result,"DIAMETER_AVP_OCCURS_TOO_MANY_TIMES"); 281 goto out; 282 } 283 } 284 else if(assignment_type==3) 285 {//Unregistered user 286 287 //TODO:place user unknown here! 288 if(count_sipaor(qry)==1) 289 { 290 if(sipuserdataalreadyavailable->avp_value->i32==0) 291 {//Data not available, we must provide it 292 if(got_datatype==1) 293 { 294 //We provide User Data 295 CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, groupedavp) ); 233 ret=add_user_datatype(sipaorhdr->avp_value->os.data, sipaorhdr->avp_value->os.len,ans); 234 235 if(ret==0) 236 { 237 //We found and added datatype 238 got_datatype=1; 239 } 240 else if(ret==1) 241 { 242 //No data type was found 243 got_datatype=0; 244 } 245 else 246 {//error 247 //We couldn't make the request, we must stop process! 248 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 249 goto out; 250 } 296 251 } 297 252 } … … 309 264 if(got_datatype==1) 310 265 { 311 //We provide User Data 312 CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, groupedavp) ); 266 ret=add_user_datatype(sipaorhdr->avp_value->os.data, sipaorhdr->avp_value->os.len,ans); 267 268 if(ret==0) 269 { 270 //We found and added datatype 271 got_datatype=1; 272 } 273 else if(ret==1) 274 { 275 //No data type was found 276 got_datatype=0; 277 } 278 else 279 {//error 280 //We couldn't make the request, we must stop process! 281 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 282 goto out; 283 } 313 284 } 314 285 } … … 338 309 {//Data not available, we must provide it 339 310 340 //We provide User Data 341 CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, groupedavp) ); 342 } 343 else 344 { 345 CHECK_FCT( fd_msg_free( groupedavp ) ); 311 ret=add_user_datatype(sipaorhdr->avp_value->os.data, sipaorhdr->avp_value->os.len,ans); 312 313 if(ret==0) 314 { 315 //We found and added datatype 316 got_datatype=1; 317 } 318 else if(ret==1) 319 { 320 //No data type was found 321 got_datatype=0; 322 } 323 else 324 {//error 325 //We couldn't make the request, we must stop process! 326 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 327 goto out; 328 } 346 329 } 347 330 } … … 399 382 if(avp!=NULL) 400 383 { 401 //TODO: check that SIP-server_URI provided is the same as associated and answer unable to comply if so 402 //TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO here 403 404 405 CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr )); 406 407 if(got_datatype==1) 384 unsigned char * sipserver_uri; 385 size_t sipserverurilen; 386 387 388 389 390 ret=get_sipserver_uri(sipaorhdr->avp_value->os.data, sipaorhdr->avp_value->os.len, &sipserver_uri, &sipserverurilen); 391 392 if(ret==0) 393 {//found 394 CHECK_FCT( fd_msg_avp_hdr( avp, &avphdr )); 395 396 397 398 399 if(strncmp((char *)avphdr->avp_value->os.data,(char *)sipserver_uri,sipserverurilen)) 400 { 401 if(got_datatype==1) 402 { 403 if(sipuserdataalreadyavailable->avp_value->i32==0) 404 {//Data not available, we must provide it 405 406 ret=add_user_datatype(sipaorhdr->avp_value->os.data, sipaorhdr->avp_value->os.len,ans); 407 408 if(ret==0) 409 { 410 //We found and added datatype 411 got_datatype=1; 412 } 413 else if(ret==1) 414 { 415 //No data type was found 416 got_datatype=0; 417 } 418 else 419 {//error 420 //We couldn't make the request, we must stop process! 421 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 422 goto out; 423 } 424 } 425 } 426 } 427 else 428 {//error 429 TRACE_DEBUG(FULL,"SIP_Server_URI is different from the one in database"); 430 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 431 goto out; 432 } 433 } 434 else 408 435 { 409 if(sipuserdataalreadyavailable->avp_value->i32==0) 410 {//Data not available, we must provide it 411 412 //We provide User Data 413 CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, groupedavp) ); 414 } 415 else 416 { 417 CHECK_FCT( fd_msg_free( groupedavp ) ); 418 } 419 } 436 TRACE_DEBUG(FULL,"SIP_Server_URI is different from the one in database"); 437 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 438 goto out; 439 } 440 441 442 420 443 421 444 … … 428 451 else 429 452 { 430 TRACE_DEBUG(INFO, "There was no SIP -AORin this request, we can't proceed request!'");453 TRACE_DEBUG(INFO, "There was no SIP_Server_URI in this request, we can't proceed request!'"); 431 454 strcpy(result,"DIAMETER_UNABLE_TO_COMPLY"); 432 455 goto out; … … 435 458 else if(assignment_type==9 || assignment_type==10) 436 459 { 437 if(count_ sipaor(qry)==1)460 if(count_avp(qry, CODE_SIP_AOR,0)==1) 438 461 { 439 462 //TODO: remove SIP-server URI for sip_aor -
extensions/test_sip/serverassignment.c
r430 r432 46 46 47 47 //Fake values START 48 48 char *sip_aor="sip:aw-lappy@tera.ics.keio.ac.jp"; 49 49 size_t aor_len=strlen(sip_aor); 50 50 char *destination_realm="tera.ics.keio.ac.jp"; 51 51 size_t destination_realmlen=strlen(destination_realm); 52 52 char *destination_host="suika.tera.ics.keio.ac.jp"; 53 53 size_t destination_hostlen=strlen(destination_host); 54 54 char *username="aw-lappy"; 55 55 size_t usernamelen=strlen(username); 56 char *sipserveruri="sip:ichigo@tera.ics.keio.ac.jp"; 57 size_t sipserverurilen=strlen(sipserveruri); 56 58 // char *visitednetwork="Pink"; 57 59 //size_t visitednetworklen=strlen(visitednetwork); … … 149 151 CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) ); 150 152 } 153 //SIP_server_uri 154 { 155 156 CHECK_FCT( fd_msg_avp_new ( sip_dict.SIP_Server_URI, 0, &avp ) ); 157 value.os.data=(unsigned char *)sipserveruri; 158 value.os.len=sipserverurilen; 159 CHECK_FCT( fd_msg_avp_setvalue( avp, &value ) ); 160 CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_LAST_CHILD, avp ) ); 161 162 } 151 163 152 164 fd_msg_dump_walk(INFO,message);
Note: See TracChangeset
for help on using the changeset viewer.