示例#1
0
DLL_PUBLIC int fstatFile(void* stream, LPDVDFILESTAT pFileStat)
{
    LPDVDFILEHANDLE pHandle = (LPDVDFILEHANDLE)stream;

    if (pHandle == NULL && pFileStat != NULL)
    {
        return -1;
    }

    memset(pFileStat, 0, sizeof(DVDFILESTAT));

    if (!isUrl(pHandle->m_strFileName))
    {
        // Local files
        struct stat buf;

        if (fstat(fileno(pHandle->m_pFile), &buf) == -1)
        {
            return -1;
        }

        pFileStat->m_FileTime       = buf.st_mtime;
        pFileStat->m_qwFileSize     = buf.st_size;
        pFileStat->m_bIsDirectory   = S_ISDIR(buf.st_mode) ? true : false;
    }
    else if (pHandle->m_pHttpServer != NULL)
    {
        pFileStat->m_FileTime       = pHandle->m_pHttpServer->getTimeStamp();
        pFileStat->m_qwFileSize     = pHandle->m_pHttpServer->getContentSize();
    }
    return 0;
}
示例#2
0
DLL_PUBLIC void * openFile(const char *filename, const char *mode, const char *proxy)
{
    LPDVDFILEHANDLE pHandle = new DVDFILEHANDLE;

    if (pHandle == NULL)
    {
        return NULL;
    }

    pHandle->m_strFileName = filename;

    if (!isUrl(pHandle->m_strFileName))
    {
#ifdef _WIN32
        wchar_t szUtf16Filename[MAX_PATH];
        wchar_t szMode[20];
        utf8ToUtf16(szMode, mode);
        if (utf8ToUtf16(szUtf16Filename, filename))
        {
            pHandle->m_pFile = _wfopen(szUtf16Filename, szMode);
        }
        else
        {
            pHandle->m_pFile = NULL;
        }
#else
        pHandle->m_pFile = fopen(filename, mode);
#endif

        pHandle->m_pHttpServer = NULL;
        pHandle->m_bWebFile = false;

        if (pHandle->m_pFile == NULL)
        {
            closeFile(pHandle);
            pHandle = NULL;
        }
    }
    else
    {
        pHandle->m_pFile = NULL;
        pHandle->m_pHttpServer = new http;
        pHandle->m_bWebFile = true;

        if (proxy != NULL)
        {
            pHandle->m_pHttpServer->setProxy(proxy);
        }

        int res = pHandle->m_pHttpServer->request(http::GET, pHandle->m_strFileName);

        if (res != 200)
        {
            closeFile(pHandle);
            pHandle = NULL;
        }
    }

    return pHandle;
}
示例#3
0
Node Importer::applySceneImports(const std::string& scenePath, const std::string& resourceRoot) {

    std::string path;
    std::string fullPath = resourceRoot + scenePath;

    m_sceneQueue.push_back(fullPath);

    while (true) {
        {
            std::unique_lock<std::mutex> lock(sceneMutex);

            m_condition.wait(lock, [&, this]{
                    if (m_sceneQueue.empty()) {
                        // Not busy at all?
                        if (progressCounter == 0) { return true; }
                    } else {
                        // More work and not completely busy?
                        if (progressCounter < MAX_SCENE_DOWNLOAD) { return true; }
                    }

                    return false;
                });


            if (m_sceneQueue.empty()) {
                if (progressCounter == 0) {
                    break;
                }
                continue;
            }

            path = m_sceneQueue.back();
            m_sceneQueue.pop_back();

            if (m_scenes.find(path) != m_scenes.end()) { continue; }
        }

        // TODO: generic handling of uri
        if (isUrl(path)) {
            progressCounter++;
            startUrlRequest(path,
                    [&, p = path](std::vector<char>&& rawData) {

                    if (!rawData.empty()) {
                        std::unique_lock<std::mutex> lock(sceneMutex);
                        processScene(p, std::string(rawData.data(), rawData.size()));
                    }
                    progressCounter--;
                    m_condition.notify_all();
            });
        } else {
            std::unique_lock<std::mutex> lock(sceneMutex);
            processScene(path, getSceneString(path));
        }
    }

    auto root = importScenes(fullPath);

    return root;
}
示例#4
0
QList<QUrl> REventHandler::getUrlsFromMimeData(QMimeData* mimeData) {
    if (mimeData==NULL) {
        return QList<QUrl>();
    }

    QList<QUrl> urls;

    if (mimeData->hasFormat("text/uri-list")) {
        urls = mimeData->urls();
    }

    else if (mimeData->hasFormat("text/plain")) {
        QString text = mimeData->text();
        QUrl url(text);
        if (!url.isValid()) {
            return urls;
        }
        if (!isUrl(url.toString())) {
            return urls;
        }
        urls.append(url);
    }

    return urls;
}
示例#5
0
DLL_PUBLIC int statFile(const char *filename, LPDVDFILESTAT pFileStat, const char *proxy)
{
    memset(pFileStat, 0, sizeof(DVDFILESTAT));

    if (!isUrl(filename))
    {
        // Local files
#ifdef _WIN32
        struct _stat buf;
        wchar_t szUtf16Filename[MAX_PATH];
        if (utf8ToUtf16(szUtf16Filename, filename))
        {
            if (_wstat(szUtf16Filename, &buf) == -1)
            {
                return -1;
            }
        }
        else
        {
            return -1;
        }
#else
        struct stat buf;

        if (stat(filename, &buf) == -1)
        {
            return -1;
        }
#endif

        pFileStat->m_FileTime       = buf.st_mtime;
        pFileStat->m_qwFileSize     = buf.st_size;
        pFileStat->m_bIsDirectory   = S_ISDIR(buf.st_mode) ? true : false;
    }
    else
    {
        http httpserver;

        if (proxy != NULL)
        {
            httpserver.setProxy(proxy);
        }

        int res = httpserver.request(http::GET_HEADERSONLY, filename);

        if (res != 200)
        {
            return -1;
        }

        pFileStat->m_FileTime       = httpserver.getTimeStamp();
        pFileStat->m_qwFileSize     = httpserver.getContentSize();
    }

    return 0;
}
示例#6
0
std::string Importer::normalizePath(const std::string &_path,
                                    const std::string &_parentPath) {

    std::string path;

    // Check if absolute path or network url , return as it is
    if (_path[0] == '/' || isUrl(_path)) {
        path = _path;
    } else {
        auto r = std::regex("[^//]+$");
        path = std::regex_replace(_parentPath, r, _path);
    }

    LOGD("Normalize '%s', '%s' => '%s'", _parentPath.c_str(), _path.c_str(), path.c_str());

    return path;
}
示例#7
0
void PageApi::updateUrls()
{
	QString url;
	QString search = m_search.join(" ");
	m_errors.clear();

	// URL searches
	if (m_search.count() == 1 && !search.isEmpty() && isUrl(search))
	{ url = search; }
	else
	{
		PageUrl ret = m_api->pageUrl(search, m_page, m_imagesPerPage, m_lastPage, m_lastPageMinId, m_lastPageMaxId, m_site);
		if (!ret.error.isEmpty())
		{ m_errors.append(ret.error); }
		url = ret.url;
	}

	// Add site information to URL
	url = m_site->fixUrl(url).toString();

	m_originalUrl = QString(url);
	m_url = QString(url);
	m_urlRegex = QUrl(url);
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
void CPosLmGpxParser::OnAttributesL( 
    TPosXmlTagType aParent,
    const Xml::RAttributeArray& aAttributes )
    {
    switch ( aParent )
        {
        case EPosXmlRoot:
            {
            for ( TInt i = 0; i < aAttributes.Count(); ++i )
                {
                TPosXmlTagType attribute = AttributeTypeL( aParent, aAttributes[i].Attribute() );
                if ( attribute == EPosXmlVersion )
                    {
                    HBufC* value = PosLmConverterUtils::Utf8ToUnicodeLC( aAttributes[i].Value().DesC() );
                    SetContentL( EPosXmlVersion, *value );
                    CleanupStack::PopAndDestroy( value );
                    }
                }
            PosLmConverterUtils::AssertL( iGpxVersion > EGpxVersionUnknown );
            }
            break;
            
        case EPosXmlLandmark:
            {
            for ( TInt i = 0; i < aAttributes.Count(); ++i )
                {
                TPosXmlTagType attribute = AttributeTypeL( aParent, aAttributes[i].Attribute() );
                
                if ( attribute == EPosXmlCoordLatitude ||
                     attribute == EPosXmlCoordLongitude )
                    {
                    HBufC* value = PosLmConverterUtils::Utf8ToUnicodeLC( aAttributes[i].Value().DesC() );
                    SetContentL( attribute, *value );
                    CleanupStack::PopAndDestroy( value );
                    }
                }

            // both lat and lon must be present
            PosLmConverterUtils::AssertL( 
                !Math::IsNaN( iParsedLatitude ) && 
                !Math::IsNaN( iParsedLongitude ) );
            }
            break;
            
        case EPosXmlLmMediaLink:
            {
            TBool isUrl( EFalse );
            for ( TInt i = 0; i < aAttributes.Count(); ++i )
                {
                TPosXmlTagType attribute = AttributeTypeL( aParent, aAttributes[i].Attribute() );
                if ( attribute == EPosXmlMediaLinkUrl )
                    {
                    HBufC* value = PosLmConverterUtils::Utf8ToUnicodeLC( aAttributes[i].Value().DesC() );
                    SetContentL( EPosXmlMediaLinkUrl, *value );
                    CleanupStack::PopAndDestroy( value );
                    isUrl = ETrue;
                    }
                }
            PosLmConverterUtils::AssertL( isUrl );
            }
            break;
            
        default:
            break;
        }
    }
示例#9
0
void FunctionsTest::testIsUrl()
{
	// Valid URLs
	QCOMPARE(isUrl("http://foo.com/blah_blah"), true);
	QCOMPARE(isUrl("http://foo.com/blah_blah_(wikipedia)"), true);
	QCOMPARE(isUrl("http://foo.com/blah_(wikipedia)_blah#cite-1"), true);
	QCOMPARE(isUrl("http://foo.com/(something)?after=parens"), true);
	QCOMPARE(isUrl("http://1337.net"), true);
	QCOMPARE(isUrl("http://a.b-c.de"), true);
	QCOMPARE(isUrl("http://223.255.255.254"), true);

	// Invalid URLs
	QCOMPARE(isUrl("http://"), false);
	QCOMPARE(isUrl("http://."), false);
	QCOMPARE(isUrl("http://?"), false);
	QCOMPARE(isUrl("//"), false);
	QCOMPARE(isUrl("http:///a"), false);
	QCOMPARE(isUrl("foo.com"), false);
}
示例#10
0
文件: dcap_stream.c 项目: ic-hep/emi3
int dc_feof(FILE *fp)
{
	int     rc 	;
	struct vsp_node *node;

	node = get_vsp_node(FILE_NO(fp));
	if( node == NULL ) {
		return system_feof(fp);
	}

#if defined(__linux__) || defined(__GNU__) || defined(__FreeBSD_kernel__) || defined(__CYGWIN__)
	if ( ((FILE *)fp)->_flags & _IO_EOF_SEEN ) {
#else
	if ( ((FILE *)fp)->_flag & _IOEOF ) {
#endif
		rc = 1 ;
	}else {
		rc = 0 ;
	}

	m_unlock(&node->mux);
	return rc ;

}

FILE   *dc_fopen64(const char *file, const char *mode);

FILE   *dc_fopen(const char *file, const char *mode)
{
	return dc_fopen64(file, mode);
}

FILE   *dc_fopen64(const char *file, const char *mode)
{
	int fd, rw, oflags ;
	FILE *fp;

	if( isPnfs( file )  || isUrl(file) ) {

		rw= ( mode[1] == '+' ) ;
		switch(*mode) {
			case 'a':
				oflags= O_APPEND | O_CREAT | ( rw ? O_RDWR : O_WRONLY ) ;
				break ;
			case 'r':
				oflags= rw ? O_RDWR : O_RDONLY ;
				break ;
			case 'w':
				oflags= O_TRUNC | O_CREAT | ( rw ? O_RDWR : O_WRONLY ) ;
				break ;
			default:
				return NULL ;
		}


		fp = (FILE *)malloc( sizeof(FILE) );
		if( fp == NULL ) {
			return NULL;
		}

		/* break FILE chain */
	#if defined(__linux__) || defined(__GNU__) || defined(__FreeBSD_kernel__)
		fp->_chain = NULL;
		fp->_IO_write_ptr = NULL;
		fp->_IO_write_base = NULL;
		fp->_lock = NULL;
		fp->_flags = 0;
	#else
		fp->_flag = 0;
	#endif
		fd = dc_open(file,oflags, 0644) ;
		if ( fd < 0 ) {
			free(fp);
			return NULL ;
		}

		FILE_NO(fp) = fd;

	} else {
		dc_debug(DC_TRACE, "Running system native fopen [%s, %s]", file, mode);
		fp = system_fopen64( file, mode );
	}

	return fp;
}