Subversion Repositories wimsdev

Rev

Rev 7491 | Go to most recent revision | Details | Compare with Previous | 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
 */
8185 bpr 17
#include "wimslogd.h"
10 reyssat 18
 
19
/* daemon command processing */
20
 
7491 bpr 21
/* testing routine. Don't touch! */
10 reyssat 22
void cmd_test(char *p)
23
{
24
}
25
 
26
void cmd_ping(char *p)
27
{
28
    char *p1;
29
    int qtest;
30
    p1=find_word_start(p); *find_word_end(p1)=0;
31
    if(*p1!=0 && qbuf[0]!=0 && wordchr(qbuf,p1)!=NULL) qtest=1; else qtest=0;
32
    snprintf(textbuf+3,MAX_LINELEN,"%d %s\n%s",qtest,loadavg,ipbuf);
33
}
34
 
35
void cmd_forklist(char *p)
36
{
37
    snprintf(textbuf+3,MAX_LINELEN,"%d",forkcnt);
38
}
39
 
40
void cmd_readfile(char *p)
41
{
42
    char *cut[2];
43
    int l;
44
    cutwords(p,cut,2);
45
    if(cut[1][0]) l=evalue(cut[1]); else l=MAX_LINELEN-16;
46
    if(l<=0 || cut[0][0]==0) return;
47
    if(l>BUFFERLEN-16) l=BUFFERLEN-16;
48
    readfile(cut[0],textbuf+3,l);
49
}
50
 
51
void cmd_record(char *p)
52
{
53
    char *cut[2];
54
    cutwords(p,cut,2);
55
    if(cut[1][0]==0) return;
56
    datafile_fnd_record(cut[1],atoi(cut[0]),textbuf+3);
57
}
58
 
59
void cmd_recordcnt(char *p)
60
{
61
    char *p1;
62
    p1=find_word_start(p);
63
    if(*p1==0) return;
64
    *find_word_end(p1)=0;
65
    snprintf(textbuf+3,16,"%d",datafile_recordnum(p1));
66
}
67
 
8185 bpr 68
struct cmdlist cmdlist[]={
7491 bpr 69
        {"forkcnt",    cmd_forklist},
70
        {"forkcount",    cmd_forklist},
71
        {"forklist",    cmd_forklist},
72
        {"getscore",    cmd_getscore},
73
        {"ping",    cmd_ping},
74
        {"readfile",    cmd_readfile},
75
        {"record",    cmd_record},
76
        {"recordcnt",    cmd_recordcnt},
77
        {"recordcount",    cmd_recordcnt},
78
        {"recordno",    cmd_recordcnt},
79
        {"recordnum",    cmd_recordcnt},
80
        {"scorelog",    cmd_scorelog},
81
        {"test",    cmd_test},
10 reyssat 82
};
8185 bpr 83
int cmdcnt=(sizeof(cmdlist)/sizeof(cmdlist[0]));
10 reyssat 84
 
85
void cmd(void)
86
{
87
    char *p1, *p2, cmdline[MAX_LINELEN+1];
88
    int i;
7491 bpr 89
 
10 reyssat 90
    errno=0;
91
    p1=find_word_start(textptr); p2=find_word_end(p1);
92
    if(*p2) *p2++=0;
93
    i=search_list(cmdlist,cmdcnt,sizeof(cmdlist[0]),p1);
94
    if(i<0) {sockerror(2,"bad_cmd %s",p1); return;}
95
    mystrncpy(cmdline,find_word_start(p2),sizeof(cmdline));
96
    memmove(textbuf,"OK\n",4);
97
    cmdlist[i].routine(cmdline);
98
}
99