43 #endif //HAVE_CONFIG_H 65 #include <arpa/inet.h> 67 #include <sys/ioctl.h> 69 #include <sys/types.h> 70 #include <sys/socket.h> 78 #endif //COMPILING_MCS 82 #include <netinet/in.h> 104 #include "mcs_config.h" 114 #define TBOLD "\x1B[1m" 115 #define REV "\x1B[7m" 116 #define RED "\x1B[31m" 117 #define GREEN "\x1B[32m" 118 #define BLUE "\x1B[34m" 119 #define CYAN "\x1B[36m" 120 #define YELLOW "\x1B[33m" 121 #define MAGENTA "\x1B[35m" 123 #define BGBLUE "\x1B[44m" 124 #define NORMAL "\x1B[0m" 125 #define CLEANS "\x1B[2J" 128 #define MERROR std::cerr << RED << "\r(E)\t"<< GREEN << __FILE__ << "," << __LINE__ << NORMAL << "\t" <<TBOLD<<__FUNCTION__<<NORMAL << "\t" 129 #define MINFO std::cout << BLUE << "\r(I)\t"<< GREEN << __FILE__ << "," << __LINE__ << NORMAL << "\t" <<TBOLD<<__FUNCTION__<<NORMAL << "\t" 130 #define MWARN std::cout << YELLOW << "\r(W)\t"<< GREEN << __FILE__ << "," << __LINE__ << NORMAL << "\t" <<TBOLD<<__FUNCTION__<<NORMAL << "\t" 138 #define MYSQL_SOCK NULL 143 #define MYSQL_BIND char 147 typedef struct st_mysql_time
149 unsigned int year, month, day, hour, minute, second;
151 #endif //ENABLE_MYSQL 156 #ifdef HAVE_OPENSSL_SSL_H 157 #include <openssl/ssl.h> 158 #include <openssl/err.h> 159 #endif //HAVE_OPENSSL_SSL_H 168 #endif //COMPILING_MCS 189 #define MCS_DEFAULT_PORT 6523 198 #define MCS_DEFAULTCHUNKSIZE 16384 202 #define MCS_DEFAULT_MAX_USERS 100 206 #define MCS_DEFAULT_CLIENT_TIMEOUT 10 * 60 * 1000 210 #define MCS_COMMBUFSIZE 1024 214 #define MCS_SSLCERT "mcscert.pem" 215 #define MCS_SSLPRIV "mcspkey.pem" 218 #define MCS_GRANT_NO_GRANTS 0 219 #define MCS_GRANT_LOGIN 1 220 #define MCS_GRANT_SQL_SCRIPTS 2 221 #define MCS_GRANT_SCRIPTS 4 222 #define MCS_GRANT_QUERY 8 223 #define MCS_GRANT_BATCH 16 224 #define MCS_GRANT_GET 32 225 #define MCS_GRANT_PUT 64 226 #define MCS_GRANT_SYS 128 227 #define MCS_GRANT_ADMIN 256 228 #define MCS_GRANT_ALL 511 232 #define MCS_BANNER "\nMy Customizable Server (MCS) ver. " PACKAGE_VERSION "\n" 235 #define MCS_MISSING_COPY_CONSTRUCTOR(CLASS) \ 239 #define MCS_MISSING_ASSIGNMENT_OPERATOR(CLASS) \ 240 CLASS& operator=(const CLASS&); 276 #define MCS_PROMPT_OK MCS_PRE "0--" 279 #define MCS_PROMPT_WARN MCS_PRE "0W-" 282 #define MCS_PROMPT_ERROR MCS_PRE "0E-" 291 #define MCS_CMD_NOP "NOP" 292 #define MCS_CMD_NOP_HELP "No operation (dummy) command." 296 #define MCS_CMD_CLIENT_INFO "CLINFO" 297 #define MCS_CMD_CLIENT_INFO_HELP "Return all client informations." 301 #define MCS_CMD_USERNAME "USR" 302 #define MCS_CMD_USERNAME_HELP "Supply user name.\n" \ 306 #define MCS_CMD_PASSWORD "PWD" 307 #define MCS_CMD_PASSWORD_HELP "Supply password.\n" \ 311 #define MCS_CMD_DBNAME "DBN" 312 #define MCS_CMD_DBNAME_HELP "Supply application (database) name.\n" \ 313 "DBN <application_name>" 317 #define MCS_CMD_DBCONNECT "CON" 318 #define MCS_CMD_DBCONNECT_HELP "Finalize the authentication process and log in.\n" \ 322 #define MCS_CMD_CLOSECLIENT "BYE" 323 #define MCS_CMD_CLOSECLIENT_HELP "Close the session.\n" \ 327 #define MCS_CMD_CID "CID" 328 #define MCS_CMD_CID_HELP "Retrieve the Client identifier.\n" \ 337 #define MCS_CMD_RECORD "FETCH" 338 #define MCS_CMD_RECORD_HELP "Retrieve the record at a specified position, or at\n" \ 339 "current position (if none is specified) of the last\n" \ 340 "query executed.\n" \ 348 #define MCS_CMD_QUERY "QRY" 349 #define MCS_CMD_QUERY_HELP "Execute queries on the database.\n" \ 353 #define MCS_CMD_SENDQUERYRES "QRES" 354 #define MCS_CMD_SENDQUERYRES_HELP "Retrieve a file with an ASCII dump of the entire set\n" \ 355 "of records returned by the last query." \ 360 #define MCS_CMD_TABLELIST "TLIST" 361 #define MCS_CMD_TABLELIST_HELP "Retrieve the list of tables actually present in the\n" \ 366 #define MCS_CMD_TABLEINFO "TINFO" 367 #define MCS_CMD_TABLEINFO_HELP "Retrieve information about a table.\n" \ 369 #endif //ENABLE_MYSQL 378 #define MCS_OPT_SAVEQUERYFITS "sqfits" 379 #define MCS_OPT_SAVEQUERYFITS_HELP "Save query result in FITS format.\n " \ 383 #define MCS_OPT_SAVEQUERYASCII "sqascii" 384 #define MCS_OPT_SAVEQUERYASCII_HELP "Save query result in ASCII format.\n" \ 389 #define MCS_OPT_FORCE "force" 390 #define MCS_OPT_FORCE_HELP "Continue execution of commands even if an error\n" \ 395 #define MCS_OPT_ALL_ERRORS "werr" 396 #define MCS_OPT_ALL_ERRORS_HELP "Turns all warning into errors, so that a warning can\n" \ 397 "stop the execution.\n" \ 401 #define MCS_OPT_LOOP "loop" 402 #define MCS_OPT_LOOP_HELP "Put a copy of thr received Data object in the \n" \ 403 "\"send\" vector.\n" \ 407 #define MCS_OPT_HELP "help" 411 #define MCS_CMD_EXEC "EXEC" 412 #define MCS_CMD_EXEC_HELP "Execute an external program, SQL or batch file.\n" \ 413 "EXEC <alias> [[PAR1] [PAR2] ...]" 416 #define MCS_CMD_GET "GET" 417 #define MCS_CMD_GET_HELP "Download a file from the work directory.\n" \ 421 #define MCS_CMD_PUT "PUT" 422 #define MCS_CMD_PUT_HELP "Upload a file to the work directory.\n" \ 423 "PUT <filename> <size>" 426 #define MCS_CMD_GETDATA "GDATA" 427 #define MCS_CMD_GETDATA_HELP "Download Data objects.\n" \ 431 #define MCS_CMD_PUTDATA "PDATA" 432 #define MCS_CMD_PUTDATA_HELP "Upload Data objects.\n" \ 479 #include "mcstypes.hh" 490 #define my_mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N))) 499 #define MCS_SUBST_QUOTE_WITH 1 502 #define MCS_SUBST_LEADING 4 505 #define MCS_SUBST_TRAILING 8 515 string subst(
string s,
string what,
string with,
int op = 0);
519 string trim(
string s);
522 string chomp(
string s);
540 vector<string>
split(
string s,
string sep =
" ");
580 int stoi(
string s,
int errval);
587 string vtos(vector<string> vec);
590 string dtos(
double f);
596 string hexDump(
const void* buf,
unsigned int size);
599 #define MCS_MKDIR_UMASK 0 600 #define MCS_MKDIR_PROTECT S_IRUSR | S_IWUSR | S_IXUSR 618 string Types2Str(Types type,
bool isunsigned);
640 int copy(
char* OLDNAME,
char* NEWNAME);
655 int move(
char* OLDNAME,
char* NEWNAME);
670 bool MYSQL2Types(enum_field_types mtype, Types& type);
679 bool Types2MYSQL(Types& type, enum_field_types& mtype);
690 #endif //ENABLE_MYSQL 701 bool FITS2Types(
int fits, Types& dbt,
bool& isunsigned);
710 bool Types2FITS(Types dbt,
bool isunsigned,
int& fits);
719 bool Types2S_FITS(Types dbt,
int len,
bool isunsigned,
string& fits);
724 #endif //ENABLE_CFITSIO 730 #define MCS_VMSG_SIZE 1000 844 static void init_vmsg();
849 void init(
string atFile,
unsigned int atLine,
RetValue type,
int code);
868 Event(
string atFile,
unsigned int atLine,
RetValue type,
int code,
869 string s1 =
"",
string s2 =
"",
string s3 =
"");
878 Event(
string atFile,
unsigned int atLine,
RetValue type,
int code,
888 Event(
string atFile,
unsigned int atLine,
RetValue type,
int code,
889 int i1,
string s1 =
"");
899 Event(
string atFile,
unsigned int atLine,
RetValue type,
int code,
937 Event& subcode(
int subcode);
953 static string static_vmsg(
unsigned int i);
958 #define MCS_OK(A, rest...) mcs::Event(__FILE__, __LINE__, mcs::OK, A, ## rest) 961 #define MCS_WARN(A, rest...) mcs::Event(__FILE__, __LINE__, mcs::WARN, A, ## rest) 964 #define MCS_ERROR(A, rest...) mcs::Event(__FILE__, __LINE__, mcs::ERROR, A, ## rest) 967 #define MCS_FATAL(A, rest...) mcs::Event(__FILE__, __LINE__, mcs::FATAL, A, ## rest) 970 #define MCS_(TYPE, rest...) mcs::Event(__FILE__, __LINE__, TYPE , ## rest) 980 #define MCS_DEBUG_ALLOC 981 #define MCS_DEBUG_SETUP(A, B) 983 #define MCS_DEBUG_ENTER(A) 984 #define MCS_DEBUG_LEAVE(A) 987 #undef MCS_DEBUG_ALLOC 988 #undef MCS_DEBUG_SETUP 990 #undef MCS_DEBUG_ENTER 991 #undef MCS_DEBUG_LEAVE 993 #define MCS_DEBUG_ALLOC Debug _debug_ 994 #define MCS_DEBUG_SETUP(A, B) _debug_.setDebug(B, this, A) 995 #define MCS_DEBUG(A) if (_debug_.getDebugFlag()) { cout << _debug_.debug(__FILE__, __LINE__, __FUNCTION__) << A << endl; } 996 #define MCS_DEBUG_ENTER(A) MCS_DEBUG("-> " A); 997 #define MCS_DEBUG_LEAVE(A) MCS_DEBUG("<- " A); 999 #define MCS_DEBUG_NTHR 100 1008 static pthread_t thrs[MCS_DEBUG_NTHR];
1009 static bool thrmap[MCS_DEBUG_NTHR];
1017 string debug(
const char* file,
int line,
const char*
function);
1019 void setDebug(
string className,
void* pthis = 0,
bool active =
false);
1021 bool getDebugFlag();
1023 #endif //ENABLE_DEBUG 1024 #endif //DOXYGEN_SKIP 1133 Buffer(
void* extbuf,
unsigned int size,
1142 MCS_MISSING_COPY_CONSTRUCTOR(
Buffer);
1151 MCS_MISSING_ASSIGNMENT_OPERATOR(
Buffer);
1171 Buffer& operator()(
unsigned int start,
unsigned int len);
1182 Buffer& operator()(
unsigned int len);
1193 Buffer& operator<<(
const void* extbuf);
1195 Buffer& operator<<(istream& stream);
1206 Buffer& operator>>(
void* extbuf);
1208 Buffer& operator>>(ostream& stream);
1210 operator void*()
const {
return buf; }
1214 char* operator[](
unsigned int pos);
1242 void resize(
unsigned int size);
1245 unsigned int size();
1265 #define MCS_SERIAL_UNKNOWN 0 1266 #define MCS_SERIAL_BUFFER 1 1267 #define MCS_SERIAL_FILENAME 2 1327 void init(
int type,
unsigned int lmaxChunksize);
1344 virtual char* nextChunk_unknown(
char* userdata,
char* buf,
1345 unsigned int& chunksize,
bool firstTime);
1347 virtual char* serialize_unknown();
1349 virtual bool serialize_buffer(
char*& from,
unsigned int& size);
1351 virtual string serialize_filename();
1355 void serialize_end();
1392 Serializable(
void* from,
unsigned int size,
bool freeAfterUse,
1422 void* nextChunk(
unsigned int& chunksize);
1424 void* getEntireBuffer(
unsigned int& size);
1427 unsigned int maxChunkSize();
1463 unsigned int nChunk();
1470 unsigned int size();
1490 unsigned int lindex;
1492 int req(
int ioctl_num,
struct ifreq *ifr);
1495 void str_sockaddr(
struct sockaddr* sa);
1496 void str_sockaddr_in(
struct sockaddr_in* sin);
1553 string name(
int index = -1);
1556 unsigned int index();
1559 unsigned int count();
1571 string ipaddress(
int index = -1);
1591 struct sockaddr_in sin;
1594 void populate_sockaddr_in();
1603 MCS_MISSING_COPY_CONSTRUCTOR(
HostInfo);
1610 MCS_MISSING_ASSIGNMENT_OPERATOR(
HostInfo);
1673 #ifdef HAVE_OPENSSL_SSL_H 1683 void initialize_ssl_bio(
string keyfile);
1684 #endif //HAVE_OPENSSL_SSL_H 1693 struct timeval readto;
1696 struct timeval writeto;
1712 int socketToHost(
unsigned short port);
1728 void sendChunk(
void* buf,
unsigned int size);
1746 unsigned int recvChunk(
void* buf,
unsigned int size);
1753 unsigned int recvChunk(
Buffer* buf);
1811 MCS_MISSING_COPY_CONSTRUCTOR(
Socket);
1818 MCS_MISSING_ASSIGNMENT_OPERATOR(
Socket);
1834 Socket(
string host,
unsigned short int port=0,
1835 unsigned int readTimeout = 1000,
1836 unsigned int writeTimeout = 1000,
1854 unsigned int readTimeout = 1000,
1855 unsigned int writeTimeout = 1000,
1856 void* ssl_ctx = NULL);
1876 static void set_struct_timeval(
unsigned int millisec,
struct timeval* time);
1893 unsigned int read(
void* buf,
unsigned int count);
1909 unsigned int write(
void* buf,
unsigned int count);
1935 void print(
string s);
1967 unsigned int recvData(
char** buffer,
unsigned int maxsize);
1979 unsigned int recvData(
string filename);
1989 unsigned int recvData(
int filedes);
1999 unsigned int recvData(ofstream& stream);
2024 #ifdef HAVE_OPENSSL_SSL_H 2027 #endif //HAVE_OPENSSL_SSL_H 2059 ServerSocket(
string interface,
unsigned short int port,
2060 bool use_ssl =
false,
string sslcert =
"",
string sslpriv =
"");
2077 bool acceptConnection(
int& newsock,
unsigned int millisec);
2079 void* getSSLContext();
2194 #if defined(_POSIX_TIMEOUTS) && (_POSIX_TIMEOUTS - 200112L) >= 0L 2220 MCS_MISSING_COPY_CONSTRUCTOR(
Synchro);
2228 MCS_MISSING_ASSIGNMENT_OPERATOR(
Synchro);
2256 void synchronize(
bool setactive);
2259 #define MCS_SYNCHRO_LOCK 1 2262 #define MCS_SYNCHRO_TRY_LOCK 2 2266 #define MCS_SYNCHRO_TRY_TIMED 3 2305 bool tryenter(
unsigned int timeout = 0);
2321 #ifdef ENABLE_CLEANUP_HANDLERS 2330 static void CH_leave(
void* This);
2331 #endif //ENABLE_CLEANUP_HANDLERS 2375 #define MCS_CRITICAL_SECTION_BEGIN enter(); try { 2380 #define MCS_CRITICAL_SECTION_END } catch(Event e) { leave(); throw e; } leave(); 2382 #define MCS_CRITICAL_SECTION_END_RETURN(What...) \ 2383 leave(); return What; } \ 2384 catch(Event e) { leave(); throw e; } 2393 #define MCS_CRITICAL_SECTION(BLOCK...) \ 2394 MCS_CRITICAL_SECTION_BEGIN \ 2396 MCS_CRITICAL_SECTION_END 2406 #define MCS_STATE_CREATED 1 2409 #define MCS_STATE_RUNNING 2 2413 #define MCS_STATE_TERMINATING 3 2416 #define MCS_STATE_END 4 2493 static void* RunThread(
void* args);
2516 static void cleanup_Handler(
void* This);
2524 bool checkTerminating();
2558 virtual void notify(
int id,
Thread* ref);
2571 virtual void initial();
2589 virtual void final();
2606 void set_cancel_state(
bool cancel);
2692 void startDetached(
bool selfDelete =
false);
2738 template<
class BASE>
2745 static void generic_destructor(
void* p)
2746 {
delete ((BASE*) p); }
2748 void (*destructor)(
void*);
2753 destructor = generic_destructor;
2755 destructor = ext_destructor;
2757 pthread_key_create(&key, destructor);
2761 { pthread_key_delete(key); }
2769 pthread_setspecific(key, NULL);
2772 void init(BASE* p = NULL,
int tag = 0)
2779 pthread_setspecific(key, p);
2786 BASE* operator->()
const 2787 {
return ((BASE*) pthread_getspecific(key)); }
2790 {
return ((BASE*) pthread_getspecific(key)); }
2800 int (*start_routine1)(
void*);
2801 Event* (*start_routine2)(
void*);
2809 ThreadFunc(
int (*start_routine)(
void*),
void* arg);
2823 void sleep_ms(
unsigned int millisec);
2842 time_t my_timelocal(
struct tm* tm);
2889 static const char* parseTime(
const char* s,
struct tm* tm);
2893 void to_MYSQL_TIME();
2903 time_t getTime()
const;
2917 void setMysqlBuffer(MYSQL_TIME* mysql);
2933 void setTimeMode(
enum TimeMode tm);
2941 void settval(time_t t);
2945 { settval(t);
return *
this; }
2951 void setsval(
string s);
2955 { setsval(s);
return *
this; }
2972 void settmval(
struct tm& ltm);
2976 { settmval(ltm);
return *
this; }
2980 time_t tval()
const;
2983 operator time_t()
const 2988 struct tm tmval() const;
2991 operator struct tm() const
2995 string sval()
const;
2998 operator string()
const 3004 #define MCS_ID_UNKNOWN -1 3005 #define MCS_ID_LOCAL -2 3006 #define MCS_ID_CLIENT -3 3020 #define MCS_DATA_NDIM 15 3097 void reallocBuffer();
3166 void init(MYSQL_BIND* bind,
Types type,
const char* name=
"",
3167 unsigned short int maxLength=0,
bool isunsigned=
false,
3168 unsigned int flags = 0);
3193 bool serialize_buffer(
char*& from,
unsigned int& size);
3209 unsigned short int ldim[MCS_DATA_NDIM];
3212 unsigned short int mult[MCS_DATA_NDIM];
3222 unsigned int objSize();
3247 Data(
Types type,
unsigned short int maxLength = 0,
3248 bool isunsigned =
false,
string dimSpec =
"");
3274 const char* name=
"",
unsigned short int maxLength=0,
3275 bool isunsigned=
false,
unsigned int flags = 0,
3276 unsigned char tag = 0);
3285 Data(
int v,
unsigned char tag = 0);
3293 Data(
long long int v,
unsigned char tag = 0);
3301 Data(
double v,
unsigned char tag = 0);
3311 Data(
string v,
unsigned char tag = 0);
3319 Data(
struct tm v,
unsigned char tag = 0);
3327 Data(time_t v,
unsigned char tag = 0);
3340 Data(
void* lbuf,
unsigned int size,
unsigned char tag = 0);
3368 void setName(
string name);
3377 unsigned short int maxLength();
3380 unsigned short int length();
3389 bool isAutoIncrement();
3392 void* buffer()
const;
3408 unsigned int uival()
const;
3416 long long int lval()
const;
3424 unsigned long long int ulval()
const;
3440 double dval()
const;
3448 string sval(
bool addWhiteSpaces =
false)
const;
3461 int cval(
char* c,
int maxlength)
const;
3466 time_t tval()
const;
3475 void tval(
struct tm* t)
const;
3480 void setpval(
void* p);
3484 void setNull(
bool null =
true);
3487 void setival(
int v);
3490 void setuival(
unsigned int v);
3493 void setlval(
long long int v);
3496 void setulval(
unsigned long long int v);
3499 void setdval(
double v);
3502 void setcval(
const char* v);
3505 void setsval(
string v);
3508 void setblob(
void* lbuf,
unsigned int size);
3511 void settimeval(
struct tm v);
3514 void settimeval(time_t v);
3519 void setTimeMode(
enum TimeMode tm);
3559 void resize(
string dimSpec);
3572 void resizeVaryingDim(
unsigned short int newsize);
3579 unsigned short int dim(
int d);
3590 unsigned int howManyDim();
3601 unsigned int varyingDim();
3608 unsigned int arraySize();
3617 unsigned int array(
unsigned short int i1 = 0,
3618 unsigned short int i2 = 0,
3619 unsigned short int i3 = 0,
3620 unsigned short int i4 = 0,
3621 unsigned short int i5 = 0,
3622 unsigned short int i6 = 0,
3623 unsigned short int i7 = 0,
3624 unsigned short int i8 = 0,
3625 unsigned short int i9 = 0,
3626 unsigned short int i10 = 0,
3627 unsigned short int i11 = 0,
3628 unsigned short int i12 = 0,
3629 unsigned short int i13 = 0,
3630 unsigned short int i14 = 0,
3631 unsigned short int i15 = 0);
3636 Data& operator()(
const int i1 = 0,
3654 { setival(v);
return *
this; }
3658 { setuival(v);
return *
this; }
3662 { setlval(v);
return *
this; }
3666 { setulval(v);
return *
this; }
3670 { setdval(v);
return *
this; }
3674 { setsval(v);
return *
this; }
3678 { setsval(v);
return *
this; }
3682 { settimeval(v);
return *
this; }
3686 { settimeval(v);
return *
this; }
3689 operator const int ()
const {
return ival (); }
3692 operator const unsigned int ()
const {
return uival (); }
3695 operator const long long int ()
const {
return lval (); }
3698 operator const unsigned long long int ()
const {
return ulval (); }
3701 operator const float ()
const {
return dval (); }
3704 operator const double ()
const {
return dval (); }
3707 operator const char* ()
const {
return (
char*) pval(); }
3710 operator const string ()
const {
return sval (); }
3713 operator const struct tm () const {
struct tm v; tval(&v);
return v; }
3716 operator const time_t ()
const {
return tval (); }
3750 static void parseTime(
string s,
struct tm* ts);
3766 static long long int MinValue(
Types ltype,
bool flunsigned);
3780 static long long int MaxValue(
Types ltype,
bool flunsigned);
3786 void setTag(
unsigned char tag);
3789 unsigned char getTag();
3793 void setSourceID(
int id);
3794 void setDestID(
int id);
3800 #define DYNAMIC_ARRAY_DEFAULT_STEP 10 3812 template<
class BASE>
3831 void check_allocation(
int count);
3933 BASE pop(
int pos = 0);
3964 BASE& operator[](
int pos);
3991 template<
class BASE>
3994 static int max_size = Data::MaxValue(
SMALL,
true);
3996 if (count >= max_size)
3997 throw MCS_ERROR(MSG_INDEX_OUT_RANGE, count, max_size);
4001 size =
sizeof(BASE*) * step_alloc * DYNAMIC_ARRAY_DEFAULT_STEP;
4003 if (step_alloc == 1)
4004 arr = (BASE**) malloc(size);
4006 arr = (BASE**) realloc(arr, size);
4011 template<
class BASE>
4015 synchronize(synchro);
4022 template<
class BASE>
4029 template<
class BASE>
4035 for (i=0; i<from.
count(); i++)
4042 template<
class BASE>
4046 check_allocation(lcount + 1);
4053 template<
class BASE>
4057 check_allocation(lcount + 1);
4058 arr[lcount++] =
new BASE(d);
4071 template<
class BASE>
4077 BASE d = BASE(
operator[](pos));
4083 for (i=pos; i<lcount; i++)
4087 MCS_CRITICAL_SECTION_END_RETURN(d);
4091 template<
class BASE>
4097 throw MCS_ERROR(MSG_INVALID_POSITION, pos);
4100 throw MCS_ERROR(MSG_INDEX_OUT_RANGE, pos, lcount);
4106 template<
class BASE>
4111 BASE d = operator[](pos);
4113 MCS_CRITICAL_SECTION_END_RETURN(d);
4117 template<
class BASE>
4123 template<
class BASE>
4125 return (
bool) (lcount > 0);
4129 template<
class BASE>
4135 for (i=0; i<lcount; i++)
4202 bool serialize_buffer(
char*& from,
unsigned int& size);
4228 Record(
bool synchro =
false);
4239 Record(
void* lbuf,
bool synchro =
false);
4255 void addField(
Data* d);
4258 void addField(
Data& d);
4268 void addField(
string s,
char tag = 0);
4278 void addField(
int i,
char tag = 0);
4288 void addField(
long long int i,
char tag = 0);
4298 void addField(
double f,
char tag = 0);
4300 Data pop(
int x = 0);
4363 void setFieldMap(
string s =
"");
4366 void setFieldMap(
Record& rec);
4384 Data& operator[](
string name);
4386 Data& operator[](
int pos);
4389 Data field(
string name);
4391 Data field(
int pos);
4395 unsigned int objSize();
4398 string asString(
string sep =
"\t");
4399 string asStringNames(
string sep =
"\t");
4400 string asStringTypes(
string sep =
"\t");
4437 #define MCS_RS_ACCUM 1 4449 #define MCS_RS_USEMETAREC 2 4457 #define MCS_RS_KNOW_NROWS 4 4466 #define MCS_RS_RANDOM 8 4480 #define MCS_RS_INSERT 16 4566 virtual Record* newRecord();
4579 bool internal_fetch(
unsigned int newpos);
4607 void init(
unsigned char code,
unsigned int nrows = 0,
Record* meta = NULL,
4638 virtual bool fetch(
unsigned int newpos,
bool random);
4641 virtual void hk_dump(
string fn);
4651 MCS_MISSING_COPY_CONSTRUCTOR(
RecordSet);
4659 MCS_MISSING_ASSIGNMENT_OPERATOR(
RecordSet);
4683 void setFieldMap(
string s =
"");
4696 void insert(
Record* rec);
4708 void insert(
Record& rec);
4769 bool setWhere(
int i,
string equalTo);
4788 bool setWhere(
int field,
int equalTo);
4806 bool setPos(
unsigned int i);
4808 void dump(
string fn);
4811 unsigned int nRows();
4818 bool alwaysSameStructure();
4869 int index(
string section,
string key);
4880 MCS_MISSING_COPY_CONSTRUCTOR(
Conf);
4888 MCS_MISSING_ASSIGNMENT_OPERATOR(
Conf);
4895 Conf(
string filename =
"");
4900 void open(
string filename);
4932 Data& val(
string section =
"",
string key =
"");
4947 string sval(
string section,
string key);
4963 string sval(
string section,
string key,
string defval);
4980 int ival(
string section,
string key);
4996 int ival(
string section,
string key,
int defval);
5012 long long int lval(
string section,
string key);
5028 long long int lval(
string section,
string key,
int defval);
5045 void setval(
string section,
string key,
string val,
string comment =
"");
5062 void setval(
string section,
string key,
long long int val,
string comment =
"");
5077 void setval(
string section,
string key,
int val,
string comment =
"");
5093 void setval(
string section,
string key,
Data* val,
string comment =
"");
5106 void save(
string filename =
"");
5117 #define MCS_CMD_MAX_TOKENS 100 5228 static string clean(
string c);
5271 string token(
int i);
5287 string line_afterToken(
int i);
5355 Data& optarg(
int i);
5358 void parseCmd(
string c);
5361 void parseCmd(
int argc,
char* argv[]);
5375 bool cmpCmd(
string cmd);
5378 bool givenOpt(
string opt);
5381 bool givenOpt(
string opt,
int& i);
5400 vector<string> replPars_onFile(
string fn);
5415 string replPars(
string str);
5467 MCS_MISSING_COPY_CONSTRUCTOR(
DBConn);
5475 MCS_MISSING_ASSIGNMENT_OPERATOR(
DBConn);
5497 void connect(
string user,
string pass,
string db,
string host=
"");
5594 vector<string> printResultSet(
unsigned int& nrows,
5595 unsigned int& nfields,
5596 MYSQL_RES* res = NULL);
5616 bool fetch(
unsigned int newpos,
bool random);
5639 void parseFieldList(
int op,
string& fields,
string& values,
int& autoIncr);
5649 MCS_MISSING_COPY_CONSTRUCTOR(
Query);
5657 MCS_MISSING_ASSIGNMENT_OPERATOR(
Query);
5673 Query(
DBConn* lconn,
bool call_newDBConn =
false);
5689 void query(
string SQL,
bool StoreResult =
false);
5732 vector<string> simpleQuery(
string SQL,
5733 unsigned int& nrows,
unsigned int& nfields);
5737 vector<string> simpleQuery(
string SQL);
5760 void prepare(
string SQL=
"");
5762 #define MCS_PAB_INSERT 1 5763 #define MCS_PAB_UPDATE 2 5764 #define MCS_PAB_REPLACE 3 5807 void prepare_with_parameters(
int op,
string fields,
string table,
5808 string where=
"",
int nrec=1);
5822 void prepare_with_parameters(
int op,
char** fields,
int nfields,
5823 string table,
string where=
"",
int nrec=1);
5833 unsigned int nAffectedRows();
5862 Data& lookup(
string field,
string table,
string where =
"");
5895 void execute(
bool StoreResult =
false);
5898 bool gotRecordSet();
5911 void readTableList();
5927 vector<string> tableInfo(
string tbl);
5931 vector<string> ExecutionDetails(
string pre =
"");
5953 void customFillBuffer(
char* buf,
unsigned int& chunksize,
bool firstTime);
5961 void Result2Ascii(
string fn);
5972 long long int last_id();
6016 void insert_or_update(
int op);
6025 MCS_MISSING_COPY_CONSTRUCTOR(
Table);
6033 MCS_MISSING_ASSIGNMENT_OPERATOR(
Table);
6181 static int fileType(
string fn);
6196 int chkExt(
string& s);
6236 static int spawn(
string fn,
string pars,
6241 string dbname =
"x",
6242 string fout =
"out",
6243 string ferr =
"err");
6251 #define MCS_FT_UNKNOWN 0 6254 #define MCS_FT_BATCH 1 6257 #define MCS_FT_SQL 2 6260 #define MCS_FT_SCRIPT 3 6263 #define MCS_FT_BIN 4 6286 Data& timeConnetcted();
6292 Data& lastCommand();
6295 Data& timeLastCommand();
6298 Data& commandExecuted();
6423 void setActiveRS(
RecordSet* rs,
bool delWhenFinished =
true);
6435 string wpath(
string fn =
"");
6481 RetValue Send(
string filename,
string path);
6572 virtual RetValue hk_auth(
int& grants,
bool& loginok);
6618 virtual void hk_disconnect();
6643 RetValue exec(
string cmd,
string pars =
"");
6654 void send2OtherThread(
Data& d,
int destid);
6707 void wakeUpClient(
Event* e = NULL);
6771 void dataDispatcher();
6790 bool userID2clientID(
int userid,
int* cid);
6871 #endif //ENABLE_MYSQL 6896 Env(
string app =
"mcs",
string inipath =
"mcs.conf");
6904 MCS_MISSING_COPY_CONSTRUCTOR(
Env);
6912 MCS_MISSING_ASSIGNMENT_OPERATOR(
Env);
7199 void notify(
int id,
Thread* ref);
7202 void newClient(
int newsock);
7209 void killAllClients();
7226 virtual void hk_newClient(
int i);
7229 void killClient(
int i);
7238 virtual UserThread* newUserThread(
int lID,
int newsock);
7255 MCS_MISSING_COPY_CONSTRUCTOR(
Server);
7263 MCS_MISSING_ASSIGNMENT_OPERATOR(
Server);
7301 void (*cb_disconnect) ();
7304 void (*cbwa_log) ();
7307 void (*cbwa_connect) ();
7310 void (*cbwa_auth) ();
7313 void (*cbwa_exec) ();
7316 void (*cbwa_postexec) ();
7319 void (*cb_newClient) (
int i);
7377 Env*
mcsStart(
string appname,
string inipath =
"",
7413 #define MCS_CUSTOM_USER(CLASS) \ 7414 class CLASS : public mcs::UserThread \ 7417 CLASS(mcs::Thread* p, int id, int sock) : \ 7418 UserThread(p, id, sock) {} \ 7420 #define MCS_CUSTOM_USER_END(CLASS) }; 7423 #define MCS_CUSTOM_LOCAL(CLASS) \ 7424 class CLASS : public mcs::LocalThread \ 7427 CLASS(mcs::Thread* p) : \ 7430 #define MCS_CUSTOM_LOCAL_END(CLASS) }; 7446 #define MCS_CUSTOM_SERVER(CLIENT, LOCAL) \ 7447 mcs::Server* newCustomServer(mcs::Env* env); \ 7449 class mcsCustomServer : public mcs::Server \ 7452 mcs::UserThread* newUserThread(int id, int sock) { \ 7453 return new CLIENT(this, id, sock); \ 7456 mcs::LocalThread* newLocalThread() { \ 7457 return new LOCAL(this); \ 7461 mcsCustomServer(mcs::Env* lenv): Server(lenv) {} \ 7463 ~mcsCustomServer() {} \ 7466 mcs::Server* newCustomServer(Env* env) \ 7467 { return new mcsCustomServer(env); } \ 7469 mcs::Env* mcsCustomStart(string appname, string inipath = "") \ 7470 { return mcsStart(appname, inipath, &newCustomServer); } 7548 void clearRecords();
7554 bool fetch(
unsigned int newpos,
bool random);
7571 MCS_MISSING_COPY_CONSTRUCTOR(
Client);
7618 bool synchro =
false,
bool SSL =
false,
7637 bool login(
string user,
string pass,
string db =
"");
7646 bool exec(
string cmd,
Data* data = NULL);
7648 void writeToFile(
int des);
7650 #define MCS_CLIENT_ERROR 1 7651 #define MCS_CLIENT_DATA 2 7652 #define MCS_CLIENT_FILE 3 7653 #define MCS_CLIENT_DISCONNECT 4 7654 virtual void event(
int op,
Data d,
int code = 0);
7743 bool consumerHasGone();
7751 string createNamed();
7787 class URLReader :
Pipe 7791 static bool fl_curl_global_init;
7799 static size_t cb_write(
void *ptr,
size_t size,
size_t nmemb,
void *This);
7802 static int thread_run(
void* p);
7803 void thread_fetch();
7813 virtual unsigned int Write(
void *ptr,
unsigned int size,
unsigned int nmemb);
7822 virtual ~URLReader();
7825 int OpenAsFD(
string url);
7828 const char* OpenAsFifo(
string url);
7830 void Download(
string url,
string fn);
7836 int Read(
char* buf,
int maxlen);
7854 static bool chkLocal(
string& url);
7875 bool fetch(
unsigned int newpos,
bool random);
7886 void open(
string fn);
7892 void selectHDU(
int hdunum);
7893 bool selectNextHDU();
7895 void selectHDU(
string name,
int extver = 0);
7899 bool ffile_is_compressed(
string fn);
7901 void read_json_header(
const string& json_string);
7920 void open(
string fn,
bool compressed =
false);
7923 void newKeyword(
string key,
string value,
string comment =
"");
7924 void newBinTable(
Record& meta,
string name =
"");
7925 void newAsciiTable(
int nfields,
string name =
"");
7926 void newImage(
Types bitpix,
unsigned int naxis,
unsigned int naxes,
7927 void* buf,
string name =
"");
7930 void write(
void* buf);
7932 #endif //ENABLE_CFITSIO 7963 #define MCS_B64_DEF_LINE 72 7964 #define MCS_B64_MIN_LINE 4 7966 #define MCS_B64_ENCODE 0 7967 #define MCS_B64_DECODE 1 7968 #define MCS_B64_DECODEINPLACE 2 7980 static const char* cb64;
7985 static const char* cd64;
7994 void requireSpace(
unsigned int Length);
8020 unsigned char precData[4];
8027 unsigned char readData();
8030 void writeData(
unsigned char d);
8033 void encodeblock(
unsigned char in[3],
unsigned char out[4],
int len);
8036 void decodeblock(
unsigned char in[4],
unsigned char out[3]);
8058 unsigned int encode(
char* buf_in,
int Length,
char* par_buf_out = NULL,
8059 unsigned int linesize = MCS_B64_DEF_LINE);
8074 unsigned int decode(
char* buf_in,
int Length,
char* par_buf_out = NULL);
8077 unsigned int bufUsed();
8082 #define MCS_SELECT_READ 0 8083 #define MCS_SELECT_WRITE 1 8086 int Select(
int fd,
unsigned int sec_timeout,
unsigned int usec_timeout,
int op);
8087 int Select(
int fd[],
int nfd,
unsigned int sec_timeout,
unsigned int usec_timeout,
int op);
#define MCS_DEFAULT_PORT
Default port on which the server is listening.
mode_t read_umask()
Read the file creation mask of the current process.
unsigned char tag
Tag for user convenience.
int step_alloc
How many blocks are allocated.
string btos(bool b)
Convert a boolean to a string containing "true" or "false".
bool lusemetarec
If all records share the same meta structure.
Retrieve informations about network interfaces.
Data & operator=(const struct tm v)
Wrapper assignment operator to settimeval(struct tm)
string itos(int i)
Convert an integer to a string.
A class to hold date time information.
Record send
Record of Data objects to be dispatched to be sent to client.
Data & operator=(const int v)
Wrapper assignment operator to setival(int).
short int lid
General purpose identificator.
string lpass
User password.
Connect to a MCS server as a client.
Data & operator=(const char *v)
Wrapper assignment operator to setsval(string)
MYSQL_STMT * lstmt
Mysql statement structure.
int lid
General purpose Thread identifier.
int lsubcode
Event subcode, usually an external library message code;.
TimeMode
Enumerate operational mode for a DateTime object.
unsigned int laffectedRows
Rows affected by the last INSERT-LIKE query.
int luserid
The userid of current user.
A class to directly set and retrieve value from a database table.
#define DYNAMIC_ARRAY_DEFAULT_STEP
Size of allocation block for the Dynamic_Array class.
Serialize memory buffers or files into chunks.
Base class for MCS threaded objects.
bool Types2FITS(Types dbt, bool isunsigned, int &fits)
Convert a MCS type into a FITSIO type.
vector< string > tableList
A vector<string> containing the table list.
#define MCS_CMD_MAX_TOKENS
Max number of tokens for a command line.
Dynamic_Array & operator=(Dynamic_Array &from)
Assignment operator.
int port
Server port number.
int lcount
How many elements are in the array.
#define MCS_COMMBUFSIZE
Max length of a message being sent between client and server.
string fnout
Default output file.
Execute queries on the database.
vector< string > keys
Internal vector containing keys names.
unsigned char code
Flags used in the init() method.
unsigned int maxChunksize
Maximum size of the chunk.
A simple class to implement "critical sections".
string smap
String representation of the map.
bool File_Dir_Exist(string fn, unsigned int &size)
Check if a file or directory exists.
bool lautoincr
If the AUTO_INCREMENT flag is true.
The server side client thread.
vector< string > rest
vector of "rests".
string ldb
Database name to connect to.
bool IntType(Types type)
Tell if "type" is an integer type.
UserThread ** pClient
Array of pointers to UserThread objects.
char * EOIB
Pointer to the end of input buffer.
static const char * tmfmt
Format to handle time in sprintf/sscanf calls.
DateTime & operator=(time_t t)
Wrapper to settval(time_t)
Data & operator=(const long long int v)
Wrapper assignment operator to setlval(long long int).
string Pwd()
Return the current working dir.
long long int lastid
Last generated id on an AUTO_INCREMENT column.
Dynamic_Array(bool synchro)
Constructor with optional synchronization.
Event * lerror
Last error.
vector< string > comments
Internal vector containing comments, this is used in the save() method.
unsigned int wstart
Beginning of the window (0-based).
bool ready()
Tells if there are objects in the array.
static const char * dfmt
Format to handle double float in sprintf/sscanf calls.
int batchlevel
Nested batch level.
Class holding information about a client connection.
Main server class for a MCS-based application.
unsigned int arrpos
Last selected array cell.
bool linsert
If true the insert mechanism will be used.
BufferFreeOnDestroy
Values to be used in Buffer class constructor.
unsigned int arrsize
Array size, i.e. how many cells are in the array.
Data & operator=(const unsigned long long int v)
Wrapper assignment operator to setulval(unsigned long long int).
bool cl_autoexec
Auto execute batch file "auto".
bool lknow_nrows
If the number of records is known.
Record dispatch
Record of Data objects to be sent to various threads.
A high level class to use system pipes.
unsigned long llength
Actual length of real data in the buffer, useful only when the base type is a variable length type...
MYSQL_TIME * mysql
Pointer to linked MYSQL_TIME structure.
Hold informations about an event.
string db_host
Host running database server.
static Env * env
Pointer to the actual Env object, this can be seen in all threaded object.
bool lconnOpened
True if the connection has been opened.
Record out
Record containing all output lines (code: MSG_OUT) sent by the server while executing the last comman...
unsigned int current
Internal position in the Dynamic_Array object.
A dynamic array of Data objects.
int copy(char *OLDNAME, char *NEWNAME)
Copy a file from OLDNAME to NEWNAME.
BASE ** arr
Array of pointer to template objects.
#define MCS_SYNCHRO_LOCK
To be used with Synchro.enter(): enter a critical section.
string MYSQL2Str(enum_field_types type)
Return the name of the MySQL type given in "type".
char * buf
Pointer to temporary buffer containing the next chunk.
A thread safe, template class to handle an array of objects.
unsigned char ldimspec
Multi-dimensional array specification.
string origcmdline
Command line parsed.
bool loginok
Tells if client has logged in correctly.
int move(char *OLDNAME, char *NEWNAME)
Move a file from OLDNAME to NEWNAME.
bool laccum
If all records has been fetched during the init() call.
BASE pop(int pos=0)
Extracts an element from the array.
unsigned int linesize
Required linesize (when encoding).
string fnerr
Default error file.
string path
Main server path (APPD).
BASE peek(int pos)
Retrieve an element from the array but don't extract it.
#define MCS_VMSG_SIZE
Size of the Event.vmsg static array.
string dbhost
Host running database server.
void push(BASE *d)
Push an existing element at the end of the array.
int stoi(string s, int errval)
Convert a string to an integer.
int sockfd
C socket file descriptor.
void ls2Record(string fn, Record &v)
Fill a vector with a list of file.
int csocket
C socket descriptor, used to initialize the Socket object.
#define MCS_DEFAULTCHUNKSIZE
File chunk size.
bool extbuffer
Tell if we are handling a user allocated buffer.
string db_name
Database name.
MYSQL * lconn
Mysql connection to use.
unsigned int bufsize
Size of data buffer.
pthread_t lthrID
System's thread identifier.
Data & operator=(const double v)
Wrapper assignment operator to setdval(double).
void sleep_ms(unsigned int millisec)
A millisecond resolution sleep function.
The base class that implement the data abstraction layer.
#define MCS_ERROR(A, rest...)
Facility to easily pass all necessary parameter to an Event constructor.
int max_users
How many clients can be connected at the same time.
string lcmd
First token, that is the command.
Data & operator=(const string v)
Wrapper assignment operator to setsval(string).
static int filecount
Used to generate a unique filename.
bool isActive
Whether this object is a "dummy" object or not.
char * from
Pointer to source buffer, if type = MCS_SERIAL_BUFFER.
bool leof
If the current position (lpos) is at the end of the set.
string appname
Application name.
void * ssl_ctx
Pointer to the global SSL context object, used if cl_use_ssl is true.
string Types2Str(Types type, bool isunsigned)
Return the name of the type given in "type" and "isunsigned".
~Dynamic_Array()
Destructor, this also destroy all objects in the array.
string fitsError(int status)
Return a description of a FITS error.
unsigned int posfieldkey
Position of the index field.
unsigned int bufsize
Size of the buffer.
unsigned int wlen
Length of the window.
char * pout
Cursor for output buffer.
Data & operator=(const unsigned int v)
Wrapper assignment operator to setuival(unsigned int).
RetValue
Return value for MCS routines.
vector< string > args
vector of arguments.
bool use_ssl
True if the connection should be encrypted.
string vtos(vector< string > vec)
Join a vector of strings in a single string using newlines.
static const char * dtfmt
Format to handle datetime in sprintf/sscanf calls.
string Types2MYSQLStr(Types &type, bool isunsigned)
Convert a MCS type into a MySQL type.
Read and write configuration files.
bool cl_restartlocal
Resart local thread when it dies.
Record msg
Record containing all reply's messages sent by the server while executing the last command...
string lhost
Host running database server.
bool FloatType(Types type)
Tell if "type" is a float type.
char * buf
Pointer to internal buffer.
bool cl_createlocal
Create local thread.
bool connected
Flag telling if the client is connected or not.
string remTrailing(string &s, const char *p)
Remove any trailing character "p".
Data & operator=(const time_t v)
Wrapper assignment operator to settimeval(time_t)
bool use_ssl
True if the connection should be encrypted.
int type
Type of data to be sent.
bool Types2S_FITS(Types dbt, int len, bool isunsigned, string &fits)
Convert a MCS type into a FITSIO type code.
BASE & operator[](int pos)
The operator[] for the array.
string dbname
Database name, usually the same as Env.appname.
DateTime & operator=(struct tm <m)
Wrapper to settmval()
string lpath
Local path to read/write files.
Thread * lparent
Reference to parent Thread object, if any is given in the constructor.
MYSQL_BIND * lbrec
Record of binding structure for output.
static const char * lfmt
Format to handle long integers in sprintf/sscanf calls.
bool cl_local_kills_mcs
When the local thread dies the server will be stopped.
A Base 64 encoder/decoder.
bool cl_logfile
Use log file.
bool cl_have_db
Activate DB facilities.
vector< string > split(string s, string sep=" ")
Split a string into tokens.
pthread_mutex_t mutex
The mutex used to do the job.
Handle database connection.
pthread_mutexattr_t attr
Attribute of the mutex (PTHREAD_MUTEX_RECURSIVE_NP).
Server side administrative thread.
vector< string > sections
Internal vector containing section names.
string inipath
Application ini file.
string remTabs(string s)
Remove any tab.
#define MCS_CRITICAL_SECTION_END
End a critical section, there must be no "return" or "goto" instruction inside the section...
string interface
Server interface name.
bool select
If a window has been selected.
string filename
Path to the configuration file.
time_t time
Internal storage (seconds elapsed since 1970-01-01 00:00:00 UTC).
static const char * ifmt
Format to handle integers in sprintf/sscanf calls.
Env * mcsStart(string appname, string inipath="", Server *(*cb_newServer)(Env *)=NULL)
Start a MCS server.
int lstate
State of the object, see state() method.
unsigned short int lmaxlength
Max number of bytes that can be stored in the buffer (size of the buffer).
char * pin
Cursor for input buffer.
ofstream * flog
Stream to write the log file.
bool cl_logstdout
Copy log on stdout.
bool cl_clean_logout
Clean work dir on user logout.
bool cl_work_cid
Work path is created using cid if true, otherwise with the user name.
char * buf_out
Pointer to output buffer.
vector< string > names
Vector containing the name of all interfaces present in the system.
string chomp(string s)
Remove any trailing newlines.
int extractCode(const char *msg)
Extract the numeric code from a server reply.
unsigned int bufused
Size of data in output buffer.
bool VarLenType(Types type)
Tell if "type" is a variable length type.
void check_allocation(int count)
Alloc necessary memory to store data in the array.
vector< string > optargs
vector of argument to options.
MYSQL * lconn
MYSQL connection structure.
DateTime & operator=(string s)
Wrapper to setsval(string)
A general purpose data type.
Record recv
Record of Data objects received from the client or other threads.
unsigned short int port
Port on which this socket will connect.
Dynamic_Array< Record > rs
Internal Record set.
unsigned int timeout
Timeout for client operations, in millisecond.
char * bufAllocated
Pointer to allocated internal buffer.
bool MYSQL2Types(enum_field_types mtype, Types &type)
Convert a MySQL type into a MCS type.
string subst(string s, string what, string with, int op=0)
Perform substitutions on a string.
Record recv
Record containing all Data objects sent by the server.
bool rmDir(string path, enum ThrowExceptions throwexc=THROW)
Removes a directory.
string db_user
User name for the local thread access to DB.
string pipefn
Name of the FIFO file.
void clear()
Empty the array.
bool flcreated
Tell if a pipe has been created.
Types ltype
Object base type.
string latFile
Source file.
int id_source
The userid of the thread who send this object.
Socket * sock
Socket to client.
Record recv
Record of Data objects received from other threads.
ThrowExceptions
Values to be used with throwexc parameters.
string remLeading(string &s, const char *p)
Remove any leading character "p".
bool lrandom
If random access (setFirst, setLast, setPos) is allowed.
Query * query
Query object.
Record newrec
Array of values for insert.
int cl_chunksize
Default size of a chunk of a Serializable object, that is chunks that goes through the network...
Hold all environment variables.
bool cl_read_grants
Read grants from the DB table (deprecated).
bool detached
Tell if the thread is to be created in the detached state.
string trim(string s)
Remove any leading or trailing blanks.
bool lconnInitialized
True if the connection has been initialized.
A class to create separate threads.
bool cl_use_ssl
Use secure connections.
bool FITS2Types(int fits, Types &dbt, bool &isunsigned)
Convert a FITSIO type into a MCS type.
string hexDump(const void *buf, unsigned int size)
Return a string with an hex dump of the buffer pointed by "buf", with a length of "size"...
string sslpriv
Path to the SSL private key file, used if cl_use_ssl = 1.
static bool flInitialized
Flag to tell if the init() method has been already called.
bool selfDelete
Tell if the object should delete himself once the thread is terminated.
bool lhandleNewDBConn
Flag to indicate that a new DBConn object has been created.
vector< string > opts
vector of options.
vector< string > tokens
vector of tokens.
unsigned int lflags
Flags (EXPERIMENTAL).
bool gotResult
True if we got a result from the last query.
RetValue ltype
Event type.
#define MCS_CRITICAL_SECTION_BEGIN
Start a critical section, there must be no "return" or "goto" instruction inside the section...
int sockfd
Server socket descriptor.
string lfieldkey
Name of the index field.
Conf * cnf
Pointer to the Conf object used to read the configuration file.
ifstream * stream
Pointer to an ifstream, if type = MCS_SERIAL_FILENAME.
bool gotStmtInitialized
True if the statement has been initialized.
Record lmetarec
Record of meta structure, to be used only if lusemetarec is true.
unsigned int lnrows
Number of records, to be used only if lknow_nrows is true.
static const char * ffmt
Format to handle float in sprintf/sscanf calls.
DBConn * ldbc
Internal reference to the DBConn object used to connect to db.
my_bool lisnull
The object has a null value.
string appvers
Application version.
Dynamic_Array< int > lmap
Array of mapped fields.
string dtos(double f)
Convert an floating point number to a string.
ClientInfo linfo
Structure containing client informations.
bool Types2MYSQL(Types &type, enum_field_types &mtype)
Convert a MCS type into a MySQL type.
vector< string > values
Internal vector containing values names.
string sslcert
Path to the SSL certificate file, used if cl_use_ssl = 1.
bool lisunsigned
Base type is unsigned.
static const char * dafmt
Format to handle date in sprintf/sscanf calls.
bool cl_custom_auth
Activate custom authentication.
unsigned int lsize
Size of the actual chunk.
bool mkDir(string path, mode_t perm=0, enum ThrowExceptions throwexc=THROW)
Create a directory.
bool freeAfterUse
If true the external buffer will be automatically freed, used when type = MCS_SERIAL_BUFFER.
int count()
Returns number of elements in the array.
Manage TCP server sockets.
bool named
If it is a named pipe (a FIFO file) or not.
string filename
Filename of the file being sent, if type = MCS_SERIAL_FILENAME.
int Count
How many time the Mutex has been locked, or a thread entered a critical section.
fd_set fds
Set of socket file descriptors, used with select().
bool cl_work
Use private (per user) working dir, otherwise use path.
Retrieve informations about a network host.
#define MCS_DEFAULT_CLIENT_TIMEOUT
Default client connection timeout, in milliseconds: 10 minutes.
unsigned int blocksout
Blocks of base64 data already written.
string localhost
Host name.
unsigned int bufsize
Size of allocated buffer.
Synchro synchro
To protect the filecount variable.
Record aux
Record containing all auxiliary fields sent by the server.
Dynamic_Array< Data > array
Array of fields.
unsigned int lpos
Current position in the recordset.
Namespace for MCS library.
MYSQL_BIND * lbparam
Record of binding structure for input (parameters).
bool lfetch
If true the fetch mechanism will be used.
Types
Enumeration of base type for Data.
int id_dest
The userid of the thread that will receive this object.
Record lparam
Record of binded Data objects for input (parameters).