示例#1
0
int
MultiServer::wstat(ServerContext& s, const char *path, file_stat_t& fileStat, uint32_t mask)
{
	string subdir;
	FileServer *server = getServer(s, path, subdir);
	if (fileStat.fs_rename.length() > 0)
	{
		string newname;
		FileServer *server2 = getServer(s, fileStat.fs_rename.c_str(), newname);
		if (server2 && server == server2)
		{
			fileStat.fs_rename = newname;
		}
		else
		{
			return -EPERM;
		}
	}
	if (server && !server->readOnly(s))
	{
		return server->wstat(s, subdir.c_str(), fileStat, mask);
	}
	// MemoryServer::wstat(s, path, fileStat, mask));
	return -EPERM;
}
示例#2
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    FileServer fileserver;

    fileserver.showFullScreen();
    return app.exec();
}
示例#3
0
int
MultiServer::readLink(ServerContext& s, const char *path, std::string& linkpath)
{
	string subdir;
	FileServer *server = getServer(s, path, subdir);
	return (server
			? server->readLink(s, subdir.c_str(), linkpath)
			: MemoryServer::readLink(s, path, linkpath));
}
示例#4
0
int
MultiServer::rstat(ServerContext& s, const char *path, file_stat_t& fileStat)
{
	//TRACE();
	_DEBUG("rstat path = %s", path);
	string subdir;
	FileServer *server = getServer(s, path, subdir);
	return (server
			? server->rstat(s, subdir.c_str(), fileStat)
			: MemoryServer::rstat(s, path, fileStat));
}
示例#5
0
int
MultiServer::removeFile(ServerContext& s, const char *path)
{
	string subdir;
	FileServer *server = getServer(s, path, subdir);
	if (server && !server->readOnly(s))
	{
		return server->removeFile(s, subdir.c_str());
	}
	return -EPERM;
}
示例#6
0
int
MultiServer::createMlink(ServerContext& s, const char *path, const char *link)
{
	string subdir;
	FileServer *server = getServer(s, path, subdir);
	if (server && !server->readOnly(s))
	{
		return server->createMlink(s, subdir.c_str(), link);
	}
	return -EPERM;
}
示例#7
0
文件: Main.cpp 项目: giftnuss/sparrow
int main()
{
	try
	{
		FileServer app;
		app.Run();
		Environment::WaitForTermination();
	}
	catch(exception& e)
	{
		LOG(LogError)<<e.what();
	}
}
示例#8
0
int
MultiServer::createDir(ServerContext& s, const char *path, uint32_t mode)
{
	string subdir;
	FileServer *server = getServer(s, path, subdir);
	
	if (server && !server->readOnly(s))
	{
		return server->createDir(s, subdir.c_str(), mode);
	}
	// MemoryServer::wstat(s, path, fileStat, mask));
	return -EPERM;
}
示例#9
0
int
MultiServer::openFile(ServerContext& s, const char *path, void **handle, const char *flags, int mode)
{
	string subdir;
	FileServer *server = getServer(s, path, subdir);
	struct multi_handle *mh = new struct multi_handle;
	mh->handle = NULL;
	mh->path = subdir;
	mh->server = server;
	*handle = mh;
	return (server
			? server->openFile(s, subdir.c_str(), &mh->handle, flags, mode)
			: MemoryServer::openFile(s, path, &mh->handle, flags, mode));
}
示例#10
0
int
MultiServer::openDir(ServerContext& s, const char *path, void **handle)
{
	string subdir;
	FileServer *server = getServer(s, path, subdir);
	struct multi_handle *mh = new struct multi_handle;
	mh->handle = NULL;
	mh->path = subdir;
	mh->server = server;
	*handle = mh;
	_DEBUG("open_dir (%p) from %s to %s", server, path, subdir.c_str());
	return (server
			? server->openDir(s, subdir.c_str(), &mh->handle)
			: MemoryServer::openDir(s, path, &mh->handle));
}
示例#11
0
void
FileAction::unregisterActions(FileServer& server)
{
	ScopedMutex lock(&g_action_mutex);
	share_action_t::iterator it = g_share_actions.find(server.name());
	if (it != g_share_actions.end())
	{
		action_map_t::iterator iit = it->second.begin();
		for (; it->second.end() != iit; iit++)
		{
			delete iit->second;
			iit->second = NULL;
		}
		g_share_actions.erase(server.name());
	}
}
示例#12
0
void
FileAction::registerAction(FileServer& server, FileAction *action)
{
	ASSERT(action);
	ScopedMutex lock(&g_action_mutex);
	g_share_actions[server.name()][action->rule()] = action;
}
示例#13
0
// Owner Action methods
int
OwnerAction::onRead(ServerContext& ctxt, FileServer& server, const char *path, string& contents)
{
	string owner = server.getOwnerFile(ctxt, path);
	_DEBUG("checking :owner %s is %s and %d", owner.c_str(), ctxt.user(), ctxt.isOwner());
	contents = ctxt.user() == owner ? "1\n" : "0\n";
	return 2;
}
示例#14
0
// Public Action methods
int
PublicAction::onRead(ServerContext& ctxt, FileServer& server, const char *path, string& contents)
{
	string dir;
	dir_name(path, dir);
	dir += "/.inetfs_public";
	SingleFile file(ctxt, server, path);
	contents = (!server.isPrivate() || file.exists()) ? "1\n" : "0\n";
	return 2;
}
示例#15
0
 /*
  Either file size was sent and now we send the file,
  or the file was sent and we delete the connection
  */
 inline void FileServer::write_cb(struct bufferevent *bev, void *context) {
   try {
     auto u_ctx = static_cast<UploadContext*>(context);
     if(u_ctx->size_sent()) {
       LOG_DEBUG("File size was sent, sending file ");
       evbuffer_add_file(bufferevent_get_output(bev), u_ctx->fd(), 0,
                         u_ctx->file()->size());
       bufferevent_setwatermark(bev, EV_WRITE, 0, 0);
       u_ctx->size_sent(false);
       u_ctx->transfer_started(true);
       LOG_DEBUG("File transfer has started ");
     } else if(u_ctx->transfer_started()) {
       LOG_DEBUG("Transfer Completed");
       FileServer * server = static_cast<FileServer*>(u_ctx->reader());
       server->TransferDone(u_ctx);
     }
   } catch(std::exception& e) {
     LOG_ERR(e.what());
     delete static_cast<ConnectionContext*>(context);
     exit(EXIT_FAILURE);
   }
 }
