/[LeafOK_CVS]/innwebd/base.cpp
ViewVC logotype

Diff of /innwebd/base.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 by sysadm, Sat Jul 3 13:56:04 2004 UTC Revision 1.10 by sysadm, Fri Sep 17 02:34:27 2004 UTC
# Line 1  Line 1 
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                              */
# Line 22  using namespace std; Line 22  using namespace std;
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)
# Line 30  base::base(void) Line 32  base::base(void)
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)
# Line 232  int base::bbs_post(const CString& head, Line 236  int base::bbs_post(const CString& head,
236                          this->Db.ExecuteSQL(sql); //7671                          this->Db.ExecuteSQL(sql); //7671
237    
238                          //Add logfile                          //Add logfile
239                          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)"
240                                          " values(%ld,%ld,'I',now(),'%s',1)",                                          " values(%ld,%ld,'I',now(),'%s')",
241                                          aid,this->innd_uid,this->hostaddr);                                          aid,this->innd_uid,this->hostaddr);
242                          this->Db.ExecuteSQL(sql);                          this->Db.ExecuteSQL(sql);
243                    
# Line 272  int base::bbs_post(const CString& head, Line 276  int base::bbs_post(const CString& head,
276                                                  this->Db.ExecuteSQL(sql);                                                  this->Db.ExecuteSQL(sql);
277                                                  rid = this->last_insert_id();                                                  rid = this->last_insert_id();
278    
279                                                  //Send notification message                                                  //Send notication message
280    
281                          msg_content.Format("[hi]SYS_R_Reply_Article[/hide]"                            msg_content.Format("[hide]SYS_R_Reply_Article[/hide]"
282                                                          "有人回复了您所发表的文章,快来[url recommend_view.php?id=%ld"                                                          "有人回复了您所发表的文章,快来[url recommend_view.php?id=%ld"
283                                                          "]看看[/url]《%s》吧!\n",rid,addslashes(subject));                                                          "]看看[/url]《%s》吧!\n",rid,addslashes(subject));
284    
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,content,send_dt,send_ip)"
287                                                                  " valulues(%ld,%ld,'%s',now(),'%s')",                                                                  " values(%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);
# Line 300  int base::bbs_post(const CString& head, Line 304  int base::bbs_post(const CString& head,
304          }          }
305          catch(CException* e)          catch(CException* e)
306          {          {
307                  syslog << logfile::log_head << "Error in bbs_post()" << endl;                  char strErrMsg[1024];
308                    e->GetErrorMessage(strErrMsg,1024);
309                    syslog << logfile::log_head << "Error in bbs_post() [" << strErrMsg << "]" << endl;
310                  e->Delete();                  e->Delete();
311                  return -1;                  return -1;
312          }          }
# Line 373  int base::bbs_delete(long id) Line 379  int base::bbs_delete(long id)
379                          this->Db.ExecuteSQL(sql);                          this->Db.ExecuteSQL(sql);
380    
381                          //Add logfile                          //Add logfile
382                          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)"
383                                  "op_ip,complete) values(%ld,%ld,'C',now(),'%s',1)",                                  " values(%ld,%ld,'C',now(),'%s')",
384                                  id,innd_uid,this->hostaddr);                                  id,innd_uid,this->hostaddr);
385                          this->Db.ExecuteSQL(sql);                          this->Db.ExecuteSQL(sql);
386    
# Line 385  int base::bbs_delete(long id) Line 391  int base::bbs_delete(long id)
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[1024];
402                    e->GetErrorMessage(strErrMsg,1024);
403                    syslog << logfile::log_head << "Getting article error in bbs_delete() [" << strErrMsg << "]" << endl;
404                  e->Delete();                  e->Delete();
405                  return -1;                  return -1;
406          }          }
# Line 422  int base::s_send(const char* in_str, boo Line 430  int base::s_send(const char* in_str, boo
430          return 0;          return 0;
431  }  }
432    
433  int base::s_receive(CString& out_str, const char* end_str)  int base::s_receive(CString& out_str, char end_str[])
434  {  {
435          char buf_str[2048];          char buf_str[2048];
436          int buf_read,total_read;          int buf_read,total_read;
# Line 441  int base::s_receive(CString& out_str, co Line 449  int base::s_receive(CString& out_str, co
449                          out_str += buf_str;                          out_str += buf_str;
450                          if (out_str.Right((int)strlen(end_str)) == end_str)                          if (out_str.Right((int)strlen(end_str)) == end_str)
451                                  break;                                  break;
452                            //different line-end symbol in different OS
453                            if (strcmp(end_str,"\r") == 0)
454                            {
455                                    if (out_str.Right(2) == "\r\n")
456                                            break;
457                            }
458                  }                  }
459          }          }
460          catch(CException* e)          catch(CException* e)
# Line 455  int base::s_receive(CString& out_str, co Line 469  int base::s_receive(CString& out_str, co
469    
470  int base::begin(void)  int base::begin(void)
471  {  {
472            HANDLE hThread;
473          ULONG ulThreadId;          ULONG ulThreadId;
474          unsigned int time_wait = 0;          unsigned int time_wait = 0;
475    
476          if (!this->IsShutdown())          if (!this->IsShutdown())
477                  return 1;                  return 1;
478    
479          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))
480          {          {
481                    CloseHandle(hThread);
482                  syslog << logfile::log_head << "Create thread ... OK" << endl;                  syslog << logfile::log_head << "Create thread ... OK" << endl;
483          }          }
484          else          else
# Line 489  int base::begin(void) Line 505  int base::begin(void)
505    
506  DWORD base::Thread(LPVOID pParam)  DWORD base::Thread(LPVOID pParam)
507  {  {
         HANDLE hThreadCurrent;  
508          base* p;          base* p;
509    
510          syslog << logfile::log_head << "Thread started." << endl;          syslog << logfile::log_head << "Thread started." << endl;
511    
512          p = (base*)pParam;          p = (base*)pParam;
         hThreadCurrent = GetCurrentThread();  
513    
514          if (p->GetParentThread()->GetThreadPool()->AddThread(hThreadCurrent, CLOCKS_PER_SEC * 30) != 0)          p->ulMainThreadId = GetCurrentThreadId();
515    
516            if (p->GetParentThread()->GetThreadPool()->AddThread(GetCurrentThreadId(), CLOCKS_PER_SEC * 30) != 0)
517          {          {
518                  syslog << logfile::log_head << "Register thread ... Failed" << endl;                  syslog << logfile::log_head << "Register thread ... Failed" << endl;
519          }          }
520          p->GetParentThread()->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WORKING);          p->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING);
521    
522          p->w_call();          p->w_call();
523    
524          if (p->GetParentThread()->GetThreadPool()->RemoveThread(hThreadCurrent) != 0)          if (p->GetParentThread()->GetThreadPool()->RemoveThread(GetCurrentThreadId()) != 0)
525          {          {
526                  syslog << logfile::log_head << "Unregister thread ... Failed" << endl;                  syslog << logfile::log_head << "Unregister thread ... Failed" << endl;
527          }          }
# Line 549  int base::Startup(void) Line 565  int base::Startup(void)
565  {  {
566          return 0;          return 0;
567  }  }
568    
569    bool base::IsThreadActive(void)
570    {
571            bool bIsActive = false;
572    
573            switch (this->GetParentThread()->GetThreadPool()->GetThreadStatus(this->ulMainThreadId))
574            {
575            case thread_pool::S_WAITING:
576            case thread_pool::S_WORKING:
577                    bIsActive = true;
578                    break;
579            default:
580                    bIsActive = false;
581            }
582    
583            return bIsActive;
584    }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1