UniMRCP  1.7.0
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  RTSP_METHOD_OPTIONS,
52 
53  RTSP_METHOD_COUNT,
54  RTSP_METHOD_UNKNOWN = RTSP_METHOD_COUNT
56 
57 /** Status codes */
58 typedef enum {
59  RTSP_STATUS_CODE_UNKNOWN = 0,
60  /** Success codes (2xx) */
62  RTSP_STATUS_CODE_CREATED = 201,
63  /** Failure codec (4xx) */
65  RTSP_STATUS_CODE_UNAUTHORIZED = 401,
66  RTSP_STATUS_CODE_NOT_FOUND = 404,
67  RTSP_STATUS_CODE_METHOD_NOT_ALLOWED = 405,
68  RTSP_STATUS_CODE_NOT_ACCEPTABLE = 406,
69  RTSP_STATUS_CODE_PROXY_AUTH_REQUIRED = 407,
70  RTSP_STATUS_CODE_REQUEST_TIMEOUT = 408,
71  RTSP_STATUS_CODE_SESSION_NOT_FOUND = 454,
72 
73  RTSP_STATUS_CODE_INTERNAL_SERVER_ERROR = 500,
74  RTSP_STATUS_CODE_NOT_IMPLEMENTED = 501,
75  RTSP_STATUS_CODE_SERVICE_UNAVAILABLE = 503
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_SERVICE_UNAVAILABLE,
93  RTSP_REASON_PHRASE_COUNT,
94 
95  /** Unknown reason phrase */
96  RTSP_REASON_PHRASE_UNKNOWN = RTSP_REASON_PHRASE_COUNT
98 
99 
100 /** RTSP request-line declaration */
102 /** RTSP status-line declaration */
104 /** RTSP start-line declaration */
106 
107 /** RTSP request-line */
109  /** Method name */
111  /** Method id */
113  /** RTSP URL */
115  /** Resource name parsed from RTSP URL */
116  const char *resource_name;
117  /** Version of protocol in use */
119 };
120 
121 /** RTSP status-line */
123  /** Version of protocol in use */
125  /** success or failure or other status of the request */
127  /** Reason phrase */
129 };
130 
131 /** RTSP start-line */
133  /** RTSP message type */
135  /** RTSP start-line */
136  union {
137  rtsp_request_line_t request_line;
138  rtsp_status_line_t status_line;
139  } common;
140 };
141 
142 
143 static APR_INLINE void rtsp_request_line_init(rtsp_request_line_t *request_line)
144 {
145  apt_string_reset(&request_line->method_name);
146  request_line->method_id = RTSP_METHOD_UNKNOWN;
147  apt_string_reset(&request_line->url);
148  request_line->resource_name = NULL;
149  request_line->version = RTSP_VERSION_1;
150 }
151 
152 static APR_INLINE void rtsp_status_line_init(rtsp_status_line_t *status_line)
153 {
154  status_line->version = RTSP_VERSION_1;
155  status_line->status_code = RTSP_STATUS_CODE_OK;
156  apt_string_reset(&status_line->reason);
157 }
158 
159 /** Initialize RTSP start-line */
160 static APR_INLINE void rtsp_start_line_init(rtsp_start_line_t *start_line, rtsp_message_type_e message_type)
161 {
162  start_line->message_type = message_type;
163  if(message_type == RTSP_MESSAGE_TYPE_REQUEST) {
164  rtsp_request_line_init(&start_line->common.request_line);
165  }
166  else if(message_type == RTSP_MESSAGE_TYPE_RESPONSE) {
167  rtsp_status_line_init(&start_line->common.status_line);
168  }
169 }
170 
171 /** Parse RTSP start-line */
172 RTSP_DECLARE(apt_bool_t) rtsp_start_line_parse(rtsp_start_line_t *start_line, apt_str_t *str, apr_pool_t *pool);
173 
174 /** Generate RTSP start-line */
176 
177 /** Get reason phrase by status code */
179 
181 
182 #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:132
Definition: apt_text_stream.h:43
Definition: rtsp_start_line.h:61
rtsp_version_e version
Definition: rtsp_start_line.h:118
#define APT_END_EXTERN_C
Definition: apt.h:38
int apt_bool_t
Definition: apt.h:57
Definition: rtsp_start_line.h:64
const char * resource_name
Definition: rtsp_start_line.h:116
rtsp_version_e version
Definition: rtsp_start_line.h:124
rtsp_reason_phrase_e
Definition: rtsp_start_line.h:79
rtsp_version_e
Definition: rtsp_start_line.h:31
Definition: rtsp_start_line.h:122
rtsp_method_id
Definition: rtsp_start_line.h:46
rtsp_message_type_e
Definition: rtsp_start_line.h:39
Definition: rtsp_start_line.h:108
#define APT_BEGIN_EXTERN_C
Definition: apt.h:36
rtsp_method_id method_id
Definition: rtsp_start_line.h:112
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:126
apt_str_t reason
Definition: rtsp_start_line.h:128
Definition: rtsp_start_line.h:35
rtsp_status_code_e
Definition: rtsp_start_line.h:58
apt_str_t url
Definition: rtsp_start_line.h:114
Definition: apt_string.h:36
Definition: rtsp_start_line.h:33
apt_str_t method_name
Definition: rtsp_start_line.h:110
union rtsp_start_line_t::@8 common
RTSP Core Definitions.
Definition: rtsp_start_line.h:96
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:134
Text Stream Parse/Generate Routine.