1/***********************************************************************/
2/* GLOBAL.H: Declaration file used by all CONNECT implementations. */
3/* (C) Copyright MariaDB Corporation Ab */
4/* Author Olivier Bertrand 1993-2017 */
5/***********************************************************************/
6
7/***********************************************************************/
8/* Included C-definition files common to all Plug routines */
9/***********************************************************************/
10#include <string.h> /* String manipulation declares */
11#include <stdlib.h> /* C standard library */
12#include <ctype.h> /* C language specific types */
13#include <stdio.h> /* FOPEN_MAX declaration */
14#include <time.h> /* time_t type declaration */
15#include <setjmp.h> /* Long jump declarations */
16
17#if defined(__WIN__) && !defined(NOEX)
18#define DllExport __declspec( dllexport )
19#else // !__WIN__
20#define DllExport
21#endif // !__WIN__
22
23#if defined(DOMDOC_SUPPORT) || defined(LIBXML2_SUPPORT)
24#define XML_SUPPORT 1
25#endif
26
27#if defined(XMSG)
28//#error Option XMSG is not yet fully implemented
29// Definition used to read messages from message file.
30#include "msgid.h"
31#define MSG(I) PlugReadMessage(NULL, MSG_##I, #I)
32#define STEP(I) PlugReadMessage(g, MSG_##I, #I)
33#elif defined(NEWMSG)
34//#error Option NEWMSG is not yet fully implemented
35// Definition used to get messages from resource.
36#include "msgid.h"
37#define MSG(I) PlugGetMessage(NULL, MSG_##I)
38#define STEP(I) PlugGetMessage(g, MSG_##I)
39#else // !XMSG and !NEWMSG
40// Definition used to replace messages ID's by their definition.
41#include "messages.h"
42#define MSG(I) MSG_##I
43#define STEP(I) MSG_##I
44#endif // !XMSG and !NEWMSG
45
46#if defined(__WIN__)
47#define CRLF 2
48#else // !__WIN__
49#define CRLF 1
50#endif // !__WIN__
51
52/***********************************************************************/
53/* Define access to the thread based trace value. */
54/***********************************************************************/
55#define trace(T) (bool)(GetTraceValue() & (uint)T)
56
57/***********************************************************************/
58/* Miscellaneous Constants */
59/***********************************************************************/
60#define NO_IVAL -95684275 /* Used by GetIntegerOption */
61#define MAX_JUMP 24 /* Maximum jump level number */
62#define MAX_STR 4160 /* Maximum message length */
63
64#define TYPE_VOID -1
65#define TYPE_ERROR 0
66#define TYPE_STRING 1
67#define TYPE_DOUBLE 2
68#define TYPE_SHORT 3
69#define TYPE_TINY 4
70#define TYPE_BIGINT 5
71#define TYPE_LIST 6
72#define TYPE_INT 7
73#define TYPE_DATE 8
74#define TYPE_DECIM 9
75#define TYPE_BIN 10
76#define TYPE_PCHAR 11
77
78#if defined(__cplusplus)
79extern "C" {
80#endif
81
82/***********************************************************************/
83/* Static variables */
84/***********************************************************************/
85
86/***********************************************************************/
87/* File-Selection Indicators */
88/***********************************************************************/
89#define PAT_LOG "log"
90
91#if defined(UNIX) || defined(LINUX) || defined(UNIV_LINUX)
92 /*********************************************************************/
93 /* printf does not accept null pointer for %s target. */
94 /*********************************************************************/
95 #define SVP(S) ((S) ? S : "<null>")
96#else
97 /*********************************************************************/
98 /* printf accepts null pointer for %s target. */
99 /*********************************************************************/
100 #define SVP(S) S
101#endif
102
103#if defined(STORAGE)
104 FILE *debug;
105#else
106 extern FILE *debug;
107#endif
108
109
110/***********************************************************************/
111/* General purpose type definitions. */
112/***********************************************************************/
113#include "os.h"
114
115typedef uint OFFSET;
116typedef char NAME[9];
117
118typedef struct {
119 ushort Length;
120 char String[2];
121 } VARSTR;
122
123#if !defined(PGLOBAL_DEFINED)
124typedef struct _global *PGLOBAL;
125#define PGLOBAL_DEFINED
126#endif
127typedef struct _globplg *PGS;
128typedef struct _activity *PACTIVITY;
129typedef struct _parm *PPARM;
130
131/***********************************************************************/
132/* Segment Sub-Allocation block structure declares. */
133/* Next block is an implementation dependent segment suballoc save */
134/* structure used to keep the suballocation system offsets and to */
135/* restore them if needed. This scheme implies that no SubFree be used */
136/***********************************************************************/
137typedef struct { /* Plug Area SubAlloc header */
138 OFFSET To_Free; /* Offset of next free block */
139 uint FreeBlk; /* Size of remaining free memory */
140 } POOLHEADER, *PPOOLHEADER;
141
142/***********************************************************************/
143/* Language block. Containing all global information for the language */
144/* this block is saved and retrieved with the language. Information */
145/* in this block can be set and modified under Grammar editing. */
146/***********************************************************************/
147#if defined(BIT64)
148typedef int TIME_T; /* Lang block size must not change */
149#else // BIT32
150typedef time_t TIME_T; /* time_t */
151#endif // BIT32
152
153typedef struct {
154 uint Memsize;
155 uint Size;
156 } AREADEF;
157
158typedef struct Lang_block {
159 NAME LangName; /* Language name */
160 NAME Application; /* Application name */
161 } LANG, *PLANG;
162
163/***********************************************************************/
164/* Application block. It contains all global information for the */
165/* current parse and execution using the corresponding language. */
166/* This block is dynamically allocated and set at language init. */
167/***********************************************************************/
168typedef struct _activity { /* Describes activity and language */
169 void *Aptr; /* Points to user work area(s) */
170 NAME Ap_Name; /* Current application name */
171 } ACTIVITY;
172
173/*---------------- UNIT ?????????? VERSION ? ----------------------*/
174typedef struct _parm {
175 union {
176 void *Value;
177 int Intval;
178 }; // end union
179 short Type, Domain;
180 PPARM Next;
181 } PARM;
182
183/***********************************************************************/
184/* Global Structure Block. This block contains, or points to, all */
185/* information used by CONNECT tables. Passed as an argument */
186/* to any routine allows it to have access to the entire information */
187/* currently available for the whole set of loaded languages. */
188/***********************************************************************/
189typedef struct _global { /* Global structure */
190 void *Sarea; /* Points to work area */
191 uint Sarea_Size; /* Work area size */
192 PACTIVITY Activityp;
193 char Message[MAX_STR];
194 ulong More; /* Used by jsonudf */
195 int Createas; /* To pass info to created table */
196 void *Xchk; /* indexes in create/alter */
197 short Alchecked; /* Checked for ALTER */
198 short Mrr; /* True when doing mrr */
199 int N; /* Utility */
200 int jump_level;
201 jmp_buf jumper[MAX_JUMP + 2];
202 } GLOBAL;
203
204/***********************************************************************/
205/* Exported routine declarations. */
206/***********************************************************************/
207#if defined(XMSG)
208DllExport char *PlugReadMessage(PGLOBAL, int, char *);
209#elif defined(NEWMSG)
210DllExport char *PlugGetMessage(PGLOBAL, int);
211#endif // XMSG || NEWMSG
212#if defined(__WIN__)
213DllExport short GetLineLength(PGLOBAL); // Console line length
214#endif // __WIN__
215DllExport PGLOBAL PlugInit(LPCSTR, uint); // Plug global initialization
216DllExport int PlugExit(PGLOBAL); // Plug global termination
217DllExport LPSTR PlugRemoveType(LPSTR, LPCSTR);
218DllExport LPCSTR PlugSetPath(LPSTR to, LPCSTR prefix, LPCSTR name, LPCSTR dir);
219DllExport BOOL PlugIsAbsolutePath(LPCSTR path);
220DllExport bool AllocSarea(PGLOBAL, uint);
221DllExport void FreeSarea(PGLOBAL);
222DllExport BOOL PlugSubSet(PGLOBAL, void *, uint);
223DllExport char *PlugDup(PGLOBAL g, const char *str);
224DllExport void *MakePtr(void *, OFFSET);
225DllExport void htrc(char const *fmt, ...);
226//DllExport int GetTraceValue(void);
227DllExport uint GetTraceValue(void);
228
229#if defined(__cplusplus)
230} // extern "C"
231#endif
232
233/***********************************************************************/
234/* Non exported routine declarations. */
235/***********************************************************************/
236void *PlugSubAlloc(PGLOBAL, void *, size_t); // Does throw
237
238/*-------------------------- End of Global.H --------------------------*/
239