Changeset 432:533188d2e6cc in freeDiameter for extensions/app_sip/libdiamsip.c
- Timestamp:
- Jul 28, 2010, 3:14:11 AM (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note: See TracChangeset
for help on using the changeset viewer.