|
|
@ -23,37 +23,76 @@ |
|
|
#define _GNU_SOURCE |
|
|
#define _GNU_SOURCE |
|
|
|
|
|
|
|
|
#include <sys/types.h> |
|
|
#include <sys/types.h> |
|
|
|
|
|
#include <stdint.h> |
|
|
|
|
|
|
|
|
|
|
|
#include <inttypes.h> |
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
|
#include "trdata.h" |
|
|
#include "trdata.h" |
|
|
|
|
|
|
|
|
#include "session.h" |
|
|
#include "session.h" |
|
|
#include "application/application.h" |
|
|
#include "application/application.h" |
|
|
|
|
|
|
|
|
|
|
|
static |
|
|
|
|
|
inline |
|
|
|
|
|
int |
|
|
|
|
|
sessionIpIndexComp(const void * a, const void * b) |
|
|
|
|
|
{ |
|
|
|
|
|
Session sess_a = (Session)a; |
|
|
|
|
|
uint32_t ip = *(uint32_t *)b; |
|
|
|
|
|
|
|
|
|
|
|
if (sess_a->ip < ip) { |
|
|
|
|
|
return -1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (sess_a->ip > ip) { |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Session |
|
|
Session |
|
|
applicationSessionGet(Application this, const char * sid) |
|
|
|
|
|
|
|
|
applicationSessionGet(Application this, const char * sid, uint32_t ip) |
|
|
{ |
|
|
{ |
|
|
Session sess = NULL; |
|
|
Session sess = NULL; |
|
|
int index; |
|
|
int index; |
|
|
|
|
|
|
|
|
if (NULL != sid) { |
|
|
|
|
|
/** |
|
|
|
|
|
* now get the session if not expired |
|
|
|
|
|
*/ |
|
|
|
|
|
for (index=0; index<SESSION_LIVETIME; index++) { |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* now get the session if not expired |
|
|
|
|
|
*/ |
|
|
|
|
|
for (index=0; index<SESSION_LIVETIME; index++) { |
|
|
|
|
|
if (NULL != sid) { |
|
|
sess = (Session)TR_hashDelete( |
|
|
sess = (Session)TR_hashDelete( |
|
|
(this->active_sessions)[index], sid, 36); |
|
|
|
|
|
if (NULL != sess) { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
(this->active_sessions)[index].sessions, sid, 36); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* update livetime of session if found |
|
|
|
|
|
*/ |
|
|
|
|
|
if (NULL != sess) { |
|
|
if (NULL != sess) { |
|
|
|
|
|
/** |
|
|
|
|
|
* update livetime of session if found |
|
|
|
|
|
*/ |
|
|
sess->livetime = this->session_time_ofs + SESSION_LIVETIME; |
|
|
sess->livetime = this->session_time_ofs + SESSION_LIVETIME; |
|
|
TR_hashAdd((this->active_sessions)[0], sess); |
|
|
|
|
|
|
|
|
sess = (Session)TR_treeDelete( |
|
|
|
|
|
&((this->active_sessions)[index].ip_index), |
|
|
|
|
|
&ip, sessionIpIndexComp); |
|
|
|
|
|
TR_hashAdd((this->active_sessions)[0].sessions, sess); |
|
|
|
|
|
TR_treeInsert( |
|
|
|
|
|
&((this->active_sessions)[0].ip_index), |
|
|
|
|
|
sess, |
|
|
|
|
|
sessionIpIndexComp); |
|
|
|
|
|
break; |
|
|
|
|
|
} else { |
|
|
|
|
|
sess = (Session)TR_treeDelete( |
|
|
|
|
|
&((this->active_sessions)[index].ip_index), |
|
|
|
|
|
&ip, sessionIpIndexComp); |
|
|
|
|
|
if (NULL != sess) { |
|
|
|
|
|
// we have a previous session from this ip, remove it. |
|
|
|
|
|
TR_hashDelete( |
|
|
|
|
|
(this->active_sessions)[index].sessions, |
|
|
|
|
|
sess->id, 36); |
|
|
|
|
|
TR_delete(sess); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|