source: code/icb.h@ e54f151

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

Rework bufferevent read code

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[cd7b81d]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>
[fa271b8]18#include <sys/tree.h>
[cd7b81d]19
20#define ICB_MSGSIZE 256
21
22#define ICB_MAXGRPLEN 32
23#define ICB_MAXNICKLEN 32
24#define ICB_MAXPASSLEN 32
25#define ICB_MAXTOPICLEN 160
[1d2125a]26#define ICB_MTABLEN 50 /* XXX */
[cd7b81d]27
28#define ICB_M_LOGIN 'a'
29#define ICB_M_OPEN 'b'
30#define ICB_M_PERSONAL 'c'
31#define ICB_M_STATUS 'd'
32enum {
33 STATUS_ARRIVE,
34 STATUS_BOOT,
35 STATUS_DEPART,
[9195a6a]36 STATUS_HELP,
[cd7b81d]37 STATUS_NAME,
[bf02a60]38 STATUS_NOBEEP,
[cd7b81d]39 STATUS_NOTIFY,
40 STATUS_SIGNON,
41 STATUS_SIGNOFF,
42 STATUS_STATUS,
43 STATUS_TOPIC,
44 STATUS_WARNING
45};
46#define ICB_M_ERROR 'e'
47#define ICB_M_IMPORTANT 'f'
48#define ICB_M_EXIT 'g'
49#define ICB_M_COMMAND 'h'
50#define ICB_M_CMDOUT 'i'
51enum {
52 CMDOUT_CO,
53 CMDOUT_EC,
54 CMDOUT_WG,
[4284008]55 CMDOUT_WH,
56 CMDOUT_WL,
[cd7b81d]57};
58#define ICB_M_PROTO 'j'
59#define ICB_M_BEEP 'k'
60#define ICB_M_PING 'l'
61#define ICB_M_PONG 'm'
62#define ICB_M_NOOP 'n'
63
64#define ICB_M_SEP '\001'
65
66struct icb_group;
67
68struct icb_session {
[fa271b8]69 uint64_t id;
[cd7b81d]70 char nick[ICB_MAXNICKLEN];
71 char client[ICB_MAXNICKLEN];
72 char host[MAXHOSTNAMELEN];
73 char buffer[ICB_MSGSIZE+1];
74 struct event ev;
75 struct bufferevent *bev;
76 struct icb_group *group;
77 size_t length;
[c9402c3]78 size_t rlen;
[cd7b81d]79 time_t login;
80 time_t last;
81 int port;
82 uint32_t flags;
83#define SETF(t, f) ((t) |= (f))
84#define CLRF(t, f) ((t) &= ~(f))
85#define ISSETF(t, f) ((t) & (f))
86#define ICB_SF_PROTOSENT 0x01
87#define ICB_SF_LOGGEDIN 0x02
88#define ICB_SF_NOGROUP 0x08
[bf02a60]89#define ICB_SF_NOBEEP 0x10
90#define ICB_SF_NOBEEP2 0x20
[fa271b8]91
92 /* session tree */
93 RB_ENTRY(icb_session) node;
94
95 /* in-group linkage */
96 LIST_ENTRY(icb_session) entry;
[cd7b81d]97};
98
99struct icb_group {
100 char name[ICB_MAXGRPLEN];
101 char mpass[ICB_MAXPASSLEN];
102 char topic[ICB_MAXTOPICLEN];
103 LIST_ENTRY(icb_group) entry;
104 LIST_HEAD(, icb_session) sess;
[4284008]105 struct icb_session *mod;
[cd7b81d]106};
107
108LIST_HEAD(icb_grlist, icb_group) groups;
109
110struct icbd_callbacks {
111 void (*drop)(struct icb_session *, char *);
112 void (*log)(struct icb_session *, int, const char *, ...);
113 void (*send)(struct icb_session *, char *, ssize_t);
114};
115
116#ifndef nitems
117#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
118#endif
119
120/* cmd.c */
121void *icb_cmd_lookup(char *);
122
123/* icb.c */
124struct icb_group *icb_addgroup(struct icb_session *, char *, char *);
[626f420]125void icb_cmdout(struct icb_session *, int, char *);
126void icb_delgroup(struct icb_group *);
127void icb_error(struct icb_session *, const char *, ...);
128void icb_init(struct icbd_callbacks *);
129void icb_input(struct icb_session *);
130inline int icb_ismod(struct icb_group *, struct icb_session *);
131int icb_modpermit(struct icb_session *);
132int icb_pass(struct icb_group *, struct icb_session *,
133 struct icb_session *);
134void icb_privmsg(struct icb_session *, char *, char *);
135void icb_remove(struct icb_session *, char *);
136void icb_sendfmt(struct icb_session *, const char *, ...);
137void icb_start(struct icb_session *);
138void icb_status(struct icb_session *, int, const char *, ...);
139void icb_status_group(struct icb_group *, struct icb_session *,
140 int, const char *, ...);
141void icb_who(struct icb_session *, struct icb_group *);
[b7bc432]142int icb_vis(char *, const char *, size_t, int);
[cd7b81d]143
144/* callbacks from icbd.c */
[626f420]145void (*icb_drop)(struct icb_session *, char *);
146void (*icb_log)(struct icb_session *, int, const char *, ...);
147void (*icb_send)(struct icb_session *, char *, ssize_t);
Note: See TracBrowser for help on using the repository browser.