1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
#ifndef _LIBGLOUGLOU_H_
#define _LIBGLOUGLOU_H_
#include <sys/types.h>
#include <dnet.h>
#include <event.h>
#if defined(__OpenBSD__)
#include <sys/queue.h>
#else
#include <bsd/sys/queue.h>
#endif
#define GLOUGLOU_PROBE_DEFAULT_PORT 4430
#define GLOUGLOU_VIZ_DEFAULT_PORT 4431
/* packet.c */
#define PACKET_VERSION 0x03
#define PACKET_HEADER_SIZE 2
#define PACKET_BUFFER_SIZE 16384
#define PACKET_SNDBUF_MAX 500
#define PACKET_ARG_MAX 60
struct __attribute__((packed)) gg_packet {
u_int8_t ver;
u_int8_t module;
};
/* client.c */
enum client_status {
GG_CLIENT_STATUS_CONNECTING = 0,
GG_CLIENT_STATUS_CONNECTED = 1
};
struct gg_client {
struct event_base *evb;
struct addr *ip;
int port;
struct sockaddr_in addr;
struct event *ev;
struct event *ev_timer;
int sock;
enum client_status status;
int (*handle_conn)(struct gg_client *);
int (*handle_packet)(struct gg_client *, struct gg_packet *);
void *usrdata;
struct sendbuf *sbuf;
};
struct gg_client *gg_client_connect(struct event_base *,
struct addr *ip, int port,
int (*handle_conn)(struct gg_client *prb),
int (*handle_pkt)(struct gg_client *prb, struct gg_packet *pkt));
void gg_client_disconnect(struct gg_client *);
int gg_client_send(struct gg_client *, struct gg_packet *);
/* server.c */
struct gg_user {
LIST_ENTRY(gg_user) entry;
int id;
int sock;
struct sockaddr_in addr;
struct sendbuf *sbuf;
};
struct gg_server {
struct event_base *evb;
struct addr *ip;
int port;
struct sockaddr_in addr;
struct event *ev;
int sock;
int (*handle_conn)(struct gg_server *, struct gg_user *);
int (*handle_packet)(struct gg_server *,
struct gg_user *, struct gg_packet *);
void *usrdata;
LIST_HEAD(, gg_user) user_list;
int user_count;
int user_id_count;
};
struct gg_server *gg_server_start(struct event_base *,
struct addr *ip, int port,
int (*handle_conn)(struct gg_server *srv, struct gg_user *usr),
int (*handle_pkt)(struct gg_server *srv, struct gg_user *usr, struct gg_packet *pkt), void *);
void gg_server_stop(struct gg_server *srv);
/* log.c */
#define LOG_FORCED -2
#define LOG_FATAL -1
#define LOG_WARN 0
#define LOG_INFO 1
#define LOG_DEBUG 2
int log_init(char *, int);
void log_shutdown(void);
void log_tmp(const char *, ...);
void log_debug(const char *, ...);
void log_info(const char *, ...);
void log_warn(const char *, ...);
#if defined(__OpenBSD__)
void __dead log_fatal(const char *, ...);
#else
void log_fatal(const char *, ...);
#endif
/* utils.c */
struct mod {
LIST_ENTRY(mod) entry;
void *handle;
char *name;
void *dl;
};
struct modules {
LIST_HEAD(, mod) list;
int count;
};
void *xmalloc(size_t);
void *xcalloc(size_t, size_t);
void fd_nonblock(int);
void addrcpy(struct sockaddr_in *, struct sockaddr_in *);
int addrcmp(struct sockaddr_in *, struct sockaddr_in *);
void droppriv(char *, int, char *);
struct modules *modules_load(char *, char *);
int exec_pipe(char *, char **, char *, char **);
void kill_wait(pid_t, int);
struct event *udp_server_create(struct event_base *, struct addr *, int, event_callback_fn, void *);
void setprocname(const char *);
#endif /* _LIBGLOUGLOU_H_ */
|