UniMRCP  1.3.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mrcp_header_accessor.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_header_accessor.h 2136 2014-07-04 06:33:36Z achaloyan@gmail.com $
17  */
18 
19 #ifndef MRCP_HEADER_ACCESSOR_H
20 #define MRCP_HEADER_ACCESSOR_H
21 
22 /**
23  * @file mrcp_header_accessor.h
24  * @brief Abstract MRCP Header Accessor
25  */
26 
27 #include "apt_text_stream.h"
28 #include "apt_header_field.h"
29 #include "mrcp.h"
30 
32 
33 /** MRCP header accessor declaration */
35 /** MRCP header vtable declaration */
37 
38 /** MRCP header accessor interface */
40  /** Allocate actual header data */
41  void* (*allocate)(mrcp_header_accessor_t *accessor, apr_pool_t *pool);
42  /** Destroy header data */
43  void (*destroy)(mrcp_header_accessor_t *accessor);
44 
45  /** Parse header field value */
46  apt_bool_t (*parse_field)(mrcp_header_accessor_t *accessor, apr_size_t id, const apt_str_t *value, apr_pool_t *pool);
47  /** Generate header field value */
48  apt_bool_t (*generate_field)(const mrcp_header_accessor_t *accessor, apr_size_t id, apt_str_t *value, apr_pool_t *pool);
49  /** Duplicate header field value */
50  apt_bool_t (*duplicate_field)(mrcp_header_accessor_t *accessor, const mrcp_header_accessor_t *src, apr_size_t id, const apt_str_t *value, apr_pool_t *pool);
51 
52  /** Table of fields */
54  /** Number of fields */
55  apr_size_t field_count;
56 };
57 
58 /** MRCP header accessor */
60  /** Actual header data allocated by accessor */
61  void *data;
62  /** Header accessor interface */
64 };
65 
66 
67 
68 /** Initialize header vtable */
69 static APR_INLINE void mrcp_header_vtable_init(mrcp_header_vtable_t *vtable)
70 {
71  vtable->allocate = NULL;
72  vtable->destroy = NULL;
73  vtable->parse_field = NULL;
74  vtable->generate_field = NULL;
75  vtable->duplicate_field = NULL;
76  vtable->field_table = NULL;
77  vtable->field_count = 0;
78 }
79 
80 /** Validate header vtable */
81 static APR_INLINE apt_bool_t mrcp_header_vtable_validate(const mrcp_header_vtable_t *vtable)
82 {
83  return (vtable->allocate && vtable->destroy &&
84  vtable->parse_field && vtable->generate_field &&
85  vtable->duplicate_field && vtable->field_table &&
86  vtable->field_count) ? TRUE : FALSE;
87 }
88 
89 
90 /** Initialize header accessor */
91 static APR_INLINE void mrcp_header_accessor_init(mrcp_header_accessor_t *accessor)
92 {
93  accessor->data = NULL;
94  accessor->vtable = NULL;
95 }
96 
97 /** Allocate header data */
98 static APR_INLINE void* mrcp_header_allocate(mrcp_header_accessor_t *accessor, apr_pool_t *pool)
99 {
100  if(accessor->data) {
101  return accessor->data;
102  }
103  if(!accessor->vtable || !accessor->vtable->allocate) {
104  return NULL;
105  }
106  return accessor->vtable->allocate(accessor,pool);
107 }
108 
109 /** Destroy header data */
110 static APR_INLINE void mrcp_header_destroy(mrcp_header_accessor_t *accessor)
111 {
112  if(!accessor->vtable || !accessor->vtable->destroy) {
113  return;
114  }
115  accessor->vtable->destroy(accessor);
116 }
117 
118 
119 /** Parse header field value */
121 
122 /** Generate header field value */
123 MRCP_DECLARE(apt_header_field_t*) mrcp_header_field_value_generate(const mrcp_header_accessor_t *accessor, apr_size_t id, apt_bool_t empty_value, apr_pool_t *pool);
124 
125 /** Duplicate header field value */
126 MRCP_DECLARE(apt_bool_t) mrcp_header_field_value_duplicate(mrcp_header_accessor_t *accessor, const mrcp_header_accessor_t *src_accessor, apr_size_t id, const apt_str_t *value, apr_pool_t *pool);
127 
128 
130 
131 #endif /* MRCP_HEADER_ACCESSOR_H */