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