libpurple/protocols/ircv3/purpleircv3parser.c

Thu, 02 Nov 2023 23:38:51 -0500

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Thu, 02 Nov 2023 23:38:51 -0500
changeset 42472
409148c5c5b7
parent 42333
a34601ac633c
child 42503
55eff782a478
permissions
-rw-r--r--

Add symbol visibility on IRCv3 protocol plugin

This only adds visibility to things that have `Since: 3.0.0` _and_ are not already tagged with `G_GNUC_INTERNAL`.

It also assumes that the version is the same as libpurple, but that 3.0 is the minimum instead of 2.0, so everything is `PURPLE_IRCV3_AVAILABLE_IN_ALL`.

Testing Done:
Compiled on Linux and Windows.

Bugs closed: PIDGIN-17840

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

41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * (at your option) any later version.
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * GNU General Public License for more details.
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * along with this program; if not, see <https://www.gnu.org/licenses/>.
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include "purpleircv3parser.h"
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
41951
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
21 #include "purpleircv3capabilities.h"
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22 #include "purpleircv3core.h"
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
23 #include "purpleircv3message.h"
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41774
diff changeset
24 #include "purpleircv3messagehandlers.h"
42023
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
25 #include "purpleircv3sasl.h"
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 struct _PurpleIRCv3Parser {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 GObject parent;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 GRegex *regex_message;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 GRegex *regex_tags;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 PurpleIRCv3MessageHandler fallback_handler;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 GHashTable *handlers;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 };
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 G_DEFINE_TYPE(PurpleIRCv3Parser, purple_ircv3_parser, G_TYPE_OBJECT)
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 /******************************************************************************
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 * Helpers
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 *****************************************************************************/
41931
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
42 static char *
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
43 purple_ircv3_parser_unescape_tag_value(const char *value) {
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
44 GString *unescaped = g_string_new("");
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
45 gboolean escaping = FALSE;
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
46
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
47 /* Walk the string and replace escaped values according to
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
48 * https://ircv3.net/specs/extensions/message-tags.html#escaping-values
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
49 */
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
50 for(int i = 0; value[i] != '\0'; i++) {
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
51 if(escaping) {
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
52 /* Set the replacement to the current character which will fall
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
53 * through for everything, including '\\'
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
54 */
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
55 char replacement = value[i];
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
56
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
57 if(value[i] == ':') {
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
58 replacement = ';';
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
59 } else if(value[i] == 's') {
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
60 replacement = ' ';
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
61 } else if(value[i] == 'r') {
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
62 replacement = '\r';
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
63 } else if(value[i] == 'n') {
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
64 replacement = '\n';
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
65 }
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
66
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
67 g_string_append_c(unescaped, replacement);
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
68 escaping = FALSE;
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
69 } else {
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
70 if(value[i] == '\\') {
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
71 escaping = TRUE;
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
72 } else {
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
73 g_string_append_c(unescaped, value[i]);
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
74 }
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
75 }
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
76 }
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
77
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
78 return g_string_free(unescaped, FALSE);
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
79 }
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
80
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 static GHashTable *
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 purple_ircv3_parser_parse_tags(PurpleIRCv3Parser *parser,
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 const gchar *tags_string, GError **error)
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 GError *local_error = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 GHashTable *tags = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 GMatchInfo *info = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 gboolean matches = FALSE;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 tags = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 /* tags_string can never be NULL, because g_match_info_fetch_named always
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 * returns a string. So if we were passed an empty string, just return the
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 * empty hash table.
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 */
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 if(*tags_string == '\0') {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 return tags;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 matches = g_regex_match_full(parser->regex_tags, tags_string, -1, 0, 0,
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 &info, &local_error);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 if(local_error != NULL) {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 g_propagate_error(error, local_error);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 g_match_info_unref(info);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 return tags;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 if(!matches) {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 g_set_error_literal(error, PURPLE_IRCV3_DOMAIN, 0,
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 "failed to parse tags: unknown error");
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 g_match_info_unref(info);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 return tags;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 while(g_match_info_matches(info)) {
41931
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
121 char *key = NULL;
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
122 char *value = NULL;
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
123 char *unescaped = NULL;
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 key = g_match_info_fetch_named(info, "key");
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126 value = g_match_info_fetch_named(info, "value");
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127
41931
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
128 unescaped = purple_ircv3_parser_unescape_tag_value(value);
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
129 g_free(value);
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
130
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 /* the hash table is created with destroy notifies for both key and
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132 * value, so there's no need to free the allocated memory right now.
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 */
41931
f35eb5adb2e0 Unescape tag values in IRCv3
Gary Kramlich <grim@reaperworld.com>
parents: 41821
diff changeset
134 g_hash_table_insert(tags, key, unescaped);
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 g_match_info_next(info, &local_error);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 if(local_error != NULL) {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 g_propagate_error(error, local_error);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 break;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144 g_match_info_unref(info);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146 return tags;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
149 static guint
41941
355bd17297f0 Set the C standard to C99 and set warning_level to 2 for the IRCv3 Protocol Plugin
Gary Kramlich <grim@reaperworld.com>
parents: 41931
diff changeset
150 purple_ircv3_parser_extract_params(G_GNUC_UNUSED PurpleIRCv3Parser *parser,
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151 GStrvBuilder *builder, const gchar *str)
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152 {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153 gchar *ptr = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154 guint count = 0;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156 /* Loop through str finding each space separated string. */
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157 while(str != NULL && *str != '\0') {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158 /* Look for a space. */
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159 ptr = strchr(str, ' ');
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 /* If we found one, set it to null terminator and add the string to our
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162 * builder.
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 */
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 if(ptr != NULL) {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 *ptr = '\0';
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 g_strv_builder_add(builder, str);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 /* Move str to the next character as we know there's another
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 * character which might be another null terminator.
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 */
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171 str = ptr + 1;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 /* And don't forget to increment the count... ah ah ah! */
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174 count++;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 } else {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 /* Add the remaining string. */
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 g_strv_builder_add(builder, str);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179 /* Give the count another one, ah ah ah! */
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
180 count++;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
181
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
182 /* Finally break out of the loop. */
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
183 break;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
184 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187 return count;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
190 static GStrv
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191 purple_ircv3_parser_build_params(PurpleIRCv3Parser *parser,
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
192 const gchar *middle, const gchar *coda,
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
193 const gchar *trailing, guint *n_params)
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
194 {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
195 GStrvBuilder *builder = g_strv_builder_new();
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
196 GStrv result = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
198 purple_ircv3_parser_extract_params(parser, builder, middle);
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
199
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200 if(*coda != '\0') {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
201 g_strv_builder_add(builder, trailing);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
202 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
203
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
204 result = g_strv_builder_end(builder);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
205
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
206 g_strv_builder_unref(builder);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
208 if(result != NULL && n_params != NULL) {
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
209 *n_params = g_strv_length(result);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
210 }
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
211
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
212 return result;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
213 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
214
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
215 /******************************************************************************
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
216 * Handlers
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
217 *****************************************************************************/
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
218 static gboolean
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
219 purple_ircv3_fallback_handler(PurpleIRCv3Message *message,
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
220 GError **error,
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
221 G_GNUC_UNUSED gpointer data)
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
222 {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
223 g_set_error(error, PURPLE_IRCV3_DOMAIN, 0, "no handler for command %s",
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
224 purple_ircv3_message_get_command(message));
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
225
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
226 return FALSE;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
227 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
228
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
229 /******************************************************************************
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
230 * GObject Implementation
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
231 *****************************************************************************/
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
232 static void
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
233 purple_ircv3_parser_finalize(GObject *obj) {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234 PurpleIRCv3Parser *parser = PURPLE_IRCV3_PARSER(obj);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
235
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236 g_clear_pointer(&parser->regex_message, g_regex_unref);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
237 g_clear_pointer(&parser->regex_tags, g_regex_unref);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
238
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
239 g_hash_table_destroy(parser->handlers);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
240
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
241 G_OBJECT_CLASS(purple_ircv3_parser_parent_class)->finalize(obj);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
242 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
243
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
244 static void
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
245 purple_ircv3_parser_init(PurpleIRCv3Parser *parser) {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
246 parser->regex_message = g_regex_new("(?:@(?<tags>[^ ]+) )?"
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
247 "(?::(?<source>[^ ]+) +)?"
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
248 "(?<command>[^ :]+)"
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
249 "(?: +(?<middle>(?:[^ :]+(?: +[^ :]+)*)))*"
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
250 "(?<coda> +:(?<trailing>.*)?)?",
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
251 0, 0, NULL);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
252 g_assert(parser->regex_message != NULL);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
253
42055
2f5bbcc91854 IRCv3: Negotiate the message-tags capability and make sure our regex matches the BNF
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
254 parser->regex_tags = g_regex_new("(?<key>(?<client_prefix>\\+?)"
2f5bbcc91854 IRCv3: Negotiate the message-tags capability and make sure our regex matches the BNF
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
255 "(?:(?<vendor>[A-Za-z0-9-\\.]+)\\/)?"
2f5bbcc91854 IRCv3: Negotiate the message-tags capability and make sure our regex matches the BNF
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
256 "(?<key_name>[A-Za-z0-9-]+)"
2f5bbcc91854 IRCv3: Negotiate the message-tags capability and make sure our regex matches the BNF
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
257 ")"
2f5bbcc91854 IRCv3: Negotiate the message-tags capability and make sure our regex matches the BNF
Gary Kramlich <grim@reaperworld.com>
parents: 42023
diff changeset
258 "(?:=(?<value>[^\r\n;]*))?(?:;|$)",
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
259 0, 0, NULL);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
260 g_assert(parser->regex_tags != NULL);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
261
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
262 parser->fallback_handler = purple_ircv3_fallback_handler;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
263 parser->handlers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
264 NULL);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
265 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
266
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
267 static void
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
268 purple_ircv3_parser_class_init(PurpleIRCv3ParserClass *klass) {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
269 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
270
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
271 obj_class->finalize = purple_ircv3_parser_finalize;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
272 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
273
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
274 /******************************************************************************
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
275 * Public API
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
276 *****************************************************************************/
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
277 PurpleIRCv3Parser *
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
278 purple_ircv3_parser_new(void) {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
279 return g_object_new(PURPLE_IRCV3_TYPE_PARSER, NULL);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
280 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
281
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
282 void
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
283 purple_ircv3_parser_set_fallback_handler(PurpleIRCv3Parser *parser,
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
284 PurpleIRCv3MessageHandler handler)
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
285 {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
286 g_return_if_fail(PURPLE_IRCV3_IS_PARSER(parser));
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
287
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
288 parser->fallback_handler = handler;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
289 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
290
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
291 gboolean
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
292 purple_ircv3_parser_parse(PurpleIRCv3Parser *parser, const gchar *buffer,
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
293 GError **error, gpointer data)
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
294 {
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
295 PurpleIRCv3Message *message = NULL;
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
296 PurpleIRCv3MessageHandler handler = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
297 GError *local_error = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
298 GHashTable *tags = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
299 GMatchInfo *info = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
300 GStrv params = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
301 gchar *coda = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
302 gchar *command = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
303 gchar *middle = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
304 gchar *source = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
305 gchar *tags_string = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
306 gchar *trailing = NULL;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
307 gboolean matches = FALSE;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
308 gboolean result = FALSE;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
309
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
310 g_return_val_if_fail(PURPLE_IRCV3_IS_PARSER(parser), FALSE);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
311 g_return_val_if_fail(buffer != NULL, FALSE);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
312
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
313 /* Check if the buffer matches our regex for messages. */
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
314 matches = g_regex_match(parser->regex_message, buffer, 0, &info);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
315 if(!matches) {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
316 g_set_error(error, PURPLE_IRCV3_DOMAIN, 0,
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
317 "failed to parser buffer '%s'", buffer);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
318
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
319 g_match_info_unref(info);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
320
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
321 return FALSE;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
322 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
323
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
324 /* Extract the command from the buffer, so we can find the handler. */
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
325 command = g_match_info_fetch_named(info, "command");
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
326 handler = g_hash_table_lookup(parser->handlers, command);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
327 if(handler == NULL) {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
328 if(parser->fallback_handler == NULL) {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
329 g_set_error(error, PURPLE_IRCV3_DOMAIN, 0,
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
330 "no handler found for command %s and no default "
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
331 "handler set.", command);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
332
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
333 g_free(command);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
334 g_match_info_unref(info);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
335
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
336 return FALSE;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
337 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
338
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
339 handler = parser->fallback_handler;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
340 }
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
341
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
342 /* If we made it this far, we have our handler, so lets get the rest of the
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343 * parameters and call the handler.
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
344 */
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
345 message = purple_ircv3_message_new(command);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
346
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
347 tags_string = g_match_info_fetch_named(info, "tags");
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
348 tags = purple_ircv3_parser_parse_tags(parser, tags_string, &local_error);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
349 g_free(tags_string);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
350 if(local_error != NULL) {
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
351 g_propagate_error(error, local_error);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
352
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
353 g_free(command);
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
354 g_clear_object(&message);
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
355 g_hash_table_destroy(tags);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
356 g_match_info_unref(info);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
357
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
358 return FALSE;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
359 }
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
360 if(tags != NULL) {
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
361 purple_ircv3_message_set_tags(message, tags);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
362 g_hash_table_unref(tags);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
363 }
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
364
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
365 source = g_match_info_fetch_named(info, "source");
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
366 if(!purple_strempty(source)) {
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
367 purple_ircv3_message_set_source(message, source);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
368 }
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
369 g_free(source);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
370
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
371 middle = g_match_info_fetch_named(info, "middle");
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
372 coda = g_match_info_fetch_named(info, "coda");
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
373 trailing = g_match_info_fetch_named(info, "trailing");
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
374 params = purple_ircv3_parser_build_params(parser, middle, coda, trailing,
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
375 NULL);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
376 if(params != NULL) {
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
377 purple_ircv3_message_set_params(message, params);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
378 }
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
379
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
380 g_free(command);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
381 g_free(middle);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
382 g_free(coda);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
383 g_free(trailing);
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
384 g_strfreev(params);
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
385
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
386 /* Call the handler. */
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
387 result = handler(message, error, data);
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
388
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
389 /* Cleanup the left overs. */
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
390 g_match_info_unref(info);
42333
a34601ac633c Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents: 42275
diff changeset
391 g_clear_object(&message);
41774
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
392
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
393 return result;
170078e728c0 Implement a parser for ircv3 and add unit tests to it.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
394 }
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41774
diff changeset
395
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41774
diff changeset
396 void
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
397 purple_ircv3_parser_add_handler(PurpleIRCv3Parser *parser,
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
398 const char *command,
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
399 PurpleIRCv3MessageHandler handler)
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
400 {
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
401 g_return_if_fail(PURPLE_IRCV3_IS_PARSER(parser));
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
402 g_return_if_fail(command != NULL);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
403 g_return_if_fail(handler != NULL);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
404
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
405 g_hash_table_insert(parser->handlers, g_strdup(command), handler);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
406 }
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
407
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
408 void
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
409 purple_ircv3_parser_add_handlers(PurpleIRCv3Parser *parser,
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
410 PurpleIRCv3MessageHandler handler,
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
411 ...)
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
412 {
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
413 va_list vargs;
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
414 const char *command = NULL;
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
415
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
416 g_return_if_fail(PURPLE_IRCV3_IS_PARSER(parser));
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
417 g_return_if_fail(handler != NULL);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
418
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
419 va_start(vargs, handler);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
420
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
421 while((command = va_arg(vargs, const char *)) != NULL) {
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
422 purple_ircv3_parser_add_handler(parser, command, handler);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
423 }
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
424
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
425 va_end(vargs);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
426 }
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
427
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
428 void
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41774
diff changeset
429 purple_ircv3_parser_add_default_handlers(PurpleIRCv3Parser *parser) {
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41774
diff changeset
430 g_return_if_fail(PURPLE_IRCV3_IS_PARSER(parser));
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41774
diff changeset
431
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41774
diff changeset
432 purple_ircv3_parser_set_fallback_handler(parser,
41821
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41813
diff changeset
433 purple_ircv3_message_handler_fallback);
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41774
diff changeset
434
42023
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
435 /* Core functionality. */
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
436 purple_ircv3_parser_add_handler(parser, "CAP",
41951
00c472cd0fff Create PurpleIRCv3Capabilities for managing capabilities for each connection
Gary Kramlich <grim@reaperworld.com>
parents: 41941
diff changeset
437 purple_ircv3_capabilities_message_handler);
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
438 purple_ircv3_parser_add_handler(parser, "NOTICE",
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
439 purple_ircv3_message_handler_privmsg);
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41774
diff changeset
440 purple_ircv3_parser_add_handler(parser, "PING",
41821
ec766a6f010a Properly namespace the message handlers and reorganize them
Gary Kramlich <grim@reaperworld.com>
parents: 41813
diff changeset
441 purple_ircv3_message_handler_ping);
41813
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
442 purple_ircv3_parser_add_handler(parser, "PRIVMSG",
86302ce7e3c1 Add support for handling PRIVMSG and NOTICE messages from the server
Gary Kramlich <grim@reaperworld.com>
parents: 41807
diff changeset
443 purple_ircv3_message_handler_privmsg);
42023
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
444
42275
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
445 /* Post Registration Greetings */
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
446 purple_ircv3_parser_add_handlers(parser,
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
447 purple_ircv3_message_handler_status_ignore_param0,
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
448 "001", "002", "003", "004", NULL);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
449
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
450 /* Luser's */
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
451 purple_ircv3_parser_add_handlers(parser,
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
452 purple_ircv3_message_handler_status_ignore_param0,
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
453 "251", "252", "253", "254", "255", NULL);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
454
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
455 /* MOTD */
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
456 purple_ircv3_parser_add_handlers(parser,
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
457 purple_ircv3_message_handler_status_ignore_param0,
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
458 "372", "375", "376", NULL);
7568bf87e388 Add a basic status window to the IRCv3 protocol plugin
Gary Kramlich <grim@reaperworld.com>
parents: 42055
diff changeset
459
42023
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
460 /* SASL stuff. */
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
461 purple_ircv3_parser_add_handler(parser, "900",
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
462 purple_ircv3_sasl_logged_in);
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
463 purple_ircv3_parser_add_handler(parser, "901",
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
464 purple_ircv3_sasl_logged_out);
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
465 purple_ircv3_parser_add_handler(parser, "902",
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
466 purple_ircv3_sasl_nick_locked);
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
467 purple_ircv3_parser_add_handler(parser, "903",
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
468 purple_ircv3_sasl_success);
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
469 purple_ircv3_parser_add_handler(parser, "904",
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
470 purple_ircv3_sasl_failed);
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
471 purple_ircv3_parser_add_handler(parser, "905",
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
472 purple_ircv3_sasl_message_too_long);
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
473 purple_ircv3_parser_add_handler(parser, "906",
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
474 purple_ircv3_sasl_aborted);
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
475 purple_ircv3_parser_add_handler(parser, "907",
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
476 purple_ircv3_sasl_already_authed);
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
477 purple_ircv3_parser_add_handler(parser, "908",
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
478 purple_ircv3_sasl_mechanisms);
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
479 purple_ircv3_parser_add_handler(parser, "AUTHENTICATE",
5bda87b90d8d Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents: 41951
diff changeset
480 purple_ircv3_sasl_authenticate);
41796
ebe4ff278b02 Use the parser on ircv3 messages and handle pings
Gary Kramlich <grim@reaperworld.com>
parents: 41774
diff changeset
481 }

mercurial