1106406c89e18eda923988764c8a25015e78b52f
[com/gs-lite.git] / include / hfta / hfta_runtime_library.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 __HFTA_RUNTIME_LIBRARY__
17 #define __HFTA_RUNTIME_LIBRARY__
18 #include "host_tuple.h"
19 #include "gsconfig.h"
20 #include "gstypes.h"
21
22
23 #define string_hash(s) hfta_vstr_hashfunc(s)
24 #define string_hash_long(s) hfta_vstr_long_hashfunc(s) 
25
26
27 #define DNS_SAMPLE_HASH_SZ 50000000
28 #define DNS_HITLIST_HASH_SZ 50000000
29 #define DNS_HITLIST_ENTRY_SZ 500000
30
31
32 //              Internal functions
33 gs_retval_t Vstring_Constructor(vstring *, gs_csp_t);
34 gs_retval_t hfta_vstr_length(vstring *);
35 void hfta_vstr_assign_with_copy_in_tuple(vstring32 *, const vstring *,
36         gs_sp_t, int);
37 void hfta_vstr_assign_with_copy(vstring *, const vstring *);
38 void hfta_vstr_destroy(vstring *);
39 void hfta_vstr_replace(vstring *, const vstring *);
40
41 gs_uint32_t hfta_vstr_hashfunc(const vstring *);
42 gs_uint64_t hfta_vstr_long_hashfunc(const vstring *);
43 gs_retval_t hfta_vstr_compare(const vstring *, const vstring *);
44 gs_retval_t hfta_vstr_equal(const vstring *, const vstring *);
45
46 gs_retval_t hfta_ipv6_compare(const hfta_ipv6_str &i1, const hfta_ipv6_str &i2);
47 hfta_ipv6_str And_Ipv6(const hfta_ipv6_str &i1, const hfta_ipv6_str &i2);
48 hfta_ipv6_str Or_Ipv6(const hfta_ipv6_str &i1, const hfta_ipv6_str &i2);
49 gs_uint32_t hfta_ipv6_hashfunc(const hfta_ipv6_str *s) ;
50 hfta_ipv6_str hton_ipv6(hfta_ipv6_str s);
51 hfta_ipv6_str ntoh_ipv6(hfta_ipv6_str s);
52 gs_retval_t HFTA_Ipv6_Constructor(hfta_ipv6_str *s, gs_csp_t l) ;
53
54
55
56
57 //              External functions
58
59 inline static gs_retval_t str_truncate(vstring * result, vstring *str, gs_uint32_t length) {
60         result->offset=str->offset;
61         result->length=(str->length<length)?str->length:length;
62         result->reserved=SHALLOW_COPY;
63         return 0;
64 }
65
66 gs_retval_t str_exists_substr(vstring * s1, vstring * s2);
67 gs_retval_t str_compare(vstring * s1, vstring * s2);
68 gs_retval_t str_equal(vstring * s1, vstring * s2);
69
70 gs_uint32_t str_match_offset(gs_uint32_t offset,vstring *s1,vstring *s2);
71 gs_uint32_t byte_match_offset( gs_uint32_t offset, gs_uint32_t val,vstring *s2);
72
73
74 // REGEX functions
75
76 gs_retval_t str_regex_match(vstring* str, gs_param_handle_t pattern_handle);
77 gs_param_handle_t register_handle_for_str_regex_match_slot_1(vstring* pattern);
78 gs_retval_t deregister_handle_for_str_regex_match_slot_1(gs_param_handle_t handle);
79
80 gs_retval_t str_partial_regex_match(vstring* str, gs_param_handle_t pattern_handle);
81 gs_param_handle_t register_handle_for_str_partial_regex_match_slot_1(vstring* pattern);
82 gs_retval_t deregister_handle_for_str_partial_regex_match_slot_1(gs_param_handle_t handle);
83
84 gs_param_handle_t register_handle_for_str_extract_regex_slot_1(vstring* pattern);
85 gs_retval_t str_extract_regex( vstring * result, vstring * str, gs_param_handle_t handle);
86 gs_retval_t deregister_handle_for_str_extract_regex_slot_1(gs_param_handle_t handle);
87
88
89
90
91 // type conversion
92 //              Avoid redefinition from rts_udaf.h
93 #ifndef INT
94         #define INT(c) ((int)(c))
95         #define UINT(c) ((gs_uint32_t)(c))
96         #define FLOAT(c) ((gs_float_t)(c))
97         #define LLONG(c) ((long long int)(c))
98         #define ULLONG(c) ((gs_uint64_t)(c))
99 #endif
100
101 // string conversions
102
103 gs_uint32_t strtoi(gs_uint32_t * r, struct vstring *data);
104 gs_uint32_t strtoip(gs_uint32_t * r, struct vstring *data);
105
106 //      constant string conversions
107 //              Avoid redefinition from rts_udaf.h
108 #ifndef strtoi_c
109         #define strtoi_c(h) ((gs_uint32_t)(h))
110         #define strtoip_c(h) ((gs_uint32_t)(h))
111 #endif
112 gs_param_handle_t register_handle_for_strtoi_c_slot_0(vstring* istr) ;
113 gs_retval_t deregister_handle_for_strtoi_c_slot_0(gs_param_handle_t h) ;
114
115 gs_param_handle_t register_handle_for_strtoip_c_slot_0(vstring* istr) ;
116 gs_retval_t deregister_handle_for_strtoip_c_slot_0(gs_param_handle_t h) ;
117
118
119 inline gs_uint32_t str_match_offset( gs_uint32_t offset, struct vstring * s1, struct vstring * s2) {
120         register gs_uint8_t *st1 = (gs_uint8_t *) s1->offset;
121         register gs_uint8_t *st2 = (gs_uint8_t *) (s2->offset+offset);
122         register gs_int32_t x;
123         register gs_int32_t len2 = s2->length-offset;
124         register gs_int32_t len1 = s1->length;
125         if (len2<len1) return 0;
126         for(x=0; x<len1; x++) {
127                 if (st1[x]!=st2[x]) return 0;
128         }
129         return 1;
130 }
131
132 // -------------------------------------------------------
133 //              map_int_to_string and its support functions, structs
134
135 gs_param_handle_t register_handle_for_int_to_string_map_slot_1(vstring *filename);
136 gs_retval_t int_to_string_map(vstring *result, gs_int64_t val, gs_param_handle_t handle);
137 gs_param_handle_t deregister_handle_for_int_to_string_map_slot_1(gs_param_handle_t handle);
138
139
140 #endif