comparison mcabber/src/commands.c @ 1391:e20ab87c4c4c

The command /room ban can be used with a nickname If the parameter doesn't look like a jid, check if it is a room member nickname.
author Mikael Berthe <mikael@lilotux.net>
date Wed, 05 Dec 2007 22:05:41 +0100
parents 3067c096cfc4
children 3d4963c8ce87
comparison
equal deleted inserted replaced
1390:753a348c65c1 1391:e20ab87c4c4c
2199 2199
2200 // The expected argument is a Jabber id 2200 // The expected argument is a Jabber id
2201 static void room_ban(gpointer bud, char *arg) 2201 static void room_ban(gpointer bud, char *arg)
2202 { 2202 {
2203 char **paramlst; 2203 char **paramlst;
2204 gchar *fjid; 2204 gchar *fjid, *bjid;
2205 const gchar *banjid;
2205 gchar *jid_utf8, *reason_utf8; 2206 gchar *jid_utf8, *reason_utf8;
2206 struct role_affil ra; 2207 struct role_affil ra;
2207 const char *roomid = buddy_getjid(bud); 2208 const char *roomid = buddy_getjid(bud);
2208 2209
2209 paramlst = split_arg(arg, 2, 1); // jid, [reason] 2210 paramlst = split_arg(arg, 2, 1); // jid, [reason]
2217 } 2218 }
2218 2219
2219 ra.type = type_affil; 2220 ra.type = type_affil;
2220 ra.val.affil = affil_outcast; 2221 ra.val.affil = affil_outcast;
2221 2222
2222 jid_utf8 = to_utf8(fjid); 2223 bjid = jidtodisp(fjid);
2224 jid_utf8 = to_utf8(bjid);
2225
2226 // If the argument doesn't look like a jid, we'll try to find a matching
2227 // nickname.
2228 if (!strchr(bjid, JID_DOMAIN_SEPARATOR) || check_jid_syntax(bjid)) {
2229 const gchar *tmp;
2230 // We want the initial argument, so the fjid variable, because
2231 // we don't want to strip a resource-like string from the nickname!
2232 g_free(jid_utf8);
2233 jid_utf8 = to_utf8(fjid);
2234 tmp = buddy_getrjid(bud, jid_utf8);
2235 if (!tmp) {
2236 scr_LogPrint(LPRINT_NORMAL, "Wrong JID or nickname");
2237 goto room_ban_return;
2238 }
2239 banjid = jidtodisp(tmp);
2240 } else
2241 banjid = jid_utf8;
2242
2243 scr_LogPrint(LPRINT_NORMAL, "Requesting a ban for %s", banjid);
2244
2223 reason_utf8 = to_utf8(arg); 2245 reason_utf8 = to_utf8(arg);
2224 jb_room_setattrib(roomid, jid_utf8, NULL, ra, reason_utf8); 2246 jb_room_setattrib(roomid, banjid, NULL, ra, reason_utf8);
2247 g_free(reason_utf8);
2248
2249 room_ban_return:
2250 g_free(bjid);
2225 g_free(jid_utf8); 2251 g_free(jid_utf8);
2226 g_free(reason_utf8);
2227
2228 free_arg_lst(paramlst); 2252 free_arg_lst(paramlst);
2229 } 2253 }
2230 2254
2231 // The expected argument is a Jabber id 2255 // The expected argument is a Jabber id
2232 static void room_unban(gpointer bud, char *arg) 2256 static void room_unban(gpointer bud, char *arg)