// invitation event handler // TODO: if event is accepted, check if other events to the same room exist and // destroy them? (need invitation registry list for that) static gboolean evscallback_invitation(guint evcontext, const char *arg, gpointer userdata) { event_muc_invitation *invitation = userdata; // Sanity check if (G_UNLIKELY(!invitation)) { // Shouldn't happen. scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback."); return FALSE; } if (evcontext == EVS_CONTEXT_TIMEOUT) { scr_LogPrint(LPRINT_LOGNORM, "Invitation event %s timed out, cancelled.", invitation->to); return FALSE; } if (evcontext == EVS_CONTEXT_CANCEL) { scr_LogPrint(LPRINT_LOGNORM, "Invitation event %s cancelled.", invitation->to); return FALSE; } if (!(evcontext == EVS_CONTEXT_ACCEPT || evcontext == EVS_CONTEXT_REJECT)) return FALSE; // Ok, let's work now if (evcontext == EVS_CONTEXT_ACCEPT) { char *nickname = default_muc_nickname(invitation->to); xmpp_room_join(invitation->to, nickname, invitation->passwd); g_free(nickname); } else { scr_LogPrint(LPRINT_LOGNORM, "Invitation to %s refused.", invitation->to); if (invitation->reply) decline_invitation(invitation, arg); } return FALSE; }
static void storage_bookmarks_parse_conference(LmMessageNode *node) { const char *fjid, *name, *autojoin; const char *pstatus, *awhois, *fjoins, *group; char *bjid; GSList *room_elt; fjid = lm_message_node_get_attribute(node, "jid"); if (!fjid) return; name = lm_message_node_get_attribute(node, "name"); autojoin = lm_message_node_get_attribute(node, "autojoin"); awhois = lm_message_node_get_attribute(node, "autowhois"); pstatus = lm_message_node_get_child_value(node, "print_status"); fjoins = lm_message_node_get_child_value(node, "flag_joins"); group = lm_message_node_get_child_value(node, "group"); bjid = jidtodisp(fjid); // Bare jid // Make sure this is a room (it can be a conversion user->room) room_elt = roster_find(bjid, jidsearch, 0); if (!room_elt) { room_elt = roster_add_user(bjid, name, group, ROSTER_TYPE_ROOM, sub_none, -1); } else { buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); /* // If the name is available, should we use it? // I don't think so, it would be confusing because this item is already // in the roster. if (name) buddy_setname(room_elt->data, name); // The same question for roster group. if (group) buddy_setgroup(room_elt->data, group); */ } // Set the print_status and auto_whois values if (pstatus) { enum room_printstatus i; for (i = status_none; i <= status_all; i++) if (!strcasecmp(pstatus, strprintstatus[i])) break; if (i <= status_all) buddy_setprintstatus(room_elt->data, i); } if (awhois) { enum room_autowhois i = autowhois_default; if (!g_strcmp0(awhois, "1") || !(g_strcmp0(awhois, "true"))) i = autowhois_on; else if (!g_strcmp0(awhois, "0") || !(g_strcmp0(awhois, "false"))) i = autowhois_off; if (i != autowhois_default) buddy_setautowhois(room_elt->data, i); } if (fjoins) { enum room_flagjoins i; for (i = flagjoins_none; i <= flagjoins_all; i++) if (!strcasecmp(fjoins, strflagjoins[i])) break; if (i <= flagjoins_all) buddy_setflagjoins(room_elt->data, i); } // Is autojoin set? // If it is, we'll look up for more information (nick? password?) and // try to join the room. if (autojoin && !g_strcmp0(autojoin, "1")) { const char *nick, *passwd; char *tmpnick = NULL; nick = lm_message_node_get_child_value(node, "nick"); passwd = lm_message_node_get_child_value(node, "password"); if (!nick || !*nick) nick = tmpnick = default_muc_nickname(NULL); // Let's join now scr_LogPrint(LPRINT_LOGNORM, "Auto-join bookmark <%s>", bjid); xmpp_room_join(bjid, nick, passwd); g_free(tmpnick); } g_free(bjid); buddylist_build(); update_roster = TRUE; }