示例#1
0
void WARequest::sendRequest(QString url)
{
    qDebug()<< "SENDING";

    QNetworkRequest request;
    request.setUrl(QUrl(url+"?"+encodeUrl(params)));

    request.setRawHeader("User-Agent", userAgent.toAscii());
    //request.setRawHeader("Content-Type","application/x-www-form-urlencoded");
    //request.setRawHeader("Accept","text/xml");

    //QNetworkReply *reply = manager->post(request,encodeUrl(params));
    QNetworkReply *reply = manager->get(request);
    reply->ignoreSslErrors();

    //connect(reply, SIGNAL(readyRead()), this, SLOT(readyRead()));
   connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
            this, SLOT(networkError(QNetworkReply::NetworkError)));
    connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
            this, SLOT(sslError(QList<QSslError>)));



   // qDebug()<<encodeUrl(params);

   // manager->get(request);

    //manager->post(request,encodeUrl(params));
}
示例#2
0
void SearchLocationID::findNext( const QString& serverConfigFile )
{
	kdebugf();
	
	connect(&httpClient_, SIGNAL(finished()), this, SLOT(downloadingFinished()));
	connect(&httpClient_, SIGNAL(error()), this, SLOT(downloadingError()));
	connect(&httpClient_, SIGNAL(redirected(QString)), this, SLOT(downloadingRedirected(QString)));
	
	serverConfigFile_ = serverConfigFile;

	if (weatherConfig_ != 0)
		delete weatherConfig_;
	
	weatherConfig_ = new PlainConfigFile(WeatherGlobal::getConfigPath(serverConfigFile_));
		
	QString encoding = weatherConfig_->readEntry("Default","Encoding");
	decoder_ = QTextCodec::codecForName(encoding.ascii());
	
	host_ = weatherConfig_->readEntry("Name Search","Search host");
	httpClient_.setHost(host_);
	
	QString encodedCity = city_;
	encodeUrl(&encodedCity, encoding);
	url_.sprintf(weatherConfig_->readEntry("Name Search","Search path").ascii() , encodedCity.ascii());
	
	timerTimeout_->start(weather_global->CONNECTION_TIMEOUT, false);
	timeoutCount_ = weather_global->CONNECTION_COUNT;
	httpClient_.get(url_);
	
	kdebugf2();
}
/// <summary>
/// Fetches all available reports for the given device
/// </summary>
/// <param name="device">Name of the device to select reports for (GL_RENDERER) </param>
/// <returns></returns>
vector<reportInfo> VulkanDatabase::fetchDeviceReports(string device)
{
    vector<reportInfo> reportList;
    string httpReply;
    stringstream urlss;
    urlss << getBaseUrl() << "services/gl_getdevicereports.php?glrenderer=" << device;
    string url;
    url = encodeUrl(urlss.str());
    httpReply = httpGet(url);

    if (!httpReply.empty())
    {
        QXmlStreamReader xmlReader(&httpReply[0]);

        while (!xmlReader.atEnd()) {

            if ((xmlReader.name() == "report") && (xmlReader.isStartElement())) {
                reportInfo report;
                report.device = device;
                QXmlStreamAttributes xmlAttribs = xmlReader.attributes();
                report.operatingSystem = xmlAttribs.value("os").toString().toStdString();
                report.reportId = xmlAttribs.value("id").toInt();
                report.version = xmlReader.readElementText().toStdString();
                reportList.push_back(report);
            }

            xmlReader.readNext();
        }

    };

    return reportList;
}
/// <summary>
/// Gets the Id of a report from the online database
/// </summary>
/// <param name="description">Description of the report to get the Id for</param>
/// <returns></returns>
int VulkanDatabase::getReportId(VulkanDeviceInfo device)
{
    string reply;
    stringstream urlss;
    urlss << getBaseUrl() << "/services/getreportid.php?"
          << "devicename=" << device.props.deviceName
          << "&driverversion=" << device.getDriverVersion()
          << "&osname=" << device.os.name
          << "&osversion=" << device.os.version
          << "&osarchitecture=" << device.os.architecture;
    string url = encodeUrl(urlss.str());
    reply = httpGet(url);
    return (!reply.empty()) ? atoi(reply.c_str()) : -1;
}
示例#5
0
/*!
 * Export QT Contact into Versit Document.
 */
