File: UriParser.cpp

package info (click to toggle)
spring 103.0%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,720 kB
  • ctags: 63,685
  • sloc: cpp: 368,283; ansic: 33,988; python: 12,417; java: 12,203; awk: 5,879; sh: 1,846; xml: 655; perl: 405; php: 211; objc: 194; makefile: 77; sed: 2
file content (49 lines) | stat: -rw-r--r-- 1,428 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#include "UriParser.h"
#include "Util.h"

static void SplitString(const std::string& text, const char* sepChar, std::string& s1, std::string& s2, std::string& all)
{
	const size_t q = text.find(sepChar);
	if (q != std::string::npos) {
		s1 = text.substr(0, q);
		s2 = text.substr(q + 1);
		return;
	}
	all = text;
}

bool ParseSpringUri(const std::string& uri, std::string& username, std::string& password, std::string& host, int& port)
{
	// see http://cpp-netlib.org/0.10.1/in_depth/uri.html (2014)
	if (uri.find("spring://") == std::string::npos)
		return false; // wrong scheme

	const std::string full = uri.substr(std::string("spring://").length());
	std::string authority, query, user_info, server, portStr;
	bool error = false;
	SplitString(full,      "/", authority, query, authority);
	SplitString(authority, "@", user_info, server, server);
	SplitString(user_info, ":", username, password, username);
	SplitString(server,    ":", host, portStr, host);
	if (portStr.empty())
		return true;
	port = StringToInt(portStr, &error);
	if (error) {
		port = 0;
		return false;
	}
	//FIXME pass query
	return true;
}

bool ParseRapidUri(const std::string& uri, std::string& tag)
{
	if (uri.find("rapid://") == std::string::npos) {
		return false; // wrong scheme
	}
	tag = uri.substr(std::string("rapid://").length());
	return !tag.empty();
}