summaryrefslogtreecommitdiff
path: root/src/plugins/irc/irc-protocol.h
blob: 50ea3cf11fb6195b22a37be33be6a2e890652fd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright (C) 2003-2021 Sébastien Helleu <flashcode@flashtux.org>
 *
 * This file is part of WeeChat, the extensible chat client.
 *
 * WeeChat is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * WeeChat is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WeeChat.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef WEECHAT_PLUGIN_IRC_PROTOCOL_H
#define WEECHAT_PLUGIN_IRC_PROTOCOL_H

#include <time.h>

#define IRC_PROTOCOL_CALLBACK(__command)                                \
    int                                                                 \
    irc_protocol_cb_##__command (struct t_irc_server *server,           \
                                 time_t date,                           \
                                 const char *irc_message,               \
                                 struct t_hashtable *tags,              \
                                 const char *nick,                      \
                                 const char *address,                   \
                                 const char *host,                      \
                                 const char *command,                   \
                                 int ignored,                           \
                                 const char **params,                   \
                                 int num_params)
#define IRCB(__message, __decode_color, __keep_trailing_spaces,         \
             __func_cb)                                                 \
    { #__message,                                                       \
      __decode_color,                                                   \
      __keep_trailing_spaces,                                           \
      &irc_protocol_cb_##__func_cb }

#define IRC_PROTOCOL_MIN_PARAMS(__min_params)                           \
    (void) date;                                                        \
    (void) irc_message;                                                 \
    (void) tags;                                                        \
    (void) nick;                                                        \
    (void) address;                                                     \
    (void) host;                                                        \
    (void) command;                                                     \
    (void) ignored;                                                     \
    (void) params;                                                      \
    (void) num_params;                                                  \
    if (num_params < __min_params)                                      \
    {                                                                   \
        weechat_printf (server->buffer,                                 \
                        _("%s%s: too few parameters received in "       \
                          "command \"%s\" (received: %d, expected: "    \
                          "at least %d)"),                              \
                        weechat_prefix ("error"), IRC_PLUGIN_NAME,      \
                        command, num_params, __min_params);             \
        return WEECHAT_RC_ERROR;                                        \
    }

#define IRC_PROTOCOL_CHECK_NICK                                         \
    if (!nick || !nick[0])                                              \
    {                                                                   \
        weechat_printf (server->buffer,                                 \
                        _("%s%s: command \"%s\" received without "      \
                          "nick"),                                      \
                        weechat_prefix ("error"), IRC_PLUGIN_NAME,      \
                        command);                                       \
        return WEECHAT_RC_ERROR;                                        \
    }

struct t_irc_server;

typedef int (t_irc_recv_func)(struct t_irc_server *server,
                              time_t date, const char *irc_message,
                              struct t_hashtable *tags,
                              const char *nick, const char *address,
                              const char *host, const char *command,
                              int ignored,
                              const char **params, int num_params);

struct t_irc_protocol_msg
{
    char *name;                     /* IRC message name                      */
    int decode_color;               /* decode color before calling function  */
    int keep_trailing_spaces;       /* keep trailing spaces in message       */
    t_irc_recv_func *recv_function; /* function called when msg is received  */
};

extern const char *irc_protocol_tags (const char *command, const char *tags,
                                      const char *nick, const char *address);
extern time_t irc_protocol_parse_time (const char *time);
extern void irc_protocol_recv_command (struct t_irc_server *server,
                                       const char *irc_message,
                                       const char *msg_command,
                                       const char *msg_channel);

#endif /* WEECHAT_PLUGIN_IRC_PROTOCOL_H */