UniMRCP  1.5.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
rtsp_start_line.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 RTSP_START_LINE_H
18 #define RTSP_START_LINE_H
19 
20 /**
21  * @file rtsp_start_line.h
22  * @brief RTSP Start Line (request-line/status-line)
23  */
24 
25 #include "rtsp.h"
26 #include "apt_text_stream.h"
27 
29 
30 /** Protocol version */
31 typedef enum {
32  /** Unknown version */
34  /** RTSP 1.0 */
37 
38 /** RTSP message types */
39 typedef enum {
40  RTSP_MESSAGE_TYPE_UNKNOWN,
41  RTSP_MESSAGE_TYPE_REQUEST,
42  RTSP_MESSAGE_TYPE_RESPONSE
44 
45 /** RTSP methods */
46 typedef enum{
47  RTSP_METHOD_SETUP,
48  RTSP_METHOD_ANNOUNCE,
49  RTSP_METHOD_TEARDOWN,
50  RTSP_METHOD_DESCRIBE,
51 
52  RTSP_METHOD_COUNT,
53  RTSP_METHOD_UNKNOWN = RTSP_METHOD_COUNT
55 
56 /** Status codes */
57 typedef enum {
58  RTSP_STATUS_CODE_UNKNOWN = 0,
59  /** Success codes (2xx) */
61  RTSP_STATUS_CODE_CREATED = 201,
62  /** Failure codec (4xx) */
64  RTSP_STATUS_CODE_UNAUTHORIZED = 401,
65  RTSP_STATUS_CODE_NOT_FOUND = 404,
66  RTSP_STATUS_CODE_METHOD_NOT_ALLOWED = 405,
67  RTSP_STATUS_CODE_NOT_ACCEPTABLE = 406,
68  RTSP_STATUS_CODE_PROXY_AUTH_REQUIRED = 407,
69  RTSP_STATUS_CODE_REQUEST_TIMEOUT = 408,
70  RTSP_STATUS_CODE_SESSION_NOT_FOUND = 454,
71 
72  RTSP_STATUS_CODE_INTERNAL_SERVER_ERROR = 500,
73  RTSP_STATUS_CODE_NOT_IMPLEMENTED = 501,
74  RTSP_STATUS_CODE_SERVICE_UNAVAILABLE = 503
76 
77 /** Reason phrases */
78 typedef enum {
79  RTSP_REASON_PHRASE_OK,
80  RTSP_REASON_PHRASE_CREATED,
81  RTSP_REASON_PHRASE_BAD_REQUEST,
82  RTSP_REASON_PHRASE_UNAUTHORIZED,
83  RTSP_REASON_PHRASE_NOT_FOUND,
84  RTSP_REASON_PHRASE_METHOD_NOT_ALLOWED,
85  RTSP_REASON_PHRASE_NOT_ACCEPTABLE,
86  RTSP_REASON_PHRASE_PROXY_AUTH_REQUIRED,
87  RTSP_REASON_PHRASE_REQUEST_TIMEOUT,
88  RTSP_REASON_PHRASE_SESSION_NOT_FOUND,
89  RTSP_REASON_PHRASE_INTERNAL_SERVER_ERROR,
90  RTSP_REASON_PHRASE_NOT_IMPLEMENTED,
91  RTSP_REASON_PHRASE_SERVICE_UNAVAILABLE,
92  RTSP_REASON_PHRASE_COUNT,
93 
94  /** Unknown reason phrase */
95  RTSP_REASON_PHRASE_UNKNOWN = RTSP_REASON_PHRASE_COUNT
97 
98 
99 /** RTSP request-line declaration */
101 /** RTSP status-line declaration */
103 /** RTSP start-line declaration */
105 
106 /** RTSP request-line */
108  /** Method name */
110  /** Method id */
112  /** RTSP URL */
114  /** Resource name parsed from RTSP URL */
115  const char *resource_name;
116  /** Version of protocol in use */
118 };
119 
120 /** RTSP status-line */
122  /** Version of protocol in use */
124  /** success or failure or other status of the request */
126  /** Reason phrase */
128 };
129 
130 /** RTSP start-line */
132  /** RTSP message type */
134  /** RTSP start-line */
135  union {
136  rtsp_request_line_t request_line;
137  rtsp_status_line_t status_line;
138  } common;
139 };
140 
141 
142 static APR_INLINE void rtsp_request_line_init(rtsp_request_line_t *request_line)
143 {
144  apt_string_reset(&request_line->method_name);
145  request_line->method_id = RTSP_METHOD_UNKNOWN;
146  apt_string_reset(&request_line->url);
147  request_line->resource_name = NULL;
148  request_line->version = RTSP_VERSION_1;
149 }
150 
151 static APR_INLINE void rtsp_status_line_init(rtsp_status_line_t *status_line)
152 {
153  status_line->version = RTSP_VERSION_1;
154  status_line->status_code = RTSP_STATUS_CODE_OK;
155  apt_string_reset(&status_line->reason);
156 }
157 
158 /** Initialize RTSP start-line */
159 static APR_INLINE void rtsp_start_line_init(rtsp_start_line_t *start_line, rtsp_message_type_e message_type)
160 {
161  start_line->message_type = message_type;
162  if(message_type == RTSP_MESSAGE_TYPE_REQUEST) {
163  rtsp_request_line_init(&start_line->common.request_line);
164  }
165  else if(message_type == RTSP_MESSAGE_TYPE_RESPONSE) {
166  rtsp_status_line_init(&start_line->common.status_line);
167  }
168 }
169 
170 /** Parse RTSP start-line */
171 RTSP_DECLARE(apt_bool_t) rtsp_start_line_parse(rtsp_start_line_t *start_line, apt_str_t *str, apr_pool_t *pool);
172 
173 /** Generate RTSP start-line */
175 
176 /** Get reason phrase by status code */
178 
180 
181 #endif /* RTSP_START_LINE_H */
apt_bool_t rtsp_start_line_parse(rtsp_start_line_t *start_line, apt_str_t *str, apr_pool_t *pool)
Definition: rtsp_start_line.h:131
Definition: apt_text_stream.h:43
Definition: rtsp_start_line.h:60
rtsp_version_e version
Definition: rtsp_start_line.h:117
#define APT_END_EXTERN_C
Definition: apt.h:38
int apt_bool_t
Definition: apt.h:57
Definition: rtsp_start_line.h:63
const char * resource_name
Definition: rtsp_start_line.h:115
rtsp_version_e version
Definition: rtsp_start_line.h:123
rtsp_reason_phrase_e
Definition: rtsp_start_line.h:78
rtsp_version_e
Definition: rtsp_start_line.h:31
Definition: rtsp_start_line.h:121
rtsp_method_id
Definition: rtsp_start_line.h:46
rtsp_message_type_e
Definition: rtsp_start_line.h:39
Definition: rtsp_start_line.h:107
#define APT_BEGIN_EXTERN_C
Definition: apt.h:36
rtsp_method_id method_id
Definition: rtsp_start_line.h:111
const apt_str_t * rtsp_reason_phrase_get(rtsp_reason_phrase_e reason)
#define RTSP_DECLARE(type)
Definition: rtsp.h:41
rtsp_status_code_e status_code
Definition: rtsp_start_line.h:125
apt_str_t reason
Definition: rtsp_start_line.h:127
Definition: rtsp_start_line.h:35
rtsp_status_code_e
Definition: rtsp_start_line.h:57
apt_str_t url
Definition: rtsp_start_line.h:113
Definition: apt_string.h:36
Definition: rtsp_start_line.h:33
apt_str_t method_name
Definition: rtsp_start_line.h:109
union rtsp_start_line_t::@8 common
RTSP Core Definitions.
Definition: rtsp_start_line.h:95
apt_bool_t rtsp_start_line_generate(rtsp_start_line_t *start_line, apt_text_stream_t *text_stream)
rtsp_message_type_e message_type
Definition: rtsp_start_line.h:133
Text Stream Parse/Generate Routine.