/** * Lookup a supported service so it can be reconfigured. * @param name name of the service; e.g. "receive-pack"/"git-receive-pack" or * "upload-pack"/"git-upload-pack". * @return the service; null if this daemon implementation doesn't support * the requested service type. */ public synchronized DaemonService getService( String name ) { if ( !name.startsWith( "git-" ) ) { name = "git-" + name; } for ( final DaemonService s : services ) { if ( s.getCommandName().equals( name ) ) { return s; } } return null; }
synchronized DaemonService matchService( final String cmd ) { for ( final DaemonService d : services ) { if ( d.handles( cmd ) ) { return d; } } return null; }
private boolean isEnabledFor( final Repository db ) { if ( isOverridable() ) { return db.getConfig().get( configKey ).enabled; } return isEnabled(); }
void execute( final DaemonClient client, final String commandLine ) throws IOException, ServiceNotEnabledException, ServiceNotAuthorizedException { final String name = commandLine.substring( command.length() + 1 ); Repository db; try { db = client.getDaemon().openRepository( client, name ); } catch ( ServiceMayNotContinueException e ) { // An error when opening the repo means the client is expecting a ref // advertisement, so use that style of error. PacketLineOut pktOut = new PacketLineOut( client.getOutputStream() ); pktOut.writeString( "ERR " + e.getMessage() + "\n" ); db = null; } if ( db == null ) { return; } try { if ( isEnabledFor( db ) ) { execute( client, db ); } } finally { db.close(); } }
ServiceConfig( final DaemonService service, final Config cfg, final String name ) { enabled = cfg.getBoolean( "daemon", name, service.isEnabled() ); } }
void execute( final Socket sock ) throws IOException, ServiceNotEnabledException, ServiceNotAuthorizedException { rawIn = new BufferedInputStream( sock.getInputStream() ); rawOut = new SafeBufferedOutputStream( sock.getOutputStream() ); if ( 0 < daemon.getTimeout() ) { sock.setSoTimeout( daemon.getTimeout() * 1000 ); } String cmd = new PacketLineIn( rawIn ).readStringRaw(); final int nul = cmd.indexOf( '\0' ); if ( nul >= 0 ) { // Newer clients hide a "host" header behind this byte. // Currently we don't use it for anything, so we ignore // this portion of the command. // cmd = cmd.substring( 0, nul ); } final DaemonService srv = getDaemon().matchService( cmd ); if ( srv == null ) { return; } sock.setSoTimeout( 0 ); srv.execute( this, cmd ); } }
private void buildAndStartDaemon() { daemonService = new Daemon( new InetSocketAddress( DAEMON_HOST, DAEMON_PORT ) ); daemonService.getService( "git-receive-pack" ).setEnabled( DAEMON_UPLOAD ); daemonService.setRepositoryResolver( new RepositoryResolverImpl() ); daemonService.setReceivePackFactory( new ReceivePackFactory<DaemonClient>() {