d1fdf7b769cfa0464b7466dcc783e533d8dd1cb9
[com/gs-lite.git] / include / lfta / rts_external.h
1 #ifndef RTS_STRING_H
2 #define RTS_STRING_H
3
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
9  
10  http://www.apache.org/licenses/LICENSE-2.0
11  
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  ------------------------------------------- */
18
19 #include <stdint.h>
20 #include<math.h>
21
22
23 #include "gsconfig.h"
24 #include "gstypes.h"
25
26 #define IS_BIG_ENDIAN (*(uint16_t *)"\0\xff" < 0x100)
27
28 //      struct string32 matches vstring32, its the packed record format.
29 //      struct gs_string is the in-memory format.
30
31 struct string32{
32         gs_int32_t length;
33         gs_int32_t offset;
34         gs_int32_t reserved;
35 };
36
37
38 /* struct gs_string has to match definition in host.h however, the data
39  types differ */
40
41 struct gs_string {
42     gs_int32_t length;
43     gs_sp_t data;
44     struct FTA * owner;    
45 };
46
47 #include "fta.h"
48 #include "rts.h"
49
50
51 /* Basic string operation */
52
53 gs_retval_t str_assign_with_copy(struct FTA *, struct gs_string * dest, struct gs_string * src);
54
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);
57
58 #define str_destroy(s) {if ((s)->owner!=0) fta_free((s)->owner,(s)->data);}
59
60 gs_retval_t str_replace(struct FTA *,  struct gs_string * dest, struct gs_string * src );
61
62 #define str_length(s) (s)->length
63
64 /* Searching within a string */
65
66 gs_retval_t str_exists_substr( struct gs_string * str1, struct gs_string * str2);
67
68 /* String comparison */
69
70 gs_retval_t str_compare( struct gs_string * str1, struct gs_string * str2);
71
72 /* String equality */
73
74 gs_retval_t str_equal( struct gs_string * str1, struct gs_string * str2);
75
76 /*      Construct a string constant */
77
78 gs_retval_t str_constructor(struct gs_string *s, gs_sp_t l);
79
80 /*      string hash     */
81
82 #define string_hash(s) lfta_V_STR_to_hash((*(s)))
83
84 /* External Function definitions */
85
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)))
96
97 // type conversion
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))
103
104 // comparison
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))
110
111 // if_else
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)))
117
118 //      Cast away temporality
119 #define non_temporal(x)(x)
120
121 //      endian swap
122 #define endian_swap_ui(x) ( (( (x) & 0xFF000000) >> 24) | (( (x) & 0x00FF0000) >> 8) | (( (x) & 0x0000FF00) << 8) | (( (x) & 0x000000FF) << 24) ) 
123
124
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)
141
142
143
144
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);
151
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,
156                                     gs_uint32_t maxlen);
157 gs_retval_t deregister_handle_for_str_partial_regex_match_slot_1(
158                                                                  gs_param_handle_t
159                                                                  handle);
160
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;
164         return 0;
165 }
166
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))
171
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))
175
176
177
178 ////////////////////////////////////////////////
179 ///             IPV6
180
181 #ifndef IPV6_STR
182 #define IPV6_STR
183 struct ipv6_str{
184         gs_uint32_t v[4];
185 };
186 #endif
187
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);
194
195
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);
201
202 gs_uint32_t signaturelib_get_fqdn(struct gs_string* result);
203 gs_uint32_t signaturelib_get_channel_type(struct gs_string* result);
204
205 #endif