38 throw MCS_ERROR(MSG_DIRECTORY_NOT_FOUND, s.csz);
46 appvers = cnf->sval(
"MCS_Generic",
"APPVERS" ,
"0.0" );
47 path = cnf->sval(
"MCS_Generic",
"PATH" ,
Pwd() );
50 interface = cnf->sval("MCS_Generic", "INTERFACE" , "lo0" );
52 interface = cnf->sval("MCS_Generic", "INTERFACE" , "lo" );
58 db_user = cnf->sval(
"MCS_Generic",
"DB_USER" ,
"" );
59 db_pass = cnf->sval(
"MCS_Generic",
"DB_PASS" ,
"" );
60 db_name = cnf->sval(
"MCS_Generic",
"DB_NAME" ,
"" );
61 cl_local_kills_mcs = cnf->ival(
"MCS_Generic",
"local_kills_mcs", 0 );
62 cl_have_db = cnf->ival(
"MCS_Generic",
"have_db" , 0 );
63 cl_custom_auth = cnf->ival(
"MCS_Generic",
"custom_auth" , 0 );
64 cl_logfile = cnf->ival(
"MCS_Generic",
"logfile" , 0 );
65 cl_work = cnf->ival(
"MCS_Generic",
"work" , 1 );
66 cl_work_cid = cnf->ival(
"MCS_Generic",
"work_cid" , 0 );
67 cl_logstdout = cnf->ival(
"MCS_Generic",
"logstdout" , 1 );
68 cl_createlocal = cnf->ival(
"MCS_Generic",
"createlocal" , 1 );
69 cl_restartlocal = cnf->ival(
"MCS_Generic",
"restartlocal" , 0 );
70 cl_clean_logout = cnf->ival(
"MCS_Generic",
"clean_logout" , 0 );
71 cl_read_grants = cnf->ival(
"MCS_Generic",
"read_grants" , 0 );
72 cl_autoexec = cnf->ival(
"MCS_Generic",
"autoexec" , 0 );
73 cl_use_ssl = cnf->ival(
"MCS_Generic",
"use_ssl" , 0 );
77 appvers = cnf->sval(appname ,
"APPVERS" , appvers );
78 path = cnf->sval(appname ,
"PATH" , path );
79 interface = cnf->sval(appname , "INTERFACE" , interface );
80 port = cnf->ival(appname ,
"PORT" , port );
81 timeout = cnf->ival(appname ,
"TIMEOUT" , (
int) timeout );
82 max_users = cnf->ival(appname ,
"MAX_USERS" , max_users );
83 db_user = cnf->sval(appname ,
"DB_USER" , db_user );
84 db_pass = cnf->sval(appname ,
"DB_PASS" , db_pass );
85 db_name = cnf->sval(appname ,
"DB_NAME" , db_name );
86 cl_local_kills_mcs = cnf->ival(appname ,
"local_kills_mcs", cl_local_kills_mcs);
87 cl_have_db = cnf->ival(appname ,
"have_db" , cl_have_db );
88 cl_custom_auth = cnf->ival(appname ,
"custom_auth" , cl_custom_auth );
89 cl_logfile = cnf->ival(appname ,
"logfile" , cl_logfile );
90 cl_work = cnf->ival(appname ,
"work" , cl_work );
91 cl_work_cid = cnf->ival(appname ,
"work_cid" , cl_work_cid );
92 cl_logstdout = cnf->ival(appname ,
"logstdout" , cl_logstdout );
93 cl_createlocal = cnf->ival(appname ,
"createlocal" , cl_createlocal );
94 cl_restartlocal = cnf->ival(appname ,
"restartlocal" , cl_restartlocal );
95 cl_clean_logout = cnf->ival(appname ,
"clean_logout" , cl_clean_logout );
96 cl_read_grants = cnf->ival(appname ,
"read_grants" , cl_read_grants );
97 cl_autoexec = cnf->ival(appname ,
"autoexec" , cl_autoexec );
98 cl_use_ssl = cnf->ival(appname ,
"use_ssl" , cl_use_ssl );
99 cl_chunksize = cnf->ival(appname ,
"chunksize" , cl_chunksize );
106 cnf =
new Conf(inipath);
108 cnf->
setval(appname,
"APPVERS" , appvers );
109 cnf->
setval(appname,
"PATH" , path );
110 cnf->
setval(appname,
"INTERFACE" , interface );
111 cnf->
setval(appname,
"PORT" , port );
112 cnf->
setval(appname,
"TIMEOUT" , (
int) timeout );
113 cnf->
setval(appname,
"MAX_USERS" , max_users );
114 cnf->
setval(appname,
"DB_USER" , db_user );
115 cnf->
setval(appname,
"DB_PASS" , db_pass );
116 cnf->
setval(appname,
"DB_NAME" , db_name );
117 cnf->
setval(appname,
"local_kills_mcs", cl_local_kills_mcs);
118 cnf->
setval(appname,
"have_db" , cl_have_db );
119 cnf->
setval(appname,
"custom_auth" , cl_custom_auth );
120 cnf->
setval(appname,
"logfile" , cl_logfile );
121 cnf->
setval(appname,
"work" , cl_work );
122 cnf->
setval(appname,
"work_cid" , cl_work_cid );
123 cnf->
setval(appname,
"logstdout" , cl_logstdout );
124 cnf->
setval(appname,
"createlocal" , cl_createlocal );
125 cnf->
setval(appname,
"restartlocal" , cl_restartlocal );
126 cnf->
setval(appname,
"clean_logout" , cl_clean_logout );
127 cnf->
setval(appname,
"read_grants" , cl_read_grants );
128 cnf->
setval(appname,
"autoexec" , cl_autoexec );
129 cnf->
setval(appname,
"use_ssl" , cl_use_ssl );
130 cnf->
setval(appname,
"chunksize" , cl_chunksize );
153 localhost=
"localhost";
154 if ((p=getenv(
"HOSTNAME")))
157 this->inipath = inipath;
158 cnf =
new Conf(inipath);
168 const char *format=
"%Y%m%d%H%M%S";
169 const int lenfmt=strlen(format)+3;
170 time_t tp=time(NULL);
171 strftime(ts, lenfmt, format, localtime(&tp));
174 s+=string(
"/mcs-") + appname + string(
"-");
178 flog=
new ofstream(s.csz, ios::app);
179 if (!(flog->is_open()))
180 throw MCS_ERROR(MSG_CANT_OPEN_FILE, s.csz);
183 #ifdef HAVE_OPENSSL_SSL_H 187 sslcert = path +
"/" + string(MCS_SSLCERT);
188 sslpriv = path +
"/" + string(MCS_SSLPRIV);
192 throw MCS_ERROR(MSG_ERROR,
"Can't found certificate and private key files, run \"mcscreatekey\"");
194 #endif //HAVE_OPENSSL_SSL_H #define MCS_DEFAULT_PORT
Default port on which the server is listening.
#define MCS_DEFAULT_MAX_USERS
Default max number of clients connected.
bool File_Dir_Exist(string fn, unsigned int &size)
Check if a file or directory exists.
string Pwd()
Return the current working dir.
void save(string filename="")
Save all the values in a configuration file.
#define MCS_DEFAULTCHUNKSIZE
File chunk size.
#define MCS_ERROR(A, rest...)
Facility to easily pass all necessary parameter to an Event constructor.
void setval(string section, string key, string val, string comment="")
Set a new value for the specified section/key pair.
Read and write configuration files.
string remTrailing(string &s, const char *p)
Remove any trailing character "p".
Env(string app="mcs", string inipath="mcs.conf")
Env constructor.
Main include file for all MCS based applications.
void LoadConf()
Load configuration entries.
void chkTree()
Check the entire MCS tree.
bool mkDir(string path, mode_t perm=0, enum ThrowExceptions throwexc=THROW)
Create a directory.
#define MCS_DEFAULT_CLIENT_TIMEOUT
Default client connection timeout, in milliseconds: 10 minutes.
void DumpConf()
Dump environment to configuration file.
Namespace for MCS library.