james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anagha Mudigonda <anaghamudigo...@yahoo.com>
Subject suggestions to http://wiki.apache.org/james/FastFail
Date Wed, 15 Jun 2005 16:57:55 GMT
Danny and Noel,

I would like to contribute in arriving at a
lightweight in-protocol
framework that is *reasonably* extensible and
configurable. I tweaked
the interfaces little bit and there are two major
deviations from the
proposals put forth at
http://wiki.apache.org/james/FastFail. 

1. Response interface is dropped as it is making the
design less
flexible apart from adding up configuration
complexity. Moreover the
Response object should also indicate if the session
should be 
terminated
or not.
2. There is no separate MessageHandler interface
because message is not
an independent entity and is always associate with a
command. Hence the
message processing is included as a method (onMessage)
in 
CommandHandler
class itself.

Here are the framework classes and config.xml from my
second iteration
and I am not completely convinced yet. Am thinking
coding a simple
command-line app emulating SMTP commands to evaluate
the extensiblility
of the interfaces.

Class design
------------

The framework consists of 3 core interfaces -
ProtocolHandler,
CommandHandler and Rule.
ProtocolHandler: delegates the command and message
processing to
appropriate command handlers. Also ensures that all
the configured 
rules
are applied. Protocol handler maintains the state of
the protocol
session. Example: SMTPHandler

CommandHandler: the actual command and message
processing is done here.
The command provides methods to access command
arguments and message.
These access methods are used by Rule objects.

Rule: Rules can be applied as soon as the client
initiates connection.
These are known as connection rules. The Command rules
are applied
before processing command after. The Message rules
that are applied
after message is processed and before accepting for
delivery.


details 
-------

A set of framework classes placed under a new package
org.apache.james.protocol

ProtocolHandler {
    //configure and add command
    void addCommand(Command cmdHandler);

    //configure and rules
    void addRule(Rule rule);
    void addRule(Rule rule, Command cmdHandler);

    //get rules
    Rules[] getConnectionRules();
    Rules[] getCommandRules(Command cmdHamdler);
    Rules[] getMessageRules(Command cmdHandler);

    //get all the registered command handlers
    CommandHandler[] getCommandHandlers();

    //state info
    boolean isCommandAllowed(String cmdName);
    void SetCommandStatus(String cmdName, boolean
status);
    CommandHandler getCurrentCommandHandler()

    //access function used by command and message
processing
    InputStream getInputStream();
    InputStream getOutputStream();
    String nextCommand();
}    


public interface CommandHandler {
    configure(...);//
    void onCommand(String cmdStr); //for command
processing
    boolean waitForMessage(); //if message is expected
for the command
    void onMessage(); //for message processing
    byte[] getMessage(); //return message buffer

    String getName(); //get command Name
    String getArgument(); //return the arguments for
the command
    void setProtocolHandler(ProtocolHandler handler);
// to access to
I/O and state 
    boolean equals(String cmdString);//to check if the
command string
can be processed by the handler
}

public interface Rule {
    public final type; // 3 types rules as mentioned
    void apply() throws Exception;//continue session
if there is no
exception
    configure(..); //configure the rule 
}


Configuration
-------------
Here is a sample configuration (config.xml) that shows
how command
handlers and various rules can configured.

<Protocol name= "SMTP"
class="org.apache.james.smtp.SMTPHandler">

<!-DNS black lists and white lists
<Rule name="DNSRBL" type=connection class =
"org.apache.james.smtp.DNSRBLRule">
config..
</Rule>

<!-the RCPT command has no associated message -->
<commandHandler name="RCPT"
class="org.apache.james.smtp.MailHandler">
<rule name="Recepients" type="command"
class=""org.apache.james.smtp.RecepientRule" > 
config..
</rule>
<rule name="userQuota" type="command"
class=""org.apache.james.smtp.userQuotoRule" > 
config..
</rule>
</commandHandler>

<!-the DATA command and associated message rules -->
<commandHandler name="DATA"
class=="org.apache.james.smtp.DATAHandler">
<rule name="SpamRule" type="message"
class=""org.apache.james.smtp.SpamRule" > 
config..
</rule>
<rule name="MessageSize" type="message"
class=""org.apache.james.smtp.MessageSizeRule" > 
config..
</rule>
<rule name="your custom handlers" type="message"
class=""MYCustomRule" 
>

config..
</rule>
</commandHandler>

</protocol>


SMTPHandler implementation example
----------------------------------
SMTPHandler implements the ProtocolHandler interface.

///initialization steps
read config.xml
create and configure command objects
create and configure connection rules
create and configure command and message rules

////processing commands and messages
//get all connection rules and apply
Rules[] connectionRules = getConnectionRules();
for(int i = 0;  i < connectionRules.length; i++) {
    connectionRules[i].apply();
}

while(true) {
    //Get matching command handler
    cmdString = nextComand();
    Command[] commands = getCommands();
    Command currCmd = null;
    for(int i = 0; i < commands.length; i++)
    {
        if(commands[i].equals(cmdString))
        {
            currCmd = commands[i];
            break;
        }
    }
    //handle command and message
    if(currCmd == null) //command not supported
    else {
        //apply command rules
        Rules[] commandRules =
getCommandRules(currCmd);
        for(int i = 0; i < commandRules.length; i++) {
            commandRules[i].apply();
        }
                     
        currCmd.onCommand(); //process command
        //if there is no associate message stop
        if(!currCmd.waitForMessage()) continue;
        //else process message
        currCmd.onMessage();
              
        //apply message rules
        Rules[] msgRules = getMessageRules(currCmd);
        for(int i = 0; i < msgRules.length; i++) {
            msgRulesRules[i].apply();
        }
    }





		
__________________________________ 
Discover Yahoo! 
Find restaurants, movies, travel and more fun for the weekend. Check it out! 
http://discover.yahoo.com/weekend.html 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message