1 /*
2 * Copyright 2012 The Netty Project
3 *
4 * The Netty Project licenses this file to you under the Apache License,
5 * version 2.0 (the "License"); you may not use this file except in compliance
6 * with the License. You may obtain a copy of the License at:
7 *
8 * https://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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16 package io.netty.handler.codec.rtsp;
17
18 import static io.netty.util.internal.ObjectUtil.checkNonEmptyAfterTrim;
19
20 import io.netty.handler.codec.http.HttpMethod;
21
22 import java.util.HashMap;
23 import java.util.Locale;
24 import java.util.Map;
25
26 /**
27 * The request getMethod of RTSP.
28 */
29 public final class RtspMethods {
30
31 /**
32 * The OPTIONS getMethod represents a request for information about the communication options
33 * available on the request/response chain identified by the Request-URI. This getMethod allows
34 * the client to determine the options and/or requirements associated with a resource, or the
35 * capabilities of a server, without implying a resource action or initiating a resource
36 * retrieval.
37 */
38 public static final HttpMethod OPTIONS = HttpMethod.OPTIONS;
39
40 /**
41 * The DESCRIBE getMethod retrieves the description of a presentation or
42 * media object identified by the request URL from a server.
43 */
44 public static final HttpMethod DESCRIBE = HttpMethod.valueOf("DESCRIBE");
45
46 /**
47 * The ANNOUNCE posts the description of a presentation or media object
48 * identified by the request URL to a server, or updates the client-side
49 * session description in real-time.
50 */
51 public static final HttpMethod ANNOUNCE = HttpMethod.valueOf("ANNOUNCE");
52
53 /**
54 * The SETUP request for a URI specifies the transport mechanism to be
55 * used for the streamed media.
56 */
57 public static final HttpMethod SETUP = HttpMethod.valueOf("SETUP");
58
59 /**
60 * The PLAY getMethod tells the server to start sending data via the
61 * mechanism specified in SETUP.
62 */
63 public static final HttpMethod PLAY = HttpMethod.valueOf("PLAY");
64
65 /**
66 * The PAUSE request causes the stream delivery to be interrupted
67 * (halted) temporarily.
68 */
69 public static final HttpMethod PAUSE = HttpMethod.valueOf("PAUSE");
70
71 /**
72 * The TEARDOWN request stops the stream delivery for the given URI,
73 * freeing the resources associated with it.
74 */
75 public static final HttpMethod TEARDOWN = HttpMethod.valueOf("TEARDOWN");
76
77 /**
78 * The GET_PARAMETER request retrieves the value of a parameter of a
79 * presentation or stream specified in the URI.
80 */
81 public static final HttpMethod GET_PARAMETER = HttpMethod.valueOf("GET_PARAMETER");
82
83 /**
84 * The SET_PARAMETER requests to set the value of a parameter for a
85 * presentation or stream specified by the URI.
86 */
87 public static final HttpMethod SET_PARAMETER = HttpMethod.valueOf("SET_PARAMETER");
88
89 /**
90 * The REDIRECT request informs the client that it must connect to another
91 * server location.
92 */
93 public static final HttpMethod REDIRECT = HttpMethod.valueOf("REDIRECT");
94
95 /**
96 * The RECORD getMethod initiates recording a range of media data according to
97 * the presentation description.
98 */
99 public static final HttpMethod RECORD = HttpMethod.valueOf("RECORD");
100
101 private static final Map<String, HttpMethod> methodMap = new HashMap<String, HttpMethod>();
102
103 static {
104 methodMap.put(DESCRIBE.toString(), DESCRIBE);
105 methodMap.put(ANNOUNCE.toString(), ANNOUNCE);
106 methodMap.put(GET_PARAMETER.toString(), GET_PARAMETER);
107 methodMap.put(OPTIONS.toString(), OPTIONS);
108 methodMap.put(PAUSE.toString(), PAUSE);
109 methodMap.put(PLAY.toString(), PLAY);
110 methodMap.put(RECORD.toString(), RECORD);
111 methodMap.put(REDIRECT.toString(), REDIRECT);
112 methodMap.put(SETUP.toString(), SETUP);
113 methodMap.put(SET_PARAMETER.toString(), SET_PARAMETER);
114 methodMap.put(TEARDOWN.toString(), TEARDOWN);
115 }
116
117 /**
118 * Returns the {@link HttpMethod} represented by the specified name.
119 * If the specified name is a standard RTSP getMethod name, a cached instance
120 * will be returned. Otherwise, a new instance will be returned.
121 */
122 public static HttpMethod valueOf(String name) {
123 // RFC 2326 RTSP method names are ASCII tokens. toUpperCase() without an explicit Locale
124 // uses the JVM default, which in Turkish (tr_TR) maps 'i' to 'İ' (U+0130) and breaks the
125 // lookup of methods such as "describe" or "redirect" against the cached uppercase keys.
126 name = checkNonEmptyAfterTrim(name, "name").toUpperCase(Locale.US);
127 HttpMethod result = methodMap.get(name);
128 if (result != null) {
129 return result;
130 } else {
131 return HttpMethod.valueOf(name);
132 }
133 }
134
135 private RtspMethods() {
136 }
137 }