Fixed newline characters throughout the code
[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
78 /* External Function definitions */
79
80 #define LLMIN(x,y) ((x)<(y)?(x):(y))
81 #define LLMAX(x,y) ((x)<(y)?(y):(x))
82 #define UMIN(x,y) ((x)<(y)?(x):(y))
83 #define UMAX(x,y) ((x)<(y)?(y):(x))
84 // type conversion
85 #define INT(c) ((int)(c))
86 #define UINT(c) ((unsigned int)(c))
87 #define ULLONG(c) ((unsigned long long)(c))
88 #define FLOAT(c) ((double)(c))
89 #define EQ(x,y) ((x)==(y))
90 #define GEQ(x,y) ((x)>=(y))
91 #define LEQ(x,y) ((x)<=(y))
92
93 //      Cast away temporality
94 #define non_temporal(x)(x)
95
96 //      Access math libraries
97 #define sqrt(x) sqrt(x)
98
99
100
101
102 gs_uint32_t str_match_offset( gs_uint32_t offset, struct gs_string * s1, struct gs_string * s2);
103 gs_uint32_t byte_match_offset( gs_uint32_t offset, gs_uint32_t val, struct gs_string * s2);
104 gs_param_handle_t register_handle_for_str_regex_match_slot_1(struct FTA * f,
105                                                              struct gs_string* pattern);
106 gs_uint32_t str_regex_match(struct gs_string* str, gs_param_handle_t pattern_handle);
107 gs_retval_t deregister_handle_for_str_regex_match_slot_1(gs_param_handle_t handle);
108
109 gs_param_handle_t register_handle_for_str_partial_regex_match_slot_1(struct FTA * f,
110                                                                      struct gs_string* pattern);
111 gs_uint32_t str_partial_regex_match(struct gs_string* str,
112                                     gs_param_handle_t pattern_handle,
113                                     gs_uint32_t maxlen);
114 gs_retval_t deregister_handle_for_str_partial_regex_match_slot_1(
115                                                                  gs_param_handle_t
116                                                                  handle);
117
118 inline static gs_retval_t str_truncate(struct gs_string * result, struct gs_string *str, gs_uint32_t length) {
119         result->data=str->data;
120         result->length=(str->length<length)?str->length:length;
121         return 0;
122 }
123
124 //      constant string conversions
125 gs_param_handle_t register_handle_for_strtoi_c_slot_0(struct FTA * f, struct gs_string* istr) ;
126 gs_retval_t deregister_handle_for_strtoi_c_slot_0(gs_param_handle_t h) ;
127 #define strtoi_c(h) ((unsigned int)(h))
128
129 gs_param_handle_t register_handle_for_strtoip_c_slot_0(struct FTA * f, struct gs_string* istr) ;
130 gs_retval_t deregister_handle_for_strtoip_c_slot_0(gs_param_handle_t h) ;
131 #define strtoip_c(h) ((unsigned int)(h))
132
133
134
135 ////////////////////////////////////////////////
136 ///             IPV6
137
138 #ifndef IPV6_STR
139 #define IPV6_STR
140 struct ipv6_str{
141         gs_uint32_t v[4];
142 };
143 #endif
144
145 gs_int32_t ipv6_compare( struct ipv6_str  i1, struct ipv6_str  i2);
146 gs_int32_t Ipv6_Constructor(struct ipv6_str *s, char *l);
147 struct ipv6_str And_Ipv6(const struct ipv6_str i1, const struct ipv6_str i2);
148 struct ipv6_str Or_Ipv6(const struct ipv6_str i1, const struct ipv6_str i2);
149 struct ipv6_str hton_ipv6(struct ipv6_str s);
150 struct ipv6_str ntoh_ipv6(struct ipv6_str s);
151
152
153 ////////////////////////////////////////////////
154 ///             Regex pattern extraction based on signature library for VideoNOC
155 gs_param_handle_t register_handle_for_signaturelib_get_content_id_slot_2(struct FTA * f, struct gs_string* signature_file);
156 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);
157 gs_retval_t deregister_handle_for_signaturelib_get_content_id_slot_2(gs_param_handle_t handle);
158
159 gs_uint32_t signaturelib_get_fqdn(struct gs_string* result);
160 gs_uint32_t signaturelib_get_channel_type(struct gs_string* result);
161
162 #endif