diff mcabber/src/commands.c @ 452:dfd9c62b3a39

Jabber Id syntax checks
author Mikael Berthe <mikael@lilotux.net>
date Mon, 26 Sep 2005 22:08:48 +0200
parents e08b0c2d0e54
children d647b92e541f
line wrap: on
line diff
--- a/mcabber/src/commands.c	Mon Sep 26 00:27:56 2005 +0200
+++ b/mcabber/src/commands.c	Mon Sep 26 22:08:48 2005 +0200
@@ -459,9 +459,14 @@
   while (*st && *st == ' ')
     st++;
 
-  // FIXME check id =~ jabber id
-  scr_LogPrint(LPRINT_LOGNORM, "Sending to <%s> /status %s", id, st);
-  setstatus(id, st);
+  if (check_jid_syntax(id)) {
+    scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", id);
+  } else {
+    mc_strtolower(id);
+    scr_LogPrint(LPRINT_LOGNORM, "Sending to <%s> /status %s", id, st);
+    setstatus(id, st);
+  }
+  g_free(id);
 }
 
 static void do_add(char *arg)
@@ -480,11 +485,15 @@
       nick++;
   }
 
-  // FIXME check id =~ jabber id
-  // 2nd parameter = optional nickname
-  jb_addbuddy(id, nick, NULL);
-  scr_LogPrint(LPRINT_LOGNORM, "Sent presence notification request to <%s>",
-               id);
+  if (check_jid_syntax(id)) {
+    scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", id);
+  } else {
+    mc_strtolower(id);
+    // 2nd parameter = optional nickname
+    jb_addbuddy(id, nick, NULL);
+    scr_LogPrint(LPRINT_LOGNORM, "Sent presence notification request to <%s>",
+                 id);
+  }
   g_free(id);
 }
 
@@ -943,12 +952,22 @@
       return;
     }
     // room syntax: "room@server/nick"
-    // FIXME: check roomid is a jid
     roomid = g_strdup_printf("%s/%s", roomname, nick);
+    if (check_jid_syntax(roomid)) {
+      scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber room", roomid);
+      g_free(roomname);
+      g_free(roomid);
+      return;
+    }
+
+    mc_strtolower(roomid);
     jb_room_join(roomid);
+
+    // We need to save the nickname for future use
     roster_usr = roster_add_user(roomname, NULL, NULL, ROSTER_TYPE_ROOM);
     if (roster_usr)
       buddy_setnickname(roster_usr->data, nick);
+
     g_free(roomname);
     g_free(roomid);
     buddylist_build();