1 /*
2 ** Copyright 2003, Double Precision Inc.
3 **
4 ** See COPYING for distribution information.
5 */
6 #include "nntpgroup.H"
7 #include <sstream>
8
9 using namespace std;
10
11 //
12 // Make sure a particular group is selected, before proceeding
13 //
14
GroupTask(callback * callbackArg,nntp & myserverArg,std::string groupNameArg)15 mail::nntp::GroupTask::GroupTask(callback *callbackArg, nntp &myserverArg,
16 std::string groupNameArg)
17 : LoggedInTask(callbackArg, myserverArg),
18 groupName(groupNameArg)
19 {
20 }
21
~GroupTask()22 mail::nntp::GroupTask::~GroupTask()
23 {
24 }
25
loggedIn()26 void mail::nntp::GroupTask::loggedIn()
27 {
28 if (myserver->serverGroup == groupName &&
29 myserver->openedGroup == groupName)
30 // Must check openedGroup
31 {
32 selectedCurrentGroup();
33 return;
34 }
35
36 response_func= &mail::nntp::GroupTask::processGroupStatus;
37 myserver->serverGroup="";
38 myserver->socketWrite("GROUP " + groupName + "\r\n");
39 }
40
processLine(const char * message)41 void mail::nntp::GroupTask::processLine(const char *message)
42 {
43 (this->*response_func)(message);
44 }
45
selectedCurrentGroup()46 void mail::nntp::GroupTask::selectedCurrentGroup()
47 {
48 response_func= &mail::nntp::GroupTask::processOtherStatus;
49 if (myserver->index.size() == 0)
50 selectedGroup(0, 0, 0);
51 else
52 selectedGroup(myserver->index[0].msgNum,
53 myserver->index.end()[-1].msgNum,
54 myserver->index.size());
55 }
56
processGroupStatus(const char * msg)57 void mail::nntp::GroupTask::processGroupStatus(const char *msg)
58 {
59 string buf=msg;
60 istringstream i(buf);
61
62 int status;
63 msgnum_t est, lo, hi;
64
65 i >> status >> est >> lo >> hi;
66
67 if (i.bad() || i.fail() || (status / 100) != 2)
68 {
69 fail(msg);
70 return;
71 }
72
73 ++hi;
74
75 if (est > hi-lo)
76 est=hi-lo; // Fix an impossibility
77
78
79 response_func= &mail::nntp::GroupTask::processOtherStatus;
80 myserver->serverGroup=groupName;
81
82 if (myserver->openedGroup == groupName)
83 selectedCurrentGroup();
84 else
85 selectedGroup(est, lo, hi);
86 }
87
processOtherStatus(const char * msg)88 void mail::nntp::GroupTask::processOtherStatus(const char *msg)
89 {
90 processGroup(msg);
91 }
92