[Gd-chatter] r11088 - trunk/libraries/network/xmpp-bot

hannes at gwydiondylan.org hannes at gwydiondylan.org
Wed Dec 20 22:34:48 CET 2006


Author: hannes
Date: Wed Dec 20 22:34:47 2006
New Revision: 11088

Modified:
   trunk/libraries/network/xmpp-bot/xmpp-bot.dylan
Log:
Bug: 7257
some locking

Modified: trunk/libraries/network/xmpp-bot/xmpp-bot.dylan
==============================================================================
--- trunk/libraries/network/xmpp-bot/xmpp-bot.dylan	(original)
+++ trunk/libraries/network/xmpp-bot/xmpp-bot.dylan	Wed Dec 20 22:34:47 2006
@@ -40,19 +40,20 @@
   send(xmpp-bot.client, make(<iq>, type: #"get", query: with-xml() query(xmlns => "jabber:iq:roster") end, id: "roster"));
 end;
 
+define constant $lock = make(<lock>);
 define method auto-subscriber (xmpp-bot, client, presence)
-  if (presence.type)
-    select (presence.type)
-      #"subscribe" => begin
-                        send(client, make(<presence>,
-                                          to: presence.from,
-                                          type: #"subscribed"));
-                        send(client, make(<presence>,
-                                          to: presence.from,
-                                          type: #"subscribe"));
-                        
-                      end;
-      #"unsubscribe" =>
+  with-lock($lock)
+    if (presence.type)
+      select (presence.type)
+        #"subscribe" => begin
+                          send(client, make(<presence>,
+                                            to: presence.from,
+                                            type: #"subscribed"));
+                          send(client, make(<presence>,
+                                            to: presence.from,
+                                            type: #"subscribe"));
+                        end;
+        #"unsubscribe" =>
                         begin
                           send(client, make(<presence>,
                                             to: presence.from,
@@ -67,30 +68,33 @@
                                                            as(<string>, presence.from),
                                                            test: subsequence-position);
                         end;
-      #"unavailable" => begin
-                          format-out("%s went offline\n", as(<string>, presence.from));
-                          xmpp-bot.online-users := remove!(xmpp-bot.online-users,
-                                                           as(<string>, presence.from),
-                                                           test: \=);
-                        end;
-       otherwise => begin
-                      format-out("Didn't know what to do with type %=\n", presence.type);
-                    end;
-    end select;
-  else
-    unless (any?(method(a) a = as(<string>, presence.from) end, xmpp-bot.online-users))
-      xmpp-bot.online-users := add!(xmpp-bot.online-users, as(<string>, presence.from));
+        #"unavailable" => begin
+                            format-out("%s went offline\n", as(<string>, presence.from));
+                            xmpp-bot.online-users := remove!(xmpp-bot.online-users,
+                                                             as(<string>, presence.from),
+                                                             test: \=);
+                          end;
+         otherwise => begin
+                        format-out("Didn't know what to do with type %=\n", presence.type);
+                      end;
+      end select;
+    else
+      unless (any?(method(a) a = as(<string>, presence.from) end, xmpp-bot.online-users))
+        xmpp-bot.online-users := add!(xmpp-bot.online-users, as(<string>, presence.from));
+      end;
     end;
   end;
 end;
 
 define method broadcast-message (bot :: <xmpp-bot>, message :: type-union(<string>, <element>))
-  do(method (user)
-       send(bot.client,
-            make(<message>,
-                 type: #"chat",
-                 body: message,
-                 to: user));
-     end, bot.online-users);
+  with-lock($lock)
+    do(method (user)
+         send(bot.client,
+              make(<message>,
+                   type: #"chat",
+                   body: message,
+                   to: user));
+       end, bot.online-users);
+  end;
 end;
 



More information about the chatter mailing list