2
This code is derived from jgit (http://eclipse.org/jgit).
3
Copyright owners are documented in jgit's IP log.
5
This program and the accompanying materials are made available
6
under the terms of the Eclipse Distribution License v1.0 which
7
accompanies this distribution, is reproduced below, and is
8
available at http://www.eclipse.org/org/documents/edl-v10.php
12
Redistribution and use in source and binary forms, with or
13
without modification, are permitted provided that the following
16
- Redistributions of source code must retain the above copyright
17
notice, this list of conditions and the following disclaimer.
19
- Redistributions in binary form must reproduce the above
20
copyright notice, this list of conditions and the following
21
disclaimer in the documentation and/or other materials provided
22
with the distribution.
24
- Neither the name of the Eclipse Foundation, Inc. nor the
25
names of its contributors may be used to endorse or promote
26
products derived from this software without specific prior
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48
namespace NGit.Transport
51
/// A service exposed by
52
/// <see cref="Daemon">Daemon</see>
53
/// over anonymous <code>git://</code>.
55
public abstract class DaemonService
57
private readonly string command;
59
private readonly Config.SectionParser<DaemonService.ServiceConfig> configKey;
63
private bool overridable;
65
internal DaemonService(string cmdName, string cfgName)
67
command = cmdName.StartsWith("git-") ? cmdName : "git-" + cmdName;
68
configKey = new _SectionParser_67(this, cfgName);
72
private sealed class _SectionParser_67 : Config.SectionParser<DaemonService.ServiceConfig
75
public _SectionParser_67(DaemonService _enclosing, string cfgName)
77
this._enclosing = _enclosing;
78
this.cfgName = cfgName;
81
public DaemonService.ServiceConfig Parse(Config cfg)
83
return new DaemonService.ServiceConfig(this._enclosing, cfg, cfgName);
86
private readonly DaemonService _enclosing;
88
private readonly string cfgName;
91
private class ServiceConfig
93
internal readonly bool enabled;
95
internal ServiceConfig(DaemonService service, Config cfg, string name)
97
enabled = cfg.GetBoolean("daemon", name, service.IsEnabled());
101
/// <returns>is this service enabled for invocation?</returns>
102
public virtual bool IsEnabled()
107
/// <param name="on">true to allow this service to be used; false to deny it.</param>
108
public virtual void SetEnabled(bool on)
113
/// <returns>can this service be configured in the repository config file?</returns>
114
public virtual bool IsOverridable()
119
/// <param name="on">
120
/// true to permit repositories to override this service's enabled
121
/// state with the <code>daemon.servicename</code> config setting.
123
public virtual void SetOverridable(bool on)
128
/// <returns>name of the command requested by clients.</returns>
129
public virtual string GetCommandName()
134
/// <summary>Determine if this service can handle the requested command.</summary>
135
/// <remarks>Determine if this service can handle the requested command.</remarks>
136
/// <param name="commandLine">input line from the client.</param>
137
/// <returns>true if this command can accept the given command line.</returns>
138
public virtual bool Handles(string commandLine)
140
return command.Length + 1 < commandLine.Length && commandLine[command.Length] ==
141
' ' && commandLine.StartsWith(command);
144
/// <exception cref="System.IO.IOException"></exception>
145
/// <exception cref="NGit.Transport.Resolver.ServiceNotEnabledException"></exception>
146
/// <exception cref="NGit.Transport.Resolver.ServiceNotAuthorizedException"></exception>
147
internal virtual void Execute(DaemonClient client, string commandLine)
149
string name = Sharpen.Runtime.Substring(commandLine, command.Length + 1);
150
Repository db = client.GetDaemon().OpenRepository(client, name);
157
if (IsEnabledFor(db))
168
private bool IsEnabledFor(Repository db)
172
return db.GetConfig().Get(configKey).enabled;
177
/// <exception cref="System.IO.IOException"></exception>
178
/// <exception cref="NGit.Transport.Resolver.ServiceNotEnabledException"></exception>
179
/// <exception cref="NGit.Transport.Resolver.ServiceNotAuthorizedException"></exception>
180
internal abstract void Execute(DaemonClient client, Repository db);