source: code/icb.h@ 9195a6a

Last change on this file since 9195a6a was 9195a6a, checked in by Mike Belopuhov <mike@…>, 11 years ago

add a simple help command

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * Copyright (c) 2009 Mike Belopuhov
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <sys/queue.h>
18
19#define ICB_MSGSIZE 256
20
21#define ICB_MAXGRPLEN 32
22#define ICB_MAXNICKLEN 32
23#define ICB_MAXPASSLEN 32
24#define ICB_MAXTOPICLEN 160
25
26#define ICB_M_LOGIN 'a'
27#define ICB_M_OPEN 'b'
28#define ICB_M_PERSONAL 'c'
29#define ICB_M_STATUS 'd'
30enum {
31 STATUS_ARRIVE,
32 STATUS_BOOT,
33 STATUS_DEPART,
34 STATUS_HELP,
35 STATUS_NAME,
36 STATUS_NOBEEP,
37 STATUS_NOTIFY,
38 STATUS_SIGNON,
39 STATUS_SIGNOFF,
40 STATUS_STATUS,
41 STATUS_TOPIC,
42 STATUS_WARNING
43};
44#define ICB_M_ERROR 'e'
45#define ICB_M_IMPORTANT 'f'
46#define ICB_M_EXIT 'g'
47#define ICB_M_COMMAND 'h'
48#define ICB_M_CMDOUT 'i'
49enum {
50 CMDOUT_CO,
51 CMDOUT_EC,
52 CMDOUT_WL,
53 CMDOUT_WG,
54};
55#define ICB_M_PROTO 'j'
56#define ICB_M_BEEP 'k'
57#define ICB_M_PING 'l'
58#define ICB_M_PONG 'm'
59#define ICB_M_NOOP 'n'
60
61#define ICB_M_SEP '\001'
62
63struct icb_group;
64
65struct icb_session {
66 char nick[ICB_MAXNICKLEN];
67 char client[ICB_MAXNICKLEN];
68 char host[MAXHOSTNAMELEN];
69 char buffer[ICB_MSGSIZE+1];
70 struct event ev;
71 LIST_ENTRY(icb_session) entry;
72 struct bufferevent *bev;
73 struct icb_group *group;
74 size_t length;
75 time_t login;
76 time_t last;
77 int port;
78 uint32_t flags;
79#define SETF(t, f) ((t) |= (f))
80#define CLRF(t, f) ((t) &= ~(f))
81#define ISSETF(t, f) ((t) & (f))
82#define ICB_SF_PROTOSENT 0x01
83#define ICB_SF_LOGGEDIN 0x02
84#define ICB_SF_NOGROUP 0x08
85#define ICB_SF_NOBEEP 0x10
86#define ICB_SF_NOBEEP2 0x20
87};
88
89struct icb_group {
90 char name[ICB_MAXGRPLEN];
91 char mpass[ICB_MAXPASSLEN];
92 char topic[ICB_MAXTOPICLEN];
93 LIST_ENTRY(icb_group) entry;
94 LIST_HEAD(, icb_session) sess;
95 struct icb_session *moder;
96};
97
98LIST_HEAD(icb_grlist, icb_group) groups;
99
100struct icbd_callbacks {
101 void (*drop)(struct icb_session *, char *);
102 void (*log)(struct icb_session *, int, const char *, ...);
103 void (*send)(struct icb_session *, char *, ssize_t);
104};
105
106#ifndef nitems
107#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
108#endif
109
110/* cmd.c */
111void *icb_cmd_lookup(char *);
112
113/* icb.c */
114struct icb_group *icb_addgroup(struct icb_session *, char *, char *);
115void icb_cmdout(struct icb_session *, int, char *);
116void icb_delgroup(struct icb_group *);
117void icb_error(struct icb_session *, const char *, ...);
118void icb_init(struct icbd_callbacks *);
119void icb_input(struct icb_session *);
120int icb_ismoder(struct icb_group *, struct icb_session *);
121int icb_pass(struct icb_group *, struct icb_session *, struct icb_session *);
122void icb_privmsg(struct icb_session *, char *, char *);
123void icb_remove(struct icb_session *, char *);
124void icb_sendfmt(struct icb_session *, const char *, ...);
125void icb_start(struct icb_session *);
126void icb_status(struct icb_session *, int, const char *, ...);
127void icb_status_group(struct icb_group *, struct icb_session *, int ,
128 const char *, ...);
129void icb_who(struct icb_session *, struct icb_group *);
130
131/* callbacks from icbd.c */
132void (*icb_drop)(struct icb_session *, char *);
133void (*icb_log)(struct icb_session *, int, const char *, ...);
134void (*icb_send)(struct icb_session *, char *, ssize_t);
Note: See TracBrowser for help on using the repository browser.