libpurple/protocols/ircv3/purpleircv3source.c

Mon, 04 Dec 2023 02:21:08 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Mon, 04 Dec 2023 02:21:08 -0600
changeset 42544
95d36c221e21
parent 42336
14c850aeee79
child 42568
31e8c7c92e2f
permissions
-rw-r--r--

Implement CTCP ACTION and VERSION

Testing Done:
Used irssi to send `CTCP VERSION` to a channel and the pidgin3 user directly and verified the response was sent and that the default message was still displayed.

Bugs closed: PIDGIN-17721

Reviewed at https://reviews.imfreedom.org/r/2863/

42336
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * (at your option) any later version.
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * GNU General Public License for more details.
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * along with this program; if not, see <https://www.gnu.org/licenses/>.
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include <purple.h>
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 #include "purpleircv3source.h"
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 /******************************************************************************
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24 * Public API
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 *****************************************************************************/
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 void
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 purple_ircv3_source_parse(const char *source, char **nick, char **user,
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 char **host)
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 GRegex *regex = NULL;
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 GMatchInfo *info = NULL;
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 gboolean matched = FALSE;
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 g_return_if_fail(!purple_strempty(source));
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 g_return_if_fail(nick != NULL || user != NULL || host != NULL);
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 /* If we find any \r \n or spaces in our source, it's invalid so we just
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 * bail immediately.
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 */
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 matched = g_regex_match_simple("[\r\n ]", source, G_REGEX_DEFAULT,
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 G_REGEX_MATCH_DEFAULT);
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 if(matched) {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 return;
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 }
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 regex = g_regex_new("^(?P<nick>[^ \r\n!]+)(?:!(?P<user>[^@]+)(?:@(?P<host>[^!@]+))?)?$",
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, NULL);
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 matched = g_regex_match(regex, source, G_REGEX_MATCH_DEFAULT, &info);
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 if(!matched) {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 if(nick != NULL) {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 *nick = g_strdup(source);
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 }
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 g_clear_pointer(&info, g_match_info_unref);
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 g_clear_pointer(&regex, g_regex_unref);
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 return;
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 }
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 if(nick != NULL) {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 *nick = g_match_info_fetch_named(info, "nick");
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 }
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 if(user != NULL) {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 char *tmp = g_match_info_fetch_named(info, "user");
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 if(!purple_strempty(tmp)) {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 *user = tmp;
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 } else {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 g_free(tmp);
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 }
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 }
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 if(host != NULL) {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 char *tmp = g_match_info_fetch_named(info, "host");
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 if(!purple_strempty(tmp)) {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 *host = tmp;
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 } else {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 g_free(tmp);
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 }
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 }
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 g_clear_pointer(&info, g_match_info_unref);
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 g_clear_pointer(&regex, g_regex_unref);
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 }

mercurial