Navigation


Changeset 409:c2fb5b26bfcb in freeDiameter


Ignore:
Timestamp:
Jul 8, 2010, 4:19:28 PM (14 years ago)
Author:
Alexandre Westfahl <awestfahl@freediameter.net>
Branch:
default
Phase:
public
Message:

Fix for ticket 8

Location:
extensions
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • extensions/app_sip/diamsip.c

    r392 r409  
    3737
    3838struct disp_hdl * diamsip_MAR_hdl=NULL;
     39struct disp_hdl * diamsip_LIR_hdl=NULL;
     40struct disp_hdl * diamsip_UAR_hdl=NULL;
     41struct disp_hdl * diamsip_SAR_hdl=NULL;
     42struct disp_hdl * diamsip_PPA_hdl=NULL;
     43struct disp_hdl * diamsip_RTA_hdl=NULL;
     44
     45
    3946struct disp_hdl * diamsip_default_hdl=NULL;
    4047struct session_handler * ds_sess_hdl;
     
    137144        memset(&data, 0, sizeof(data));
    138145        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Session Initiation Protocol (SIP) Application", &data.app, ENOENT) );
    139         CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Multimedia-Auth-Request", &data.command, ENOENT) );
    140146       
    141         //Callback for unexpected messages
    142         CHECK_FCT( fd_disp_register( diamsip_MAR_cb, DISP_HOW_APPID, &data, &diamsip_default_hdl ) );
    143147       
    144148        //**Command Codes
    145149        //MAR
     150        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Multimedia-Auth-Request", &data.command, ENOENT) );
    146151        CHECK_FCT( fd_disp_register( diamsip_MAR_cb, DISP_HOW_CC, &data, &diamsip_MAR_hdl ) );
     152        //RTA
     153        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Registration-Termination-Answer", &data.command, ENOENT) );
     154        CHECK_FCT( fd_disp_register( diamsip_RTA_cb, DISP_HOW_CC, &data, &diamsip_RTA_hdl ) );
    147155       
    148         //TRACE_DEBUG(INFO,"*%s*%s*%s*%s*",DB_SERVER,DB_USERNAME, DB_PASSWORD, DB_DATABASE);
     156        //Callback for unexpected messages
     157        CHECK_FCT( fd_disp_register( diamsip_default_cb, DISP_HOW_APPID, &data, &diamsip_default_hdl ) );
     158       
     159       
    149160        //We start database connection
    150161        if(start_mysql_connection())
     
    160171{
    161172       
    162         if (diamsip_MAR_cb) {
    163                 (void) fd_disp_unregister(&diamsip_MAR_hdl);
    164                 CHECK_FCT_DO( fd_sess_handler_destroy(&ds_sess_hdl),return);
    165         }
     173       
     174        (void) fd_disp_unregister(&diamsip_MAR_hdl);
     175        CHECK_FCT_DO( fd_sess_handler_destroy(&ds_sess_hdl),return);
     176       
    166177       
    167178        //We close database connection
  • extensions/app_sip/diamsip.h

    r392 r409  
    7676
    7777void calc_md5(char *buffer, char * data);
    78 void clear_digest(char * digest, char * readable_digest, int digestlength);
     78void clear_digest(uint8_t * digest, char * readable_digest, int digestlength);
    7979struct avp_hdr * walk_digest(struct avp *avp, int avp_code);
    8080int start_mysql_connection();
     
    8282void close_mysql_connection();
    8383
     84void DigestCalcHA1(char * pszAlg,char * pszUserName,char * pszRealm,char * pszPassword,char * pszNonce,char * pszCNonce,HASHHEX SessionKey);
     85void DigestCalcResponse(HASHHEX HA1,char * pszNonce,char * pszNonceCount,char * pszCNonce,char * pszQop,char * pszMethod,char * pszDigestUri,HASHHEX HEntity,HASHHEX Response);
     86void DigestCalcResponseAuth(HASHHEX HA1,char * pszNonce,char * pszNonceCount,char * pszCNonce,char * pszQop,char * pszMethod,char * pszDigestUri,HASHHEX HEntity,HASHHEX Response);
    8487
     88int fd_avp_search_avp ( struct avp * groupedavp, struct dict_object * what, struct avp ** avp );
    8589
    8690int ds_entry();
     
    8892int diamsip_default_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act);
    8993int diamsip_MAR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act);
     94int diamsip_RTA_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act);
    9095#define SQL_GETPASSWORD "SELECT `password` FROM ds_users WHERE `username` ='%s'"
    9196#define SQL_GETPASSWORD_LEN 52
  • extensions/app_sip/libdiamsip.c

    r392 r409  
    3838
    3939MYSQL *conn;
    40 /*
    41 void calculate_nonce(u8 * nonce)
    42 {
    43 
    44         nonce="lkgbsljhsdjdsgj";
    45         return;
    46 }*/
    47 
    48 void clear_digest(char * digest, char * readable_digest, int digestlength)
     40
     41void clear_digest(uint8_t * digest, char * readable_digest, int digestlength)
    4942{
    5043        int i=0;
     
    8174        struct avp_hdr * nextavphdr;
    8275        struct dict_avp_data    dictdata;
    83         enum dict_object_type   dicttype;
     76       
    8477       
    8578        TRACE_ENTRY("%p %p %p", groupedavp, what, avp);
     
    125118{
    126119        struct avp_hdr *temphdr=NULL;
    127         CHECK_FCT_DO(fd_msg_browse ( avp, MSG_BRW_WALK, &avp, NULL),0 );
     120        CHECK_FCT_DO(fd_msg_browse ( avp, MSG_BRW_WALK, &avp, NULL),return NULL);
    128121       
    129122        while(avp!=NULL)
    130123        {
    131124               
    132                 CHECK_FCT_DO( fd_msg_avp_hdr( avp,&temphdr ),0);
     125                CHECK_FCT_DO( fd_msg_avp_hdr( avp,&temphdr ),return NULL);
    133126
    134127                if(temphdr->avp_code==avp_code)
     
    149142                else
    150143                {
    151                         CHECK_FCT_DO(fd_msg_browse ( avp, MSG_BRW_WALK, &avp, NULL),0 );
     144                        CHECK_FCT_DO(fd_msg_browse ( avp, MSG_BRW_WALK, &avp, NULL),return NULL);
    152145                        temphdr=NULL;
    153146                       
  • extensions/app_sip/md5.c

    r360 r409  
    5353
    5454      MD5Init(&Md5Ctx);
    55       MD5Update(&Md5Ctx, pszUserName, strlen(pszUserName));
    56       MD5Update(&Md5Ctx, ":", 1);
    57       MD5Update(&Md5Ctx, pszRealm, strlen(pszRealm));
    58       MD5Update(&Md5Ctx, ":", 1);
    59       MD5Update(&Md5Ctx, pszPassword, strlen(pszPassword));
    60       MD5Final(HA1, &Md5Ctx);
     55      MD5Update(&Md5Ctx, (const unsigned char *)pszUserName, strlen(pszUserName));
     56      MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
     57      MD5Update(&Md5Ctx, (const unsigned char *)pszRealm, strlen(pszRealm));
     58      MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
     59      MD5Update(&Md5Ctx, (const unsigned char *)pszPassword, strlen(pszPassword));
     60      MD5Final((unsigned char *)HA1, &Md5Ctx);
    6161      if (strcmp(pszAlg, "md5-sess") == 0) {   
    6262                MD5Init(&Md5Ctx);
    63                 MD5Update(&Md5Ctx, HA1, HASHLEN);
    64                 MD5Update(&Md5Ctx, ":", 1);
    65                 MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce));
    66                 MD5Update(&Md5Ctx, ":", 1);
    67                 MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
    68                 MD5Final(HA1, &Md5Ctx);
     63                MD5Update(&Md5Ctx, (const unsigned char *)HA1, HASHLEN);
     64                MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
     65                MD5Update(&Md5Ctx, (const unsigned char *)pszNonce, strlen(pszNonce));
     66                MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
     67                MD5Update(&Md5Ctx, (const unsigned char *)pszCNonce, strlen(pszCNonce));
     68                MD5Final((unsigned char *)HA1, &Md5Ctx);
    6969      }
    7070      CvtHex(HA1, SessionKey);
     
    8181      // calculate H(A2)
    8282      MD5Init(&Md5Ctx);
    83       MD5Update(&Md5Ctx, pszMethod, strlen(pszMethod));
    84       MD5Update(&Md5Ctx, ":", 1);
    85       MD5Update(&Md5Ctx, pszDigestUri, strlen(pszDigestUri));
     83      MD5Update(&Md5Ctx, (const unsigned char *)pszMethod, strlen(pszMethod));
     84      MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
     85      MD5Update(&Md5Ctx, (const unsigned char *)pszDigestUri, strlen(pszDigestUri));
    8686      if (strcmp(pszQop, "auth-int") == 0) {
    87             MD5Update(&Md5Ctx, ":", 1);
    88             MD5Update(&Md5Ctx, HEntity, HASHHEXLEN);
     87            MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
     88            MD5Update(&Md5Ctx, (const unsigned char *)HEntity, HASHHEXLEN);
    8989      }
    90       MD5Final(HA2, &Md5Ctx);
     90      MD5Final((unsigned char *)HA2, &Md5Ctx);
    9191       CvtHex(HA2, HA2Hex);
    9292       
    9393      // calculate response
    9494      MD5Init(&Md5Ctx);
    95       MD5Update(&Md5Ctx, HA1, HASHHEXLEN);
    96       MD5Update(&Md5Ctx, ":", 1);
    97       MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce));
    98       MD5Update(&Md5Ctx, ":", 1);
     95      MD5Update(&Md5Ctx, (const unsigned char *)HA1, HASHHEXLEN);
     96      MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
     97      MD5Update(&Md5Ctx,(const unsigned char *) pszNonce, strlen(pszNonce));
     98      MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
    9999      if (*pszQop) {
    100           MD5Update(&Md5Ctx, pszNonceCount, strlen(pszNonceCount));
    101           MD5Update(&Md5Ctx, ":", 1);
    102           MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
    103           MD5Update(&Md5Ctx, ":", 1);
    104           MD5Update(&Md5Ctx, pszQop, strlen(pszQop));
    105           MD5Update(&Md5Ctx, ":", 1);
     100          MD5Update(&Md5Ctx, (const unsigned char *)pszNonceCount, strlen(pszNonceCount));
     101          MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
     102          MD5Update(&Md5Ctx, (const unsigned char *)pszCNonce, strlen(pszCNonce));
     103          MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
     104          MD5Update(&Md5Ctx, (const unsigned char *)pszQop, strlen(pszQop));
     105          MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
    106106      }
    107       MD5Update(&Md5Ctx, HA2Hex, HASHHEXLEN);
    108       MD5Final(RespHash, &Md5Ctx);
     107      MD5Update(&Md5Ctx, (const unsigned char *)HA2Hex, HASHHEXLEN);
     108      MD5Final((unsigned char *)RespHash, &Md5Ctx);
    109109      CvtHex(RespHash, Response);
    110110}
     
    119119      // calculate H(A2)
    120120      MD5Init(&Md5Ctx);
    121       MD5Update(&Md5Ctx, ":", 1);
    122       MD5Update(&Md5Ctx, pszDigestUri, strlen(pszDigestUri));
     121      MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
     122      MD5Update(&Md5Ctx, (const unsigned char *)pszDigestUri, strlen(pszDigestUri));
    123123      if (strcmp(pszQop, "auth-int") == 0) {
    124             MD5Update(&Md5Ctx, ":", 1);
    125             MD5Update(&Md5Ctx, HEntity, HASHHEXLEN);
     124            MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
     125            MD5Update(&Md5Ctx, (const unsigned char *)HEntity, HASHHEXLEN);
    126126      }
    127       MD5Final(HA2, &Md5Ctx);
     127      MD5Final((unsigned char *)HA2, &Md5Ctx);
    128128       CvtHex(HA2, HA2Hex);
    129129       
    130130      // calculate response
    131131      MD5Init(&Md5Ctx);
    132       MD5Update(&Md5Ctx, HA1, HASHHEXLEN);
    133       MD5Update(&Md5Ctx, ":", 1);
    134       MD5Update(&Md5Ctx, pszNonce, strlen(pszNonce));
    135       MD5Update(&Md5Ctx, ":", 1);
     132      MD5Update(&Md5Ctx, (const unsigned char *)HA1, HASHHEXLEN);
     133      MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
     134      MD5Update(&Md5Ctx, (const unsigned char *)pszNonce, strlen(pszNonce));
     135      MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
    136136      if (*pszQop) {
    137           MD5Update(&Md5Ctx, pszNonceCount, strlen(pszNonceCount));
    138           MD5Update(&Md5Ctx, ":", 1);
    139           MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
    140           MD5Update(&Md5Ctx, ":", 1);
    141           MD5Update(&Md5Ctx, pszQop, strlen(pszQop));
    142           MD5Update(&Md5Ctx, ":", 1);
     137          MD5Update(&Md5Ctx, (const unsigned char *)pszNonceCount, strlen(pszNonceCount));
     138          MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
     139          MD5Update(&Md5Ctx, (const unsigned char *)pszCNonce, strlen(pszCNonce));
     140          MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
     141          MD5Update(&Md5Ctx, (const unsigned char *)pszQop, strlen(pszQop));
     142          MD5Update(&Md5Ctx, (const unsigned char *)":", 1);
    143143      }
    144       MD5Update(&Md5Ctx, HA2Hex, HASHHEXLEN);
    145       MD5Final(RespHash, &Md5Ctx);
     144      MD5Update(&Md5Ctx, (const unsigned char *)HA2Hex, HASHHEXLEN);
     145      MD5Final((unsigned char *)RespHash, &Md5Ctx);
    146146      CvtHex(RespHash, Response);
    147147}
  • extensions/app_sip/multimediaauth.c

    r368 r409  
    4141        struct msg *ans, *qry;
    4242        struct avp *avp, *a2, *authdataitem;
    43         struct msg_hdr * header = NULL;
     43        //struct msg_hdr * header = NULL;
    4444        struct avp_hdr * avphdr=NULL, *avpheader=NULL, *avpheader_auth=NULL,*digestheader=NULL;
    4545        union avp_value val;
     
    4848        char * result;
    4949        char password[51];
    50         int idx=0, idx2=0, number_of_auth_items=0,i=0;
     50        int idx=0, number_of_auth_items=0,i=0;
    5151        //Flags and variables for Database
    5252        int sipurinotstored=0, authenticationpending=0, querylen=0, usernamelen=0;
     
    7070
    7171
    72         /* Add the appropriate command code & Auth-Application-Id */
     72        /* Add the appropriate command code & Auth-Application-Id
    7373        {
    7474               
     
    7979               
    8080               
    81                 /* Add the Auth-Application-Id */
     81                // Add the Auth-Application-Id
    8282                {
    8383                        CHECK_FCT( fd_msg_avp_new ( sip_dict.Auth_Application_Id, 0, &avp ) );
     
    8787                        CHECK_FCT( fd_msg_avp_add ( ans, MSG_BRW_LAST_CHILD, avp) );
    8888                }
    89         }
     89        }*/
    9090       
    9191       
     
    125125                        username=malloc(avphdr->avp_value->os.len*2+1);
    126126                        //We purify username not to have forbidden characters
    127                         usernamelen=mysql_real_escape_string(conn, username, avphdr->avp_value->os.data, avphdr->avp_value->os.len);
    128                        
    129                        
    130                         if((strncmp(avpheader->avp_value->os.data,"REGISTER",avpheader->avp_value->os.len)==0))
     127                        usernamelen=mysql_real_escape_string(conn, username, (const char *)avphdr->avp_value->os.data, avphdr->avp_value->os.len);
     128                       
     129                       
     130                        if((strncmp((const char *)avpheader->avp_value->os.data,"REGISTER",avpheader->avp_value->os.len)==0))
    131131                        {
    132132                                not_found=1;
     
    153153                                while ((row = mysql_fetch_row(res)) != NULL)
    154154                                {
    155                                         if(row[0]!="")
     155                                        if(strlen(row[0])>0)
    156156                                        {
    157157                                                strcpy(password,row[0]);
     
    195195                                while ((row = mysql_fetch_row(res)) != NULL)
    196196                                {
    197                                         if(strncmp(avphdr->avp_value->os.data,row[0],avphdr->avp_value->os.len)==0)
     197                                        if(strncmp((const char *)avphdr->avp_value->os.data,row[0],avphdr->avp_value->os.len)==0)
    198198                                        {
    199199                                                not_found=0;
     
    225225                                sipuri=malloc(avphdr->avp_value->os.len*2+1);
    226226                                //We purify SIP-URI not to have forbidden characters
    227                                 sipurilen=mysql_real_escape_string(conn, sipuri, avphdr->avp_value->os.data, avphdr->avp_value->os.len);
     227                                sipurilen=mysql_real_escape_string(conn, sipuri, (const char *)avphdr->avp_value->os.data, avphdr->avp_value->os.len);
    228228                               
    229229                               
     
    245245                                while ((row = mysql_fetch_row(res)) != NULL)
    246246                                {
    247                                         if(strncmp(avphdr->avp_value->os.data,row[0],avphdr->avp_value->os.len)==0)
     247                                        if(strncmp((const char *)avphdr->avp_value->os.data,row[0],avphdr->avp_value->os.len)==0)
    248248                                        {
    249249                                                not_found=0;
     
    361361                                                                {
    362362                                                                        CHECK_FCT( fd_msg_avp_new ( sip_dict.Digest_QOP, 0, &a2 ) );
    363                                                                         val.os.data="auth";
    364                                                                         val.os.len=strlen(val.os.data);
     363                                                                        val.os.data=(unsigned char *)"auth";
     364                                                                        val.os.len=strlen((const char *)val.os.data);
    365365                                                                        CHECK_FCT( fd_msg_avp_setvalue( a2, &val ) );
    366366                                                                        CHECK_FCT( fd_msg_avp_add( sipAuthenticate, MSG_BRW_LAST_CHILD, a2 ) );
     
    387387                                                                        CHECK_FCT( fd_sess_state_store ( ds_sess_hdl, sess, &storednonce )); 
    388388                                                                       
    389                                                                         val.os.data=nonce;
     389                                                                        val.os.data=(unsigned char *)nonce;
    390390                                                                        val.os.len=NONCE_SIZE * 2;
    391391                                                                       
     
    396396                                                                {
    397397                                                                        CHECK_FCT( fd_msg_avp_new ( sip_dict.Digest_Algorithm, 0, &a2 ) );
    398                                                                         val.os.data="MD5";
    399                                                                         val.os.len=strlen(val.os.data);
     398                                                                        val.os.data=(unsigned char *)"MD5";
     399                                                                        val.os.len=strlen((const char *)val.os.data);
    400400                                                                        CHECK_FCT( fd_msg_avp_setvalue( a2, &val ) );
    401401                                                                        CHECK_FCT( fd_msg_avp_add( sipAuthenticate, MSG_BRW_LAST_CHILD, a2 ) );
     
    464464                                                                        //uint8_t bufferresp[DIGEST_LEN];
    465465                                                                        //char response[DIGEST_LEN*2+1];
    466                                                                         int i=0;
     466                                                                       
    467467                                                                       
    468468                                                                        //We extract all the data we need
     
    640640                                                                       
    641641                                                                        DigestCalcHA1(digest_algorithm, digest_username, digest_realm, password, digest_nonce,digest_cnonce, HA1);
    642                                                                        
    643                                                         DigestCalcResponse(HA1, digest_nonce, digest_noncecount, digest_cnonce, digest_qop,digest_method, digest_uri, HA2, response);
     642                                                                DigestCalcResponse(HA1, digest_nonce, digest_noncecount, digest_cnonce, digest_qop,digest_method, digest_uri, HA2, response);
    644643                                                                       
    645644               
     
    677676                                                                                //Digest-HA1 MUST be used instead of Digest-Response-Auth if Digest-Qop is 'auth-int'.
    678677                                                                                CHECK_FCT( fd_msg_avp_new ( sip_dict.Digest_HA1, 0, &a2 ) );
    679                                                                                 val.os.data=HA1;
     678                                                                                val.os.data=(unsigned char *)HA1;
    680679                                                                                val.os.len=HASHHEXLEN+1;
    681680                                                                                CHECK_FCT( fd_msg_avp_setvalue( a2, &val ) );
     
    686685                                                                                //Digest-Response-Auth MUST be used instead of Digest-HA1 if Digest-Qop is 'auth'.
    687686                                                                                CHECK_FCT( fd_msg_avp_new ( sip_dict.Digest_Response_Auth, 0, &a2 ) );
    688                                                                                 val.os.data=responseauth;
     687                                                                                val.os.data=(unsigned char *)responseauth;
    689688                                                                                val.os.len=DIGEST_LEN*2;
    690689                                                                                CHECK_FCT( fd_msg_avp_setvalue( a2, &val ) );
  • extensions/test_sip/test_sip.c

    r392 r409  
    4040
    4141
     42struct disp_hdl * test_sip_MAA_hdl=NULL;
     43struct disp_hdl * test_sip_LIA_hdl=NULL;
     44struct disp_hdl * test_sip_UAA_hdl=NULL;
     45struct disp_hdl * test_sip_SAA_hdl=NULL;
     46struct disp_hdl * test_sip_PPR_hdl=NULL;
     47struct disp_hdl * test_sip_RTR_hdl=NULL;
    4248
     49
     50struct disp_hdl * test_sip_default_hdl=NULL;
     51struct session_handler * ts_sess_hdl;
     52
     53//configuration stucture
     54struct ts_conf * ts_conf=NULL;
     55static struct ts_conf app_sip_conf;
     56
     57//dictionary of SIP
     58struct test_sip_dict sip_dict;
     59
     60int test_sip_default_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act)
     61{
     62        TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act);
     63       
     64        return 0;
     65}
     66
     67username = "awestfahl"
     68password = "test"
     69sip_aor = "sip:awestfahl@tera.ics.keio.ac.jp"
     70
     71#Destination information
     72destination_realm = "freediameter.net"
     73destination_sip = "sip:awestfahl@freediameter.net"
     74
     75void dump_config()
     76{
     77        TRACE_DEBUG(FULL,"***Configuration of TEST Diameter-SIP extension***");
     78        TRACE_DEBUG(FULL,"# username: *%s*",ts_conf->username);
     79        TRACE_DEBUG(FULL,"# password: *%s*",ts_conf->password);
     80        TRACE_DEBUG(FULL,"# sip_aor: *%s*",ts_conf->sip_aor);
     81        TRACE_DEBUG(FULL,"# destination_realm: *%s*",ts_conf->destination_realm);
     82        TRACE_DEBUG(FULL,"# destination_sip: *%s*",ts_conf->destination_sip);
     83        TRACE_DEBUG(FULL,"***End of TEST Diameter-SIP configuration extension***");
     84}
     85
     86static int ts_conf_init(void)
     87{
     88        ts_conf=&test_sip_conf;
     89        //memset(app_sip_conf, 0, sizeof(struct ts_conf));
     90       
     91
     92        return 0;
     93}
     94
     95/* entry point */
     96int as_entry(char * conffile)
     97{
     98        TRACE_ENTRY("%p", conffile);
     99       
     100        struct dict_object * app=NULL;
     101        struct disp_when data;
     102       
     103        /* Initialize configuration */
     104        CHECK_FCT( ts_conf_init() );
     105       
     106       
     107        //We parse the configuration file
     108        if (conffile != NULL) {
     109                CHECK_FCT( ts_conf_handle(conffile) );
     110        }
     111        else
     112        {
     113                TRACE_DEBUG(INFO, "We need a configuration file for Diameter-SIP extension. See doc/ for an example.");
     114        }
     115       
     116        //We can dump the configuration extracted from app_sip.conf
     117        dump_config();
     118       
     119        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Session Initiation Protocol (SIP) Application", &app, ENOENT) );
     120        CHECK_FCT( fd_disp_app_support ( app, NULL, 1, 0 ) );
     121       
     122       
     123       
     124        //We set usefull AVPs
     125        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Session-State", &sip_dict.Auth_Session_State, ENOENT) );
     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        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) );
     128        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authorization", &sip_dict.SIP_Authorization, ENOENT) );
     129        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authenticate", &sip_dict.SIP_Authenticate, ENOENT) );
     130        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Number-Auth-Items", &sip_dict.SIP_Number_Auth_Items, ENOENT) );
     131        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authentication-Scheme", &sip_dict.SIP_Authentication_Scheme, ENOENT) );
     132        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Authentication-Info", &sip_dict.SIP_Authentication_Info, ENOENT) );
     133        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Server-URI", &sip_dict.SIP_Server_URI, ENOENT) );
     134        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-Method", &sip_dict.SIP_Method, ENOENT) );
     135        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "SIP-AOR", &sip_dict.SIP_AOR, ENOENT) );
     136        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Realm", &sip_dict.Digest_Realm, ENOENT) );
     137        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-URI", &sip_dict.Digest_URI, ENOENT) );
     138        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Nonce", &sip_dict.Digest_Nonce, ENOENT) );
     139        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-CNonce", &sip_dict.Digest_CNonce, ENOENT) );
     140        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Method", &sip_dict.Digest_Method, ENOENT) );
     141        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Nonce-Count", &sip_dict.Digest_Nonce_Count, ENOENT) );
     142        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Realm", &sip_dict.Digest_Realm, ENOENT) );
     143        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Response", &sip_dict.Digest_Response, ENOENT) );
     144        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Response-Auth", &sip_dict.Digest_Response_Auth, ENOENT) );
     145        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Username", &sip_dict.Digest_Username, ENOENT) );
     146        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-Algorithm", &sip_dict.Digest_Algorithm, ENOENT) );
     147        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-QoP", &sip_dict.Digest_QOP, ENOENT) );
     148        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "User-Name", &sip_dict.User_Name, ENOENT) );
     149       
     150        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Digest-HA1", &sip_dict.Digest_HA1, ENOENT) );
     151       
     152       
     153        //Register Application
     154        memset(&data, 0, sizeof(data));
     155        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Session Initiation Protocol (SIP) Application", &data.app, ENOENT) );
     156       
     157       
     158        //**Command Codes
     159        //MAR
     160        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Multimedia-Auth-Request", &data.command, ENOENT) );
     161        CHECK_FCT( fd_disp_register( test_sip_MAR_cb, DISP_HOW_CC, &data, &test_sip_MAR_hdl ) );
     162        //RTR
     163        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Registration-Termination-Request", &data.command, ENOENT) );
     164        CHECK_FCT( fd_disp_register( test_sip_RTR_cb, DISP_HOW_CC, &data, &test_sip_RTA_hdl ) );
     165       
     166       
     167        //Callback for unexpected messages
     168        CHECK_FCT( fd_disp_register( test_sip_default_cb, DISP_HOW_APPID, &data, &test_sip_default_hdl ) );
     169       
     170       
     171        //We start database connection
     172        if(start_mysql_connection())
     173                return 1;
     174       
     175        CHECK_FCT(fd_sess_handler_create(&ds_sess_hdl, free));
     176       
     177        return 0;
     178}
     179
     180//Cleanup callback
     181void fd_ext_fini(void)
     182{
     183       
     184        if (test_sip_MAR_cb) {
     185                (void) fd_disp_unregister(&test_sip_MAR_hdl);
     186                CHECK_FCT_DO( fd_sess_handler_destroy(&ds_sess_hdl),return);
     187        }
     188       
     189        //We close database connection
     190        close_mysql_connection();
     191       
     192
     193       
     194        TRACE_ENTRY();
     195        return ;
     196}
     197
     198EXTENSION_ENTRY("test_sip", ts_entry);
     199
  • extensions/test_sip/test_sip.h

    r392 r409  
    3838/* The module configuration */
    3939struct test_sip_conf {
    40         int             mode;           /* default MODE_DSSERVER | MODE_SL */
    41         enum {ASMYSQL} datasource;
    42         char * mysql_login;
    43         char * mysql_password;
    44         char * mysql_database;
    45         char * mysql_server;
    46         uint16_t  mysql_port;
    47        
     40        char * destination_sip;
     41        char * destination_realm;
     42        char * username;
     43        char * password;
     44        char * sip_aor;
    4845};
    4946extern struct test_sip_conf * test_sip_conf;
    5047
    5148
     49//Storage for some usefull AVPs
     50struct sip_dict{
     51        struct dict_object * Auth_Session_State;
     52        struct dict_object * Auth_Application_Id;
     53        struct dict_object * User_Name;
     54        struct dict_object * SIP_Auth_Data_Item;
     55        struct dict_object * SIP_Authorization;
     56        struct dict_object * SIP_Authenticate;
     57        struct dict_object * SIP_Number_Auth_Items;     
     58        struct dict_object * SIP_Authentication_Scheme;
     59        struct dict_object * SIP_Authentication_Info;   
     60        struct dict_object * SIP_Server_URI;
     61        struct dict_object * SIP_Method;
     62        struct dict_object * SIP_AOR;
     63        struct dict_object * Digest_URI;               
     64        struct dict_object * Digest_Nonce;
     65        struct dict_object * Digest_Nonce_Count;
     66        struct dict_object * Digest_CNonce;             
     67        struct dict_object * Digest_Realm;             
     68        struct dict_object * Digest_Response;   
     69        struct dict_object * Digest_Response_Auth;     
     70        struct dict_object * Digest_Username;   
     71        struct dict_object * Digest_Method;
     72        struct dict_object * Digest_QOP;       
     73        struct dict_object * Digest_Algorithm;
     74        struct dict_object * Digest_HA1;
     75};
     76
     77extern  struct sip_dict  sip_dict;
    5278
    5379
    5480
    5581
     82int test_sip_default_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act);
     83int test_sip_MAA_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act);
     84int test_sip_RTR_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act);
    5685
    5786
    58 
    59 
    60 
    61 
    62 
Note: See TracChangeset for help on using the changeset viewer.