36 const char *format=
"%Y%m%d %H%M%S ";
37 const int lenfmt=strlen(format)+3;
39 p+=strftime(p, lenfmt, format, localtime(&tp));
40 p+=sprintf(p,
"%s ", tID);
57 str +=
" " + e.
where() +
"]";
60 if (env->cl_logstdout) cout << str << endl;
61 if (env->cl_logfile)
if (env->flog) (*(env->flog)) << str << endl;
64 (e.
code() != MSG_THREAD_CREATE) &&
65 (e.
code() != MSG_THREAD_DESTROY) &&
77 sprintf(
tID,
"%03d", ID);
83 sprintf(
tID,
"%3s", ltID);
105 #define FT_TEMPL_BATCH "#BATCH" 106 #define FT_TEMPL_SQL "#SQL" 107 #define FT_TEMPL_SCRIPT "#SCRIPT" 108 #define FT_TEMPL_BIN "\177ELF" 119 if (!(fin.is_open()))
120 throw MCS_ERROR(MSG_CANT_OPEN_FILE, fn.csz);
126 else if (! memcmp(buffer, FT_TEMPL_BATCH, strlen(FT_TEMPL_BATCH)))
128 else if (! memcmp(buffer, FT_TEMPL_SQL, strlen(FT_TEMPL_SQL)))
130 else if (! memcmp(buffer, FT_TEMPL_SCRIPT, strlen(FT_TEMPL_SCRIPT)))
132 else if (! memcmp(buffer, FT_TEMPL_BIN, strlen(FT_TEMPL_BIN)))
148 throw MCS_ERROR(MSG_UNKNOWN_FILE_TYPE, fn.csz);
151 throw MCS_WARN(MSG_EXT_NOT_AVAILABLE, s.c_str());
160 string wpath,
string thrID,
161 string user,
string pass,
string dbname,
162 string fout,
string ferr)
168 static string bl =
" ";
170 tmp = fn + bl + pars;
172 if (strchr(tmp.c_str(),
'>'))
173 throw MCS_WARN(MSG_CHARACTER_NOT_ALLOWED,
">");
175 if (strchr(tmp.c_str(),
'<'))
176 throw MCS_WARN(MSG_CHARACTER_NOT_ALLOWED,
"<");
178 if (strchr(tmp.c_str(),
'|'))
179 throw MCS_WARN(MSG_CHARACTER_NOT_ALLOWED,
"|");
184 throw MCS_ERROR(MSG_CANT_EXECUTE_FILE, fn);
187 tmp = BINDIR + string(
"/mcsexec ");
189 tmp += user + bl + pass + bl + dbname + bl;
195 tmp += fn + bl + pars;
196 tmp +=
" > " + fout ;
197 tmp +=
" 2> " + ferr;
204 throw MCS_ERROR( MSG_EXT_BIN_UNEXPECTED );
#define MCS_FT_SQL
Return value for BaseThread.fileType(), SQL file.
RetValue Log(Event e)
Logging facility.
string sval(string section, string key)
Search for the specified section/key value and return it as a string.
#define MCS_COMMBUFSIZE
Max length of a message being sent between client and server.
char tID[4]
Thread identifier stored as a null terminated string.
The server side client thread.
string where()
Returns the place where the error occurred formatted as FILE:LINE (CODE).
Hold informations about an event.
static Env * env
Pointer to the actual Env object, this can be seen in all threaded object.
int chkExt(string &s)
Check if an external program or script is registered in the configuration file.
Thread * parent()
Returns the address of the parent.
#define MCS_ERROR(A, rest...)
Facility to easily pass all necessary parameter to an Event constructor.
static int fileType(string fn)
Determine the file type of an external program or script.
string msg()
Returns the message.
#define MCS_FT_BATCH
Return value for BaseThread.fileType(), batch file.
string appname
Application name.
RetValue
Return value for MCS routines.
RetValue type()
Return the event type.
#define MCS_FT_SCRIPT
Return value for BaseThread.fileType(), script file.
BaseThread(const BaseThread &)
Declared to avoid using of default copy constructor.
Main include file for all MCS based applications.
#define MCS_WARN(A, rest...)
Facility to easily pass all necessary parameter to an Event constructor.
int code()
Returns the event code.
#define MCS_FT_UNKNOWN
Return value for BaseThread.fileType(), unknown type.
#define MCS_FT_BIN
Return value for BaseThread.fileType(), binary file.
Hold all environment variables.
static int spawn(string fn, string pars, string wpath=".", string thrID="x", string user="x", string pass="x", string dbname="x", string fout="out", string ferr="err")
Execute an external program or script in a dedicated environment.
A class to create separate threads.
Conf * cnf
Pointer to the Conf object used to read the configuration file.
const char * tid()
Return the thread identifier.
Namespace for MCS library.