grim/purple-spasm

cffbcb39672a
Parents 60d133ef0a45
Children 46ef890a6f02
Handle names reply (353) and fix scoping on some variables
--- a/src/spasm-chat.c Mon Apr 20 00:42:50 2020 -0500
+++ b/src/spasm-chat.c Mon Apr 20 15:51:14 2020 -0500
@@ -42,6 +42,7 @@
GRegex *regex_message;
GRegex *regex_target;
+ GRegex *regex_names_reply;
};
typedef void (*SpasmChatMessageHandler)(SpasmChatService *sa,
@@ -60,13 +61,18 @@
spasm_chat_service_regex_init(SpasmChatService *chat) {
chat->regex_message = g_regex_new("(?::(?<prefix>[^ ]+) +)?"
"(?<command>[^ :]+)"
- "(?:(?: +(?<middle>[^ :]+)))*"
+ "(?: (?<middle>(?:[^ :]+(?: [^ :]+)*)))*"
"(?<coda> +:(?<trailing>.*)?)?",
0, 0, NULL);
g_assert(chat->regex_message != NULL);
chat->regex_target = g_regex_new("(?:#(?<target>[^\\s]+))", 0, 0, NULL);
g_assert(chat->regex_target != NULL);
+
+ chat->regex_names_reply = g_regex_new("(?:[^ ]+) (?<scope>[=*@]) "
+ "#(?<target>[^ ]+)",
+ 0, 0, NULL);
+ g_assert(chat->regex_names_reply != NULL);
}
static gchar *
@@ -146,8 +152,6 @@
const gchar *middle, const gchar *trailing)
{
PurpleAccount *account = spasm_account_get_account(chat->sa);
- PurpleConnection *connection = NULL;
- PurpleConversation *conversation = NULL;
GMatchInfo *info = NULL;
gchar *nick= NULL, *target = NULL;
@@ -162,10 +166,11 @@
target = g_match_info_fetch_named(info, "target");
g_match_info_unref(info);
- connection = spasm_account_get_connection(chat->sa);
nick = spasm_chat_service_nick_from_mask(prefix);
if(purple_utf8_strcasecmp(nick, purple_account_get_username(account)) == 0) {
+ PurpleConnection *connection = spasm_account_get_connection(chat->sa);
+
/* We initiated the join. */
serv_got_joined_chat(connection, chat->id++, target);
@@ -176,6 +181,7 @@
} else {
/* Someone else is joining a channel we're in. */
PurpleConvChat *chat = NULL;
+ PurpleConversation *conversation = NULL;
conversation = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT,
target, account);
@@ -200,6 +206,56 @@
}
static void
+spasm_chat_service_handle_names(SpasmChatService *chat, const gchar *prefix,
+ const gchar *middle, const gchar *trailing)
+{
+ PurpleAccount *account = NULL;
+ PurpleConvChat *chat_conversation = NULL;
+ PurpleConversation *conversation = NULL;
+ GMatchInfo *info = NULL;
+ gchar **names = NULL;
+ gchar *target = NULL;
+ gint i = 0;
+
+ if(!g_regex_match(chat->regex_names_reply, middle, 0, &info)) {
+ purple_debug_misc("spasm-chat", "failed to parse names reply '%s'\n",
+ middle);
+
+ g_match_info_unref(info);
+
+ return;
+ }
+
+ target = g_match_info_fetch_named(info, "target");
+ g_match_info_unref(info);
+
+ account = spasm_account_get_account(chat->sa);
+ conversation = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT,
+ target, account);
+
+ if(conversation == NULL) {
+ purple_debug_misc("spasm-chat",
+ "Ignoring 353 for non-existent channel %s\n",
+ target);
+
+ g_free(target);
+
+ return;
+ }
+
+ g_free(target);
+
+ chat_conversation = PURPLE_CONV_CHAT(conversation);
+
+ names = g_strsplit(trailing, " ", -1);
+ for(i = 0; names[i] != NULL; i++) {
+ purple_conv_chat_add_user(chat_conversation, names[i], NULL,
+ PURPLE_CBFLAGS_NONE, TRUE);
+ }
+ g_strfreev(names);
+}
+
+static void
spasm_chat_service_handle_part(SpasmChatService *chat, const gchar *prefix,
const gchar *middle, const gchar *trailing)
{
@@ -310,7 +366,7 @@
g_hash_table_insert(handlers, "002", NULL); /* Ignore RPL_YOURHOST */
g_hash_table_insert(handlers, "003", NULL); /* Ignore RPL_CREATED */
g_hash_table_insert(handlers, "004", NULL); /* Ignore RPL_MYINFO */
-// g_hash_table_insert(handlers, "353", NULL); /* Ignore RPL_NAMREPLY */
+ g_hash_table_insert(handlers, "353", spasm_chat_service_handle_names);
g_hash_table_insert(handlers, "366", NULL); /* Ignore RPL_ENDOFNAMES */
g_hash_table_insert(handlers, "372", NULL); /* Ignore RPL_MOTD */
g_hash_table_insert(handlers, "375", NULL); /* Ignore RPL_MOTDSTART */