You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2003/01/10 09:30:16 UTC

cvs commit: jakarta-james/src/java/org/apache/james/nntpserver/repository NNTPArticleImpl.java NNTPGroupImpl.java NNTPSpooler.java

noel        2003/01/10 00:30:16

  Modified:    src/java/org/apache/james/nntpserver Tag: branch_2_1_fcs
                        NNTPHandler.java
               src/java/org/apache/james/nntpserver/repository Tag:
                        branch_2_1_fcs NNTPArticleImpl.java
                        NNTPGroupImpl.java NNTPSpooler.java
  Log:
  NNTP protocol fixes.  For details see: http://nagoya.apache.org/eyebrowse/ReadMsg?listName=james-dev@jakarta.apache.org&msgNo=6583
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.25.4.1  +34 -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.25
  retrieving revision 1.25.4.1
  diff -u -r1.25 -r1.25.4.1
  --- NNTPHandler.java	2 Nov 2002 09:03:52 -0000	1.25
  +++ NNTPHandler.java	10 Jan 2003 08:30:15 -0000	1.25.4.1
  @@ -298,7 +298,7 @@
        */
       void idleClose() {
           if (getLogger() != null) {
  -            getLogger().error("Remote Manager Connection has idled out.");
  +            getLogger().error("NNTP Connection has idled out.");
           }
           try {
               if (socket != null) {
  @@ -601,10 +601,28 @@
        * an argument.
        *
        * @param argument the argument passed in with the NEWNEWS command.
  -     *                 Should be a date.
  +     *                 Should be NEWNEWS newsgroups date time [GMT] [<distribution>]
  +     *                 see RFC 977 #3.8, RFC 2980 #4.5.
        */
       private void doNEWNEWS(String argument) {
  -        // see section 11.4
  +
  +        String wildmat = "*";
  +        if (argument != null) {
  +            int spaceIndex = argument.indexOf(" ");
  +            if (spaceIndex >= 0) {
  +                wildmat = argument.substring(0, spaceIndex);
  +                argument = argument.substring(spaceIndex + 1);
  +            } else {
  +                getLogger().error("NEWNEWS had an invalid argument");
  +                writeLoggedFlushedResponse("501 Syntax error");
  +                return;
  +            }
  +        } else {
  +            getLogger().error("NEWNEWS had a null argument");
  +            writeLoggedFlushedResponse("501 Syntax error");
  +            return;
  +        }
  +
           Date theDate = null;
           try {
               theDate = getDateFrom(argument);
  @@ -613,15 +631,20 @@
               writeLoggedFlushedResponse("501 Syntax error");
               return;
           }
  -        Iterator iter = theConfigData.getNNTPRepository().getArticlesSince(theDate);
  +
           writeLoggedFlushedResponse("230 list of new articles by message-id follows");
  -        while ( iter.hasNext() ) {
  -            StringBuffer iterBuffer =
  -                new StringBuffer(64)
  -                    .append("<")
  -                    .append(((NNTPArticle)iter.next()).getUniqueID())
  -                    .append(">");
  -            writeLoggedResponse(iterBuffer.toString());
  +
  +        Iterator groups = theConfigData.getNNTPRepository().getMatchedGroups(wildmat);
  +        while (groups.hasNext() ) {
  +            Iterator articles = ((NNTPGroup)(groups.next())).getArticlesSince(theDate);
  +            while ( articles.hasNext() ) {
  +                StringBuffer iterBuffer =
  +                                         new StringBuffer(64)
  +                                         .append("<")
  +                                         .append(((NNTPArticle)articles.next()).getUniqueID())
  +                                         .append(">");
  +                writeLoggedResponse(iterBuffer.toString());
  +            }
           }
           writeLoggedFlushedResponse(".");
       }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.10.4.1  +5 -4      jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPArticleImpl.java
  
  Index: NNTPArticleImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPArticleImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.10.4.1
  diff -u -r1.10 -r1.10.4.1
  --- NNTPArticleImpl.java	26 Oct 2002 04:15:29 -0000	1.10
  +++ NNTPArticleImpl.java	10 Jan 2003 08:30:16 -0000	1.10.4.1
  @@ -140,14 +140,15 @@
               String references = hdr.getHeader("References",null);
               long byteCount = articleFile.length();
               long lineCount = -1;
  -            StringBuffer line=new StringBuffer(128)
  +            StringBuffer line=new StringBuffer(256)
  +                .append(getArticleNumber())      .append("\t")
                   .append(cleanHeader(subject))    .append("\t")
                   .append(cleanHeader(author))     .append("\t")
                   .append(cleanHeader(date))       .append("\t")
                   .append(cleanHeader(msgId))      .append("\t")
                   .append(cleanHeader(references)) .append("\t")
  -                .append(byteCount + "\t")
  -                .append(lineCount + "");
  +                .append(byteCount)               .append("\t")
  +                .append(lineCount);
               prt.println(line.toString());
           } catch(Exception ex) { throw new NNTPException(ex); }
       }
  @@ -180,7 +181,7 @@
           StringBuffer sb = new StringBuffer(field);
           for( int i=0 ; i<sb.length() ; i++ ) {
               char c = sb.charAt(i);
  -            if( (c=='\n') || (c=='\t') ) {
  +            if( (c=='\n') || (c=='\t') || (c=='\r') ) {
                   sb.setCharAt(i, ' ');
               }
           }
  
  
  
  1.9.4.1   +12 -3     jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPGroupImpl.java
  
  Index: NNTPGroupImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPGroupImpl.java,v
  retrieving revision 1.9
  retrieving revision 1.9.4.1
  diff -u -r1.9 -r1.9.4.1
  --- NNTPGroupImpl.java	26 Oct 2002 04:15:29 -0000	1.9
  +++ NNTPGroupImpl.java	10 Jan 2003 08:30:16 -0000	1.9.4.1
  @@ -206,10 +206,19 @@
               throws IOException {
           File articleFile = null;
           synchronized (this) {
  -            int artNum = getLastArticleNumber();
  -            articleFile = new File(root,(artNum + 1)+"");
  +            int artNum;
  +            if (numOfArticles < 0)
  +                throw new IllegalStateException("NNTP Group is corrupt (articles < 0).");
  +            else if (numOfArticles == 0) {
  +                firstArticle = 1;
  +                artNum = 1;
  +            } else {
  +                artNum = getLastArticleNumber() + 1;
  +            }
  +            
  +            articleFile = new File(root, artNum + "");
               articleFile.createNewFile();
  -            lastArticle++;
  +            lastArticle = artNum;
               numOfArticles++;
           }
           if (getLogger().isDebugEnabled()) {
  
  
  
  1.11.4.1  +29 -8     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.11
  retrieving revision 1.11.4.1
  diff -u -r1.11 -r1.11.4.1
  --- NNTPSpooler.java	26 Oct 2002 04:15:29 -0000	1.11
  +++ NNTPSpooler.java	10 Jan 2003 08:30:16 -0000	1.11.4.1
  @@ -23,6 +23,7 @@
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.FileOutputStream;
  +import java.io.IOException;
   import java.util.Properties;
   
   /**
  @@ -201,7 +202,7 @@
            * if it loses it tries to lock and process the next article.
            */
           public void run() {
  -            getLogger().debug("in spool thread");
  +            getLogger().debug(Thread.currentThread().getName() + " is the NNTP spooler thread.");
               try {
                   while ( Thread.currentThread().interrupted() == false ) {
                       String[] list = spoolPath.list();
  @@ -219,7 +220,9 @@
                                   lock.unlock(list[i]);
                               }
                           }
  +                        list[i] = null;
                       }
  +                    list = null;
                       // this is good for other non idle threads
                       try {
                           Thread.currentThread().sleep(threadIdleTime);
  @@ -250,23 +253,35 @@
               // TODO: Why is this a block?
               {   // Get the message for copying to destination groups.
                   FileInputStream fin = new FileInputStream(spoolFile);
  -                msg = new MimeMessage(null,fin);
  -                fin.close();
  +                try {
  +                    msg = new MimeMessage(null,fin);
  +                } finally {
  +                    try {
  +                        fin.close();
  +                    } catch (IOException _) { /* ignore close error */ }
  +                }
   
                   // ensure no duplicates exist.
                   String[] idheader = msg.getHeader("Message-Id");
                   articleID = ((idheader != null && (idheader.length > 0))? idheader[0] : null);
                   if ((articleID != null) && ( articleIDRepo.isExists(articleID))) {
                       getLogger().debug("Message already exists: "+articleID);
  -                    spoolFile.delete();
  +                    if (spoolFile.delete() == false)
  +                        getLogger().error("Could not delete duplicate message from spool: " + spoolFile.getAbsolutePath());
                       return;
                   }
                   if ( articleID == null ) {
                       articleID = articleIDRepo.generateArticleID();
                       msg.setHeader("Message-Id", articleID);
                       FileOutputStream fout = new FileOutputStream(spoolFile);
  -                    msg.writeTo(fout);
  -                    fout.close();
  +                    try {
  +                        msg.writeTo(fout);
  +                    } finally {
  +                        try {
  +                            fout.close();
  +                        } catch (IOException _) { /* ignore close error */ }
  +                    }
  +
                   }
               }
   
  @@ -282,8 +297,14 @@
                       }
   
                       FileInputStream newsStream = new FileInputStream(spoolFile);
  -                    NNTPArticle article = group.addArticle(newsStream);
  -                    prop.setProperty(group.getName(),article.getArticleNumber() + "");
  +                    try {
  +                        NNTPArticle article = group.addArticle(newsStream);
  +                        prop.setProperty(group.getName(),article.getArticleNumber() + "");
  +                    } finally {
  +                        try {
  +                            newsStream.close();
  +                        } catch (IOException _) { /* ignore close error */ }
  +                    }
                   }
               }
               articleIDRepo.addArticle(articleID,prop);
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>