Skip to content
This repository has been archived by the owner on Nov 19, 2022. It is now read-only.

Commit

Permalink
2005-11-02 Gonzalo Paniagua Javier <gonzalo@ximian.com>
Browse files Browse the repository at this point in the history
	* src/ModMonoWorkerRequest.cs:
	* src/ModMonoRequest.cs:
	* src/server.cs:
	* src/Mono.WebServer/ApplicationServer.cs:
	* src/ModMonoApplicationHost.cs: added support for dynamically created
	ASP.NET applications.

	* man/xsp.1.in: documented the --master option.


svn path=/trunk/xsp/; revision=52486
  • Loading branch information
gonzalop committed Nov 2, 2005
1 parent a6ae8b0 commit 18d7038
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 14 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
@@ -1,3 +1,14 @@
2005-11-02 Gonzalo Paniagua Javier <gonzalo@ximian.com>

* src/ModMonoWorkerRequest.cs:
* src/ModMonoRequest.cs:
* src/server.cs:
* src/Mono.WebServer/ApplicationServer.cs:
* src/ModMonoApplicationHost.cs: added support for dynamically created
ASP.NET applications.

* man/xsp.1.in: documented the --master option.

2005-10-21 Gonzalo Paniagua Javier <gonzalo@ximian.com>

* src/ModMonoWorkerRequest.cs:
Expand Down
6 changes: 6 additions & 0 deletions man/xsp.1.in
Expand Up @@ -89,6 +89,12 @@ Two applications like the above ones are handled.
.B myhost.someprovider.net:/blog:../myblog
The virtual /blog at myhost.someprovider.net is mapped to ../myblog.
.TP
.I \-\-master
.TP
This instance will be used to by mod_mono to create ASP.NET
applications on demand. If this option is provided, there is no
need to provide a list of applications to start.
This applies only to mod-mono-server.exe.
.I \-\-nonstop
This applies only to xsp.exe: by default xsp will stop processing
requests when the return key is pressed. Use this to avoid this
Expand Down
77 changes: 74 additions & 3 deletions src/ModMonoApplicationHost.cs
Expand Up @@ -243,6 +243,69 @@ public void Run (object state)
}
}

VPathToHost GetOrCreateApplication (string vhost, int port, string filepath, string virt)
{
VPathToHost vapp = null;
string vdir = Path.GetDirectoryName (virt);
string pdir = Path.GetDirectoryName (filepath);
DirectoryInfo vinfo = new DirectoryInfo (vdir);
DirectoryInfo pinfo = new DirectoryInfo (pdir);
string final_pdir = null;
string final_vdir = null;
while (vinfo != null && pinfo != null) {
if (final_pdir == null && CheckDirectory (pinfo)) {
final_pdir = pinfo.ToString ();
final_vdir = vinfo.ToString ();
break;
}

if (pinfo.Name != vinfo.Name) {
final_vdir = vinfo.ToString ();
break;
}

pinfo = pinfo.Parent;
vinfo = vinfo.Parent;
}

if (final_pdir == null) {
final_pdir = pinfo.ToString ();
}

if (final_vdir == null) {
final_vdir = vinfo.ToString ();
}


Console.Error.WriteLine ("final_pdir: {0} final_vdir: {1}", final_pdir, final_vdir);
vapp = server.GetApplicationForPath (vhost, port, virt, false);
if (vapp == null) {
final_pdir = "file://" + final_pdir;
if (final_vdir [0] != '/')
final_vdir = "/" + final_vdir;
server.AddApplication (vhost, port, final_vdir, final_pdir);
vapp = server.GetApplicationForPath (vhost, port, virt, false);
}

return vapp;
}

static bool CheckDirectory (DirectoryInfo info)
{
if (!info.Exists)
return false;

FileInfo [] g1 = info.GetFiles ("Global.asax");
if (g1.Length != 0)
return true;

g1 = info.GetFiles ("global.asax");
if (g1.Length != 0)
return true;

return (info.GetDirectories ("bin").Length != 0);
}

void InnerRun (object state)
{
requestId = -1;
Expand All @@ -266,10 +329,18 @@ void InnerRun (object state)
port = 80;
}
}

VPathToHost vapp = server.GetApplicationForPath (vhost, port, rr.GetUriPath (), false);

VPathToHost vapp = null;
string vpath = rr.GetUriPath ();
string path = rr.GetPhysicalPath ();
if (path == null) {
vapp = server.GetApplicationForPath (vhost, port, vpath, false);
} else {
vapp = GetOrCreateApplication (vhost, port, path, vpath);
}

if (vapp == null) {
rr.NotFound (); // No app to handle the request
rr.Decline ();
Stream.Close ();
Stream = null;
return;
Expand Down
9 changes: 9 additions & 0 deletions src/ModMonoRequest.cs
Expand Up @@ -83,6 +83,7 @@ public class ModMonoRequest
bool shutdown;
StringBuilder out_headers = new StringBuilder ();
bool headers_sent;
string physical_path;

public ModMonoRequest (NetworkStream ns)
{
Expand Down Expand Up @@ -125,6 +126,9 @@ void GetInitialData ()
string key = ReadString ();
headers [key] = ReadString ();
}

if (reader.ReadByte () != 0)
physical_path = ReadString ();
}

