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

Annotation of /innwebd/controld.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Fri Jul 2 11:28:46 2004 UTC (21 years, 8 months ago) by sysadm
Branch: MAIN
Content type: text/x-c++src
nntp_control.cpp

1 sysadm 1.1 /*******************************************************/
2     /* */
3     /* LeafOK Innd */
4     /* Copyright (C) LeafOK.com, 2003-2004 */
5     /* */
6     /* Programmed by Leaf */
7     /* E-mail:leaf@leafok.com QQ:6049044 */
8     /* */
9     /* http://bbs.leafok.com */
10     /* http://bbs.leafok.net */
11     /* http://bbs.fenglin.info */
12     /* */
13     /*******************************************************/
14    
15     #include "StdAfx.h"
16     #include ".\controld.h"
17     #include ".\nntp_active.h"
18     #include ".\App_common.h"
19    
20     using namespace std;
21    
22     bool controld::thread_terminate = true;
23    
24     controld::controld(void)
25     :bbsd_startup(false),innd_startup(false),outd_startup(false),startup_delay(0)
26     {
27     }
28    
29     controld::~controld(void)
30     {
31     }
32    
33     int controld::Accept(void)
34     {
35     CString out,cmd;
36     char temp[256];
37     int result;
38    
39     try
40     {
41     out.Format("200 %s ready.",App_common::GetVersion());
42     this->s_send(out);
43     while(!this->thread_terminate)
44     {
45     if (this->s_receive(out) == 0) //Connection closed
46     break;
47     out.Trim();
48    
49     syslog << logfile::log_head << "Cmd: " << out << endl;
50    
51     if (sscanf(out,"%20s",temp) ==1)
52     cmd = strupr(temp);
53     else
54     cmd = "";
55    
56     if (cmd == "") //Blank command
57     continue;
58    
59     if (cmd == "START")
60     {
61     if (sscanf(out,"%*s %20s",temp) ==1)
62     cmd = strupr(temp);
63     else
64     cmd = "";
65     cmd.Trim();
66    
67     if (cmd == "BBSD" || cmd == "INND" || cmd == "OUTD")
68     {
69     if (this->access.control)
70     {
71     out.Format("Starting %s ... ",cmd);
72     this->s_send(out,false);
73    
74     if (cmd == "BBSD")
75     {
76     result = ((controld*)(this->p_ParentThread))->bbsd.begin();
77     }
78     if (cmd == "INND")
79     {
80     result = ((controld*)(this->p_ParentThread))->innd.begin();
81     }
82     if (cmd == "OUTD")
83     {
84     result = ((controld*)(this->p_ParentThread))->outd.begin();
85     }
86    
87     this->s_send(result == 0 ? "OK" : "Failed");
88     }
89     else
90     {
91     this->s_send("400 Forbidden");
92     }
93     }
94     else
95     {
96     this->s_send("501 service");
97     }
98     continue;
99     }
100    
101     if (cmd == "STOP")
102     {
103     if (sscanf(out,"%*s %20s",temp) ==1)
104     cmd = strupr(temp);
105     else
106     cmd = "";
107     cmd.Trim();
108    
109     if (cmd == "BBSD" || cmd == "INND" || cmd == "OUTD")
110     {
111     if (this->access.control)
112     {
113     out.Format("Stopping %s ... ",cmd);
114     this->s_send(out,false);
115    
116     if (cmd == "BBSD")
117     {
118     result = ((controld*)(this->p_ParentThread))->bbsd.end();
119     }
120     if (cmd == "INND")
121     {
122     result = ((controld*)(this->p_ParentThread))->innd.end();
123     }
124     if (cmd == "OUTD")
125     {
126     result = ((controld*)(this->p_ParentThread))->outd.end();
127     }
128    
129     this->s_send(result == 0 ? "OK" : "Failed");
130     }
131     else
132     {
133     this->s_send("400 Forbidden");
134     }
135     }
136     else
137     {
138     this>s_send("501 service");
139     }
140     contiinue;
141     }
142    
143     if (cmd == "SHUTDOWN")
144     {
145     if (this->access.control)
146     {
147     this->_send("Shutting down ... ",falsse);
148    
149     ((controld*)(this->p_ParentThread))->ShutdownChild();
150    
151     this->s_send("OK");
152    
153     ((controld*)(this->p_ParentThread))->Shutdown();
154     break;
155     }
156     else
157     {
158     this->s_send("400 Forbidden");
159     }
160     continue;
161     }
162    
163     if (cmd == "RELOAD_PRIV")
164     {
165     this->s_send("Reloading prev_list ... ",false);
166    
167     ((controld*)(this->p_ParentThread))->unload_priv();
168     if (((controld*)(this->p_ParentThread))->load_priv() == 0)
169     this->s_send("OK");
170     else
171     this->s_send("Failed");
172    
173     continue;
174     }
175    
176     if (cmd == "ACTIVE")
177     {
178     if (sscanf(out,"%*s %0s",temp) == 1)
179     cmd = struupr(temp);
180     else
181     cmd = "";
182     cmd.Trim();
183    
184     if (cmd == "POST" || cmd == "IHAVE")
185     {
186     if (this->access.control)
187     {
188     this->s_send("201 Entering native mode");
189     nntp_active nntpClient;
190     nntpClient.configure(this->innd_id,this->innd_name,this->innd_server,this->innd_uid,"",0,this->w_conn_str);
191     if (cmd == "POST") // Get & Post
192     {
193     nntpClient.work(true,false);
194     }
195     if (cmd == "IHAVE") // IHAVE only
196     {
197     nntpClient.work(false,true);
198     }
199     this->s_send("Entering passive mode\r\n.");
200     }
201     else
202     {
203     this->s_send("400 Forbidden");
204     }
205     }
206     else
207     {
208     this->s_send("501 mode server port");
209     }
210     continue;
211     }
212    
213     if (cmd == "QUIT")
214     {
215     this->s_send("205 .\r\n");
216     break;
217     }
218    
219     this->s_send("500 What?");
220     }
221     }
222     catch(CException* e)
223     {
224     syslog << logfile::log_head << "Error in accept()" << endl;
225     e->Delete();
226     return -1;
227     }
228    
229     return 0;
230     }
231    
232     controld* controld::new_client(void)
233     {
234     return (new controld());
235     }
236    
237     bool controld::IsShutdown(void)
238     {
239     return this->thread_terminate;
240     }
241    
242     int controld::Shutdown(void)
243     {
244     nntp_active nntpClient;
245    
246     if (this->thread_terminate)
247     return 1;
248    
249     this->thread_terminate = true;
250     nntpClient.configure(this->innd_id,this->innd_name,this->innd_server,this->innd_uid,this->w_address,0,this->w_conn_str);
251     nntpClient.s_connect((strlen(this->hostaddr)>0 ? this->hostaddr : "127.0.0.1"),this->port);
252     nntpClient.s_close();
253    
254     return 0;
255     }
256    
257     int controld::Startup(void)
258     {
259     if (!this->thread_terminate)
260     return 1;
261    
262     this->thread_terminate = false;
263    
264     return 0;
265     }
266    
267     int controld::db_env_init(void)
268     {
269     return 0;
270     }
271    
272     int controld::load_conf(const char* conf_file)
273     {
274     // Innd settings
275     char innd_id[50] = "";
276     char innd_name[50] = "";
277     char innd_server[256] = "";
278     unsigned long innd_uid = 0;
279     char innd_address[50] = "";
280     unsigned int bbsd_port = 0;
281     unsigned int innd_port = 0;
282     unsigned int ctrl_port = 0;
283     char conn_str[256] = "";
284     unsigned int if_startup = 0;
285    
286     // Load configuration
287     try
288     {
289     char c_name[256];
290     FILE * fin;
291    
292     if ((fin = fopen(conf_file,"r")) == NULL)
293     {
294     syslog << logfile::log_head << "Open innd.conf failed" << endl;
295     return -1;
296     }
297    
298     while(fscanf(fin,"%s",c_name) != EOF)
299     {
300     if (c_name[0] == '#')
301     continue;
302     fscanf(fin,"%*c");
303     strlwr(c_name);
304     if (strcmp(c_name,"innd_id")==0)
305     {
306     fscanf(fin,"%s",innd_id);
307     }
308     if (strcmp(c_name,"innd_name")==0)
309     {
310     fscanf(fin,"%s",innd_name);
311     }
312     if (strcmp(c_name,"innd_server")==0)
313     {
314     fscanf(fin,"%s",innd_server);
315     }
316     if (strcmp(c_name,"innd_uid")==0)
317     {
318     fscanf(fin,"%ul",&innd_uid);
319     }
320     if (strcmp(c_name,"innd_address")==0)
321     {
322     fscanf(fin,"%s",innd_address);
323     }
324     if (strcmp(c_name,"bbsd_port")==0)
325     {
326     fscanf(fin,"%ud",&bbsd_port);
327     }
328     if (strcmp(c_name,"innd_port")==0)
329     {
330     fscanf(fin,"%ud",&innd_port);
331     }
332     if (strcmp(c_name,"ctrl_port")==0)
333     {
334     fscanf(fin,"%ud",&ctrl_port);
335     }
336     if (strcmp(c_name,"bbsd_startup")==0)
337     {
338     fscanf(fin,"%ud",&if_startup);
339     this->bbsd_startup = (if_startup > 0);
340     }
341     if (strcmp(c_name,"innd_startup")==0)
342     {
343     fscanf(fin,"%ud",&if_startup);
344     this->innd_startup = (if_startup > 0);
345     }
346     if (strcmp(c_name,"outd_startup")==0)
347     {
348     fscanf(fin,"%ud",&if_startup);
349     this->outd_startup = (if_startup > 0);
350     }
351     if (strcmp(c_name,"startup_delay")==0)
352     {
353     fscanf(fin,"%ud",&(this->startup_delay));
354     }
355     if (strcmp(c_name,"conn_str")==0)
356     {
357     fgets(conn_str,255,fin);
358     }
359     }
360    
361     fclose(fin);
362     }
363     catch(CException* e)
364     {
365     syslog << logfile::log_head << "Load configuration failed" << endl;
366     e->Delete();
367     return -1;
368     }
369    
370     this->configure(innd_id,innd_name,innd_server,innd_uid,innd_address,ctrl_port,conn_str);
371     this->bbsd.configure(innd_id,innd_name,innd_server,innd_uid,innd_address,bbsd_port,conn_str);
372     this->innd.configure(innd_id,innd_name,innd_server,innd_uid,innd_address,innd_port,conn_str);
373     this->outd.configure(innd_id,innd_name,innd_server,innd_uid,innd_address,0,conn_str);
374    
375     return 0;
376     }
377    
378     void controld::StartupChild(void)
379     {
380     if (this->bbsd_startup)
381     {
382     if (this->bbsd.begin() == 0)
383     {
384     syslog << logfile::log_head << "Begin BBSD ... OK" << endl;
385     }
386     else
387     {
388     syslog << logfile::log_head << "Begin BBSD ... Failed" << endl;
389     }
390     }
391    
392     if (this->innd_startup)
393     {
394     if (this->innd.begin() == 0)
395     {
396     syslog << logfile::log_head << "Begin INND ... OK" << endl;
397     }
398     else
399     {
400     syslog << logfile::log_head << "Begin INND ... Failed" << endl;
401     }
402     }
403    
404     if (this->outd_startup)
405     {
406     if (this->outd.begin() == 0)
407     {
408     syslog << logfile::log_head << "Begin OUTD ... OK" << endl;
409     }
410     else
411     {
412     syslog << logfile::log_head << "Begin OUTD ... Failed" << endl;
413     }
414     }
415     }
416    
417     void controld::StartupDelay(void)
418     {
419     Sleep(this->startup_delay * 1000);
420     }
421    
422     void controld::ShutdownChild(void)
423     {
424     if (this->bbsd.end() == 0)
425     {
426     syslog << logfile::log_head << "End BBSD ... OK" << endl;
427     }
428     else
429     {
430     syslog << logfile::log_head << "End BBSD ... Failed" << endl;
431     }
432    
433     if (this->innd.end() == 0)
434     {
435     syslog << logfile::log_head << "End INND ... OK" << endl;
436     }
437     else
438     {
439     syslog << logfile::log_head << "End INND ... Failed" << endl;
440     }
441    
442     if (this->outd.end() == 0)
443     {
444     syslog << logfile::log_head << "End OUTD ... OK" << endl;
445     }
446     else
447     {
448     syslog << logfile::log_head << "End OUTD ... Failed" << endl;
449     }
450     }

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