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: rtsp_start_line.h 2136 2014-07-04 06:33:36Z achaloyan@gmail.com $
17 */
18
19 #ifndef RTSP_START_LINE_H
20 #define RTSP_START_LINE_H
21
22 /**
23 * @file rtsp_start_line.h
24 * @brief RTSP Start Line (request-line/status-line)
25 */
26
27 #include "rtsp.h"
28 #include "apt_text_stream.h"
29
30 APT_BEGIN_EXTERN_C
31
32 /** Protocol version */
33 typedef enum {
34 /** Unknown version */
35 RTSP_VERSION_UNKNOWN = 0,
36 /** RTSP 1.0 */
37 RTSP_VERSION_1 = 1,
38 } rtsp_version_e;
39
40 /** RTSP message types */
41 typedef enum {
42 RTSP_MESSAGE_TYPE_UNKNOWN,
43 RTSP_MESSAGE_TYPE_REQUEST,
44 RTSP_MESSAGE_TYPE_RESPONSE
45 } rtsp_message_type_e;
46
47 /** RTSP methods */
48 typedef enum{
49 RTSP_METHOD_SETUP,
50 RTSP_METHOD_ANNOUNCE,
51 RTSP_METHOD_TEARDOWN,
52 RTSP_METHOD_DESCRIBE,
53
54 RTSP_METHOD_COUNT,
55 RTSP_METHOD_UNKNOWN = RTSP_METHOD_COUNT
56 } rtsp_method_id;
57
58 /** Status codes */
59 typedef enum {
60 RTSP_STATUS_CODE_UNKNOWN = 0,
61 /** Success codes (2xx) */
62 RTSP_STATUS_CODE_OK = 200,
63 RTSP_STATUS_CODE_CREATED = 201,
64 /** Failure codec (4xx) */
65 RTSP_STATUS_CODE_BAD_REQUEST = 400,
66 RTSP_STATUS_CODE_UNAUTHORIZED = 401,
67 RTSP_STATUS_CODE_NOT_FOUND = 404,
68 RTSP_STATUS_CODE_METHOD_NOT_ALLOWED = 405,
69 RTSP_STATUS_CODE_NOT_ACCEPTABLE = 406,
70 RTSP_STATUS_CODE_PROXY_AUTH_REQUIRED = 407,
71 RTSP_STATUS_CODE_REQUEST_TIMEOUT = 408,
72 RTSP_STATUS_CODE_SESSION_NOT_FOUND = 454,
73
74 RTSP_STATUS_CODE_INTERNAL_SERVER_ERROR = 500,
75 RTSP_STATUS_CODE_NOT_IMPLEMENTED = 501,
76 } rtsp_status_code_e;
77
78 /** Reason phrases */
79 typedef enum {
80 RTSP_REASON_PHRASE_OK,
81 RTSP_REASON_PHRASE_CREATED,
82 RTSP_REASON_PHRASE_BAD_REQUEST,
83 RTSP_REASON_PHRASE_UNAUTHORIZED,
84 RTSP_REASON_PHRASE_NOT_FOUND,
85 RTSP_REASON_PHRASE_METHOD_NOT_ALLOWED,
86 RTSP_REASON_PHRASE_NOT_ACCEPTABLE,
87 RTSP_REASON_PHRASE_PROXY_AUTH_REQUIRED,
88 RTSP_REASON_PHRASE_REQUEST_TIMEOUT,
89 RTSP_REASON_PHRASE_SESSION_NOT_FOUND,
90 RTSP_REASON_PHRASE_INTERNAL_SERVER_ERROR,
91 RTSP_REASON_PHRASE_NOT_IMPLEMENTED,
92 RTSP_REASON_PHRASE_COUNT,
93
94 /** Unknown reason phrase */
95 RTSP_REASON_PHRASE_UNKNOWN = RTSP_REASON_PHRASE_COUNT
96 } rtsp_reason_phrase_e;
97
98
99 /** RTSP request-line declaration */
100 typedef struct rtsp_request_line_t rtsp_request_line_t;
101 /** RTSP status-line declaration */
102 typedef struct rtsp_status_line_t rtsp_status_line_t;
103 /** RTSP start-line declaration */
104 typedef struct rtsp_start_line_t rtsp_start_line_t;
105
106 /** RTSP request-line */
107 struct rtsp_request_line_t {
108 /** Method name */
109 apt_str_t method_name;
110 /** Method id */
111 rtsp_method_id method_id;
112 /** RTSP URL */
113 apt_str_t url;
114 /** Resource name parsed from RTSP URL */
115 const char *resource_name;
116 /** Version of protocol in use */
117 rtsp_version_e version;
118 };
119
120 /** RTSP status-line */
121 struct rtsp_status_line_t {
122 /** Version of protocol in use */
123 rtsp_version_e version;
124 /** success or failure or other status of the request */
125 rtsp_status_code_e status_code;
126 /** Reason phrase */
127 apt_str_t reason;
128 };
129
130 /** RTSP start-line */
131 struct rtsp_start_line_t {
132 /** RTSP message type */
133 rtsp_message_type_e 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
rtsp_request_line_init(rtsp_request_line_t * request_line)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
rtsp_status_line_init(rtsp_status_line_t * status_line)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 */
rtsp_start_line_init(rtsp_start_line_t * start_line,rtsp_message_type_e message_type)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 */
174 RTSP_DECLARE(apt_bool_t) rtsp_start_line_generate(rtsp_start_line_t *start_line, apt_text_stream_t *text_stream);
175
176 /** Get reason phrase by status code */
177 RTSP_DECLARE(const apt_str_t*) rtsp_reason_phrase_get(rtsp_reason_phrase_e reason);
178
179 APT_END_EXTERN_C
180
181 #endif /* RTSP_START_LINE_H */
182