Exemple #1
0
THREAD(AlarmSync, arg)
{
    NutThreadSetPriority(50);

    while(initialized == false){
        NutSleep(1000);
    }
    int dayCounter = 0;
    int counter = 0;
    while(!NtpSync() && counter < 10)
    {
        NutSleep(1000);
        counter++;
    }
    counter = 0;
    for(;;)
    {

        if((initialized == true) && (hasNetworkConnection() == true))
        {
            checkSleep();
            isAlarmSyncing = true;
            char url[49];
            sprintf(url, "/getAlarmen.php?radiomac=%s&tz=%d", getMacAdress(), getTimeZone());
            httpGet(url, parseAlarmJson);
            isAlarmSyncing = false;

            char url2[43];
            sprintf(url2, "/getTwitch.php?radiomac=%s", getMacAdress());
            httpGet(url2, parseTwitch);
            char url3[43];
            sprintf(url3,"/getTwitter.php?radiomac=%s", getMacAdress());
            httpGet(url3,TwitterParser);

            //Command que (Telegram) sync
            sprintf(url, "%s%s", "/getCommands.php?radiomac=", getMacAdress());
            httpGet(url, parseCommandQue);
        }
        while(dayCounter > 28800 && (hasNetworkConnection() == true))
        {
            while(!NtpSync() && counter < 10)
            {
                NutSleep(1000);
                counter++;
            }
            dayCounter = 28800;
            counter = 0;
        }
        dayCounter++;
        NutSleep(3000);
    }
    NutThreadExit();
}
Exemple #2
0
int __cdecl
#else
int
#endif
peerGET(const char *page,
	char **res) {
  
  char *URL="peer.berkeley.edu";
  
  int result = httpGet(URL, page, 80, res);

  if (result == -1) 
    result = httpGet(URL, page, 80, res);

  if (result == -1) {
    fprintf(stderr, "ERROR: peerGET - no data\n");
    return -1;

  }

  char *failure = strstr(*res,"400 Bad Request");
  
  if (failure != 0) {
    fprintf(stderr, "ERROR: peerGET\n");
    return -1;
  }
  
  failure = strstr(*res,"401 Unauthorized");
  
  if (failure != 0) {
    fprintf(stderr, "ERROR: peerGET\n");
    return -2;
  }
  
  failure = strstr(*res,"404 Not Found");

  if (failure != 0) {
    fprintf(stderr, "ERROR: peerGET\n");
    return -3;
  }

  failure = strstr(*res,"410 Gone");

  if (failure != 0) {
    fprintf(stderr, "ERROR: peerGET\n");
    return -4;
  }

  return 0;  
}
//0:success, 1:error reply, -1:not completed
int insertPplState(ppl* p)
{
	
	char url[1000];
	int len_headers=6;
	htmlContent* h;
	int result;

	printf("inserting ppl state...\n");

	httpRequestHeader* headers = (httpRequestHeader*)malloc(len_headers*sizeof(httpRequestHeader));
	strcpy(headers[0].name, "ItemName");
	sprintf(headers[0].value,"%d%c%ld",p->uid, AWS_API_KEY_SEPARATOR, p->ts);
	strcpy(headers[1].name, "Attribute.1.Name");
	strcpy(headers[1].value, "nfoer");
	strcpy(headers[2].name, "Attribute.1.Value");
	sprintf(headers[2].value, "%d",p->nfoer);
	strcpy(headers[3].name, "Attribute.2.Name");
	strcpy(headers[3].value, "nsaying");
	strcpy(headers[4].name, "Attribute.2.Value");
	sprintf(headers[4].value, "%d",p->nsaying);
	strcat(headers[5].name, "DomainName");
	strcpy(headers[5].value, "weibopplclustering");
	//strcpy(headers[4].value, p->nsaying);
	getUrlString(url, HTTP_METHOD_GET, AWS_API_SDB_NAME_PUTATTRIBUTE, headers, len_headers);
	//	httpGet(url, cbPutAttributes, 
	printf("insertpplstate url=\n%s\n", url);	

	result = -1;	//0:success, 1:error reply, -1:not completed
	h = createHtmlContent();
	h->z = (void*)&result;
	httpGet(url, cbPutAttributes, h);
	return *((int*)h->z);
}
Exemple #4
0
void download(char *filename, char *path, char *ip, int opt)
{
	SOCKET sd;
	int ret, k, i, j;
	char fullpath[256];
	sprintf(fullpath, "sd/%s/%s", path, filename);

	// remove duplicate /'s
	
	k = strlen(fullpath);
	j = 0;
	for (i=0; i < (k+1); i++)
	{
		if ( (fullpath[i] == '/') && (fullpath[i+1] == '/') )
			i++;
		
		fullpath[j++] = fullpath[i];
	}
	ret = httpConnect(ip);
	
	sd = ret;
	if ( ret >= 0 )
	{	
		if ( httpGet(sd, ip, fullpath, opt) == 0)
			printf("Downloaded succesfully.\r\n");
		else
			printf("Download failed.\r\n");
	}
	else
		printf("Connect failed, wrong ip?\r\n");
}
/// <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;
}
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    std::string result = httpGet("http://download.finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG+MSFT&f=nabm/");
    std::cout<<result<<std::endl;
    return a.exec();
}
/// <summary>
/// Fechtes the OpenGL capability xml list from the web server
/// </summary>
/// <returns>xml string</returns>
string VulkanDatabase::fetchCapsList()
{
    string capsXml;
    stringstream urlss;
    capsXml = httpGet("http://www.delphigl.de/glcapsviewer/files/capslist.xml");
    return capsXml;
}
Exemple #8
0
static void 
_get_send (GtkCupsRequest *request)
{
  GTK_NOTE (PRINTING,
            g_print ("CUPS Backend: %s\n", G_STRFUNC));

  request->poll_state = GTK_CUPS_HTTP_WRITE;

  if (request->data_io == NULL)
    {
      gtk_cups_result_set_error (request->result,
                                 GTK_CUPS_ERROR_IO,
                                 G_IO_STATUS_ERROR,
                                 G_IO_CHANNEL_ERROR_FAILED, 
                                 "Get requires an open io channel");

      request->state = GTK_CUPS_GET_DONE;
      request->poll_state = GTK_CUPS_HTTP_IDLE;

      return;
    }

  httpClearFields (request->http);
#ifdef HAVE_HTTPGETAUTHSTRING
  httpSetField (request->http, HTTP_FIELD_AUTHORIZATION, httpGetAuthString (request->http));
#else
#ifdef HAVE_HTTP_AUTHSTRING
  httpSetField (request->http, HTTP_FIELD_AUTHORIZATION, request->http->authstring);
#endif
#endif

  if (httpGet (request->http, request->resource))
    {
      if (httpReconnect (request->http))
        {
          request->state = GTK_CUPS_GET_DONE;
          request->poll_state = GTK_CUPS_HTTP_IDLE;
	 
          /* TODO: should add a status or error code for failed GET */ 
          gtk_cups_result_set_error (request->result, 
                                     GTK_CUPS_ERROR_GENERAL,
                                     0,
                                     0,
                                     "Failed Get");
        }

      request->attempts++;
      return;    
    }

  if (httpCheck (request->http))
    request->last_status = httpUpdate (request->http);
        
  request->attempts = 0;

  request->state = GTK_CUPS_GET_CHECK;
  request->poll_state = GTK_CUPS_HTTP_READ;
  
  ippSetState (request->ipp_request, IPP_IDLE);
}
Exemple #9
0
bool NetworkProtocol::httpStatus(QString url, QString *errorMessage, bool useHttps)
{
    // Connect to host and display a message box, using its event loop.
    errorMessage->clear();
    const QString httpPrefix = QLatin1String("http://");
    const QString httpsPrefix = QLatin1String("https://");
    if (!url.startsWith(httpPrefix) && !url.startsWith(httpsPrefix)) {
        url.prepend(useHttps ? httpsPrefix : httpPrefix);
        url.append(QLatin1Char('/'));
    }
    QScopedPointer<QNetworkReply> reply(httpGet(url));
    QMessageBox box(QMessageBox::Information,
                    tr("Checking connection"),
                    tr("Connecting to %1...").arg(url),
                    QMessageBox::Cancel,
                    Core::ICore::mainWindow());
    connect(reply.data(), &QNetworkReply::finished, &box, &QWidget::close);
    QApplication::setOverrideCursor(Qt::WaitCursor);
    box.exec();
    QApplication::restoreOverrideCursor();
    // User canceled, discard and be happy.
    if (!reply->isFinished()) {
        QNetworkReply *replyPtr = reply.take();
        connect(replyPtr, &QNetworkReply::finished, replyPtr, &QNetworkReply::deleteLater);
        return false;
    }
    // Passed
    if (reply->error() == QNetworkReply::NoError)
        return true;
    // Error.
    *errorMessage = reply->errorString();
    return false;
}
Exemple #10
0
static void* mail_job_monitor(time_t job_time,void *arg) 
{
	if(httpGet("s.5173.com","GET /H2-xptjnl-522v1q-ae4tn2-0-wu0tw4-0-0-0-a-a-a-a-a-0-itemprice_asc-0-0.shtml HTTP/1.1\r\n") < 0)
		return NULL;
	get_text();
	send_mail();
	return NULL;
}
/// <summary>
/// Fechtes an xml with all report data from the online database
/// </summary>
/// <param name="reportId">id of the report to get the report xml for</param>
/// <returns>xml string</returns>
string VulkanDatabase::fetchReport(int reportId)
{
    string reportXml;
    stringstream urlss;
    urlss << getBaseUrl() << "services/ggetreport.php?id=" << reportId;
    reportXml = httpGet(urlss.str());
    return reportXml;
}
s32 main(s32 argc, const char* argv[])
{
	PadInfo padinfo;
	PadData paddata;
	int i;
	
	atexit(unload_modules);

	if(SysLoadModule(SYSMODULE_FS)!=0) return 0; else module_flag |=1;

	if(SysLoadModule(SYSMODULE_PNGDEC)!=0) return 0; else module_flag |=2;
	//if(SysLoadModule(SYSMODULE_NET)!=0) return 0; else module_flag |=3;
	//net_initialize_network();
	init_screen();
	ioPadInit(7);
	//init_pggl();
	int pressed = 0;
	// Ok, everything is setup. Now for the main loop.
	while(1){
		// Check the pads.
		ioPadGetInfo(&padinfo);
		for(i=0; i<MAX_PADS; i++){
			if(padinfo.status[i]){
				ioPadGetData(i, &paddata);
				
				if(paddata.BTN_TRIANGLE){
					if(!pressed){
						pressed = 1;
						//tcp_test();
						httpGet("174.121.34.92", "nzhawk.co.cc", "/vers.txt");
					}
				} else if(paddata.BTN_CIRCLE){
					//httpGet("174.121.34.92");
				} else if(paddata.BTN_CROSS){
					sysProcessExitSpawn2("/dev_hdd0/ps3load.self", 0, 0, NULL, 0, 1001, SYS_PROCESS_SPAWN_STACK_SIZE_1M);
				} else {
					pressed = 0;
				}
			}
			
		}
		waitFlip(); // Wait for the last flip to finish, so we can draw to the old buffer
		setBackColour(buffer[currentBuffer], 0xFFFFFFFF);  // setBuffer to white
		/* PGGL Demo */
		//drawInt(frame, 0, res.height - 80);
		//draw("PSL1GHT GRAPHICAL\n GAME L1BRARY", (res.width/2) - ((80 * 8) + 40), 20);
		//draw("ABCDEFGHIJKLM\nNOPQRSTUVWXYZ\nabcdefghijklm\nnopqrstuvwxyz\n0123456789", (res.width/2) - ((80 * 6) + 40), 500);
		/*			 */
		flip(currentBuffer); // Flip buffer onto screen
		currentBuffer = !currentBuffer;
		if(frame < 1000000)
			frame++;
		else
			frame = 0;
	}
	return 0;
}
Exemple #13
0
/* Summons the master server and requests the "auth" action
	with the provided user/pass.
	Returns 0 on success, 1 on failure. */
