1.1 --- a/org/sonews/daemon/command/ListCommand.java Wed Jul 01 10:48:22 2009 +0200
1.2 +++ b/org/sonews/daemon/command/ListCommand.java Wed Jul 22 14:04:05 2009 +0200
1.3 @@ -19,10 +19,10 @@
1.4 package org.sonews.daemon.command;
1.5
1.6 import java.io.IOException;
1.7 -import java.sql.SQLException;
1.8 import java.util.List;
1.9 import org.sonews.daemon.NNTPConnection;
1.10 -import org.sonews.daemon.storage.Group;
1.11 +import org.sonews.storage.Channel;
1.12 +import org.sonews.storage.StorageBackendException;
1.13
1.14 /**
1.15 * Class handling the LIST command.
1.16 @@ -30,12 +30,13 @@
1.17 * @author Dennis Schwerdel
1.18 * @since n3tpd/0.1
1.19 */
1.20 -public class ListCommand extends AbstractCommand
1.21 +public class ListCommand implements Command
1.22 {
1.23
1.24 - public ListCommand(final NNTPConnection conn)
1.25 + @Override
1.26 + public String[] getSupportedCommandStrings()
1.27 {
1.28 - super(conn);
1.29 + return new String[]{"LIST"};
1.30 }
1.31
1.32 @Override
1.33 @@ -43,10 +44,16 @@
1.34 {
1.35 return true;
1.36 }
1.37 +
1.38 + @Override
1.39 + public boolean isStateful()
1.40 + {
1.41 + return false;
1.42 + }
1.43
1.44 @Override
1.45 - public void processLine(final String line)
1.46 - throws IOException, SQLException
1.47 + public void processLine(NNTPConnection conn, final String line, byte[] raw)
1.48 + throws IOException, StorageBackendException
1.49 {
1.50 final String[] command = line.split(" ");
1.51
1.52 @@ -54,54 +61,59 @@
1.53 {
1.54 if (command[1].equalsIgnoreCase("OVERVIEW.FMT"))
1.55 {
1.56 - printStatus(215, "information follows");
1.57 - println("Subject:\nFrom:\nDate:\nMessage-ID:\nReferences:\nBytes:\nLines:\nXref");
1.58 - println(".");
1.59 + conn.println("215 information follows");
1.60 + conn.println("Subject:\nFrom:\nDate:\nMessage-ID:\nReferences:\nBytes:\nLines:\nXref");
1.61 + conn.println(".");
1.62 }
1.63 else if (command[1].equalsIgnoreCase("NEWSGROUPS"))
1.64 {
1.65 - printStatus(215, "information follows");
1.66 - final List<Group> list = Group.getAll();
1.67 - for (Group g : list)
1.68 + conn.println("215 information follows");
1.69 + final List<Channel> list = Channel.getAll();
1.70 + for (Channel g : list)
1.71 {
1.72 - println(g.getName() + "\t" + "-");
1.73 + conn.println(g.getName() + "\t" + "-");
1.74 }
1.75 - println(".");
1.76 + conn.println(".");
1.77 }
1.78 else if (command[1].equalsIgnoreCase("SUBSCRIPTIONS"))
1.79 {
1.80 - printStatus(215, "information follows");
1.81 - println(".");
1.82 + conn.println("215 information follows");
1.83 + conn.println(".");
1.84 }
1.85 else if (command[1].equalsIgnoreCase("EXTENSIONS"))
1.86 {
1.87 - printStatus(202, "Supported NNTP extensions.");
1.88 - println("LISTGROUP");
1.89 - println(".");
1.90 -
1.91 + conn.println("202 Supported NNTP extensions.");
1.92 + conn.println("LISTGROUP");
1.93 + conn.println("XDAEMON");
1.94 + conn.println("XPAT");
1.95 + conn.println(".");
1.96 }
1.97 else
1.98 {
1.99 - printStatus(500, "unknown argument to LIST command");
1.100 + conn.println("500 unknown argument to LIST command");
1.101 }
1.102 }
1.103 else
1.104 {
1.105 - final List<Group> groups = Group.getAll();
1.106 + final List<Channel> groups = Channel.getAll();
1.107 if(groups != null)
1.108 {
1.109 - printStatus(215, "list of newsgroups follows");
1.110 - for (Group g : groups)
1.111 + conn.println("215 list of newsgroups follows");
1.112 + for (Channel g : groups)
1.113 {
1.114 - // Indeed first the higher article number then the lower
1.115 - println(g.getName() + " " + g.getLastArticleNumber() + " "
1.116 - + g.getFirstArticleNumber() + " y");
1.117 + if(!g.isDeleted())
1.118 + {
1.119 + String writeable = g.isWriteable() ? " y" : " n";
1.120 + // Indeed first the higher article number then the lower
1.121 + conn.println(g.getName() + " " + g.getLastArticleNumber() + " "
1.122 + + g.getFirstArticleNumber() + writeable);
1.123 + }
1.124 }
1.125 - println(".");
1.126 + conn.println(".");
1.127 }
1.128 else
1.129 {
1.130 - printStatus(500, "server database malfunction");
1.131 + conn.println("500 server database malfunction");
1.132 }
1.133 }
1.134 }