Ejemplo n.º 1
0
        public override void Execute(NntpSession session)
        {
            using (INntpConnection connection = session.Repository.CreateConnection())
            {
                List <INntpGroup> groups =
                    new List <INntpGroup>(connection.GetGroups());

                session.Connection.SendLine("215 List of newsgroups follows");

                foreach (INntpGroup group in groups)
                {
                    session.Connection.SendLine("{0}\t{1}",
                                                group.Name, group.Description);
                }

                session.Connection.SendLine(".");
            }
        }
Ejemplo n.º 2
0
        public override void Execute(NntpSession session)
        {
            using (INntpConnection connection = session.Repository.CreateConnection())
            {
                INntpGroup group;

                if (_group == null)
                {
                    if (!GetGroupByCurrentName(connection, session, out group))
                    {
                        return;
                    }
                }
                else
                {
                    if (!GetGroupByName(connection, session, _group, out group))
                    {
                        return;
                    }
                }

                if (low == 0)
                {
                    low = group.Low;
                }

                if (high == 0)
                {
                    high = group.High;
                }

                session.Context[typeof(INntpArticle)] = low; //???

                session.Connection.SendLine("211 {0} {1} {2} {3}",
                                            group.Count, group.Low, group.High, group.Name);

                foreach (KeyValuePair <int, INntpArticle> pair in group.GetArticles(low, high))
                {
                    session.Connection.SendLine("{0}", pair.Key);
                }

                session.Connection.SendLine(".");
            }
        }
