source: code/icb.h@ 1a5d69e

Last change on this file since 1a5d69e was cd7b81d, checked in by Mike Belopuhov <mike.belopuhov@…>, 15 years ago

move it to the github

  • Property mode set to 100644
File size: 3.7 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>
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_NAME,
35 STATUS_NOTIFY,
36 STATUS_SIGNON,
37 STATUS_SIGNOFF,
38 STATUS_STATUS,
39 STATUS_TOPIC,
40 STATUS_WARNING
41};
42#define ICB_M_ERROR 'e'
43#define ICB_M_IMPORTANT 'f'
44#define ICB_M_EXIT 'g'
45#define ICB_M_COMMAND 'h'
46#define ICB_M_CMDOUT 'i'
47enum {
48 CMDOUT_CO,
49 CMDOUT_EC,
50 CMDOUT_WL,
51 CMDOUT_WG,
52};
53#define ICB_M_PROTO 'j'
54#define ICB_M_BEEP 'k'
55#define ICB_M_PING 'l'
56#define ICB_M_PONG 'm'
57#define ICB_M_NOOP 'n'
58
59#define ICB_M_SEP '\001'
60
61struct icb_group;
62
63struct icb_session {
64 char nick[ICB_MAXNICKLEN];
65 char client[ICB_MAXNICKLEN];
66 char host[MAXHOSTNAMELEN];
67 char buffer[ICB_MSGSIZE+1];
68 struct event ev;
69 LIST_ENTRY(icb_session) entry;
70 struct bufferevent *bev;
71 struct icb_group *group;
72 size_t length;
73 time_t login;
74 time_t last;
75 int port;
76 uint32_t flags;
77#define SETF(t, f) ((t) |= (f))
78#define CLRF(t, f) ((t) &= ~(f))
79#define ISSETF(t, f) ((t) & (f))
80#define ICB_SF_UNKNOWN 0x00
81#define ICB_SF_PROTOSENT 0x01
82#define ICB_SF_LOGGEDIN 0x02
83#define ICB_SF_NOGROUP 0x08
84#define ICB_SF_MODERATOR 0x10
85};
86
87struct icb_group {
88 char name[ICB_MAXGRPLEN];
89 char mpass[ICB_MAXPASSLEN];
90 char topic[ICB_MAXTOPICLEN];
91 LIST_ENTRY(icb_group) entry;
92 LIST_HEAD(, icb_session) sess;
93 struct icb_session *moder;
94};
95
96LIST_HEAD(icb_grlist, icb_group) groups;
97
98struct icbd_callbacks {
99 void (*drop)(struct icb_session *, char *);
100 void (*log)(struct icb_session *, int, const char *, ...);
101 void (*send)(struct icb_session *, char *, ssize_t);
102};
103
104#ifndef nitems
105#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
106#endif
107
108/* cmd.c */
109void *icb_cmd_lookup(char *);
110
111/* icb.c */
112struct icb_group *icb_addgroup(struct icb_session *, char *, char *);
113void icb_cmdout(struct icb_session *, int, char *);
114void icb_delgroup(struct icb_group *);
115void icb_error(struct icb_session *, const char *, ...);
116void icb_init(struct icbd_callbacks *);
117void icb_input(struct icb_session *);
118int icb_ismoder(struct icb_group *, struct icb_session *);
119int icb_pass(struct icb_group *, struct icb_session *, struct icb_session *);
120void icb_privmsg(struct icb_session *, char *, char *);
121void icb_remove(struct icb_session *, char *);
122void icb_sendfmt(struct icb_session *, const char *, ...);
123void icb_start(struct icb_session *);
124void icb_status(struct icb_session *, int, const char *, ...);
125void icb_status_group(struct icb_group *, struct icb_session *, int ,
126 const char *, ...);
127void icb_who(struct icb_session *, struct icb_group *);
128
129/* callbacks from icbd.c */
130void (*icb_drop)(struct icb_session *, char *);
131void (*icb_log)(struct icb_session *, int, const char *, ...);
132void (*icb_send)(struct icb_session *, char *, ssize_t);
Note: See TracBrowser for help on using the repository browser.