示例#16
0
int
MultiServer::createHlink(ServerContext& s, const char *path, const char *link)
{
	string subdir;
	FileServer *server = getServer(s, path, subdir);
	if (link)
	{
		string lnk;
		FileServer *server2 = getServer(s, link, lnk);
		if (server2 && server == server2)
		{
			link = lnk.c_str();
		}
		else
		{
			return -EPERM;
		}
	}
	if (server && !server->readOnly(s))
	{
		return server->createHlink(s, subdir.c_str(), link);
	}
	return -EPERM;
}
示例#17
0
	virtual int onRead(ServerContext& ctxt, FileServer& server, const char *path, string& contents)
	{
		stringstream cmd;
		string_list_t list;
		const char *script = get_string(server.options(), "InfoScript", NULL);
		if (script == NULL)
		{
			return -EFAULT;
		}

		explode(path, "/", list);
		if (list.front().empty())
		{
			list.pop_front();
		}
		if (list.back() == ":info")
		{
			list.pop_back();
		}
		if (list.size() == 0)
		{
			return -EINVAL;
		}
		
		cmd << script;
		while (list.size() > 0)
		{
			cmd << " " << list.front();
			list.pop_front();
		}
		
		const char *prog = cmd.str().c_str();
		bool res = ::run_read_script(prog, contents);
		if (!res)
		{
			contents.clear();
			return -EIO;
		}

		return contents.length();
	}
