4 /* ------------------------------------------------
5 Copyright 2014 AT&T Intellectual Property
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ------------------------------------------- */
26 #define IS_BIG_ENDIAN (*(uint16_t *)"\0\xff" < 0x100)
28 // struct string32 matches vstring32, its the packed record format.
29 // struct gs_string is the in-memory format.
38 /* struct gs_string has to match definition in host.h however, the data
51 /* Basic string operation */
53 gs_retval_t str_assign_with_copy(struct FTA *, struct gs_string * dest, struct gs_string * src);
55 gs_retval_t str_assign_with_copy_in_tuple(struct string32 * dest, struct gs_string * src,
56 gs_sp_t start, gs_sp_t buf);
58 #define str_destroy(s) {if ((s)->owner!=0) fta_free((s)->owner,(s)->data);}
60 gs_retval_t str_replace(struct FTA *, struct gs_string * dest, struct gs_string * src );
62 #define str_length(s) (s)->length
64 /* Searching within a string */
66 gs_retval_t str_exists_substr( struct gs_string * str1, struct gs_string * str2);
68 /* String comparison */
70 gs_retval_t str_compare( struct gs_string * str1, struct gs_string * str2);
74 gs_retval_t str_equal( struct gs_string * str1, struct gs_string * str2);
76 /* Construct a string constant */
78 gs_retval_t str_constructor(struct gs_string *s, gs_sp_t l);
82 #define string_hash(s) lfta_V_STR_to_hash((*(s)))
84 /* External Function definitions */
86 #define ULLMIN(x,y) (unsigned long long)(((x)<(y)?(x):(y)))
87 #define ULLMAX(x,y) (unsigned long long)(((x)<(y)?(y):(x)))
88 #define LLMIN(x,y) (long long int)(((x)<(y)?(x):(y)))
89 #define LLMAX(x,y) (long long int)(((x)<(y)?(y):(x)))
90 #define UMIN(x,y) (unsigned int)(((x)<(y)?(x):(y)))
91 #define UMAX(x,y) (unsigned int)(((x)<(y)?(y):(x)))
92 #define LMIN(x,y) (int)(((x)<(y)?(x):(y)))
93 #define LMAX(x,y) (int)(((x)<(y)?(y):(x)))
94 #define FMIN(x,y) (double)(((x)<(y)?(x):(y)))
95 #define FMAX(x,y) (double)(((x)<(y)?(y):(x)))
98 #define INT(c) ((int)(c))
99 #define UINT(c) ((unsigned int)(c))
100 #define ULLONG(c) ((unsigned long long)(c))
101 #define LLONG(c) ((long long int)(c))
102 #define FLOAT(c) ((double)(c))
105 #define EQ(x,y) ((x)==(y))
106 #define GEQ(x,y) ((x)>=(y))
107 #define GE(x,y) ((x)>(y))
108 #define LEQ(x,y) ((x)<=(y))
109 #define LE(x,y) ((x)<(y))
112 #define if_else_f(x,y,z) (double)(((x)==0?(z):(y)))
113 #define if_else_ll(x,y,z) (long long int)(((x)==0?(z):(y)))
114 #define if_else_ul(x,y,z) (unsigned long long)(((x)==0?(z):(y)))
115 #define if_else_u(x,y,z) (unsigned int)(((x)==0?(z):(y)))
116 #define if_else_i(x,y,z) (int)(((x)==0?(z):(y)))
118 // Cast away temporality
119 #define non_temporal(x)(x)
122 #define endian_swap_ui(x) ( (( (x) & 0xFF000000) >> 24) | (( (x) & 0x00FF0000) >> 8) | (( (x) & 0x0000FF00) << 8) | (( (x) & 0x000000FF) << 24) )
125 // Access math libraries
126 #define sqrt(x) sqrt(x)
127 #define pow(x,y) pow((x),(y))
128 #define sin(x) sin(x)
129 #define cos(x) cos(x)
130 #define tan(x) tan(x)
131 #define asin(x) asin(x)
132 #define acos(x) acos(x)
133 #define atan(x) atan(x)
134 #define log(x) log(x)
135 #define log2(x) log2(x)
136 #define log10(x) log10(x)
137 #define ceil(x) ceil(x)
138 #define floor(x) floor(x)
139 #define fmod(x) fmod(x)
140 #define trunc(x) trunc(x)
145 gs_uint32_t str_match_offset( gs_uint32_t offset, struct gs_string * s1, struct gs_string * s2);
146 gs_uint32_t byte_match_offset( gs_uint32_t offset, gs_uint32_t val, struct gs_string * s2);
147 gs_param_handle_t register_handle_for_str_regex_match_slot_1(struct FTA * f,
148 struct gs_string* pattern);
149 gs_uint32_t str_regex_match(struct gs_string* str, gs_param_handle_t pattern_handle);
150 gs_retval_t deregister_handle_for_str_regex_match_slot_1(gs_param_handle_t handle);
152 gs_param_handle_t register_handle_for_str_partial_regex_match_slot_1(struct FTA * f,
153 struct gs_string* pattern);
154 gs_uint32_t str_partial_regex_match(struct gs_string* str,
155 gs_param_handle_t pattern_handle,
157 gs_retval_t deregister_handle_for_str_partial_regex_match_slot_1(
161 inline static gs_retval_t str_truncate(struct gs_string * result, struct gs_string *str, gs_uint32_t length) {
162 result->data=str->data;
163 result->length=(str->length<length)?str->length:length;
167 // constant string conversions
168 gs_param_handle_t register_handle_for_strtoi_c_slot_0(struct FTA * f, struct gs_string* istr) ;
169 gs_retval_t deregister_handle_for_strtoi_c_slot_0(gs_param_handle_t h) ;
170 #define strtoi_c(h) ((unsigned int)(h))
172 gs_param_handle_t register_handle_for_strtoip_c_slot_0(struct FTA * f, struct gs_string* istr) ;
173 gs_retval_t deregister_handle_for_strtoip_c_slot_0(gs_param_handle_t h) ;
174 #define strtoip_c(h) ((unsigned int)(h))
178 ////////////////////////////////////////////////
188 gs_int32_t ipv6_compare( struct ipv6_str i1, struct ipv6_str i2);
189 gs_int32_t Ipv6_Constructor(struct ipv6_str *s, char *l);
190 struct ipv6_str And_Ipv6(const struct ipv6_str i1, const struct ipv6_str i2);
191 struct ipv6_str Or_Ipv6(const struct ipv6_str i1, const struct ipv6_str i2);
192 struct ipv6_str hton_ipv6(struct ipv6_str s);
193 struct ipv6_str ntoh_ipv6(struct ipv6_str s);
196 ////////////////////////////////////////////////
197 /// Regex pattern extraction based on signature library for VideoNOC
198 gs_param_handle_t register_handle_for_signaturelib_get_content_id_slot_2(struct FTA * f, struct gs_string* signature_file);
199 gs_uint32_t signaturelib_get_content_id(struct gs_string* result, struct gs_string* url, gs_uint32_t content_length, gs_param_handle_t handle);
200 gs_retval_t deregister_handle_for_signaturelib_get_content_id_slot_2(gs_param_handle_t handle);
202 gs_uint32_t signaturelib_get_fqdn(struct gs_string* result);
203 gs_uint32_t signaturelib_get_channel_type(struct gs_string* result);