AmendHub

Download

jcs

/

wallops

/

irc.h

 

(View History)

jcs   irc: Do more comprehensive nick-highlight checking Latest amendment: 127 on 2024-09-20

1 /*
2 * Copyright (c) 2022 joshua stein <jcs@jcs.org>
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 #ifndef __IRC_H__
18 #define __IRC_H__
19
20 #include "chatter.h"
21 #include "tcp.h"
22 #include "util.h"
23
24 enum {
25 IRC_STATE_DISCONNECTED = 0,
26 IRC_STATE_DEAD,
27 IRC_STATE_UNREGISTERED,
28 IRC_STATE_CONNECTED
29 };
30
31 #define IRC_MSG_MAX_ARGS 7
32 #define IRC_MAX_MSG_SIZE 512
33
34 struct irc_msg {
35 short code;
36 char cmd[16];
37 char source[80];
38 char msg[IRC_MAX_MSG_SIZE];
39 char arg[IRC_MSG_MAX_ARGS][64];
40 };
41
42 struct irc_user {
43 char nick[32];
44 char username[32];
45 char hostname[128];
46 };
47
48 struct irc_channel_nick {
49 char nick[32];
50 char flags;
51 #define IRC_NICK_FLAG_OP (7 << 0)
52 #define IRC_NICK_FLAG_VOICE (6 << 0)
53 short next_nick;
54 };
55
56 struct irc_channel {
57 SLIST_ENTRY(irc_channel) list;
58 struct chatter *chatter;
59 struct irc_connection *connection;
60 struct irc_channel_nick *nicks;
61 bool parsing_nicks;
62 size_t nnicks;
63 size_t nicks_size;
64 short first_nick;
65 char name[64];
66 char mode[10];
67 char topic[400];
68 };
69 SLIST_HEAD(irc_channels_head, irc_channel);
70
71 struct irc_connection {
72 SLIST_ENTRY(irc_connection) list;
73 short state;
74 struct chatter *chatter;
75 char *hostname;
76 short port;
77 char *password;
78 char *nick;
79 short nick_len;
80 char *ident;
81 char *realname;
82 char *channel_autojoin;
83 char current_whois[member_size(struct irc_channel_nick, nick)];
84 bool did_autojoin;
85 bool hide_motd;
86 struct irc_channels_head channels_list;
87 short nchannels;
88 TCPiopb rcv_pb, send_pb, close_pb;
89 TCPStatusPB status_pb;
90 StreamPtr stream;
91 wdsEntry wds[2];
92 char obuf[512];
93 char ibuf[2048]; /* RFC2812 says max line will be 512 */
94 char line[512];
95 short ibuflen;
96 short linelen;
97 bool flushing_ibuf;
98 /* docs say 4*MTU+1024, but MTU will probably be <1500 */
99 unsigned char tcp_buf[(4 * 1500) + 2048];
100 };
101 SLIST_HEAD(irc_connections_head, irc_connection);
102 extern struct irc_connections_head irc_connections_list;
103
104 struct irc_connection * irc_connect(struct chatter *chatter,
105 const char *server, const unsigned short port, const char *password,
106 const char *nick, const char *ident, const char *realname,
107 bool hide_motd, const char *channel);
108 void irc_close_connection(struct irc_connection *conn);
109 void irc_dealloc_connection(struct irc_connection *conn);
110 void irc_process(struct irc_connection *conn);
111 void irc_abort(struct irc_connection *conn);
112 void irc_close(struct irc_connection *conn);
113 void irc_process_input(struct irc_connection *conn,
114 struct irc_channel *channel, char *query_nick, char *input);
115 void irc_part_channel(struct irc_connection *conn,
116 struct irc_channel *channel);
117
118 #endif