RtspUtil.cxx
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:11k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

C/C++

  1. /* ====================================================================
  2.  * The Vovida Software License, Version 1.0 
  3.  * 
  4.  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
  5.  * 
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  * 
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in
  15.  *    the documentation and/or other materials provided with the
  16.  *    distribution.
  17.  * 
  18.  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
  19.  *    and "Vovida Open Communication Application Library (VOCAL)" must
  20.  *    not be used to endorse or promote products derived from this
  21.  *    software without prior written permission. For written
  22.  *    permission, please contact vocal@vovida.org.
  23.  *
  24.  * 4. Products derived from this software may not be called "VOCAL", nor
  25.  *    may "VOCAL" appear in their name, without prior written
  26.  *    permission of Vovida Networks, Inc.
  27.  * 
  28.  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
  29.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
  31.  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
  32.  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
  33.  * IN EXCESS OF 281421,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
  34.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  36.  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  37.  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  39.  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  40.  * DAMAGE.
  41.  * 
  42.  * ====================================================================
  43.  * 
  44.  * This software consists of voluntary contributions made by Vovida
  45.  * Networks, Inc. and many individuals on behalf of Vovida Networks,
  46.  * Inc.  For more information on Vovida Networks, Inc., please see
  47.  * <http://www.vovida.org/>.
  48.  *
  49.  */
  50. static const char* const RtspUtil_cxx_Version =
  51.     "$Id: RtspUtil.cxx,v 1.9 2001/05/15 20:26:12 bko Exp $";
  52. #include "CharData.hxx"
  53. #include "RtspUtil.hxx"
  54. CharData RtspUtil::myMethods[] =
  55. {
  56.     CharData(""),
  57.     CharData("ANNOUNCE"),
  58.     CharData("DESCRIBE"),
  59.     CharData("PLAY"),
  60.     CharData("RECORD"),
  61.     CharData("SETUP"),
  62.     CharData("TEARDOWN"),
  63.     CharData("PAUSE"),
  64.     CharData("GET_PARAMETER"),
  65.     CharData("OPTIONS"),
  66.     CharData("REDIRECT"),
  67.     CharData("SET_PARAMETER"),
  68.     CharData("")
  69. };
  70. CharData RtspUtil::myHeaders[] =
  71. {
  72.     CharData("Accept"),
  73.     CharData("Cseq"),
  74.     CharData("Range"),
  75.     CharData("Session"),
  76.     CharData("Transport"),
  77.     CharData("Blocksize"),
  78.     CharData("Content-Base"),
  79.     CharData("Content-length"),
  80.     CharData("Content-Type"),
  81.     CharData("Accept-Encoding"),
  82.     CharData("Accept-Language"),
  83.     CharData("Allow"),
  84.     CharData("Authorization"),
  85.     CharData("Bandwidth"),
  86.     CharData("Cache-Control"),
  87.     CharData("Conference"),
  88.     CharData("Connection"),
  89.     CharData("Content-Encoding"),
  90.     CharData("Content-Language"),
  91.     CharData("Content-Location"),
  92.     CharData("Date"),
  93.     CharData("Expires"),
  94.     CharData("From"),
  95.     CharData("Host"),
  96.     CharData("If-Match"),
  97.     CharData("If-Modified-Since"),
  98.     CharData("Last-Modified"),
  99.     CharData("Location"),
  100.     CharData("Proxy-Authenticate"),
  101.     CharData("Proxy-Require"),
  102.     CharData("Public"),
  103.     CharData("Referer"),
  104.     CharData("Retry-After"),
  105.     CharData("Require"),
  106.     CharData("RTP-Info"),
  107.     CharData("Scale"),
  108.     CharData("Server"),
  109.     CharData("Speed"),
  110.     CharData("Timestamp"),
  111.     CharData("Unsupported"),
  112.     CharData("User-Agent"),
  113.     CharData("Vary"),
  114.     CharData("Via"),
  115.     CharData("WWW-Authenticate"),
  116.     CharData("")
  117. };
  118. u_int32_t RtspUtil::myStatusCodes[] =
  119. {
  120.     0,
  121.     100, //Continue
  122.     200, //OK
  123.     201, //Created
  124.     250, //Low on Storage Space
  125.     300, //Multiple Choices
  126.     301, //Moved Permanently
  127.     302, //Moved Temporarily
  128.     303, //See Other
  129.     305, //Use Proxy
  130.     400, //Bad Request
  131.     401, //Unauthorized
  132.     402, //Payment Required
  133.     403, //Forbidden
  134.     404, //Not Found
  135.     405, //Method Not Allowed
  136.     406, //Not Acceptable
  137.     407, //Proxy Authentication Required
  138.     408, //Request Time-out
  139.     410, //Gone
  140.     411, //Length Required
  141.     412, //Precondition Failed
  142.     413, //Request Entity Too Large
  143.     414, //Request-URI Too Large
  144.     415, //Unsupported Media Type
  145.     451, //Parameter Not Understood
  146.     452, //Conference Not Found
  147.     453, //Not Enough Bandwidth
  148.     454, //Session Not Found
  149.     455, //Method Not Valid in this State
  150.     456, //Header Field Not Valid For Resource
  151.     457, //Invalid Range
  152.     458, //Parameter Is Read-Only
  153.     459, //Aggregate Option Not Allowed
  154.     460, //Only Aggregate Option Allowed
  155.     461, //Unsupported Transport
  156.     462, //Destination Unreachable
  157.     500, //Internal Server Error
  158.     501, //Not Implemented
  159.     502, //Bad Gateway
  160.     503, //Service Unavailable
  161.     504, //Gateway Timeout
  162.     505, //RTSP Version not supported
  163.     551, //Option Not Supported
  164.     0
  165. };
  166. CharData RtspUtil::myStatusCodeStrings[] =
  167. {
  168.     CharData(""),
  169.     CharData("100"), //Continue
  170.     CharData("200"), //OK
  171.     CharData("201"), //Created
  172.     CharData("250"), //Low on Storage Space
  173.     CharData("300"), //Multiple Choices
  174.     CharData("301"), //Moved Permanently
  175.     CharData("302"), //Moved Temporarily
  176.     CharData("303"), //See Other
  177.     CharData("305"), //Use Proxy
  178.     CharData("400"), //Bad Request
  179.     CharData("401"), //Unauthorized
  180.     CharData("402"), //Payment Required
  181.     CharData("403"), //Forbidden
  182.     CharData("404"), //Not Found
  183.     CharData("405"), //Method Not Allowed
  184.     CharData("406"), //Not Acceptable
  185.     CharData("407"), //Proxy Authentication Required
  186.     CharData("408"), //Request Time-out
  187.     CharData("410"), //Gone
  188.     CharData("411"), //Length Required
  189.     CharData("412"), //Precondition Failed
  190.     CharData("413"), //Request Entity Too Large
  191.     CharData("414"), //Request-URI Too Large
  192.     CharData("415"), //Unsupported Media Type
  193.     CharData("451"), //Parameter Not Understood
  194.     CharData("452"), //Conference Not Found
  195.     CharData("453"), //Not Enough Bandwidth
  196.     CharData("454"), //Session Not Found
  197.     CharData("455"), //Method Not Valid in this State
  198.     CharData("456"), //Header Field Not Valid For Resource
  199.     CharData("457"), //Invalid Range
  200.     CharData("458"), //Parameter Is Read-Only
  201.     CharData("459"), //Aggregate Option Not Allowed
  202.     CharData("460"), //Only Aggregate Option Allowed
  203.     CharData("461"), //Unsupported Transport
  204.     CharData("462"), //Destination Unreachable
  205.     CharData("500"), //Internal Server Error
  206.     CharData("501"), //Not Implemented
  207.     CharData("502"), //Bad Gateway
  208.     CharData("503"), //Service Unavailable
  209.     CharData("504"), //Gateway Timeout
  210.     CharData("505"), //RTSP Version not supported
  211.     CharData("551"), //Option Not Supported
  212.     CharData("0")
  213. };
  214. CharData RtspUtil::myStatusStrings[] =
  215. {
  216.     CharData(""),
  217.     CharData("Continue"),                                          //100
  218.     CharData("OK"),                                                //200
  219.     CharData("Created"),                                           //201
  220.     CharData("Low on Storage Space"),                              //250
  221.     CharData("Multiple Choices"),                                  //300
  222.     CharData("Moved Permanently"),                                 //301
  223.     CharData("Moved Temporarily"),                                 //302
  224.     CharData("See Other"),                                         //303
  225.     CharData("Use Proxy"),                                         //305
  226.     CharData("Bad Request"),                                       //400
  227.     CharData("Unauthorized"),                                      //401
  228.     CharData("Payment Required"),                                  //402
  229.     CharData("Forbidden"),                                         //403
  230.     CharData("Not Found"),                                         //404
  231.     CharData("Method Not Allowed"),                                //405
  232.     CharData("Not Acceptable"),                                    //406
  233.     CharData("Proxy Authentication Required"),                     //407
  234.     CharData("Request Time-out"),                                  //408
  235.     CharData("Gone"),                                              //410
  236.     CharData("Length Required"),                                   //411
  237.     CharData("Precondition Failed"),                               //412
  238.     CharData("Request Entity Too Large"),                          //413
  239.     CharData("Request-URI Too Large"),                             //414
  240.     CharData("Unsupported Media Type"),                            //415
  241.     CharData("Parameter Not Understood"),                          //451
  242.     CharData("Conference Not Found"),                              //452
  243.     CharData("Not Enough Bandwidth"),                              //453
  244.     CharData("Session Not Found"),                                 //454
  245.     CharData("Method Not Valid in this State"),                    //455
  246.     CharData("Header Field Not Valid For Resource"),               //456
  247.     CharData("Invalid Range"),                                     //457
  248.     CharData("Parameter Is Read-Only"),                            //458
  249.     CharData("Aggregate Option Not Allowed"),                      //459
  250.     CharData("Only Aggregate Option Allowed"),                     //460
  251.     CharData("Unsupported Transport"),                             //461
  252.     CharData("Destination Unreachable"),                           //462
  253.     CharData("Internal Server Error"),                             //500
  254.     CharData("Not Implemented"),                                   //501
  255.     CharData("Bad Gateway"),                                       //502
  256.     CharData("Service Unavailable"),                               //503
  257.     CharData("Gateway Timeout"),                                   //504
  258.     CharData("RTSP Version not supported"),                        //505
  259.     CharData("Option Not Supported"),                              //551
  260.     CharData("")
  261. };
  262. CharData RtspUtil::myVersion[] =
  263. {
  264.     CharData("RTSP/1.0")
  265. };
  266.     
  267. u_int32_t
  268. RtspUtil::getHeaderInNumber(const CharData& hdrData)
  269. {
  270.     if (hdrData.getLen() == 0)
  271.         return RTSP_UNKNOWN_HDR;
  272.     for (int i = 0; i < RTSP_UNKNOWN_HDR; i++)
  273.     {
  274.         if (hdrData.isEqualNoCase(myHeaders[i].getPtr(),
  275.                                   myHeaders[i].getLen()))
  276.             return i;
  277.     }
  278.     return RTSP_UNKNOWN_HDR; 
  279. }
  280. u_int32_t
  281. RtspUtil::getMethodInNumber(const CharData& methodData)
  282. {
  283.     if (methodData.getLen() == 0)
  284.         return RTSP_UNKNOWN_HDR;
  285.     for (int i = 0; i < RTSP_UNKNOWN_MTHD; i++)
  286.     {
  287.         if (methodData.isEqualNoCase(myMethods[i].getPtr(),
  288.                                      myMethods[i].getLen()))
  289.             return i;
  290.     }
  291.     return RTSP_UNKNOWN_MTHD; 
  292. }
  293. /* Local Variables: */
  294. /* c-file-style: "stroustrup" */
  295. /* indent-tabs-mode: nil */
  296. /* c-file-offsets: ((access-label . -) (inclass . ++)) */
  297. /* c-basic-offset: 4 */
  298. /* End: */