1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_SHARING_RTSP_DEF_H 17 #define OHOS_SHARING_RTSP_DEF_H 18 19 #include <list> 20 #include <string> 21 #include <unordered_map> 22 #include <vector> 23 24 namespace OHOS { 25 namespace Sharing { 26 27 // RTSP methods 28 #define RTSP_METHOD_OPTIONS "OPTIONS" 29 #define RTSP_METHOD_DESCRIBE "DESCRIBE" 30 #define RTSP_METHOD_ANNOUNCE "ANNOUNCE" 31 #define RTSP_METHOD_SETUP "SETUP" 32 #define RTSP_METHOD_PLAY "PLAY" 33 #define RTSP_METHOD_PAUSE "PAUSE" 34 #define RTSP_METHOD_TEARDOWN "TEARDOWN" 35 #define RTSP_METHOD_GET_PARAMETER "GET_PARAMETER" 36 #define RTSP_METHOD_SET_PARAMETER "SET_PARAMETER" 37 #define RTSP_METHOD_REDIRECT "REDIRECT" 38 #define RTSP_METHOD_RECORD "RECORD" 39 40 // RTSP version 41 #define RTSP_VERSION "RTSP/1.0" 42 #define RTSP_CRLF "\r\n" 43 #define RTSP_SP " " 44 45 // RTSP token 46 #define RTSP_TOKEN_CSEQ "CSeq" 47 #define RTSP_TOKEN_DATE "Date" 48 #define RTSP_TOKEN_PUBLIC "Public" 49 #define RTSP_TOKEN_CONTENT_BASE "Content-Base" 50 #define RTSP_TOKEN_CONTENT_TYPE "Content-Type" 51 #define RTSP_TOKEN_CONTENT_LENGTH "Content-Length" 52 #define RTSP_TOKEN_TRANSPORT "Transport" 53 #define RTSP_TOKEN_SESSION "Session" 54 #define RTSP_TOKEN_UA "User-Agent" 55 #define RTSP_TOKEN_ACCEPT "Accept" 56 #define RTSP_TOKEN_RANGE "Range" 57 #define RTSP_TOKEN_REQUIRE "Require" 58 #define RTSP_TOKEN_AUTHORIZATION "Authorization" 59 #define RTSP_TOKEN_WWW_AUTHENTICATE "WWW-Authenticate" 60 61 #define RTSP_STATUS_CONTINUE 100 62 #define RTSP_STATUS_OK 200 63 #define RTSP_STATUS_BAD_REQUEST 400 64 #define RTSP_STATUS_UNAUTHORIZED 401 65 #define RTSP_STATUS_STREAM_NOT_FOUND 404 66 67 #define RTSP_STATUS_CONTINUE_STR "Continue" 68 #define RTSP_STATUS_OK_STR "OK" 69 #define RTSP_STATUS_BAD_REQUEST_STR "Bad Request" 70 #define RTSP_STATUS_UNAUTHORIZED_STR "Unauthorized" 71 #define RTSP_STATUS_STREAM_NOT_FOUND_STR "Stream Not Found" 72 73 #define RTSP_STATUS_TO_STR(status) status##_STR 74 75 enum class RtspErrorType { OK = 0, INVALID_MESSAGE = 0x1000, INVALID_METHOD, INCOMPLETE_MESSAGE }; 76 77 struct RtspError { 78 RtspErrorType code = RtspErrorType::OK; 79 80 std::string info = "ok"; 81 }; 82 83 class RtspCommon { 84 public: 85 static std::string GetRtspDate(); 86 static std::string Trim(const std::string &str); 87 88 static bool VerifyMethod(const std::string &method); 89 static std::vector<std::string> Split(const std::string &str, const std::string &delimiter); 90 91 static void SplitParameter(std::list<std::string> &lines, std::list<std::pair<std::string, std::string>> ¶ms); 92 93 static RtspError ParseMessage(const std::string &message, std::vector<std::string> &firstLine, 94 std::unordered_map<std::string, std::string> &header, std::list<std::string> &body); 95 96 static std::string GenerateAuthorization(const std::string &username, const std::string &realm, 97 const std::string &password, const std::string &nonce, 98 const std::string &method, const std::string &url); 99 }; 100 } // namespace Sharing 101 } // namespace OHOS 102 #endif // OHOS_SHARING_RTSP_DEF_H 103