Fixed newline characters throughout the code
[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 #define DNS_SAMPLE_HASH_SZ 50000000
23 #define DNS_HITLIST_HASH_SZ 50000000
24 #define DNS_HITLIST_ENTRY_SZ 500000
25
26
27 //              Internal functions
28 gs_retval_t Vstring_Constructor(vstring *, gs_csp_t);
29 gs_retval_t hfta_vstr_length(vstring *);
30 void hfta_vstr_assign_with_copy_in_tuple(vstring32 *, vstring *, gs_sp_t, int);
31 void hfta_vstr_assign_with_copy(vstring *, vstring *);
32 void hfta_vstr_destroy(vstring *);
33 void hfta_vstr_replace(vstring *, vstring *);
34
35 gs_uint32_t hfta_vstr_hashfunc(const vstring *);
36 gs_retval_t hfta_vstr_compare(const vstring *, const vstring *);
37
38 gs_retval_t hfta_ipv6_compare(const hfta_ipv6_str &i1, const hfta_ipv6_str &i2);
39 hfta_ipv6_str And_Ipv6(const hfta_ipv6_str &i1, const hfta_ipv6_str &i2);
40 hfta_ipv6_str Or_Ipv6(const hfta_ipv6_str &i1, const hfta_ipv6_str &i2);
41 gs_uint32_t hfta_ipv6_hashfunc(const hfta_ipv6_str *s) ;
42 hfta_ipv6_str hton_ipv6(hfta_ipv6_str s);
43 hfta_ipv6_str ntoh_ipv6(hfta_ipv6_str s);
44 gs_retval_t HFTA_Ipv6_Constructor(hfta_ipv6_str *s, gs_csp_t l) ;
45
46
47
48
49 //              External functions
50
51 inline static gs_retval_t str_truncate(vstring * result, vstring *str, gs_uint32_t length) {
52         result->offset=str->offset;
53         result->length=(str->length<length)?str->length:length;
54         result->reserved=SHALLOW_COPY;
55         return 0;
56 }
57
58 gs_retval_t str_exists_substr(vstring * s1, vstring * s2);
59 gs_retval_t str_compare(vstring * s1, vstring * s2);
60
61 gs_uint32_t str_match_offset(gs_uint32_t offset,vstring *s1,vstring *s2);
62 gs_uint32_t byte_match_offset( gs_uint32_t offset, gs_uint32_t val,vstring *s2);
63
64
65 // REGEX functions
66
67 gs_retval_t str_regex_match(vstring* str, gs_param_handle_t pattern_handle);
68 gs_param_handle_t register_handle_for_str_regex_match_slot_1(vstring* pattern);
69 gs_retval_t deregister_handle_for_str_regex_match_slot_1(gs_param_handle_t handle);
70
71 gs_retval_t str_partial_regex_match(vstring* str, gs_param_handle_t pattern_handle);
72 gs_param_handle_t register_handle_for_str_partial_regex_match_slot_1(vstring* pattern);
73 gs_retval_t deregister_handle_for_str_partial_regex_match_slot_1(gs_param_handle_t handle);
74
75 gs_param_handle_t register_handle_for_str_extract_regex_slot_1(vstring* pattern);
76 gs_retval_t str_extract_regex( vstring * result, vstring * str, gs_param_handle_t handle);
77 gs_retval_t deregister_handle_for_str_extract_regex_slot_1(gs_param_handle_t handle);
78
79
80
81
82 // type conversion
83 #define INT(c) ((int)(c))
84 #define UINT(c) ((gs_uint32_t)(c))
85 #define FLOAT(c) ((gs_float_t)(c))
86 #define ULLONG(c) ((gs_uint64_t)(c))
87
88 // string conversions
89
90 gs_uint32_t strtoi(gs_uint32_t * r, struct vstring *data);
91 gs_uint32_t strtoip(gs_uint32_t * r, struct vstring *data);
92
93 //      constant string conversions
94 gs_param_handle_t register_handle_for_strtoi_c_slot_0(vstring* istr) ;
95 gs_retval_t deregister_handle_for_strtoi_c_slot_0(gs_param_handle_t h) ;
96 #define strtoi_c(h) ((gs_uint32_t)(h))
97
98 gs_param_handle_t register_handle_for_strtoip_c_slot_0(vstring* istr) ;
99 gs_retval_t deregister_handle_for_strtoip_c_slot_0(gs_param_handle_t h) ;
100 #define strtoip_c(h) ((gs_uint32_t)(h))
101
102
103 inline gs_uint32_t str_match_offset( gs_uint32_t offset, struct vstring * s1, struct vstring * s2) {
104         register gs_uint8_t *st1 = (gs_uint8_t *) s1->offset;
105         register gs_uint8_t *st2 = (gs_uint8_t *) (s2->offset+offset);
106         register gs_int32_t x;
107         register gs_int32_t len2 = s2->length-offset;
108         register gs_int32_t len1 = s1->length;
109         if (len2<len1) return 0;
110         for(x=0; x<len1; x++) {
111                 if (st1[x]!=st2[x]) return 0;
112         }
113         return 1;
114 }
115
116
117
118 #endif