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

Diff of /innwebd/controld.cpp

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

Revision 1.4 by sysadm, Sat Jul 3 13:56:04 2004 UTC Revision 1.11 by sysadm, Thu Sep 16 15:38:59 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 35  int controld::Accept(void) Line 35  int controld::Accept(void)
35          CString out,cmd;          CString out,cmd;
36          char temp[256];          char temp[256];
37          int result;          int result;
         HANDLE hThreadCurrent;  
38    
39          try          try
40          {          {
                 hThreadCurrent = GetCurrentThread();  
   
41                  out.Format("200 %s ready.",App_common::GetVersion());                  out.Format("200 %s ready.",App_common::GetVersion());
42                  this->s_send(out);                  this->s_send(out);
43                  while(!this->thread_terminate)                  while(!this->thread_terminate)
44                  {                  {
45                          this->GetParentThread()->GetThreadPool()->SetThreadStatus(hThreadCurrent,thread_pool::S_WAITING);                          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(hThreadCurrent,thread_pool::S_WORKING);                          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    
# Line 142  int controld::Accept(void) Line 139  int controld::Accept(void)
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    
# Line 182  int controld::Accept(void) Line 179  int controld::Accept(void)
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 = "";
# Line 195  int controld::Accept(void) Line 192  int controld::Accept(void)
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);
# Line 203  int controld::Accept(void) Line 203  int controld::Accept(void)
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
# Line 379  int controld::load_conf(const char* conf Line 382  int controld::load_conf(const char* conf
382          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);
383          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);
384    
         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;  
         }  
   
385          return 0;          return 0;
386  }  }
387    
# Line 439  void controld::StartupChild(void) Line 426  void controld::StartupChild(void)
426    
427  void controld::StartupDelay(void)  void controld::StartupDelay(void)
428  {  {
429            syslog << logfile::log_head << "Startup delay for " <<
430                    this->startup_delay << " seconds"<< endl;
431    
432          Sleep(this->startup_delay * 1000);          Sleep(this->startup_delay * 1000);
433  }  }
434    
435  void controld::ShutdownChild(void)  void controld::ShutdownChild(void)
436  {  {
437          if (this->bbsd.end() == 0)          if (this->bbsd.IsRunning())
         {  
                 syslog << logfile::log_head << "End BBSD ... OK" << endl;  
         }  
         else  
438          {          {
439                  syslog << logfile::log_head << "End BBSD ... Failed" << endl;                  if (this->bbsd.end() == 0)
440                    {
441                            syslog << logfile::log_head << "End BBSD ... OK" << endl;
442                    }
443                    else
444                    {
445                            syslog << logfile::log_head << "End BBSD ... Failed" << endl;
446                    }
447          }          }
448    
449          if (this->innd.end() == 0)          if (this->innd.IsRunning())
450          {          {
451                  syslog << logfile::log_head << "End INND ... OK" << endl;                  if (this->innd.end() == 0)
452          }                  {
453          else                          syslog << logfile::log_head << "End INND ... OK" << endl;
454          {                  }
455                  syslog << logfile::log_head << "End INND ... Failed" << endl;                  else
456                    {
457                            syslog << logfile::log_head << "End INND ... Failed" << endl;
458                    }
459          }          }
460    
461          if (this->outd.end() == 0)          if (this->outd.IsRunning())
462          {          {
463                  syslog << logfile::log_head << "End OUTD ... OK" << endl;                  if (this->outd.end() == 0)
464                    {
465                            syslog << logfile::log_head << "End OUTD ... OK" << endl;
466                    }
467                    else
468                    {
469                            syslog << logfile::log_head << "End OUTD ... Failed" << endl;
470                    }
471          }          }
472          else  }
473    
474    int controld::InitThreadPool(void)
475    {
476            base* p_ParentThread;
477    
478            p_ParentThread = new controld();
479    
480            this->SetParentThread(p_ParentThread);
481            this->bbsd.SetParentThread(p_ParentThread);
482            this->innd.SetParentThread(p_ParentThread);
483            this->outd.SetParentThread(p_ParentThread);
484    
485            p_ParentThread->SetThreadPool(new thread_pool(TS_MAX_THREAD));
486    
487            if (p_ParentThread->GetThreadPool()->GetLastError() != 0)
488          {          {
489                  syslog << logfile::log_head << "End OUTD ... Failed" << endl;                  syslog << logfile::log_head << "Create Thread Pool ... failed" << endl;
490          }          }
491    
492            return 0;
493    }
494    
495    int controld::CleanupThreadPool(void)
496    {
497            delete(this->GetParentThread());
498    
499            return 0;
500    }
501    
502    bool controld::check_priv(void)
503    {
504            return this->access.control;
505  }  }


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

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