AmendHub

Download

jcs

/

wallops

/

irc.h

 

(View History)

jcs   irc: Fix nick flags Latest amendment: 142 on 2025-12-17

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 unsigned char flags;
51 #define IRC_NICK_FLAG_OP (1 << 0)
52 #define IRC_NICK_FLAG_VOICE (1 << 1)
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 char *nicks_buf;
62 size_t nicks_buf_len;
63 size_t nicks_buf_size;
64 size_t nnicks;
65 size_t nicks_size;
66 short first_nick;
67 char name[64];
68 char mode[10];
69 char topic[400];
70 };
71 SLIST_HEAD(irc_channels_head, irc_channel);
72
73 struct irc_connection {
74 SLIST_ENTRY(irc_connection) list;
75 short state;
76 struct chatter *chatter;
77 char *hostname;
78 short port;
79 char *password;
80 char *nick;
81 short nick_len;
82 char *ident;
83 char *realname;
84 char *channel_autojoin;
85 char current_whois[member_size(struct irc_channel_nick, nick)];
86 bool did_autojoin;
87 bool hide_motd;
88 struct irc_channels_head channels_list;
89 short nchannels;
90 TCPiopb rcv_pb, send_pb, close_pb;
91 TCPStatusPB status_pb;
92 StreamPtr stream;
93 wdsEntry wds[2];
94 char obuf[512];
95 char ibuf[2048]; /* RFC2812 says max line will be 512 */
96 char line[512];
97 short ibuflen;
98 short linelen;
99 bool flushing_ibuf;
100 /* docs say 4*MTU+1024, but MTU will probably be <1500 */
101 unsigned char tcp_buf[(4 * 1500) + 2048];
102 };
103 SLIST_HEAD(irc_connections_head, irc_connection);
104 extern struct irc_connections_head irc_connections_list;
105
106 struct irc_connection * irc_connect(struct chatter *chatter,
107 const char *server, const unsigned short port, const char *password,
108 const char *nick, const char *ident, const char *realname,
109 bool hide_motd, const char *channel);
110 void irc_close_connection(struct irc_connection *conn);
111 void irc_dealloc_connection(struct irc_connection *conn);
112 void irc_process(struct irc_connection *conn);
113 void irc_abort(struct irc_connection *conn);
114 void irc_close(struct irc_connection *conn);
115 void irc_process_input(struct irc_connection *conn,
116 struct irc_channel *channel, char *query_nick, char *input);
117 void irc_part_channel(struct irc_connection *conn,
118 struct irc_channel *channel);
119
120 #endif