Navigation


Changeset 432:533188d2e6cc in freeDiameter for extensions/app_sip/libdiamsip.c


Ignore:
Timestamp:
Jul 28, 2010, 3:14:11 AM (14 years ago)
Author:
Alexandre Westfahl <awestfahl@freediameter.net>
Branch:
default
Phase:
public
Message:

Corrected bugs on SAR/SAA; added SQL files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/app_sip/libdiamsip.c

    r430 r432  
    584584
    585585//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;
     586int 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;
    592593        union avp_value value;
    593594        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;
    599600       
    600601        //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security
     
    604605                case ASMYSQL:
    605606                       
    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);
     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);
    617618                       
    618619                        MYSQL_RES *res;
     
    628629                        }
    629630                        not_found=1;
    630                        
    631                         counter=0;
    632                         unsigned long *length=0;
    633                        
    634                         //int index=0;//current field number
    635                        
    636631                        while ((row = mysql_fetch_row(res)) != NULL)
    637632                        {
    638633                                length=mysql_fetch_lengths(res);
    639634                               
    640                                 for(counter=0;counter<num_elements; counter++)
     635                                if(strlen(row[0])>1)
    641636                                {
    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;
    665658                                }
    666                                 //index++;
     659                               
    667660                        }
    668661                       
    669662                        mysql_free_result(res);
    670663                        free(query);
    671                         free(username_pure);
     664                        free(sipaor_pure);
    672665                        break;
    673666                       
     
    683676        //0 if it was found
    684677        return not_found;
     678       
     679       
    685680       
    686681}
     
    952947}
    953948
    954 int count_sipaor(const struct msg * message)
     949
     950int count_avp(struct msg * message, int code, int vendor)
    955951{
    956952        CHECK_PARAMS(message);
     
    960956        int counter=0;
    961957       
    962         CHECK_FCT(fd_msg_browse ( &message, MSG_BRW_WALK, &avp, NULL));
     958        CHECK_FCT(fd_msg_browse (message, MSG_BRW_WALK, &avp, NULL));
    963959       
    964960        while(avp!=NULL)
     
    967963                CHECK_FCT( fd_msg_avp_hdr( avp,&temphdr ));
    968964               
    969                 if(temphdr->avp_code==122 && temphdr->avp_vendor==0)
     965                if(temphdr->avp_code==code && temphdr->avp_vendor==vendor)
    970966                {
    971967                        counter++;
    972968                }
    973969               
    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));
    999971        }
    1000972        return counter;
Note: See TracChangeset for help on using the changeset viewer.