protocols/ircv3/purpleircv3source.c

Thu, 11 Apr 2024 21:32:59 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 11 Apr 2024 21:32:59 -0500
changeset 42692
12506cd6fa96
parent 42652
225762d4e206
permissions
-rw-r--r--

Remove PurpleConnectionUiOps as they are no longer used

Testing Done:
Checked in with the turtles.

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

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 *
42568
31e8c7c92e2f Make sure all of the license headers for IRCv3 are GPLv2
Gary Kramlich <grim@reaperworld.com>
parents: 42336
diff changeset
5 * Purple is the legal property of its developers, whose names are too numerous
31e8c7c92e2f Make sure all of the license headers for IRCv3 are GPLv2
Gary Kramlich <grim@reaperworld.com>
parents: 42336
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
31e8c7c92e2f Make sure all of the license headers for IRCv3 are GPLv2
Gary Kramlich <grim@reaperworld.com>
parents: 42336
diff changeset
7 * source distribution.
31e8c7c92e2f Make sure all of the license headers for IRCv3 are GPLv2
Gary Kramlich <grim@reaperworld.com>
parents: 42336
diff changeset
8 *
31e8c7c92e2f Make sure all of the license headers for IRCv3 are GPLv2
Gary Kramlich <grim@reaperworld.com>
parents: 42336
diff changeset
9 * This library is free software; you can redistribute it and/or modify
42336
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * 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
11 * 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
12 * (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
13 *
42568
31e8c7c92e2f Make sure all of the license headers for IRCv3 are GPLv2
Gary Kramlich <grim@reaperworld.com>
parents: 42336
diff changeset
14 * This library is distributed in the hope that it will be useful,
42336
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * 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
16 * 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
17 * 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
18 *
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
42568
31e8c7c92e2f Make sure all of the license headers for IRCv3 are GPLv2
Gary Kramlich <grim@reaperworld.com>
parents: 42336
diff changeset
20 * along with this library; if not, see <https://www.gnu.org/licenses/>.
42336
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
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 #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
24
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 #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
26
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 /******************************************************************************
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 * Public API
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 void
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 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
32 char **host)
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 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
35 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
36 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
37
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 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
39 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
40
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 /* 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
42 * bail immediately.
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 */
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 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
45 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
46 if(matched) {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 return;
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
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 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
51 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
52
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 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
54 if(!matched) {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 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
56 *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
57 }
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 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
60 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
61
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 return;
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(nick != NULL) {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 *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
67 }
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 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
70 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
71
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 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
73 *user = tmp;
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 } else {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 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
76 }
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
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 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
80 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
81
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 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
83 *host = tmp;
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 } else {
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 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
86 }
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 }
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88
14c850aeee79 IRCv3: add ircv3_source_parse to parse sources into nick, user, and host
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89 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
90 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
91 }

mercurial