Session* SessionMgr::CreateSession( SOCKET sock, const std::string& ip, int port ) { //add this session int sessionID = GenerateSessionID(); if( 0 == sessionID ) { LOG_ERROR( logger, __FUNCTION__ << " failed to generate session id!" ); return NULL; } Session* pSession = s_SessionPool.AllocateSession( sessionID, sock, ip, port ); if( NULL == pSession ) { LOG_ERROR( logger, __FUNCTION__ << " failed to allocate session from pool!" ); return NULL; } if( !InsertSession( pSession ) ) { LOG_ERROR( logger, __FUNCTION__ << " failed to insert session into SessionMgr!" ); return NULL; } return pSession; }
wcsession *CreateSession(int Lockable, int Static, wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t *ListMutex) { wcsession *TheSession; TheSession = (wcsession *) malloc(sizeof(wcsession)); memset(TheSession, 0, sizeof(wcsession)); TheSession->Hdr = Hdr; TheSession->serv_sock = (-1); TheSession->lastreq = time(NULL);; pthread_setspecific(MyConKey, (void *)TheSession); /* If we're recreating a session that expired, it's best to give it the same * session number that it had before. The client browser ought to pick up * the new session number and start using it, but in some rare situations it * doesn't, and that's a Bad Thing because it causes lots of spurious sessions * to get created. */ if (Hdr->HR.desired_session == 0) { TheSession->wc_session = GenerateSessionID(); syslog(LOG_DEBUG, "Created new session %d", TheSession->wc_session); } else { TheSession->wc_session = Hdr->HR.desired_session; syslog(LOG_DEBUG, "Re-created session %d", TheSession->wc_session); } Hdr->HR.Static = Static; session_new_modules(TheSession); if (Lockable) { pthread_mutex_init(&TheSession->SessionMutex, NULL); if (ListMutex != NULL) CtdlLogResult(pthread_mutex_lock(ListMutex)); if (wclist != NULL) { TheSession->nonce = rand(); TheSession->next = *wclist; *wclist = TheSession; } if (ListMutex != NULL) CtdlLogResult(pthread_mutex_unlock(ListMutex)); } return TheSession; }
LiveTrack24::SessionID LiveTrack24::GenerateSessionID(UserID user_id) { return GenerateSessionID() | (user_id & 0x00ffffff); }