DataPromisePtr DirectorySharingPromise::data (const Path & subPath, const String & user) const {
	if (sf::checkDangerousPath(subPath.toString())) {
		Log (LogWarning) << LOGID << subPath << " looks dangerous, rejecting" << std::endl;
	}
	
	if (user.empty()){
		// Check if it is a directory
		DataPromisePtr tryDirectory = directoryListing (subPath);
		if (tryDirectory) return tryDirectory;

	
		// It must be a file
		return subFile (subPath);
	}
	if (user == "list"){
		return directoryListing (subPath);
	}
	if (user == "file"){
		return subFile (subPath);
	}
	if (user == "glob") {
		return DataPromisePtr (new GlobPromise (mGlobber, osPath (subPath)));
	}
	// unknown user flag
	Log (LogWarning) << LOGID << "Unknown user flag: " << user << std::endl;
	return DataPromisePtr ();
}
Exemplo n.º 2
0
bool LsColJob::finished()
{
    if (reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 207) {
        // Parse DAV response
        QXmlStreamReader reader(reply());
        reader.addExtraNamespaceDeclaration(QXmlStreamNamespaceDeclaration("d", "DAV:"));

        QStringList folders;
        QString currentItem;

        while (!reader.atEnd()) {
            QXmlStreamReader::TokenType type = reader.readNext();
            if (type == QXmlStreamReader::StartElement &&
                    reader.namespaceUri() == QLatin1String("DAV:")) {
                QString name = reader.name().toString();
                if (name == QLatin1String("href")) {
                    currentItem = reader.readElementText();
                } else if (name == QLatin1String("collection") &&
                           !currentItem.isEmpty()) {
                    folders.append(QUrl::fromEncoded(currentItem.toLatin1()).path());
                    currentItem.clear();
                }
            }
        }
        emit directoryListing(folders);
    }
    return true;
}
Exemplo n.º 3
0
void SelectiveSyncTreeView::refreshFolders()
{
    LsColJob *job = new LsColJob(_account, _folderPath, this);
    connect(job, SIGNAL(directoryListing(QStringList)),
            this, SLOT(slotUpdateDirectories(QStringList)));
    job->start();
    clear();
    _loading->show();
    _loading->move(10,10);
}
Exemplo n.º 4
0
void processResponse(int fd, char* protocol, char* filePath, int code, char* fileType, int dir)
{
	
	write(fd, "HTTP/1.0 ", 9);
	
	if (code == 200)
	{
	
		write(fd, "200 Document follows", 20);
		
	}
	else if (code == 404)
	{
	
		write(fd, "404 File Not Found", 18);
		
	}
	
	write(fd, "\r\n", 2); 
	
	write(fd, "Server: CS 252 lab5\r\n", 21);
	
	write(fd, "Content-type: ", 14);
	
	switch (fileType[0])
	{
	
		case 'g': write(fd, "image/gif", 9);
			break;
			
		case 'j': write(fd, "image/jpeg", 10);
			break;
			
		case 't': write(fd, "text/plain", 10);
			break;
			
		case 'h': write(fd, "text/html", 9);
			break;
			
		case 'i': write(fd, "image/x-icon", 12);
			break;
		
		default: if(!dir) write(fd, "text/plain", 10);
			break;
			
	}
	
	write(fd, "\r\n", 2);
	
	write(fd, "\r\n", 2);
	
	if (code == 200)
	{
	
		if (dir == 0)
		{
		
			char* buffer = (char*)malloc(sizeof(char)*128);
			
			FILE* in = fopen(filePath, "rb");
			
			int n = 0;
			
			while (n = fread(buffer, sizeof(char), 128, in))
			{
				
				if (n < 1)
				
					break;
					
				write(fd, buffer, n);
				
				if (n < 128)
				
					break;
			
			}
			
			free(buffer);
			
			fclose(in);
			
		}
		else
		{
		
			directoryListing(filePath, fd);
			
		}
		
	}
	else if (code == 404)
	{
	
		write(fd, "File could not be found!", 24);
		
	}
		
}