当前位置: 首页>>代码示例>>C++>>正文


C++ URI::Reset方法代码示例

本文整理汇总了C++中URI::Reset方法的典型用法代码示例。如果您正苦于以下问题:C++ URI::Reset方法的具体用法?C++ URI::Reset怎么用?C++ URI::Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在URI的用法示例。


在下文中一共展示了URI::Reset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_ParseURL

void CommonTestsSuite::test_ParseURL() {
	URI uri;

	uri.Reset();
	uri.port = 9999;
	TS_ASSERT(URI::FromString("", false, uri) == false);
	TS_ASSERT(uri.host == "");
	TS_ASSERT(uri.port == 0);
	TS_ASSERT(uri.userName == "");
	TS_ASSERT(uri.password == "");
	TS_ASSERT(uri.fullDocumentPath == "");

	uri.Reset();
	uri.port = 9999;
	TS_ASSERT(URI::FromString("sjdhfkjsdhfjksdh", false, uri) == false);
	TS_ASSERT(uri.host == "");
	TS_ASSERT(uri.port == 0);
	TS_ASSERT(uri.userName == "");
	TS_ASSERT(uri.password == "");
	TS_ASSERT(uri.fullDocumentPath == "");

	uri.Reset();
	uri.port = 9999;
	TS_ASSERT(URI::FromString("http:/gigi/stiintza", false, uri) == false);
	TS_ASSERT(uri.host == "");
	TS_ASSERT(uri.port == 0);
	TS_ASSERT(uri.userName == "");
	TS_ASSERT(uri.password == "");
	TS_ASSERT(uri.fullDocumentPath == "");

	uri.Reset();
	uri.port = 9999;
	TS_ASSERT(URI::FromString("htt://gigi/stiintza", false, uri) == false);
	TS_ASSERT(uri.host == "");
	TS_ASSERT(uri.port == 0);
	TS_ASSERT(uri.userName == "");
	TS_ASSERT(uri.password == "");
	TS_ASSERT(uri.fullDocumentPath == "");

	uri.Reset();
	uri.port = 9999;
	TS_ASSERT(URI::FromString("http://:gigi/stiintza", false, uri) == false);
	TS_ASSERT(uri.host == "");
	TS_ASSERT(uri.port == 0);
	TS_ASSERT(uri.userName == "");
	TS_ASSERT(uri.password == "");
	TS_ASSERT(uri.fullDocumentPath == "");

	uri.Reset();
	uri.port = 9999;
	TS_ASSERT(URI::FromString("http://gigi:gfgf/stiintza", false, uri) == false);
	TS_ASSERT(uri.host == "");
	TS_ASSERT(uri.port == 0);
	TS_ASSERT(uri.userName == "");
	TS_ASSERT(uri.password == "");
	TS_ASSERT(uri.fullDocumentPath == "");

	uri.Reset();
	uri.port = 9999;
	TS_ASSERT(URI::FromString("http://gigi:123456/stiintza", false, uri) == false);
	TS_ASSERT(uri.host == "");
	TS_ASSERT(uri.port == 0);
	TS_ASSERT(uri.userName == "");
	TS_ASSERT(uri.password == "");
	TS_ASSERT(uri.fullDocumentPath == "");


	uri.Reset();
	uri.port = 9999;
	TS_ASSERT(URI::FromString("http://:@gigi/stiintza", false, uri) == false);
	TS_ASSERT(uri.host == "");
	TS_ASSERT(uri.port == 0);
	TS_ASSERT(uri.userName == "");
	TS_ASSERT(uri.password == "");
	TS_ASSERT(uri.fullDocumentPath == "");

	uri.Reset();
	uri.port = 9999;
	TS_ASSERT(URI::FromString("http://aaa:[email protected]/stiintza", false, uri) == true);
	TS_ASSERT(uri.host == "gigi");
	TS_ASSERT(uri.port == 80);
	TS_ASSERT(uri.userName == "aaa");
	TS_ASSERT(uri.password == "ddd");
	TS_ASSERT(uri.fullDocumentPath == "/stiintza");

	uri.Reset();
	uri.port = 9999;
	TS_ASSERT(URI::FromString("http://gigi/stiintza", false, uri) == true);
	TS_ASSERT(uri.host == "gigi");
	TS_ASSERT(uri.port == 80);
	TS_ASSERT(uri.userName == "");
	TS_ASSERT(uri.password == "");
	TS_ASSERT(uri.fullDocumentPath == "/stiintza");

	uri.Reset();
	uri.port = 9999;
	TS_ASSERT(URI::FromString("http://@gigi/stiintza", false, uri) == false);
	TS_ASSERT(uri.host == "");
	TS_ASSERT(uri.port == 0);
	TS_ASSERT(uri.userName == "");
//.........这里部分代码省略.........
开发者ID:a4tunado,项目名称:crtmpserver,代码行数:101,代码来源:commontestssuite.cpp

示例2: parseURI

bool parseURI(string stringUri, URI &uri) {
	/*
	 * schema://[username[:password]@]host[:port][/[path[?parameters]]]
	 */
	LOG_URI("------------------------");
	LOG_URI("stringUri: `%s`", STR(stringUri));
	string fullUri;
	string fullUriWithAuth = stringUri;
	string scheme;
	string authentication;
	string username;
	string password;
	string hostPort;
	string host;
	string portString;
	uint16_t port;
	bool portSpecified;
	string fullDocumentPathWithParameters;
	string fullDocumentPath;
	string fullParameters;
	string documentPath;
	string document;
	string documentWithFullParameters;
	Variant parameters;

	string::size_type cursor = 0;
	string::size_type pos = 0;

	//1. Reset
	uri.Reset();

	//2. trim
	trim(stringUri);
	if (stringUri == "") {
		FATAL("Empty uri");
		return false;
	}

	//2. Get the scheme and the default port
	pos = stringUri.find("://", cursor);
	if (pos == string::npos) {
		FATAL("Unable to determine scheme");
		return false;
	}
	scheme = lowerCase(stringUri.substr(cursor, pos - cursor));
	cursor = pos + 3;
	if (_schemeToPort.size() == 0) {
		_schemeToPort["http"] = 80;
		_schemeToPort["rtmpt"] = 80;
		_schemeToPort["rtmpte"] = 80;
		_schemeToPort["https"] = 443;
		_schemeToPort["rtmps"] = 443;
		_schemeToPort["rtsp"] = 554;
		_schemeToPort["rtmp"] = 1935;
		_schemeToPort["rtmpe"] = 1935;
		_schemeToPort["mms"] = 1755;
	}
	if (MAP_HAS1(_schemeToPort, scheme)) {
		port = _schemeToPort[scheme];
	}
	//	else {
	//		FATAL("Scheme `%s` not supported", STR(scheme));
	//		return false;
	//	}
	LOG_URI("scheme: %s; default port: %"PRIu16, STR(scheme), port);

	//3. get the authentication portion. the search starts from
	//where the scheme detection left and up to the first / character
	string::size_type limit = stringUri.find("/", cursor);
	bool hasAuthentication = false;
	pos = stringUri.find("@", cursor);
	if (pos != string::npos) {
		if (limit != string::npos) {
			hasAuthentication = pos<limit;
		}
		hasAuthentication = true;
	}
	if (hasAuthentication) {
		authentication = stringUri.substr(cursor, pos - cursor);
		fullUri = stringUri.substr(0, cursor);
		fullUri += stringUri.substr(pos + 1);
		cursor = pos + 1;
	} else {
		fullUri = fullUriWithAuth;
	}
	if (authentication != "") {
		pos = authentication.find(":");
		if (pos != string::npos) {
			username = authentication.substr(0, pos);
			password = authentication.substr(pos + 1);
		} else {
			username = authentication;
			password = "";
		}
	}
	LOG_URI("fullUri: `%s`; fullUriWithAuth: `%s`", STR(fullUri), STR(fullUriWithAuth));
	LOG_URI("username: `%s`; password: `%s`", STR(username), STR(password));

	//4. Get the host:port
	pos = stringUri.find("/", cursor);
//.........这里部分代码省略.........
开发者ID:dista,项目名称:crtmpserver,代码行数:101,代码来源:uri.cpp

示例3: parseURI

bool parseURI(string stringUri, URI &uri) {
	LOG_URI_SPLIT("stringUri: %s", STR(stringUri));
	uri.Reset();
	trim(stringUri);
	if (stringUri == "")
		return false;

	if (stringUri.size() > 1024)
		return false;

	uri.fullUri = stringUri;
	LOG_URI_SPLIT("uri.fullUri: %s", STR(uri.fullUri));


	// scheme://user:[email protected]:port/document/parts/here

	vector<string> components;
	split(stringUri, "/", components);
	for (uint32_t i = 0; i < components.size(); i++) {
		LOG_URI_SPLIT("%u: %s", i, STR(components[i]));
	}

	//0 - scheme:
	if (components[0] == "")
		return false;

	if (components[0][components[0].size() - 1] != ':')
		return false;

	uri.scheme = lowerCase(components[0].substr(0, components[0].size() - 1));
	LOG_URI_SPLIT("uri.scheme: %s", STR(uri.scheme));


	//1 - nothing
	if (components[1] != "")
		return false;

	//2 - user:[email protected]:port
	vector<string> hostComponents;
	if (components[2].find("@") != string::npos) {
		split(components[2], "@", hostComponents);
		if (hostComponents.size() != 2)
			return false;
		if ((hostComponents[0] == "")
				|| (hostComponents[1] == "")) {
			return false;
		}
		components[2] = hostComponents[1];
		vector<string> userNamePasswordComponents;
		split(hostComponents[0], ":", userNamePasswordComponents);
		if (userNamePasswordComponents.size() != 2)
			return false;
		if ((userNamePasswordComponents[0] == "")
				|| (userNamePasswordComponents[1] == "")) {
			return false;
		}
		uri.userName = userNamePasswordComponents[0];
		LOG_URI_SPLIT("uri.userName: %s", STR(uri.userName));
		uri.password = userNamePasswordComponents[1];
		LOG_URI_SPLIT("uri.password: %s", STR(uri.password));
	}

	split(components[2], ":", hostComponents);
	if (hostComponents.size() == 1) {
		if (hostComponents[0] == "")
			return false;
		uri.host = hostComponents[0];
		LOG_URI_SPLIT("uri.host: %s", STR(uri.host));
	} else if (hostComponents.size() == 2) {
		if ((hostComponents[0] == "")
				|| (hostComponents[0] == ""))
			return false;
		uri.host = hostComponents[0];
		LOG_URI_SPLIT("uri.host: %s", STR(uri.host));
		int32_t port = atoi(STR(hostComponents[1]));
		if ((port <= 0) || (port > 65535))
			return false;
		uri.port = (uint16_t) port;
	} else {
		return false;
	}

	if (uri.port == 0) {
		if (___schemeToPort.size() == 0) {
			___schemeToPort["http"] = 80;
			___schemeToPort["rtmpt"] = 80;
			___schemeToPort["rtmpte"] = 80;
			___schemeToPort["https"] = 443;
			___schemeToPort["rtmps"] = 443;
			___schemeToPort["rtsp"] = 554;
			___schemeToPort["rtmp"] = 1935;
			___schemeToPort["rtmpe"] = 1935;
			___schemeToPort["mms"] = 1755;
		}
		if (MAP_HAS1(___schemeToPort, uri.scheme))
			uri.port = ___schemeToPort[uri.scheme];
		else
			return false;
	}
	LOG_URI_SPLIT("uri.port: %u", uri.port);
//.........这里部分代码省略.........
开发者ID:Undev,项目名称:crtmpserver,代码行数:101,代码来源:uri.cpp


注:本文中的URI::Reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。