Add new udafs and RMR support to gsprintconsole_ves
[com/gs-lite.git] / include / schemaparser.h
1 /* ------------------------------------------------
2 Copyright 2014 AT&T Intellectual Property
3    Licensed under the Apache License, Version 2.0 (the "License");
4    you may not use this file except in compliance with the License.
5    You may obtain a copy of the License at
6
7      http://www.apache.org/licenses/LICENSE-2.0
8
9    Unless required by applicable law or agreed to in writing, software
10    distributed under the License is distributed on an "AS IS" BASIS,
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12    See the License for the specific language governing permissions and
13    limitations under the License.
14  ------------------------------------------- */
15
16 #ifndef __INTERFACE_LIB_INCLUDED__
17 #define __INTERFACE_LIB_INCLUDED__
18 #include "gsconfig.h"
19 #include "gstypes.h"
20
21 #include<stdio.h>
22 #include "byteswap.h"
23 #include "type_indicators.h"
24 #include "fta.h"
25 #include <fta_stat.h>
26 /* #include"type_objects.h"             */
27 /* #include"parse_fta.h"                */
28
29
30 /*//////////////////////////////////////////////////////
31 ////                    Include data type definitions.  */
32
33 /*                      Include vstring.h to get the vstring definition. */
34
35 /* XXXX OS This data definitions and prototypes are mirrored in schemaparser.h
36  * any changes have to be reflected there !!
37  */
38
39 #include"vstring.h"
40
41 #include<sys/time.h>
42 /*
43 #ifndef _TIMEVAL_T
44 #define _TIMEVAL_T
45 struct timeval {
46     long  tv_sec;
47     long  tv_usec;
48 };
49 #endif
50 */
51
52 struct fstring_str{
53         gs_int32_t size;
54         gs_sp_t data;   // gs_int8_t *
55 };
56
57 /*                      Universal result holder.        */
58 #ifndef _struct_access_result_defined_
59 #define _struct_access_result_defined_
60 struct access_result {
61         int field_data_type; // as defined
62         union {
63                 gs_int32_t i;
64                 gs_uint32_t ui;
65                 gs_int64_t l;
66                 gs_uint64_t ul;
67                 gs_float_t f;
68                 struct timeval t;               // defined in sys/time.h
69                 struct vstring vs;
70                 struct fstring_str fs;
71                 struct hfta_ipv6_str ip6;
72         } r;
73 };
74 #endif
75
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79
80
81 /*//////////////////////////////////////
82 ////            Version functions               */
83
84 gs_int32_t get_schemaparser_version();
85 gs_int32_t *get_schemaparser_accepted_versions();       // returns zero-terminated array
86 gs_int32_t schemaparser_accepts_version(gs_int32_t v);  // 1 if true, 0 o'wise.
87
88
89 /*/////////////////////////////////////////////////
90 ////                    Helper functions        */
91
92 // int fta_field_size(int dt, int *is_udef);
93
94
95 /*///////////////////////////////////////////////////
96 ////                    Interface functions     */
97
98
99 /*///   FTA management          ////////////// */
100
101 /*                      Create a new schema representation, return
102                         an integer handle.
103                         Input is a char array with the stream schema.
104                         returns -1 on error.
105                         Diagnostics written to stderr.
106                         use the _prot version to also to accept a PROTOCOL (table)
107 */
108
109 gs_schemahandle_t ftaschema_parse_string(gs_csp_t f);   // gs_csp_t is const char *
110 gs_schemahandle_t ftaschema_parse_string_prot(gs_csp_t f);      // gs_csp_t is const char *
111
112 /*                      Create a new schema representation, return
113                         an integer handle.
114                         Input is a STREAM schema in a file.
115                         use the _prot version to also to accept a PROTOCOL (table)
116                         returns -1 on error.
117                         Diagnostics written to stderr.
118 */
119 gs_schemahandle_t ftaschema_parse_file(FILE *f);
120 gs_schemahandle_t ftaschema_parse_file_prot(FILE *f);
121
122 /*                      Release memory used by the schema representation.
123                         return non-zero on error.
124 */
125 gs_int32_t ftaschema_free(gs_schemahandle_t sh);        // gs_sp_t is char *
126
127 /* name of fta schema null terminated */
128 /* Returns NULL if sh is out of bounds. */
129 /* NO ALLOCATION IS PERFORMED!   Must treat result as const. */
130 gs_sp_t ftaschema_name(gs_schemahandle_t sh);
131
132 /*              key of fta
133                 This function is omitted because we are using name only.
134 FTAkey * ftaschema_key(schema_handle sh);
135 */
136
137 /*/////         Tuple management        //////////////////// */
138
139 /* number of entries in a tuple */
140 /* Return -1 if the schema handle is out of range.      */
141 gs_int32_t ftaschema_tuple_len(gs_schemahandle_t sh);
142
143
144 /* tuple entry name */
145 /* Returns NULL if sh or index is out of bounds.        */
146 /* NO ALLOCATION IS PERFORMED!   Must treat result as const. */
147 gs_sp_t ftaschema_field_name(gs_schemahandle_t sh, gs_uint32_t index);
148
149
150 /* returns field offset by name (for direct access)  */
151 /* if sh is out of bounds, or if fieldname is not the name of a field,
152    or len is too small,
153    return value is -1 (field_offset) / UNDEFINED_TYPE (field_type)
154         gs_sp_t is char *
155 */
156 gs_int32_t ftaschema_get_field_offset_by_name(gs_schemahandle_t sh, gs_csp_t fieldname);
157 gs_int32_t ftaschema_get_field_type_by_name(gs_schemahandle_t sh, gs_csp_t fieldname);
158
159 /* get field_offset, field_type bu index instead of name */
160 gs_int32_t ftaschema_get_field_offset_by_index(gs_schemahandle_t sh, gs_int32_t index);
161 gs_int32_t ftaschema_get_field_type_by_index(gs_schemahandle_t sh, gs_int32_t index);
162
163
164 /* returns field value based on name */
165 /* if sh is out of bounds, or if fieldname is not the name of a field,
166    or len is too small,
167    return value is of type UNDEFINED_TYPE
168    NO COPYING IS PERFORMED FOR vstring TYPES.
169         gs_sp_t is char *
170 */
171 struct access_result ftaschema_get_field_by_name(gs_schemahandle_t sh,
172                                 gs_csp_t fieldname, void * data, gs_int32_t len);
173
174 /* return field value by index */
175 /* if sh is out of bounds, or if fieldname is not the name of a field,
176    or len is too small,
177    return value is of type UNDEFINED_TYPE
178    NO COPYING IS PERFORMED FOR vstring TYPES.
179 */
180 struct access_result ftaschema_get_field_by_index(gs_schemahandle_t sh,
181                                 gs_uint32_t index, void * data, gs_uint32_t len);
182
183 /* The following functions deals with temporal status tuples */
184
185 //              Get location of eof, temporal-tuple metadata.
186 gs_int32_t ftaschema_get_tuple_metadata_offset(gs_schemahandle_t sh);
187
188 /* checks whether tuple is temporal
189   return value 1 indicates that tuple istemporal, 0 - not temporal
190 */
191 gs_int32_t ftaschema_is_temporal_tuple(gs_int32_t schema_handle, void *data);
192 //gs_int32_t ftaschema_is_temporal_tuple_offset(int metadata_offset, void *data) ;
193 #define ftaschema_is_temporal_tuple_offset(metadata_offset,data) (*((gs_sp_t)(data) + (metadata_offset)) == TEMPORAL_TUPLE)
194
195 /* checks whether tuple is special end-of_file tuple
196   return value 1 indicates that tuple is eof_tuple, 0 - otherwise
197 */
198 gs_int32_t ftaschema_is_eof_tuple(gs_int32_t schema_handle, void *data);
199 gs_int32_t ftaschema_is_eof_tuple_offset(int metadata_offset, void *data) ;
200
201
202
203
204
205 /* extracts the trace from the temporal tuple */
206 gs_int32_t ftaschema_get_trace(gs_int32_t schema_handle, void* data,
207         gs_int32_t len,
208         gs_uint64_t * trace_id, gs_uint32_t* sz, fta_stat** trace );
209
210
211 /*      The following functions operate directly on the tuple
212     to return field values.  Problem set to 1 if the len is too small.
213     unpack_vstr does not make a copy of the buffer.
214         Neither does unpack_fstring
215 */
216 gs_uint32_t fta_unpack_uint(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
217 gs_uint32_t fta_unpack_ushort(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
218 gs_uint32_t fta_unpack_bool(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
219 gs_int32_t fta_unpack_int(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
220 gs_uint64_t fta_unpack_ullong(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
221 gs_int64_t fta_unpack_llong(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
222 gs_float_t fta_unpack_float(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
223 struct timeval fta_unpack_timeval(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
224 struct vstring fta_unpack_vstr(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
225 struct hfta_ipv6_str fta_unpack_ipv6(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
226 gs_sp_t fta_unpack_fstring(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
227
228 gs_uint32_t fta_unpack_uint_nocheck(void *data, gs_uint32_t offset);
229 gs_uint32_t fta_unpack_ushort_nocheck(void *data, gs_uint32_t offset);
230 gs_uint32_t fta_unpack_bool_nocheck(void *data, gs_uint32_t offset);
231 gs_int32_t fta_unpack_int_nocheck(void *data, gs_uint32_t offset);
232 gs_uint64_t fta_unpack_ullong_nocheck(void *data, gs_uint32_t offset);
233 gs_int64_t fta_unpack_llong_nocheck(void *data, gs_uint32_t offset);
234 gs_float_t fta_unpack_float_nocheck(void *data, gs_uint32_t offset);
235 struct timeval fta_unpack_timeval_nocheck(void *data, gs_uint32_t offset);
236 struct hfta_ipv6_str fta_unpack_ipv6_nocheck(void *data, gs_uint32_t offset);
237
238 //              THe same as above, but no ntoh xform
239 gs_uint32_t fta_unpack_uint_noxf(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
240 gs_uint32_t fta_unpack_ushort_noxf(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
241 gs_uint32_t fta_unpack_bool_noxf(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
242 gs_int32_t fta_unpack_int_noxf(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
243 gs_uint64_t fta_unpack_ullong_noxf(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
244 gs_int64_t fta_unpack_llong_noxf(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
245 gs_float_t fta_unpack_float_noxf(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
246 struct timeval fta_unpack_timeval_noxf(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
247 struct hfta_ipv6_str fta_unpack_ipv6_noxf(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
248 struct vstring fta_unpack_vstr_noxf(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
249 gs_sp_t fta_unpack_fstring_noxf(void *data, gs_int32_t len, gs_uint32_t offset, gs_int32_t *problem);
250
251 gs_uint32_t fta_unpack_uint_noxf_nocheck(void *data, gs_uint32_t offset);
252 gs_uint32_t fta_unpack_ushort_noxf_nocheck(void *data, gs_uint32_t offset);
253 gs_uint32_t fta_unpack_bool_noxf_nocheck(void *data, gs_uint32_t offset);
254 gs_int32_t fta_unpack_int_noxf_nocheck(void *data, gs_uint32_t offset);
255 gs_uint64_t fta_unpack_ullong_noxf_nocheck(void *data, gs_uint32_t offset);
256 gs_int64_t fta_unpack_llong_noxf_nocheck(void *data, gs_uint32_t offset);
257 gs_float_t fta_unpack_float_noxf_nocheck(void *data, gs_uint32_t offset);
258 struct timeval fta_unpack_timeval_noxf_nocheck(void *data, gs_uint32_t offset);
259 struct hfta_ipv6_str fta_unpack_ipv6_noxf_nocheck(void *data, gs_uint32_t offset);
260
261
262
263 /*///////               Param block management          ///////////////*/
264
265
266 /* number of parameters */
267 /*      Return -1 if sh is out of bounds        */
268 gs_int32_t ftaschema_parameter_len(gs_schemahandle_t sh);
269
270 /* parameter entry name */
271 /*      Return NULL if sh or index is out of bounds.    */
272 /*      NO COPYING IS PERFORMED */
273 gs_sp_t ftaschema_parameter_name(gs_schemahandle_t sh, gs_uint32_t index);
274
275 /*
276                 No need to create param handles, it is done at schema parse time.
277                 (downside: must be careful to set all parameters if
278                  the user sends param blocks to multiple instances)
279
280          creates a parameter structure handle for a particular schema
281 paramhandle ftaschema_create_paramhandle(schema_handle sh);
282
283          frees a parameter structure handle
284 int ftaschema_free_paramhandle(paramhandle ph);
285 */
286
287
288 /* set parameter value for parameter handle */
289 /*      Pass in the parameter in its char string representation. */
290 /*  Return value is -1 on error, else 0 */
291 gs_int32_t ftaschema_setparam_by_name(gs_schemahandle_t sh, gs_sp_t param_name,
292                                gs_sp_t param_val, gs_int32_t len);
293
294 /* set parameter value for parameter handle */
295 /*      Pass in the parameter in its char string representation. */
296 /*  Return value is -1 on error, else 0 */
297 gs_int32_t ftaschema_setparam_by_index(gs_schemahandle_t sh, gs_int32_t index,
298                                 gs_sp_t param_val, gs_int32_t len);
299
300 /* creates the parameter block which can be passed in control and
301    init operations. The function allocates the memory returned and
302    the caller is responsible to free it.
303    Return value is -1 on error, else 0.
304    ALL VALUES CONVERTED TO NETWORK BYTE ORDER
305    */
306
307 gs_int32_t ftaschema_create_param_block(gs_schemahandle_t sh, void ** block, gs_int32_t * size);
308
309 //void ftaschema_debugdump(int handle);
310
311 #ifdef __cplusplus
312 }
313 #endif
314
315
316 #endif
317