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
7 http://www.apache.org/licenses/LICENSE-2.0
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 ------------------------------------------- */
16 #ifndef __INTERFACE_LIB_INCLUDED__
17 #define __INTERFACE_LIB_INCLUDED__
23 #include "type_indicators.h"
26 /* #include"type_objects.h" */
27 /* #include"parse_fta.h" */
30 /*//////////////////////////////////////////////////////
31 //// Include data type definitions. */
33 /* Include vstring.h to get the vstring definition. */
35 /* XXXX OS This data definitions and prototypes are mirrored in schemaparser.h
36 * any changes have to be reflected there !!
54 gs_sp_t data; // gs_int8_t *
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
68 struct timeval t; // defined in sys/time.h
70 struct fstring_str fs;
71 struct hfta_ipv6_str ip6;
81 /*//////////////////////////////////////
82 //// Version functions */
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.
89 /*/////////////////////////////////////////////////
90 //// Helper functions */
92 // int fta_field_size(int dt, int *is_udef);
95 /*///////////////////////////////////////////////////
96 //// Interface functions */
99 /*/// FTA management ////////////// */
101 /* Create a new schema representation, return
103 Input is a char array with the stream schema.
105 Diagnostics written to stderr.
106 use the _prot version to also to accept a PROTOCOL (table)
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 *
112 /* Create a new schema representation, return
114 Input is a STREAM schema in a file.
115 use the _prot version to also to accept a PROTOCOL (table)
117 Diagnostics written to stderr.
119 gs_schemahandle_t ftaschema_parse_file(FILE *f);
120 gs_schemahandle_t ftaschema_parse_file_prot(FILE *f);
122 /* Release memory used by the schema representation.
123 return non-zero on error.
125 gs_int32_t ftaschema_free(gs_schemahandle_t sh); // gs_sp_t is char *
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);
133 This function is omitted because we are using name only.
134 FTAkey * ftaschema_key(schema_handle sh);
137 /*///// Tuple management //////////////////// */
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);
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);
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,
153 return value is -1 (field_offset) / UNDEFINED_TYPE (field_type)
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);
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);
164 /* returns field value based on name */
165 /* if sh is out of bounds, or if fieldname is not the name of a field,
167 return value is of type UNDEFINED_TYPE
168 NO COPYING IS PERFORMED FOR vstring TYPES.
171 struct access_result ftaschema_get_field_by_name(gs_schemahandle_t sh,
172 gs_csp_t fieldname, void * data, gs_int32_t len);
174 /* return field value by index */
175 /* if sh is out of bounds, or if fieldname is not the name of a field,
177 return value is of type UNDEFINED_TYPE
178 NO COPYING IS PERFORMED FOR vstring TYPES.
180 struct access_result ftaschema_get_field_by_index(gs_schemahandle_t sh,
181 gs_uint32_t index, void * data, gs_uint32_t len);
183 /* The following functions deals with temporal status tuples */
185 // Get location of eof, temporal-tuple metadata.
186 gs_int32_t ftaschema_get_tuple_metadata_offset(gs_schemahandle_t sh);
188 /* checks whether tuple is temporal
189 return value 1 indicates that tuple istemporal, 0 - not temporal
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)
195 /* checks whether tuple is special end-of_file tuple
196 return value 1 indicates that tuple is eof_tuple, 0 - otherwise
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) ;
205 /* extracts the trace from the temporal tuple */
206 gs_int32_t ftaschema_get_trace(gs_int32_t schema_handle, void* data,
208 gs_uint64_t * trace_id, gs_uint32_t* sz, fta_stat** trace );
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
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);
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);
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);
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);
263 /*/////// Param block management ///////////////*/
266 /* number of parameters */
267 /* Return -1 if sh is out of bounds */
268 gs_int32_t ftaschema_parameter_len(gs_schemahandle_t sh);
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);
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)
280 creates a parameter structure handle for a particular schema
281 paramhandle ftaschema_create_paramhandle(schema_handle sh);
283 frees a parameter structure handle
284 int ftaschema_free_paramhandle(paramhandle ph);
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);
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);
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
307 gs_int32_t ftaschema_create_param_block(gs_schemahandle_t sh, void ** block, gs_int32_t * size);
309 //void ftaschema_debugdump(int handle);