UniMRCP  1.3.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
apt_header_field.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2014 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  * $Id: apt_header_field.h 2136 2014-07-04 06:33:36Z achaloyan@gmail.com $
17  */
18 
19 #ifndef APT_HEADER_FIELD_H
20 #define APT_HEADER_FIELD_H
21 
22 /**
23  * @file apt_header_field.h
24  * @brief Header Field Declaration (RFC5322)
25  */
26 
27 #ifdef WIN32
28 #pragma warning(disable: 4127)
29 #endif
30 #include <apr_ring.h>
31 #include "apt_string.h"
32 
34 
35 /** Header field declaration */
37 /** Header section declaration */
39 
40 /** Header field */
42  /** Ring entry */
44 
45  /** Name of the header field */
47  /** Value of the header field */
49 
50  /** Numeric identifier associated with name */
51  apr_size_t id;
52 };
53 
54 /**
55  * Header section
56  * @remark The header section is a collection of header fields.
57  * The header fields are stored in both a ring and an array.
58  * The goal is to ensure efficient access and manipulation on the header fields.
59  */
61  /** List of header fields (name-value pairs) */
62  APR_RING_HEAD(apt_head_t, apt_header_field_t) ring;
63  /** Array of pointers to header fields */
65  /** Max number of header fields */
66  apr_size_t arr_size;
67 };
68 
69 
70 /**
71  * Allocate an empty header field.
72  * @param pool the pool to allocate memory from
73  */
75 
76 /**
77  * Create a header field using given name and value APT strings.
78  * @param name the name of the header field
79  * @param value the value of the header field
80  * @param pool the pool to allocate memory from
81  */
82 APT_DECLARE(apt_header_field_t*) apt_header_field_create(const apt_str_t *name, const apt_str_t *value, apr_pool_t *pool);
83 
84 /**
85  * Create a header field using given name and value C strings.
86  * @param name the name of the header field
87  * @param value the value of the header field
88  * @param pool the pool to allocate memory from
89  */
90 APT_DECLARE(apt_header_field_t*) apt_header_field_create_c(const char *name, const char *value, apr_pool_t *pool);
91 
92 /**
93  * Create a header field from entire text line consisting of a name and value pair.
94  * @param line the text line, which consists of a name and value pair
95  * @param separator the name and value separator
96  * @param pool the pool to allocate memory from
97  */
98 APT_DECLARE(apt_header_field_t*) apt_header_field_create_from_line(const apt_str_t *line, char separator, apr_pool_t *pool);
99 
100 /**
101  * Copy specified header field.
102  * @param src_header_field the header field to copy
103  * @param pool the pool to allocate memory from
104  */
105 APT_DECLARE(apt_header_field_t*) apt_header_field_copy(const apt_header_field_t *src_header_field, apr_pool_t *pool);
106 
107 /**
108  * Initialize header section (collection of header fields).
109  * @param header the header section to initialize
110  */
112 
113 /**
114  * Allocate header section to set/get header fields by numeric identifiers.
115  * @param header the header section to allocate
116  * @param max_field_count the max number of header fields in the section (protocol dependent)
117  * @param pool the pool to allocate memory from
118  */
119 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);
120 
121 /**
122  * Add (append) header field to header section.
123  * @param header the header section to add field to
124  * @param header_field the header field to add
125  */
127 
128 /**
129  * Insert header field to header section based on numreic identifier if specified.
130  * @param header the header section to insert field into
131  * @param header_field the header field to insert
132  */
134 
135 /**
136  * Set header field in the array of header fields using associated numeric identifier.
137  * @param header the header section to set field for
138  * @param header_field the header field to set
139  * @remark Typically, the header field should be already added to the header section using apt_header_section_field_add()
140  */
142 
143 /**
144  * Remove header field from header section.
145  * @param header the header section to remove field from
146  * @param header_field the header field to remove
147  */
149 
150 /**
151  * Check whether specified header field is set.
152  * @param header the header section to use
153  * @param id the identifier associated with the header_field to check
154  */
155 static APR_INLINE apt_bool_t apt_header_section_field_check(const apt_header_section_t *header, apr_size_t id)
156 {
157  if(id < header->arr_size) {
158  return header->arr[id] ? TRUE : FALSE;
159  }
160  return FALSE;
161 }
162 
163 /**
164  * Get header field by specified identifier.
165  * @param header the header section to use
166  * @param id the identifier associated with the header_field
167  */
168 static APR_INLINE apt_header_field_t* apt_header_section_field_get(const apt_header_section_t *header, apr_size_t id)
169 {
170  if(id < header->arr_size) {
171  return header->arr[id];
172  }
173  return NULL;
174 }
175 
177 
178 #endif /* APT_HEADER_FIELD_H */