Changeset 625


Ignore:
Timestamp:
09/14/11 02:35:44 (8 months ago)
Author:
shiretu
Message:

-- re-implemented uri parsing from scratch
-- fixed an important bug inside amf0serializer
-- added branding to the onmetadata message

Location:
trunk/sources
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/applications/applestreamingclient/src/clientcontext.cpp

    r413 r625  
    673673        } 
    674674 
    675         if (uri.fullDocumentPath == "") { 
    676                 uri.fullDocumentPath = "/"; 
    677         } 
    678  
    679         if (uri.scheme == "https") { 
     675        if (uri.scheme() == "https") { 
    680676 
    681677                FOR_VECTOR_ITERATOR(uint64_t, protocolStackTypes, i) { 
     
    693689        Variant parameters; 
    694690        parameters["fullUri"] = uriString; 
    695         parameters["document"] = uri.fullDocumentPath; 
    696         parameters["host"] = uri.host; 
     691        parameters["document"] = uri.fullDocumentPath(); 
     692        parameters["host"] = uri.host(); 
    697693        parameters["applicationId"] = _applicationId; 
    698694        parameters["contextId"] = _id; 
     
    700696 
    701697        //4. Start the connection process 
    702         if (!TCPConnector<ClientContext>::Connect(uri.ip, uri.port, protocolStackTypes, parameters)) { 
     698        if (!TCPConnector<ClientContext>::Connect(uri.ip(), uri.port(), protocolStackTypes, parameters)) { 
    703699                FATAL("Unable to open connection to origin"); 
    704700                return false; 
  • trunk/sources/applications/proxypublish/src/proxypublishapplication.cpp

    r579 r625  
    129129                        return false; 
    130130                } 
    131                 if (uri.scheme.find("rtmp") != 0) { 
     131                if (uri.scheme().find("rtmp") != 0) { 
    132132                        FATAL("Supported target scheme is rtmp for now...."); 
    133133                        return false; 
     
    135135 
    136136 
    137                 target["targetUri"] = uri.ToVariant(); 
     137                target["targetUri"] = uri; 
    138138        } 
    139139        _targetServers = _configuration["targetServers"]; 
  • trunk/sources/applications/samplefactory/src/httpdownloadprotocol.cpp

    r473 r625  
    107107        //3. Prepare the custom parameters (the payload) 
    108108        Variant parameters; 
    109         parameters["uri"] = uri.ToVariant(); 
     109        parameters["uri"] = uri; 
    110110        parameters["payload"] = payload; 
    111111 
    112112        //4. Start the HTTP request 
    113         if (!TCPConnector<HTTPDownloadProtocol>::Connect(uri.ip, uri.port, chain, 
     113        if (!TCPConnector<HTTPDownloadProtocol>::Connect(uri.ip(), uri.port(), chain, 
    114114                        parameters)) { 
    115115                FATAL("Unable to open connection"); 
  • trunk/sources/applications/stresstest/src/rtmpappprotocolhandler.cpp

    r411 r625  
    6767 
    6868        Variant streamConfig; 
    69         streamConfig["uri"] = uri.ToVariant(); 
     69        streamConfig["uri"] = uri; 
    7070        streamConfig["localStreamName"] = generateRandomString(8); 
    7171 
  • trunk/sources/common/include/utils/misc/uri.h

    r576 r625  
    2424#include "utils/misc/variant.h" 
    2525 
    26 typedef struct _URI { 
    27         string fullUri; 
    28         string fullUriWithAuth; 
    29         string scheme; 
    30         string host; 
    31         string ip; 
    32         uint16_t port; 
    33         string userName; 
    34         string password; 
    35         string fullDocumentPath; 
    36         string documentPath; 
    37         string document; 
    38         string fullParameters; 
    39         string documentWithParameters; 
    40         map<string, string> parameters; 
     26class DLLEXP URI 
     27: public Variant { 
     28private: 
     29        static Variant _dummy; 
     30public: 
     31        VARIANT_GETSET(string, originalUri, ""); 
     32        VARIANT_GETSET(string, fullUri, ""); 
     33        VARIANT_GETSET(string, fullUriWithAuth, ""); 
     34        VARIANT_GETSET(string, scheme, ""); 
     35        VARIANT_GETSET(string, userName, ""); 
     36        VARIANT_GETSET(string, password, ""); 
     37        VARIANT_GETSET(string, host, ""); 
     38        VARIANT_GETSET(string, ip, ""); 
     39        VARIANT_GETSET(uint16_t, port, 0); 
     40        VARIANT_GETSET(bool, portSpecified, false); 
     41        VARIANT_GETSET(string, fullDocumentPathWithParameters, ""); 
     42        VARIANT_GETSET(string, fullDocumentPath, ""); 
     43        VARIANT_GETSET(string, fullParameters, ""); 
     44        VARIANT_GETSET(string, documentPath, ""); 
     45        VARIANT_GETSET(string, document, ""); 
     46        VARIANT_GETSET(string, documentWithFullParameters, ""); 
     47        VARIANT_GETSET(Variant, parameters, _dummy); 
    4148 
    42         DLLEXP void Reset(); 
    43  
    44         DLLEXP Variant ToVariant(); 
    45         DLLEXP static bool FromVariant(Variant & variant, _URI & uri); 
    46  
    47         DLLEXP string ToString(); 
    48         DLLEXP static bool FromString(string stringUri, bool resolveHost, _URI & uri); 
    49 } URI; 
     49        DLLEXP static bool FromVariant(Variant & variant, URI &uri); 
     50        DLLEXP static bool FromString(string stringUri, bool resolveHost, URI &uri); 
     51}; 
    5052 
    5153#endif  /* _URI_H */ 
  • trunk/sources/common/include/utils/misc/variant.h

    r484 r625  
    3838#define DYNAMIC_FREE(type) 
    3939#endif 
     40 
     41#define VARIANT_GET(type,name,defaultValue) \ 
     42type name() { \ 
     43        if((*this)!=V_MAP) \ 
     44                return defaultValue; \ 
     45        if(this->HasKey(#name)) \ 
     46                return (type)((*this)[#name]); \ 
     47        return defaultValue; \ 
     48}; 
     49 
     50#define VARIANT_SET(type,name) \ 
     51void name(type val) { \ 
     52    (*this)[#name]=(type)val; \ 
     53}; 
     54 
     55#define VARIANT_GETSET(type, name, defaultValue) VARIANT_GET(type,name,defaultValue);VARIANT_SET(type,name); 
    4056 
    4157typedef enum _VariantType { 
  • trunk/sources/common/src/utils/misc/uri.cpp

    r576 r625  
    2222#include "utils/logging/logging.h" 
    2323 
    24 //#define LOG_URI_SPLIT(...) FINEST(__VA_ARGS__) 
    25 #define LOG_URI_SPLIT(...) 
    26  
    27 static map<string, uint16_t> ___schemeToPort; 
     24static map<string, uint16_t> _schemeToPort; 
     25Variant URI::_dummy; 
     26 
     27#ifdef DEBUG_URI 
     28#define LOG_URI(...) FINEST(__VA_ARGS__) 
     29#else 
     30#define LOG_URI(...) 
     31#endif /* DEBUG_URI */ 
    2832 
    2933bool parseURI(string stringUri, URI &uri) { 
    30         LOG_URI_SPLIT("stringUri: %s", STR(stringUri)); 
     34        /* 
     35         * schema://[username[:password]@]host[:port][/[path[?parameters]]] 
     36         */ 
     37        LOG_URI("------------------------"); 
     38        LOG_URI("stringUri: `%s`", STR(stringUri)); 
     39        string fullUri; 
     40        string fullUriWithAuth = stringUri; 
     41        string scheme; 
     42        string authentication; 
     43        string username; 
     44        string password; 
     45        string hostPort; 
     46        string host; 
     47        string portString; 
     48        uint16_t port; 
     49        bool portSpecified; 
     50        string fullDocumentPathWithParameters; 
     51        string fullDocumentPath; 
     52        string fullParameters; 
     53        string documentPath; 
     54        string document; 
     55        string documentWithFullParameters; 
     56        Variant parameters; 
     57 
     58        string::size_type cursor = 0; 
     59        string::size_type pos = 0; 
     60 
     61        //1. Reset 
    3162        uri.Reset(); 
     63 
     64        //2. trim 
    3265        trim(stringUri); 
    33         if (stringUri == "") 
    34                 return false; 
    35  
    36         if (stringUri.size() > 1024) 
    37                 return false; 
    38  
    39         uri.fullUri = uri.fullUriWithAuth = stringUri; 
    40         LOG_URI_SPLIT("uri.fullUri: %s", STR(uri.fullUri)); 
    41  
    42  
    43         // scheme://user:pwd@host:port/document/parts/here 
    44  
    45         vector<string> components; 
    46         split(stringUri, "/", components); 
    47         for (uint32_t i = 0; i < components.size(); i++) { 
    48                 LOG_URI_SPLIT("%u: %s", i, STR(components[i])); 
    49         } 
    50  
    51         //0 - scheme: 
    52         if (components[0] == "") 
    53                 return false; 
    54  
    55         if (components[0][components[0].size() - 1] != ':') 
    56                 return false; 
    57  
    58         uri.scheme = lowerCase(components[0].substr(0, components[0].size() - 1)); 
    59         LOG_URI_SPLIT("uri.scheme: %s", STR(uri.scheme)); 
    60  
    61  
    62         //1 - nothing 
    63         if (components[1] != "") 
    64                 return false; 
    65  
    66         //2 - user:pwd@host:port 
    67         vector<string> hostComponents; 
    68         if (components[2].find("@") != string::npos) { 
    69                 split(components[2], "@", hostComponents); 
    70                 if (hostComponents.size() != 2) 
     66        if (stringUri == "") { 
     67                FATAL("Empty uri"); 
     68                return false; 
     69        } 
     70 
     71        //2. Get the scheme and the default port 
     72        pos = stringUri.find("://", cursor); 
     73        if (pos == string::npos) { 
     74                FATAL("Unable to determine scheme"); 
     75                return false; 
     76        } 
     77        scheme = lowerCase(stringUri.substr(cursor, pos - cursor)); 
     78        cursor = pos + 3; 
     79        if (_schemeToPort.size() == 0) { 
     80                _schemeToPort["http"] = 80; 
     81                _schemeToPort["rtmpt"] = 80; 
     82                _schemeToPort["rtmpte"] = 80; 
     83                _schemeToPort["https"] = 443; 
     84                _schemeToPort["rtmps"] = 443; 
     85                _schemeToPort["rtsp"] = 554; 
     86                _schemeToPort["rtmp"] = 1935; 
     87                _schemeToPort["rtmpe"] = 1935; 
     88                _schemeToPort["mms"] = 1755; 
     89        } 
     90        if (MAP_HAS1(_schemeToPort, scheme)) { 
     91                port = _schemeToPort[scheme]; 
     92        } else { 
     93                FATAL("Scheme `%s` not supported", STR(scheme)); 
     94                return false; 
     95        } 
     96        LOG_URI("scheme: %s; default port: %"PRIu16, STR(scheme), port); 
     97 
     98        //3. get the authentication portion. the search starts from 
     99        //where the scheme detection left and up to the first / character 
     100        string::size_type limit = stringUri.find("/", cursor); 
     101        bool hasAuthentication = false; 
     102        pos = stringUri.find("@", cursor); 
     103        if (pos != string::npos) { 
     104                if (limit != string::npos) { 
     105                        hasAuthentication = pos<limit; 
     106                } 
     107                hasAuthentication = true; 
     108        } 
     109        if (hasAuthentication) { 
     110                authentication = stringUri.substr(cursor, pos - cursor); 
     111                fullUri = stringUri.substr(0, cursor); 
     112                fullUri += stringUri.substr(pos + 1); 
     113                cursor = pos + 1; 
     114        } else { 
     115                fullUri = fullUriWithAuth; 
     116        } 
     117        if (authentication != "") { 
     118                pos = authentication.find(":"); 
     119                if (pos != string::npos) { 
     120                        username = authentication.substr(0, pos); 
     121                        password = authentication.substr(pos + 1); 
     122                } else { 
     123                        username = authentication; 
     124                        password = ""; 
     125                } 
     126        } 
     127        LOG_URI("fullUri: `%s`; fullUriWithAuth: `%s`", STR(fullUri), STR(fullUriWithAuth)); 
     128        LOG_URI("username: `%s`; password: `%s`", STR(username), STR(password)); 
     129 
     130        //4. Get the host:port 
     131        pos = stringUri.find("/", cursor); 
     132        if (pos == string::npos) { 
     133                hostPort = stringUri.substr(cursor); 
     134                cursor = stringUri.size() - 1; 
     135                fullDocumentPathWithParameters = "/"; 
     136        } else { 
     137                hostPort = stringUri.substr(cursor, pos - cursor); 
     138                cursor = pos + 1; 
     139                fullDocumentPathWithParameters = "/" + stringUri.substr(cursor); 
     140        } 
     141        trim(hostPort); 
     142        if (hostPort == "") { 
     143                FATAL("Invalid host:port specified"); 
     144                return false; 
     145        } 
     146        pos = hostPort.find(":"); 
     147        if (pos == string::npos) { 
     148                host = hostPort; 
     149                portSpecified = false; 
     150        } else { 
     151                host = hostPort.substr(0, pos); 
     152                trim(host); 
     153                portString = hostPort.substr(pos + 1); 
     154                portSpecified = true; 
     155                port = (uint16_t) atoi(STR(portString)); 
     156                if (format("%"PRIu16, port) != portString) { 
     157                        FATAL("Invalid port number specified: `%s`", STR(portString)); 
    71158                        return false; 
    72                 if ((hostComponents[0] == "") 
    73                                 || (hostComponents[1] == "")) { 
    74                         return false; 
    75                 } 
    76                 components[2] = hostComponents[1]; 
    77                 vector<string> userNamePasswordComponents; 
    78                 split(hostComponents[0], ":", userNamePasswordComponents); 
    79                 if (userNamePasswordComponents.size() != 2) 
    80                         return false; 
    81                 if ((userNamePasswordComponents[0] == "") 
    82                                 || (userNamePasswordComponents[1] == "")) { 
    83                         return false; 
    84                 } 
    85                 uri.userName = userNamePasswordComponents[0]; 
    86                 LOG_URI_SPLIT("uri.userName: %s", STR(uri.userName)); 
    87                 uri.password = userNamePasswordComponents[1]; 
    88                 LOG_URI_SPLIT("uri.password: %s", STR(uri.password)); 
    89                 replace(uri.fullUri, uri.userName + ":" + uri.password + "@", ""); 
    90         } 
    91  
    92         split(components[2], ":", hostComponents); 
    93         if (hostComponents.size() == 1) { 
    94                 if (hostComponents[0] == "") 
    95                         return false; 
    96                 uri.host = hostComponents[0]; 
    97                 LOG_URI_SPLIT("uri.host: %s", STR(uri.host)); 
    98         } else if (hostComponents.size() == 2) { 
    99                 if ((hostComponents[0] == "") 
    100                                 || (hostComponents[0] == "")) 
    101                         return false; 
    102                 uri.host = hostComponents[0]; 
    103                 LOG_URI_SPLIT("uri.host: %s", STR(uri.host)); 
    104                 int32_t port = atoi(STR(hostComponents[1])); 
    105                 if ((port <= 0) || (port > 65535)) 
    106                         return false; 
    107                 uri.port = (uint16_t) port; 
    108         } else { 
    109                 return false; 
    110         } 
    111  
    112         if (uri.port == 0) { 
    113                 if (___schemeToPort.size() == 0) { 
    114                         ___schemeToPort["http"] = 80; 
    115                         ___schemeToPort["rtmpt"] = 80; 
    116                         ___schemeToPort["rtmpte"] = 80; 
    117                         ___schemeToPort["https"] = 443; 
    118                         ___schemeToPort["rtmps"] = 443; 
    119                         ___schemeToPort["rtsp"] = 554; 
    120                         ___schemeToPort["rtmp"] = 1935; 
    121                         ___schemeToPort["rtmpe"] = 1935; 
    122                         ___schemeToPort["mms"] = 1755; 
    123                 } 
    124                 if (MAP_HAS1(___schemeToPort, uri.scheme)) 
    125                         uri.port = ___schemeToPort[uri.scheme]; 
    126                 else 
    127                         return false; 
    128         } 
    129         LOG_URI_SPLIT("uri.port: %u", uri.port); 
    130  
    131         for (uint32_t i = 3; i < components.size(); i++) { 
    132                 uri.fullDocumentPath += "/" + components[i]; 
    133         } 
    134         LOG_URI_SPLIT("uri.fullDocumentPath: %s", STR(uri.fullDocumentPath)); 
    135  
    136         uri.documentPath = "/"; 
    137         for (uint32_t i = 3; i < components.size() - 1; i++) { 
    138                 uri.documentPath += components[i]; 
    139                 if (i != components.size() - 2) 
    140                         uri.documentPath += "/"; 
    141         } 
    142         LOG_URI_SPLIT("uri.documentPath: %s", STR(uri.documentPath)); 
    143  
    144         if ((components.size() - 1) >= 3) { 
    145                 uri.document = components[components.size() - 1]; 
    146                 uri.documentWithParameters = uri.document; 
    147                 vector<string> documentComponents; 
    148                 split(uri.document, "?", documentComponents); 
    149                 if (documentComponents.size() == 2) { 
    150                         uri.document = documentComponents[0]; 
    151                         uri.fullParameters = documentComponents[1]; 
    152                         map<string, string> params; 
    153                         params = mapping(documentComponents[1], "&", "=", true); 
    154  
    155                         FOR_MAP(params, string, string, i) { 
    156                                 uri.parameters[MAP_KEY(i)] = MAP_VAL(i); 
    157                                 LOG_URI_SPLIT("uri.parameters[\"%s\"]: %s", 
    158                                                 STR(MAP_KEY(i)), 
    159                                                 STR(MAP_VAL(i))); 
     159                } 
     160        } 
     161        LOG_URI("host: %s; port: %"PRIu16"; portSpecified: %d", STR(host), port, portSpecified); 
     162 
     163        //5. fullDocumentPathWithParameters 
     164        fullDocumentPath = "/"; 
     165        fullParameters = ""; 
     166        documentPath = "/"; 
     167        document = ""; 
     168        documentWithFullParameters = ""; 
     169        parameters.Reset(); 
     170        parameters.IsArray(false); 
     171        if (fullDocumentPathWithParameters != "/") { 
     172                pos = fullDocumentPathWithParameters.find("?"); 
     173                if (pos == string::npos) { 
     174                        fullDocumentPath = fullDocumentPathWithParameters; 
     175                        fullParameters = ""; 
     176                } else { 
     177                        fullDocumentPath = fullDocumentPathWithParameters.substr(0, pos); 
     178                        fullParameters = fullDocumentPathWithParameters.substr(pos + 1); 
     179                } 
     180 
     181                trim(fullParameters); 
     182                if (fullParameters != "") { 
     183                        vector<string> elements; 
     184                        split(fullParameters, "&", elements); 
     185                        for (uint32_t i = 0; i < elements.size(); i++) { 
     186                                string kvp = elements[i]; 
     187                                if (kvp == "") 
     188                                        continue; 
     189                                string k = ""; 
     190                                string v = ""; 
     191                                pos = kvp.find("="); 
     192                                if (pos == string::npos) { 
     193                                        k = kvp; 
     194                                        v = ""; 
     195                                } else { 
     196                                        k = kvp.substr(0, pos); 
     197                                        v = kvp.substr(pos + 1); 
     198                                } 
     199                                if (k == "") 
     200                                        continue; 
     201                                parameters[k] = v; 
    160202                        } 
    161                 } else { 
    162                         uri.document = documentComponents[0]; 
    163                         uri.fullParameters = ""; 
    164                 } 
    165         } 
    166         LOG_URI_SPLIT("uri.document: %s", STR(uri.document)); 
     203                } 
     204 
     205                for (string::size_type i = fullDocumentPath.size() - 1; i >= 0; i--) { 
     206                        if (fullDocumentPath[i] == '/') 
     207                                break; 
     208                        document = fullDocumentPath[i] + document; 
     209                } 
     210                documentPath = fullDocumentPath.substr(0, fullDocumentPath.size() - document.size()); 
     211                documentWithFullParameters = document; 
     212                if (fullParameters != "") 
     213                        documentWithFullParameters += "?" + fullParameters; 
     214        } 
     215        LOG_URI("fullDocumentPathWithParameters: `%s`", STR(fullDocumentPathWithParameters)); 
     216        LOG_URI("fullDocumentPath: `%s`", STR(fullDocumentPath)); 
     217        LOG_URI("fullParameters: `%s`", STR(fullParameters)); 
     218        LOG_URI("documentPath: `%s`", STR(documentPath)); 
     219        LOG_URI("document: `%s`", STR(document)); 
     220        LOG_URI("documentWithFullParameters: `%s`", STR(documentWithFullParameters)); 
     221        LOG_URI("parameters:"); 
     222#ifdef DEBUG_URI 
     223 
     224        FOR_MAP(parameters, string, Variant, i) { 
     225                LOG_URI("\t`%s`: `%s`", STR(MAP_KEY(i)), STR(MAP_VAL(i))); 
     226        } 
     227#endif /* DEBUG_URI */ 
     228 
     229        uri.originalUri(stringUri); 
     230        uri.fullUri(fullUri); 
     231        uri.fullUriWithAuth(fullUriWithAuth); 
     232        uri.scheme(scheme); 
     233        uri.userName(username); 
     234        uri.password(password); 
     235        uri.host(host); 
     236        uri.port(port); 
     237        uri.portSpecified(portSpecified); 
     238        uri.fullDocumentPathWithParameters(fullDocumentPathWithParameters); 
     239        uri.fullDocumentPath(fullDocumentPath); 
     240        uri.fullParameters(fullParameters); 
     241        uri.documentPath(documentPath); 
     242        uri.document(document); 
     243        uri.documentWithFullParameters(documentWithFullParameters); 
     244        uri.parameters(parameters); 
    167245 
    168246        return true; 
    169247} 
    170248 
    171 void URI::Reset() { 
    172         fullUri = fullUriWithAuth = scheme = host = userName = password 
    173                         = fullDocumentPath = documentPath = document = fullParameters 
    174                         = documentWithParameters = ""; 
    175         port = 0; 
    176         parameters.clear(); 
    177 } 
    178  
    179 Variant URI::ToVariant() { 
    180         Variant result; 
    181         result["fullUri"] = fullUri; 
    182         result["fullUriWithAuth"] = fullUriWithAuth; 
    183         result["scheme"] = scheme; 
    184         result["host"] = host; 
    185         result["ip"] = ip; 
    186         result["port"] = (uint16_t) port; 
    187         result["userName"] = userName; 
    188         result["password"] = password; 
    189         result["fullDocumentPath"] = fullDocumentPath; 
    190         result["documentPath"] = documentPath; 
    191         result["document"] = document; 
    192         result["documentWithParameters"] = documentWithParameters; 
    193         if (fullParameters != "") { 
    194                 result["fullParameters"] = fullParameters; 
    195  
    196                 FOR_MAP(parameters, string, string, i) { 
    197                         result["parameters"][MAP_KEY(i)] = MAP_VAL(i); 
    198                 } 
    199         } 
    200  
    201         return result; 
    202 } 
    203  
    204249bool URI::FromVariant(Variant & variant, URI &uri) { 
    205250        uri.Reset(); 
    206251 
    207         if (variant != V_MAP) 
    208                 return false; 
    209  
    210         if ((!(variant.HasKeyChain(V_STRING, true, 1, "fullUri"))) 
     252        if (variant != V_MAP) { 
     253                FATAL("Variant is not a map"); 
     254                return false; 
     255        } 
     256 
     257        if ((!(variant.HasKeyChain(V_STRING, true, 1, "originalUri"))) 
     258                        || (!(variant.HasKeyChain(V_STRING, true, 1, "fullUri"))) 
    211259                        || (!(variant.HasKeyChain(V_STRING, true, 1, "fullUriWithAuth"))) 
    212260                        || (!(variant.HasKeyChain(V_STRING, true, 1, "scheme"))) 
     261                        || (!(variant.HasKeyChain(V_STRING, true, 1, "userName"))) 
     262                        || (!(variant.HasKeyChain(V_STRING, true, 1, "password"))) 
    213263                        || (!(variant.HasKeyChain(V_STRING, true, 1, "host"))) 
    214264                        || (!(variant.HasKeyChain(V_STRING, true, 1, "ip"))) 
    215                         || (!(variant.HasKeyChain(V_UINT16, true, 1, "port"))) 
    216                         || (!(variant.HasKeyChain(V_STRING, true, 1, "userName"))) 
    217                         || (!(variant.HasKeyChain(V_STRING, true, 1, "password"))) 
     265                        || (!(variant.HasKeyChain(_V_NUMERIC, true, 1, "port"))) 
     266                        || (!(variant.HasKeyChain(V_BOOL, true, 1, "portSpecified"))) 
     267                        || (!(variant.HasKeyChain(V_STRING, true, 1, "fullDocumentPathWithParameters"))) 
    218268                        || (!(variant.HasKeyChain(V_STRING, true, 1, "fullDocumentPath"))) 
     269                        || (!(variant.HasKeyChain(V_STRING, true, 1, "fullParameters"))) 
    219270                        || (!(variant.HasKeyChain(V_STRING, true, 1, "documentPath"))) 
    220271                        || (!(variant.HasKeyChain(V_STRING, true, 1, "document"))) 
    221                         || (!(variant.HasKeyChain(V_STRING, true, 1, "documentWithParameters"))) 
     272                        || (!(variant.HasKeyChain(V_STRING, true, 1, "documentWithFullParameters"))) 
     273                        || (!(variant.HasKeyChain(V_MAP, true, 1, "parameters"))) 
    222274                        ) { 
    223                 return false; 
    224         } 
    225  
    226         uri.fullUri = (string) variant["fullUri"]; 
    227         uri.fullUriWithAuth = (string) variant["fullUriWithAuth"]; 
    228         uri.scheme = (string) variant["scheme"]; 
    229         uri.host = (string) variant["host"]; 
    230         uri.ip = (string) variant["ip"]; 
    231         uri.port = (uint16_t) variant["port"]; 
    232         uri.userName = (string) variant["userName"]; 
    233         uri.password = (string) variant["password"]; 
    234         uri.fullDocumentPath = (string) variant["fullDocumentPath"]; 
    235         uri.documentPath = (string) variant["documentPath"]; 
    236         uri.document = (string) variant["document"]; 
    237         uri.documentWithParameters = (string) variant["documentWithParameters"]; 
    238  
    239         if (variant.HasKeyChain(V_STRING, true, 1, "fullParameters")) { 
    240                 if (!(variant.HasKeyChain(V_MAP, true, 1, "parameters"))) { 
    241                         uri.Reset(); 
    242                         return false; 
    243                 } 
    244                 uri.fullParameters = (string) variant["fullParameters"]; 
    245  
    246                 FOR_MAP(variant["parameters"], string, Variant, i) { 
    247                         if (((VariantType) MAP_VAL(i)) != V_STRING) { 
    248                                 uri.Reset(); 
    249                                 return false; 
    250                         } 
    251                         uri.parameters[MAP_KEY(i)] = (string) MAP_VAL(i); 
    252                 } 
    253         } else { 
    254                 uri.fullParameters = ""; 
    255                 uri.parameters.clear(); 
    256         } 
     275                FATAL("One or more type mismatch"); 
     276                return false; 
     277        } 
     278 
     279        Variant *pURI = (Variant *) & uri; 
     280        *pURI = variant; 
    257281 
    258282        return true; 
    259 } 
    260  
    261 string URI::ToString() { 
    262         return fullUriWithAuth; 
    263283} 
    264284 
     
    270290 
    271291        if (resolveHost) { 
    272                 uri.ip = getHostByName(uri.host); 
    273                 if (uri.ip == "") { 
    274                         FATAL("Unable to resolve host: %s", STR(uri.host)); 
     292                string ip = getHostByName(uri.host()); 
     293                if (ip == "") { 
     294                        FATAL("Unable to resolve host: %s", STR(uri.host())); 
    275295                        uri.Reset(); 
    276296                        return false; 
    277297                } 
     298                uri.ip(ip); 
     299        } else { 
     300                uri.ip(""); 
    278301        } 
    279302 
  • trunk/sources/thelib/include/protocols/rtmp/basertmpappprotocolhandler.h

    r608 r625  
    281281         * Send the initial connect invoke 
    282282         * */ 
    283         bool ConnectForPullPush(BaseRTMPProtocol *pFrom, string uriPath, Variant &config); 
     283        bool ConnectForPullPush(BaseRTMPProtocol *pFrom, string uriPath, 
     284                        Variant &config, bool isPull); 
    284285 
    285286        /* 
  • trunk/sources/thelib/src/application/baseappprotocolhandler.cpp

    r577 r625  
    5050bool BaseAppProtocolHandler::PullExternalStream(URI uri, Variant streamConfig) { 
    5151        WARN("Pulling in streams for scheme %s in application %s not yet implemented. Stream configuration was:\n%s", 
    52                         STR(uri.scheme), 
     52                        STR(uri.scheme()), 
    5353                        STR(GetApplication()->GetName()), 
    5454                        STR(streamConfig.ToString())); 
  • trunk/sources/thelib/src/application/baseclientapplication.cpp

    r616 r625  
    301301                return false; 
    302302        } 
    303         streamConfig["uri"] = uri.ToVariant(); 
     303        streamConfig["uri"] = uri; 
    304304 
    305305        //3. Depending on the scheme name, get the curresponding protocol handler 
    306306        ///TODO: integrate this into protocol factory manager via protocol factories 
    307         BaseAppProtocolHandler *pProtocolHandler = GetProtocolHandler(uri.scheme); 
     307        string scheme = uri.scheme(); 
     308        BaseAppProtocolHandler *pProtocolHandler = GetProtocolHandler(scheme); 
    308309        if (pProtocolHandler == NULL) { 
    309310                WARN("Unable to find protocol handler for scheme %s in application %s", 
    310                                 STR(uri.scheme), 
     311                                STR(scheme), 
    311312                                STR(GetName())); 
    312313                return false; 
     
    341342                return false; 
    342343        } 
    343         streamConfig["targetUri"] = uri.ToVariant(); 
     344        streamConfig["targetUri"] = uri; 
    344345 
    345346        //3. Depending on the scheme name, get the curresponding protocol handler 
    346347        ///TODO: integrate this into protocol factory manager via protocol factories 
    347         BaseAppProtocolHandler *pProtocolHandler = GetProtocolHandler(uri.scheme); 
     348        string scheme = uri.scheme(); 
     349        BaseAppProtocolHandler *pProtocolHandler = GetProtocolHandler(scheme); 
    348350        if (pProtocolHandler == NULL) { 
    349351                WARN("Unable to find protocol handler for scheme %s in application %s", 
    350                                 STR(uri.scheme), 
     352                                STR(scheme), 
    351353                                STR(GetName())); 
    352354                return false; 
  • trunk/sources/thelib/src/protocols/cli/http4cliprotocol.cpp

    r471 r625  
    9292        URI uri; 
    9393        string dummy = "http://localhost" + (string) headers[HTTP_FIRST_LINE][HTTP_URL]; 
    94         FINEST("dummy: %s",STR(dummy)); 
     94        //FINEST("dummy: %s", STR(dummy)); 
    9595        if (!URI::FromString(dummy, false, uri)) { 
    9696                FATAL("Invalid request"); 
    9797                return false; 
    9898        } 
    99         string fullCommand=uri.document; 
    100         fullCommand+=" "; 
    101         if(uri.parameters.size()!=0){ 
    102                 fullCommand+=unb64(MAP_VAL(uri.parameters.begin())); 
     99        string fullCommand = uri.document(); 
     100        fullCommand += " "; 
     101        if (uri.parameters().MapSize() != 0) { 
     102                fullCommand += unb64(MAP_VAL(uri.parameters().begin())); 
    103103        } 
    104         fullCommand+="\n"; 
     104        fullCommand += "\n"; 
    105105        _localInputBuffer.ReadFromString(fullCommand); 
    106106 
  • trunk/sources/thelib/src/protocols/rtmp/amf0serializer.cpp

    r427 r625  
    227227        } 
    228228 
     229        variant.IsArray(false); 
     230 
    229231        return true; 
    230232} 
  • trunk/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp

    r619 r625  
    161161                streamConfig["localStreamName"] = "stream_" + generateRandomString(8); 
    162162                WARN("No localstream name for external URI: %s. Defaulted to %s", 
    163                                 STR(uri.fullUri), 
     163                                STR(uri.fullUri()), 
    164164                                STR(streamConfig["localStreamName"])); 
    165165        } 
     
    169169        parameters["customParameters"]["externalStreamConfig"] = streamConfig; 
    170170        parameters[CONF_APPLICATION_NAME] = GetApplication()->GetName(); 
    171         if (uri.scheme == "rtmp") { 
     171        string scheme = uri.scheme(); 
     172        if (scheme == "rtmp") { 
    172173                parameters[CONF_PROTOCOL] = CONF_PROTOCOL_OUTBOUND_RTMP; 
    173         } else if (uri.scheme == "rtmpt") { 
     174        } else if (scheme == "rtmpt") { 
    174175                parameters[CONF_PROTOCOL] = CONF_PROTOCOL_OUTBOUND_RTMPT; 
    175         } else if (uri.scheme == "rtmpe") { 
     176        } else if (scheme == "rtmpe") { 
    176177                parameters[CONF_PROTOCOL] = CONF_PROTOCOL_OUTBOUND_RTMPE; 
    177178        } else { 
    178                 FATAL("scheme %s not supported by RTMP handler", STR(uri.scheme)); 
     179                FATAL("scheme %s not supported by RTMP handler", STR(scheme)); 
    179180                return false; 
    180181        } 
    181182 
    182183        //3. start the connecting sequence 
    183         return OutboundRTMPProtocol::Connect(uri.ip, uri.port, parameters); 
     184        return OutboundRTMPProtocol::Connect(uri.ip(), uri.port(), parameters); 
    184185} 
    185186 
     
    904905                                        ST_IN_NET_RTMP); 
    905906                        request["waitForLiveStream"] = (bool)true; 
    906                         request["streamName"]=streamName; 
     907                        request["streamName"] = streamName; 
    907908                        return pBaseOutNetRTMPStream != NULL; 
    908909                } 
     
    926927                                        ST_IN_NET_RTMP); 
    927928                        request["waitForLiveStream"] = (bool)true; 
    928                         request["streamName"]=streamName; 
     929                        request["streamName"] = streamName; 
    929930                        return pBaseOutNetRTMPStream != NULL; 
    930931                } 
     
    13021303 
    13031304                Variant FCSubscribeRequest = StreamMessageFactory::GetInvokeFCSubscribe( 
    1304                                 parameters["uri"]["documentWithParameters"]); 
     1305                                parameters["uri"]["documentWithFullParameters"]); 
    13051306                if (!SendRTMPMessage(pFrom, FCSubscribeRequest, true)) { 
    13061307                        FATAL("Unable to send request:\n%s", STR(FCSubscribeRequest.ToString())); 
     
    13751376        if (NeedsToPullExternalStream(pFrom)) { 
    13761377                publishPlayRequest = StreamMessageFactory::GetInvokePlay(3, rtmpStreamId, 
    1377                                 parameters["uri"]["documentWithParameters"], -2, -1); 
     1378                                parameters["uri"]["documentWithFullParameters"], -2, -1); 
    13781379        } else { 
    13791380                string targetStreamType = ""; 
     
    19521953 
    19531954        //2. Issue the connect invoke 
    1954         return ConnectForPullPush(pFrom, "uri", streamConfig); 
     1955        return ConnectForPullPush(pFrom, "uri", streamConfig, true); 
    19551956} 
    19561957 
     
    19601961 
    19611962        //2. Issue the connect invoke 
    1962         return ConnectForPullPush(pFrom, "targetUri", streamConfig); 
     1963        return ConnectForPullPush(pFrom, "targetUri", streamConfig, false); 
    19631964} 
    19641965 
    19651966bool BaseRTMPAppProtocolHandler::ConnectForPullPush(BaseRTMPProtocol *pFrom, 
    1966                 string uriPath, Variant &streamConfig) { 
     1967                string uriPath, Variant &streamConfig, bool isPull) { 
    19671968        URI uri; 
    19681969        if (!URI::FromVariant(streamConfig[uriPath], uri)) { 
     
    19721973 
    19731974        //2. get the application name 
    1974         string appName = uri.documentPath; 
    1975         if (appName == "/") 
    1976                 appName = uri.document; 
     1975        string appName = ""; 
     1976        if (isPull) { 
     1977                appName = uri.documentPath(); 
     1978        } else { 
     1979                appName = uri.fullDocumentPath(); 
     1980        } 
    19771981        if (appName != "") { 
    19781982                if (appName[0] == '/') 
    19791983                        appName = appName.substr(1, appName.size() - 1); 
     1984                if (appName != "") { 
     1985                        if (appName[appName.size() - 1] == '/') 
     1986                                appName = appName.substr(0, appName.size() - 1); 
     1987                } 
    19801988        } 
    19811989        if (appName == "") { 
    1982                 FATAL("Invalid uri: %s", STR(uri.fullUri)); 
    1983                 return false; 
    1984         } 
    1985         if (uri.userName != "") { 
     1990                FATAL("Invalid uri: %s", STR(uri.fullUri())); 
     1991                return false; 
     1992        } 
     1993        if (uri.userName() != "") { 
    19861994                if (streamConfig.HasKey("auth")) { 
    1987                         string user = uri.userName; 
    1988                         string password = uri.password; 
     1995                        string user = uri.userName(); 
     1996                        string password = uri.password(); 
    19891997                        string salt = streamConfig["auth"]["salt"]; 
    19901998                        string opaque = streamConfig["auth"]["opaque"]; 
     
    19922000                        string response = b64(md5(b64(md5(user + salt + password, false)) + opaque + challenge, false)); 
    19932001                        appName = appName + "?authmod=adobe" 
    1994                                         + "&user=" + uri.userName 
     2002                                        + "&user=" + uri.userName() 
    19952003                                        + "&challenge=" + challenge 
    19962004                                        + "&opaque=" + opaque 
     
    19992007                        streamConfig["emulateUserAgent"] = "FMLE/3.0 (compatible; FMSc/1.0)"; 
    20002008                } else { 
    2001                         appName = appName + "?authmod=adobe&user=" + uri.userName; 
     2009                        appName = appName + "?authmod=adobe&user=" + uri.userName(); 
    20022010                        streamConfig["emulateUserAgent"] = "FMLE/3.0 (compatible; FMSc/1.0)"; 
    20032011                } 
     
    20062014        //3. Compute tcUrl: rtmp://host/appName 
    20072015        string tcUrl = format("%s://%s%s/%s", 
    2008                         STR(uri.scheme), 
    2009                         STR(uri.host), 
    2010                         STR(uri.port == 1935 ? "" : format(":%hu", uri.port)), 
     2016                        STR(uri.scheme()), 
     2017                        STR(uri.host()), 
     2018                        STR(uri.portSpecified() ? format(":%"PRIu32) : ""), 
    20112019                        STR(appName)); 
    20122020 
  • trunk/sources/thelib/src/protocols/rtmp/messagefactories/streammessagefactory.cpp

    r368 r625  
    334334                Variant metadata) { 
    335335        Variant parameters; 
     336        metadata[HTTP_HEADERS_SERVER] = HTTP_HEADERS_SERVER_US; 
    336337        parameters[(uint32_t) 0] = metadata; 
    337338        return GenericMessageFactory::GetNotify(channelId, streamId, timeStamp, 
  • trunk/sources/thelib/src/protocols/rtmp/streaming/baseoutnetrtmpstream.cpp

    r609 r625  
    421421                        if (pCapabilities->videoCodecId == CODEC_VIDEO_AVC) { 
    422422                                Variant meta; 
     423                                meta.IsArray(false); 
    423424                                if ((pCapabilities->avc._widthOverride != 0) 
    424425                                                && (pCapabilities->avc._heightOverride != 0)) { 
  • trunk/sources/thelib/src/protocols/rtp/basertspappprotocolhandler.cpp

    r621 r625  
    124124        customParameters["isClient"] = (bool)true; 
    125125        customParameters["appId"] = GetApplication()->GetId(); 
    126         customParameters["uri"] = uri.ToVariant(); 
     126        customParameters["uri"] = uri; 
    127127        customParameters["connectionType"] = "pull"; 
    128128 
    129129        //3. Connect 
    130130        if (!TCPConnector<BaseRTSPAppProtocolHandler>::Connect( 
    131                         uri.ip, 
    132                         uri.port, 
     131                        uri.ip(), 
     132                        uri.port(), 
    133133                        chain, customParameters)) { 
    134134                FATAL("Unable to connect to %s:%hu", 
     
    408408                return false; 
    409409        } 
    410         if (uri.documentWithParameters == "") { 
    411                 FATAL("Inavlid stream name"); 
    412                 return false; 
    413         } 
    414         string streamName = uri.documentWithParameters; 
     410        string streamName = uri.documentWithFullParameters(); 
     411        if (streamName == "") { 
     412                FATAL("Invalid stream name"); 
     413                return false; 
     414        } 
    415415 
    416416        //2. Get the inbound stream capabilities 
  • trunk/sources/thelib/src/protocols/variant/basevariantappprotocolhandler.cpp

    r617 r625  
    195195        } 
    196196 
    197         //5. Fix the document 
    198         if (uri.fullDocumentPath == "") { 
    199                 uri.fullDocumentPath = "/"; 
    200         } 
    201  
    202197        //6. build the end result 
    203         result["username"] = uri.userName; 
    204         result["password"] = uri.password; 
    205         result["host"] = uri.host; 
    206         result["ip"] = uri.ip; 
    207         result["port"] = uri.port; 
    208         result["document"] = uri.fullDocumentPath; 
     198        result["username"] = uri.userName(); 
     199        result["password"] = uri.password(); 
     200        result["host"] = uri.host(); 
     201        result["ip"] = uri.ip(); 
     202        result["port"] = uri.port(); 
     203        result["document"] = uri.fullDocumentPath(); 
    209204        result["applicationName"] = GetApplication()->GetName(); 
    210205 
Note: See TracChangeset for help on using the changeset viewer.