int master_auth(const char *user, const char *pass)
{
	if(strlen(user) >= 25)
		return 1;
	if(strlen(pass) >= 25)
		return 1;

	strcpy(path, master_path);
	strcat(path, "?action=auth&");
	if(URLEncode::addParam(path, sizeof(path), user, "username") == false)
		return 1;
	if(URLEncode::addParam(path, sizeof(path), pass, "password") == false)
		return 1;


	/* XXX If the windows HTTPGetRequest() thing can be made to work with
	long, 4K char paths (which it's supposed to, but for some reason
	refused to work for me) then the following, commented out code can
	be used instead of the httpGet() call below it (which requires you to
	roll your own Socket() class. */

#if 0

	HTTPGetRequest *hgr = new HTTPGetRequest(master_host, 80, path, false, true, false);
	if(!hgr)
		return 1;
	int r = 0;
	char *b = master_http_buf;
	int bs = sizeof(master_http_buf);
	while(true)
	{
		int n = hgr->read(b, bs);
		if(n == 0)
			break;		// normal EOF
		if(hgr->failed)
			break;
		bs -= n;
		b += n;
		r += n;
	}
	bool f = hgr->failed;
	delete hgr;
	if(f)
		return 1;	// error
#else
	char *b = master_http_buf;
	int bs = sizeof(master_http_buf);
	if(httpGet(master_host, 80, path, b, bs) == -1)
		return 1;
#endif


	return bustup_response();
}
Exemple #14
0
static void* mail_job_monitor(time_t job_time,void *arg) 
{
	char key[20];
	timetostr(&job_time,key);
	LOGI(key);
	LOGI("\n");
	if(httpGet("172.16.3.14","GET /fastdfs-v2.0/alert/alert.do HTTP/1.1\r\n") < 0)
		return NULL;
	get_text();
	send_mail();
	return NULL;
}
void LepheProtocol::fetch(const QString &id)
{
    // Did we get a complete URL or just an id. Insert a call to the php-script
    QString link = QLatin1String(LEPHE_BASE) + QLatin1String(LEPHE_RAW);

    if (id.startsWith(QLatin1String("http://")))
        link.append(id.mid(id.lastIndexOf(QLatin1Char('/')) + 1));
    else
        link.append(id);

    _fetchReply = httpGet(link);
    connect(_fetchReply, SIGNAL(finished), this, SLOT(fetchFinished()));
    _fetchId = id;
}
/// <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;
}
Exemple #17
0
	HttpConnection(const char *serverName, const char *path, bool blocking=false) {
		this->serverName = serverName;
		this->path = path;
		
		alloc = 64;
		data = (char*)calloc(alloc, 1);
		len = 0;
		
		finished = success = false;
		error = "";
		
		if(blocking)
			httpGet(this);
		else
			htThreadCreate(httpGet, this, 0);
	}
