1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/*:*
*: File: ./src/chat/sman.cpp
*:
*: yChat; Homepage: www.yChat.org; Version 0.7.9.5-RELEASE
*:
*: Copyright (C) 2003 Paul C. Buetow, Volker Richter
*: Copyright (C) 2004 Paul C. Buetow
*: Copyright (C) 2005 EXA Digital Solutions GbR
*:
*: This program is free software; you can redistribute it and/or
*: modify it under the terms of the GNU General Public License
*: as published by the Free Software Foundation; either version 2
*: of the License, or (at your option) any later version.
*:
*: This program is distributed in the hope that it will be useful,
*: but WITHOUT ANY WARRANTY; without even the implied warranty of
*: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*: GNU General Public License for more details.
*:
*: You should have received a copy of the GNU General Public License
*: along with this program; if not, write to the Free Software
*: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*:*/
#ifndef SMAN_CPP
#define SMAN_CPP
#include "sman.h"
#include "../tool/tool.h"
#include "../maps/mtools.h"
#include "../contrib/crypt/md5.h"
sman::sman()
{
i_session_count = 0;
pthread_mutex_init( &mut_i_session_count, NULL );
}
sman::~sman()
{
// Delete each session object of the shashmap!
shashmap<sess*>::run_func( mtools<sess*>::delete_obj );
pthread_mutex_destroy( &mut_i_session_count );
}
string sman::generate_id( int i_len )
{
string s_valid = wrap::CONF->get_elem("chat.session.validchars");
string s_ret = "";
srand(time(0)+tool::string2int(wrap::CONF->get_elem("chat.session.kloakkey")));
int i_char;
for (int i = 0; i < i_len; i++)
{
i_char = rand() % s_valid.length();
s_ret += s_valid[i_char];
}
if ( wrap::CONF->get_elem("chat.session.md5hash") == "true" )
{
string s_salt = wrap::CONF->get_elem("chat.session.md5salt");
string s_hash(md5::MD5Crypt(s_ret.c_str(), s_salt.c_str()));
s_ret.append(s_hash.substr(s_ret.find(s_salt) + s_salt.length() + 3));
}
// Prove, if the TempID already exists
sess* p_sess = get_elem(s_ret);
if (p_sess)
{
wrap::system_message(SESSEXI);
return generate_id(i_len);
}
return s_ret;
}
sess *sman::create_session( )
{
string s_tmpid = generate_id( tool::string2int( wrap::CONF->get_elem( "chat.session.length" ) ) );
sess* p_sess = new sess( s_tmpid );
pthread_mutex_lock( &mut_i_session_count );
i_session_count++;
#ifdef NCURSES
print_sessions();
#endif
pthread_mutex_unlock( &mut_i_session_count );
//????
add_elem( p_sess, s_tmpid );
return p_sess;
}
sess *sman::get_session( string s_id )
{
return get_elem( s_id );
}
void
sman::destroy_session( string s_id )
{
pthread_mutex_lock( &mut_i_session_count );
i_session_count--;
#ifdef NCURSES
print_sessions();
#endif
pthread_mutex_unlock( &mut_i_session_count );
sess* p_sess = get_elem( s_id );
del_elem( s_id );
delete p_sess;
}
#ifdef NCURSES
void sman::print_sessions()
{
if ( wrap::NCUR->is_ready() )
{
mvprintw( NCUR_SESSION_X,NCUR_SESSION_Y, "Sessions: %d ", i_session_count);
refresh();
}
}
#ifdef NCURSES
void sman::print_init_ncurses()
{
pthread_mutex_lock( &mut_i_session_count );
print_sessions();
pthread_mutex_unlock( &mut_i_session_count );
}
#endif
int
sman::get_session_count()
{
int i_ret;
pthread_mutex_lock( &mut_i_session_count );
i_ret = i_session_count;
pthread_mutex_unlock( &mut_i_session_count );
return i_ret;
}
#endif
#endif
|