UniMRCP  1.7.0
apt_header_field.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2015 Arsen Chaloyan
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef APT_HEADER_FIELD_H
18 #define APT_HEADER_FIELD_H
19 
20 /**
21  * @file apt_header_field.h
22  * @brief Header Field Declaration (RFC5322)
23  */
24 
25 #ifdef WIN32
26 #pragma warning(disable: 4127)
27 #endif
28 #include <apr_ring.h>
29 #include "apt_string.h"
30 
32 
33 /** Header field declaration */
35 /** Header section declaration */
37 
38 /** Header field */
40  /** Ring entry */
42 
43  /** Name of the header field */
45  /** Value of the header field */
47 
48  /** Numeric identifier associated with name */
49  apr_size_t id;
50 };
51 
52 /**
53  * Header section
54  * @remark The header section is a collection of header fields.
55  * The header fields are stored in both a ring and an array.
56  * The goal is to ensure efficient access and manipulation on the header fields.
57  */
59  /** List of header fields (name-value pairs) */
60  APR_RING_HEAD(apt_head_t, apt_header_field_t) ring;
61  /** Array of pointers to header fields */
63  /** Max number of header fields */
64  apr_size_t arr_size;
65 };
66 
67 
68 /**
69  * Allocate an empty header field.
70  * @param pool the pool to allocate memory from
71  */
73 
74 /**
75  * Create a header field using given name and value APT strings.
76  * @param name the name of the header field
77  * @param value the value of the header field
78  * @param pool the pool to allocate memory from
79  */
81 
82 /**
83  * Create a header field using given name and value C strings.
84  * @param name the name of the header field
85  * @param value the value of the header field
86  * @param pool the pool to allocate memory from
87  */
88 APT_DECLARE(apt_header_field_t*) apt_header_field_create_c(const char *name, const char *value, apr_pool_t *pool);
89 
90 /**
91  * Create a header field from entire text line consisting of a name and value pair.
92  * @param line the text line, which consists of a name and value pair
93  * @param separator the name and value separator
94  * @param pool the pool to allocate memory from
95  */
96 APT_DECLARE(apt_header_field_t*) apt_header_field_create_from_line(const apt_str_t *line, char separator, apr_pool_t *pool);
97 
98 /**
99  * Copy specified header field.
100  * @param src_header_field the header field to copy
101  * @param pool the pool to allocate memory from
102  */
103 APT_DECLARE(apt_header_field_t*) apt_header_field_copy(const apt_header_field_t *src_header_field, apr_pool_t *pool);
104 
105 /**
106  * Initialize header section (collection of header fields).
107  * @param header the header section to initialize
108  */
110 
111 /**
112  * Allocate header section to set/get header fields by numeric identifiers.
113  * @param header the header section to allocate
114  * @param max_field_count the max number of header fields in the section (protocol dependent)
115  * @param pool the pool to allocate memory from
116  */
117 APT_DECLARE(apt_bool_t) apt_header_section_array_alloc(apt_header_section_t *header, apr_size_t max_field_count, apr_pool_t *pool);
118 
119 /**
120  * Add (append) header field to header section.
121  * @param header the header section to add field to
122  * @param header_field the header field to add
123  */
125 
126 /**
127  * Insert header field to header section based on numreic identifier if specified.
128  * @param header the header section to insert field into
129  * @param header_field the header field to insert
130  */
132 
133 /**
134  * Set header field in the array of header fields using associated numeric identifier.
135  * @param header the header section to set field for
136  * @param header_field the header field to set
137  * @remark Typically, the header field should be already added to the header section using apt_header_section_field_add()
138  */
140 
141 /**
142  * Remove header field from header section.
143  * @param header the header section to remove field from
144  * @param header_field the header field to remove
145  */
147 
148 /**
149  * Check whether specified header field is set.
150  * @param header the header section to use
151  * @param id the identifier associated with the header_field to check
152  */
153 static APR_INLINE apt_bool_t apt_header_section_field_check(const apt_header_section_t *header, apr_size_t id)
154 {
155  if(id < header->arr_size) {
156  return header->arr[id] ? TRUE : FALSE;
157  }
158  return FALSE;
159 }
160 
161 /**
162  * Get header field by specified identifier.
163  * @param header the header section to use
164  * @param id the identifier associated with the header_field
165  */
166 static APR_INLINE apt_header_field_t* apt_header_section_field_get(const apt_header_section_t *header, apr_size_t id)
167 {
168  if(id < header->arr_size) {
169  return header->arr[id];
170  }
171  return NULL;
172 }
173 
175 
176 #endif /* APT_HEADER_FIELD_H */
apt_bool_t apt_header_section_field_remove(apt_header_section_t *header, apt_header_field_t *header_field)
apt_header_field_t * apt_header_field_create_c(const char *name, const char *value, apr_pool_t *pool)
apt_bool_t apt_header_section_array_alloc(apt_header_section_t *header, apr_size_t max_field_count, apr_pool_t *pool)
#define APT_END_EXTERN_C
Definition: apt.h:38
int apt_bool_t
Definition: apt.h:57
apr_size_t arr_size
Definition: apt_header_field.h:64
Definition: apt_header_field.h:39
APR_RING_ENTRY(apt_header_field_t) link
apt_header_field_t * apt_header_field_create(const apt_str_t *name, const apt_str_t *value, apr_pool_t *pool)
#define APT_BEGIN_EXTERN_C
Definition: apt.h:36
#define APT_DECLARE(type)
Definition: apt.h:53
apt_header_field_t * apt_header_field_copy(const apt_header_field_t *src_header_field, apr_pool_t *pool)
void apt_header_section_init(apt_header_section_t *header)
apt_str_t name
Definition: apt_header_field.h:44
apt_bool_t apt_header_section_field_insert(apt_header_section_t *header, apt_header_field_t *header_field)
apt_header_field_t ** arr
Definition: apt_header_field.h:62
apt_header_field_t * apt_header_field_alloc(apr_pool_t *pool)
apt_bool_t apt_header_section_field_set(apt_header_section_t *header, apt_header_field_t *header_field)
Definition: apt_header_field.h:58
apt_header_field_t * apt_header_field_create_from_line(const apt_str_t *line, char separator, apr_pool_t *pool)
Definition: apt_string.h:36
apr_size_t id
Definition: apt_header_field.h:49
apt_str_t value
Definition: apt_header_field.h:46
String Representation.
apt_bool_t apt_header_section_field_add(apt_header_section_t *header, apt_header_field_t *header_field)