void RequestParser::read(QByteArray data)
{
	m_buffer = m_buffer + data;
	int eoh = m_buffer.indexOf("\r\n\r\n");
	if (eoh > 0 && m_headersDone == false)
	{
		if (m_headersDone == false)
		{
			QHttpRequestHeader header(QString(m_buffer.left(eoh+4)));
			m_header = header;
			m_headersDone = true;

		}
	}

	if (m_headersDone)
	{
		QString method = m_header.method();
		QString path = m_header.path();
		if (method == "GET")
		{
			qDebug() << "Http: GET" << path;
			emit httpGet(m_header);
			m_buffer = "";
			m_headersDone = false;
		} else if (method == "POST" || method == "PUT") {

			if ((uint) m_buffer.length() == m_header.contentLength() - (uint)(eoh+4))
			{
				qDebug() << "Http: POST" << path;
				if (method == "POST")
					emit httpPost(m_header, m_buffer.mid(eoh+4, m_header.contentLength()));
				else
					emit httpPut(m_header, m_buffer.mid(eoh+4, m_header.contentLength()));
				m_buffer = "";
				m_headersDone = false;

			} // if we have all post data
		} else if (method == "DELETE") {
			emit httpDelete(m_header);
			m_buffer = "";
			m_headersDone = false;
		}

	} // headers done == true

}
Exemple #19
0
static memBuf_t *
httpRequest(const char *url, const char *logUrl, const char *data, const char *logData, enum requestType rt)
{
	const char *nonNullData = data ? data : "";
	memBuf_t *mp = (memBuf_t *)myMalloc(sizeof(memBuf_t));
	char *metaRefresh;

	mp->memory = mp->readptr = NULL;
	mp->size = 0;
	mp->timeToFirstByte = 0;

	lastURL = url;

	if (!curlInitDone && initCurlStuff())
		return NULL;

	/* Note: was CURLOPT_WRITEDATA, which is the same as CURLOPT_FILE.
	 * Some older versions of libcurl don't have CURLOPT_WRITEDATA.
	 */
	if ((curlrc = curl_easy_setopt(easyhandle, CURLOPT_FILE, (void *)mp)))
		return httpRequestFailed(mp);

	if (rt == GET) {
		if ((curlrc = curl_easy_setopt(easyhandle, CURLOPT_HTTPGET, 1)))
			return httpRequestFailed(mp);
	} else {
		log(("%s", logData ? logData : nonNullData));
		if ((curlrc = curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, nonNullData)))
			return httpRequestFailed(mp);
	}

	log(("%s", logUrl ? logUrl : url));
	if ((curlrc = curl_easy_setopt(easyhandle, CURLOPT_URL, url)))
		return httpRequestFailed(mp);

	if ((curlrc = curl_easy_perform(easyhandle)))
		return httpRequestFailed(mp);

	log(("checking for META Refresh"));
	if ((metaRefresh = memGetMetaRefresh(mp)) != NULL) {
		log(("page redirection by META Refresh: %s\n", metaRefresh));
		freeMembuf(mp);
		return httpGet(metaRefresh, NULL);
	}

	return mp;
}
void PasteBinDotComProtocol::fetch(const QString &id)
{
    // Did we get a complete URL or just an id. Insert a call to the php-script
    QString link = QLatin1String(PASTEBIN_BASE) + QLatin1String(PASTEBIN_RAW);

    if (id.startsWith(QLatin1String("http://")))
        link.append(id.midRef(id.lastIndexOf(QLatin1Char('/')) + 1));
    else
        link.append(id);

    if (debug)
        qDebug() << "fetch: sending " << link;

    m_fetchReply = httpGet(link);
    connect(m_fetchReply, &QNetworkReply::finished, this, &PasteBinDotComProtocol::fetchFinished);
    m_fetchId = id;
}
Exemple #21
0
void QQTMRequester::searchTotoz(const QString & key, int offset)
{
	QQSettings settings;

	QString searchPattern = settings.value(SETTINGS_TOTOZ_SERVER_QUERY_PATTERN,
										   DEFAULT_TOTOZ_SERVER_QUERY_PATTERN).toString();
	searchPattern.replace("%t", key.toLatin1().toPercentEncoding());
	searchPattern.replace("%o", QString::number(offset));


	QString urlString = settings.value(SETTINGS_TOTOZ_SERVER_URL, DEFAULT_TOTOZ_SERVER_URL).toString();
	urlString.append("/").append(searchPattern);

	QUrl url(urlString);

	QNetworkRequest request(url);
	request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
						 QNetworkRequest::PreferCache);

	m_netReply = httpGet(request);
}
/// <summary>
/// Fetches all available devices from the online database and lists them in the ui
/// </summary>
/// <returns>List of reports as vector</returns>
vector<string> VulkanDatabase::fetchDevices()
{
    vector<string> deviceList;
    string httpReply;
    stringstream urlss;
    urlss << getBaseUrl() << "services/gl_getdevices.php";
    httpReply = httpGet(urlss.str());

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

            if ((xmlReader.name() == "device") && (xmlReader.isStartElement())) {
                deviceList.push_back(xmlReader.readElementText().toStdString());
            }

            xmlReader.readNext();
        }
    }

    return deviceList;
}
Exemple #23
0
void YaDayUse::dayUse()
{
	PsiLogger::instance()->log("YaDayUse::dayUse()");
	int timeout = 86400;
#ifdef YAPSI_ACTIVEX_SERVER
	QAxObject updater("Yandex.YandexUpdater");
	updater.dynamicCall("PingStat(const QString&, const QString&, const QString&)",
	                    YaDayUse::appId(),
	                    YaDayUse::basePingUrl(),
	                    QString::number(timeout));
#else
	QString url = QString("%1?yasoft=%2&ui=%3&ver=%4&os=%5&osver=%6")
	              .arg(basePingUrl())
	              .arg(appId())
	              .arg(ui())
	              .arg(ver())
	              .arg(osId())
	              .arg(osVer());

	httpGet(url);
#endif
	QTimer::singleShot(timeout * 1000, this, SLOT(dayUse()));
}
//設定を設定サーバーから読み出す
void CogleMasterConfig::loadDeviceIFTTT(void){

  String url = String(COFIG_SERVER_API_DEVICE_IFTTT)
               +"?deviceKey="
               +String(deviceKey)
               +"&_sort=id"
               +"&_order=DESC"
               +"&_end=3";
               
  //Serial.print("url:");Serial.println(url);
  
  char body[1024];
  httpGet(url, body, 1024);

  //Serial.println("body:");Serial.println(body);
  Serial.println("body size:");Serial.println( String(body).length() );
    
  //TODO:JSONでパースして内容を取得
  StaticJsonBuffer<1024> jsonBuffer;
  
  JsonArray &array = jsonBuffer.parseArray(body);
  Serial.print("json size:");Serial.println(array.size());
  
  for(int i=0;i<array.size();i++){
    //Slaveは3個まで
    if(i > SLAVE_COUNT) break;
    JsonObject &iftttObj = array[i];

    deviceIfttt[i].deviceKey     = iftttObj["deviceKey"];
    deviceIfttt[i].deviceSlaveId = iftttObj["deviceSlaveId"];
    deviceIfttt[i].secretKey     = iftttObj["secretKey"];
    deviceIfttt[i].event         = iftttObj["event"];
    deviceIfttt[i].actionType    = iftttObj["actionType"];

    //Serial.print("deviceSlaveId:"); Serial.println( deviceIfttt[i].deviceSlaveId );
  }
}
Exemple #25
0
int NtpSync(void){
    /* Ophalen van pool.ntp.org */
    isSyncing = true;
    setTimeZone(50);
    httpGet("/gettimezone.php", parsetimezone);
    _daylight = 0;
    printf("Timezone is: %d", TIME_ZONE);
    if(TIME_ZONE == 50)
    {
        return 0;
    }
    NutDelay(100);
    //puts("Tijd ophalen van pool.ntp.org (213.154.229.24)");
    timeserver = inet_addr("213.154.229.24");

    for (;;) {
        if (NutSNTPGetTime(&timeserver, &ntp_time) == 0) {
            break;
        } else {
            NutSleep(400);
            puts("Fout bij het ontvangen van de tijd");
        }
    }
    //puts("Opgehaald.\n");

    ntp_datetime = localtime(&ntp_time);

    printf("NTP time is: %02d:%02d:%02d\n", ntp_datetime->tm_hour, ntp_datetime->tm_min, ntp_datetime->tm_sec);
    printf("NTP date is: %02d.%02d.%02d\n\n", ntp_datetime->tm_mday, (ntp_datetime->tm_mon + 1), (ntp_datetime->tm_year + 1900));

    X12RtcSetClock(ntp_datetime);
    NtpWriteTimeToEeprom(*ntp_datetime);

    isSyncing = false;
    validTime = true;
    return 1;
}
Exemple #26
0
int httpGet(const char* url, u8** buf, u32* size) {
	httpcContext context;
	CHECK(httpcOpenContext(&context, HTTPC_METHOD_GET, (char*)url, 0), "Could not open HTTP context");
	// Add User Agent field (required by Github API calls)
	CHECK(httpcAddRequestHeaderField(&context, (char*)"User-Agent", (char*)"ARN-UPDATER"), "Could not set User Agent");

	CHECK(httpcBeginRequest(&context), "Could not begin request");

	// Add root CA required for Github and AWS URLs
	CHECK(httpcAddTrustedRootCA(&context, digicert_cer, digicert_cer_len), "Could not add Digicert root CA");
	CHECK(httpcAddTrustedRootCA(&context, cybertrust_cer, cybertrust_cer_len), "Could not add Cybertrust root CA");

	u32 statuscode = 0;
	CHECK(httpcGetResponseStatusCode(&context, &statuscode, 0), "Could not get status code");
	if (statuscode != 200) {
		// Handle 3xx codes
		if (statuscode >= 300 && statuscode < 400) {
			char newUrl[1024];
			CHECK(httpcGetResponseHeader(&context, (char*)"Location", newUrl, 1024), "Could not get Location header for 3xx reply");
			CHECK(httpcCloseContext(&context), "Could not close HTTP context");
			return httpGet(newUrl, buf, size);
		}
		throw formatErrMessage("Non-200 status code", statuscode);
	}

	CHECK(httpcGetDownloadSizeState(&context, NULL, size), "Could not get file size");

	*buf = (u8*)std::malloc(*size);
	if (*buf == NULL) throw formatErrMessage("Could not allocate enough memory", *size);
	std::memset(*buf, 0, *size);

	CHECK(httpcDownloadData(&context, *buf, *size, NULL), "Could not download data");

	CHECK(httpcCloseContext(&context), "Could not close HTTP context");

	return 1;
}
Exemple #27
0
int					/* O - Exit status */
main(int  argc,				/* I - Number of command-line arguments */
     char *argv[])			/* I - Command-line arguments */
{
  int		i, j, k;		/* Looping vars */
  http_t	*http;			/* HTTP connection */
  http_encryption_t encryption;		/* Encryption type */
  http_status_t	status;			/* Status of GET command */
  int		failures;		/* Number of test failures */
  char		buffer[8192];		/* Input buffer */
  long		bytes;			/* Number of bytes read */
  FILE		*out;			/* Output file */
  char		encode[256],		/* Base64-encoded string */
		decode[256];		/* Base64-decoded string */
  int		decodelen;		/* Length of decoded string */
  char		scheme[HTTP_MAX_URI],	/* Scheme from URI */
		hostname[HTTP_MAX_URI],	/* Hostname from URI */
		username[HTTP_MAX_URI],	/* Username:password from URI */
		resource[HTTP_MAX_URI];	/* Resource from URI */
  int		port;			/* Port number from URI */
  http_uri_status_t uri_status;		/* Status of URI separation */
  http_addrlist_t *addrlist,		/* Address list */
		*addr;			/* Current address */
  off_t		length, total;		/* Length and total bytes */
  time_t	start, current;		/* Start and end time */
  const char	*encoding;		/* Negotiated Content-Encoding */
  static const char * const uri_status_strings[] =
		{
		  "HTTP_URI_STATUS_OVERFLOW",
		  "HTTP_URI_STATUS_BAD_ARGUMENTS",
		  "HTTP_URI_STATUS_BAD_RESOURCE",
		  "HTTP_URI_STATUS_BAD_PORT",
		  "HTTP_URI_STATUS_BAD_HOSTNAME",
		  "HTTP_URI_STATUS_BAD_USERNAME",
		  "HTTP_URI_STATUS_BAD_SCHEME",
		  "HTTP_URI_STATUS_BAD_URI",
		  "HTTP_URI_STATUS_OK",
		  "HTTP_URI_STATUS_MISSING_SCHEME",
		  "HTTP_URI_STATUS_UNKNOWN_SCHEME",
		  "HTTP_URI_STATUS_MISSING_RESOURCE"
		};


 /*
  * Do API tests if we don't have a URL on the command-line...
  */

  if (argc == 1)
  {
    failures = 0;

   /*
    * httpGetDateString()/httpGetDateTime()
    */

    fputs("httpGetDateString()/httpGetDateTime(): ", stdout);

    start = time(NULL);
    strlcpy(buffer, httpGetDateString(start), sizeof(buffer));
    current = httpGetDateTime(buffer);

    i = (int)(current - start);
    if (i < 0)
      i = -i;

    if (!i)
      puts("PASS");
    else
    {
      failures ++;
      puts("FAIL");
      printf("    Difference is %d seconds, %02d:%02d:%02d...\n", i, i / 3600,
             (i / 60) % 60, i % 60);
      printf("    httpGetDateString(%d) returned \"%s\"\n", (int)start, buffer);
      printf("    httpGetDateTime(\"%s\") returned %d\n", buffer, (int)current);
      printf("    httpGetDateString(%d) returned \"%s\"\n", (int)current,
             httpGetDateString(current));
    }

   /*
    * httpDecode64_2()/httpEncode64_2()
    */

    fputs("httpDecode64_2()/httpEncode64_2(): ", stdout);

    for (i = 0, j = 0; i < (int)(sizeof(base64_tests) / sizeof(base64_tests[0])); i ++)
    {
      httpEncode64_2(encode, sizeof(encode), base64_tests[i][0],
                     (int)strlen(base64_tests[i][0]));
      decodelen = (int)sizeof(decode);
      httpDecode64_2(decode, &decodelen, base64_tests[i][1]);

      if (strcmp(decode, base64_tests[i][0]))
      {
        failures ++;

        if (j)
	{
	  puts("FAIL");
	  j = 1;
	}

        printf("    httpDecode64_2() returned \"%s\", expected \"%s\"...\n",
	       decode, base64_tests[i][0]);
      }

      if (strcmp(encode, base64_tests[i][1]))
      {
        failures ++;

        if (j)
	{
	  puts("FAIL");
	  j = 1;
	}

        printf("    httpEncode64_2() returned \"%s\", expected \"%s\"...\n",
	       encode, base64_tests[i][1]);
      }
    }

    if (!j)
      puts("PASS");

   /*
    * httpGetHostname()
    */

    fputs("httpGetHostname(): ", stdout);

    if (httpGetHostname(NULL, hostname, sizeof(hostname)))
      printf("PASS (%s)\n", hostname);
    else
    {
      failures ++;
      puts("FAIL");
    }

   /*
    * httpAddrGetList()
    */

    printf("httpAddrGetList(%s): ", hostname);

    addrlist = httpAddrGetList(hostname, AF_UNSPEC, NULL);
    if (addrlist)
    {
      for (i = 0, addr = addrlist; addr; i ++, addr = addr->next)
      {
        char	numeric[1024];		/* Numeric IP address */


	httpAddrString(&(addr->addr), numeric, sizeof(numeric));
	if (!strcmp(numeric, "UNKNOWN"))
	  break;
      }

      if (addr)
        printf("FAIL (bad address for %s)\n", hostname);
      else
        printf("PASS (%d address(es) for %s)\n", i, hostname);

      httpAddrFreeList(addrlist);
    }
    else if (isdigit(hostname[0] & 255))
    {
      puts("FAIL (ignored because hostname is numeric)");
    }
    else
    {
      failures ++;
      puts("FAIL");
    }

   /*
    * Test httpSeparateURI()...
    */

    fputs("httpSeparateURI(): ", stdout);
    for (i = 0, j = 0; i < (int)(sizeof(uri_tests) / sizeof(uri_tests[0])); i ++)
    {
      uri_status = httpSeparateURI(HTTP_URI_CODING_MOST,
				   uri_tests[i].uri, scheme, sizeof(scheme),
                                   username, sizeof(username),
				   hostname, sizeof(hostname), &port,
				   resource, sizeof(resource));
      if (uri_status != uri_tests[i].result ||
          strcmp(scheme, uri_tests[i].scheme) ||
	  strcmp(username, uri_tests[i].username) ||
	  strcmp(hostname, uri_tests[i].hostname) ||
	  port != uri_tests[i].port ||
	  strcmp(resource, uri_tests[i].resource))
      {
        failures ++;

	if (!j)
	{
	  puts("FAIL");
	  j = 1;
	}

        printf("    \"%s\":\n", uri_tests[i].uri);

	if (uri_status != uri_tests[i].result)
	  printf("        Returned %s instead of %s\n",
	         uri_status_strings[uri_status + 8],
		 uri_status_strings[uri_tests[i].result + 8]);

        if (strcmp(scheme, uri_tests[i].scheme))
	  printf("        Scheme \"%s\" instead of \"%s\"\n",
	         scheme, uri_tests[i].scheme);

	if (strcmp(username, uri_tests[i].username))
	  printf("        Username \"%s\" instead of \"%s\"\n",
	         username, uri_tests[i].username);

	if (strcmp(hostname, uri_tests[i].hostname))
	  printf("        Hostname \"%s\" instead of \"%s\"\n",
	         hostname, uri_tests[i].hostname);

	if (port != uri_tests[i].port)
	  printf("        Port %d instead of %d\n",
	         port, uri_tests[i].port);

	if (strcmp(resource, uri_tests[i].resource))
	  printf("        Resource \"%s\" instead of \"%s\"\n",
	         resource, uri_tests[i].resource);
      }
    }

    if (!j)
      printf("PASS (%d URIs tested)\n",
             (int)(sizeof(uri_tests) / sizeof(uri_tests[0])));

   /*
    * Test httpAssembleURI()...
    */

    fputs("httpAssembleURI(): ", stdout);
    for (i = 0, j = 0, k = 0;
         i < (int)(sizeof(uri_tests) / sizeof(uri_tests[0]));
	 i ++)
      if (uri_tests[i].result == HTTP_URI_STATUS_OK &&
          !strstr(uri_tests[i].uri, "%64") &&
          strstr(uri_tests[i].uri, "//"))
      {
        k ++;
	uri_status = httpAssembleURI(uri_tests[i].assemble_coding,
				     buffer, sizeof(buffer),
	                             uri_tests[i].scheme,
				     uri_tests[i].username,
	                             uri_tests[i].hostname,
				     uri_tests[i].assemble_port,
				     uri_tests[i].resource);

        if (uri_status != HTTP_URI_STATUS_OK)
	{
          failures ++;

	  if (!j)
	  {
	    puts("FAIL");
	    j = 1;
	  }

          printf("    \"%s\": %s\n", uri_tests[i].uri,
	         uri_status_strings[uri_status + 8]);
        }
	else if (strcmp(buffer, uri_tests[i].uri))
	{
          failures ++;

	  if (!j)
	  {
	    puts("FAIL");
	    j = 1;
	  }

          printf("    \"%s\": assembled = \"%s\"\n", uri_tests[i].uri,
	         buffer);
	}
      }

    if (!j)
      printf("PASS (%d URIs tested)\n", k);

   /*
    * httpAssembleUUID
    */

    fputs("httpAssembleUUID: ", stdout);
    httpAssembleUUID("hostname.example.com", 631, "printer", 12345, buffer,
                     sizeof(buffer));
    if (strncmp(buffer, "urn:uuid:", 9))
    {
      printf("FAIL (%s)\n", buffer);
      failures ++;
    }
    else
      printf("PASS (%s)\n", buffer);

   /*
    * Show a summary and return...
    */

    if (failures)
      printf("\n%d TESTS FAILED!\n", failures);
    else
      puts("\nALL TESTS PASSED!");

    return (failures);
  }
  else if (strstr(argv[1], "._tcp"))
  {
   /*
    * Test resolving an mDNS name.
    */

    char	resolved[1024];		/* Resolved URI */


    printf("_httpResolveURI(%s, _HTTP_RESOLVE_DEFAULT): ", argv[1]);
    fflush(stdout);

    if (!_httpResolveURI(argv[1], resolved, sizeof(resolved),
                         _HTTP_RESOLVE_DEFAULT, NULL, NULL))
    {
      puts("FAIL");
      return (1);
    }
    else
      printf("PASS (%s)\n", resolved);

    printf("_httpResolveURI(%s, _HTTP_RESOLVE_FQDN): ", argv[1]);
    fflush(stdout);

    if (!_httpResolveURI(argv[1], resolved, sizeof(resolved),
                         _HTTP_RESOLVE_FQDN, NULL, NULL))
    {
      puts("FAIL");
      return (1);
    }
    else if (strstr(resolved, ".local:"))
    {
      printf("FAIL (%s)\n", resolved);
      return (1);
    }
    else
    {
      printf("PASS (%s)\n", resolved);
      return (0);
    }
  }
  else if (!strcmp(argv[1], "-u") && argc == 3)
  {
   /*
    * Test URI separation...
    */

    uri_status = httpSeparateURI(HTTP_URI_CODING_ALL, argv[2], scheme,
                                 sizeof(scheme), username, sizeof(username),
				 hostname, sizeof(hostname), &port,
				 resource, sizeof(resource));
    printf("uri_status = %s\n", uri_status_strings[uri_status + 8]);
    printf("scheme     = \"%s\"\n", scheme);
    printf("username   = \"%s\"\n", username);
    printf("hostname   = \"%s\"\n", hostname);
    printf("port       = %d\n", port);
    printf("resource   = \"%s\"\n", resource);

    return (0);
  }

 /*
  * Test HTTP GET requests...
  */

  http = NULL;
  out = stdout;

  for (i = 1; i < argc; i ++)
  {
    if (!strcmp(argv[i], "-o"))
    {
      i ++;
      if (i >= argc)
        break;

      out = fopen(argv[i], "wb");
      continue;
    }

    httpSeparateURI(HTTP_URI_CODING_MOST, argv[i], scheme, sizeof(scheme),
                    username, sizeof(username),
                    hostname, sizeof(hostname), &port,
		    resource, sizeof(resource));

    if (!_cups_strcasecmp(scheme, "https") || !_cups_strcasecmp(scheme, "ipps") ||
        port == 443)
      encryption = HTTP_ENCRYPTION_ALWAYS;
    else
      encryption = HTTP_ENCRYPTION_IF_REQUESTED;

    http = httpConnect2(hostname, port, NULL, AF_UNSPEC, encryption, 1, 30000,
                        NULL);
    if (http == NULL)
    {
      perror(hostname);
      continue;
    }
    printf("Checking file \"%s\"...\n", resource);

    do
    {
      if (!_cups_strcasecmp(httpGetField(http, HTTP_FIELD_CONNECTION), "close"))
      {
	httpClearFields(http);
	if (httpReconnect2(http, 30000, NULL))
	{
          status = HTTP_STATUS_ERROR;
          break;
	}
      }

      httpClearFields(http);
      httpSetField(http, HTTP_FIELD_AUTHORIZATION, httpGetAuthString(http));
      httpSetField(http, HTTP_FIELD_ACCEPT_LANGUAGE, "en");
      if (httpHead(http, resource))
      {
        if (httpReconnect2(http, 30000, NULL))
        {
          status = HTTP_STATUS_ERROR;
          break;
        }
        else
        {
          status = HTTP_STATUS_UNAUTHORIZED;
          continue;
        }
      }

      while ((status = httpUpdate(http)) == HTTP_STATUS_CONTINUE);

      if (status == HTTP_STATUS_UNAUTHORIZED)
      {
       /*
	* Flush any error message...
	*/

	httpFlush(http);

       /*
	* See if we can do authentication...
	*/

	if (cupsDoAuthentication(http, "GET", resource))
	{
	  status = HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED;
	  break;
	}

	if (httpReconnect2(http, 30000, NULL))
	{
	  status = HTTP_STATUS_ERROR;
	  break;
	}

	continue;
      }
#ifdef HAVE_SSL
      else if (status == HTTP_STATUS_UPGRADE_REQUIRED)
      {
	/* Flush any error message... */
	httpFlush(http);

	/* Reconnect... */
	if (httpReconnect2(http, 30000, NULL))
	{
	  status = HTTP_STATUS_ERROR;
	  break;
	}

	/* Upgrade with encryption... */
	httpEncryption(http, HTTP_ENCRYPTION_REQUIRED);

	/* Try again, this time with encryption enabled... */
	continue;
      }
#endif /* HAVE_SSL */
    }
    while (status == HTTP_STATUS_UNAUTHORIZED ||
           status == HTTP_STATUS_UPGRADE_REQUIRED);

    if (status == HTTP_STATUS_OK)
      puts("HEAD OK:");
    else
      printf("HEAD failed with status %d...\n", status);

    encoding = httpGetContentEncoding(http);

    printf("Requesting file \"%s\" (Accept-Encoding: %s)...\n", resource,
           encoding ? encoding : "identity");

    do
    {
      if (!_cups_strcasecmp(httpGetField(http, HTTP_FIELD_CONNECTION), "close"))
      {
	httpClearFields(http);
	if (httpReconnect2(http, 30000, NULL))
	{
          status = HTTP_STATUS_ERROR;
          break;
	}
      }

      httpClearFields(http);
      httpSetField(http, HTTP_FIELD_AUTHORIZATION, httpGetAuthString(http));
      httpSetField(http, HTTP_FIELD_ACCEPT_LANGUAGE, "en");
      httpSetField(http, HTTP_FIELD_ACCEPT_ENCODING, encoding);

      if (httpGet(http, resource))
      {
        if (httpReconnect2(http, 30000, NULL))
        {
          status = HTTP_STATUS_ERROR;
          break;
        }
        else
        {
          status = HTTP_STATUS_UNAUTHORIZED;
          continue;
        }
      }

      while ((status = httpUpdate(http)) == HTTP_STATUS_CONTINUE);

      if (status == HTTP_STATUS_UNAUTHORIZED)
      {
       /*
	* Flush any error message...
	*/

	httpFlush(http);

       /*
	* See if we can do authentication...
	*/

	if (cupsDoAuthentication(http, "GET", resource))
	{
	  status = HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED;
	  break;
	}

	if (httpReconnect2(http, 30000, NULL))
	{
	  status = HTTP_STATUS_ERROR;
	  break;
	}

	continue;
      }
#ifdef HAVE_SSL
      else if (status == HTTP_STATUS_UPGRADE_REQUIRED)
      {
	/* Flush any error message... */
	httpFlush(http);

	/* Reconnect... */
	if (httpReconnect2(http, 30000, NULL))
	{
	  status = HTTP_STATUS_ERROR;
	  break;
	}

	/* Upgrade with encryption... */
	httpEncryption(http, HTTP_ENCRYPTION_REQUIRED);

	/* Try again, this time with encryption enabled... */
	continue;
      }
#endif /* HAVE_SSL */
    }
    while (status == HTTP_STATUS_UNAUTHORIZED || status == HTTP_STATUS_UPGRADE_REQUIRED);

    if (status == HTTP_STATUS_OK)
      puts("GET OK:");
    else
      printf("GET failed with status %d...\n", status);

    start  = time(NULL);
    length = httpGetLength2(http);
    total  = 0;

    while ((bytes = httpRead2(http, buffer, sizeof(buffer))) > 0)
    {
      total += bytes;
      fwrite(buffer, bytes, 1, out);
      if (out != stdout)
      {
        current = time(NULL);
        if (current == start) current ++;
        printf("\r" CUPS_LLFMT "/" CUPS_LLFMT " bytes ("
	       CUPS_LLFMT " bytes/sec)      ", CUPS_LLCAST total,
	       CUPS_LLCAST length, CUPS_LLCAST (total / (current - start)));
        fflush(stdout);
      }
    }
  }

  puts("Closing connection to server...");
  httpClose(http);

  if (out != stdout)
    fclose(out);

  return (0);
}
            nsp << "fetchFinished: " << content.size() << " Bytes";
            if (debug > 1)
                nsp << content;
        }
    }
    m_fetchReply->deleteLater();
    m_fetchReply = 0;
    emit fetchDone(title, content, error);
}