Ejemplo n.º 3
0
        protected static bool GetGroupByCurrentName(INntpConnection connection, NntpSession session, out INntpGroup group)
        {
            group = null;

            if (!session.Context.ContainsKey(typeof(INntpGroup)))
            {
                session.Connection.SendLine("412 No newsgroup selected");
                return(false);
            }

            group = connection.GetGroup((string)session.Context[typeof(INntpGroup)]);

            if (group == null)
            {
                session.Connection.SendLine("412 No newsgroup selected");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        protected static bool GetArticleByNumber(INntpConnection connection, NntpSession session, int number, out KeyValuePair <int, INntpArticle> pair)
        {
            pair = new KeyValuePair <int, INntpArticle>(number, null);

            INntpGroup group;

            if (!GetGroupByCurrentName(connection, session, out group))
            {
                return(false);
            }

            pair = new KeyValuePair <int, INntpArticle>(number, group.GetArticle(number));

            if (pair.Value == null)
            {
                session.Connection.SendLine("423 No article with that number");
                return(false);
            }

            session.Context[typeof(INntpArticle)] = number;

            return(true);
        }
Ejemplo n.º 5
0
        protected static bool GetArticleByCurrentNumber(INntpConnection connection, NntpSession session, out KeyValuePair <int, INntpArticle> pair)
        {
            pair = new KeyValuePair <int, INntpArticle>(0, null);

            INntpGroup group;

            if (!GetGroupByCurrentName(connection, session, out group))
            {
                return(false);
            }

            int number = (int)session.Context[typeof(INntpArticle)];

            pair = new KeyValuePair <int, INntpArticle>(number, group.GetArticle(number));

            if (pair.Value == null)
            {
                session.Connection.SendLine("420 Current article number is invalid");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 6
0
        public override void Execute(NntpSession session)
        {
            using (INntpConnection connection = session.Repository.CreateConnection())
            {
                KeyValuePair <int, INntpArticle> pair;

                switch (type)
                {
                case RequestType.ByMessageID:
                    if (!GetArticleByMessageID(connection, session, id, out pair))
                    {
                        return;
                    }

                    break;

                case RequestType.ByArticleNumber:
                    if (!GetArticleByNumber(connection, session, number, out pair))
                    {
                        return;
                    }

                    break;

                case RequestType.ByCurrentArticleNumber:
                    if (!GetArticleByCurrentNumber(connection, session, out pair))
                    {
                        return;
                    }

                    break;

                default:
                    throw new InvalidOperationException("Unknown request type");
                }

                if (name == "ARTICLE")
                {
                    session.Connection.SendLine("220 {0} {1}", pair.Key, pair.Value.MessageID);
                }

                if (name == "HEAD")
                {
                    session.Connection.SendLine("221 {0} {1}", pair.Key, pair.Value.MessageID);
                }

                if (name == "BODY")
                {
                    session.Connection.SendLine("222 {0} {1}", pair.Key, pair.Value.MessageID);
                }

                if (name == "STAT")
                {
                    session.Connection.SendLine("223 {0} {1}", pair.Key, pair.Value.MessageID);
                }

                if (name == "ARTICLE" || name == "HEAD")
                {
                    SendHeader(session, NntpHeaderName.MessageID, pair.Value.MessageID);
                    SendHeader(session, NntpHeaderName.Subject, pair.Value.Subject);
                    SendHeader(session, NntpHeaderName.From, pair.Value.From);
                    SendHeader(session, NntpHeaderName.Date, pair.Value.Date);
                    SendHeader(session, NntpHeaderName.Newsgroups, pair.Value.Newsgroups);

                    if (pair.Value.References != "")
                    {
                        SendHeader(session, NntpHeaderName.References, pair.Value.References);
                    }

                    foreach (KeyValuePair <string, string> header in pair.Value.Headers)
                    {
                        SendHeader(session, header.Key, header.Value);
                    }
                }

                if (name == "ARTICLE")
                {
                    session.Connection.SendLine("");
                }

                if (name == "ARTICLE" || name == "BODY")
                {
                    string[] lines = pair.Value.Body.Split('\n');

                    for (int i = 0; i < lines.Length; i++)
                    {
                        string line = lines[i];

                        if (line.StartsWith("."))
                        {
                            line = '.' + line;
                        }

                        session.Connection.SendLine(line);
                    }
                }

                if (name != "STAT")
                {
                    session.Connection.SendLine(".");
                }
            }
        }
Ejemplo n.º 7
0
 private static void SendHeader(NntpSession session, string name, string value)
 {
     session.Connection.SendLine("{0}: {1}", name, value);
 }
Ejemplo n.º 8
0
 public override void Execute(NntpSession session)
 {
     session.Connection.SendLine("231 List of new newsgroups follows");
     session.Connection.SendLine(".");
 }
Ejemplo n.º 9
0
 public abstract void Execute(NntpSession session);
Ejemplo n.º 10
0
 public override void Execute(NntpSession session)
 {
     session.Connection.SendLine("200 Reader mode, posting permitted");
 }
Ejemplo n.º 11
0
 public override void Execute(NntpSession session)
 {
     variant.Execute(session);
 }
Ejemplo n.º 12
0
        public override void Execute(NntpSession session)
        {
            using (INntpConnection connection = session.Repository.CreateConnection())
            {
                List <KeyValuePair <int, INntpArticle> > pairs = new List <KeyValuePair <int, INntpArticle> >();

                switch (type)
                {
                case RequestType.ByMessageId:
                {
                    KeyValuePair <int, INntpArticle> pair;

                    if (!GetArticleByMessageID(connection, session, id, out pair))
                    {
                        return;
                    }

                    pairs.Add(pair);
                }

                break;

                case RequestType.ByArticleNumberRange:
                {
                    INntpGroup group;

                    if (!GetGroupByCurrentName(connection, session, out group))
                    {
                        return;
                    }

                    if (high == 0)
                    {
                        high = group.High;
                    }

                    pairs.AddRange(group.GetArticles(low, high));

                    if (pairs.Count == 0)
                    {
                        session.Connection.SendLine("423 No articles in that range");
                        return;
                    }
                }

                break;

                case RequestType.ByCurrentArticleNumber:
                {
                    KeyValuePair <int, INntpArticle> pair;

                    if (!GetArticleByCurrentNumber(connection, session, out pair))
                    {
                        return;
                    }

                    pairs.Add(pair);
                }

                break;
                }

                session.Connection.SendLine("224 Overview information follows");

                foreach (KeyValuePair <int, INntpArticle> pair in pairs)
                {
                    session.Connection.SendLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}",
                                                pair.Key, pair.Value.Subject, pair.Value.From, pair.Value.Date,
                                                pair.Value.MessageID, pair.Value.References, pair.Value.Bytes, pair.Value.Lines);
                }

                session.Connection.SendLine(".");
            }
        }
Ejemplo n.º 13
0
 public override void Execute(NntpSession session)
 {
     session.Connection.SendLine("205 Connection closing");
     session.Connection.Close();
 }
Ejemplo n.º 14
0
 public override void Execute(NntpSession session)
 {
     session.Connection.SendLine("111 {0}",
                                 DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmmss"));
 }