pgoldstein 2002/08/18 00:30:18
Modified: src/java/org/apache/james/nntpserver ArticleWriter.java
AuthService.java AuthServiceImpl.java
LISTGroup.java NNTPHandler.java NNTPServer.java
src/java/org/apache/james/nntpserver/repository
ArticleIDRepository.java NNTPRepositoryImpl.java
NNTPSpooler.java
Log:
Added comments, adjusted spacing.
Revision Changes Path
1.4 +1 -1
jakarta-james/src/java/org/apache/james/nntpserver/ArticleWriter.java
Index: ArticleWriter.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/ArticleWriter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ArticleWriter.java 18 Jan 2002 02:48:36 -0000 1.3
+++ ArticleWriter.java 18 Aug 2002 07:30:17 -0000 1.4
@@ -14,7 +14,7 @@
/**
* used by ARTICLE, HEAD, BODY, STAT command.
- * these commands are identical except in the writing the Article header
+ * these commands are identical except in how they write the Article header
* and body to the response stream
* ARTICLE - writes header and body
* HEAD - writes headers
1.3 +28 -1
jakarta-james/src/java/org/apache/james/nntpserver/AuthService.java
Index: AuthService.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/AuthService.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AuthService.java 3 Jun 2002 16:07:06 -0000 1.2
+++ AuthService.java 18 Aug 2002 07:30:17 -0000 1.3
@@ -8,16 +8,43 @@
package org.apache.james.nntpserver;
/**
- * Authenticates users and
+ * Authenticates users and provides
* Access Control for User Commands.
*
* @author Harmeet <[EMAIL PROTECTED]>
*/
public interface AuthService {
+
+ /**
+ * The component role used by components implementing this service
+ */
String ROLE = "org.apache.james.nntpserver.AuthService";
+ /**
+ * Check whether the service is authenticated
+ *
+ * @return true if the user and password have been set and are valid, false
otherwise
+ */
boolean isAuthenticated();
+
+ /**
+ * Set the user id for this service
+ *
+ * @param userid the user id for this AuthService
+ */
void setUser(String userid);
+
+ /**
+ * Set the password for this service
+ *
+ * @param password the password for this AuthService
+ */
void setPassword(String password);
+
+ /**
+ * Check whether the service is authenticated
+ *
+ * @return true if the user is authenticated and is authorized to execute this
command
+ */
boolean isAuthorized(String command);
}
1.5 +15 -0
jakarta-james/src/java/org/apache/james/nntpserver/AuthServiceImpl.java
Index: AuthServiceImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/AuthServiceImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AuthServiceImpl.java 7 Aug 2002 23:37:02 -0000 1.4
+++ AuthServiceImpl.java 18 Aug 2002 07:30:17 -0000 1.5
@@ -52,6 +52,15 @@
return allowed;
}
+ /**
+ * Pass the <code>ComponentManager</code> to the <code>composer</code>.
+ * The instance uses the specified <code>ComponentManager</code> to
+ * acquire the components it needs for execution.
+ *
+ * @param componentManager The <code>ComponentManager</code> which this
+ * <code>Composable</code> uses.
+ * @throws ComponentException if an error occurs
+ */
public void compose( final ComponentManager componentManager )
throws ComponentException
{
@@ -59,6 +68,12 @@
repo = usersStore.getRepository("LocalUsers");
}
+ /**
+ * Pass the <code>Configuration</code> to the instance.
+ *
+ * @param configuration the class configurations.
+ * @throws ConfigurationException if an error occurs
+ */
public void configure( Configuration configuration ) throws
ConfigurationException {
authRequired =
configuration.getChild("authRequired").getValueAsBoolean(false);
1.5 +3 -0
jakarta-james/src/java/org/apache/james/nntpserver/LISTGroup.java
Index: LISTGroup.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/LISTGroup.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LISTGroup.java 7 Aug 2002 23:37:02 -0000 1.4
+++ LISTGroup.java 18 Aug 2002 07:30:17 -0000 1.5
@@ -19,7 +19,9 @@
* @author Harmeet Bedi <[EMAIL PROTECTED]>
*/
interface LISTGroup {
+
void show(NNTPGroup group);
+
class Factory {
static LISTGroup ACTIVE(final PrintWriter prt) {
return new LISTGroup() {
@@ -37,6 +39,7 @@
}
};
}
+
static LISTGroup NEWSGROUPS(final PrintWriter prt) {
return new LISTGroup() {
public void show(NNTPGroup group) {
1.15 +58 -11
jakarta-james/src/java/org/apache/james/nntpserver/NNTPHandler.java
Index: NNTPHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/NNTPHandler.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- NNTPHandler.java 9 Aug 2002 06:44:31 -0000 1.14
+++ NNTPHandler.java 18 Aug 2002 07:30:17 -0000 1.15
@@ -65,6 +65,15 @@
private static final boolean DEBUG_PROTOCOL =
Boolean.getBoolean("apache.nntpserver.debug");
+ /**
+ * Pass the <code>ComponentManager</code> to the <code>composer</code>.
+ * The instance uses the specified <code>ComponentManager</code> to
+ * acquire the components it needs for execution.
+ *
+ * @param componentManager The <code>ComponentManager</code> which this
+ * <code>Composable</code> uses.
+ * @throws ComponentException if an error occurs
+ */
public void compose( final ComponentManager componentManager )
throws ComponentException
{
@@ -170,6 +179,18 @@
} catch (IOException e) { }
}
+ /**
+ * This method parses NNTP commands read off the wire in handleConnection.
+ * Actual processing of the command (possibly including additional back and
+ * forth communication with the client) is delegated to one of a number of
+ * command specific handler methods. The primary purpose of this method is
+ * to parse the raw command string to determine exactly which handler should
+ * be called. It returns true if expecting additional commands, false
otherwise.
+ *
+ * @param commandRaw the raw command string passed in over the socket
+ *
+ * @return whether additional commands are expected.
+ */
private boolean parseCommand(String commandRaw) {
if (commandRaw == null) {
return false;
@@ -254,10 +275,12 @@
writer.println("381 More authentication information required");
} else if ( command.equals("PASS") ) {
auth.setPassword(tok.nextToken());
- if ( auth.isAuthenticated() )
+ if ( auth.isAuthenticated() ) {
writer.println("281 Authentication accepted");
- else
+ }
+ else {
writer.println("482 Authentication rejected");
+ }
}
}
@@ -304,7 +327,7 @@
// returns the date from @param input.
// The input tokens are assumed to be in format date time [GMT|UTC] .
// 'date' is in format [XX]YYMMDD. 'time' is in format 'HHMMSS'
- // NOTE: This routine would do with some format checks.
+ // NOTE: This routine could do with some format checks.
private Date getDateFrom(StringTokenizer tok) {
String date = tok.nextToken();
String time = tok.nextToken();
@@ -345,6 +368,7 @@
public static final SimplifiedDateFormat DF_RFC2980 = new RFC2980DateFormat();
public static final long UTC_OFFSET =
Calendar.getInstance().get(Calendar.ZONE_OFFSET);
+
private void doDATE() {
//Calendar c = Calendar.getInstance();
//long UTC_OFFSET = c.get(c.ZONE_OFFSET) + c.get(c.DST_OFFSET);
@@ -352,9 +376,11 @@
String dtStr = DF_RFC2980.format(new Date(dt.getTime() - UTC_OFFSET));
writer.println("111 "+dtStr);
}
+
private void doQUIT() {
writer.println("205 closing connection");
}
+
private void doLIST(StringTokenizer tok) {
// see section 9.4.1
String wildmat = "*";
@@ -363,28 +389,34 @@
String param = tok.nextToken().toUpperCase(Locale.US);
// list of variations not supported - 9.4.2.1, 9.4.3.1, 9.4.4.1
String[] notSupported = { "ACTIVE.TIMES", "DISTRIBUTIONS",
"DISTRIB.PATS" };
+ // TODO: I don't understand what this loop is trying to accomplish --
PMG
for ( int i = 0 ; i < notSupported.length ; i++ ) {
if ( param.equals("ACTIVE.TIMES") ) {
writer.println("503 program error, function not performed");
return;
}
}
- if ( param.equals("NEWSGROUPS") )
+ if ( param.equals("NEWSGROUPS") ) {
output = LISTGroup.Factory.NEWSGROUPS(writer);
- else
+ }
+ else {
check(param,param.equals("ACTIVE"));
- if ( tok.hasMoreTokens() )
+ }
+ if ( tok.hasMoreTokens() ) {
wildmat = tok.nextToken();
+ }
}
Iterator iter = repo.getMatchedGroups(wildmat);
writer.println("215 list of newsgroups follows");
- while ( iter.hasNext() )
+ while ( iter.hasNext() ) {
output.show((NNTPGroup)iter.next());
+ }
writer.println(".");
}
private void check(String id,boolean b) {
- if ( b == false )
+ if ( b == false ) {
throw new RuntimeException(id);
+ }
}
private void doIHAVE(String id) {
// see section 9.3.2.1
@@ -398,27 +430,34 @@
writer.println("235 article received ok");
}
}
+
private void doPOST() {
// see section 9.3.1.1
writer.println("340 send article to be posted. End with <CR-LF>.<CR-LF>");
createArticle();
writer.println("240 article received ok");
}
+
private void createArticle() {
repo.createArticle(new NNTPLineReaderImpl(reader));
}
+
private void doSTAT(String param) {
doARTICLE(param,ArticleWriter.Factory.STAT(writer));
}
+
private void doBODY(String param) {
doARTICLE(param,ArticleWriter.Factory.BODY(writer));
}
+
private void doHEAD(String param) {
doARTICLE(param,ArticleWriter.Factory.HEAD(writer));
}
+
private void doARTICLE(String param) {
doARTICLE(param,ArticleWriter.Factory.ARTICLE(writer));
}
+
private void doARTICLE(String param,ArticleWriter articleWriter) {
// section 9.2.1
NNTPArticle article = null;
@@ -464,6 +503,7 @@
if ( article != null )
articleWriter.write(article);
}
+
private void doNEXT() {
// section 9.1.1.3.1
if ( group == null )
@@ -484,6 +524,7 @@
writer.println(respBuffer.toString());
}
}
+
private void doLAST() {
// section 9.1.1.2.1
if ( group == null )
@@ -504,6 +545,7 @@
writer.println(respBuffer.toString());
}
}
+
private void doGROUP(String groupName) {
group = repo.getGroup(groupName);
// section 9.1.1.1
@@ -532,6 +574,7 @@
writer.println(respBuffer.toString());
}
}
+
private void doLISTEXTENSIONS() {
// 8.1.1
writer.println("202 Extensions supported:");
@@ -643,8 +686,9 @@
List list = new ArrayList();
for ( int i = start ; i <= end ; i++ ) {
NNTPArticle article = group.getArticle(i);
- if ( article != null )
+ if ( article != null ) {
list.add(article);
+ }
}
return (NNTPArticle[])list.toArray(new NNTPArticle[0]);
}
@@ -652,6 +696,7 @@
private void doXOVER(String range) {
doOVER(range);
}
+
private void doOVER(String range) {
// 9.5.2.2.1
if ( group == null ) {
@@ -660,12 +705,14 @@
}
NNTPArticle[] article = getRange(range);
ArticleWriter articleWriter = ArticleWriter.Factory.OVER(writer);
- if ( article.length == 0 )
+ if ( article.length == 0 ) {
writer.println("420 No article(s) selected");
+ }
else {
writer.println("224 Overview information follows");
- for ( int i = 0 ; i < article.length ; i++ )
+ for ( int i = 0 ; i < article.length ; i++ ) {
articleWriter.write(article[i]);
+ }
writer.println(".");
}
}
1.8 +13 -0
jakarta-james/src/java/org/apache/james/nntpserver/NNTPServer.java
Index: NNTPServer.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/NNTPServer.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- NNTPServer.java 7 Aug 2002 23:37:02 -0000 1.7
+++ NNTPServer.java 18 Aug 2002 07:30:17 -0000 1.8
@@ -28,6 +28,12 @@
return new DefaultHandlerFactory( NNTPHandler.class );
}
+ /**
+ * Pass the <code>Configuration</code> to the instance.
+ *
+ * @param configuration the class configurations.
+ * @throws ConfigurationException if an error occurs
+ */
public void configure( final Configuration configuration )
throws ConfigurationException
{
@@ -54,6 +60,13 @@
}
}
+ /**
+ * Initialize the component. Initialization includes
+ * allocating any resources required throughout the
+ * components lifecycle.
+ *
+ * @throws Exception if an error occurs
+ */
public void initialize() throws Exception {
//System.out.println(getClass().getName() + ": init");
super.initialize();
1.7 +1 -1
jakarta-james/src/java/org/apache/james/nntpserver/repository/ArticleIDRepository.java
Index: ArticleIDRepository.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/repository/ArticleIDRepository.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ArticleIDRepository.java 8 Aug 2002 00:43:29 -0000 1.6
+++ ArticleIDRepository.java 18 Aug 2002 07:30:17 -0000 1.7
@@ -80,7 +80,7 @@
b64Id = Base64.encodeAsString(articleID);
} catch (Exception e) {
throw new RuntimeException("This shouldn't happen: " + e);
- }
+ }
return new File(root, b64Id);
}
1.8 +22 -0
jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java
Index: NNTPRepositoryImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- NNTPRepositoryImpl.java 7 Aug 2002 23:38:48 -0000 1.7
+++ NNTPRepositoryImpl.java 18 Aug 2002 07:30:17 -0000 1.8
@@ -49,11 +49,25 @@
private String[] addGroups = null;
+ /**
+ * Pass the Context to the component.
+ * This method is called after the setLogger()
+ * method and before any other method.
+ *
+ * @param context the context
+ * @throws ContextException if context is invalid
+ */
public void contextualize(Context context)
throws ContextException {
this.context = context;
}
+ /**
+ * Pass the <code>Configuration</code> to the instance.
+ *
+ * @param configuration the class configurations.
+ * @throws ConfigurationException if an error occurs
+ */
public void configure( Configuration configuration ) throws
ConfigurationException {
//System.out.println(getClass().getName() + ": configure");
//NNTPUtil.show(configuration,System.out);
@@ -83,6 +97,14 @@
addGroups = (String[])addGroupsList.toArray(new String[0]);
getLogger().debug("repository configuration done");
}
+
+ /**
+ * Initialize the component. Initialization includes
+ * allocating any resources required throughout the
+ * components lifecycle.
+ *
+ * @throws Exception if an error occurs
+ */
public void initialize() throws Exception {
//System.out.println(getClass().getName() + ": init");
if ( rootPath.exists() == false )
1.7 +16 -1
jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPSpooler.java
Index: NNTPSpooler.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPSpooler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- NNTPSpooler.java 8 Aug 2002 00:43:29 -0000 1.6
+++ NNTPSpooler.java 18 Aug 2002 07:30:17 -0000 1.7
@@ -43,6 +43,12 @@
this.context = context;
}
+ /**
+ * Pass the <code>Configuration</code> to the instance.
+ *
+ * @param configuration the class configurations.
+ * @throws ConfigurationException if an error occurs
+ */
public void configure( Configuration configuration ) throws
ConfigurationException {
//System.out.println(getClass().getName()+": configure");
//NNTPUtil.show(configuration,System.out);
@@ -66,10 +72,19 @@
worker[i].setArticleIDRepository(articleIDRepo);
}
File getSpoolPath() {
- if ( spoolPath.exists() == false )
+ if ( spoolPath.exists() == false ) {
spoolPath.mkdirs();
+ }
return spoolPath;
}
+
+ /**
+ * Initialize the component. Initialization includes
+ * allocating any resources required throughout the
+ * components lifecycle.
+ *
+ * @throws Exception if an error occurs
+ */
public void initialize() throws Exception {
//System.out.println(getClass().getName()+": init");
for ( int i = 0 ; i < worker.length ; i++ )
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>