void SendSimpleCommand (Cmd cmd)
Expand Down Expand Up @@ -259,6 +263,11 @@ public string GetServerVariable (string name)
return (string) serverVariables [name];
}

public string GetPhysicalPath ()
{
return physical_path;
}

public string GetUri ()
{
return uri;
Expand Down
5 changes: 5 additions & 0 deletions src/ModMonoWorkerRequest.cs
Expand Up @@ -66,6 +66,11 @@ public string GetUriPath ()
return path;
}

public string GetPhysicalPath ()
{
return request.GetPhysicalPath ();
}

public void Decline ()
{
request.Decline ();
Expand Down
11 changes: 2 additions & 9 deletions src/Mono.WebServer/ApplicationServer.cs
Expand Up @@ -107,9 +107,6 @@ public ApplicationServer (IWebSource source)
public void AddApplication (string vhost, int vport, string vpath, string fullPath)
{
// TODO - check for duplicates, sort, optimize, etc.
if (started)
throw new InvalidOperationException ("The server is already started.");

if (verbose) {
Console.WriteLine("Registering application:");
Console.WriteLine(" Host: {0}", (vhost != null) ? vhost : "any");
Expand Down Expand Up @@ -255,9 +252,6 @@ public bool Start (bool bgThread)
if (vpathToHost == null)
throw new InvalidOperationException ("SetApplications must be called first.");

if (vpathToHost.Count == 0)
throw new InvalidOperationException ("No applications defined or all of them are disabled");

listen_socket = webSource.CreateSocket ();
listen_socket.Listen (500);
listen_socket.Blocking = false;
Expand Down Expand Up @@ -537,7 +531,7 @@ public class VPathToHost
public readonly string vhost;
public readonly int vport;
public readonly string vpath;
public readonly string realPath;
public string realPath;
public readonly bool haveWildcard;

public IApplicationHost AppHost;
Expand All @@ -554,7 +548,6 @@ public VPathToHost (string vhost, int vport, string vpath, string realPath)

this.realPath = realPath;
this.AppHost = null;

if (vhost != null && this.vhost.Length != 0 && this.vhost [0] == '*') {
haveWildcard = true;
if (this.vhost.Length > 2 && this.vhost [1] == '.')
Expand Down Expand Up @@ -641,7 +634,7 @@ public void CreateHost (ApplicationServer server, IWebSource webSource)
if (v != "/" && v.EndsWith ("/")) {
v = v.Substring (0, v.Length - 1);
}

AppHost = ApplicationHost.CreateApplicationHost (webSource.GetApplicationHostType(), v, realPath) as IApplicationHost;
AppHost.Server = server;

Expand Down
13 changes: 11 additions & 2 deletions src/server.cs
Expand Up @@ -171,6 +171,9 @@ static void ShowHelp ()
Console.WriteLine (" --terminate: gracefully terminates a running mod-mono-server instance.");
Console.WriteLine (" All other options but --filename or --address and --port");
Console.WriteLine (" are ignored if this option is provided.");
Console.WriteLine (" --master: this instance will be used to by mod_mono to create ASP.NET");
Console.WriteLine (" applications on demand. If this option is provided, there is no");
Console.WriteLine (" need to provide a list of applications to start.");
#endif
Console.WriteLine (" --nonstop: don't stop the server by pressing enter. Must be used");
Console.WriteLine (" when the server has no controlling terminal.");
Expand All @@ -193,7 +196,8 @@ enum Options {
Address = 1 << 7,
Port = 1 << 8,
Terminate = 1 << 9,
Https = 1 << 10
Https = 1 << 10,
Master = 1 << 11
}

static void CheckAndSetOptions (string name, Options value, ref Options options)
Expand Down Expand Up @@ -234,6 +238,7 @@ public static int Main (string [] args)
string rootDir = ConfigurationSettings.AppSettings ["MonoServerRootDir"];
object oport;
string ip = ConfigurationSettings.AppSettings ["MonoServerAddress"];
bool master = false;
#if MODMONO_SERVER
string filename = ConfigurationSettings.AppSettings ["MonoUnixSocket"];
#endif
Expand All @@ -259,6 +264,10 @@ public static int Main (string [] args)
case "--terminate":
CheckAndSetOptions (a, Options.Terminate, ref options);
break;
case "--master":
CheckAndSetOptions (a, Options.Master, ref options);
master = true;
break;
#else
case "--https":
CheckAndSetOptions (a, Options.Https, ref options);
Expand Down Expand Up @@ -434,7 +443,7 @@ public static int Main (string [] args)
if (appConfigDir != null)
server.AddApplicationsFromConfigDirectory (appConfigDir);

if (apps == null && appConfigDir == null && appConfigFile == null)
if (!master && apps == null && appConfigDir == null && appConfigFile == null)
server.AddApplicationsFromCommandLine ("/:.");
#if MODMONO_SERVER
if (!useTCP) {
Expand Down

0 comments on commit 18d7038

Please sign in to comment.