| 1 |
/*******************************************************/ |
/*******************************************************/ |
| 2 |
/* */ |
/* */ |
| 3 |
/* LeafOK Innd */ |
/* LeafOK Innbbsd */ |
|
/* Copyright (C) LeafOK.com, 2003-2004 */ |
|
| 4 |
/* */ |
/* */ |
| 5 |
/* Programmed by Leaf */ |
/* Copyright (C) LeafOK.com, 2003-2008 */ |
|
/* E-mail:leaf@leafok.com QQ:6049044 */ |
|
| 6 |
/* */ |
/* */ |
| 7 |
/* http://bbs.leafok.com */ |
/* http://www.leafok.com */ |
|
/* http://bbs.leafok.net */ |
|
|
/* http://bbs.fenglin.info */ |
|
| 8 |
/* */ |
/* */ |
| 9 |
/*******************************************************/ |
/*******************************************************/ |
| 10 |
|
|
| 31 |
CString out,cmd; |
CString out,cmd; |
| 32 |
char temp[256]; |
char temp[256]; |
| 33 |
int result; |
int result; |
|
HANDLE hThreadCurrent; |
|
| 34 |
|
|
| 35 |
try |
try |
| 36 |
{ |
{ |
|
hThreadCurrent = GetCurrentThread(); |
|
|
|
|
| 37 |
out.Format("200 %s ready.",App_common::GetVersion()); |
out.Format("200 %s ready.",App_common::GetVersion()); |
| 38 |
this->s_send(out); |
this->s_send(out); |
| 39 |
while(!this->thread_terminate) |
while(!this->thread_terminate) |
| 40 |
{ |
{ |
| 41 |
this->GetParentThread()->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WAITING); |
this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WAITING); |
| 42 |
|
|
| 43 |
if (this->s_receive(out) == 0) //Connection closed |
if (this->s_receive(out) == 0) //Connection closed |
| 44 |
break; |
break; |
| 45 |
out.Trim(); |
out.Trim(); |
| 46 |
|
|
| 47 |
this->GetParentThread()->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WORKING); |
this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); |
| 48 |
|
|
| 49 |
syslog << logfile::log_head << "Cmd: " << out << endl; |
syslog << logfile::log_head << "Cmd: " << out << endl; |
| 50 |
|
|
| 85 |
} |
} |
| 86 |
|
|
| 87 |
this->s_send(result == 0 ? "OK" : "Failed"); |
this->s_send(result == 0 ? "OK" : "Failed"); |
| 88 |
|
|
| 89 |
|
syslog << logfile::log_head << "Begin " << cmd << " ... " << (result == 0 ? "OK" : "Failed") << endl; |
| 90 |
} |
} |
| 91 |
else |
else |
| 92 |
{ |
{ |
| 129 |
} |
} |
| 130 |
|
|
| 131 |
this->s_send(result == 0 ? "OK" : "Failed"); |
this->s_send(result == 0 ? "OK" : "Failed"); |
| 132 |
|
|
| 133 |
|
syslog << logfile::log_head << "End " << cmd << " ... " << (result == 0 ? "OK" : "Failed") << endl; |
| 134 |
} |
} |
| 135 |
else |
else |
| 136 |
{ |
{ |
| 139 |
} |
} |
| 140 |
else |
else |
| 141 |
{ |
{ |
| 142 |
this>s_send("501 service"); |
this->s_send("501 service"); |
| 143 |
} |
} |
| 144 |
contiinue; |
continue; |
| 145 |
} |
} |
| 146 |
|
|
| 147 |
if (cmd == "SHUTDOWN") |
if (cmd == "SHUTDOWN") |
| 148 |
{ |
{ |
| 149 |
if (this->access.control) |
if (this->access.control) |
| 150 |
{ |
{ |
| 151 |
this->_send("Shutting down ... ",falsse); |
this->s_send("Shutting down ... ",false); |
| 152 |
|
|
| 153 |
((controld*)(this->GetParentThread()))->ShutdownChild(); |
((controld*)(this->GetParentThread()))->ShutdownChild(); |
| 154 |
|
|
| 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 = strupr(temp); |
cmd = strupr(temp); |
| 184 |
else |
else |
| 185 |
cmd = ""; |
cmd = ""; |
| 192 |
this->s_send("201 Entering native mode"); |
this->s_send("201 Entering native mode"); |
| 193 |
base_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 |
| 231 |
} |
} |
| 232 |
catch(CException* e) |
catch(CException* e) |
| 233 |
{ |
{ |
| 234 |
syslog << logfile::log_head << "Error in accept()" << endl; |
char strErrMsg[1024]; |
| 235 |
|
e->GetErrorMessage(strErrMsg,1024); |
| 236 |
|
syslog << logfile::log_head << "Error in accept() [" << strErrMsg << "]" << endl; |
| 237 |
e->Delete(); |
e->Delete(); |
| 238 |
return -1; |
return -1; |
| 239 |
} |
} |
| 374 |
} |
} |
| 375 |
catch(CException* e) |
catch(CException* e) |
| 376 |
{ |
{ |
| 377 |
syslog << logfile::log_head << "Load configuration failed" << endl; |
char strErrMsg[1024]; |
| 378 |
|
e->GetErrorMessage(strErrMsg,1024); |
| 379 |
|
syslog << logfile::log_head << "Load configuration failed [" << strErrMsg << "]" << endl; |
| 380 |
e->Delete(); |
e->Delete(); |
| 381 |
return -1; |
return -1; |
| 382 |
} |
} |
| 386 |
this->innd.configure(innd_id,innd_name,innd_server,innd_uid,innd_address,innd_port,conn_str); |
this->innd.configure(innd_id,innd_name,innd_server,innd_uid,innd_address,innd_port,conn_str); |
| 387 |
this->outd.configure(innd_id,innd_name,innd_server,innd_uid,innd_address,0,conn_str); |
this->outd.configure(innd_id,innd_name,innd_server,innd_uid,innd_address,0,conn_str); |
| 388 |
|
|
|
base* p_ParentThread; |
|
|
|
|
|
p_ParentThread = new base_active(); |
|
|
|
|
|
this->SetParentThread(p_ParentThread); |
|
|
this->bbsd.SetParentThread(p_ParentThread); |
|
|
this->innd.SetParentThread(p_ParentThread); |
|
|
this->outd.SetParentThread(p_ParentThread); |
|
|
|
|
|
p_ParentThread->SetThreadPool(new thread_pool(TS_MAX_THREAD)); |
|
|
|
|
|
if (p_ParentThread->GetThreadPool()->GetLastError() != 0) |
|
|
{ |
|
|
syslog << logfile::log_head << "Create Thread Pool ... failed" << endl; |
|
|
} |
|
|
|
|
| 389 |
return 0; |
return 0; |
| 390 |
} |
} |
| 391 |
|
|
| 430 |
|
|
| 431 |
void controld::StartupDelay(void) |
void controld::StartupDelay(void) |
| 432 |
{ |
{ |
| 433 |
|
syslog << logfile::log_head << "Startup delay for " << |
| 434 |
|
this->startup_delay << " seconds"<< endl; |
| 435 |
|
|
| 436 |
Sleep(this->startup_delay * 1000); |
Sleep(this->startup_delay * 1000); |
| 437 |
} |
} |
| 438 |
|
|
| 439 |
void controld::ShutdownChild(void) |
void controld::ShutdownChild(void) |
| 440 |
{ |
{ |
| 441 |
if (this->bbsd.end() == 0) |
if (this->bbsd.IsRunning()) |
|
{ |
|
|
syslog << logfile::log_head << "End BBSD ... OK" << endl; |
|
|
} |
|
|
else |
|
| 442 |
{ |
{ |
| 443 |
syslog << logfile::log_head << "End BBSD ... Failed" << endl; |
if (this->bbsd.end() == 0) |
| 444 |
|
{ |
| 445 |
|
syslog << logfile::log_head << "End BBSD ... OK" << endl; |
| 446 |
|
} |
| 447 |
|
else |
| 448 |
|
{ |
| 449 |
|
syslog << logfile::log_head << "End BBSD ... Failed" << endl; |
| 450 |
|
} |
| 451 |
} |
} |
| 452 |
|
|
| 453 |
if (this->innd.end() == 0) |
if (this->innd.IsRunning()) |
|
{ |
|
|
syslog << logfile::log_head << "End INND ... OK" << endl; |
|
|
} |
|
|
else |
|
| 454 |
{ |
{ |
| 455 |
syslog << logfile::log_head << "End INND ... Failed" << endl; |
if (this->innd.end() == 0) |
| 456 |
|
{ |
| 457 |
|
syslog << logfile::log_head << "End INND ... OK" << endl; |
| 458 |
|
} |
| 459 |
|
else |
| 460 |
|
{ |
| 461 |
|
syslog << logfile::log_head << "End INND ... Failed" << endl; |
| 462 |
|
} |
| 463 |
} |
} |
| 464 |
|
|
| 465 |
if (this->outd.end() == 0) |
if (this->outd.IsRunning()) |
| 466 |
{ |
{ |
| 467 |
syslog << logfile::log_head << "End OUTD ... OK" << endl; |
if (this->outd.end() == 0) |
| 468 |
|
{ |
| 469 |
|
syslog << logfile::log_head << "End OUTD ... OK" << endl; |
| 470 |
|
} |
| 471 |
|
else |
| 472 |
|
{ |
| 473 |
|
syslog << logfile::log_head << "End OUTD ... Failed" << endl; |
| 474 |
|
} |
| 475 |
} |
} |
| 476 |
else |
} |
| 477 |
|
|
| 478 |
|
int controld::InitThreadPool(void) |
| 479 |
|
{ |
| 480 |
|
base* p_ParentThread; |
| 481 |
|
|
| 482 |
|
p_ParentThread = new controld(); |
| 483 |
|
|
| 484 |
|
this->SetParentThread(p_ParentThread); |
| 485 |
|
this->bbsd.SetParentThread(p_ParentThread); |
| 486 |
|
this->innd.SetParentThread(p_ParentThread); |
| 487 |
|
this->outd.SetParentThread(p_ParentThread); |
| 488 |
|
|
| 489 |
|
p_ParentThread->SetThreadPool(new thread_pool(TS_MAX_THREAD)); |
| 490 |
|
|
| 491 |
|
if (p_ParentThread->GetThreadPool()->GetLastError() != 0) |
| 492 |
{ |
{ |
| 493 |
syslog << logfile::log_head << "End OUTD ... Failed" << endl; |
syslog << logfile::log_head << "Create Thread Pool ... failed" << endl; |
| 494 |
} |
} |
| 495 |
|
|
| 496 |
|
return 0; |
| 497 |
|
} |
| 498 |
|
|
| 499 |
|
int controld::CleanupThreadPool(void) |
| 500 |
|
{ |
| 501 |
|
delete(this->GetParentThread()); |
| 502 |
|
|
| 503 |
|
return 0; |
| 504 |
|
} |
| 505 |
|
|
| 506 |
|
bool controld::check_priv(void) |
| 507 |
|
{ |
| 508 |
|
return this->access.control; |
| 509 |
} |
} |