UniMRCP  1.7.0
mrcp_message.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 MRCP_MESSAGE_H
18 #define MRCP_MESSAGE_H
19 
20 /**
21  * @file mrcp_message.h
22  * @brief MRCP Message Definition
23  */
24 
25 #include "mrcp_types.h"
26 #include "mrcp_start_line.h"
27 #include "mrcp_header.h"
28 #include "mrcp_generic_header.h"
29 
31 
32 /** Macro to log channel identifier of the message */
33 #define MRCP_MESSAGE_SIDRES(message) \
34  (message)->channel_id.session_id.buf, (message)->channel_id.resource_name.buf
35 
36 /** MRCP message */
38  /** Start-line of MRCP message */
40  /** Channel-identifier of MRCP message */
42  /** Header of MRCP message */
44  /** Body of MRCP message */
46 
47  /** Associated MRCP resource */
49  /** Memory pool to allocate memory from */
50  apr_pool_t *pool;
51 };
52 
53 /**
54  * Create an MRCP message.
55  * @param pool the pool to allocate memory from
56  */
58 
59 /**
60  * Create an MRCP request message.
61  * @param resource the MRCP resource to use
62  * @param version the MRCP version to use
63  * @param method_id the MRCP resource specific method identifier
64  * @param pool the pool to allocate memory from
65  */
67  const mrcp_resource_t *resource,
68  mrcp_version_e version,
69  mrcp_method_id method_id,
70  apr_pool_t *pool);
71 
72 /**
73  * Create an MRCP response message based on given request message.
74  * @param request_message the MRCP request message to create a response for
75  * @param pool the pool to allocate memory from
76  */
77 MRCP_DECLARE(mrcp_message_t*) mrcp_response_create(const mrcp_message_t *request_message, apr_pool_t *pool);
78 
79 /**
80  * Create an MRCP event message based on given requuest message.
81  * @param request_message the MRCP request message to create an event for
82  * @param event_id the MRCP resource specific event identifier
83  * @param pool the pool to allocate memory from
84  */
86  const mrcp_message_t *request_message,
87  mrcp_method_id event_id,
88  apr_pool_t *pool);
89 
90 /**
91  * Associate MRCP resource with message.
92  * @param message the message to associate resource with
93  * @param resource the resource to associate
94  */
96 
97 /**
98  * Validate MRCP message.
99  * @param message the message to validate
100  */
102 
103 /**
104  * Destroy MRCP message.
105  * @param message the message to destroy
106  */
108 
109 
110 /**
111  * Get MRCP generic header.
112  * @param message the message to get generic header from
113  */
114 static APR_INLINE mrcp_generic_header_t* mrcp_generic_header_get(const mrcp_message_t *message)
115 {
117 }
118 
119 /**
120  * Allocate (if not allocated) and get MRCP generic header.
121  * @param message the message to prepare generic header for
122  */
123 static APR_INLINE mrcp_generic_header_t* mrcp_generic_header_prepare(mrcp_message_t *message)
124 {
125  return (mrcp_generic_header_t*) mrcp_header_allocate(&message->header.generic_header_accessor,message->pool);
126 }
127 
128 /**
129  * Add MRCP generic header field by specified property (numeric identifier).
130  * @param message the message to add property for
131  * @param id the numeric identifier to add
132  */
134 
135 /**
136  * Add only the name of MRCP generic header field specified by property (numeric identifier).
137  * @param message the message to add property for
138  * @param id the numeric identifier to add
139  * @remark Should be used to construct empty header fiedls for GET-PARAMS requests
140  */
142 
143 /**
144  * Remove MRCP generic header field by specified property (numeric identifier).
145  * @param message the message to remove property from
146  * @param id the numeric identifier to remove
147  */
148 static APR_INLINE apt_bool_t mrcp_generic_header_property_remove(mrcp_message_t *message, apr_size_t id)
149 {
150  apt_header_field_t *header_field = apt_header_section_field_get(&message->header.header_section,id);
151  if(header_field) {
152  return apt_header_section_field_remove(&message->header.header_section,header_field);
153  }
154  return FALSE;
155 }
156 
157 /**
158  * Check whether specified by property (numeric identifier) MRCP generic header field is set or not.
159  * @param message the message to use
160  * @param id the numeric identifier to check
161  */
162 static APR_INLINE apt_bool_t mrcp_generic_header_property_check(const mrcp_message_t *message, apr_size_t id)
163 {
164  return apt_header_section_field_check(&message->header.header_section,id);
165 }
166 
167 
168 /**
169  * Get MRCP resource header.
170  * @param message the message to get resource header from
171  */
172 static APR_INLINE void* mrcp_resource_header_get(const mrcp_message_t *message)
173 {
174  return message->header.resource_header_accessor.data;
175 }
176 
177 /**
178  * Allocate (if not allocated) and get MRCP resource header.
179  * @param message the message to prepare resource header for
180  */
181 static APR_INLINE void* mrcp_resource_header_prepare(mrcp_message_t *mrcp_message)
182 {
183  return mrcp_header_allocate(&mrcp_message->header.resource_header_accessor,mrcp_message->pool);
184 }
185 
186 /**
187  * Add MRCP resource header field by specified property (numeric identifier).
188  * @param message the message to add property for
189  * @param id the numeric identifier to add
190  */
192 
193 /**
194  * Add only the name of MRCP resource header field specified by property (numeric identifier).
195  * @param message the message to add property for
196  * @param id the numeric identifier to add
197  * @remark Should be used to construct empty header fiedls for GET-PARAMS requests
198  */
200 
201 /**
202  * Remove MRCP resource header field by specified property (numeric identifier).
203  * @param message the message to remove property from
204  * @param id the numeric identifier to remove
205  */
206 static APR_INLINE apt_bool_t mrcp_resource_header_property_remove(mrcp_message_t *message, apr_size_t id)
207 {
208  apt_header_field_t *header_field = apt_header_section_field_get(&message->header.header_section,id + GENERIC_HEADER_COUNT);
209  if(header_field) {
210  return apt_header_section_field_remove(&message->header.header_section,header_field);
211  }
212  return FALSE;
213 }
214 
215 /**
216  * Check whether specified by property (numeric identifier) MRCP resource header field is set or not.
217  * @param message the message to use
218  * @param id the numeric identifier to check
219  */
220 static APR_INLINE apt_bool_t mrcp_resource_header_property_check(const mrcp_message_t *message, apr_size_t id)
221 {
222  return apt_header_section_field_check(&message->header.header_section,id + GENERIC_HEADER_COUNT);
223 }
224 
225 /**
226  * Add MRCP header field.
227  * @param message the message to add header field for
228  * @param header_field the header field to add
229  */
230 static APR_INLINE apt_bool_t mrcp_message_header_field_add(mrcp_message_t *message, apt_header_field_t *header_field)
231 {
232  return mrcp_header_field_add(&message->header,header_field,message->pool);
233 }
234 
235 /**
236  * Get the next MRCP header field.
237  * @param message the message to use
238  * @param header_field current header field
239  * @remark Should be used to iterate on header fields
240  *
241  * apt_header_field_t *header_field = NULL;
242  * while( (header_field = mrcp_message_next_header_field_get(message,header_field)) != NULL ) {
243  * }
244  */
246  const mrcp_message_t *message,
247  apt_header_field_t *header_field);
248 
250 
251 #endif /* MRCP_MESSAGE_H */
Definition: mrcp_start_line.h:79
mrcp_header_accessor_t resource_header_accessor
Definition: mrcp_header.h:46
mrcp_message_t * mrcp_response_create(const mrcp_message_t *request_message, apr_pool_t *pool)
#define MRCP_DECLARE(type)
Definition: mrcp.h:40
apt_bool_t mrcp_message_resource_set(mrcp_message_t *message, const mrcp_resource_t *resource)
mrcp_message_t * mrcp_event_create(const mrcp_message_t *request_message, mrcp_method_id event_id, apr_pool_t *pool)
apt_bool_t apt_header_section_field_remove(apt_header_section_t *header, apt_header_field_t *header_field)
mrcp_message_header_t header
Definition: mrcp_message.h:43
apr_size_t mrcp_method_id
Definition: mrcp_types.h:66
const mrcp_resource_t * resource
Definition: mrcp_message.h:48
#define APT_END_EXTERN_C
Definition: apt.h:38
int apt_bool_t
Definition: apt.h:57
apt_header_section_t header_section
Definition: mrcp_header.h:49
apt_bool_t mrcp_resource_header_property_add(mrcp_message_t *message, apr_size_t id)
mrcp_channel_id channel_id
Definition: mrcp_message.h:41
mrcp_message_t * mrcp_request_create(const mrcp_resource_t *resource, mrcp_version_e version, mrcp_method_id method_id, apr_pool_t *pool)
apt_bool_t mrcp_message_validate(mrcp_message_t *message)
mrcp_version_e
Definition: mrcp_types.h:30
Definition: apt_header_field.h:39
apt_bool_t mrcp_generic_header_name_property_add(mrcp_message_t *message, apr_size_t id)
Definition: mrcp_generic_header.h:73
#define APT_BEGIN_EXTERN_C
Definition: apt.h:36
Definition: mrcp_header.h:42
apt_bool_t mrcp_header_field_add(mrcp_message_header_t *header, apt_header_field_t *header_field, apr_pool_t *pool)
Definition: mrcp_header.h:53
Basic MRCP Types.
void mrcp_message_destroy(mrcp_message_t *message)
apr_pool_t * pool
Definition: mrcp_message.h:50
apt_str_t body
Definition: mrcp_message.h:45
mrcp_message_t * mrcp_message_create(apr_pool_t *pool)
MRCP Message Header Definition.
mrcp_header_accessor_t generic_header_accessor
Definition: mrcp_header.h:44
Definition: apt_string.h:36
void * data
Definition: mrcp_header_accessor.h:59
mrcp_start_line_t start_line
Definition: mrcp_message.h:39
apt_bool_t mrcp_generic_header_property_add(mrcp_message_t *message, apr_size_t id)
apt_header_field_t * mrcp_message_next_header_field_get(const mrcp_message_t *message, apt_header_field_t *header_field)
MRCP Generic Header.
MRCP Start Line Definition.
apt_bool_t mrcp_resource_header_name_property_add(mrcp_message_t *message, apr_size_t id)
Definition: mrcp_resource.h:32
Definition: mrcp_message.h:37