Exemplo n.º 1
0
HttpPost::HttpPost(HttpConnection* connection, QString const& path,  
   QString const& postData) : HttpReply(connection), m_postData(postData)
{
   setUrl(path);
}
Exemplo n.º 2
0
void Livre::chargement(QDomElement & e)
{
    QDomNodeList zeus = e.elementsByTagName ("nom");
    if(zeus.size () != 1)
    {
        throw QString("Il y a un souci sur la balise nom");
    }

    setNom(zeus.at (0).toElement ().text ());

    zeus = e.elementsByTagName ("url");
    if(zeus.size () == 1)
    {
        setUrl (zeus.at (0).toElement ().text ());
    }

    zeus = e.elementsByTagName ("genre");
    if(zeus.size () != 1)
    {
        throw QString("Il y a un souci sur la balise genre");
    }
    setGenre (zeus.at (0).toElement ().text ());

    zeus = e.elementsByTagName ("editeur");
    if(zeus.size () != 1)
    {
        throw QString("Il y a un souci sur la balise editeur");
    }
    setEditeur (zeus.at (0).toElement ().text ());

    zeus = e.elementsByTagName ("cycle");
    if(zeus.size () == 1)
    {
        QDomElement chronos = zeus.at (0).toElement ();
        setCycle(chronos.text ());
        setNumeroTome (chronos.attribute ("tome").toInt ());
    }

    zeus = e.elementsByTagName ("sortie");
    if(zeus.size () != 1)
    {
        throw QString("Il y a un souci sur la balise sortie");
    }

    setDate(QDate::fromString (zeus.at (0).toElement ().text ()));

    zeus = e.elementsByTagName ("auteur");
    if(zeus.size () == 0)
    {
        throw QString("Il manque au moins un auteur");
    }

    for(int venus = 0; venus < zeus.size (); venus ++)
    {
        addAuteur (zeus.at (venus).toElement ().text ());
    }

    zeus = e.elementsByTagName ("lu");

    if(zeus.size () != 1)
    {
        throw QString("Il y a un probleme avec la balise lu");
    }

    setFini (zeus.at (0).toElement ().text ().toInt ());
}
Exemplo n.º 3
0
HttpGet::HttpGet(HttpConnection* connection,  QString const& sourcePath) 
 : HttpReply(connection), m_file(0)
{
   setUrl(sourcePath);
}
Exemplo n.º 4
0
Arquivo: WLink.C Projeto: 913862627/wt
WLink::WLink(const std::string& url)
{ 
  setUrl(url);
}
Exemplo n.º 5
0
CNetworkReply::CNetworkReply( QObject *parent, const QNetworkRequest &req, const QNetworkAccessManager::Operation op )
	: QNetworkReply( parent )
{
	// Setup the request
	setRequest( req );
	setUrl( req.url() );
	setOperation( op );
	QNetworkReply::open( QIODevice::ReadOnly | QIODevice::Unbuffered );

	// Bogus content
	m_lOffset = 0;
	m_content.clear();

	// Get the path to the file
	QByteArray path = req.url().path().toUtf8();

	str::t_string8 mime = "application/octet-stream";
	str::t_string8 full = 
		disk::WebPath< str::t_string8 >( "htm", str::t_string8( path.data(), path.length() ) );

	printf( "%s(%d) : RES : %s\n", __FILE__, __LINE__, full.c_str() );

	// Check for linked in resources
	CHmResources res;
	if ( res.IsValid() )
	{
		// See if there is such a resource
		HMRES hRes = res.FindResource( 0, full.c_str() );
		if ( hRes )
		{
			// Set return type
			setAttribute( QNetworkRequest::HttpStatusCodeAttribute, QVariant( 200 ) );

			switch ( res.Type( hRes ) )
			{
				default :
					break;

				case 1 :
				{
					mime = disk::GetMimeType( full );
					const void *ptr = res.Ptr( hRes );
					unsigned long sz = res.Size( hRes );

					if ( ptr && 0 < sz )
						m_content.append( QByteArray::fromRawData( (const char* )ptr, sz ) );

				} break;

				case 2 :
				{
					mime = "text/html";

					// Get function pointer
					CHmResources::t_fn pFn = res.Fn( hRes );
					if ( pFn )
					{
						// in / out
						TPropertyBag< str::t_string8 > in;
						TPropertyBag< str::t_string8 > out;
						
						// Copy GET parameters
						long szQi = req.url().encodedQueryItems().size();
						if ( szQi )
						{	TPropertyBag< str::t_string8 > &pbGet = in[ "GET" ];
							for( long i = 0; i < szQi; i++ ) 
							{	const QPair< QByteArray, QByteArray > it = req.url().encodedQueryItems().at( i );
								pbGet[ parser::DecodeUrlStr( str::t_string8( it.first.data(), it.first.length() ) ) ]
									= parser::DecodeUrlStr( str::t_string8( it.second.data(), it.second.length() ) );
							} // end for
						} // end if

						// Execute the page
						pFn( in, out );

						// Set the output
						m_content.append( out.data(), out.length() );

					} // end if

				} break;

			} // end switch

		} // end if

		else
			setAttribute( QNetworkRequest::HttpStatusCodeAttribute, QVariant( 404 ) );

	} // end if

	else
		setAttribute( QNetworkRequest::HttpStatusCodeAttribute, QVariant( 404 ) );

	// Data size
	setHeader( QNetworkRequest::ContentLengthHeader, QVariant( m_content.size() ) );

	// Access control
	// setRawHeader( "Access-Control-Allow-Origin", "*" );

	// MIME Type
	if ( mime.length() )
		setHeader( QNetworkRequest::ContentTypeHeader, QVariant( mime.c_str() ) );

	// Call notify functions
	QMetaObject::invokeMethod( this, "metaDataChanged", Qt::QueuedConnection );
	QMetaObject::invokeMethod( this, "readyRead", Qt::QueuedConnection );
	QMetaObject::invokeMethod( this, "downloadProgress", Qt::QueuedConnection,
							   Q_ARG( qint64, m_content.size() ), Q_ARG( qint64, m_content.size() ) );
	QMetaObject::invokeMethod( this, "finished", Qt::QueuedConnection );

}
Exemplo n.º 6
0
MaiaXmlRpcClient::MaiaXmlRpcClient(QUrl url, QObject* parent) : QObject(parent)
{
	setUrl(url);
}
Exemplo n.º 7
0
Arquivo: WLink.C Projeto: 913862627/wt
WLink::WLink(const char *url)
{ 
  setUrl(url);
}
Exemplo n.º 8
0
void WebBrowser::onStopLogin()
{
    setUrl(QUrl("about:blank"));
    emit visibleChanged(m_visible = false);
}
Exemplo n.º 9
0
void WebBrowser::onStartLogin(const QUrl url)
{
    setUrl(url);
    m_visible = true;
    emit visibleChanged(m_visible);
}
Exemplo n.º 10
0
/**
 * @brief Connect to server.
 *
 * @param url
 */
