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