1 /** @file
2 
3   A brief file description
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 #pragma once
25 
26 #include "tscore/ink_string++.h"
27 #include "MIME.h"
28 #include "tscore/Diags.h"
29 
30 class HttpCompat
31 {
32 public:
33   static void parse_tok_list(StrList *list, int trim_quotes, const char *comma_list_str, int comma_list_len, char tok);
34 
35   static void parse_tok_list(StrList *list, int trim_quotes, const char *comma_list_str, char tok);
36 
37   static bool lookup_param_in_strlist(StrList *param_list, const char *param_name, char *param_val, int param_val_length);
38 
39   static bool lookup_param_in_semicolon_string(const char *semicolon_string, int semicolon_string_len, const char *param_name,
40                                                char *param_val, int param_val_length);
41 
42   static void parse_mime_type(const char *mime_string, char *type, char *subtype, int type_len, int subtype_len);
43 
44   static void parse_mime_type_with_len(const char *mime_string, int mime_string_len, char *type, char *subtype, int type_len,
45                                        int subtype_len);
46 
47   static bool do_vary_header_values_match(MIMEField *hv1, MIMEField *hv2);
48 
49   static float find_Q_param_in_strlist(StrList *strlist);
50 
51   static float match_accept_language(const char *lang_str, int lang_len, StrList *acpt_lang_list, int *matching_length,
52                                      int *matching_index, bool ignore_wildcards = false);
53 
54   static float match_accept_charset(const char *charset_str, int charset_len, StrList *acpt_charset_list, int *matching_index,
55                                     bool ignore_wildcards = false);
56 
57   static void
parse_comma_list(StrList * list,const char * comma_list_str)58   parse_comma_list(StrList *list, const char *comma_list_str)
59   {
60     parse_tok_list(list, 1, comma_list_str, ',');
61   }
62 
63   static void
parse_comma_list(StrList * list,const char * comma_list_str,int comma_list_len)64   parse_comma_list(StrList *list, const char *comma_list_str, int comma_list_len)
65   {
66     parse_tok_list(list, 1, comma_list_str, comma_list_len, ',');
67   }
68 
69   static void
parse_semicolon_list(StrList * list,const char * comma_list_str)70   parse_semicolon_list(StrList *list, const char *comma_list_str)
71   {
72     parse_tok_list(list, 1, comma_list_str, ';');
73   }
74 
75   static void
parse_semicolon_list(StrList * list,const char * comma_list_str,int comma_list_len)76   parse_semicolon_list(StrList *list, const char *comma_list_str, int comma_list_len)
77   {
78     parse_tok_list(list, 1, comma_list_str, comma_list_len, ';');
79   }
80 };
81