Rev 7491 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10 | reyssat | 1 | /* Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis |
2 | * |
||
3 | * This program is free software; you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation; either version 2 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program; if not, write to the Free Software |
||
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
||
16 | */ |
||
17 | |||
18 | /* daemon command processing */ |
||
19 | |||
20 | /* testing routine. Don't touch! */ |
||
21 | void cmd_test(char *p) |
||
22 | { |
||
23 | } |
||
24 | |||
25 | void cmd_ping(char *p) |
||
26 | { |
||
27 | char *p1; |
||
28 | int qtest; |
||
29 | p1=find_word_start(p); *find_word_end(p1)=0; |
||
30 | if(*p1!=0 && qbuf[0]!=0 && wordchr(qbuf,p1)!=NULL) qtest=1; else qtest=0; |
||
31 | snprintf(textbuf+3,MAX_LINELEN,"%d %s\n%s",qtest,loadavg,ipbuf); |
||
32 | } |
||
33 | |||
34 | void cmd_forklist(char *p) |
||
35 | { |
||
36 | snprintf(textbuf+3,MAX_LINELEN,"%d",forkcnt); |
||
37 | } |
||
38 | |||
39 | void cmd_readfile(char *p) |
||
40 | { |
||
41 | char *cut[2]; |
||
42 | int l; |
||
43 | cutwords(p,cut,2); |
||
44 | if(cut[1][0]) l=evalue(cut[1]); else l=MAX_LINELEN-16; |
||
45 | if(l<=0 || cut[0][0]==0) return; |
||
46 | if(l>BUFFERLEN-16) l=BUFFERLEN-16; |
||
47 | readfile(cut[0],textbuf+3,l); |
||
48 | } |
||
49 | |||
50 | void cmd_record(char *p) |
||
51 | { |
||
52 | char *cut[2]; |
||
53 | cutwords(p,cut,2); |
||
54 | if(cut[1][0]==0) return; |
||
55 | datafile_fnd_record(cut[1],atoi(cut[0]),textbuf+3); |
||
56 | } |
||
57 | |||
58 | void cmd_recordcnt(char *p) |
||
59 | { |
||
60 | char *p1; |
||
61 | p1=find_word_start(p); |
||
62 | if(*p1==0) return; |
||
63 | *find_word_end(p1)=0; |
||
64 | snprintf(textbuf+3,16,"%d",datafile_recordnum(p1)); |
||
65 | } |
||
66 | |||
67 | struct { |
||
68 | char *name; |
||
69 | void (*routine) (char *p); |
||
70 | } cmdlist[]={ |
||
71 | {"forkcnt", cmd_forklist}, |
||
72 | {"forkcount", cmd_forklist}, |
||
73 | {"forklist", cmd_forklist}, |
||
74 | {"getscore", cmd_getscore}, |
||
75 | {"ping", cmd_ping}, |
||
76 | {"readfile", cmd_readfile}, |
||
77 | {"record", cmd_record}, |
||
78 | {"recordcnt", cmd_recordcnt}, |
||
79 | {"recordcount", cmd_recordcnt}, |
||
80 | {"recordno", cmd_recordcnt}, |
||
81 | {"recordnum", cmd_recordcnt}, |
||
82 | {"scorelog", cmd_scorelog}, |
||
83 | {"test", cmd_test}, |
||
84 | }; |
||
85 | #define cmdcnt (sizeof(cmdlist)/sizeof(cmdlist[0])) |
||
86 | |||
87 | void cmd(void) |
||
88 | { |
||
89 | char *p1, *p2, cmdline[MAX_LINELEN+1]; |
||
90 | int i; |
||
91 | |||
92 | errno=0; |
||
93 | p1=find_word_start(textptr); p2=find_word_end(p1); |
||
94 | if(*p2) *p2++=0; |
||
95 | i=search_list(cmdlist,cmdcnt,sizeof(cmdlist[0]),p1); |
||
96 | if(i<0) {sockerror(2,"bad_cmd %s",p1); return;} |
||
97 | mystrncpy(cmdline,find_word_start(p2),sizeof(cmdline)); |
||
98 | memmove(textbuf,"OK\n",4); |
||
99 | cmdlist[i].routine(cmdline); |
||
100 | } |
||
101 |