Navigation



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/serverassignment.c

    r430 r432  
    4242       
    4343        struct msg *ans, *qry;
    44         struct avp *avp, *groupedavp=NULL;
     44        struct avp *avp;
    4545        struct avp_hdr *avphdr, *sipaorhdr, *usernamehdr, *sipuserdataalreadyavailable;
    4646        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;
    4848       
    4949       
     
    176176        }
    177177       
    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       
    256181       
    257182        //We get SIP_User_Data_Already_Available AVP
     
    263188        if(assignment_type==1 || assignment_type==2)
    264189        {//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)
    266228                {
    267229                        if(sipuserdataalreadyavailable->avp_value->i32==0)
     
    269231                                if(got_datatype==1)
    270232                                {
    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                                        }
    296251                                }
    297252                        }
     
    309264                        if(got_datatype==1)
    310265                        {
    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                                }
    313284                        }
    314285                }
     
    338309                        {//Data not available, we must provide it
    339310                               
    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                                }
    346329                        }
    347330                }
     
    399382                if(avp!=NULL)
    400383                {
    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
    408435                        {
    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                       
    420443                       
    421444                       
     
    428451                else
    429452                {
    430                         TRACE_DEBUG(INFO, "There was no SIP-AOR in 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!'");
    431454                        strcpy(result,"DIAMETER_UNABLE_TO_COMPLY");
    432455                        goto out;
     
    435458        else if(assignment_type==9 || assignment_type==10)
    436459        {
    437                 if(count_sipaor(qry)==1)
     460                if(count_avp(qry, CODE_SIP_AOR,0)==1)
    438461                {
    439462                        //TODO: remove SIP-server URI for sip_aor
Note: See TracChangeset for help on using the changeset viewer.