Navigation


Changeset 706:4ffbc9f1e922 in freeDiameter for libfdcore/messages.c


Ignore:
Timestamp:
Feb 9, 2011, 3:26:58 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Large UNTESTED commit with the following changes:

  • Improved DiameterIdentity? handling (esp. interationalization issues), and improve efficiency of some string operations in peers, sessions, and dictionary modules (closes #7)
  • Cleanup in the session module to free only unreferenced sessions (#16)
  • Removed fd_cpu_flush_cache(), replaced by more robust alternatives.
  • Improved peer state machine algorithm to counter SCTP multistream race condition.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/messages.c

    r688 r706  
    3636#include "fdcore-internal.h"
    3737
     38static struct dict_object * dict_avp_SI  = NULL; /* Session-Id */
    3839static struct dict_object * dict_avp_OH  = NULL; /* Origin-Host */
    3940static struct dict_object * dict_avp_OR  = NULL; /* Origin-Realm */
     
    5455       
    5556        /* Initialize the dictionary objects that we may use frequently */
     57        CHECK_FCT(  fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Id",         &dict_avp_SI , ENOENT)  );
    5658        CHECK_FCT(  fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Origin-Host",        &dict_avp_OH  , ENOENT)  );
    5759        CHECK_FCT(  fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Origin-Realm",       &dict_avp_OR  , ENOENT)  );
     
    8991        /* Set its value */
    9092        memset(&val, 0, sizeof(val));
    91         val.os.data = (unsigned char *)fd_g_config->cnf_diamid;
     93        val.os.data = (os0_t)fd_g_config->cnf_diamid;
    9294        val.os.len  = fd_g_config->cnf_diamid_len;
    9395        CHECK_FCT( fd_msg_avp_setvalue( avp_OH, &val ) );
     
    102104        /* Set its value */
    103105        memset(&val, 0, sizeof(val));
    104         val.os.data = (unsigned char *)fd_g_config->cnf_diamrlm;
     106        val.os.data = (os0_t)fd_g_config->cnf_diamrlm;
    105107        val.os.len  = fd_g_config->cnf_diamrlm_len;
    106108        CHECK_FCT( fd_msg_avp_setvalue( avp_OR, &val ) );
     
    124126        return 0;
    125127}
     128
     129/* Create a new Session-Id and add at the beginning of the message. */
     130int fd_msg_new_session( struct msg * msg, os0_t opt, size_t optlen )
     131{
     132        union avp_value val;
     133        struct avp * avp  = NULL;
     134        struct session * sess = NULL;
     135        os0_t sid;
     136        size_t sidlen;
     137       
     138        TRACE_ENTRY("%p %p %zd", msg, opt, optlen);
     139        CHECK_PARAMS(  msg  );
     140       
     141        /* Check there is not already a session in the message */
     142        CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, msg, &sess, NULL) );
     143        CHECK_PARAMS( sess == NULL );
     144       
     145        /* Ok, now create the session */
     146        CHECK_FCT( fd_sess_new ( &sess, fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len, opt, optlen ) );
     147        CHECK_FCT( fd_sess_getsid( sess, &sid, &sidlen) );
     148       
     149        /* Create an AVP to hold it */
     150        CHECK_FCT( fd_msg_avp_new( dict_avp_SI, 0, &avp ) );
     151       
     152        /* Set its value */
     153        memset(&val, 0, sizeof(val));
     154        val.os.data = sid;
     155        val.os.len  = sidlen;
     156        CHECK_FCT( fd_msg_avp_setvalue( avp, &val ) );
     157       
     158        /* Add it to the message */
     159        CHECK_FCT( fd_msg_avp_add( msg, MSG_BRW_FIRST_CHILD, avp ) );
     160       
     161        /* Done! */
     162        return 0;
     163}
     164
    126165
    127166/* Add Result-Code and eventually Failed-AVP, Error-Message and Error-Reporting-Host AVPs */
     
    147186                memset(&req, 0, sizeof(struct dict_enumval_request));
    148187               
    149                 /* First, get the enumerated type of the Result-Code AVP */
     188                /* First, get the enumerated type of the Result-Code AVP (this is fast, no need to cache the object) */
    150189                CHECK_FCT(  fd_dict_search( fd_g_config->cnf_dict, DICT_TYPE, TYPE_OF_AVP, dict_avp_RC, &(req.type_obj), ENOENT  )  );
    151190               
     
    184223                /* Set its value */
    185224                memset(&val, 0, sizeof(val));
    186                 val.os.data = (unsigned char *)fd_g_config->cnf_diamid;
     225                val.os.data = (uint8_t *)fd_g_config->cnf_diamid;
    187226                val.os.len  = fd_g_config->cnf_diamid_len;
    188227                CHECK_FCT( fd_msg_avp_setvalue( avp_ERH, &val ) );
     
    246285               
    247286                if (errormsg) {
    248                         val.os.data = (unsigned char *)errormsg;
     287                        val.os.data = (uint8_t *)errormsg;
    249288                        val.os.len  = strlen(errormsg);
    250289                } else {
    251                         val.os.data = (unsigned char *)rescode;
     290                        val.os.data = (uint8_t *)rescode;
    252291                        val.os.len  = strlen(rescode);
    253292                }
     
    311350        if      ((ret != EBADMSG)       /* Parsing grouped AVP failed / Conflicting rule found */
    312351                && (ret != ENOTSUP))    /* Command is not supported / Mandatory AVP is not supported */
    313                 return ret;
     352                return ret; /* 0 or another error */
    314353       
    315354        TRACE_DEBUG(INFO, "A message does not comply to the dictionary and/or rules (%s)", pei.pei_errcode);
Note: See TracChangeset for help on using the changeset viewer.