UniMRCP  1.4.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,
75 
76 /** Reason phrases */
77 typedef enum {
78  RTSP_REASON_PHRASE_OK,
79  RTSP_REASON_PHRASE_CREATED,
80  RTSP_REASON_PHRASE_BAD_REQUEST,
81  RTSP_REASON_PHRASE_UNAUTHORIZED,
82  RTSP_REASON_PHRASE_NOT_FOUND,
83  RTSP_REASON_PHRASE_METHOD_NOT_ALLOWED,
84  RTSP_REASON_PHRASE_NOT_ACCEPTABLE,
85  RTSP_REASON_PHRASE_PROXY_AUTH_REQUIRED,
86  RTSP_REASON_PHRASE_REQUEST_TIMEOUT,
87  RTSP_REASON_PHRASE_SESSION_NOT_FOUND,
88  RTSP_REASON_PHRASE_INTERNAL_SERVER_ERROR,
89  RTSP_REASON_PHRASE_NOT_IMPLEMENTED,
90  RTSP_REASON_PHRASE_COUNT,
91 
92  /** Unknown reason phrase */
93  RTSP_REASON_PHRASE_UNKNOWN = RTSP_REASON_PHRASE_COUNT
95 
96 
97 /** RTSP request-line declaration */
99 /** RTSP status-line declaration */
101 /** RTSP start-line declaration */
103 
104 /** RTSP request-line */
106  /** Method name */
108  /** Method id */
110  /** RTSP URL */
112  /** Resource name parsed from RTSP URL */
113  const char *resource_name;
114  /** Version of protocol in use */
116 };
117 
118 /** RTSP status-line */
120  /** Version of protocol in use */
122  /** success or failure or other status of the request */
124  /** Reason phrase */
126 };
127 
128 /** RTSP start-line */
130  /** RTSP message type */
132  /** RTSP start-line */
133  union {
134  rtsp_request_line_t request_line;
135  rtsp_status_line_t status_line;
136  } common;
137 };
138 
139 
140 static APR_INLINE void rtsp_request_line_init(rtsp_request_line_t *request_line)
141 {
142  apt_string_reset(&request_line->method_name);
143  request_line->method_id = RTSP_METHOD_UNKNOWN;
144  apt_string_reset(&request_line->url);
145  request_line->resource_name = NULL;
146  request_line->version = RTSP_VERSION_1;
147 }
148 
149 static APR_INLINE void rtsp_status_line_init(rtsp_status_line_t *status_line)
150 {
151  status_line->version = RTSP_VERSION_1;
152  status_line->status_code = RTSP_STATUS_CODE_OK;
153  apt_string_reset(&status_line->reason);
154 }
155 
156 /** Initialize RTSP start-line */
157 static APR_INLINE void rtsp_start_line_init(rtsp_start_line_t *start_line, rtsp_message_type_e message_type)
158 {
159  start_line->message_type = message_type;
160  if(message_type == RTSP_MESSAGE_TYPE_REQUEST) {
161  rtsp_request_line_init(&start_line->common.request_line);
162  }
163  else if(message_type == RTSP_MESSAGE_TYPE_RESPONSE) {
164  rtsp_status_line_init(&start_line->common.status_line);
165  }
166 }
167 
168 /** Parse RTSP start-line */
169 RTSP_DECLARE(apt_bool_t) rtsp_start_line_parse(rtsp_start_line_t *start_line, apt_str_t *str, apr_pool_t *pool);
170 
171 /** Generate RTSP start-line */
173 
174 /** Get reason phrase by status code */
176 
178 
179 #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:129
Definition: apt_text_stream.h:43
Definition: rtsp_start_line.h:60
rtsp_version_e version
Definition: rtsp_start_line.h:115
#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:113
rtsp_version_e version
Definition: rtsp_start_line.h:121
rtsp_reason_phrase_e
Definition: rtsp_start_line.h:77
rtsp_version_e
Definition: rtsp_start_line.h:31
Definition: rtsp_start_line.h:119
rtsp_method_id
Definition: rtsp_start_line.h:46
rtsp_message_type_e
Definition: rtsp_start_line.h:39
Definition: rtsp_start_line.h:105
#define APT_BEGIN_EXTERN_C
Definition: apt.h:36
rtsp_method_id method_id
Definition: rtsp_start_line.h:109
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:123
apt_str_t reason
Definition: rtsp_start_line.h:125
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:111
Definition: apt_string.h:36
Definition: rtsp_start_line.h:33
apt_str_t method_name
Definition: rtsp_start_line.h:107
union rtsp_start_line_t::@8 common
RTSP Core Definitions.
Definition: rtsp_start_line.h:93
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:131
Text Stream Parse/Generate Routine.