void Client::connect(const Url *url)
{
    setUrl(url);
    resolve(m_url.host());
}
Exemplo n.º 11
0
QNetworkReplyFileImpl::QNetworkReplyFileImpl(QObject *parent, const QNetworkRequest &req, const QNetworkAccessManager::Operation op)
    : QNetworkReply(*new QNetworkReplyFileImplPrivate(), parent)
{
    setRequest(req);
    setUrl(req.url());
    setOperation(op);
    setFinished(true);
    QNetworkReply::open(QIODevice::ReadOnly);

    QNetworkReplyFileImplPrivate *d = (QNetworkReplyFileImplPrivate*) d_func();

    QUrl url = req.url();
    if (url.host() == QLatin1String("localhost"))
        url.setHost(QString());

#if !defined(Q_OS_WIN)
    // do not allow UNC paths on Unix
    if (!url.host().isEmpty()) {
        // we handle only local files
        QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Request for opening non-local file %1").arg(url.toString());
        setError(QNetworkReply::ProtocolInvalidOperationError, msg);
        QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
            Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ProtocolInvalidOperationError));
        QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);
        return;
    }
#endif
    if (url.path().isEmpty())
        url.setPath(QLatin1String("/"));
    setUrl(url);


    QString fileName = url.toLocalFile();
    if (fileName.isEmpty()) {
        if (url.scheme() == QLatin1String("qrc"))
            fileName = QLatin1Char(':') + url.path();
        else
            fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery);
    }

    QFileInfo fi(fileName);
    if (fi.isDir()) {
        QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Cannot open %1: Path is a directory").arg(url.toString());
        setError(QNetworkReply::ContentOperationNotPermittedError, msg);
        QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
            Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentOperationNotPermittedError));
        QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);
        return;
    }

    d->realFile.setFileName(fileName);
    bool opened = d->realFile.open(QIODevice::ReadOnly | QIODevice::Unbuffered);

    // could we open the file?
    if (!opened) {
        QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Error opening %1: %2")
                .arg(d->realFile.fileName(), d->realFile.errorString());

        if (d->realFile.exists()) {
            setError(QNetworkReply::ContentAccessDenied, msg);
            QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
                Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentAccessDenied));
        } else {
            setError(QNetworkReply::ContentNotFoundError, msg);
            QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
                Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentNotFoundError));
        }
        QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);
        return;
    }

    setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified());
    d->realFileSize = fi.size();
    setHeader(QNetworkRequest::ContentLengthHeader, d->realFileSize);

    QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection);

    QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection,
        Q_ARG(qint64, d->realFileSize), Q_ARG(qint64, d->realFileSize));

    QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection);
    QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);
}
Exemplo n.º 12
0
int main(int const argc, char** argv) {
	struct AddrFilter filter = {.allow_private = false};
	int (* addr_processor)(struct IPAddr);

	// Deal with options

	const char short_opts[] = "vVh46pa";
	struct option long_opts[] = {
		{"allow-private", no_argument, 0, 'p'},
		{"process-all", no_argument, 0, 'a'},
		{"verbose", no_argument, 0, 'v'},
		{"version", no_argument, 0, 'V'},
		{"help", no_argument, 0, 'h'},
	};
	bool verbosity = 0;
	bool process_all = false;
	int opt_index = 0;
	char opt;

	while ((opt = getopt_long(argc, argv, short_opts, long_opts, &opt_index)) != -1) {
		switch (opt) {
		case 'a':
			process_all = true;
			break;
		case 'v':
			verbosity = 1;
			break;
		case 'V':
			puts(version);
			return EXIT_SUCCESS;
		case '4':
			addFilterAf(&filter, AF_INET);
			break;
		case '6':
			addFilterAf(&filter, AF_INET6);
			break;
		case 'p':
			filter.allow_private = true;
			break;
		case 'h':
			printUsage();
			return EXIT_SUCCESS;
		default:
			printUsage();
			return EXIT_USAGE;
		}
	}

	// Listen for all changes if none specified.
	if (filter.num_af == 0){
		addFilterAf(&filter, AF_INET);
		addFilterAf(&filter, AF_INET6);
	}

	switch ((argc - optind)){
	case 1:
		addr_processor = printAddr;
		break;
	case 2:
		setUrl(argv[optind + 1]);
		addr_processor = webUpdate;
		break;
	default:
		puts("Usage:\n");
		printUsage();
		return EXIT_USAGE;
	}

	char const * const iface_name = argv[optind];
	filter.iface = if_nametoindex(iface_name);
	if (!filter.iface) {
		fprintf(stderr, "Error resolving interface %s: %s\n",
			iface_name, strerror(errno));
		return EXIT_FAILURE;
	}

	if (verbosity){
		puts("Running in verbose mode.");
		printf("Listening on interfaces: %s (#%d)\n", iface_name, filter.iface);
		fputs("Listening for address changes in:", stdout);
		if (checkFilterAf(filter, AF_INET))
			printf(" IPv4");
		if (checkFilterAf(filter, AF_INET6))
			printf(" IPv6");
		puts("");
	}

	// Prepare monitoring, cleanup necessary if exiting after this point.
	struct MonitorState state;
	if (!initState(filter, &state, 1024)){
		perror("Couldn't set up for monitoring");
		return EXIT_FAILURE;
	}

	// Main loop

	pid_t child = -1;
	do {
		struct IPAddr new_addr = nextAddr(filter, &state);
		if (child != -1){
			// Make sure kill isn't called on first loop.
			if (!process_all)
				kill(child, termsig);

			int status;
			if (waitpid(child, &status, 0) == -1){
				perror("Error waiting for child");
				break;
			}
			if (!childOK(status))
				break;
		}

		if (new_addr.af == AF_MAX){
			perror("An error occurred while waiting for a new IP");
			break;
		} else if (new_addr.af == AF_UNSPEC) {
			fputs("Netlink socket closed by kernel.", stderr);
			break;
		}

		// TODO: Could use exec
		child = fork();
		if (child == -1){
			perror("Could not fork to process new address.");
			break;
		} else if (!child){
			close(state.socket); // Make sure to set CLOEXEC if changing to exec.
			return addr_processor(new_addr);
		}
	} while (true);

	close(state.socket);
	free(state.buf);
	return EXIT_FAILURE;
}