Пример #1
0
extern "C" void rho_sys_unset_http_proxy()
{
#if defined(OS_WINDOWS_DESKTOP) || defined(RHODES_EMULATOR)
	_AtlModule.GetAppWindow().setProxy();
#endif
	RHOCONF().removeProperty("http_proxy_host", false);
	RHOCONF().removeProperty("http_proxy_port", false);
	RHOCONF().removeProperty("http_proxy_login", false);
	RHOCONF().removeProperty("http_proxy_password", false);
	RAWLOG_INFO("Unsetting HTTP proxy");
}
Пример #2
0
CMainWindow& getAppWindow() 
{
	return _AtlModule.GetAppWindow();
}
Пример #3
0
void parseHttpProxyURI(const rho::String &http_proxy)
{
	// http://<login>:<passwod>@<host>:<port>
	const char *default_port = "8080";

	if (http_proxy.length() == 0)
		rho_sys_unset_http_proxy();

	if (http_proxy.length() < 8) {
		RAWLOG_ERROR("invalid http proxy url");
		return;
	}

	int index = http_proxy.find("http://", 0, 7);
	if (index == string::npos) {
		RAWLOG_ERROR("http proxy url should starts with \"http://\"");
		return;
	}
	index = 7;

	enum {
		ST_START,
		ST_LOGIN,
		ST_PASSWORD,
		ST_HOST,
		ST_PORT,
		ST_FINISH
	};

	String token, login, password, host, port;
	char c, state = ST_START, prev_state = state;
	int length = http_proxy.length();

	for (int i = index; i < length; i++) {
		c = http_proxy[i];

		switch (state) {
		case ST_START:
			if (c == '@') {
				prev_state = state; state = ST_HOST;
			} else if (c == ':') {
				prev_state = state; state = ST_PASSWORD;
			} else {
				token +=c;
				state = ST_HOST;
			}
			break;
		case ST_HOST:
			if (c == ':') {
				host = token; token.clear();			
				prev_state = state; state = ST_PORT;
			} else if (c == '@') {
				host = token; token.clear();		
				prev_state = state;	state = ST_LOGIN;					
			} else {
				token += c;
				if (i == (length - 1)) {
					host = token; token.clear();								
				}
			}
			break;
		case ST_PORT:
			if (c == '@') {
				port = token; token.clear();			
				prev_state = state; state = ST_LOGIN;
			} else {
				token += c;
				if (i == (length - 1)) {
					port = token; token.clear();
				}
			}
			break;
		case ST_LOGIN:
			if (prev_state == ST_PORT || prev_state == ST_HOST) {
				login    = host; host.clear();
				password = port; port.clear();
				prev_state = state; state = ST_HOST;
				token += c;
			} else {
				token += c;
				if (i == (length - 1)) {
					login = token; token.clear();								
				}
			}
			break;
		case ST_PASSWORD:
			if (c == '@') {
				password = token; token.clear();			
				prev_state = state; state = ST_HOST;
			} else {
				token += c;
				if (i == (length - 1)) {
					password = token; token.clear();								
				}
			}
			break;
		default:
			;
		}
	}

	RAWLOG_INFO("Setting up HTTP proxy:");
	RAWLOG_INFO1("URI: %s", http_proxy.c_str());
	RAWLOG_INFO1("HTTP proxy login    = %s", login.c_str());
	RAWLOG_INFO1("HTTP proxy password = %s", password.c_str());
	RAWLOG_INFO1("HTTP proxy host     = %s", host.c_str());
	RAWLOG_INFO1("HTTP proxy port     = %s", port.c_str());

	if (host.length()) {
#if defined(OS_WINDOWS_DESKTOP) || defined(RHODES_EMULATOR)
		_AtlModule.GetAppWindow().setProxy(host, port, login, password);
#endif
		RHOCONF().setString ("http_proxy_host", host, false);

		if (port.length()){
			RHOCONF().setString ("http_proxy_port", port, false);
		} else {
			RAWLOG_WARNING("there is no proxy port defined");
		}

		if (login.length())
			RHOCONF().setString ("http_proxy_login", login, false);

		if (password.length())
			RHOCONF().setString ("http_proxy_password", password, false);

	} else {
		RAWLOG_ERROR("empty host name in HTTP-proxy URL");
	}
}