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 __HFTA_RUNTIME_LIBRARY__
17 #define __HFTA_RUNTIME_LIBRARY__
18 #include "host_tuple.h"
23 #define string_hash(s) hfta_vstr_hashfunc(s)
24 #define string_hash_long(s) hfta_vstr_long_hashfunc(s)
27 #define DNS_SAMPLE_HASH_SZ 50000000
28 #define DNS_HITLIST_HASH_SZ 50000000
29 #define DNS_HITLIST_ENTRY_SZ 500000
33 void hfta_vstr_init(vstring * str);
34 gs_retval_t Vstring_Constructor(vstring *, gs_csp_t);
35 gs_retval_t hfta_vstr_length(vstring *);
36 void hfta_vstr_assign_with_copy_in_tuple(vstring32 *, const vstring *,
38 void hfta_vstr_assign_with_copy(vstring *, const vstring *);
39 void hfta_vstr_destroy(vstring *);
40 void hfta_vstr_replace(vstring *, const vstring *);
42 gs_uint32_t hfta_vstr_hashfunc(const vstring *);
43 gs_uint64_t hfta_vstr_long_hashfunc(const vstring *);
44 gs_retval_t hfta_vstr_compare(const vstring *, const vstring *);
45 gs_retval_t hfta_vstr_equal(const vstring *, const vstring *);
47 gs_retval_t hfta_ipv6_compare(const hfta_ipv6_str &i1, const hfta_ipv6_str &i2);
48 hfta_ipv6_str And_Ipv6(const hfta_ipv6_str &i1, const hfta_ipv6_str &i2);
49 hfta_ipv6_str Or_Ipv6(const hfta_ipv6_str &i1, const hfta_ipv6_str &i2);
50 gs_uint32_t hfta_ipv6_hashfunc(const hfta_ipv6_str *s) ;
51 hfta_ipv6_str hton_ipv6(hfta_ipv6_str s);
52 hfta_ipv6_str ntoh_ipv6(hfta_ipv6_str s);
53 gs_retval_t HFTA_Ipv6_Constructor(hfta_ipv6_str *s, gs_csp_t l) ;
60 inline static gs_retval_t str_truncate(vstring * result, vstring *str, gs_uint32_t length) {
61 result->offset=str->offset;
62 result->length=(str->length<length)?str->length:length;
63 result->reserved=SHALLOW_COPY;
67 gs_retval_t str_exists_substr(vstring * s1, vstring * s2);
68 gs_retval_t str_compare(vstring * s1, vstring * s2);
69 gs_retval_t str_equal(vstring * s1, vstring * s2);
71 gs_uint32_t str_match_offset(gs_uint32_t offset,vstring *s1,vstring *s2);
72 gs_uint32_t byte_match_offset( gs_uint32_t offset, gs_uint32_t val,vstring *s2);
77 gs_retval_t str_regex_match(vstring* str, gs_param_handle_t pattern_handle);
78 gs_param_handle_t register_handle_for_str_regex_match_slot_1(vstring* pattern);
79 gs_retval_t deregister_handle_for_str_regex_match_slot_1(gs_param_handle_t handle);
81 gs_retval_t str_partial_regex_match(vstring* str, gs_param_handle_t pattern_handle);
82 gs_param_handle_t register_handle_for_str_partial_regex_match_slot_1(vstring* pattern);
83 gs_retval_t deregister_handle_for_str_partial_regex_match_slot_1(gs_param_handle_t handle);
85 gs_param_handle_t register_handle_for_str_extract_regex_slot_1(vstring* pattern);
86 gs_retval_t str_extract_regex( vstring * result, vstring * str, gs_param_handle_t handle);
87 gs_retval_t deregister_handle_for_str_extract_regex_slot_1(gs_param_handle_t handle);
93 // Avoid redefinition from rts_udaf.h
95 #define INT(c) ((int)(c))
96 #define UINT(c) ((gs_uint32_t)(c))
97 #define FLOAT(c) ((gs_float_t)(c))
98 #define LLONG(c) ((long long int)(c))
99 #define ULLONG(c) ((gs_uint64_t)(c))
102 // string conversions
104 gs_uint32_t strtoi(gs_uint32_t * r, struct vstring *data);
105 gs_uint32_t strtoip(gs_uint32_t * r, struct vstring *data);
107 // constant string conversions
108 // Avoid redefinition from rts_udaf.h
110 #define strtoi_c(h) ((gs_uint32_t)(h))
111 #define strtoip_c(h) ((gs_uint32_t)(h))
113 gs_param_handle_t register_handle_for_strtoi_c_slot_0(vstring* istr) ;
114 gs_retval_t deregister_handle_for_strtoi_c_slot_0(gs_param_handle_t h) ;
116 gs_param_handle_t register_handle_for_strtoip_c_slot_0(vstring* istr) ;
117 gs_retval_t deregister_handle_for_strtoip_c_slot_0(gs_param_handle_t h) ;
120 inline gs_uint32_t str_match_offset( gs_uint32_t offset, struct vstring * s1, struct vstring * s2) {
121 register gs_uint8_t *st1 = (gs_uint8_t *) s1->offset;
122 register gs_uint8_t *st2 = (gs_uint8_t *) (s2->offset+offset);
123 register gs_int32_t x;
124 register gs_int32_t len2 = s2->length-offset;
125 register gs_int32_t len1 = s1->length;
126 if (len2<len1) return 0;
127 for(x=0; x<len1; x++) {
128 if (st1[x]!=st2[x]) return 0;
133 // -------------------------------------------------------
134 // map_int_to_string and its support functions, structs
136 gs_param_handle_t register_handle_for_int_to_string_map_slot_1(vstring *filename);
137 gs_retval_t int_to_string_map(vstring *result, gs_int64_t val, gs_param_handle_t handle);
138 gs_param_handle_t deregister_handle_for_int_to_string_map_slot_1(gs_param_handle_t handle);