001: /*
002: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License version
007: * 2 only, as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful, but
010: * WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * General Public License version 2 for more details (a copy is
013: * included at /legal/license.txt).
014: *
015: * You should have received a copy of the GNU General Public License
016: * version 2 along with this work; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018: * 02110-1301 USA
019: *
020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021: * Clara, CA 95054 or visit www.sun.com if you need additional
022: * information or have any questions.
023: */
024: package com.sun.mmedia.rtsp.protocol;
025:
026: import java.io.*;
027: import java.util.*;
028:
029: public class Header extends Parser {
030: public int type; // the header type
031: public Object parameter; // parameter entries
032: public int contentLength;
033:
034: public final static int TRANSPORT = 1;
035: public final static int CSEQ = 2;
036: public final static int SESSION = 3;
037: public final static int DURATION = 4;
038: public final static int RANGE = 5;
039: public final static int DATE = 6;
040: public final static int SERVER = 7;
041: public final static int CONTENT_TYPE = 8;
042: public final static int CONTENT_BASE = 9;
043: public final static int CONTENT_LENGTH = 10;
044:
045: public Header(String input) {
046: ByteArrayInputStream bin = new ByteArrayInputStream(input
047: .getBytes());
048:
049: String id = getToken(bin).toUpperCase();
050:
051: // changed equalsIgnoreCase to toUpperCase
052:
053: if (id.equals("CSEQ:")) {
054: type = CSEQ;
055:
056: String number = getStringToken(bin).trim();
057:
058: parameter = new CSeqHeader(number);
059: } else if (id.equals("TRANSPORT:")) {
060: type = TRANSPORT;
061:
062: String tx = getToken(bin);
063:
064: parameter = new TransportHeader(tx);
065: } else if (id.equals("SESSION:")) {
066: type = SESSION;
067:
068: String tx = getToken(bin);
069:
070: parameter = new SessionHeader(tx);
071: } else if (id.equals("DURATION:")) {
072: type = DURATION;
073:
074: String tx = getToken(bin);
075:
076: System.out.println("Duration : " + tx);
077:
078: parameter = new DurationHeader(tx);
079: } else if (id.equals("RANGE:")) {
080: type = RANGE;
081:
082: String tx = getToken(bin);
083:
084: parameter = new RangeHeader(tx);
085: } else if (id.equals("DATE:")) {
086: type = DATE;
087:
088: String date = getStringToken(bin);
089:
090: // Debug.println( "Date : " + date);
091: } else if (id.equals("ALLOW:")) {
092: type = DATE;
093:
094: String entries = getStringToken(bin);
095:
096: // Debug.println( "Allow : " + entries);
097: } else if (id.equals("SERVER:")) {
098: type = SERVER;
099:
100: String server = getStringToken(bin);
101:
102: // Debug.println ( "Server : " + server);
103: } else if (id.equals("CONTENT-TYPE:")) {
104: type = CONTENT_TYPE;
105:
106: String content_type = getStringToken(bin);
107:
108: // Debug.println( "Content-Type : " + content_type);
109: } else if (id.equals("CONTENT-BASE:")) {
110: type = CONTENT_BASE;
111: String content_base = getStringToken(bin);
112:
113: parameter = new ContentBaseHeader(content_base);
114: } else if (id.equals("CONTENT-LENGTH:")) {
115: type = CONTENT_LENGTH;
116:
117: String content_length = getStringToken(bin);
118:
119: // System.out.println( "Content-Length : " + content_length);
120:
121: contentLength = Integer.parseInt(content_length);
122: } else if (id.equals("LAST-MODIFIED:")) {
123: String date = getStringToken(bin);
124:
125: // Debug.println( "Last-Modified: " + date);
126: } else if (id.equals("RTP-INFO:")) {
127: String rtpInfo = getStringToken(bin);
128:
129: // Debug.println( "RTP-Info: " + rtpInfo);
130: } else if (id.length() > 0) {
131: System.out.println("unknown id : <" + id + ">");
132:
133: String tmp = getStringToken(bin);
134: }
135: }
136: }
|