| 1 |
/*******************************************************/ |
/*******************************************************/ |
| 2 |
/* */ |
/* */ |
| 3 |
/* LeafOK Innd */ |
/* LeafOK Innbbsd */ |
| 4 |
/* Copyright (C) LeafOK.com, 2003-2004 */ |
/* Copyright (C) LeafOK.com, 2003-2005 */ |
| 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, char end_str[]) |
| 40 |
{ |
{ |
| 41 |
try{ |
try{ |
| 42 |
if (in_str != NULL) |
if (in_str != NULL) |
| 105 |
bool head_find; |
bool head_find; |
| 106 |
CString head_name,head_value,path,from,subject,newsgroups,organization,date,msg_id; //Head |
CString head_name,head_value,path,from,subject,newsgroups,organization,date,msg_id; //Head |
| 107 |
DateTimeConvert sub_dt; |
DateTimeConvert sub_dt; |
| 108 |
CString ptitle,nickname,dt_str,content,msg_content,sql; |
CString ptitle,username,nickname,dt_str,content,msg_content,sql; |
| 109 |
int length; |
int length; |
| 110 |
long id,aid,cid,rid; |
long id,aid,cid; |
| 111 |
|
|
| 112 |
try |
try |
| 113 |
{ |
{ |
| 197 |
if (subject.GetLength() > 80) |
if (subject.GetLength() > 80) |
| 198 |
subject = subject.Left(75) + " ……"; |
subject = subject.Left(75) + " ……"; |
| 199 |
|
|
| 200 |
//Get nickname |
//Get username |
| 201 |
nickname = "cn.bbs"; |
username = "cn.bbs."; |
| 202 |
for (int i=0;i<from.GetLength();i++) |
for (int i=0;i<from.GetLength();i++) |
| 203 |
{ |
{ |
| 204 |
if (from[i] == '.' || from[i] == '@') |
if (from[i] == '.' || from[i] == '@') |
| 209 |
if (from[j] == ' ' || from[j] == '<') |
if (from[j] == ' ' || from[j] == '<') |
| 210 |
break; |
break; |
| 211 |
} |
} |
| 212 |
nickname = from.Mid(j+1,i-j-1) + "."; |
username = from.Mid(j+1,i-j-1) + "."; |
| 213 |
|
break; |
| 214 |
|
} |
| 215 |
|
} |
| 216 |
|
if (username.GetLength() > 12) |
| 217 |
|
username = username.Left(12) + "."; |
| 218 |
|
|
| 219 |
|
//Get nickname |
| 220 |
|
nickname = "cn.bbs"; |
| 221 |
|
for (int i=0;i<from.GetLength();i++) |
| 222 |
|
{ |
| 223 |
|
if (from[i] == '(') |
| 224 |
|
{ |
| 225 |
|
int j; |
| 226 |
|
for (j=i+1;j<from.GetLength();j++) |
| 227 |
|
{ |
| 228 |
|
if (from[j] == ')') |
| 229 |
|
break; |
| 230 |
|
} |
| 231 |
|
nickname = from.Mid(i+1,j-i-1); |
| 232 |
break; |
break; |
| 233 |
} |
} |
| 234 |
} |
} |
| 235 |
if (nickname.GetLength() > 20) |
if (nickname.GetLength() > 20) |
| 236 |
nickname = nickname.Left(19) + "."; |
nickname = nickname.Left(20); |
| 237 |
|
|
| 238 |
//Reference /bbs/add_sub.php |
//Reference /bbs/add_sub.php |
| 239 |
|
|
| 242 |
this->Db.ExecuteSQL(sql); |
this->Db.ExecuteSQL(sql); |
| 243 |
cid = this->last_insert_id(); |
cid = this->last_insert_id(); |
| 244 |
|
|
| 245 |
sql.Format("insert into bbs(SID,TID,UID,nickname,title,CID,sub_dt," |
sql.Format("insert into bbs(SID,TID,UID,username,nickname,title,CID,sub_dt," |
| 246 |
"sub_ip,last_reply_dt,icon,length,transship)" |
"sub_ip,last_reply_dt,icon,length,transship)" |
| 247 |
"values(%d,%ld,%ld,'%s','%s',%ld,adddate('%s',interval '8' hour)," |
"values(%d,%ld,%ld,'%s','%s','%s',%ld,adddate('%s',interval '8' hour)," |
| 248 |
"'%s',adddate('%s',interval '8' hour),1,%d,1)", |
"'%s',adddate('%s',interval '8' hour),1,%d,1)", |
| 249 |
sid,id,this->innd_uid,addslashes(nickname),addslashes(subject), |
sid,id,this->innd_uid,addslashes(username),addslashes(nickname),addslashes(subject), |
| 250 |
cid,dt_str,this->hostaddr,dt_str,length); |
cid,dt_str,this->hostaddr,dt_str,length); |
| 251 |
this->Db.ExecuteSQL(sql); |
this->Db.ExecuteSQL(sql); |
| 252 |
aid = this->last_insert_id(); |
aid = this->last_insert_id(); |
| 255 |
this->Db.ExecuteSQL(sql); //7671 |
this->Db.ExecuteSQL(sql); //7671 |
| 256 |
|
|
| 257 |
//Add logfile |
//Add logfile |
| 258 |
sql.Format("insert delayed into bbs_article_op(AID,UID,type,op_dt,op_ip,complete)" |
sql.Format("insert delayed into bbs_article_op(AID,UID,type,op_dt,op_ip)" |
| 259 |
" values(%ld,%ld,'I',now(),'%s',1)", |
" values(%ld,%ld,'I',now(),'%s')", |
| 260 |
aid,this->innd_uid,this->hostaddr); |
aid,this->innd_uid,this->hostaddr); |
| 261 |
this->Db.ExecuteSQL(sql); |
this->Db.ExecuteSQL(sql); |
| 262 |
|
|
| 265 |
{ |
{ |
| 266 |
sql.Format("update bbs set cached=0, reply_count=reply_count+1," |
sql.Format("update bbs set cached=0, reply_count=reply_count+1," |
| 267 |
"last_reply_dt=adddate('%s',interval '8' hour),last_reply_UID=%ld," |
"last_reply_dt=adddate('%s',interval '8' hour),last_reply_UID=%ld," |
| 268 |
"last_reply_nickname='%s' where aid=%ld", |
"last_reply_username='%s',last_reply_nickname='%s' where aid=%ld", |
| 269 |
dt_str,this->innd_uid,nickname,id); |
dt_str,this->innd_uid,username,nickname,id); |
| 270 |
this->Db.ExecuteSQL(sql); |
this->Db.ExecuteSQL(sql); |
| 271 |
} |
} |
| 272 |
|
|
| 273 |
//Notify the author of the artile which is replyed. |
//Notify the author of the artile which is replyed. |
| 274 |
if (id != 0) |
if (id != 0) |
| 275 |
{ |
{ |
| 276 |
sql.Format("select user_pubinfo.UID,user_pubinfo.nickname," |
sql.Format("select distinct UID from bbs where (AID=%ld or TID=%ld)" |
| 277 |
"user_pubinfo.email from bbs left join user_pubinfo on" |
" and visible and reply_note and UID<>%ld",id,id,this->innd_uid); |
|
" bbs.UID=user_pubinfo.UID where AID=%ld and reply_note", |
|
|
id); |
|
| 278 |
RS.Open(CRecordset::snapshot,sql,CRecordset::forwardOnly | CRecordset::readOnly); |
RS.Open(CRecordset::snapshot,sql,CRecordset::forwardOnly | CRecordset::readOnly); |
| 279 |
|
|
| 280 |
if (!RS.IsEOF()) |
while (!RS.IsEOF()) |
| 281 |
{ |
{ |
| 282 |
RS.GetFieldValue("UID",dbVar),SQL_C_SLONG; |
//Send notication message |
| 283 |
if (dbVar.m_lVal != innd_uid) |
|
| 284 |
{ |
msg_content.Format("[hide]SYS_R_Reply_Article[/hide]" |
| 285 |
sql.Format("update user_pubinfo set exp=exp+1 where UID=%ld", |
"有人回复了您所发表的文章,快来[article %ld#%ld" |
| 286 |
dbVar.m_lVal); |
"]看看[/article]《%s》吧!\n",id,aid,addslashes(subject)); |
| 287 |
this->Db.ExecuteSQL(sql); |
|
| 288 |
|
RS.GetFieldValue("UID",dbVar,SQL_C_SLONG); |
| 289 |
RS.GetFieldValue("email",dbVar,SQL_C_CHAR); |
|
| 290 |
sql.Format("insert into bbs_recommend(UID,TID,type,dt,email,ip)" |
sql.Format("insert into bbs_msg(fromUID,toUID,content,send_dt,send_ip)" |
| 291 |
" values(%ld,%ld,'D',now(),'%s','%s')", |
" values(%ld,%ld,'%s',now(),'%s')", |
| 292 |
this->innd_uid,aid,dbVar.m_pstring,this->hostaddr); |
this->innd_uid,dbVar.m_lVal,addslashes(msg_content),this->hostaddr); |
| 293 |
this->Db.ExecuteSQL(sql); |
this->Db.ExecuteSQL(sql); |
| 294 |
rid = this->last_insert_id(); |
} |
|
|
|
|
//Send notification message |
|
|
|
|
|
msg_content.Format("[hi]SYS_R_Reply_Article[/hide]" |
|
|
"有人回复了您所发表的文章,快来[url recommend_view.php?id=%ld" |
|
|
"]看看[/url]《%s》吧!\n",rid,addslashes(subject)); |
|
|
|
|
|
RS.GetFieldValue("UID",dbVar,SQL_C_SLONG); |
|
|
sql.Format("insert into bbs_msg(fromUID,toUID,ntent,send_dt,send_ip)" |
|
|
" valulues(%ld,%ld,'%s',now(),'%s')", |
|
|
this->innd_uid,dbVar.m_lVal,addslashes(msg_connt),ththis->hostaddr); |
|
|
this->Db.ExecuteSQL(sql); |
|
|
} |
|
|
} |
|
| 295 |
RS.Close(); |
RS.Close(); |
| 296 |
} |
} |
| 297 |
|
|
| 298 |
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" |
| 299 |
"(%ld,%ld,'%s','I')", |
"(%ld,%ld,'%s','I')", |
| 300 |
aid,art_id,addslashes(msg_id)); |
aid,art_id,addslashes(msg_id)); |
| 301 |
this->Db.ExecuteSQL(sql); |
this->Db.ExecuteSQL(sql); |
| 307 |
} |
} |
| 308 |
catch(CException* e) |
catch(CException* e) |
| 309 |
{ |
{ |
| 310 |
syslog << logfile::log_head << "Error in bbs_post()" << endl; |
char strErrMsg[1024]; |
| 311 |
|
e->GetErrorMessage(strErrMsg,1024); |
| 312 |
|
syslog << logfile::log_head << "Error in bbs_post() [" << strErrMsg << "]" << endl; |
| 313 |
e->Delete(); |
e->Delete(); |
| 314 |
return -1; |
return -1; |
| 315 |
} |
} |
| 382 |
this->Db.ExecuteSQL(sql); |
this->Db.ExecuteSQL(sql); |
| 383 |
|
|
| 384 |
//Add logfile |
//Add logfile |
| 385 |
sql.Format("insert delayed into bbs_article_op(AID,UID,type,op_dt," |
sql.Format("insert delayed into bbs_article_op(AID,UID,type,op_dt,op_ip)" |
| 386 |
"op_ip,complete) values(%ld,%ld,'C',now(),'%s',1)", |
" values(%ld,%ld,'C',now(),'%s')", |
| 387 |
id,innd_uid,this->hostaddr); |
id,innd_uid,this->hostaddr); |
| 388 |
this->Db.ExecuteSQL(sql); |
this->Db.ExecuteSQL(sql); |
| 389 |
|
|
| 394 |
this->Db.ExecuteSQL(sql); |
this->Db.ExecuteSQL(sql); |
| 395 |
} |
} |
| 396 |
|
|
| 397 |
sql.Format("update innd_logfile set cancel=1 where AID=%ld",id); |
sql.Format("update innd_log set cancel=1 where AID=%ld",id); |
| 398 |
this->Db.ExecuteSQL(sql); |
this->Db.ExecuteSQL(sql); |
| 399 |
} |
} |
| 400 |
RS.Close(); |
RS.Close(); |
| 401 |
} |
} |
| 402 |
catch(CException* e) |
catch(CException* e) |
| 403 |
{ |
{ |
| 404 |
syslog << logfile::log_head << "Getting article error in bbs_delete()" << endl; |
char strErrMsg[1024]; |
| 405 |
|
e->GetErrorMessage(strErrMsg,1024); |
| 406 |
|
syslog << logfile::log_head << "Getting article error in bbs_delete() [" << strErrMsg << "]" << endl; |
| 407 |
e->Delete(); |
e->Delete(); |
| 408 |
return -1; |
return -1; |
| 409 |
} |
} |
| 433 |
return 0; |
return 0; |
| 434 |
} |
} |
| 435 |
|
|
| 436 |
int base::s_receive(CString& out_str, const char* end_str) |
int base::s_receive(CString& out_str, char end_str[]) |
| 437 |
{ |
{ |
| 438 |
char buf_str[2048]; |
char buf_str[2048]; |
| 439 |
int buf_read,total_read; |
int buf_read,total_read; |
| 452 |
out_str += buf_str; |
out_str += buf_str; |
| 453 |
if (out_str.Right((int)strlen(end_str)) == end_str) |
if (out_str.Right((int)strlen(end_str)) == end_str) |
| 454 |
break; |
break; |
| 455 |
|
//different line-end symbol in different OS |
| 456 |
|
if (strcmp(end_str,"\r") == 0) |
| 457 |
|
{ |
| 458 |
|
if (out_str.Right(2) == "\r\n") |
| 459 |
|
break; |
| 460 |
|
} |
| 461 |
} |
} |
| 462 |
} |
} |
| 463 |
catch(CException* e) |
catch(CException* e) |
| 472 |
|
|
| 473 |
int base::begin(void) |
int base::begin(void) |
| 474 |
{ |
{ |
| 475 |
|
HANDLE hThread; |
| 476 |
ULONG ulThreadId; |
ULONG ulThreadId; |
| 477 |
unsigned int time_wait = 0; |
unsigned int time_wait = 0; |
| 478 |
|
|
| 479 |
if (!this->IsShutdown()) |
if (!this->IsShutdown()) |
| 480 |
return 1; |
return 0; |
| 481 |
|
|
| 482 |
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)) |
| 483 |
{ |
{ |
| 484 |
|
CloseHandle(hThread); |
| 485 |
syslog << logfile::log_head << "Create thread ... OK" << endl; |
syslog << logfile::log_head << "Create thread ... OK" << endl; |
| 486 |
} |
} |
| 487 |
else |
else |
| 494 |
{ |
{ |
| 495 |
Sleep(100); |
Sleep(100); |
| 496 |
time_wait += 100; |
time_wait += 100; |
| 497 |
if (time_wait > 10000) //Wait 10 seconds |
if (time_wait > 30000) //Wait 30 seconds |
| 498 |
{ |
{ |
| 499 |
syslog << logfile::log_head << "Module timeout in begin()" << endl; |
syslog << logfile::log_head << "Module timeout in begin()" << endl; |
| 500 |
this->end(); |
this->end(); |
| 508 |
|
|
| 509 |
DWORD base::Thread(LPVOID pParam) |
DWORD base::Thread(LPVOID pParam) |
| 510 |
{ |
{ |
|
HANDLE hThreadCurrent; |
|
| 511 |
base* p; |
base* p; |
| 512 |
|
|
| 513 |
syslog << logfile::log_head << "Thread started." << endl; |
syslog << logfile::log_head << "Thread started." << endl; |
| 514 |
|
|
| 515 |
p = (base*)pParam; |
p = (base*)pParam; |
|
hThreadCurrent = GetCurrentThread(); |
|
| 516 |
|
|
| 517 |
if (p->GetParentThread()->GetThreadPool()->AddThread(hThreadCurrent, CLOCKS_PER_SEC * 30) != 0) |
p->ulMainThreadId = GetCurrentThreadId(); |
| 518 |
|
|
| 519 |
|
if (p->GetParentThread()->GetThreadPool()->AddThread(GetCurrentThreadId(), CLOCKS_PER_SEC * 60) != 0) |
| 520 |
{ |
{ |
| 521 |
syslog << logfile::log_head << "Register thread ... Failed" << endl; |
syslog << logfile::log_head << "Register thread ... Failed" << endl; |
| 522 |
} |
} |
| 523 |
p->GetParentThread()->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WORKING); |
p->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING); |
| 524 |
|
|
| 525 |
p->w_call(); |
p->w_call(); |
| 526 |
|
|
| 527 |
if (p->GetParentThread()->GetThreadPool()->RemoveThread(hThreadCurrent) != 0) |
if (p->GetParentThread()->GetThreadPool()->RemoveThread(GetCurrentThreadId()) != 0) |
| 528 |
{ |
{ |
| 529 |
syslog << logfile::log_head << "Unregister thread ... Failed" << endl; |
syslog << logfile::log_head << "Unregister thread ... Failed" << endl; |
| 530 |
} |
} |
| 568 |
{ |
{ |
| 569 |
return 0; |
return 0; |
| 570 |
} |
} |
| 571 |
|
|
| 572 |
|
bool base::IsThreadActive(void) |
| 573 |
|
{ |
| 574 |
|
bool bIsActive = false; |
| 575 |
|
|
| 576 |
|
switch (this->GetParentThread()->GetThreadPool()->GetThreadStatus(this->ulMainThreadId)) |
| 577 |
|
{ |
| 578 |
|
case thread_pool::S_WAITING: |
| 579 |
|
case thread_pool::S_WORKING: |
| 580 |
|
bIsActive = true; |
| 581 |
|
break; |
| 582 |
|
default: |
| 583 |
|
bIsActive = false; |
| 584 |
|
} |
| 585 |
|
|
| 586 |
|
return bIsActive; |
| 587 |
|
} |