/[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.3 by sysadm, Sat Jul 3 05:35:02 2004 UTC Revision 1.13 by sysadm, Fri May 20 14:32:36 2005 UTC
# Line 1  Line 1 
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                              */
# Line 42  int controld::Accept(void) Line 42  int controld::Accept(void)
42                  this->s_send(out);                  this->s_send(out);
43                  while(!this->thread_terminate)                  while(!this->thread_terminate)
44                  {                  {
45                            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(GetCurrentThreadId(),thread_pool::S_WORKING);
52    
53                          syslog << logfile::log_head << "Cmd: " << out << endl;                          syslog << logfile::log_head << "Cmd: " << out << endl;
54    
55                          if (sscanf(out,"%20s",temp) ==1)                          if (sscanf(out,"%20s",temp) ==1)
# Line 73  int controld::Accept(void) Line 77  int controld::Accept(void)
77    
78                                                  if (cmd == "BBSD")                                                  if (cmd == "BBSD")
79                                                  {                                                  {
80                                                          result = ((controld*)(this->p_ParentThread))->bbsd.begin();                                                          result = ((controld*)(this->GetParentThread()))->bbsd.begin();
81                                                  }                                                  }
82                                                  if (cmd == "INND")                                                  if (cmd == "INND")
83                                                  {                                                  {
84                                                          result = ((controld*)(this->p_ParentThread))->innd.begin();                                                          result = ((controld*)(this->GetParentThread()))->innd.begin();
85                                                  }                                                  }
86                                                  if (cmd == "OUTD")                                                  if (cmd == "OUTD")
87                                                  {                                                  {
88                                                          result = ((controld*)(this->p_ParentThread))->outd.begin();                                                          result = ((controld*)(this->GetParentThread()))->outd.begin();
89                                                  }                                                  }
90    
91                                                  this->s_send(result == 0 ? "OK" : "Failed");                                                  this->s_send(result == 0 ? "OK" : "Failed");
92    
93                                                    syslog << logfile::log_head << "Begin " << cmd << " ... " << (result == 0 ? "OK" : "Failed") << endl;
94                                          }                                          }
95                                          else                                          else
96                                          {                                          {
# Line 115  int controld::Accept(void) Line 121  int controld::Accept(void)
121    
122                                                  if (cmd == "BBSD")                                                  if (cmd == "BBSD")
123                                                  {                                                  {
124                                                          result = ((controld*)(this->p_ParentThread))->bbsd.end();                                                          result = ((controld*)(this->GetParentThread()))->bbsd.end();
125                                                  }                                                  }
126                                                  if (cmd == "INND")                                                  if (cmd == "INND")
127                                                  {                                                  {
128                                                          result = ((controld*)(this->p_ParentThread))->innd.end();                                                          result = ((controld*)(this->GetParentThread()))->innd.end();
129                                                  }                                                  }
130                                                  if (cmd == "OUTD")                                                  if (cmd == "OUTD")
131                                                  {                                                  {
132                                                          result = ((controld*)(this->p_ParentThread))->outd.end();                                                          result = ((controld*)(this->GetParentThread()))->outd.end();
133                                                  }                                                  }
134    
135                                                  this->s_send(result == 0 ? "OK" : "Failed");                                                  this->s_send(result == 0 ? "OK" : "Failed");
136    
137                                                    syslog << logfile::log_head << "End " << cmd << " ... " << (result == 0 ? "OK" : "Failed") << endl;
138                                          }                                          }
139                                          else                                          else
140                                          {                                          {
# Line 135  int controld::Accept(void) Line 143  int controld::Accept(void)
143                                  }                                  }
144                                  else                                  else
145                                  {                                  {
146                                          this>s_send("501 service");                                          this->s_send("501 service");
147                                  }                                  }
148                                  contiinue;                                  continue;
149                          }                          }
150    
151                          if (cmd == "SHUTDOWN")                          if (cmd == "SHUTDOWN")
152                          {                          {
153                                  if (this->access.control)                                  if (this->access.control)
154                                  {                                  {
155                                          this->_send("Shutting down ... ",falsse);                                          this->s_send("Shutting down ... ",false);
156    
157                                          ((controld*)(this->p_ParentThread))->ShutdownChild();                                          ((controld*)(this->GetParentThread()))->ShutdownChild();
158    
159                                          this->s_send("OK");                                          this->s_send("OK");
160    
161                                          ((controld*)(this->p_ParentThread))->Shutdown();                                          ((controld*)(this->GetParentThread()))->Shutdown();
162                                          break;                                          break;
163                                  }                                  }
164                                  else                                  else
# Line 164  int controld::Accept(void) Line 172  int controld::Accept(void)
172                          {                          {
173                                  this->s_send("Reloading prev_list ... ",false);                                  this->s_send("Reloading prev_list ... ",false);
174    
175                                  ((controld*)(this->p_ParentThread))->unload_priv();                                  ((controld*)(this->GetParentThread()))->unload_priv();
176                                  if (((controld*)(this->p_ParentThread))->load_priv() == 0)                                  if (((controld*)(this->GetParentThread()))->load_priv() == 0)
177                                          this->s_send("OK");                                          this->s_send("OK");
178                                  else                                  else
179                                          this->s_send("Failed");                                          this->s_send("Failed");
# Line 175  int controld::Accept(void) Line 183  int controld::Accept(void)
183    
184                          if (cmd == "ACTIVE")                          if (cmd == "ACTIVE")
185                          {                          {
186                                  if (sscanf(out,"%*s %0s",temp) == 1)                                  if (sscanf(out,"%*s %20s",temp) == 1)
187                                          cmd = strupr(temp);                                          cmd = strupr(temp);
188                                  else                                  else
189                                          cmd = "";                                          cmd = "";
# Line 188  int controld::Accept(void) Line 196  int controld::Accept(void)
196                                                  this->s_send("201 Entering native mode");                                                  this->s_send("201 Entering native mode");
197                                                  base_active nntpClient;                                                  base_active nntpClient;
198                                                  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);
199    
200                                                    this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WAITING);
201    
202                                                  if (cmd == "POST") // Get & Post                                                  if (cmd == "POST") // Get & Post
203                                                  {                                                  {
204                                                          nntpClient.work(true,false);                                                          nntpClient.work(true,false);
# Line 196  int controld::Accept(void) Line 207  int controld::Accept(void)
207                                                  {                                                  {
208                                                          nntpClient.work(false,true);                                                          nntpClient.work(false,true);
209                                                  }                                                  }
210    
211                                                    this->GetParentThread()->GetThreadPool()->SetThreadStatus(GetCurrentThreadId(),thread_pool::S_WORKING);
212    
213                                                  this->s_send("Entering passive mode\r\n.");                                                  this->s_send("Entering passive mode\r\n.");
214                                          }                                          }
215                                          else                                          else
# Line 416  void controld::StartupChild(void) Line 430  void controld::StartupChild(void)
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())
454          {          {
455                  syslog << logfile::log_head << "End INND ... OK" << endl;                  if (this->innd.end() == 0)
456          }                  {
457          else                          syslog << logfile::log_head << "End INND ... OK" << endl;
458          {                  }
459                  syslog << logfile::log_head << "End INND ... Failed" << endl;                  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  }  }


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

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