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 * 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, 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 io.netty.buffer.ByteBuf;
19 import io.netty.handler.codec.TooLongFrameException;
20 import io.netty.handler.codec.http.HttpMessage;
21 import io.netty.handler.codec.http.HttpObjectDecoder;
22
23 /**
24 * Decodes {@link ByteBuf}s into RTSP messages represented in
25 * {@link HttpMessage}s.
26 * <p>
27 * <h3>Parameters that prevents excessive memory consumption</h3>
28 * <table border="1">
29 * <tr>
30 * <th>Name</th><th>Meaning</th>
31 * </tr>
32 * <tr>
33 * <td>{@code maxInitialLineLength}</td>
34 * <td>The maximum length of the initial line
35 * (e.g. {@code "SETUP / RTSP/1.0"} or {@code "RTSP/1.0 200 OK"})
36 * If the length of the initial line exceeds this value, a
37 * {@link TooLongFrameException} will be raised.</td>
38 * </tr>
39 * <tr>
40 * <td>{@code maxHeaderSize}</td>
41 * <td>The maximum length of all headers. If the sum of the length of each
42 * header exceeds this value, a {@link TooLongFrameException} will be raised.</td>
43 * </tr>
44 * <tr>
45 * <td>{@code maxContentLength}</td>
46 * <td>The maximum length of the content. If the content length exceeds this
47 * value, a {@link TooLongFrameException} will be raised.</td>
48 * </tr>
49 * </table>
50 *
51 * @deprecated Use {@link RtspDecoder} instead.
52 */
53 @Deprecated
54 public abstract class RtspObjectDecoder extends HttpObjectDecoder {
55
56 /**
57 * Creates a new instance with the default
58 * {@code maxInitialLineLength (4096)}, {@code maxHeaderSize (8192)}, and
59 * {@code maxContentLength (8192)}.
60 */
61 protected RtspObjectDecoder() {
62 this(4096, 8192, 8192);
63 }
64
65 /**
66 * Creates a new instance with the specified parameters.
67 */
68 protected RtspObjectDecoder(int maxInitialLineLength, int maxHeaderSize, int maxContentLength) {
69 super(maxInitialLineLength, maxHeaderSize, maxContentLength * 2, false);
70 }
71
72 protected RtspObjectDecoder(
73 int maxInitialLineLength, int maxHeaderSize, int maxContentLength, boolean validateHeaders) {
74 super(maxInitialLineLength, maxHeaderSize, maxContentLength * 2, false, validateHeaders);
75 }
76
77 @Override
78 protected boolean isContentAlwaysEmpty(HttpMessage msg) {
79 // Unlike HTTP, RTSP always assumes zero-length body if Content-Length
80 // header is absent.
81 boolean empty = super.isContentAlwaysEmpty(msg);
82 if (empty) {
83 return true;
84 }
85 if (!msg.headers().contains(RtspHeaders.Names.CONTENT_LENGTH)) {
86 return true;
87 }
88 return empty;
89 }
90 }