]> Pileus Git - ~andy/lamechat/blob - chat.h
Refactor chat.
[~andy/lamechat] / chat.h
1 /*
2  * Copyright (C) 2017 Andy Spencer <andy753421@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 /* Message Types */
19 typedef unsigned long long stamp_t;
20
21 typedef struct server_t server_t;
22 typedef struct channel_t channel_t;
23
24 typedef enum {
25         IRC,
26         XMPP,
27 } protocol_t;
28
29 typedef struct server_t {
30         protocol_t  protocol;
31         char       *name;
32         server_t   *next;
33 } server_t;
34
35 typedef struct channel_t {
36         server_t   *server;
37         char       *name;
38         channel_t  *next;
39 } channel_t;
40
41 typedef struct {
42         channel_t  *channel;
43         stamp_t     when;
44         char       *from;
45         char       *text;
46 } message_t;
47
48 /* Global Data */
49 extern server_t  *servers;
50 extern channel_t *channels;
51 extern message_t *messages;
52 extern int        history;
53
54 /* Chat functions */
55 void chat_init(void);
56 void chat_config(const char *group, const char *name,
57                  const char *key, const char *value);
58 void chat_notice(const char *channel_name, const char *from, const char *fmt, ...);
59 void chat_recv(const char *channel_name, const char *from, const char *msg);
60 void chat_send(const char *channel_name, const char *msg);
61 void chat_exit(void);
62
63 server_t  *add_server(const char *name, protocol_t protocol);
64 channel_t *add_channel(const char *name, server_t *server);
65 server_t  *find_server(const char *name);
66 channel_t *find_channel(const char *name);
67
68 /* Protocol functions */
69 extern void irc_init(void);
70 extern server_t *irc_server(void);
71 extern channel_t *irc_channel(void);
72 extern void irc_config(server_t *server, channel_t *channel,
73                        const char *group, const char *name,
74                        const char *key, const char *value);
75 extern void irc_send(message_t *msg);
76 extern void irc_exit(void);
77
78 extern void xmpp_init(void);
79 extern server_t *xmpp_server(void);
80 extern channel_t *xmpp_channel(void);
81 extern void xmpp_config(server_t *server, channel_t *channel,
82                         const char *group, const char *name,
83                         const char *key, const char *value);
84 extern void xmpp_send(message_t *msg);
85 extern void xmpp_exit(void);