MCS  0.3.3-alpha7
mcs.hh
Go to the documentation of this file.
1 // ----------------------------------------------------------------------^
2 // Copyright (C) 2004 -- 2011, Giorgio Calderone
3 // (mailto: <gcalderone@ifc.inaf.it>)
4 //
5 // This file is part of MCS.
6 //
7 // MCS is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // MCS is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with MCS; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 // ----------------------------------------------------------------------$
22 
23 
24 
32 #ifndef DEF_MCS_HH
33 #define DEF_MCS_HH
34 
35 
36 //The symbol COMPILING_MCS is defined when we are compiling the MCS library
37 #undef COMPILING_MCS
38 #ifdef HAVE_CONFIG_H
39  //We are compiling the MCS library
40 #define COMPILING_MCS
41 #else
42  //We are compiling a MCS-based program
43 #endif //HAVE_CONFIG_H
44 
45 
46 
47 //We need the following includes only when compiling the MCS library
48 #ifdef COMPILING_MCS
49 //--------------------------------------------------------------------
50 //System's library include
51 
52 //Portability with old libc
53 // LN
54 #ifndef __APPLE__
55 #include <wait.h>
56 #endif
57 
58 #include <sys/stat.h>
59 #include <math.h>
60 #include <stdint.h>
61 #include <stdarg.h>
62 #include <dirent.h>
63 #include <pthread.h>
64 #include <errno.h>
65 #include <arpa/inet.h>
66 #include <net/if.h>
67 #include <sys/ioctl.h>
68 #include <sys/time.h>
69 #include <sys/types.h>
70 #include <sys/socket.h>
71 #include <netdb.h>
72 #include <fcntl.h>
73 
74 //Portability with old libc
75 #include <unistd.h>
76 
77 #include <fstream>
78 #endif //COMPILING_MCS
79 
80 
81 //The following include is necessary for some network related type
82 #include <netinet/in.h>
83 
84 
85 //The following includes are probably needed by user programs, so we
86 //include them here instead of in the "COMPILING_MCS" section.
87 #include <string>
88 #include <iostream>
89 #include <vector>
90 using namespace std;
91 
92 //#include <stdlib.h>
93 #include <cstdlib>
94 
95 //LN
96 #include <cstdio>
97 #include <cstring>
98 
99 
100 
101 
102 //--------------------------------------------------------------------
103 //MCS configuration file.
104 #include "mcs_config.h"
105 
106 
107 
108 
109 
110 
111 
112 /*Pierre's stuff*/
113 
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"
122 #define BEEP "\x7"
123 #define BGBLUE "\x1B[44m"
124 #define NORMAL "\x1B[0m"
125 #define CLEANS "\x1B[2J"
126 
127 
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"
131 
132 
133 #if ENABLE_MYSQL
134 //--------------------------------------------------------------------
135 //MySQL include, this will be needed by user programs until the
136 //"mysql_stmt_param_metadata" function is available.
137 #include <mysql.h>
138 #define MYSQL_SOCK NULL
139 
140 #else
141 //If MySQL facilities are disabled we need the following declaration to
142 //compile correctly.
143 #define MYSQL_BIND char
144 #define my_bool bool
145 
146 //This has been copied from MySQL's include file mysql_time.h
147 typedef struct st_mysql_time
148 {
149  unsigned int year, month, day, hour, minute, second;
150 } MYSQL_TIME;
151 #endif //ENABLE_MYSQL
152 
153 
154 
155 //OpenSSL include
156 #ifdef HAVE_OPENSSL_SSL_H
157 #include <openssl/ssl.h>
158 #include <openssl/err.h>
159 #endif //HAVE_OPENSSL_SSL_H
160 
161 
162 
163 #ifdef COMPILING_MCS
164 
165 //--------------------------------------------------------------------
166 //PCRE include
167 #include <pcrecpp.h>
168 #endif //COMPILING_MCS
169 
170 
180 namespace mcs
181 {
182 
183 
184 
185 //--------------------------------------------------------------------
186 //MCS constants
187 
189 #define MCS_DEFAULT_PORT 6523
190 
191 
198 #define MCS_DEFAULTCHUNKSIZE 16384
199 
200 
202 #define MCS_DEFAULT_MAX_USERS 100
203 
204 
206 #define MCS_DEFAULT_CLIENT_TIMEOUT 10 * 60 * 1000
207 // min sec msec
208 
210 #define MCS_COMMBUFSIZE 1024
211 
212 
213 
214 #define MCS_SSLCERT "mcscert.pem"
215 #define MCS_SSLPRIV "mcspkey.pem"
216 
217 //Grants constants
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
229 
230 
232 #define MCS_BANNER "\nMy Customizable Server (MCS) ver. " PACKAGE_VERSION "\n"
233 
234 
235 #define MCS_MISSING_COPY_CONSTRUCTOR(CLASS) \
236 CLASS(const CLASS&);
237 
238 
239 #define MCS_MISSING_ASSIGNMENT_OPERATOR(CLASS) \
240 CLASS& operator=(const CLASS&);
241 
242 
247 {
250 };
251 
252 
253 
258 {
261 };
262 
263 
264 
265 
266 //--------------------------------------------------------------------
267 //Protocol Specification:
268 
270 #define MCS_PRE "#"
271 
273 #define MCS_SEP "|"
274 
276 #define MCS_PROMPT_OK MCS_PRE "0--"
277 
279 #define MCS_PROMPT_WARN MCS_PRE "0W-"
280 
282 #define MCS_PROMPT_ERROR MCS_PRE "0E-"
283 
284 
285 //Protocol messages and numeric identifiers
286 #include <mcsmsg.hh>
287 
288 //Protocol commands: (help lines MUST ends on column 93)
289 
291 #define MCS_CMD_NOP "NOP"
292 #define MCS_CMD_NOP_HELP "No operation (dummy) command."
293 
294 
296 #define MCS_CMD_CLIENT_INFO "CLINFO"
297 #define MCS_CMD_CLIENT_INFO_HELP "Return all client informations."
298 
299 
301 #define MCS_CMD_USERNAME "USR"
302 #define MCS_CMD_USERNAME_HELP "Supply user name.\n" \
303  "USR <user_name>"
304 
306 #define MCS_CMD_PASSWORD "PWD"
307 #define MCS_CMD_PASSWORD_HELP "Supply password.\n" \
308  "PWD <password>"
309 
311 #define MCS_CMD_DBNAME "DBN"
312 #define MCS_CMD_DBNAME_HELP "Supply application (database) name.\n" \
313  "DBN <application_name>"
314 
315 
317 #define MCS_CMD_DBCONNECT "CON"
318 #define MCS_CMD_DBCONNECT_HELP "Finalize the authentication process and log in.\n" \
319  "CON"
320 
322 #define MCS_CMD_CLOSECLIENT "BYE"
323 #define MCS_CMD_CLOSECLIENT_HELP "Close the session.\n" \
324  "BYE"
325 
327 #define MCS_CMD_CID "CID"
328 #define MCS_CMD_CID_HELP "Retrieve the Client identifier.\n" \
329  "CID"
330 
331 
332 
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" \
341  "FETCH [position]"
342 
343 
344 #if ENABLE_MYSQL
345 //Commands for DB access
346 
348 #define MCS_CMD_QUERY "QRY"
349 #define MCS_CMD_QUERY_HELP "Execute queries on the database.\n" \
350  "QRY <SQL query>"
351 
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." \
356  "QRES"
357 
358 
360 #define MCS_CMD_TABLELIST "TLIST"
361 #define MCS_CMD_TABLELIST_HELP "Retrieve the list of tables actually present in the\n" \
362  "database.\n" \
363  "TLIST"
364 
366 #define MCS_CMD_TABLEINFO "TINFO"
367 #define MCS_CMD_TABLEINFO_HELP "Retrieve information about a table.\n" \
368  "TINFO"
369 #endif //ENABLE_MYSQL
370 
371 
372 
373 
374 //Options (to be used with "-" like in a shell command)
375 
376 
378 #define MCS_OPT_SAVEQUERYFITS "sqfits"
379 #define MCS_OPT_SAVEQUERYFITS_HELP "Save query result in FITS format.\n " \
380  "-sqfits"
381 
383 #define MCS_OPT_SAVEQUERYASCII "sqascii"
384 #define MCS_OPT_SAVEQUERYASCII_HELP "Save query result in ASCII format.\n" \
385  "-sqascii"
386 
387 
389 #define MCS_OPT_FORCE "force"
390 #define MCS_OPT_FORCE_HELP "Continue execution of commands even if an error\n" \
391  "occurred.\n" \
392  "-force"
393 
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" \
398  "-werr"
399 
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" \
404  "-loop"
405 
407 #define MCS_OPT_HELP "help"
408 
409 
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] ...]"
414 
416 #define MCS_CMD_GET "GET"
417 #define MCS_CMD_GET_HELP "Download a file from the work directory.\n" \
418  "GET <filename>"
419 
421 #define MCS_CMD_PUT "PUT"
422 #define MCS_CMD_PUT_HELP "Upload a file to the work directory.\n" \
423  "PUT <filename> <size>"
424 
426 #define MCS_CMD_GETDATA "GDATA"
427 #define MCS_CMD_GETDATA_HELP "Download Data objects.\n" \
428  "GDATA <position>"
429 
431 #define MCS_CMD_PUTDATA "PDATA"
432 #define MCS_CMD_PUTDATA_HELP "Upload Data objects.\n" \
433  "PDATA <size>"
434 
435 
436 
437 
438 
439 //--------------------------------------------------------------------
440 //MCS enumerations
441 
471 enum RetValue {
472  OK,
476 };
477 
478 
479 #include "mcstypes.hh"
480 
481 
482 //--------------------------------------------------------------------
483 //MCS macro facilities
484 
486 #define csz c_str()
487 
488 
490 #define my_mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
491 
492 
493 
494 
495 //--------------------------------------------------------------------
496 //MCS utilities functions
497 
499 #define MCS_SUBST_QUOTE_WITH 1
500 
502 #define MCS_SUBST_LEADING 4
503 
505 #define MCS_SUBST_TRAILING 8
506 
515 string subst(string s, string what, string with, int op = 0);
516 
517 
519 string trim(string s);
520 
522 string chomp(string s);
523 
525 string remTabs(string s);
526 
528 string remLeading(string& s, const char* p);
529 
531 string remTrailing(string& s, const char* p);
532 
540 vector<string> split(string s, string sep = " ");
541 
543 int extractCode(const char* msg);
544 
553 bool File_Dir_Exist(string fn, unsigned int& size);
554 
556 string itos(int i);
557 
558 
568 int stoi(string s);
569 
580 int stoi(string s, int errval);
581 
582 
584 string btos(bool b);
585 
587 string vtos(vector<string> vec);
588 
590 string dtos(double f);
591 
593 string Pwd();
594 
596 string hexDump(const void* buf, unsigned int size);
597 
598 
599 #define MCS_MKDIR_UMASK 0
600 #define MCS_MKDIR_PROTECT S_IRUSR | S_IWUSR | S_IXUSR
601 
603 bool mkDir(string path, mode_t perm = 0, enum ThrowExceptions throwexc = THROW);
604 
605 
607 mode_t read_umask();
608 
610 bool rmDir(string path, enum ThrowExceptions throwexc = THROW);
611 
612 class Record;
613 
615 void ls2Record(string fn, Record& v);
616 
618 string Types2Str(Types type, bool isunsigned);
619 
621 bool VarLenType(Types type);
622 
624 bool IntType(Types type);
625 
627 bool FloatType(Types type);
628 
640 int copy(char* OLDNAME, char* NEWNAME);
641 
655 int move(char* OLDNAME, char* NEWNAME);
656 
657 
658 #if ENABLE_MYSQL
659 string MYSQL2Str(enum_field_types type);
661 
662 
670 bool MYSQL2Types(enum_field_types mtype, Types& type);
671 
679 bool Types2MYSQL(Types& type, enum_field_types& mtype);
680 
688 string Types2MYSQLStr(Types& type, bool isunsigned);
689 
690 #endif //ENABLE_MYSQL
691 
692 
693 #if ENABLE_CFITSIO
694 
701 bool FITS2Types(int fits, Types& dbt, bool& isunsigned);
702 
710 bool Types2FITS(Types dbt, bool isunsigned, int& fits);
711 
719 bool Types2S_FITS(Types dbt, int len, bool isunsigned, string& fits);
720 
721 
723 string fitsError(int status);
724 #endif //ENABLE_CFITSIO
725 
726 
727 
728 //--------------------------------------------------------------------
730 #define MCS_VMSG_SIZE 1000
731 
814 class Event
815 {
816 private:
818  string latFile;
819 
821  int latLine;
822 
824  char buf[MCS_COMMBUFSIZE];
825 
827  string lmsg;
828 
830  int lcode;
831 
833  int lsubcode;
834 
837 
838  friend class UserThread;
839 
841  static const char* vmsg[MCS_VMSG_SIZE];
842 
844  static void init_vmsg();
845 
847  static bool flInitialized;
848 
849  void init(string atFile, unsigned int atLine, RetValue type, int code);
850 
851 public:
853  static void (*custom_init_vmsg) (const char* vmsg[MCS_VMSG_SIZE]);
854 
868  Event(string atFile, unsigned int atLine, RetValue type, int code,
869  string s1 = "", string s2 = "", string s3 = "");
870 
878  Event(string atFile, unsigned int atLine, RetValue type, int code,
879  string s1, int i1);
880 
888  Event(string atFile, unsigned int atLine, RetValue type, int code,
889  int i1, string s1 = "");
890 
891 
899  Event(string atFile, unsigned int atLine, RetValue type, int code,
900  int i1, int i2);
901 
903  ~Event();
904 
906  string msg();
907 
909  string where();
910 
912  int code();
913 
915  int subcode();
916 
937  Event& subcode(int subcode);
938 
941  string codemsg();
942 
944  string file();
945 
947  unsigned int line();
948 
950  RetValue type();
951 
953  static string static_vmsg(unsigned int i);
954 };
955 
956 
958 #define MCS_OK(A, rest...) mcs::Event(__FILE__, __LINE__, mcs::OK, A, ## rest)
959 
961 #define MCS_WARN(A, rest...) mcs::Event(__FILE__, __LINE__, mcs::WARN, A, ## rest)
962 
964 #define MCS_ERROR(A, rest...) mcs::Event(__FILE__, __LINE__, mcs::ERROR, A, ## rest)
965 
967 #define MCS_FATAL(A, rest...) mcs::Event(__FILE__, __LINE__, mcs::FATAL, A, ## rest)
968 
970 #define MCS_(TYPE, rest...) mcs::Event(__FILE__, __LINE__, TYPE , ## rest)
971 
972 
973 #ifndef DOXYGEN_SKIP
974 //--------------------------------------------------------------------
975 //MCS macro facilities for debug, see also the Debug class
976 #ifndef NOARGS
977 #define NOARGS
978 #endif //NOARGS
979 
980 #define MCS_DEBUG_ALLOC
981 #define MCS_DEBUG_SETUP(A, B)
982 #define MCS_DEBUG(A)
983 #define MCS_DEBUG_ENTER(A)
984 #define MCS_DEBUG_LEAVE(A)
985 
986 #if ENABLE_DEBUG
987 #undef MCS_DEBUG_ALLOC
988 #undef MCS_DEBUG_SETUP
989 #undef MCS_DEBUG
990 #undef MCS_DEBUG_ENTER
991 #undef MCS_DEBUG_LEAVE
992 
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);
998 
999 #define MCS_DEBUG_NTHR 100
1000 
1001 class Debug
1002 {
1003 private:
1004  bool active;
1005  string className;
1006  void* pThis;
1007 
1008  static pthread_t thrs[MCS_DEBUG_NTHR];
1009  static bool thrmap[MCS_DEBUG_NTHR];
1010  static int dummy;
1011  static int init();
1012 
1013 public:
1014  Debug();
1015  ~Debug();
1016 
1017  string debug(const char* file, int line, const char* function);
1018 
1019  void setDebug(string className, void* pthis = 0, bool active = false);
1020  void setDebug();
1021  bool getDebugFlag();
1022 };
1023 #endif //ENABLE_DEBUG
1024 #endif //DOXYGEN_SKIP
1025 
1026 
1027 
1028 
1029 
1030 
1095 class Buffer {
1096 private:
1098  char* buf;
1099 
1101  unsigned int bufsize;
1102 
1104  enum BufferFreeOnDestroy freebuffer;
1105 
1108 
1110  bool select;
1111 
1113  unsigned int wstart;
1114 
1116  unsigned int wlen;
1117 
1118 public:
1125  Buffer(enum BufferFreeOnDestroy freeBuffer = AUTO_FREE);
1126 
1133  Buffer(void* extbuf, unsigned int size,
1134  enum BufferFreeOnDestroy freeBuffer = DONT_FREE);
1135 
1142  MCS_MISSING_COPY_CONSTRUCTOR(Buffer);
1143 
1144 
1151  MCS_MISSING_ASSIGNMENT_OPERATOR(Buffer);
1152 
1154  ~Buffer();
1155 
1156 
1157  void set(void* extbuf, unsigned int size, enum BufferFreeOnDestroy freeBuffer);
1158 
1159 
1171  Buffer& operator()(unsigned int start, unsigned int len);
1172 
1173 
1182  Buffer& operator()(unsigned int len);
1183 
1184 
1193  Buffer& operator<<(const void* extbuf);
1194 
1195  Buffer& operator<<(istream& stream);
1196 
1206  Buffer& operator>>(void* extbuf);
1207 
1208  Buffer& operator>>(ostream& stream);
1209 
1210  operator void*() const { return buf; }
1211 
1212 
1214  char* operator[](unsigned int pos);
1215 
1216 
1224  void free();
1225 
1226 
1242  void resize(unsigned int size);
1243 
1245  unsigned int size();
1246 };
1247 
1248 
1249 
1250 
1251 
1252 
1253 
1254 
1255 
1256 
1257 
1258 
1259 
1260 
1261 
1262 
1263 
1264 
1265 #define MCS_SERIAL_UNKNOWN 0
1266 #define MCS_SERIAL_BUFFER 1
1267 #define MCS_SERIAL_FILENAME 2
1268 
1269 //--------------------------------------------------------------------
1270 //MCS Serializable class
1291 {
1292 private:
1293  MCS_DEBUG_ALLOC;
1294 
1296  char* buf;
1297 
1299  unsigned int maxChunksize;
1300 
1302  unsigned int lsize;
1303 
1305  string filename;
1306 
1308  int type;
1309 
1311  char* from;
1312 
1318 
1320  ifstream* stream;
1321 
1327  void init(int type, unsigned int lmaxChunksize);
1328 
1329  char* userdata; //To be used with virtual_nextChunk
1330 
1331  bool firstTime; //To be used with virtual_nextChunk
1332 
1344  virtual char* nextChunk_unknown(char* userdata, char* buf,
1345  unsigned int& chunksize, bool firstTime);
1346 
1347  virtual char* serialize_unknown();
1348 
1349  virtual bool serialize_buffer(char*& from, unsigned int& size);
1350 
1351  virtual string serialize_filename();
1352 
1353  void serialize();
1354 
1355  void serialize_end();
1356 
1357 public:
1364  MCS_MISSING_COPY_CONSTRUCTOR(Serializable);
1365 
1366 
1373  MCS_MISSING_ASSIGNMENT_OPERATOR(Serializable);
1374 
1381  Serializable(unsigned int lmaxChunksize = MCS_DEFAULTCHUNKSIZE);
1382 
1383 
1392  Serializable(void* from, unsigned int size, bool freeAfterUse,
1393  unsigned int lmaxChunksize = MCS_DEFAULTCHUNKSIZE);
1394 
1395 
1403  Serializable(string filename, unsigned int lmaxChunksize = MCS_DEFAULTCHUNKSIZE);
1404 
1405  Serializable(int type, unsigned int lmaxChunksize = MCS_DEFAULTCHUNKSIZE);
1406 
1410  virtual ~Serializable();
1411 
1412 
1413 // /*!
1414 // \brief Fills a buffer with next chunk to be sent.
1415 //
1416 // \param chunksize Upon exit contains the size of the chunk.
1417 // \return Address of the buffer containing the chunk, or NULL if there are
1418 // no more data.
1419 // */
1420 // char* fillBuffer(unsigned int& chunksize);
1421 
1422  void* nextChunk(unsigned int& chunksize);
1423 
1424  void* getEntireBuffer(unsigned int& size);
1425 
1427  unsigned int maxChunkSize();
1428 
1429 
1430 // /*!
1431 // \brief Reinitialize internal data.
1432 //
1433 // Reinitialize internal data, so that next call to fillBuffer() will read
1434 // data from the beginning of the buffer or the file. If type =
1435 // SERIAL_UNKNOWN the next call to fillBuffer will have firstTime =
1436 // true.
1437 // */
1438 // void abort();
1439 
1440 
1441 // /*!
1442 // \brief Tells if the object is in use.
1443 //
1444 // If a call to fillBuffer() has already be done, and data are not yet
1445 // finished this will return true. Otherwise return false.
1446 // */
1447 // bool inUse();
1448 
1449 
1457  bool knowSize();
1458 
1463  unsigned int nChunk();
1464 
1465 
1470  unsigned int size();
1471 };
1472 
1473 
1474 
1475 
1476 
1477 
1478 
1479 //--------------------------------------------------------------------
1488 {
1489 protected:
1490  unsigned int lindex;
1491 
1492  int req(int ioctl_num, struct ifreq *ifr);
1493  int getflags();
1494  bool isup();
1495  void str_sockaddr(struct sockaddr* sa);
1496  void str_sockaddr_in(struct sockaddr_in* sin);
1497 
1499  vector<string> names;
1500 
1501 public:
1516 //LN-darwin
1517 #ifdef __APPLE__
1518  NetInterface(string name = "lo0");
1519 #else
1520  NetInterface(string name = "lo");
1521 #endif
1522 
1523 //NetInterface(string name = "127.0.0.1");
1524 
1526  ~NetInterface();
1527 
1534  MCS_MISSING_COPY_CONSTRUCTOR(NetInterface);
1535 
1541  MCS_MISSING_ASSIGNMENT_OPERATOR(NetInterface);
1542 
1553  string name(int index = -1);
1554 
1556  unsigned int index();
1557 
1559  unsigned int count();
1560 
1571  string ipaddress(int index = -1);
1572 };
1573 
1574 
1575 
1576 
1577 
1578 
1579 
1580 //--------------------------------------------------------------------
1589 {
1590 protected:
1591  struct sockaddr_in sin;
1592  string host;
1593  string ipaddr;
1594  void populate_sockaddr_in();
1595 
1596 public:
1603  MCS_MISSING_COPY_CONSTRUCTOR(HostInfo);
1604 
1610  MCS_MISSING_ASSIGNMENT_OPERATOR(HostInfo);
1611 
1622  HostInfo(string host);
1623 
1629  HostInfo(int sockfd);
1630 
1632  ~HostInfo();
1633 
1635  string hostname();
1636 
1638  string ipaddress();
1639 };
1640 
1641 
1642 
1643 
1644 
1645 
1646 //--------------------------------------------------------------------
1662 class Socket : public HostInfo
1663 {
1664 private:
1665  MCS_DEBUG_ALLOC;
1666 
1668  int sockfd;
1669 
1671  fd_set fds;
1672 
1673 #ifdef HAVE_OPENSSL_SSL_H
1674  SSL_CTX* ssl_ctx;
1676 
1678  SSL *ssl;
1679 
1681  BIO *sbio;
1682 
1683  void initialize_ssl_bio(string keyfile);
1684 #endif //HAVE_OPENSSL_SSL_H
1685 
1687  unsigned short int port;
1688 
1690  bool use_ssl;
1691 
1693  struct timeval readto;
1694 
1696  struct timeval writeto;
1697 
1712  int socketToHost(unsigned short port);
1713 
1714 
1728  void sendChunk(void* buf, unsigned int size);
1729 
1730 
1746  unsigned int recvChunk(void* buf, unsigned int size);
1747 
1753  unsigned int recvChunk(Buffer* buf);
1754 
1755 protected:
1773  bool chkSend(enum ThrowExceptions throwexc = THROW);
1774 
1775 
1799  bool chkRecv(bool chkDataAvailable = false, enum ThrowExceptions throwexc = THROW);
1800 
1801 
1802 
1803 
1804 public:
1811  MCS_MISSING_COPY_CONSTRUCTOR(Socket);
1812 
1818  MCS_MISSING_ASSIGNMENT_OPERATOR(Socket);
1819 
1834  Socket(string host, unsigned short int port=0,
1835  unsigned int readTimeout = 1000,
1836  unsigned int writeTimeout = 1000,
1837  bool ssl = false);
1838 
1839 
1853  Socket(int sockfd,
1854  unsigned int readTimeout = 1000,
1855  unsigned int writeTimeout = 1000,
1856  void* ssl_ctx = NULL);
1857 
1858 
1865  ~Socket();
1866 
1868  void Close();
1869 
1876  static void set_struct_timeval(unsigned int millisec, struct timeval* time);
1877 
1878 
1893  unsigned int read(void* buf, unsigned int count);
1894 
1895 
1909  unsigned int write(void* buf, unsigned int count);
1910 
1911 
1922  string getline();
1923 
1924 
1935  void print(string s);
1936 
1937 
1945  void sendData(Serializable* from);
1946 
1947 
1967  unsigned int recvData(char** buffer, unsigned int maxsize);
1968 
1969 
1979  unsigned int recvData(string filename);
1980 
1989  unsigned int recvData(int filedes);
1990 
1999  unsigned int recvData(ofstream& stream);
2000 };
2001 
2002 
2003 
2004 
2005 
2006 //--------------------------------------------------------------------
2016 {
2017 private:
2019  int sockfd;
2020 
2022  bool use_ssl;
2023 
2024 #ifdef HAVE_OPENSSL_SSL_H
2025  SSL_CTX* ssl_ctx;
2027 #endif //HAVE_OPENSSL_SSL_H
2028 
2029 public:
2036  MCS_MISSING_COPY_CONSTRUCTOR(ServerSocket);
2037 
2044  MCS_MISSING_ASSIGNMENT_OPERATOR(ServerSocket);
2045 
2059  ServerSocket(string interface, unsigned short int port,
2060  bool use_ssl = false, string sslcert = "", string sslpriv = "");
2061 
2063  ~ServerSocket();
2064 
2077  bool acceptConnection(int& newsock, unsigned int millisec);
2078 
2079  void* getSSLContext();
2080 };
2081 
2082 
2083 
2084 
2085 
2086 //--------------------------------------------------------------------
2187 class Synchro
2188 {
2189 private:
2190 
2191  // MCS_DEBUG_ALLOC;
2192 
2193 //LN-darwin
2194 #if defined(_POSIX_TIMEOUTS) && (_POSIX_TIMEOUTS - 200112L) >= 0L
2195 /* POSIX Timeouts are supported - option group [TMO] */
2196 
2198  // struct _pthread_cleanup_buffer _buf;
2199 #endif
2200 
2202  pthread_mutex_t mutex;
2203 
2205  pthread_mutexattr_t attr;
2206 
2208  int Count;
2209 
2211  bool isActive;
2212 
2213 public:
2220  MCS_MISSING_COPY_CONSTRUCTOR(Synchro);
2221 
2228  MCS_MISSING_ASSIGNMENT_OPERATOR(Synchro);
2229 
2239  Synchro();
2240 
2244  ~Synchro();
2245 
2256  void synchronize(bool setactive);
2257 
2259 #define MCS_SYNCHRO_LOCK 1
2260 
2262 #define MCS_SYNCHRO_TRY_LOCK 2
2263 
2266 #define MCS_SYNCHRO_TRY_TIMED 3
2267 
2301  bool enter(int op = MCS_SYNCHRO_LOCK, unsigned int timeout = 0);
2302 
2305  bool tryenter(unsigned int timeout = 0);
2306 
2308  int count();
2309 
2319  int leave();
2320 
2321 #ifdef ENABLE_CLEANUP_HANDLERS
2322 
2330  static void CH_leave(void* This);
2331 #endif //ENABLE_CLEANUP_HANDLERS
2332 
2334  // \brief Waits until some other thread locks and unlocks the same
2335  // Synchro object.
2336  //
2337  // The mutex MUST be locked before using wait() (with enter()) and unlocked
2338  // after this method returns (with leave()).
2339  //
2340  // When this method is called it immediately unlock the mutex, so
2341  // that another thread can lock it.
2342  //
2343  // If it return true then another thread has locked and unlocked the same
2344  // Synchro object, if it returns false a timeout occurred before other
2345  // threads can lock and unlock the mutex. in any case the mutex is now locked
2346  // by the current thread, so you have to unlock it with leave().
2347  //
2348  // An example follows:
2349  // \code
2350  // ...
2351  // enter();
2352  // bool b = wait(1000); //Leaving the critical section and wait
2353  // //for someone else to lock and unlock the
2354  // //same Synchro object, or a timeout of 1
2355  // //second occur.
2356  //
2357  // if (b) { //Another thread entered and leave a critical section
2358  // ... //Do some work
2359  // }
2360  // else { //A timeout occurred
2361  // ...
2362  // }
2363  // leave();
2364  // \endcode
2365  //
2366  // \param timeout Timeout in millisecond.
2367  // \return False if a timeout or an interrupt occurred, true otherwise.
2368  //*/
2370 };
2371 
2372 
2375 #define MCS_CRITICAL_SECTION_BEGIN enter(); try {
2376 
2377 
2380 #define MCS_CRITICAL_SECTION_END } catch(Event e) { leave(); throw e; } leave();
2381 
2382 #define MCS_CRITICAL_SECTION_END_RETURN(What...) \
2383 leave(); return What; } \
2384 catch(Event e) { leave(); throw e; }
2385 
2386 
2393 #define MCS_CRITICAL_SECTION(BLOCK...) \
2394 MCS_CRITICAL_SECTION_BEGIN \
2395  BLOCK; \
2396 MCS_CRITICAL_SECTION_END
2397 
2398 
2399 
2400 
2401 
2402 
2403 
2404 //--------------------------------------------------------------------
2406 #define MCS_STATE_CREATED 1
2407 
2409 #define MCS_STATE_RUNNING 2
2410 
2413 #define MCS_STATE_TERMINATING 3
2414 
2416 #define MCS_STATE_END 4
2417 
2418 
2419 
2487 class Thread
2488 {
2489 private:
2490 
2491  // MCS_DEBUG_ALLOC;
2492 
2493  static void* RunThread(void* args);
2494 
2497 
2499  pthread_t lthrID;
2500 
2502  int lid;
2503 
2505  int lstate;
2506 
2507  //Synchronization for lstate variable.
2508  // Synchro syn_lstate;
2509 
2516  static void cleanup_Handler(void* This);
2517 
2524  bool checkTerminating();
2526 
2528  bool detached;
2529 
2533 
2534 protected:
2558  virtual void notify(int id, Thread* ref);
2559 
2560 
2571  virtual void initial();
2572 
2573 
2589  virtual void final();
2590 
2591 
2601  virtual void run();
2602 
2606  void set_cancel_state(bool cancel);
2607 
2611  void test_cancel();
2612 
2615 
2616 public:
2618  Event* error();
2619 
2627  // MCS_MISSING_COPY_CONSTRUCTOR(Thread);
2628 
2637  // MCS_MISSING_ASSIGNMENT_OPERATOR(Thread);
2638 
2649  Thread(int id = 0, Thread* parent = NULL);
2650 
2662  virtual ~Thread();
2663 
2675  void start();
2676 
2677 
2692  void startDetached(bool selfDelete = false);
2693 
2694 
2704  void stop();
2705 
2714  int id();
2715 
2719  Thread* parent();
2720 
2721 
2733  int state();
2734 };
2735 
2736 
2737 
2738 template<class BASE>
2740 {
2741 private:
2742  pthread_key_t key;
2743  int ltag;
2744 
2745  static void generic_destructor(void* p)
2746  { delete ((BASE*) p); }
2747 
2748  void (*destructor)(void*);
2749 
2750 public:
2751  ThreadSpecificData(void (*ext_destructor)(void*) = NULL)
2752  {
2753  destructor = generic_destructor;
2754  if (ext_destructor)
2755  destructor = ext_destructor;
2756 
2757  pthread_key_create(&key, destructor);
2758  }
2759 
2761  { pthread_key_delete(key); }
2762 
2763  void clear()
2764  {
2765  void* p = getp();
2766  if (p)
2767  (destructor)(p);
2768 
2769  pthread_setspecific(key, NULL);
2770  }
2771 
2772  void init(BASE* p = NULL, int tag = 0)
2773  {
2774  clear();
2775 
2776  if (! p)
2777  p = new BASE();
2778 
2779  pthread_setspecific(key, p);
2780  ltag = tag;
2781  }
2782 
2783  int tag()
2784  { return ltag; }
2785 
2786  BASE* operator->() const
2787  { return ((BASE*) pthread_getspecific(key)); }
2788 
2789  BASE* getp()
2790  { return ((BASE*) pthread_getspecific(key)); }
2791 };
2792 
2793 
2794 
2795 
2796 
2797 class ThreadFunc : public Thread
2798 {
2799 private:
2800  int (*start_routine1)(void*);
2801  Event* (*start_routine2)(void*);
2802  void* arg;
2803  int ret;
2804 
2805  void run();
2806 
2807 public:
2809  ThreadFunc(int (*start_routine)(void*), void* arg);
2810  ThreadFunc(Event* (*start_routine)(void*), void* arg);
2811 
2812  int retcode();
2813 };
2814 
2815 
2816 
2823 void sleep_ms(unsigned int millisec);
2824 
2825 
2826 
2833 enum TimeMode {
2834  UTC,
2835  LOCAL
2836 };
2837 
2838 
2839 
2840 
2841 
2842 time_t my_timelocal(struct tm* tm);
2843 
2844 
2845 
2846 
2865 class DateTime {
2866 
2867 private:
2869  time_t time;
2870 
2872  enum TimeMode timemode;
2873 
2875  MYSQL_TIME* mysql;
2876 
2889  static const char* parseTime(const char* s, struct tm* tm);
2890 
2891 
2893  void to_MYSQL_TIME();
2894 
2895 
2903  time_t getTime() const;
2904 
2905 
2906 public:
2908  DateTime();
2909 
2917  void setMysqlBuffer(MYSQL_TIME* mysql);
2918 
2933  void setTimeMode(enum TimeMode tm);
2934 
2935 
2937  void now();
2938 
2939 
2941  void settval(time_t t);
2942 
2944  DateTime& operator=(time_t t)
2945  { settval(t); return *this; }
2946 
2947 
2951  void setsval(string s);
2952 
2954  DateTime& operator=(string s)
2955  { setsval(s); return *this; }
2956 
2972  void settmval(struct tm& ltm);
2973 
2975  DateTime& operator=(struct tm& ltm)
2976  { settmval(ltm); return *this; }
2977 
2978 
2980  time_t tval() const;
2981 
2983  operator time_t() const
2984  { return tval(); }
2985 
2986 
2988  struct tm tmval() const;
2989 
2991  operator struct tm() const
2992  { return tmval(); }
2993 
2995  string sval() const;
2996 
2998  operator string() const
2999  { return sval(); }
3000 };
3001 
3002 
3003 
3004 #define MCS_ID_UNKNOWN -1
3005 #define MCS_ID_LOCAL -2
3006 #define MCS_ID_CLIENT -3
3007 
3008 
3009 // Another wide use of the Data class is to to set/retrieve data of
3010 // prepared statement executions on the database. The Query class has
3011 // two fundamental methods that returns address of Data objects:
3012 // param() (to input data on prepared statement) and field() (to
3013 // retrieve data from an executed query on the database.
3014 
3015 
3016 
3017 //Max number of dimensions in a Data multi-dimensional array. Note
3018 //that this number influences the declaration and implementation of
3019 //Data::array and Data::operator=.
3020 #define MCS_DATA_NDIM 15
3021 
3022 
3023 
3024 //--------------------------------------------------------------------
3092 class Data : public Serializable
3093 {
3094 private:
3095  MCS_DEBUG_ALLOC;
3096 
3097  void reallocBuffer();
3098 
3099 #if ENABLE_MYSQL
3100  MYSQL_BIND* lbind;
3102 #endif
3103 
3106 
3108  string lname;
3109 
3111  unsigned int lflags;
3112 
3115  unsigned short int lmaxlength;
3116 
3121  unsigned long llength;
3122 
3125 
3127  my_bool lisnull;
3128 
3131 
3133  unsigned char tag;
3134 
3136  char* buf;
3137 
3139  unsigned int bufsize;
3140 
3142  static const char* dtfmt;
3143 
3145  static const char* dafmt;
3146 
3148  static const char* tmfmt;
3149 
3151  static const char* ifmt;
3152 
3154  static const char* lfmt;
3155 
3157  static const char* ffmt;
3158 
3160  static const char* dfmt;
3161 
3162  DateTime dt;
3163 
3164 
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);
3169 
3171  //void MySQL_TIME_2_time_t(MYSQL_TIME* mtime, time_t* t);
3172  //
3174  //void time_t_2_MySQL_TIME(time_t* t, MYSQL_TIME* mtime);
3175 
3193  bool serialize_buffer(char*& from, unsigned int& size);
3194 
3197 
3199  int id_dest;
3200 
3206  unsigned char ldimspec;
3207 
3209  unsigned short int ldim[MCS_DATA_NDIM];
3210 
3212  unsigned short int mult[MCS_DATA_NDIM];
3213 
3215  unsigned int arrsize;
3216 
3218  unsigned int arrpos;
3219 
3220 public:
3222  unsigned int objSize();
3223 
3224 
3226  Data();
3227 
3229  Data(const Data& from);
3230 
3231 
3247  Data(Types type, unsigned short int maxLength = 0,
3248  bool isunsigned = false, string dimSpec = "");
3249 
3250 
3273  Data(MYSQL_BIND* bind = NULL, Types type = STRING,
3274  const char* name="", unsigned short int maxLength=0,
3275  bool isunsigned=false, unsigned int flags = 0,
3276  unsigned char tag = 0);
3277 
3278 
3285  Data(int v, unsigned char tag = 0);
3286 
3293  Data(long long int v, unsigned char tag = 0);
3294 
3301  Data(double v, unsigned char tag = 0);
3302 
3311  Data(string v, unsigned char tag = 0);
3312 
3319  Data(struct tm v, unsigned char tag = 0);
3320 
3327  Data(time_t v, unsigned char tag = 0);
3328 
3340  Data(void* lbuf, unsigned int size, unsigned char tag = 0);
3341 
3342 
3350  Data(void* lbuf);
3351 
3353  ~Data();
3354 
3361  void emptyName();
3362 
3363 
3365  string name();
3366 
3367  //Set the name of the object.
3368  void setName(string name);
3369 
3371  //unsigned int flags();
3372 
3374  Types type();
3375 
3377  unsigned short int maxLength();
3378 
3380  unsigned short int length();
3381 
3383  bool isUnsigned();
3384 
3386  bool isNull();
3387 
3389  bool isAutoIncrement();
3390 
3392  void* buffer() const;
3393 
3400  int ival() const;
3401 
3408  unsigned int uival() const;
3409 
3416  long long int lval() const;
3417 
3424  unsigned long long int ulval() const;
3425 
3432  float fval() const;
3433 
3440  double dval() const;
3441 
3448  string sval(bool addWhiteSpaces = false) const;
3449 
3461  int cval(char* c, int maxlength) const;
3462 
3466  time_t tval() const;
3467 
3475  void tval(struct tm* t) const;
3476 
3477 
3478  void* pval() const;
3479 
3480  void setpval(void* p);
3481 
3482 
3484  void setNull(bool null = true);
3485 
3487  void setival(int v);
3488 
3490  void setuival(unsigned int v);
3491 
3493  void setlval(long long int v);
3494 
3496  void setulval(unsigned long long int v);
3497 
3499  void setdval(double v);
3500 
3502  void setcval(const char* v);
3503 
3505  void setsval(string v);
3506 
3508  void setblob(void* lbuf, unsigned int size);
3509 
3511  void settimeval(struct tm v);
3512 
3514  void settimeval(time_t v);
3515 
3517  void settimenow();
3518 
3519  void setTimeMode(enum TimeMode tm);
3520 
3521  //Wrapper to setsval(int).
3522  //void setval(string v);
3523 
3524  //Wrapper to setival(int).
3525  //void setval(int v);
3526 
3527  //Wrapper to setdval(int).
3528  //void setval(double v);
3529 
3530  //Wrapper to setcval(int).
3531  //void setval(const char* v);
3532 
3559  void resize(string dimSpec);
3560 
3572  void resizeVaryingDim(unsigned short int newsize);
3573 
3579  unsigned short int dim(int d);
3580 
3581 
3582  //How many dimensions, 0 means scalar value
3583 
3590  unsigned int howManyDim();
3591 
3601  unsigned int varyingDim();
3602 
3608  unsigned int arraySize();
3609 
3610 
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);
3632 
3636  Data& operator()(const int i1 = 0,
3637  const int i2 = 0,
3638  const int i3 = 0,
3639  const int i4 = 0,
3640  const int i5 = 0,
3641  const int i6 = 0,
3642  const int i7 = 0,
3643  const int i8 = 0,
3644  const int i9 = 0,
3645  const int i10 = 0,
3646  const int i11 = 0,
3647  const int i12 = 0,
3648  const int i13 = 0,
3649  const int i14 = 0,
3650  const int i15 = 0);
3651 
3653  Data& operator=(const int v)
3654  { setival(v); return *this; }
3655 
3657  Data& operator=(const unsigned int v)
3658  { setuival(v); return *this; }
3659 
3661  Data& operator=(const long long int v)
3662  { setlval(v); return *this; }
3663 
3665  Data& operator=(const unsigned long long int v)
3666  { setulval(v); return *this; }
3667 
3669  Data& operator=(const double v)
3670  { setdval(v); return *this; }
3671 
3673  Data& operator=(const char* v)
3674  { setsval(v); return *this; }
3675 
3677  Data& operator=(const string v)
3678  { setsval(v); return *this; }
3679 
3681  Data& operator=(const struct tm v)
3682  { settimeval(v); return *this; }
3683 
3685  Data& operator=(const time_t v)
3686  { settimeval(v); return *this; }
3687 
3689  operator const int () const { return ival (); }
3690 
3692  operator const unsigned int () const { return uival (); }
3693 
3695  operator const long long int () const { return lval (); }
3696 
3698  operator const unsigned long long int () const { return ulval (); }
3699 
3701  operator const float () const { return dval (); }
3702 
3704  operator const double () const { return dval (); }
3705 
3707  operator const char* () const { return (char*) pval(); }
3708 
3710  operator const string () const { return sval (); }
3711 
3713  operator const struct tm () const { struct tm v; tval(&v); return v; }
3714 
3716  operator const time_t () const { return tval (); }
3717 
3718 
3730  Data& operator=(Data& d);
3731 
3733  //static void default_struct_tm(struct tm* t);
3734 
3750  static void parseTime(string s, struct tm* ts);
3751 
3766  static long long int MinValue(Types ltype, bool flunsigned);
3767 
3780  static long long int MaxValue(Types ltype, bool flunsigned);
3781 
3783  string print();
3784 
3786  void setTag(unsigned char tag);
3787 
3789  unsigned char getTag();
3790 
3791  int getSourceID();
3792  int getDestID();
3793  void setSourceID(int id);
3794  void setDestID(int id);
3795 };
3796 
3797 
3798 
3800 #define DYNAMIC_ARRAY_DEFAULT_STEP 10
3801 
3802 
3803 
3812 template<class BASE>
3813 class Dynamic_Array : public Synchro {
3814 private:
3816  BASE** arr;
3817 
3820 
3822  int lcount;
3823 
3831  void check_allocation(int count);
3832 
3833 protected:
3834  Dynamic_Array<BASE>& array;
3835 
3836 public:
3842  Dynamic_Array(bool synchro);
3843 
3850  MCS_MISSING_COPY_CONSTRUCTOR(Dynamic_Array);
3851 
3852 
3854  Dynamic_Array& operator=(Dynamic_Array& from);
3855 
3856 
3858  ~Dynamic_Array();
3859 
3865  int count();
3866 
3877  bool ready();
3878 
3908  void push(BASE* d);
3909 
3919  void push(BASE& d);
3920 
3933  BASE pop(int pos = 0);
3934 
3964  BASE& operator[](int pos);
3965 
3979  BASE peek(int pos);
3980 
3986  void clear();
3987 };
3988 
3989 
3990 //Methods implementation of template classes must be in the header file
3991 template<class BASE>
3993  unsigned int size;
3994  static int max_size = Data::MaxValue(SMALL, true);
3995 
3996  if (count >= max_size)
3997  throw MCS_ERROR(MSG_INDEX_OUT_RANGE, count, max_size);
3998 
3999  if (count > (step_alloc * DYNAMIC_ARRAY_DEFAULT_STEP)) {
4000  step_alloc++;
4001  size = sizeof(BASE*) * step_alloc * DYNAMIC_ARRAY_DEFAULT_STEP;
4002 
4003  if (step_alloc == 1) //First allocation
4004  arr = (BASE**) malloc(size);
4005  else
4006  arr = (BASE**) realloc(arr, size);
4007  }
4008 }
4009 
4010 
4011 template<class BASE>
4013  Synchro(), array(*this)
4014 {
4015  synchronize(synchro);
4016  lcount = 0;
4017  step_alloc = 0;
4018  arr = NULL;
4019 }
4020 
4021 
4022 template<class BASE>
4024  clear();
4025 }
4026 
4027 
4028 
4029 template<class BASE>
4032  int i;
4033 
4034  clear();
4035  for (i=0; i<from.count(); i++)
4036  push(from[i]);
4037 
4038  return *this;
4039 }
4040 
4041 
4042 template<class BASE>
4045 
4046  check_allocation(lcount + 1);
4047  arr[lcount++] = d;
4048 
4050 }
4051 
4052 
4053 template<class BASE>
4056 
4057  check_allocation(lcount + 1);
4058  arr[lcount++] = new BASE(d);
4059 
4061 }
4062 
4063 
4064 
4065 //#define EVENT_IS_THROWN(INSTR...)
4066 //try { INSTR;} catch(Event e) { leave(); throw; }
4067 //{ bool _EVENT_IS_THROWN
4068 
4069 
4070 
4071 template<class BASE>
4073  int i;
4074 
4076 
4077  BASE d = BASE(operator[](pos));
4078 
4079  if (pos < lcount) {
4080  delete arr[pos];
4081 
4082  lcount--;
4083  for (i=pos; i<lcount; i++)
4084  arr[i] = arr[i+1];
4085  }
4086 
4087  MCS_CRITICAL_SECTION_END_RETURN(d);
4088 }
4089 
4090 
4091 template<class BASE>
4093  if (pos < 0)
4094  pos += lcount;
4095 
4096  if (pos < 0)
4097  throw MCS_ERROR(MSG_INVALID_POSITION, pos);
4098 
4099  if (pos >= lcount)
4100  throw MCS_ERROR(MSG_INDEX_OUT_RANGE, pos, lcount);
4101 
4102  return *(arr[pos]);
4103 }
4104 
4105 
4106 template<class BASE>
4108 {
4110 
4111  BASE d = operator[](pos);
4112 
4113  MCS_CRITICAL_SECTION_END_RETURN(d);
4114 }
4115 
4116 
4117 template<class BASE>
4119  return lcount;
4120 }
4121 
4122 
4123 template<class BASE>
4125  return (bool) (lcount > 0);
4126 }
4127 
4128 
4129 template<class BASE>
4131  int i;
4132 
4134 
4135  for (i=0; i<lcount; i++)
4136  delete arr[i];
4137 
4138  if (arr) {
4139  free(arr);
4140  arr = NULL;
4141  }
4142 
4143  lcount = 0;
4144  step_alloc = 0;
4145 
4147 }
4148 
4149 
4150 
4151 
4153 //#define MCS_VECTOR_MOVE_TO_END -1
4154 
4170 class Record : public Serializable, public Synchro
4171 {
4172 private:
4173  MCS_DEBUG_ALLOC;
4174 
4177 
4180 
4182  string smap;
4183 
4202  bool serialize_buffer(char*& from, unsigned int& size);
4203 
4204 
4205 
4206 public:
4208  Record(Record& from);
4209 
4211  Record& operator=(Record& from);
4212 
4219  void emptyName();
4220 
4224  void setNull();
4225 
4226 
4228  Record(bool synchro = false);
4229 
4230 
4239  Record(void* lbuf, bool synchro = false);
4240 
4241 
4249  ~Record();
4250 
4252  int count();
4253 
4255  void addField(Data* d);
4256 
4258  void addField(Data& d);
4259 
4268  void addField(string s, char tag = 0);
4269 
4278  void addField(int i, char tag = 0);
4279 
4288  void addField(long long int i, char tag = 0);
4289 
4298  void addField(double f, char tag = 0);
4299 
4300  Data pop(int x = 0);
4301 
4318  int posWhoseNameIs(string name , enum ThrowExceptions throwexc = THROW);
4319 
4320 
4363  void setFieldMap(string s = "");
4364 
4366  void setFieldMap(Record& rec);
4367 
4368  void clear();
4369 
4370 
4384  Data& operator[](string name);
4385 
4386  Data& operator[](int pos);
4387 
4389  Data field(string name);
4390 
4391  Data field(int pos);
4392 
4393 
4395  unsigned int objSize();
4396 
4398  string asString(string sep = "\t");
4399  string asStringNames(string sep = "\t");
4400  string asStringTypes(string sep = "\t");
4401 
4402 
4404  // \brief Move element in the Record from one position to another.
4405  //
4406  // Both indexes must be allowed ones, and "from" must be less than
4407  // "to". All elements after "from" will be shifted one position
4408  // towards the exit of the queue. This is a thread safe method.
4409  //
4410  // \param from Source position;
4411  // \param to Destination position.
4412  //
4413  // \exception ERROR MSG_INDEX_OUT_RANGE.
4414  // */
4415  //void move(int from, int to);
4416 };
4417 
4418 
4419 
4420 
4421 
4422 
4423 
4424 
4425 
4426 
4427 
4437 #define MCS_RS_ACCUM 1
4438 
4439 
4449 #define MCS_RS_USEMETAREC 2
4450 
4457 #define MCS_RS_KNOW_NROWS 4
4458 
4466 #define MCS_RS_RANDOM 8
4467 
4468 
4480 #define MCS_RS_INSERT 16
4481 
4482 
4483 
4484 
4510 class RecordSet {
4511 private:
4513  short int lid;
4514 
4516  unsigned char code;
4517 
4520 
4522  unsigned int lnrows;
4523 
4525  bool laccum;
4526 
4528  bool lrandom;
4529 
4532 
4534  bool lfetch;
4535 
4537  bool linsert;
4538 
4540  unsigned int lpos;
4541 
4543  unsigned int current;
4544 
4547 
4549  bool leof;
4550 
4553 
4566  virtual Record* newRecord();
4567 
4568  //Clear the entire Record set and the lmetarec object.
4569  void clear();
4570 
4579  bool internal_fetch(unsigned int newpos);
4580 
4581 
4582 protected:
4607  void init(unsigned char code, unsigned int nrows = 0, Record* meta = NULL,
4608  short int id = 0);
4609 
4611  void startFetch();
4612 
4638  virtual bool fetch(unsigned int newpos, bool random);
4639 
4641  virtual void hk_dump(string fn);
4642 
4643 
4644 public:
4651  MCS_MISSING_COPY_CONSTRUCTOR(RecordSet);
4652 
4659  MCS_MISSING_ASSIGNMENT_OPERATOR(RecordSet);
4660 
4667  RecordSet();
4668 
4670  virtual ~RecordSet();
4671 
4672 
4673 
4683  void setFieldMap(string s = "");
4684 
4685 
4696  void insert(Record* rec);
4697 
4708  void insert(Record& rec);
4709 
4710 
4719  bool setFirst();
4720 
4730  bool setLast();
4731 
4740  bool setNext();
4741 
4750  bool setPrev();
4751 
4769  bool setWhere(int i, string equalTo);
4770 
4788  bool setWhere(int field, int equalTo);
4789 
4806  bool setPos(unsigned int i);
4807 
4808  void dump(string fn);
4809 
4810  bool know_nRows();
4811  unsigned int nRows();
4812 
4814  int nFields();
4815 
4816  unsigned int pos();
4817  bool eof();
4818  bool alwaysSameStructure();
4819 
4820  Record& rec();
4821  Record& metarec();
4822 
4823  Record* prepRecToSend();
4824 };
4825 
4826 
4827 
4828 
4829 
4830 //--------------------------------------------------------------------
4843 class Conf
4844 {
4845 private:
4847  string filename;
4848 
4850  vector<string> sections;
4851 
4853  vector<string> keys;
4854 
4856  vector<string> values;
4857 
4859  vector<string> comments;
4860 
4869  int index(string section, string key);
4870 
4871  Data lastval;
4872 
4873 public:
4880  MCS_MISSING_COPY_CONSTRUCTOR(Conf);
4881 
4888  MCS_MISSING_ASSIGNMENT_OPERATOR(Conf);
4889 
4895  Conf(string filename = "");
4896 
4898  ~Conf();
4899 
4900  void open(string filename);
4901 
4914  bool search(string section, string key, enum ThrowExceptions throwexc = DONT_THROW);
4915 
4917 
4932  Data& val(string section = "", string key = "");
4933 
4947  string sval(string section, string key);
4948 
4963  string sval(string section, string key, string defval);
4964 
4965 
4966 
4980  int ival(string section, string key);
4981 
4996  int ival(string section, string key, int defval);
4997 
4998 
5012  long long int lval(string section, string key);
5013 
5028  long long int lval(string section, string key, int defval);
5029 
5030 
5045  void setval(string section, string key, string val, string comment = "");
5046 
5062  void setval(string section, string key, long long int val, string comment = "");
5077  void setval(string section, string key, int val, string comment = "");
5078 
5093  void setval(string section, string key, Data* val, string comment = "");
5094 
5095 
5106  void save(string filename = "");
5107 };
5108 
5109 
5110 
5111 
5112 
5113 
5114 
5115 //--------------------------------------------------------------------
5117 #define MCS_CMD_MAX_TOKENS 100
5118 
5186 private:
5187  MCS_DEBUG_ALLOC;
5188 
5190  string origcmdline;
5191 
5193  string lcmd;
5194 
5196  vector<string> tokens;
5197 
5205  vector<string> rest;
5206 
5208  vector<string> args;
5209 
5211  vector<string> opts;
5212 
5214  vector<string> optargs;
5215 
5218 
5220  Data* md_optargs[MCS_CMD_MAX_TOKENS];
5221 
5228  static string clean(string c);
5229 
5231  void clearArgs();
5232 
5233 public:
5240  MCS_MISSING_COPY_CONSTRUCTOR(CommandParser);
5241 
5248  MCS_MISSING_ASSIGNMENT_OPERATOR(CommandParser);
5249 
5251  CommandParser();
5252 
5254  ~CommandParser();
5255 
5257  int tokenc();
5258 
5271  string token(int i);
5272 
5287  string line_afterToken(int i);
5288 
5289 
5305  Data& arg(int i);
5306 
5308  string sarg(int i);
5309 
5310 
5312  int argc();
5313 
5314 
5330  string opt(int i);
5331 
5333  int optc();
5334 
5335 
5355  Data& optarg(int i);
5356 
5358  void parseCmd(string c);
5359 
5361  void parseCmd(int argc, char* argv[]);
5362 
5363 
5364 
5366  string cline();
5367 
5369  string cmd();
5370 
5372  string allargs();
5373 
5375  bool cmpCmd(string cmd);
5376 
5378  bool givenOpt(string opt);
5379 
5381  bool givenOpt(string opt, int& i);
5382 
5383 
5400  vector<string> replPars_onFile(string fn);
5401 
5402 
5415  string replPars(string str);
5416 };
5417 
5418 
5419 
5420 
5421 
5422 
5423 #if ENABLE_MYSQL
5424 //--------------------------------------------------------------------
5432 class DBConn
5433 {
5434 private:
5435  MCS_DEBUG_ALLOC;
5436 
5438  MYSQL* lconn;
5439 
5442 
5445 
5447  string luser;
5448 
5450  string lpass;
5451 
5453  string ldb ;
5454 
5456  string lhost;
5457 
5458  friend class Query;
5459 
5460 public:
5467  MCS_MISSING_COPY_CONSTRUCTOR(DBConn);
5468 
5475  MCS_MISSING_ASSIGNMENT_OPERATOR(DBConn);
5476 
5478  DBConn();
5479 
5481  ~DBConn();
5482 
5497  void connect(string user, string pass, string db, string host="");
5498 
5500  void close();
5501 
5503  bool isOpen();
5504 
5506  unsigned long id();
5507 
5522  DBConn* newDBConn();
5523 };
5524 
5525 
5526 
5527 
5528 
5529 
5530 //--------------------------------------------------------------------
5544 class Query : public RecordSet
5545 {
5546 private:
5547  MCS_DEBUG_ALLOC;
5548 
5551 
5554 
5556  MYSQL* lconn;
5557 
5560 
5563 
5565  unsigned int laffectedRows;
5566 
5568  long long int lastid;
5569 
5575 
5576 
5594  vector<string> printResultSet(unsigned int& nrows,
5595  unsigned int& nfields,
5596  MYSQL_RES* res = NULL);
5597 
5602  MYSQL_STMT* lstmt;
5603 
5608  MYSQL_BIND* lbparam;
5609 
5610  int nlparam;
5611 
5612 
5614  MYSQL_BIND* lbrec;
5615 
5616  bool fetch(unsigned int newpos, bool random);
5617 
5618  Record* myrec;
5619 
5620  Record* newRecord();
5621 
5622  /*
5623  IMPORTANT NOTE: lbparam and lparam are protected because the Table class
5624  needs them to bind parameters. Anyway this should be automatically done
5625  via mysql_stmt_param_metadata, but it is not yet implemented. When this
5626  routine will became available this two variables will become private, so
5627  users should use the method "param" wherever possible.
5628  */
5629 
5635  void bind();
5636 
5637  string SQL;
5638 
5639  void parseFieldList(int op, string& fields, string& values, int& autoIncr);
5640 
5641 
5642 public:
5649  MCS_MISSING_COPY_CONSTRUCTOR(Query);
5650 
5657  MCS_MISSING_ASSIGNMENT_OPERATOR(Query);
5658 
5673  Query(DBConn* lconn, bool call_newDBConn = false);
5674 
5681  ~Query();
5682 
5689  void query(string SQL, bool StoreResult = false);
5690 
5691 
5732  vector<string> simpleQuery(string SQL,
5733  unsigned int& nrows, unsigned int& nfields);
5734 
5735 
5737  vector<string> simpleQuery(string SQL);
5738 
5739 
5760  void prepare(string SQL="");
5761 
5762 #define MCS_PAB_INSERT 1
5763 #define MCS_PAB_UPDATE 2
5764 #define MCS_PAB_REPLACE 3
5765 
5766 
5807  void prepare_with_parameters(int op, string fields, string table,
5808  string where="", int nrec=1);
5809 
5810 
5822  void prepare_with_parameters(int op, char** fields, int nfields,
5823  string table, string where="", int nrec=1);
5824 
5825 
5833  unsigned int nAffectedRows();
5834 
5835 
5837  Record& param();
5838 
5840  // \brief Returns the current record set.
5841  //*/
5842  //DBRecordSet* result();
5843 
5862  Data& lookup(string field, string table, string where = "");
5863 
5864 
5895  void execute(bool StoreResult = false);
5896 
5897 
5898  bool gotRecordSet();
5899 
5900 
5902  void close();
5903 
5904 
5911  void readTableList();
5912 
5914  vector<string>tableList;
5915 
5927  vector<string> tableInfo(string tbl);
5928 
5929 
5931  vector<string> ExecutionDetails(string pre = "");
5932 
5933 
5953  void customFillBuffer(char* buf, unsigned int& chunksize, bool firstTime);
5954 
5961  void Result2Ascii(string fn);
5962 
5972  long long int last_id();
5973 };
5974 
5975 
5976 
5977 
5978 
5979 
5980 
5981 //--------------------------------------------------------------------
5999 class Table : public Query
6000 {
6001 private:
6002  MCS_DEBUG_ALLOC;
6003 
6005  string ltable;
6006 
6008  string lfieldkey;
6009 
6011  unsigned int posfieldkey;
6012 
6015 
6016  void insert_or_update(int op);
6017 
6018 public:
6025  MCS_MISSING_COPY_CONSTRUCTOR(Table);
6026 
6033  MCS_MISSING_ASSIGNMENT_OPERATOR(Table);
6034 
6042  Table(DBConn* db, string table, string fieldkey);
6043 
6045  ~Table();
6046 
6048  void loadTable();
6049 
6053  Record& newRec();
6054 
6060  void insert();
6061 
6067  void replace();
6068 
6069 
6076  void update();
6077 };
6078 #endif
6079 
6080 
6081 
6082 
6083 
6084 //Forward declaration
6085 class Env;
6086 class Server;
6087 
6088 
6089 
6090 //
6091 //--------------------------------------------------------------------
6098 class BaseThread : public Thread {
6099 private:
6100  MCS_DEBUG_ALLOC;
6101 
6103  char tID[4];
6104 
6105 protected:
6113  RetValue Log(Event e);
6114 
6116  static Env* env;
6117 
6118 public:
6125  MCS_MISSING_COPY_CONSTRUCTOR(BaseThread);
6126 
6133  MCS_MISSING_ASSIGNMENT_OPERATOR(BaseThread);
6134 
6143  BaseThread(Thread* parent, int lID);
6144 
6153  BaseThread(Thread* parent, const char *ltID);
6154 
6156  ~BaseThread();
6157 
6159  const char *tid();
6160 
6161 
6181  static int fileType(string fn);
6182 
6196  int chkExt(string& s);
6197 
6236  static int spawn(string fn, string pars,
6237  string wpath = ".",
6238  string thrID = "x",
6239  string user = "x",
6240  string pass = "x",
6241  string dbname = "x",
6242  string fout = "out",
6243  string ferr = "err");
6244 };
6245 
6246 
6247 
6248 
6249 //--------------------------------------------------------------------
6251 #define MCS_FT_UNKNOWN 0
6252 
6254 #define MCS_FT_BATCH 1
6255 
6257 #define MCS_FT_SQL 2
6258 
6260 #define MCS_FT_SCRIPT 3
6261 
6263 #define MCS_FT_BIN 4
6264 
6265 
6266 
6273 class ClientInfo : public Record
6274 {
6275 public:
6277  Data& id();
6278 
6280  Data& ipaddress();
6281 
6283  Data& hostname();
6284 
6286  Data& timeConnetcted();
6287 
6289  Data& username();
6290 
6292  Data& lastCommand();
6293 
6295  Data& timeLastCommand();
6296 
6298  Data& commandExecuted();
6299 
6301  Data& logged();
6302 
6303 public:
6305  ClientInfo();
6306 };
6307 
6308 
6309 
6310 
6311 
6365 class UserThread : public BaseThread {
6366 private:
6367  MCS_DEBUG_ALLOC;
6368 
6370  int csocket;
6371 
6374 
6375  RecordSet* rs;
6376 
6377  bool deleters;
6378 
6379  Synchro syn;
6380 
6381 protected:
6384 
6386  int luserid;
6387 
6390 
6392  bool loginok;
6393 
6395  int grants;
6396 
6398  string fnout;
6399 
6401  string fnerr;
6402 
6404  string user;
6405 
6407  string pass;
6408 
6410  string dbname;
6411 
6413  string dbhost;
6414 
6415 #if ENABLE_MYSQL
6416  DBConn db;
6418 
6421 #endif
6422 
6423  void setActiveRS(RecordSet* rs, bool delWhenFinished = true);
6424 
6435  string wpath(string fn = "");
6436 
6437 
6448  RetValue sendStrings(string str);
6449 
6450 
6457  RetValue Send(Event e, bool log = true);
6458 
6464  RetValue Send(Data& data);
6465 
6471  RetValue Send(Record& vec);
6472 
6481  RetValue Send(string filename, string path);
6482 
6490  RetValue Send(vector<string> vec);
6491 
6492 
6493 #if ENABLE_MYSQL
6494 
6506  RetValue sendQueryRes();
6507 #endif
6508 
6509 
6524  void prompt(RetValue ret);
6525 
6526 
6535  void run();
6536 
6537 
6551  virtual RetValue hk_connect();
6552 
6553 
6572  virtual RetValue hk_auth(int& grants, bool& loginok);
6573 
6574 
6592  virtual RetValue hk_exec(CommandParser* cmd, bool& cmd_executed);
6593 
6594 
6607  virtual void hk_postexec(CommandParser* cmd, RetValue ret);
6608 
6609 
6618  virtual void hk_disconnect();
6619 
6620 
6643  RetValue exec(string cmd, string pars = "");
6644 
6645 
6650  Server* parent();
6651 
6652 
6654  void send2OtherThread(Data& d, int destid);
6655 
6656 public:
6663  MCS_MISSING_COPY_CONSTRUCTOR(UserThread);
6664 
6671  MCS_MISSING_ASSIGNMENT_OPERATOR(UserThread);
6672 
6682  UserThread(Thread* parent, int lID, int newsock);
6683 
6685  ~UserThread();
6686 
6688  ClientInfo& info();
6689 
6707  void wakeUpClient(Event* e = NULL);
6708 
6711 
6714 
6716  string userName();
6717 
6718  int userID();
6719 };
6720 
6721 
6722 
6723 
6724 // -------------------------------------------------------------------
6741 class LocalThread : public BaseThread
6742 {
6743 private:
6744  MCS_DEBUG_ALLOC;
6745 
6754  virtual void run();
6755 
6756 
6757 protected:
6758  UserThread** client;
6759 
6761  UserThread** serverClients();
6762 
6771  void dataDispatcher();
6772 
6790  bool userID2clientID(int userid, int* cid);
6791 
6792 
6793 public:
6800  MCS_MISSING_COPY_CONSTRUCTOR(LocalThread);
6801 
6808  MCS_MISSING_ASSIGNMENT_OPERATOR(LocalThread);
6809 
6819  LocalThread(Thread* parent);
6820 
6821 
6823  ~LocalThread();
6824 
6825 
6840  virtual void hk_log(UserThread* p, Event e);
6841 
6844 };
6845 
6846 
6847 
6848 
6849 //--------------------------------------------------------------------
6867 class Env {
6868 private:
6869 #if ENABLE_MYSQL
6870  DBConn db;
6871 #endif //ENABLE_MYSQL
6872 
6874  void chkTree();
6875 
6879  void LoadConf();
6880 
6884  void DumpConf();
6885 
6886 
6887 public:
6896  Env(string app = "mcs", string inipath = "mcs.conf");
6897 
6904  MCS_MISSING_COPY_CONSTRUCTOR(Env);
6905 
6912  MCS_MISSING_ASSIGNMENT_OPERATOR(Env);
6913 
6915  ~Env();
6916 
6917  LocalThread* local;
6918 
6921 
6923  string appname;
6924 
6926  string appvers;
6927 
6929  string path;
6930 
6932  string inipath;
6933 
6935  string localhost;
6936 
6938  string interface;
6939 
6941  int port;
6942 
6944  //bool server_running;
6945 
6946  Server* server;
6947 
6950 
6953 
6956 
6959 
6962 
6964  bool cl_work;
6965 
6968 
6971 
6974 
6977 
6980 
6983 
6986 
6989 
6991  string sslcert;
6992 
6994  string sslpriv;
6995 
6997  ofstream* flog;
6998 
7000  string db_user;
7001 
7003  string db_pass;
7004 
7006  string db_name;
7007 
7009  string db_host;
7010 
7012  unsigned int timeout;
7013 
7016 
7018  void* ssl_ctx;
7019 };
7020 
7021 
7022 
7023 
7024 
7025 
7026 
7027 
7028 
7029 
7030 
7031 
7032 //--------------------------------------------------------------------
7166 class Server : public BaseThread
7167 {
7168 private:
7169  MCS_DEBUG_ALLOC;
7170 
7173 
7174  friend class LocalThread; //To give access to pClient
7175 
7184  void run();
7185 
7188  int find_free_id();
7189 
7190 protected:
7199  void notify(int id, Thread* ref);
7200 
7202  void newClient(int newsock);
7203 
7206  //void freeClient(int i);
7207 
7209  void killAllClients();
7210 
7226  virtual void hk_newClient(int i);
7227 
7229  void killClient(int i);
7230 
7231 
7238  virtual UserThread* newUserThread(int lID, int newsock);
7239 
7246  virtual LocalThread* newLocalThread();
7247 
7248 public:
7255  MCS_MISSING_COPY_CONSTRUCTOR(Server);
7256 
7263  MCS_MISSING_ASSIGNMENT_OPERATOR(Server);
7264 
7271  Server(Env* lenv);
7272 
7274  ~Server();
7275 
7283  RecordSet* getAll_ClientInfo();
7284 
7286  void (*cb_log) (UserThread* p, Event e);
7287 
7289  RetValue (*cb_connect) ();
7290 
7292  RetValue (*cb_auth) (int&, bool&);
7293 
7295  RetValue (*cb_exec) (CommandParser*, bool&_executed);
7296 
7298  void (*cb_postexec) (CommandParser*, RetValue);
7299 
7301  void (*cb_disconnect) ();
7302 
7304  void (*cbwa_log) ();
7305 
7307  void (*cbwa_connect) ();
7308 
7310  void (*cbwa_auth) ();
7311 
7313  void (*cbwa_exec) ();
7314 
7316  void (*cbwa_postexec) ();
7317 
7319  void (*cb_newClient) (int i);
7320 
7323 };
7324 
7325 
7326 
7327 
7377 Env* mcsStart(string appname, string inipath = "",
7378  Server* (*cb_newServer)(Env*) = NULL);
7379 
7380 
7410 //void mcsWait(Env* env);
7411 
7412 
7413 #define MCS_CUSTOM_USER(CLASS) \
7414 class CLASS : public mcs::UserThread \
7415 { \
7416 public: \
7417  CLASS(mcs::Thread* p, int id, int sock) : \
7418  UserThread(p, id, sock) {} \
7419  ~CLASS() {}
7420 #define MCS_CUSTOM_USER_END(CLASS) };
7421 
7422 
7423 #define MCS_CUSTOM_LOCAL(CLASS) \
7424 class CLASS : public mcs::LocalThread \
7425 { \
7426 public: \
7427  CLASS(mcs::Thread* p) : \
7428  LocalThread(p) {} \
7429  ~CLASS() {}
7430 #define MCS_CUSTOM_LOCAL_END(CLASS) };
7431 
7432 
7446 #define MCS_CUSTOM_SERVER(CLIENT, LOCAL) \
7447 mcs::Server* newCustomServer(mcs::Env* env); \
7448  \
7449 class mcsCustomServer : public mcs::Server \
7450 { \
7451 private: \
7452  mcs::UserThread* newUserThread(int id, int sock) { \
7453  return new CLIENT(this, id, sock); \
7454  } \
7455  \
7456  mcs::LocalThread* newLocalThread() { \
7457  return new LOCAL(this); \
7458  } \
7459  \
7460 public: \
7461  mcsCustomServer(mcs::Env* lenv): Server(lenv) {} \
7462  \
7463  ~mcsCustomServer() {} \
7464 }; \
7465  \
7466 mcs::Server* newCustomServer(Env* env) \
7467 { return new mcsCustomServer(env); } \
7468  \
7469 mcs::Env* mcsCustomStart(string appname, string inipath = "") \
7470 { return mcsStart(appname, inipath, &newCustomServer); }
7471 
7472 
7473 
7474 //--------------------------------------------------------------------
7538 class Client : public Socket, public RecordSet
7539 {
7540 protected:
7542  string lpath;
7543 
7546 
7548  void clearRecords();
7549 
7550  bool writetofile;
7551 
7552  int fileDescriptor;
7553 
7554  bool fetch(unsigned int newpos, bool random);
7555 
7556  Record* lrecord;
7557 
7558  //Server side Client Identificator.
7559  int lcid;
7560 
7561  //Server side chunk size.
7562  int lchunksize;
7563 
7564 public:
7571  MCS_MISSING_COPY_CONSTRUCTOR(Client);
7572 
7579  MCS_MISSING_ASSIGNMENT_OPERATOR(Client);
7580 
7581 
7586  Record code;
7587 
7593 
7599 
7602 
7605 
7617  Client(string path, string server, int port=MCS_DEFAULT_PORT,
7618  bool synchro = false, bool SSL = false,
7619  unsigned int timeout = MCS_DEFAULT_CLIENT_TIMEOUT);
7620 
7622  virtual ~Client();
7623 
7624 
7637  bool login(string user, string pass, string db = "");
7638 
7646  bool exec(string cmd, Data* data = NULL);
7647 
7648  void writeToFile(int des);
7649 
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);
7655 
7657  bool isConnected();
7658 
7660  int cid();
7661 
7663  int chunksize();
7664 };
7665 
7666 
7667 
7694 class Pipe {
7695 private:
7698 
7700  static int filecount;
7701 
7703  string pipefn;
7704 
7706  int pipefd[2];
7707 
7716 
7718  bool named;
7719 
7720 public:
7722  Pipe();
7723 
7725  ~Pipe();
7726 
7729  bool isReady();
7730 
7733  string filename();
7734 
7735 
7743  bool consumerHasGone();
7744 
7745 
7748  void create();
7749 
7751  string createNamed();
7752 
7756  int openRead();
7757 
7761  int openWrite();
7762 
7767  void closeRead();
7768 
7773  void closeWrite();
7774 };
7775 
7776 
7777 
7778 
7779 
7780 #if ENABLE_CURL
7781 
7787 class URLReader : Pipe
7788 {
7789 private:
7791  static bool fl_curl_global_init;
7792 
7794  string lurl;
7795 
7797  bool local;
7798 
7799  static size_t cb_write(void *ptr, size_t size, size_t nmemb, void *This);
7800 
7801  ThreadFunc* thr;
7802  static int thread_run(void* p);
7803  void thread_fetch();
7804 
7805 protected:
7813  virtual unsigned int Write(void *ptr, unsigned int size, unsigned int nmemb);
7814 
7815  void flush();
7816 
7817 public:
7819  URLReader();
7820 
7822  virtual ~URLReader();
7823 
7825  int OpenAsFD(string url);
7826 
7828  const char* OpenAsFifo(string url);
7829 
7830  void Download(string url, string fn);
7831 
7832 
7836  int Read(char* buf, int maxlen);
7837 
7848  void Close();
7849 
7850  string url();
7851 
7852  //Event* thread_error();
7853 
7854  static bool chkLocal(string& url);
7855 };
7856 #endif
7857 
7858 
7859 
7860 #if ENABLE_CFITSIO
7861 
7867 class FITSReader: public RecordSet
7868 {
7869 private:
7870  void* fptr;
7871  long int nrows;
7872  int ncols;
7873  bool local;
7874  int nhdu;
7875  bool fetch(unsigned int newpos, bool random);
7876 
7877  Buffer memfile;
7878  void* memfilep;
7879  size_t memfilesize;
7880 
7881 public:
7882  FITSReader();
7883  ~FITSReader();
7884 
7885  void open(Buffer& buf);
7886  void open(string fn);
7887  void close();
7888 
7889  Record header;
7890  Record header_comments;
7891 
7892  void selectHDU(int hdunum);
7893  bool selectNextHDU();
7894 
7895  void selectHDU(string name, int extver = 0);
7896  int currentHDU();
7897  int HDUCount();
7898 
7899  bool ffile_is_compressed(string fn);
7900 
7901  void read_json_header(const string& json_string);
7902 };
7903 
7904 
7911 class FITSWriter: public Record
7912 {
7913 private:
7914  void* fptr;
7915 
7916 public:
7917  FITSWriter();
7918  ~FITSWriter();
7919 
7920  void open(string fn, bool compressed = false);
7921  void close();
7922 
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 = "");
7928 
7929  //The "buf" parameter is used only to write a image HDU.
7930  void write(void* buf);
7931 };
7932 #endif //ENABLE_CFITSIO
7933 
7934 
7935 //class FileReader : public RecordSet
7936 //{
7937 //private:
7938 // URLReader input;
7939 // int fd;
7940 //
7941 // Record master;
7942 // string sep;
7943 // string eor;
7944 //
7945 // Buffer buf;
7946 //
7947 // bool fetch(unsigned int newpos, bool random);
7948 //
7949 //public:
7950 // FileReader();
7951 // ~FileReader();
7952 //
7953 // void open(string url);
7954 // void close();
7955 //
7956 // void setMaster(Record& rec);
7957 // void setMaster(Record& rec, string sep);
7958 // void setMaster(Record& rec, string sep, string eor);
7959 //};
7960 
7961 
7962 
7963 #define MCS_B64_DEF_LINE 72
7964 #define MCS_B64_MIN_LINE 4
7965 
7966 #define MCS_B64_ENCODE 0
7967 #define MCS_B64_DECODE 1
7968 #define MCS_B64_DECODEINPLACE 2
7969 
7975 class B64_Codec {
7976 private:
7977  /*
7978  ** Translation Table as described in RFC1113
7979  */
7980  static const char* cb64;
7981 
7982  /*
7983  ** Translation Table to decode (created by author)
7984  */
7985  static const char* cd64;
7986 
7989 
7991  unsigned int bufsize;
7992 
7994  void requireSpace(unsigned int Length);
7995 
7997  void freeBuffer();
7998 
8000  char* buf_out;
8001 
8003  unsigned int bufused;
8004 
8006  char* pin;
8007 
8009  char* pout;
8010 
8012  char* EOIB;
8013 
8015  unsigned int linesize;
8016 
8018  unsigned int blocksout;
8019 
8020  unsigned char precData[4];
8021  int precDataCount;
8022 
8024  bool eob();
8025 
8027  unsigned char readData();
8028 
8030  void writeData(unsigned char d);
8031 
8033  void encodeblock(unsigned char in[3], unsigned char out[4], int len);
8034 
8036  void decodeblock(unsigned char in[4], unsigned char out[3]);
8037 
8038 public:
8039 
8041  B64_Codec();
8042 
8044  ~B64_Codec();
8045 
8046  //DO NOT SET par_buf_out = buf_in (sigsegv)
8047 
8058  unsigned int encode(char* buf_in, int Length, char* par_buf_out = NULL,
8059  unsigned int linesize = MCS_B64_DEF_LINE);
8060 
8061  //Decode may happen also in the same buffer (set par_buf_out =
8062  //buf_in).
8063 
8074  unsigned int decode(char* buf_in, int Length, char* par_buf_out = NULL);
8075 
8076  char* buffer();
8077  unsigned int bufUsed();
8078 };
8079 
8080 
8081 
8082 #define MCS_SELECT_READ 0
8083 #define MCS_SELECT_WRITE 1
8084 
8085 
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);
8088 
8089 
8090 
8091 } //Namespace mcs
8092 #endif //DEF_MCS_HH
#define MCS_DEFAULT_PORT
Default port on which the server is listening.
Definition: mcs.hh:189
mode_t read_umask()
Read the file creation mask of the current process.
Definition: Utils.cc:250
unsigned char tag
Tag for user convenience.
Definition: mcs.hh:3133
int step_alloc
How many blocks are allocated.
Definition: mcs.hh:3819
string btos(bool b)
Convert a boolean to a string containing "true" or "false".
Definition: Utils.cc:113
bool lusemetarec
If all records share the same meta structure.
Definition: mcs.hh:4531
Retrieve informations about network interfaces.
Definition: mcs.hh:1487
Data & operator=(const struct tm v)
Wrapper assignment operator to settimeval(struct tm)
Definition: mcs.hh:3681
string itos(int i)
Convert an integer to a string.
Definition: Utils.cc:77
string luser
User name.
Definition: mcs.hh:5447
A class to hold date time information.
Definition: mcs.hh:2865
Record send
Record of Data objects to be dispatched to be sent to client.
Definition: mcs.hh:6710
Data & operator=(const int v)
Wrapper assignment operator to setival(int).
Definition: mcs.hh:3653
Definition: mcs.hh:472
short int lid
General purpose identificator.
Definition: mcs.hh:4513
string lpass
User password.
Definition: mcs.hh:5450
Connect to a MCS server as a client.
Definition: mcs.hh:7538
Data & operator=(const char *v)
Wrapper assignment operator to setsval(string)
Definition: mcs.hh:3673
MYSQL_STMT * lstmt
Mysql statement structure.
Definition: mcs.hh:5602
int lid
General purpose Thread identifier.
Definition: mcs.hh:2502
int lsubcode
Event subcode, usually an external library message code;.
Definition: mcs.hh:833
TimeMode
Enumerate operational mode for a DateTime object.
Definition: mcs.hh:2833
unsigned int laffectedRows
Rows affected by the last INSERT-LIKE query.
Definition: mcs.hh:5565
string db_pass
Password.
Definition: mcs.hh:7003
int luserid
The userid of current user.
Definition: mcs.hh:6386
A class to directly set and retrieve value from a database table.
Definition: mcs.hh:5999
#define DYNAMIC_ARRAY_DEFAULT_STEP
Size of allocation block for the Dynamic_Array class.
Definition: mcs.hh:3800
Serialize memory buffers or files into chunks.
Definition: mcs.hh:1290
Base class for MCS threaded objects.
Definition: mcs.hh:6098
bool Types2FITS(Types dbt, bool isunsigned, int &fits)
Convert a MCS type into a FITSIO type.
Definition: Data.cc:564
vector< string > tableList
A vector<string> containing the table list.
Definition: mcs.hh:5914
#define MCS_CMD_MAX_TOKENS
Max number of tokens for a command line.
Definition: mcs.hh:5117
Dynamic_Array & operator=(Dynamic_Array &from)
Assignment operator.
Definition: mcs.hh:4031
int port
Server port number.
Definition: mcs.hh:6941
int lcount
How many elements are in the array.
Definition: mcs.hh:3822
#define MCS_COMMBUFSIZE
Max length of a message being sent between client and server.
Definition: mcs.hh:210
string fnout
Default output file.
Definition: mcs.hh:6398
Execute queries on the database.
Definition: mcs.hh:5544
vector< string > keys
Internal vector containing keys names.
Definition: mcs.hh:4853
unsigned char code
Flags used in the init() method.
Definition: mcs.hh:4516
unsigned int maxChunksize
Maximum size of the chunk.
Definition: mcs.hh:1299
A simple class to implement "critical sections".
Definition: mcs.hh:2187
string smap
String representation of the map.
Definition: mcs.hh:4182
bool File_Dir_Exist(string fn, unsigned int &size)
Check if a file or directory exists.
Definition: Utils.cc:39
bool lautoincr
If the AUTO_INCREMENT flag is true.
Definition: mcs.hh:3130
The server side client thread.
Definition: mcs.hh:6365
vector< string > rest
vector of "rests".
Definition: mcs.hh:5205
string ltable
Table name.
Definition: mcs.hh:6005
string ldb
Database name to connect to.
Definition: mcs.hh:5453
bool IntType(Types type)
Tell if "type" is an integer type.
Definition: Data.cc:364
UserThread ** pClient
Array of pointers to UserThread objects.
Definition: mcs.hh:7172
char * EOIB
Pointer to the end of input buffer.
Definition: mcs.hh:8012
Read a FITS file.
Definition: mcs.hh:7867
static const char * tmfmt
Format to handle time in sprintf/sscanf calls.
Definition: mcs.hh:3148
DateTime & operator=(time_t t)
Wrapper to settval(time_t)
Definition: mcs.hh:2944
Data & operator=(const long long int v)
Wrapper assignment operator to setlval(long long int).
Definition: mcs.hh:3661
string Pwd()
Return the current working dir.
Definition: Utils.cc:66
long long int lastid
Last generated id on an AUTO_INCREMENT column.
Definition: mcs.hh:5568
Dynamic_Array(bool synchro)
Constructor with optional synchronization.
Definition: mcs.hh:4012
Event * lerror
Last error.
Definition: mcs.hh:2614
vector< string > comments
Internal vector containing comments, this is used in the save() method.
Definition: mcs.hh:4859
unsigned int wstart
Beginning of the window (0-based).
Definition: mcs.hh:1113
bool ready()
Tells if there are objects in the array.
Definition: mcs.hh:4124
static const char * dfmt
Format to handle double float in sprintf/sscanf calls.
Definition: mcs.hh:3160
int batchlevel
Nested batch level.
Definition: mcs.hh:6389
Class holding information about a client connection.
Definition: mcs.hh:6273
Main server class for a MCS-based application.
Definition: mcs.hh:7166
unsigned int arrpos
Last selected array cell.
Definition: mcs.hh:3218
bool linsert
If true the insert mechanism will be used.
Definition: mcs.hh:4537
BufferFreeOnDestroy
Values to be used in Buffer class constructor.
Definition: mcs.hh:246
unsigned int arrsize
Array size, i.e. how many cells are in the array.
Definition: mcs.hh:3215
char * buf
Data buffer.
Definition: mcs.hh:3136
Data & operator=(const unsigned long long int v)
Wrapper assignment operator to setulval(unsigned long long int).
Definition: mcs.hh:3665
bool cl_autoexec
Auto execute batch file "auto".
Definition: mcs.hh:6985
bool lknow_nrows
If the number of records is known.
Definition: mcs.hh:4519
Record dispatch
Record of Data objects to be sent to various threads.
Definition: mcs.hh:7322
A high level class to use system pipes.
Definition: mcs.hh:7694
unsigned long llength
Actual length of real data in the buffer, useful only when the base type is a variable length type...
Definition: mcs.hh:3121
MYSQL_TIME * mysql
Pointer to linked MYSQL_TIME structure.
Definition: mcs.hh:2875
Hold informations about an event.
Definition: mcs.hh:814
string db_host
Host running database server.
Definition: mcs.hh:7009
static Env * env
Pointer to the actual Env object, this can be seen in all threaded object.
Definition: mcs.hh:6116
bool lconnOpened
True if the connection has been opened.
Definition: mcs.hh:5444
Record out
Record containing all output lines (code: MSG_OUT) sent by the server while executing the last comman...
Definition: mcs.hh:7598
unsigned int current
Internal position in the Dynamic_Array object.
Definition: mcs.hh:4543
A dynamic array of Data objects.
Definition: mcs.hh:4170
int copy(char *OLDNAME, char *NEWNAME)
Copy a file from OLDNAME to NEWNAME.
Definition: Utils.cc:353
BASE ** arr
Array of pointer to template objects.
Definition: mcs.hh:3816
#define MCS_SYNCHRO_LOCK
To be used with Synchro.enter(): enter a critical section.
Definition: mcs.hh:2259
string MYSQL2Str(enum_field_types type)
Return the name of the MySQL type given in "type".
Definition: Data.cc:393
char * buf
Pointer to temporary buffer containing the next chunk.
Definition: mcs.hh:1296
A thread safe, template class to handle an array of objects.
Definition: mcs.hh:3813
unsigned char ldimspec
Multi-dimensional array specification.
Definition: mcs.hh:3206
string origcmdline
Command line parsed.
Definition: mcs.hh:5190
bool loginok
Tells if client has logged in correctly.
Definition: mcs.hh:6392
int move(char *OLDNAME, char *NEWNAME)
Move a file from OLDNAME to NEWNAME.
Definition: Utils.cc:395
bool laccum
If all records has been fetched during the init() call.
Definition: mcs.hh:4525
BASE pop(int pos=0)
Extracts an element from the array.
Definition: mcs.hh:4072
unsigned int linesize
Required linesize (when encoding).
Definition: mcs.hh:8015
string user
User name.
Definition: mcs.hh:6404
string fnerr
Default error file.
Definition: mcs.hh:6401
string path
Main server path (APPD).
Definition: mcs.hh:6929
BASE peek(int pos)
Retrieve an element from the array but don&#39;t extract it.
Definition: mcs.hh:4107
#define MCS_VMSG_SIZE
Size of the Event.vmsg static array.
Definition: mcs.hh:730
string dbhost
Host running database server.
Definition: mcs.hh:6413
void push(BASE *d)
Push an existing element at the end of the array.
Definition: mcs.hh:4043
int stoi(string s, int errval)
Convert a string to an integer.
Definition: Utils.cc:95
int sockfd
C socket file descriptor.
Definition: mcs.hh:1668
void ls2Record(string fn, Record &v)
Fill a vector with a list of file.
Definition: Utils.cc:290
int csocket
C socket descriptor, used to initialize the Socket object.
Definition: mcs.hh:6370
int lcode
Event code;.
Definition: mcs.hh:830
#define MCS_DEFAULTCHUNKSIZE
File chunk size.
Definition: mcs.hh:198
bool extbuffer
Tell if we are handling a user allocated buffer.
Definition: mcs.hh:1107
string db_name
Database name.
Definition: mcs.hh:7006
MYSQL * lconn
Mysql connection to use.
Definition: mcs.hh:5556
unsigned int bufsize
Size of data buffer.
Definition: mcs.hh:3139
pthread_t lthrID
System&#39;s thread identifier.
Definition: mcs.hh:2499
Data & operator=(const double v)
Wrapper assignment operator to setdval(double).
Definition: mcs.hh:3669
void sleep_ms(unsigned int millisec)
A millisecond resolution sleep function.
Definition: Thread.cc:603
The base class that implement the data abstraction layer.
Definition: mcs.hh:4510
#define MCS_ERROR(A, rest...)
Facility to easily pass all necessary parameter to an Event constructor.
Definition: mcs.hh:964
int max_users
How many clients can be connected at the same time.
Definition: mcs.hh:6949
string lcmd
First token, that is the command.
Definition: mcs.hh:5193
Data & operator=(const string v)
Wrapper assignment operator to setsval(string).
Definition: mcs.hh:3677
static int filecount
Used to generate a unique filename.
Definition: mcs.hh:7700
bool isActive
Whether this object is a "dummy" object or not.
Definition: mcs.hh:2211
char * from
Pointer to source buffer, if type = MCS_SERIAL_BUFFER.
Definition: mcs.hh:1311
bool leof
If the current position (lpos) is at the end of the set.
Definition: mcs.hh:4549
string appname
Application name.
Definition: mcs.hh:6923
void * ssl_ctx
Pointer to the global SSL context object, used if cl_use_ssl is true.
Definition: mcs.hh:7018
string Types2Str(Types type, bool isunsigned)
Return the name of the type given in "type" and "isunsigned".
Definition: Data.cc:313
~Dynamic_Array()
Destructor, this also destroy all objects in the array.
Definition: mcs.hh:4023
string fitsError(int status)
Return a description of a FITS error.
Definition: Readers.cc:438
unsigned int posfieldkey
Position of the index field.
Definition: mcs.hh:6011
unsigned int bufsize
Size of the buffer.
Definition: mcs.hh:1101
unsigned int wlen
Length of the window.
Definition: mcs.hh:1116
char * pout
Cursor for output buffer.
Definition: mcs.hh:8009
Data & operator=(const unsigned int v)
Wrapper assignment operator to setuival(unsigned int).
Definition: mcs.hh:3657
RetValue
Return value for MCS routines.
Definition: mcs.hh:471
vector< string > args
vector of arguments.
Definition: mcs.hh:5208
bool use_ssl
True if the connection should be encrypted.
Definition: mcs.hh:2022
string vtos(vector< string > vec)
Join a vector of strings in a single string using newlines.
Definition: Utils.cc:122
static const char * dtfmt
Format to handle datetime in sprintf/sscanf calls.
Definition: mcs.hh:3142
string Types2MYSQLStr(Types &type, bool isunsigned)
Convert a MCS type into a MySQL type.
Definition: Data.cc:509
Read and write configuration files.
Definition: mcs.hh:4843
bool cl_restartlocal
Resart local thread when it dies.
Definition: mcs.hh:6976
Record msg
Record containing all reply&#39;s messages sent by the server while executing the last command...
Definition: mcs.hh:7592
string lhost
Host running database server.
Definition: mcs.hh:5456
bool FloatType(Types type)
Tell if "type" is a float type.
Definition: Data.cc:379
char * buf
Pointer to internal buffer.
Definition: mcs.hh:1098
bool cl_createlocal
Create local thread.
Definition: mcs.hh:6973
bool connected
Flag telling if the client is connected or not.
Definition: mcs.hh:7545
string remTrailing(string &s, const char *p)
Remove any trailing character "p".
Definition: Utils.cc:185
High level buffer.
Definition: mcs.hh:1095
int grants
User grants.
Definition: mcs.hh:6395
Data & operator=(const time_t v)
Wrapper assignment operator to settimeval(time_t)
Definition: mcs.hh:3685
bool use_ssl
True if the connection should be encrypted.
Definition: mcs.hh:1690
int type
Type of data to be sent.
Definition: mcs.hh:1308
bool Types2S_FITS(Types dbt, int len, bool isunsigned, string &fits)
Convert a MCS type into a FITSIO type code.
Definition: Data.cc:603
Parse command lines.
Definition: mcs.hh:5185
BASE & operator[](int pos)
The operator[] for the array.
Definition: mcs.hh:4092
string dbname
Database name, usually the same as Env.appname.
Definition: mcs.hh:6410
DateTime & operator=(struct tm &ltm)
Wrapper to settmval()
Definition: mcs.hh:2975
string lpath
Local path to read/write files.
Definition: mcs.hh:7542
Thread * lparent
Reference to parent Thread object, if any is given in the constructor.
Definition: mcs.hh:2496
MYSQL_BIND * lbrec
Record of binding structure for output.
Definition: mcs.hh:5614
static const char * lfmt
Format to handle long integers in sprintf/sscanf calls.
Definition: mcs.hh:3154
bool cl_local_kills_mcs
When the local thread dies the server will be stopped.
Definition: mcs.hh:6952
A Base 64 encoder/decoder.
Definition: mcs.hh:7975
bool cl_logfile
Use log file.
Definition: mcs.hh:6961
bool cl_have_db
Activate DB facilities.
Definition: mcs.hh:6955
vector< string > split(string s, string sep=" ")
Split a string into tokens.
Definition: Utils.cc:192
pthread_mutex_t mutex
The mutex used to do the job.
Definition: mcs.hh:2202
Handle database connection.
Definition: mcs.hh:5432
pthread_mutexattr_t attr
Attribute of the mutex (PTHREAD_MUTEX_RECURSIVE_NP).
Definition: mcs.hh:2205
Server side administrative thread.
Definition: mcs.hh:6741
vector< string > sections
Internal vector containing section names.
Definition: mcs.hh:4850
string inipath
Application ini file.
Definition: mcs.hh:6932
string remTabs(string s)
Remove any tab.
Definition: Utils.cc:172
#define MCS_CRITICAL_SECTION_END
End a critical section, there must be no "return" or "goto" instruction inside the section...
Definition: mcs.hh:2380
string interface
Server interface name.
Definition: mcs.hh:6938
bool select
If a window has been selected.
Definition: mcs.hh:1110
string lname
Object name.
Definition: mcs.hh:3108
string filename
Path to the configuration file.
Definition: mcs.hh:4847
time_t time
Internal storage (seconds elapsed since 1970-01-01 00:00:00 UTC).
Definition: mcs.hh:2869
static const char * ifmt
Format to handle integers in sprintf/sscanf calls.
Definition: mcs.hh:3151
Env * mcsStart(string appname, string inipath="", Server *(*cb_newServer)(Env *)=NULL)
Start a MCS server.
Definition: Main.cc:113
int lstate
State of the object, see state() method.
Definition: mcs.hh:2505
unsigned short int lmaxlength
Max number of bytes that can be stored in the buffer (size of the buffer).
Definition: mcs.hh:3115
char * pin
Cursor for input buffer.
Definition: mcs.hh:8006
ofstream * flog
Stream to write the log file.
Definition: mcs.hh:6997
bool cl_logstdout
Copy log on stdout.
Definition: mcs.hh:6970
bool cl_clean_logout
Clean work dir on user logout.
Definition: mcs.hh:6979
bool cl_work_cid
Work path is created using cid if true, otherwise with the user name.
Definition: mcs.hh:6967
char * buf_out
Pointer to output buffer.
Definition: mcs.hh:8000
vector< string > names
Vector containing the name of all interfaces present in the system.
Definition: mcs.hh:1499
string chomp(string s)
Remove any trailing newlines.
Definition: Utils.cc:166
int extractCode(const char *msg)
Extract the numeric code from a server reply.
Definition: Utils.cc:26
unsigned int bufused
Size of data in output buffer.
Definition: mcs.hh:8003
bool VarLenType(Types type)
Tell if "type" is a variable length type.
Definition: Data.cc:349
void check_allocation(int count)
Alloc necessary memory to store data in the array.
Definition: mcs.hh:3992
vector< string > optargs
vector of argument to options.
Definition: mcs.hh:5214
MYSQL * lconn
MYSQL connection structure.
Definition: mcs.hh:5438
DateTime & operator=(string s)
Wrapper to setsval(string)
Definition: mcs.hh:2954
A general purpose data type.
Definition: mcs.hh:3092
Record recv
Record of Data objects received from the client or other threads.
Definition: mcs.hh:6713
Write a fits file.
Definition: mcs.hh:7911
unsigned short int port
Port on which this socket will connect.
Definition: mcs.hh:1687
Dynamic_Array< Record > rs
Internal Record set.
Definition: mcs.hh:4552
unsigned int timeout
Timeout for client operations, in millisecond.
Definition: mcs.hh:7012
char * bufAllocated
Pointer to allocated internal buffer.
Definition: mcs.hh:7988
bool MYSQL2Types(enum_field_types mtype, Types &type)
Convert a MySQL type into a MCS type.
Definition: Data.cc:436
string subst(string s, string what, string with, int op=0)
Perform substitutions on a string.
Definition: Utils.cc:135
Record recv
Record containing all Data objects sent by the server.
Definition: mcs.hh:7601
bool rmDir(string path, enum ThrowExceptions throwexc=THROW)
Removes a directory.
Definition: Utils.cc:274
string db_user
User name for the local thread access to DB.
Definition: mcs.hh:7000
string pipefn
Name of the FIFO file.
Definition: mcs.hh:7703
void clear()
Empty the array.
Definition: mcs.hh:4130
bool flcreated
Tell if a pipe has been created.
Definition: mcs.hh:7715
Types ltype
Object base type.
Definition: mcs.hh:3105
string latFile
Source file.
Definition: mcs.hh:818
int id_source
The userid of the thread who send this object.
Definition: mcs.hh:3196
Socket * sock
Socket to client.
Definition: mcs.hh:6383
Record recv
Record of Data objects received from other threads.
Definition: mcs.hh:6843
ThrowExceptions
Values to be used with throwexc parameters.
Definition: mcs.hh:257
string remLeading(string &s, const char *p)
Remove any leading character "p".
Definition: Utils.cc:178
bool lrandom
If random access (setFirst, setLast, setPos) is allowed.
Definition: mcs.hh:4528
Query * query
Query object.
Definition: mcs.hh:6420
Record newrec
Array of values for insert.
Definition: mcs.hh:6014
int cl_chunksize
Default size of a chunk of a Serializable object, that is chunks that goes through the network...
Definition: mcs.hh:7015
Hold all environment variables.
Definition: mcs.hh:6867
bool cl_read_grants
Read grants from the DB table (deprecated).
Definition: mcs.hh:6982
bool detached
Tell if the thread is to be created in the detached state.
Definition: mcs.hh:2528
string pass
Password.
Definition: mcs.hh:6407
string trim(string s)
Remove any leading or trailing blanks.
Definition: Utils.cc:160
bool lconnInitialized
True if the connection has been initialized.
Definition: mcs.hh:5441
A class to create separate threads.
Definition: mcs.hh:2487
bool cl_use_ssl
Use secure connections.
Definition: mcs.hh:6988
bool FITS2Types(int fits, Types &dbt, bool &isunsigned)
Convert a FITSIO type into a MCS type.
Definition: Data.cc:526
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"...
Definition: Utils.cc:211
string sslpriv
Path to the SSL private key file, used if cl_use_ssl = 1.
Definition: mcs.hh:6994
static bool flInitialized
Flag to tell if the init() method has been already called.
Definition: mcs.hh:847
bool selfDelete
Tell if the object should delete himself once the thread is terminated.
Definition: mcs.hh:2532
bool lhandleNewDBConn
Flag to indicate that a new DBConn object has been created.
Definition: mcs.hh:5553
vector< string > opts
vector of options.
Definition: mcs.hh:5211
vector< string > tokens
vector of tokens.
Definition: mcs.hh:5196
unsigned int lflags
Flags (EXPERIMENTAL).
Definition: mcs.hh:3111
bool gotResult
True if we got a result from the last query.
Definition: mcs.hh:5562
RetValue ltype
Event type.
Definition: mcs.hh:836
#define MCS_CRITICAL_SECTION_BEGIN
Start a critical section, there must be no "return" or "goto" instruction inside the section...
Definition: mcs.hh:2375
int sockfd
Server socket descriptor.
Definition: mcs.hh:2019
string lfieldkey
Name of the index field.
Definition: mcs.hh:6008
Conf * cnf
Pointer to the Conf object used to read the configuration file.
Definition: mcs.hh:6920
Manage TCP sockets.
Definition: mcs.hh:1662
ifstream * stream
Pointer to an ifstream, if type = MCS_SERIAL_FILENAME.
Definition: mcs.hh:1320
bool gotStmtInitialized
True if the statement has been initialized.
Definition: mcs.hh:5559
Record lmetarec
Record of meta structure, to be used only if lusemetarec is true.
Definition: mcs.hh:4546
string lmsg
Message.
Definition: mcs.hh:827
unsigned int lnrows
Number of records, to be used only if lknow_nrows is true.
Definition: mcs.hh:4522
static const char * ffmt
Format to handle float in sprintf/sscanf calls.
Definition: mcs.hh:3157
DBConn * ldbc
Internal reference to the DBConn object used to connect to db.
Definition: mcs.hh:5550
my_bool lisnull
The object has a null value.
Definition: mcs.hh:3127
string appvers
Application version.
Definition: mcs.hh:6926
Dynamic_Array< int > lmap
Array of mapped fields.
Definition: mcs.hh:4179
string dtos(double f)
Convert an floating point number to a string.
Definition: Utils.cc:105
ClientInfo linfo
Structure containing client informations.
Definition: mcs.hh:6373
bool Types2MYSQL(Types &type, enum_field_types &mtype)
Convert a MCS type into a MySQL type.
Definition: Data.cc:477
vector< string > values
Internal vector containing values names.
Definition: mcs.hh:4856
string sslcert
Path to the SSL certificate file, used if cl_use_ssl = 1.
Definition: mcs.hh:6991
bool lisunsigned
Base type is unsigned.
Definition: mcs.hh:3124
static const char * dafmt
Format to handle date in sprintf/sscanf calls.
Definition: mcs.hh:3145
bool cl_custom_auth
Activate custom authentication.
Definition: mcs.hh:6958
unsigned int lsize
Size of the actual chunk.
Definition: mcs.hh:1302
bool mkDir(string path, mode_t perm=0, enum ThrowExceptions throwexc=THROW)
Create a directory.
Definition: Utils.cc:259
bool freeAfterUse
If true the external buffer will be automatically freed, used when type = MCS_SERIAL_BUFFER.
Definition: mcs.hh:1317
int count()
Returns number of elements in the array.
Definition: mcs.hh:4118
Manage TCP server sockets.
Definition: mcs.hh:2015
bool named
If it is a named pipe (a FIFO file) or not.
Definition: mcs.hh:7718
string filename
Filename of the file being sent, if type = MCS_SERIAL_FILENAME.
Definition: mcs.hh:1305
int latLine
Line number.
Definition: mcs.hh:821
int Count
How many time the Mutex has been locked, or a thread entered a critical section.
Definition: mcs.hh:2208
fd_set fds
Set of socket file descriptors, used with select().
Definition: mcs.hh:1671
bool cl_work
Use private (per user) working dir, otherwise use path.
Definition: mcs.hh:6964
Retrieve informations about a network host.
Definition: mcs.hh:1588
#define MCS_DEFAULT_CLIENT_TIMEOUT
Default client connection timeout, in milliseconds: 10 minutes.
Definition: mcs.hh:206
unsigned int blocksout
Blocks of base64 data already written.
Definition: mcs.hh:8018
string localhost
Host name.
Definition: mcs.hh:6935
unsigned int bufsize
Size of allocated buffer.
Definition: mcs.hh:7991
Synchro synchro
To protect the filecount variable.
Definition: mcs.hh:7697
Record aux
Record containing all auxiliary fields sent by the server.
Definition: mcs.hh:7604
Dynamic_Array< Data > array
Array of fields.
Definition: mcs.hh:4176
unsigned int lpos
Current position in the recordset.
Definition: mcs.hh:4540
Namespace for MCS library.
MYSQL_BIND * lbparam
Record of binding structure for input (parameters).
Definition: mcs.hh:5608
bool lfetch
If true the fetch mechanism will be used.
Definition: mcs.hh:4534
Types
Enumeration of base type for Data.
Definition: mcs.hh:54
int id_dest
The userid of the thread that will receive this object.
Definition: mcs.hh:3199
Record lparam
Record of binded Data objects for input (parameters).
Definition: mcs.hh:5574

mcslogo

MCS (My Customizable Server) ver. 0.3.3-alpha7
Documentation generated on Mon May 28 07:39:41 UTC 2018