void QVersitContactExporterPrivate::exportContact(
    const QContact& contact,
    QVersitDocument& document)
{
    QList<QContactDetail> allDetails = contact.details();
    foreach (const QContactDetail& detail, allDetails) {
        // If the custom detail handler handles it, we don't have to.
        if (mDetailHandler
            && mDetailHandler->preProcessDetail(contact, detail, &document))
            continue;

        QList<QVersitProperty> removedProperties;
        QList<QVersitProperty> generatedProperties;
        QSet<QString> processedFields;

        if (detail.definitionName() == QContactName::DefinitionName) {
            encodeName(detail, document, &removedProperties, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactPhoneNumber::DefinitionName) {
            encodePhoneNumber(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactEmailAddress::DefinitionName) {
            encodeEmail(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactAddress::DefinitionName) {
            encodeAddress(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactGuid::DefinitionName) {
            encodeUid(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactUrl::DefinitionName) {
            encodeUrl(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactTimestamp::DefinitionName) {
            encodeRev(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactBirthday::DefinitionName) {
            encodeBirthDay(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactGeoLocation::DefinitionName) {
            encodeGeoLocation(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactNote::DefinitionName) {
            encodeNote(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactOrganization::DefinitionName) {
            encodeOrganization(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactRingtone::DefinitionName) {
            encodeRingtone(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactThumbnail::DefinitionName) {
            encodeThumbnail(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactAvatar::DefinitionName){
            encodeAvatar(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactAnniversary::DefinitionName) {
            encodeAnniversary(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactNickname::DefinitionName) {
            encodeNickname(detail, document, &removedProperties, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactTag::DefinitionName) {
            encodeTag(detail, document, &removedProperties, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactGender::DefinitionName) {
            encodeGender(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactOnlineAccount::DefinitionName) {
            encodeOnlineAccount(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactFamily::DefinitionName) {
            encodeFamily(detail, &generatedProperties, &processedFields);
        }

        // run plugin handlers
        foreach (QVersitContactExporterDetailHandlerV2* handler, mPluginDetailHandlers) {
            handler->detailProcessed(contact, detail, document,
                                     &processedFields, &removedProperties, &generatedProperties);
        }
        // run the v2 handler, if set
        if (mDetailHandler2 && mDetailHandlerVersion > 1) {
            mDetailHandler2->detailProcessed(contact, detail, document,
                                             &processedFields, &removedProperties, &generatedProperties);
        }

        foreach(const QVersitProperty& property, removedProperties) {
            document.removeProperty(property);
        }
bool cYTFeedParser::ParseFeed(yt_feed_mode_t mode, std::string search, std::string vid, yt_feed_orderby_t orderby)
{
	std::string answer;
	std::string url = "https://www.googleapis.com/youtube/v3/search?";
	bool append_res = true;
	std::string trailer;
	if (mode < FEED_LAST) {
		switch(mode) {
			//FIXME APIv3: we dont have the parameter "time".
			case MOST_POPULAR:
			default:
				//trailer = "&time=today";
				curfeed = "&chart=mostPopular";
			case MOST_POPULAR_ALL_TIME:
				curfeed = "&chart=mostPopular";
				break;
		}
		url = "https://www.googleapis.com/youtube/v3/videos?part=snippet";
		if (!region.empty()) {
			url += "&regionCode=";
			url += region;
		}
		url += curfeed;
	}
	else if (mode == NEXT) {
		if (next.empty())
			return false;
		url = nextprevurl;
		url += "&pageToken=";
		url += next;
		append_res = false;
	}
	else if (mode == PREV) {
		if (prev.empty())
			return false;
		url = nextprevurl;
		url += "&pageToken=";
		url += prev;
		append_res = false;
	}
	else if (mode == RELATED) {
		if (vid.empty())
			return false;
		url = "https://www.googleapis.com/youtube/v3/videos/";
		url += vid;
		url += "/related?";
	}
	else if (mode == SEARCH) {
		if (search.empty())
			return false;
		encodeUrl(search);
		url = "https://www.googleapis.com/youtube/v3/search?q=";
		url += search;
		url += "&part=snippet";
		//FIXME locale for "title" and "videoCount"
		const char *orderby_values[] = { "date","relevance","viewCount","rating","title","videoCount"};
		url += "&order=" + std::string(orderby_values[orderby & 3]);
	}

	feedmode = mode;
	if (append_res) {
		url += "&maxResults=";
		char res[10];
		sprintf(res, "%d", max_results);
		url+= res;
		url += "&key=" + key;
		nextprevurl = url;
	}

	return ParseFeed(url);
}
bool cTmdb::GetMovieDetails(std::string lang)
{
	printf("[TMDB]: %s\n",__func__);
	std::string url	= "http://api.themoviedb.org/3/search/multi?api_key="+key+"&language="+lang+"&query=" + encodeUrl(minfo.epgtitle);
	std::string answer;
	if (!getUrl(url, answer))
		return false;

	Json::Value root;
	Json::Reader reader;
	bool parsedSuccess = reader.parse(answer, root, false);
	if (!parsedSuccess) {
		printf("Failed to parse JSON\n");
		printf("%s\n", reader.getFormattedErrorMessages().c_str());
		return false;
	}

	minfo.result = root.get("total_results",0).asInt();

	printf("[TMDB]: results: %d\n",minfo.result);

	if (minfo.result > 0) {
		Json::Value elements = root["results"];
		minfo.id = elements[0].get("id",-1).asInt();
		minfo.media_type = elements[0].get("media_type","").asString();
		if (minfo.id > -1) {
			url = "http://api.themoviedb.org/3/"+minfo.media_type+"/"+to_string(minfo.id)+"?api_key="+key+"&language="+lang+"&append_to_response=credits";
			answer.clear();
			if (!getUrl(url, answer))
				return false;
			parsedSuccess = reader.parse(answer, root, false);
			if (!parsedSuccess) {
				printf("Failed to parse JSON\n");
				printf("%s\n", reader.getFormattedErrorMessages().c_str());
				return false;
			}

			minfo.overview = root.get("overview","").asString();
			minfo.poster_path = root.get("poster_path","").asString();
			minfo.original_title = root.get("original_title","").asString();;
			minfo.release_date = root.get("release_date","").asString();;
			minfo.vote_average = root.get("vote_average","").asString();;
			minfo.vote_count = root.get("vote_count",0).asInt();;
			minfo.runtime = root.get("runtime",0).asInt();;
			if (minfo.media_type == "tv") {
				minfo.original_title = root.get("original_name","").asString();;
				minfo.episodes = root.get("number_of_episodes",0).asInt();;
				minfo.seasons = root.get("number_of_seasons",0).asInt();;
				minfo.release_date = root.get("first_air_date","").asString();;
				elements = root["episode_run_time"];
				minfo.runtimes = elements[0].asString();
				for (unsigned int i= 1; i<elements.size();i++) {
					minfo.runtimes +=  + ", "+elements[i].asString();
				}
			}

			elements = root["genres"];
			minfo.genres = elements[0].get("name","").asString();
			for (unsigned int i= 1; i<elements.size();i++) {
				minfo.genres += ", " + elements[i].get("name","").asString();
			}

			elements = root["credits"]["cast"];
			for (unsigned int i= 0; i<elements.size() && i<10;i++) {
				minfo.cast +=  "  "+elements[i].get("name","").asString()+" ("+elements[i].get("character","").asString() + ")\n";
				//printf("test: %s (%s)\n",elements[i].get("character","").asString().c_str(),elements[i].get("name","").asString().c_str());
			}

			unlink(TMDB_COVER);
			if (hasCover())
				getBigCover(TMDB_COVER);
			//printf("[TMDB]: %s (%s) %s\n %s\n %d\n",minfo.epgtitle.c_str(),minfo.original_title.c_str(),minfo.release_date.c_str(),minfo.overview.c_str(),minfo.found);

			return true;
		}
	} else
		return false;

	return false;
}
示例#8
0
void HttpManager::run()
{
	unsigned int i;
	deque<pair<string,int> > linksQueue;  	//queue that is used for BFS exploring
	// We create another instance of UrlLocalResourceKey
	UrlLocalResourceKey * keygen = new UrlLocalResourceKey();
	
	linksQueue.push_back(make_pair(link,1));
	while(!linksQueue.empty())
	{
		string url=linksQueue[0].first;
		int currentDeep=linksQueue[0].second;
		linksQueue.pop_front();
				
		cout<<"Deep of search:"<<currentDeep<<" trying to get "<<url<<endl;

		WebResourceInfo webResource=downloader->getWebResourceInfo(url);
		
		//call all the validators and if not valid skip this resource
		bool valid=true;		
		for(i=0;i<validators.size();i++)valid=valid && validators[i]->isValid(webResource);
		if(!valid)
		{
			cout<<"But validators say not to download!"<<endl;
			continue;
		}

		// oldbam
		LocalResourceInfo storedLocalResource = registry->getRecord(url);
		if (storedLocalResource.getUrl() == webResource.getUrl()) {
			cout<<"INFO:"<<"Resource exists in the registry"<<endl;
			cout<<"URL:"<<storedLocalResource.getUrl()<<endl;
			cout<<"DATE:"<<storedLocalResource.getDate()<<endl;
			cout<<"LOCALPATH:"<<storedLocalResource.getLocalPath()<<endl;
			continue;
		}
		// end oldbam

		string hostName=getHostName(webResource);
		//virtual path of the resource on the server
		string resourceHostPath=getResourceDirs(webResource);
		//change last '/' to '\'
		if(resourceHostPath!="")
			resourceHostPath[resourceHostPath.length()-1]='\\';

		//local resource's path
		string localResourceDir=localDir+hostName+"\\"+resourceHostPath;
		
		//full resource's local file name(path + name)
		string fullLocalFileName=localResourceDir+getLocalFileName(webResource);
		
		
		downloader->makeDir(localResourceDir);
		bool result = downloader->download(webResource,localResourceDir);
		if (result == true) cout<<"Ok. Placed to: "<<fullLocalFileName<<endl;
		else cout<<"ERROR : Downloader returned 'false' after download."<<endl;

		//create and register LocalResource
		char timeChar [19];
        _strdate( timeChar );
		timeChar[8]='#';
		_strtime( timeChar+9 );					
		LocalResourceInfo localResource(webResource.getUrl(),(string)timeChar,fullLocalFileName);
		registry->addRecord(keygen->getKey(localResource),localResource);

		//parse and add new links to the queue
		if(webResource.getMimeValue("Content-Type").find("text/html")!=string::npos && currentDeep<maxDeep)
		{
			string content,tmp;
			ifstream file(fullLocalFileName.c_str());
			while (getline(file, tmp)) 
			{
				content += tmp;
			}
			content = encodeUrl(content, ' ');
			vector<string> links=parser->getLinks(content);
			
			//deleting duplicates
			sort(links.begin(),links.end());
			links.erase(unique(links.begin(),links.end()),links.end());						
			parser->relative2Absolute(links,getHostName(webResource)+"/"+getResourceDirs(webResource));

			// modified by oldbam, add cout for links
			cout<<"INFO : New links are found by manager:"<<endl;
			for(i=0;i<links.size();i++)
			{
				linksQueue.push_back(make_pair(links[i],currentDeep+1));
				cout<<"LINK : "<<links[i]<<endl<<"DEPTH : "<<currentDeep+1<<endl;
			}
			cout<<endl;
			// end modified by oldbam
		}
		cout<<endl;
	}
	delete keygen;
}
示例#9
0
	Result
	Medialib::addPath (const QString &path) const
	{
		return addPathEncoded (encodeUrl (path));
	}
示例#10
0
	Result
	Medialib::addPath (const QUrl &path) const
	{
		return addPathEncoded (encodeUrl (path.toString ()));
	}