1 /*
2  * control-proto.h - control protocol header definitions
3  *
4  * Copyright (C) 2011-2013 Thien-Thi Nguyen
5  * Copyright (C) 2000, 2001, 2002 Stefan Jahn <stefan@lkcc.org>
6  *
7  * This is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this package.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef __CONTROL_PROTO_H__
22 #define __CONTROL_PROTO_H__
23 
24 #define STAT_BUFFER_SIZE 256
25 
26 /*
27  * System statistics structure.
28  */
29 typedef struct
30 {
31 #if HAVE_PROC_STAT
32   char *cpufile;                /* CPU state file under Linux */
33   char *cpuline;                /* CPU line format under Linux */
34 #endif /* HAVE_PROC_STAT */
35   char *cpuinfoline;            /* the info format string */
36   char info[STAT_BUFFER_SIZE];  /* the info line itself */
37   char pinfo[STAT_BUFFER_SIZE]; /* process info itself */
38   unsigned long cpu[2][4];      /* cpu values */
39   unsigned long total[2];
40   unsigned long proc[2][4];     /* process values */
41   unsigned long ptotal[2];
42   int index;                    /* index for cpu differences */
43 }
44 cpu_state_t;
45 
46 /*
47  * Control protocol server configuration.
48  */
49 typedef struct
50 {
51   int nothing; /* (yet) */
52 }
53 ctrl_config_t;
54 
55 /* Export the control server definition.  */
56 extern svz_servertype_t ctrl_server_definition;
57 
58 /* server functions */
59 int ctrl_init (svz_server_t *server);
60 int ctrl_finalize (svz_server_t *server);
61 char *ctrl_info_server (svz_server_t *server);
62 char *ctrl_info_client (svz_server_t *server, svz_socket_t *sock);
63 
64 /* basic protocol functions */
65 int ctrl_detect_proto (svz_server_t *server, svz_socket_t *sock);
66 int ctrl_connect_socket (svz_server_t *server, svz_socket_t *sock);
67 
68 int ctrl_idle (svz_socket_t *sock);
69 int ctrl_handle_request (svz_socket_t *sock, char *request, int len);
70 
71 #define CTRL_FLAG_PASSED          0x0001
72 #define CTRL_PACKET_DELIMITER     "\n"
73 #define CTRL_PACKET_DELIMITER_LEN 1
74 
75 #if HAVE_TIMES
76 # define PROC_FORMAT \
77   "user %ld.%01ld%%, sys %ld.%01ld%%, " \
78   "child user %ld.%01ld%%, child sys %ld.%01ld%%"
79 #else
80 # define PROC_FORMAT \
81   "process %ld.%01ld%%"
82 #endif
83 
84 #if HAVE_PROC_STAT
85 # define CPU_FILE_NAME   "/proc/stat"
86 # define CPU_LINE_FORMAT "cpu  %lu %lu %lu %lu"
87 #endif /* HAVE_PROC_STAT */
88 
89 /* welcome message */
90 #define CTRL_PASSWD "Welcome to serveez control center. " \
91                     "Please login.\r\n\r\n" \
92                     "Password: "
93 
94 /* the control protocol client prompt */
95 #define CTRL_PROMPT "ctrl-sh $ "
96 
97 /* the receive and send buffer size of an control protocol client */
98 #define CTRL_RECV_BUFSIZE 512
99 #define CTRL_SEND_BUFSIZE 1024 * 100
100 
101 /* how often we update the CPU information (in seconds) */
102 #define CTRL_LOAD_UPDATE 1
103 
104 /* these are all available instructions */
105 #define CTRL_CMD_HELP          "help"
106 #define CTRL_CMD_QUIT          "quit"
107 #define CTRL_CMD_EXIT          "exit"
108 #define CTRL_CMD_BYE           "bye"
109 #define CTRL_CMD_STAT          "stat"
110 #define CTRL_CMD_STAT_CON      "stat con"
111 #define CTRL_CMD_STAT_ALL      "stat all"
112 #define CTRL_CMD_STAT_ID       "stat id"
113 #define CTRL_CMD_STAT_COSERVER "stat coserver"
114 #define CTRL_CMD_STAT_CACHE    "stat cache"
115 #define CTRL_CMD_KILL_CACHE    "kill cache"
116 #define CTRL_CMD_KILLALL       "killall"
117 #define CTRL_CMD_KILL_ID       "kill id"
118 #define CTRL_CMD_RESTART_RDNS  "restart reverse dns"
119 #define CTRL_CMD_RESTART_DNS   "restart dns"
120 #define CTRL_CMD_RESTART_IDENT "restart ident"
121 
122 #endif /* __CONTROL_PROTO_H__ */
123