358527e0ebd195aefff819e805b2d75795710584
[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
73 /*      Construct a string constant */
74
75 gs_retval_t str_constructor(struct gs_string *s, gs_sp_t l);
76
77 /*      string hash     */
78
79 #define string_hash(s) lfta_V_STR_to_hash((*(s)))
80
81 /* External Function definitions */
82
83 #define ULLMIN(x,y) (unsigned long long)(((x)<(y)?(x):(y)))
84 #define ULLMAX(x,y) (unsigned long long)(((x)<(y)?(y):(x)))
85 #define LLMIN(x,y) (long long int)(((x)<(y)?(x):(y)))
86 #define LLMAX(x,y) (long long int)(((x)<(y)?(y):(x)))
87 #define UMIN(x,y) (unsigned int)(((x)<(y)?(x):(y)))
88 #define UMAX(x,y) (unsigned int)(((x)<(y)?(y):(x)))
89 #define LMIN(x,y) (int)(((x)<(y)?(x):(y)))
90 #define LMAX(x,y) (int)(((x)<(y)?(y):(x)))
91 #define FMIN(x,y) (double)(((x)<(y)?(x):(y)))
92 #define FMAX(x,y) (double)(((x)<(y)?(y):(x)))
93
94 // type conversion
95 #define INT(c) ((int)(c))
96 #define UINT(c) ((unsigned int)(c))
97 #define ULLONG(c) ((unsigned long long)(c))
98 #define LLONG(c) ((long long int)(c))
99 #define FLOAT(c) ((double)(c))
100
101 // comparison
102 #define EQ(x,y) ((x)==(y))
103 #define GEQ(x,y) ((x)>=(y))
104 #define GE(x,y) ((x)>(y))
105 #define LEQ(x,y) ((x)<=(y))
106 #define LE(x,y) ((x)<(y))
107
108 // if_else
109 #define if_else_f(x,y,z) (double)(((x)==0?(z):(y)))
110 #define if_else_ll(x,y,z) (long long int)(((x)==0?(z):(y)))
111 #define if_else_ul(x,y,z) (unsigned long long)(((x)==0?(z):(y)))
112 #define if_else_u(x,y,z) (unsigned int)(((x)==0?(z):(y)))
113 #define if_else_i(x,y,z) (int)(((x)==0?(z):(y)))
114
115 //      Cast away temporality
116 #define non_temporal(x)(x)
117
118 //      endian swap
119 #define endian_swap_ui(x) ( (( (x) & 0xFF000000) >> 24) | (( (x) & 0x00FF0000) >> 8) | (( (x) & 0x0000FF00) << 8) | (( (x) & 0x000000FF) << 24) ) 
120
121
122 //      Access math libraries
123 #define sqrt(x) sqrt(x)
124 #define pow(x,y) pow((x),(y))
125 #define sin(x) sin(x)
126 #define cos(x) cos(x)
127 #define tan(x) tan(x)
128 #define asin(x) asin(x)
129 #define acos(x) acos(x)
130 #define atan(x) atan(x)
131 #define log(x) log(x)
132 #define log2(x) log2(x)
133 #define log10(x) log10(x)
134 #define ceil(x) ceil(x)
135 #define floor(x) floor(x)
136 #define fmod(x) fmod(x)
137 #define trunc(x) trunc(x)
138
139
140
141
142 gs_uint32_t str_match_offset( gs_uint32_t offset, struct gs_string * s1, struct gs_string * s2);
143 gs_uint32_t byte_match_offset( gs_uint32_t offset, gs_uint32_t val, struct gs_string * s2);
144 gs_param_handle_t register_handle_for_str_regex_match_slot_1(struct FTA * f,
145                                                              struct gs_string* pattern);
146 gs_uint32_t str_regex_match(struct gs_string* str, gs_param_handle_t pattern_handle);
147 gs_retval_t deregister_handle_for_str_regex_match_slot_1(gs_param_handle_t handle);
148
149 gs_param_handle_t register_handle_for_str_partial_regex_match_slot_1(struct FTA * f,
150                                                                      struct gs_string* pattern);
151 gs_uint32_t str_partial_regex_match(struct gs_string* str,
152                                     gs_param_handle_t pattern_handle,
153                                     gs_uint32_t maxlen);
154 gs_retval_t deregister_handle_for_str_partial_regex_match_slot_1(
155                                                                  gs_param_handle_t
156                                                                  handle);
157
158 inline static gs_retval_t str_truncate(struct gs_string * result, struct gs_string *str, gs_uint32_t length) {
159         result->data=str->data;
160         result->length=(str->length<length)?str->length:length;
161         return 0;
162 }
163
164 //      constant string conversions
165 gs_param_handle_t register_handle_for_strtoi_c_slot_0(struct FTA * f, struct gs_string* istr) ;
166 gs_retval_t deregister_handle_for_strtoi_c_slot_0(gs_param_handle_t h) ;
167 #define strtoi_c(h) ((unsigned int)(h))
168
169 gs_param_handle_t register_handle_for_strtoip_c_slot_0(struct FTA * f, struct gs_string* istr) ;
170 gs_retval_t deregister_handle_for_strtoip_c_slot_0(gs_param_handle_t h) ;
171 #define strtoip_c(h) ((unsigned int)(h))
172
173
174
175 ////////////////////////////////////////////////
176 ///             IPV6
177
178 #ifndef IPV6_STR
179 #define IPV6_STR
180 struct ipv6_str{
181         gs_uint32_t v[4];
182 };
183 #endif
184
185 gs_int32_t ipv6_compare( struct ipv6_str  i1, struct ipv6_str  i2);
186 gs_int32_t Ipv6_Constructor(struct ipv6_str *s, char *l);
187 struct ipv6_str And_Ipv6(const struct ipv6_str i1, const struct ipv6_str i2);
188 struct ipv6_str Or_Ipv6(const struct ipv6_str i1, const struct ipv6_str i2);
189 struct ipv6_str hton_ipv6(struct ipv6_str s);
190 struct ipv6_str ntoh_ipv6(struct ipv6_str s);
191
192
193 ////////////////////////////////////////////////
194 ///             Regex pattern extraction based on signature library for VideoNOC
195 gs_param_handle_t register_handle_for_signaturelib_get_content_id_slot_2(struct FTA * f, struct gs_string* signature_file);
196 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);
197 gs_retval_t deregister_handle_for_signaturelib_get_content_id_slot_2(gs_param_handle_t handle);
198
199 gs_uint32_t signaturelib_get_fqdn(struct gs_string* result);
200 gs_uint32_t signaturelib_get_channel_type(struct gs_string* result);
201
202 #endif