7d5ff9592ebe3f5b579409d814808dd723f35125
[com/gs-lite.git] / include / lfta / rts_external.h
1 #ifndef RTS_STRING_H
2 #define RTS_STRING_H
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8
9
10 /* ------------------------------------------------
11  Copyright 2014 AT&T Intellectual Property
12  Licensed under the Apache License, Version 2.0 (the "License");
13  you may not use this file except in compliance with the License.
14  You may obtain a copy of the License at
15  
16  http://www.apache.org/licenses/LICENSE-2.0
17  
18  Unless required by applicable law or agreed to in writing, software
19  distributed under the License is distributed on an "AS IS" BASIS,
20  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  See the License for the specific language governing permissions and
22  limitations under the License.
23  ------------------------------------------- */
24
25 #include <stdint.h>
26 #include<math.h>
27
28
29 #include "gsconfig.h"
30 #include "gstypes.h"
31
32 #define IS_BIG_ENDIAN (*(uint16_t *)"\0\xff" < 0x100)
33
34 //      struct string32 matches vstring32, its the packed record format.
35 //      struct gs_string is the in-memory format.
36
37 struct string32{
38         gs_int32_t length;
39         gs_int32_t offset;
40         gs_int32_t reserved;
41 };
42
43
44 /* struct gs_string has to match definition in host.h however, the data
45  types differ */
46
47 struct gs_string {
48     gs_int32_t length;
49     gs_sp_t data;
50     struct FTA * owner;    
51 };
52
53 #include "fta.h"
54 #include "rts.h"
55
56
57 /* Basic string operation */
58
59 gs_retval_t str_assign_with_copy(struct FTA *, struct gs_string * dest, struct gs_string * src);
60
61 gs_retval_t str_assign_with_copy_in_tuple(struct string32 * dest, struct gs_string * src,
62                                           gs_sp_t start, gs_sp_t buf);
63
64 #define str_destroy(s) {if ((s)->owner!=0) fta_free((s)->owner,(s)->data);}
65
66 gs_retval_t str_replace(struct FTA *,  struct gs_string * dest, struct gs_string * src );
67
68 #define str_length(s) (s)->length
69
70 /* Searching within a string */
71
72 gs_retval_t str_exists_substr( struct gs_string * str1, struct gs_string * str2);
73
74 /* String comparison */
75
76 gs_retval_t str_compare( struct gs_string * str1, struct gs_string * str2);
77
78 /* String equality */
79
80 gs_retval_t str_equal( struct gs_string * str1, struct gs_string * str2);
81
82 /*      Construct a string constant */
83
84 gs_retval_t str_constructor(struct gs_string *s, gs_csp_t l);
85
86 /*      string hash     */
87
88 #define string_hash(s) lfta_V_STR_to_hash((*(s)))
89
90 /* External Function definitions */
91
92 #define ULLMIN(x,y) (unsigned long long)(((x)<(y)?(x):(y)))
93 #define ULLMAX(x,y) (unsigned long long)(((x)<(y)?(y):(x)))
94 #define LLMIN(x,y) (long long int)(((x)<(y)?(x):(y)))
95 #define LLMAX(x,y) (long long int)(((x)<(y)?(y):(x)))
96 #define UMIN(x,y) (unsigned int)(((x)<(y)?(x):(y)))
97 #define UMAX(x,y) (unsigned int)(((x)<(y)?(y):(x)))
98 #define LMIN(x,y) (int)(((x)<(y)?(x):(y)))
99 #define LMAX(x,y) (int)(((x)<(y)?(y):(x)))
100 #define FMIN(x,y) (double)(((x)<(y)?(x):(y)))
101 #define FMAX(x,y) (double)(((x)<(y)?(y):(x)))
102
103 // type conversion
104 #define INT(c) ((int)(c))
105 #define UINT(c) ((unsigned int)(c))
106 #define ULLONG(c) ((unsigned long long)(c))
107 #define LLONG(c) ((long long int)(c))
108 #define FLOAT(c) ((double)(c))
109
110 // comparison
111 #define EQ(x,y) ((x)==(y))
112 #define GEQ(x,y) ((x)>=(y))
113 #define GE(x,y) ((x)>(y))
114 #define LEQ(x,y) ((x)<=(y))
115 #define LE(x,y) ((x)<(y))
116
117 // if_else
118 #define if_else_f(x,y,z) (double)(((x)==0?(z):(y)))
119 #define if_else_ll(x,y,z) (long long int)(((x)==0?(z):(y)))
120 #define if_else_ul(x,y,z) (unsigned long long)(((x)==0?(z):(y)))
121 #define if_else_u(x,y,z) (unsigned int)(((x)==0?(z):(y)))
122 #define if_else_i(x,y,z) (int)(((x)==0?(z):(y)))
123
124 //      Cast away temporality
125 #define non_temporal(x)(x)
126
127 //      endian swap
128 #define endian_swap_ui(x) ( (( (x) & 0xFF000000) >> 24) | (( (x) & 0x00FF0000) >> 8) | (( (x) & 0x0000FF00) << 8) | (( (x) & 0x000000FF) << 24) ) 
129
130
131 //      Access math libraries
132 #define sqrt(x) sqrt(x)
133 #define pow(x,y) pow((x),(y))
134 #define sin(x) sin(x)
135 #define cos(x) cos(x)
136 #define tan(x) tan(x)
137 #define asin(x) asin(x)
138 #define acos(x) acos(x)
139 #define atan(x) atan(x)
140 #define log(x) log(x)
141 #define log2(x) log2(x)
142 #define log10(x) log10(x)
143 #define ceil(x) ceil(x)
144 #define floor(x) floor(x)
145 #define fmod(x) fmod(x)
146 #define trunc(x) trunc(x)
147
148
149
150
151 gs_uint32_t str_match_offset( gs_uint32_t offset, struct gs_string * s1, struct gs_string * s2);
152 gs_uint32_t byte_match_offset( gs_uint32_t offset, gs_uint32_t val, struct gs_string * s2);
153 gs_param_handle_t register_handle_for_str_regex_match_slot_1(struct FTA * f,
154                                                              struct gs_string* pattern);
155 gs_uint32_t str_regex_match(struct gs_string* str, gs_param_handle_t pattern_handle);
156 gs_retval_t deregister_handle_for_str_regex_match_slot_1(gs_param_handle_t handle);
157
158 gs_param_handle_t register_handle_for_str_partial_regex_match_slot_1(struct FTA * f,
159                                                                      struct gs_string* pattern);
160 gs_uint32_t str_partial_regex_match(struct gs_string* str,
161                                     gs_param_handle_t pattern_handle,
162                                     gs_uint32_t maxlen);
163 gs_retval_t deregister_handle_for_str_partial_regex_match_slot_1(
164                                                                  gs_param_handle_t
165                                                                  handle);
166 // ----------------------------------
167 //      Substring functions
168 inline static gs_retval_t str_truncate(struct gs_string * result, struct gs_string *str, gs_uint32_t length) {
169         result->data=str->data;
170         result->length=(str->length<length)?str->length:length;
171         return 0;
172 }
173 gs_retval_t str_suffix(struct gs_string * ret, struct gs_string *s, gs_uint32_t n);
174 gs_retval_t get_list_entry(struct gs_string * ret, struct gs_string *l, struct gs_string *sep, gs_uint32_t pos);
175
176
177 // ----------------------------------
178 //      constant string conversions
179 gs_param_handle_t register_handle_for_strtoi_c_slot_0(struct FTA * f, struct gs_string* istr) ;
180 gs_retval_t deregister_handle_for_strtoi_c_slot_0(gs_param_handle_t h) ;
181 #define strtoi_c(h) ((unsigned int)(h))
182
183 gs_param_handle_t register_handle_for_strtoip_c_slot_0(struct FTA * f, struct gs_string* istr) ;
184 gs_retval_t deregister_handle_for_strtoip_c_slot_0(gs_param_handle_t h) ;
185 #define strtoip_c(h) ((unsigned int)(h))
186
187
188
189 ////////////////////////////////////////////////
190 ///             IPV6
191
192 #ifndef IPV6_STR
193 #define IPV6_STR
194 struct ipv6_str{
195         gs_uint32_t v[4];
196 };
197 #endif
198
199 gs_int32_t ipv6_compare( struct ipv6_str  i1, struct ipv6_str  i2);
200 gs_int32_t Ipv6_Constructor(struct ipv6_str *s, char *l);
201 struct ipv6_str And_Ipv6(const struct ipv6_str i1, const struct ipv6_str i2);
202 struct ipv6_str Or_Ipv6(const struct ipv6_str i1, const struct ipv6_str i2);
203 struct ipv6_str hton_ipv6(struct ipv6_str s);
204 struct ipv6_str ntoh_ipv6(struct ipv6_str s);
205
206
207 ////////////////////////////////////////////////
208 ///             Regex pattern extraction based on signature library for VideoNOC
209 gs_param_handle_t register_handle_for_signaturelib_get_content_id_slot_2(struct FTA * f, struct gs_string* signature_file);
210 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);
211 gs_retval_t deregister_handle_for_signaturelib_get_content_id_slot_2(gs_param_handle_t handle);
212
213 gs_uint32_t signaturelib_get_fqdn(struct gs_string* result);
214 gs_uint32_t signaturelib_get_channel_type(struct gs_string* result);
215
216 #ifdef __cplusplus
217 }
218 #endif
219
220 #endif