session.c File Reference


Detailed Description

CDiameterPeer Session Handling.

Author:
Dragos Vingarzan vingarzan -at- fokus dot fraunhofer dot de

Definition in file session.c.

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include "session.h"
#include "diameter.h"
#include "config.h"

Go to the source code of this file.

Functions

int session_init ()
 Initializes the session related structures.
int session_destroy ()
 Destroys the session related structures.
static int generate_sessionID (str *sID, unsigned int end_pad_len)
AAASessionId AAACreateSession ()
 Creates a AAASessionId.
int AAADropSession (AAASessionId *s)
 Deallocates the memory taken by a AAASessionId.

Variables

dp_configconfig
 Configuration for this diameter peer.
gen_lock_t * session_lock
 lock for session operation
unsigned int * session_id1
 first part of the session id
unsigned int * session_id2
 second part of the session id


Function Documentation

int session_init (  ) 

Initializes the session related structures.

Definition at line 72 of file session.c.

References LOG_NO_MEM, session_id1, session_id2, and session_lock.

Referenced by diameter_peer_init().

00073 {
00074     session_lock = lock_alloc();
00075     if (!session_lock){
00076         LOG_NO_MEM("lock",sizeof(gen_lock_t));
00077         goto error;
00078     }
00079     session_lock = lock_init(session_lock);
00080     session_id1 = shm_malloc(sizeof(unsigned int));
00081     if (!session_id1){
00082         LOG_NO_MEM("shm",sizeof(unsigned int));
00083         goto error;
00084     }
00085     session_id2 = shm_malloc(sizeof(unsigned int));
00086     if (!session_id2){
00087         LOG_NO_MEM("shm",sizeof(unsigned int));
00088         goto error;
00089     }
00090     srand((unsigned int)time(0));   
00091     *session_id1 = rand();
00092     *session_id1 <<= 16;
00093     *session_id1 += time(0)&0xFFFF;
00094     *session_id2 = 0;
00095     return 1;
00096 error:
00097     return 0;
00098 }

int session_destroy (  ) 

Destroys the session related structures.

Definition at line 103 of file session.c.

References session_id1, session_id2, and session_lock.

Referenced by diameter_peer_destroy().

00104 {
00105     lock_get(session_lock);
00106     lock_destroy(session_lock);
00107     lock_dealloc((void*)session_lock);  
00108     shm_free(session_id1);
00109     shm_free(session_id2);
00110     return 1;
00111 }

static int generate_sessionID ( str *  sID,
unsigned int  end_pad_len 
) [static]

Definition at line 119 of file session.c.

References config, dp_config::identity, session_id1, session_id2, and session_lock.

Referenced by AAACreateSession().

00120 {
00121     unsigned int s2;
00122 
00123     /* some checks */
00124     if (!sID)
00125         goto error;
00126 
00127     /* compute id's len */
00128     sID->len = config->identity.len +
00129         1/*;*/ + 10/*high 32 bits*/ +
00130         1/*;*/ + 10/*low 32 bits*/ +
00131 //      1/*;*/ + 8/*optional value*/ +
00132         1 /* terminating \0 */ +
00133         end_pad_len;
00134 
00135     /* get some memory for it */
00136     sID->s = (char*)shm_malloc( sID->len );
00137     if (sID->s==0) {
00138         LOG(L_ERR,"ERROR:generate_sessionID: no more free memory!\n");
00139         goto error;
00140     }
00141 
00142     lock_get(session_lock);
00143     s2 = *session_id2 +1;
00144     *session_id2 = s2;
00145     lock_release(session_lock);
00146     
00147     /* build the sessionID */
00148     sprintf(sID->s,"%.*s;%u;%u",config->identity.len,config->identity.s,*session_id1,s2);
00149     sID->len = strlen(sID->s);
00150     return 1;
00151 error:
00152     return -1;
00153 }

AAASessionId AAACreateSession (  ) 

Creates a AAASessionId.

Returns:
the new AAASessionId or an empty string on failure

Definition at line 166 of file session.c.

References generate_sessionID().

Referenced by load_cdp().

00167 {
00168     AAASessionId sID={0,0};
00169     
00170     /* generates a new session-ID - the extra pad is used to append to 
00171      * session-ID the hash-code and label of the session ".XXXXXXXX.XXXXXXXX"*/
00172     if (generate_sessionID( &(sID), 0 )!=1)
00173         goto error;
00174 
00175     return sID;
00176 error:
00177     LOG(L_ERR,"ERROR:AAACreateSession(): Error on new session generation\n");
00178     return sID;
00179 }

int AAADropSession ( AAASessionId s  ) 

Deallocates the memory taken by a AAASessionId.

Parameters:
s - the AAASessionId to be deallocated

Definition at line 185 of file session.c.

References AAA_ERR_SUCCESS.

Referenced by load_cdp().

00186 {
00187     if (s->s) shm_free(s->s);
00188     s->s =0;
00189     s->len=0;
00190     return AAA_ERR_SUCCESS;
00191 }


Variable Documentation

dp_config* config

Configuration for this diameter peer.

Definition at line 76 of file diameter_peer.c.

gen_lock_t* session_lock

lock for session operation

Definition at line 65 of file session.c.

Referenced by generate_sessionID(), session_destroy(), and session_init().

unsigned int* session_id1

first part of the session id

Definition at line 66 of file session.c.

Referenced by generate_sessionID(), session_destroy(), and session_init().

unsigned int* session_id2

second part of the session id

Definition at line 67 of file session.c.

Referenced by generate_sessionID(), session_destroy(), and session_init().


Generated on Thu Oct 23 04:14:40 2008 for Open IMS Core CSCFs by  doxygen 1.5.2