| 1 |
/* |
| 2 |
* SRT - Secure, Reliable, Transport |
| 3 |
* Copyright (c) 2018 Haivision Systems Inc. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
*/ |
| 10 |
|
| 11 |
#ifndef INC_SRT_URL_PARSER_H |
| 12 |
#define INC_SRT_URL_PARSER_H |
| 13 |
|
| 14 |
#include <string> |
| 15 |
#include <map> |
| 16 |
#include <cstdlib> |
| 17 |
#include "utilities.h" |
| 18 |
|
| 19 |
|
| 20 |
//++ |
| 21 |
// UriParser |
| 22 |
//-- |
| 23 |
|
| 24 |
class UriParser |
| 25 |
{ |
| 26 |
// Construction |
| 27 |
public: |
| 28 |
|
| 29 |
enum DefaultExpect { EXPECT_FILE, EXPECT_HOST }; |
| 30 |
enum Type |
| 31 |
{ |
| 32 |
UNKNOWN, FILE, UDP, TCP, SRT, RTMP, HTTP, RTP |
| 33 |
}; |
| 34 |
|
| 35 |
UriParser(const std::string& strUrl, DefaultExpect exp = EXPECT_FILE); |
| 36 |
UriParser(): m_uriType(UNKNOWN) {} |
| 37 |
virtual ~UriParser(void); |
| 38 |
|
| 39 |
// Some predefined types |
| 40 |
Type type() const; |
| 41 |
|
| 42 |
typedef MapProxy<std::string, std::string> ParamProxy; |
| 43 |
|
| 44 |
// Operations |
| 45 |
public: |
| 46 |
std::string uri() const { return m_origUri; } |
| 47 |
std::string proto() const; |
| 48 |
std::string scheme() const { return proto(); } |
| 49 |
std::string host() const; |
| 50 |
std::string port() const; |
| 51 |
unsigned short int portno() const; |
| 52 |
std::string hostport() const { return host() + ":" + port(); } |
| 53 |
std::string path() const; |
| 54 |
std::string queryValue(const std::string& strKey) const; |
| 55 |
std::string makeUri(); |
| 56 |
ParamProxy operator[](const std::string& key) { return ParamProxy(m_mapQuery, key); } |
| 57 |
const std::map<std::string, std::string>& parameters() const { return m_mapQuery; } |
| 58 |
typedef std::map<std::string, std::string>::const_iterator query_it; |
| 59 |
|
| 60 |
private: |
| 61 |
void Parse(const std::string& strUrl, DefaultExpect); |
| 62 |
|
| 63 |
// Overridables |
| 64 |
public: |
| 65 |
|
| 66 |
// Overrides |
| 67 |
public: |
| 68 |
|
| 69 |
// Data |
| 70 |
private: |
| 71 |
std::string m_origUri; |
| 72 |
std::string m_proto; |
| 73 |
std::string m_host; |
| 74 |
std::string m_port; |
| 75 |
std::string m_path; |
| 76 |
Type m_uriType; |
| 77 |
DefaultExpect m_expect; |
| 78 |
|
| 79 |
std::map<std::string, std::string> m_mapQuery; |
| 80 |
}; |
| 81 |
|
| 82 |
//#define TEST1 1 |
| 83 |
|
| 84 |
#endif // INC_SRT_URL_PARSER_H |