comparison src/ctrl_telnet.h @ 125:e413158cae13

Add ushare project files.
author naoyan@johnstown.minaminoshima.org
date Sun, 03 Oct 2010 11:35:19 +0900
parents
children
comparison
equal deleted inserted replaced
124:9c7bc6c0327e 125:e413158cae13
1 /* ctrltelnet.h - Header for the Telnet controler
2 * Copyright (C) 2005-2007 Sven Almgren <sven@tras.se>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 */
19
20 #ifndef _CTRL_TELNET_H_
21 #define _CTRL_TELNET_H_
22
23 #define CTRL_TELNET_PORT 1337
24 #define CTRL_TELNET_BACKLOG 10
25 #define CTRL_TELNET_SHARED_BUFFER_SIZE 256
26 #define CTRL_CLIENT_RECV_BUFFER_SIZE 256
27
28 #include <netinet/in.h>
29
30 /**
31 * @brief Structure doubling as both a connected client data holder
32 * and as a linked list
33 */
34 typedef struct ctrl_telnet_client_t
35 {
36 /* Recv buffer used to read single lines from more then one packet ...
37 Not garanteed to be NULL terminated */
38 char buffer_recv[CTRL_CLIENT_RECV_BUFFER_SIZE];
39
40 int buffer_recv_current;
41 int socket;
42 int ready; /* True if this client has a complete line, ready to be parsed */
43 int exiting;
44 struct sockaddr_in remote_address;
45 struct ctrl_telnet_client_t* next;
46 } ctrl_telnet_client;
47
48 typedef void (* ctrl_telnet_command_ptr) (ctrl_telnet_client *, int, char **);
49
50 /**
51 * @brief Starts a Telnet bound control interface
52 *
53 * @return 0 on success, -1 on error
54 */
55 int ctrl_telnet_start (int port);
56
57 /**
58 * @brief Stops all telnet bound control interfaces
59 */
60 void ctrl_telnet_stop (void);
61
62 /* FIXME: You can register a function name multiple times,
63 but the last one added is the one getting called... not a problem a.t.m. */
64 void ctrl_telnet_register (const char *funcname,
65 ctrl_telnet_command_ptr funcptr,
66 const char* description);
67
68 int ctrl_telnet_client_send (const ctrl_telnet_client *, const char* string);
69 int ctrl_telnet_client_sendf (const ctrl_telnet_client *client,
70 const char* format, ...);
71 int ctrl_telnet_client_sendsf (const ctrl_telnet_client *client,
72 char* buffer, int buffersize,
73 const char* format, ...);
74
75 #endif /* _CTRL_TELNET_H_ */