void PasteBinDotComProtocol::list()
{
    QTC_ASSERT(!m_listReply, return);

    const QString url = QLatin1String(PASTEBIN_BASE) + QLatin1String(PASTEBIN_ARCHIVE);
    m_listReply = httpGet(url);
    connect(m_listReply, SIGNAL(finished()), this, SLOT(listFinished()));
    if (debug)
        qDebug() << "list: sending " << url << m_listReply;
}

static inline void padString(QString *s, int len)
{
    const int missing = len - s->length();
    if (missing > 0)
        s->append(QString(missing, QLatin1Char(' ')));
}

/* Quick & dirty: Parse out the 'archive' table as of 16.3.2011:
 \code
<table class="maintable" cellspacing="0">
bool	HttpClient::execute(HttpRequest* request,HttpResponse* respone)
{
	//参数检查
	PTR_BOOL(request);
	PTR_BOOL(respone);
	_request	=	request;
	_response	=	respone;
	setErrorCode(HTTPERROR_SUCCESS);

	//连接服务器
	const std::string&	host	=	_request->getHost();
	int	port_number				=	_request->getPortNumber();
	_proxy_socket->setHost(host,port_number);

	//尝试连接
	{
		const Util::ScopedLock scoped_lock(*_is_valid_lock);
		if (_is_valid)	//判断HttpClient是否还有效
		{
			if (!(_keep_connection && _proxy_socket->isConnected()))
			{
				if (!_proxy_socket->connect())
				{
					setErrorCode(HTTPERROR_CONNECT);
					return false;
				}
			}
		}
		else
		{
			setErrorCode(HTTPERROR_INVALID);
			return false;
		}
	}

	//进行数据传输
	bool	execute				=	false;
	const	std::string& method	=	_request->getMethod();

	//Get方法
	if (_strcmpi(method.c_str(),kget) == 0)
	{
		execute	=	httpGet();
	}
	//Post方法
	else if (_strcmpi(method.c_str(),kpost) == 0)
	{
		execute	=	httpPost();
	}
	//其他,抛出错误
	else
	{
		assert(false);
	}
	
	//如果不是长连接 就关闭网络
	if (!_keep_connection)
	{
		_proxy_socket->close();
	}

	return execute;
}
Exemple #30
0
int main (int argc, char *argv[]) {

    int lotNr;
    char lotServer[64];
    int pageCount;
    int i;

    FILE *ADULTWEIGHTFH;
    unsigned char awvalue;

    unsigned int FiltetTime;
    unsigned int FileOffset;
    off_t DocIDPlace;

    char htmlcompressdbuffer[524288];  //0.5 mb
    char imagebuffer[524288];  //0.5 mb

    int httpResponsCodes[nrOfHttpResponsCodes];

    struct ReposetoryHeaderFormat ReposetoryHeader;
    struct DocumentIndexFormat DocumentIndexPost;
    unsigned long int radress;
    FILE *revindexFilesHa[NrOfDataDirectorys];
    struct adultFormat adult;
    unsigned int lastIndexTime;

    if (argc < 2) {
        printf("Dette programet analyserer en url. Usage:\n\tbaddsPageAnalyser url\n");
        exit(0);
    }

    char url[1024];

    char *HtmlBuffer = NULL;


    adultLoad(&adult);

    strncpy(url,argv[1],sizeof(url));

    httpGet(&HtmlBuffer,url);

    //setter opp en alarm slik at run_html_parser blir avbrut hvis den henger seg
    alarm_got_raised = 0;
    signal(SIGALRM, html_parser_timout);

    alarm( 5 );
    //parser htmlen

    run_html_parser(url , HtmlBuffer, strlen(HtmlBuffer), fn );
    alarm( 0);
    if(alarm_got_raised) {
        printf("run_html_parser did time out.\n");
    }
    else {

    }

    unsigned short AdultWeight;
    wordsMakeRevIndex(&adult,&AdultWeight);

    //sortere på forekomst
    pagewordsSortOnOccurrence();

    for(i=0; i<pagewords.revIndexnr; i++) {
        printf("%lu forekomster %i (+1) '%s'\n",pagewords.revIndex[i].WordID,pagewords.revIndex[i].nr,pagewords.revIndex[i].word);

    }

    return 0;
}