Qore Programming Language  0.8.7
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreLib.h
Go to the documentation of this file.
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreLib.h
4 
5  Qore Programming Language
6 
7  Copyright 2003 - 2013 David Nichols
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 
24 #ifndef _QORE_QORELIB_H
25 
26 #define _QORE_QORELIB_H
27 
28 #include <qore/common.h>
29 #include <qore/QoreThreadLock.h>
30 #include <qore/qore_bitopts.h>
31 #include <qore/safe_dslist>
32 
33 #include <time.h>
34 #include <string.h>
35 #include <strings.h>
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <ctype.h>
39 #include <sys/types.h>
40 
45 
46 #undef _QORE_HAS_QORE_XMLNODE_CLASS
47 
49 #undef _QORE_HAS_QORE_XMLREADER_CLASS
50 
52 #undef _QORE_HAS_QORE_XMLDOC_CLASS
53 
55 #define _QORE_HAS_HARD_TYPING 1
56 
58 #define _QORE_HAS_DBI_EXECRAW 1
59 
61 #define _QORE_HAS_TIME_ZONES 1
62 
64 #define _QORE_HAS_THREAD_RESOURCE_IDS 1
65 
67 #define _QORE_HAS_PREPARED_STATMENT_API 1
68 
70 #define _QORE_HAS_DATASOURCE_ACTIVETRANSACTION 1
71 
73 #define _QORE_HAS_DBI_SELECT_ROW 1
74 
76 #define _QORE_HAS_NUMBER_TYPE 1
77 
79 #define _QORE_HAS_PATH_IS_READABLE 1
80 
82 #define _QORE_HAS_DBI_OPTIONS 1
83 
85 #define _QORE_HAS_FIND_CREATE_TIMEZONE 1
86 
88 #define _QORE_HAS_NUMBER_CONS_WITH_PREC 1
89 
91 #define _QORE_HAS_FILE_OBJECT_HELPER 1
92 
94 #define _QORE_HAS_QUEUE_OBJECT_HELPER 1
95 
96 // qore code flags
97 #define QC_NO_FLAGS 0
98 #define QC_NOOP (1 << 0)
99 #define QC_USES_EXTRA_ARGS (1 << 1)
100 #define QC_CONSTANT_INTERN (1 << 2)
101 #define QC_DEPRECATED (1 << 3)
102 #define QC_RET_VALUE_ONLY (1 << 4)
103 #define QC_RUNTIME_NOOP (1 << 5)
104 
105 // composite flags
106 #define QC_CONSTANT (QC_CONSTANT_INTERN | QC_RET_VALUE_ONLY)
107 
108 
109 DLLEXPORT char *make_class_name(const char *fn);
110 
112 DLLEXPORT QoreStringNode *q_sprintf(const class QoreListNode *params, int field, int offset, class ExceptionSink *xsink);
113 
115 DLLEXPORT QoreStringNode *q_vsprintf(const class QoreListNode *params, int field, int offset, class ExceptionSink *xsink);
116 
118 DLLEXPORT struct tm *q_localtime(const time_t *clock, struct tm *tms);
119 
121 DLLEXPORT struct tm *q_gmtime(const time_t *clock, struct tm *tms);
122 
124 DLLEXPORT int64 q_epoch();
125 
127 DLLEXPORT int64 q_epoch_us(int &us);
128 
130 DLLEXPORT int64 q_epoch_ns(int &us);
131 
133 DLLEXPORT char *q_basename(const char *path);
134 
136 DLLEXPORT char *q_basenameptr(const char *path);
137 
139 DLLEXPORT char *q_dirname(const char *path);
140 
142 DLLEXPORT void *q_realloc(void *ptr, size_t size);
143 
144 #if (!defined _WIN32 && !defined __WIN32__) || defined __CYGWIN__
145 
146 DLLEXPORT QoreHashNode *q_getpwuid(uid_t uid);
147 
149 DLLEXPORT QoreHashNode *q_getpwnam(const char *name);
150 
152 DLLEXPORT QoreHashNode *q_getgrgid(uid_t uid);
153 
155 DLLEXPORT QoreHashNode *q_getgrnam(const char *name);
156 
158 
163 int q_uname2uid(const char *name, uid_t &uid);
164 
166 
171 int q_gname2gid(const char *name, gid_t &gid);
172 #endif // ! windows
173 
175 DLLEXPORT void qore_setup_argv(int pos, int argc, char *argv[]);
176 
178 DLLEXPORT qore_license_t qore_get_license();
179 
181 DLLEXPORT void qore_exit_process(int rc);
182 
184 
186 class FeatureList : public safe_dslist<std::string> {
187 private:
189  DLLLOCAL FeatureList(const FeatureList&);
190 
192  DLLLOCAL FeatureList& operator=(const FeatureList&);
193 
194 public:
196  DLLLOCAL FeatureList();
197 
199  DLLLOCAL ~FeatureList();
200 };
201 
203 DLLEXPORT extern FeatureList qoreFeatureList;
204 
206 static inline char *strchrs(const char *str, const char *chars) {
207  while (*str) {
208  if (strchr(chars, *str))
209  return (char *)str;
210  str++;
211  }
212  return 0;
213 }
214 
216 static inline char *strnchr(const char *str, int len, char c) {
217  int i = 0;
218  while (i++ != len) {
219  if (*str == c)
220  return (char *)str;
221  ++str;
222  }
223  return 0;
224 }
225 
227 static inline void strtolower(char *str) {
228  while (*(str)) {
229  (*str) = tolower(*str);
230  str++;
231  }
232 }
233 
235 static inline char *strtoupper(char *str) {
236  char *p = str;
237  while (*(p)) {
238  *p = toupper(*p);
239  p++;
240  }
241  return str;
242 }
243 
245 DLLEXPORT int getSecZeroInt(const AbstractQoreNode *a);
246 
248 DLLEXPORT int64 getSecZeroBigInt(const AbstractQoreNode *a);
249 
251 DLLEXPORT int getSecMinusOneInt(const AbstractQoreNode *a);
252 
254 DLLEXPORT int64 getSecMinusOneBigInt(const AbstractQoreNode *a);
255 
257 DLLEXPORT int getMsZeroInt(const AbstractQoreNode *a);
258 
260 DLLEXPORT int64 getMsZeroBigInt(const AbstractQoreNode *a);
261 
263 DLLEXPORT int getMsMinusOneInt(const AbstractQoreNode *a);
264 
266 DLLEXPORT int64 getMsMinusOneBigInt(const AbstractQoreNode *a);
267 
269 DLLEXPORT int getMicroSecZeroInt(const AbstractQoreNode *a);
270 
272 DLLEXPORT int64 getMicroSecZeroInt64(const AbstractQoreNode *a);
273 
275 static inline bool is_nothing(const AbstractQoreNode *n) {
276  if (!n || n->getType() == NT_NOTHING)
277  return true;
278 
279  return false;
280 }
281 
283 static inline void discard(AbstractQoreNode *n, ExceptionSink *xsink) {
284  if (n)
285  n->deref(xsink);
286 }
287 
288 static inline const char *get_type_name(const AbstractQoreNode *n) {
289  return n ? n->getTypeName() : "NOTHING";
290 }
291 
292 static inline qore_type_t get_node_type(const AbstractQoreNode *n) {
293  return n ? n->getType() : NT_NOTHING;
294 }
295 
296 class BinaryNode;
297 class QoreStringNode;
298 class ExceptionSink;
299 
301 DLLEXPORT BinaryNode *qore_deflate(void *ptr, unsigned long len, int level, ExceptionSink *xsink);
303 DLLEXPORT QoreStringNode *qore_inflate_to_string(const BinaryNode *b, const QoreEncoding *enc, ExceptionSink *xsink);
305 DLLEXPORT BinaryNode *qore_inflate_to_binary(const BinaryNode *b, ExceptionSink *xsink);
307 DLLEXPORT BinaryNode *qore_gzip(void *ptr, unsigned long len, int level, ExceptionSink *xsink);
309 DLLEXPORT QoreStringNode *qore_gunzip_to_string(const BinaryNode *bin, const QoreEncoding *enc, ExceptionSink *xsink);
311 DLLEXPORT BinaryNode *qore_gunzip_to_binary(const BinaryNode *bin, ExceptionSink *xsink);
313 DLLEXPORT BinaryNode *qore_bzip2(void *ptr, unsigned long len, int level, ExceptionSink *xsink);
315 DLLEXPORT QoreStringNode *qore_bunzip2_to_string(const BinaryNode *bin, const QoreEncoding *enc, ExceptionSink *xsink);
317 DLLEXPORT BinaryNode *qore_bunzip2_to_binary(const BinaryNode *bin, ExceptionSink *xsink);
318 
320 DLLEXPORT BinaryNode *parseBase64(const char *buf, int len, ExceptionSink *xsink);
321 
323 DLLEXPORT BinaryNode *parseHex(const char *buf, int len, ExceptionSink *xsink);
324 
325 class AbstractQoreZoneInfo;
326 
328 DLLEXPORT const AbstractQoreZoneInfo* findCreateOffsetZone(int seconds_east);
329 
331 
336 DLLEXPORT const AbstractQoreZoneInfo* find_create_timezone(const char* name, ExceptionSink* xsink);
337 
339 DLLEXPORT int tz_get_utc_offset(const AbstractQoreZoneInfo* tz, int64 epoch_offset, bool &is_dst, const char *&zone_name);
341 DLLEXPORT bool tz_has_dst(const AbstractQoreZoneInfo* tz);
343 DLLEXPORT const char* tz_get_region_name(const AbstractQoreZoneInfo* tz);
344 
346 #define QORE_OPT_ATOMIC_OPERATIONS "atomic operations"
347 
348 #define QORE_OPT_STACK_GUARD "stack guard"
349 
350 #define QORE_OPT_SIGNAL_HANDLING "signal handling"
351 
352 #define QORE_OPT_RUNTIME_STACK_TRACE "runtime stack tracing"
353 
354 #define QORE_OPT_LIBRARY_DEBUGGING "library debugging"
355 
356 #define QORE_OPT_SHA224 "openssl sha224"
357 
358 #define QORE_OPT_SHA256 "openssl sha256"
359 
360 #define QORE_OPT_SHA384 "openssl sha384"
361 
362 #define QORE_OPT_SHA512 "openssl sha512"
363 
364 #define QORE_OPT_MDC2 "openssl mdc2"
365 
366 #define QORE_OPT_RC5 "openssl rc5"
367 
368 #define QORE_OPT_MD2 "openssl md2"
369 
370 #define QORE_OPT_TERMIOS "termios"
371 
372 #define QORE_OPT_FILE_LOCKING "file locking"
373 
374 #define QORE_OPT_UNIX_USERMGT "unix user management"
375 
376 #define QORE_OPT_UNIX_FILEMGT "unix file management"
377 
378 #define QORE_OPT_FUNC_ROUND "round()"
379 
380 #define QORE_OPT_FUNC_TIMEGM "timegm()"
381 
382 #define QORE_OPT_FUNC_SETEUID "seteuid()"
383 
384 #define QORE_OPT_FUNC_SETEGID "setegid()"
385 
386 #define QORE_OPT_FUNC_SYSTEM "system()"
387 
388 #define QORE_OPT_FUNC_KILL "kill()"
389 
390 #define QORE_OPT_FUNC_FORK "fork()"
391 
392 #define QORE_OPT_FUNC_GETPPID "getppid()"
393 
394 #define QORE_OPT_FUNC_STATVFS "statvfs()"
395 
396 #define QORE_OPT_FUNC_SETSID "setsid()"
397 
398 #define QORE_OPT_FUNC_IS_EXECUTABLE "is_executable()"
399 
401 #define QO_OPTION 0
402 #define QO_ALGORITHM 1
403 #define QO_FUNCTION 2
404 
407  const char* option;
408  const char* constant;
409  int type;
410  bool value;
411 };
412 
414 DLLEXPORT QoreStringNode *q_strerror(int errnum);
416 DLLEXPORT void q_strerror(QoreString &str, int errnum);
417 
419 DLLEXPORT extern const qore_option_s *qore_option_list;
421 DLLEXPORT extern size_t qore_option_list_size;
422 
424 
428 DLLEXPORT QoreStringNode *qore_reassign_signal(int sig, const char *name);
429 
431 #define QORE_MAX(a, b) ((a) > (b) ? (a) : (b))
432 
434 #define QORE_MIN(a, b) ((a) < (b) ? (a) : (b))
435 
436 #define QORE_PARAM_NO_ARG (NULL)
437 
438 // define QORE_PATH_MAX
439 #ifndef QORE_PATH_MAX
440 #ifdef _XOPEN_PATH_MAX
441 #define QORE_PATH_MAX _XOPEN_PATH_MAX
442 #else
443 #define QORE_PATH_MAX 1024
444 #endif
445 #endif
446 
448 
450 DLLEXPORT void parse_set_time_zone(const char *zone);
451 
453 DLLEXPORT int qore_usleep(int64 usecs);
454 
456 DLLEXPORT bool q_path_is_readable(const char* path);
457 
459 DLLEXPORT bool q_parse_bool(const AbstractQoreNode* n);
460 
462 DLLEXPORT bool q_parse_bool(const char* str);
463 
465 DLLEXPORT bool q_get_option_value(const char* opt);
466 
468 DLLEXPORT bool q_get_option_constant_value(const char* opt);
469 
470 #endif // _QORE_QORELIB_H