示例#18
0
int main( int argc, char *argv[] )
{
#ifdef TEST_TCP_SOCKETS

  StartWinSock();

  TCPSocket listener;
  TCPSocket client;

  char *localIP = NULL;
  GetLocalIP( localIP );

  listener.SetIP( localIP );
  listener.SetPortNumber( 8000 );

  listener.Init();
  
  listener.Listen();

  while( !listener.Accept( client ) );
  
  while( true )
  {
    std::string message;
    Prompt( message, "Enter a message" );

    NetworkMessage netMessage;
    netMessage.msg_.Assign( message.c_str(), message.size() );

    client.Send( netMessage );
  }

  client.Shutdown();
  client.Close();

  listener.Shutdown();
  listener.Close();

  CloseWinSock();

#endif

  /*
  GameControl controller;

  try
  {
    controller.Init();

    try
    {
      controller.Run();
    }
    catch( BaseErrExcep e )
    {
      e.Print();
    }

    controller.Close();
  }
  catch( BaseErrExcep e )
  {
    e.Print();
  }
  */

    FileServer fileServer;

    try
    {
        fileServer.Init();

        try
        {
            fileServer.Run();
        }
        catch(BaseErrExcep& e)
        {
            e.Print();
        }

        fileServer.Close();
    }
    catch(BaseErrExcep& e)
    {
        e.Print();
    }
 
   
  printf( "\n Server is closing \n" );

  return WaitForInput();
}
示例#19
0
int main(int argc, char *argv[])
{
    bool deamonMode = true;
    bool verboseMode = false;
    int httpdPort = 80;

    int ch;
    while ((ch = getopt(argc, argv, "fhvp:")) != -1) {
        switch (ch) {
        case 'v':
            {
                verboseMode = true;
            }
            break;
        case 'f':
            {
                deamonMode = false;
            }
            break;
        case 'p':
            {
                httpdPort = atoi(optarg);
            }
            break;
        case 'h':
        case '?':
        default:
            {
                usage(argv);
                exit(EXIT_SUCCESS);
            }
        }
     }
    
    argc -= optind;
    argv += optind;

	if (argc < 1) {
		usage((argv-optind));
        return EXIT_FAILURE;
	}
    
    string roodDirectory = argv[0];
    if (roodDirectory.at(roodDirectory.length()-1) == '/') {
        roodDirectory = roodDirectory.substr(0, roodDirectory.length()-1);
    }
    
    if (deamonMode) {
        int pid = fork();
        if (pid < 0)
            exit(EXIT_FAILURE);
    
        if (0 < pid)
            exit(EXIT_SUCCESS);
 
        if (setsid() < 0)
            exit(EXIT_FAILURE);

        umask(0);
    
        close(STDIN_FILENO);
        close(STDOUT_FILENO);
        close(STDERR_FILENO);
    }
 
    FileServer fileServer;
    fileServer.setRootDirectory(roodDirectory);
    fileServer.setPort(httpdPort);
    if (fileServer.start() == false) {
        exit(EXIT_FAILURE);
    }
    
    sigset_t sigSet;
    if (sigfillset(&sigSet) != 0)
        exit(EXIT_FAILURE);

    bool isRunnging = true;
    
    while (isRunnging) {
        int sigNo;
        if (sigwait(&sigSet, &sigNo) != 0)
            break;
        switch (sigNo) {
        case SIGTERM:
        case SIGINT:
        case SIGKILL:
            {
                fileServer.stop();
                isRunnging = false;
            }
            break;
        case SIGHUP:
            {
                if (fileServer.restart() == false) {
                    exit(EXIT_FAILURE);
                }
            }
            break;
        }
    }
        
	return EXIT_SUCCESS;
}