//******************************************************************************************
//function: getWebServiceURL
//params: const QString &lpzURL
//return: QString
//Description: Get correct webservice URL.
//******************************************************************************************
QString WSClient::getWebServiceURL(const QString &lpzURL)
{
    int index = 0;
    QString lpzValidateURL = lpzURL;

    QRegExp urlRegex("^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(([0-9]{1,5})?/?.*)$");
    QValidator* urlValidate = new QRegExpValidator(urlRegex);

    if (urlValidate->validate(lpzValidateURL, index) == QValidator::Acceptable) {
        if(lpzValidateURL.indexOf(QString(SERVICE_BASE)) >= 1) {
            return lpzValidateURL;
        }
        else {
            if(lpzValidateURL.at(lpzValidateURL.length() -1) == '/') {
                lpzValidateURL += QString(SERVICE_BASE);
            }
            else {
                lpzValidateURL += "/" + QString(SERVICE_BASE);
            }
        }
    }
    else {
        throw "Invalid URL";
    }

    return lpzValidateURL;
}
bool YoutubeDL::isValidUrl(QString url)
{
    QRegExp urlRegex("^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(([0-9]{1,5})?/?.*)$");
    QRegExpValidator validator(urlRegex);
    int index = 0;

    if(validator.validate(url, index) == QValidator::Acceptable) {
        return true;
    }
    return false;
}
AutoPtr<WindowConfig> AppConfig::GetWindowByURL(const std::string& url)
{
	AutoPtr<WindowConfig> config(0);

	// First try matching the URL exactly.
	for (size_t i = 0; i < windows.size(); i++)
	{
		if (windows[i]->GetURL() == url)
		{
			config = windows[i];
			break;
		}
	}

	// If we didn't find a matching window URL, try matching
	// against the url-regex parameter of the windows configs.
	if (config.isNull())
	{
		for (size_t i = 0; i < windows.size(); i++)
		{
			if (windows[i]->GetURLRegex().empty())
				continue;

			std::string urlRegex(windows[i]->GetURLRegex());
			Poco::RegularExpression::Match match;
			Poco::RegularExpression regex(windows[i]->GetURLRegex());
			regex.match(url, match);
			if (match.length != 0)
			{
				config = windows[i];
				break;
			}
		}
	}

	// Return NULL here, because callers need to know whether
	// or not a configuration was matched.
	if (config.isNull())
		return config;

	// Return a copy here, so that the original configuration
	// is preserved when this is mutated
	config = WindowConfig::FromWindowConfig(config);
	config->SetURL(url);
	return config;
}