Fixed all compile errors within client.d

This commit is contained in:
Tristan B. Kildaire 2020-07-27 14:56:36 +02:00
parent 1d50c30e29
commit 785113e5f8
5 changed files with 40 additions and 17 deletions

View File

@ -26,9 +26,11 @@ void main()
/* Construct the listeners form the config file */
ButterflyListener[] listeners = constructListeners(config["listeners"]);
/* Start the server */
//Address address = parseAddress(config["address"].str(), to!(ushort)(config["port"].str()));
/* Create the server */
ButterflyServer server = new ButterflyServer(listeners);
/* Start the server */
server.run();
}
private ButterflyListener[] constructListeners(JSONValue listenersBlock)

View File

@ -13,13 +13,14 @@ import client.exceptions;
import std.file;
import std.exception;
import std.datetime.systime : Clock, SysTime;
import server.listener : ButterflyListener;
public final class ButterflyClient : Thread
{
/**
* The associated server
* The associated listener
*/
private ButterflyServer server;
private ButterflyListener listener;
/**
* Socket of the client connection
@ -48,11 +49,11 @@ public final class ButterflyClient : Thread
*/
private Mailbox mailbox;
this(ButterflyServer server, Socket clientSocket)
this(ButterflyListener listener, Socket clientSocket)
{
super(&run);
this.clientSocket = clientSocket;
this.server = server;
this.listener = listener;
}
private void run()
@ -490,7 +491,7 @@ public final class ButterflyClient : Thread
* Check if the domain of this recipient is this server
* or if it is a remote server.
*/
if(cmp(domain, server.domain) == 0)
if(cmp(domain, listener.getDomain()) == 0)
{
writeln("Storing mail message to "~recipient~" ...");
@ -518,7 +519,7 @@ public final class ButterflyClient : Thread
private bool filterMailOutgoing(JSONValue* mailBlock)
{
/* Add the from field to the mail block */
(*mailBlock)["from"] = mailbox.username~"@"~server.domain;
(*mailBlock)["from"] = mailbox.username~"@"~listener.getDomain();
/* Add the sent time stamp */
(*mailBlock)["sentTimestamp"] = Clock.currTime().toString();
@ -574,7 +575,7 @@ public final class ButterflyClient : Thread
* Check if the domain of this recipient is this server
* or if it is a remote server.
*/
if(server.isLocalDomain(domain))
if(listener.getServer().isLocalDomain(domain))
{
writeln("Local delivery occurring...");
@ -688,7 +689,7 @@ public final class ButterflyClient : Thread
{
/* Create the error message */
JSONValue deliveryReport;
JSONValue[] errorRecipients = [JSONValue(mailbox.username~"@"~server.domain)];
JSONValue[] errorRecipients = [JSONValue(mailbox.username~"@"~listener.getDomain())];
deliveryReport["recipients"] = errorRecipients;
/* TODO: Make more indepth, and have copy of the mail that was tried to be sent */

View File

@ -19,16 +19,18 @@ public abstract class ButterflyListener : Thread
this.domain = domain;
}
public abstract void run()
{
}
public abstract void run();
public void setServer(ButterflyServer server)
{
this.server = server;
}
public ButterflyServer getServer()
{
return server;
}
public string getName()
{
return listenerName;

View File

@ -4,6 +4,7 @@ import core.thread : Thread;
import server.listener : ButterflyListener;
import std.socket : Socket, Address, SocketType, ProtocolType;
import std.json : JSONValue;
import client.client;
public class IPv4Listener : ButterflyListener
{
@ -27,6 +28,18 @@ public class IPv4Listener : ButterflyListener
public override void run()
{
serverSocket.listen(1); //TODO: backlog
while(true)
{
/* Accept the queued connection */
Socket clientConnection = serverSocket.accept();
ButterflyClient client = new ButterflyClient();
/* Start the client handler */
butterflyClient.start();
}
}
}

View File

@ -37,8 +37,13 @@ public final class ButterflyServer
*/
this.listeners = listeners;
/* Start accepting connections */
run();
/**
* Set the server of all listeners to this server
*/
foreach(ButterflyListener listener; listeners)
{
listener.setServer(this);
}
}
private void directoryCheck()
@ -84,7 +89,7 @@ public final class ButterflyServer
}
}
private void run()
public void run()
{
/* Start the listeners */
foreach(ButterflyListener listener; listeners)