| 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 */ |
| 22 |
|
|
| 23 |
base::base(void) |
base::base(void) |
| 24 |
: p_ParentThread(NULL) |
: p_ParentThread(NULL) |
| 25 |
|
, p_ThreadPool(NULL) |
| 26 |
|
, ulMainThreadId(0) |
| 27 |
, innd_uid(0) |
, innd_uid(0) |
| 28 |
, isConnected(false) |
, isConnected(false) |
| 29 |
, running(false) |
, running(false) |
| 32 |
|
|
| 33 |
base::~base(void) |
base::~base(void) |
| 34 |
{ |
{ |
| 35 |
|
if (this->GetThreadPool() != NULL) |
| 36 |
|
delete (this->GetThreadPool()); |
| 37 |
} |
} |
| 38 |
|
|
| 39 |
int base::s_exec(const char* in_str, CString& out_str, const char* end_str) |
int base::s_exec(const char* in_str, CString& out_str, const char* end_str) |
| 285 |
RS.GetFieldValue("UID",dbVar,SQL_C_SLONG); |
RS.GetFieldValue("UID",dbVar,SQL_C_SLONG); |
| 286 |
sql.Format("insert into bbs_msg(fromUID,toUID,ntent,send_dt,send_ip)" |
sql.Format("insert into bbs_msg(fromUID,toUID,ntent,send_dt,send_ip)" |
| 287 |
" valulues(%ld,%ld,'%s',now(),'%s')", |
" valulues(%ld,%ld,'%s',now(),'%s')", |
| 288 |
this->innd_uid,dbVar.m_lVal,addslashes(msg_connt),ththis->hostaddr); |
this->innd_uid,dbVar.m_lVal,addslashes(msg_content),this->hostaddr); |
| 289 |
this->Db.ExecuteSQL(sql); |
this->Db.ExecuteSQL(sql); |
| 290 |
} |
} |
| 291 |
} |
} |
| 292 |
RS.Close(); |
RS.Close(); |
| 293 |
} |
} |
| 294 |
|
|
| 295 |
sql.Format("insert delayed into innd_logfile(AID,art_id,msg_id,op) values" |
sql.Format("insert delayed into innd_log(AID,art_id,msg_id,op) values" |
| 296 |
"(%ld,%ld,'%s','I')", |
"(%ld,%ld,'%s','I')", |
| 297 |
aid,art_id,addslashes(msg_id)); |
aid,art_id,addslashes(msg_id)); |
| 298 |
this->Db.ExecuteSQL(sql); |
this->Db.ExecuteSQL(sql); |
| 304 |
} |
} |
| 305 |
catch(CException* e) |
catch(CException* e) |
| 306 |
{ |
{ |
| 307 |
syslog << logfile::log_head << "Error in bbs_post()" << endl; |
char strErrMsg[256]; |
| 308 |
|
e->GetErrorMessage(strErrMsg,256); |
| 309 |
|
syslog << logfile::log_head << "Error in bbs_post() [" << strErrMsg << "]" << endl; |
| 310 |
e->Delete(); |
e->Delete(); |
| 311 |
return -1; |
return -1; |
| 312 |
} |
} |
| 391 |
this->Db.ExecuteSQL(sql); |
this->Db.ExecuteSQL(sql); |
| 392 |
} |
} |
| 393 |
|
|
| 394 |
sql.Format("update innd_logfile set cancel=1 where AID=%ld",id); |
sql.Format("update innd_log set cancel=1 where AID=%ld",id); |
| 395 |
this->Db.ExecuteSQL(sql); |
this->Db.ExecuteSQL(sql); |
| 396 |
} |
} |
| 397 |
RS.Close(); |
RS.Close(); |
| 398 |
} |
} |
| 399 |
catch(CException* e) |
catch(CException* e) |
| 400 |
{ |
{ |
| 401 |
syslog << logfile::log_head << "Getting article error in bbs_delete()" << endl; |
char strErrMsg[256]; |
| 402 |
|
e->GetErrorMessage(strErrMsg,256); |
| 403 |
|
syslog << logfile::log_head << "Getting article error in bbs_delete() [" << strErrMsg << "]" << endl; |
| 404 |
e->Delete(); |
e->Delete(); |
| 405 |
return -1; |
return -1; |
| 406 |
} |
} |
| 463 |
|
|
| 464 |
int base::begin(void) |
int base::begin(void) |
| 465 |
{ |
{ |
| 466 |
|
HANDLE hThread; |
| 467 |
ULONG ulThreadId; |
ULONG ulThreadId; |
| 468 |
unsigned int time_wait = 0; |
unsigned int time_wait = 0; |
| 469 |
|
|
| 470 |
if (!this->IsShutdown()) |
if (!this->IsShutdown()) |
| 471 |
return 1; |
return 1; |
| 472 |
|
|
| 473 |
if (this->hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base::Thread,(LPVOID)this,0,&ulThreadId)) |
if (hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)base::Thread,(LPVOID)this,0,&ulThreadId)) |
| 474 |
{ |
{ |
| 475 |
|
CloseHandle(hThread); |
| 476 |
syslog << logfile::log_head << "Create thread ... OK" << endl; |
syslog << logfile::log_head << "Create thread ... OK" << endl; |
| 477 |
} |
} |
| 478 |
else |
else |
| 499 |
|
|
| 500 |
DWORD base::Thread(LPVOID pParam) |
DWORD base::Thread(LPVOID pParam) |
| 501 |
{ |
{ |
|
HANDLE hThreadCurrent; |
|
| 502 |
base* p; |
base* p; |
| 503 |
|
|
| 504 |
syslog << logfile::log_head << "Thread started." << endl; |
syslog << logfile::log_head << "Thread started." << endl; |
| 505 |
|
|
| 506 |
p = (base*)pParam; |
p = (base*)pParam; |
|
hThreadCurrent = GetCurrentThread(); |
|
| 507 |
|
|
| 508 |
if (p->GetParentThread()->GetThreadPool()->AddThread(hThreadCurrent, CLOCKS_PER_SEC * 30) != 0) |
p->ulMainThreadId = GetCurrentThreadId(); |
| 509 |
|
|
| 510 |
|
if (p->GetParentThread()->GetThreadPool()->AddThread(GetCurrentThreadId(), CLOCKS_PER_SEC * 30) != 0) |
| 511 |
{ |
{ |
| 512 |
syslog << logfile::log_head << "Register thread ... Failed" << endl; |
syslog << logfile::log_head << "Register thread ... Failed" << endl; |
| 513 |
} |
} |
| 514 |
p->GetParentThread()->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WORKING); |
p->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); |
| 515 |
|
|
| 516 |
p->w_call(); |
p->w_call(); |
| 517 |
|
|
| 518 |
if (p->GetParentThread()->GetThreadPool()->RemoveThread(hThreadCurrent) != 0) |
if (p->GetParentThread()->GetThreadPool()->RemoveThread(GetCurrentThreadId()) != 0) |
| 519 |
{ |
{ |
| 520 |
syslog << logfile::log_head << "Unregister thread ... Failed" << endl; |
syslog << logfile::log_head << "Unregister thread ... Failed" << endl; |
| 521 |
} |
} |
| 559 |
{ |
{ |
| 560 |
return 0; |
return 0; |
| 561 |
} |
} |
| 562 |
|
|
| 563 |
|
bool base::IsThreadActive(void) |
| 564 |
|
{ |
| 565 |
|
bool bIsActive = false; |
| 566 |
|
|
| 567 |
|
switch (this->GetParentThread()->GetThreadPool()->GetThreadStatus(this->ulMainThreadId)) |
| 568 |
|
{ |
| 569 |
|
case thread_pool::S_WAITING: |
| 570 |
|
case thread_pool::S_WORKING: |
| 571 |
|
bIsActive = true; |
| 572 |
|
break; |
| 573 |
|
default: |
| 574 |
|
bIsActive = false; |
| 575 |
|
} |
| 576 |
|
|
| 577 |
|
return bIsActive; |
| 578 |
|
} |