| 1 |
/*******************************************************/ |
/*******************************************************/ |
| 2 |
/* */ |
/* */ |
| 3 |
/* LeafOK Innd */ |
/* LeafOK Innbbsd */ |
| 4 |
/* Copyright (C) LeafOK.com, 2003-2004 */ |
/* Copyright (C) LeafOK.com, 2003-2004 */ |
| 5 |
/* */ |
/* */ |
| 6 |
/* Programmed by Leaf */ |
/* Programmed by Leaf */ |
| 7 |
/* E-mail:leaf@leafok.com QQ:6049044 */ |
/* E-mail:leaflet@leafok.com QQ:6049044 */ |
| 8 |
/* */ |
/* */ |
| 9 |
/* http://bbs.leafok.com */ |
/* http://bbs.leafok.com */ |
| 10 |
/* http://bbs.leafok.net */ |
/* http://bbs.leafok.net */ |
| 14 |
|
|
| 15 |
#include "StdAfx.h" |
#include "StdAfx.h" |
| 16 |
#include ".\controld.h" |
#include ".\controld.h" |
| 17 |
#include ".\nntp_active.h" |
#include ".\base_active.h" |
| 18 |
#include ".\App_common.h" |
#include ".\App_common.h" |
| 19 |
|
|
| 20 |
using namespace std; |
using namespace std; |
| 42 |
this->s_send(out); |
this->s_send(out); |
| 43 |
while(!this->thread_terminate) |
while(!this->thread_terminate) |
| 44 |
{ |
{ |
| 45 |
|
this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WAITING); |
| 46 |
|
|
| 47 |
if (this->s_receive(out) == 0) //Connection closed |
if (this->s_receive(out) == 0) //Connection closed |
| 48 |
break; |
break; |
| 49 |
out.Trim(); |
out.Trim(); |
| 50 |
|
|
| 51 |
|
this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); |
| 52 |
|
|
| 53 |
syslog << logfile::log_head << "Cmd: " << out << endl; |
syslog << logfile::log_head << "Cmd: " << out << endl; |
| 54 |
|
|
| 55 |
if (sscanf(out,"%20s",temp) ==1) |
if (sscanf(out,"%20s",temp) ==1) |
| 77 |
|
|
| 78 |
if (cmd == "BBSD") |
if (cmd == "BBSD") |
| 79 |
{ |
{ |
| 80 |
result = ((controld*)(this->p_ParentThread))->bbsd.begin(); |
result = ((controld*)(this->GetParentThread()))->bbsd.begin(); |
| 81 |
} |
} |
| 82 |
if (cmd == "INND") |
if (cmd == "INND") |
| 83 |
{ |
{ |
| 84 |
result = ((controld*)(this->p_ParentThread))->innd.begin(); |
result = ((controld*)(this->GetParentThread()))->innd.begin(); |
| 85 |
} |
} |
| 86 |
if (cmd == "OUTD") |
if (cmd == "OUTD") |
| 87 |
{ |
{ |
| 88 |
result = ((controld*)(this->p_ParentThread))->outd.begin(); |
result = ((controld*)(this->GetParentThread()))->outd.begin(); |
| 89 |
} |
} |
| 90 |
|
|
| 91 |
this->s_send(result == 0 ? "OK" : "Failed"); |
this->s_send(result == 0 ? "OK" : "Failed"); |
| 119 |
|
|
| 120 |
if (cmd == "BBSD") |
if (cmd == "BBSD") |
| 121 |
{ |
{ |
| 122 |
result = ((controld*)(this->p_ParentThread))->bbsd.end(); |
result = ((controld*)(this->GetParentThread()))->bbsd.end(); |
| 123 |
} |
} |
| 124 |
if (cmd == "INND") |
if (cmd == "INND") |
| 125 |
{ |
{ |
| 126 |
result = ((controld*)(this->p_ParentThread))->innd.end(); |
result = ((controld*)(this->GetParentThread()))->innd.end(); |
| 127 |
} |
} |
| 128 |
if (cmd == "OUTD") |
if (cmd == "OUTD") |
| 129 |
{ |
{ |
| 130 |
result = ((controld*)(this->p_ParentThread))->outd.end(); |
result = ((controld*)(this->GetParentThread()))->outd.end(); |
| 131 |
} |
} |
| 132 |
|
|
| 133 |
this->s_send(result == 0 ? "OK" : "Failed"); |
this->s_send(result == 0 ? "OK" : "Failed"); |
| 150 |
{ |
{ |
| 151 |
this->_send("Shutting down ... ",falsse); |
this->_send("Shutting down ... ",falsse); |
| 152 |
|
|
| 153 |
((controld*)(this->p_ParentThread))->ShutdownChild(); |
((controld*)(this->GetParentThread()))->ShutdownChild(); |
| 154 |
|
|
| 155 |
this->s_send("OK"); |
this->s_send("OK"); |
| 156 |
|
|
| 157 |
((controld*)(this->p_ParentThread))->Shutdown(); |
((controld*)(this->GetParentThread()))->Shutdown(); |
| 158 |
break; |
break; |
| 159 |
} |
} |
| 160 |
else |
else |
| 168 |
{ |
{ |
| 169 |
this->s_send("Reloading prev_list ... ",false); |
this->s_send("Reloading prev_list ... ",false); |
| 170 |
|
|
| 171 |
((controld*)(this->p_ParentThread))->unload_priv(); |
((controld*)(this->GetParentThread()))->unload_priv(); |
| 172 |
if (((controld*)(this->p_ParentThread))->load_priv() == 0) |
if (((controld*)(this->GetParentThread()))->load_priv() == 0) |
| 173 |
this->s_send("OK"); |
this->s_send("OK"); |
| 174 |
else |
else |
| 175 |
this->s_send("Failed"); |
this->s_send("Failed"); |
| 179 |
|
|
| 180 |
if (cmd == "ACTIVE") |
if (cmd == "ACTIVE") |
| 181 |
{ |
{ |
| 182 |
if (sscanf(out,"%*s %0s",temp) == 1) |
if (sscanf(out,"%*s %20s",temp) == 1) |
| 183 |
cmd = struupr(temp); |
cmd = strupr(temp); |
| 184 |
else |
else |
| 185 |
cmd = ""; |
cmd = ""; |
| 186 |
cmd.Trim(); |
cmd.Trim(); |
| 190 |
if (this->access.control) |
if (this->access.control) |
| 191 |
{ |
{ |
| 192 |
this->s_send("201 Entering native mode"); |
this->s_send("201 Entering native mode"); |
| 193 |
nntp_active nntpClient; |
base_active nntpClient; |
| 194 |
nntpClient.configure(this->innd_id,this->innd_name,this->innd_server,this->innd_uid,"",0,this->w_conn_str); |
nntpClient.configure(this->innd_id,this->innd_name,this->innd_server,this->innd_uid,"",0,this->w_conn_str); |
| 195 |
|
|
| 196 |
|
this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WAITING); |
| 197 |
|
|
| 198 |
if (cmd == "POST") // Get & Post |
if (cmd == "POST") // Get & Post |
| 199 |
{ |
{ |
| 200 |
nntpClient.work(true,false); |
nntpClient.work(true,false); |
| 203 |
{ |
{ |
| 204 |
nntpClient.work(false,true); |
nntpClient.work(false,true); |
| 205 |
} |
} |
| 206 |
|
|
| 207 |
|
this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); |
| 208 |
|
|
| 209 |
this->s_send("Entering passive mode\r\n."); |
this->s_send("Entering passive mode\r\n."); |
| 210 |
} |
} |
| 211 |
else |
else |
| 251 |
|
|
| 252 |
int controld::Shutdown(void) |
int controld::Shutdown(void) |
| 253 |
{ |
{ |
| 254 |
nntp_active nntpClient; |
base_active nntpClient; |
| 255 |
|
|
| 256 |
if (this->thread_terminate) |
if (this->thread_terminate) |
| 257 |
return 1; |
return 1; |
| 458 |
syslog << logfile::log_head << "End OUTD ... Failed" << endl; |
syslog << logfile::log_head << "End OUTD ... Failed" << endl; |
| 459 |
} |
} |
| 460 |
} |
} |
| 461 |
|
|
| 462 |
|
int controld::InitThreadPool(void) |
| 463 |
|
{ |
| 464 |
|
base* p_ParentThread; |
| 465 |
|
|
| 466 |
|
p_ParentThread = new controld(); |
| 467 |
|
|
| 468 |
|
this->SetParentThread(p_ParentThread); |
| 469 |
|
this->bbsd.SetParentThread(p_ParentThread); |
| 470 |
|
this->innd.SetParentThread(p_ParentThread); |
| 471 |
|
this->outd.SetParentThread(p_ParentThread); |
| 472 |
|
|
| 473 |
|
p_ParentThread->SetThreadPool(new thread_pool(TS_MAX_THREAD)); |
| 474 |
|
|
| 475 |
|
if (p_ParentThread->GetThreadPool()->GetLastError() != 0) |
| 476 |
|
{ |
| 477 |
|
syslog << logfile::log_head << "Create Thread Pool ... failed" << endl; |
| 478 |
|
} |
| 479 |
|
|
| 480 |
|
return 0; |
| 481 |
|
} |
| 482 |
|
|
| 483 |
|
int controld::CleanupThreadPool(void) |
| 484 |
|
{ |
| 485 |
|
delete(this->GetParentThread()); |
| 486 |
|
|
| 487 |
|
return 0; |
| 488 |
|
} |