<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>.gitignore</filename>
    </added>
    <added>
      <filename>include/mod_muc.hrl</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -106,6 +106,8 @@
 		 logging = false,
 		 custom = []
 		}).
+		
+
 %% @type user() = #user{
 %%          jid=jid(),
 %%          nick=string(),</diff>
      <filename>include/mod_muc_room.hrl</filename>
    </modified>
    <modified>
      <diff>@@ -49,9 +49,8 @@
 
 -include(&quot;ejabberd.hrl&quot;).
 -include(&quot;jlib.hrl&quot;).
+-include(&quot;mod_muc.hrl&quot;).
 
-
--record(muc_room, {name_host, opts}).
 -record(muc_online_room, {name_host, pid}).
 -record(muc_registered, {us_host, nick}).
 
@@ -520,8 +519,7 @@ do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
 
 load_permanent_rooms(Host, ServerHost, Access, HistorySize, RoomShaper, Storage) -&gt;
 	lists:foreach(
-	  fun({Handler, R }) -&gt;
-	      {Room, Host} = R#muc_room.name_host,
+	  fun(#muc_room{type=Handler, name_host={Room, _Host}, opts=Opts}) -&gt;
 	      case mnesia:dirty_read(muc_online_room, {Room, Host}) of
 		  [] -&gt;
 		      {ok, Pid} = mod_muc_room:start(
@@ -531,7 +529,7 @@ load_permanent_rooms(Host, ServerHost, Access, HistorySize, RoomShaper, Storage)
 				    Room,
 				    HistorySize,
 				    RoomShaper,
-				    R#muc_room.opts,
+				    Opts,
 				    Handler,
 				    Storage),
 		      register_room(Host, Room, Pid);</diff>
      <filename>src/mod_muc.erl</filename>
    </modified>
    <modified>
      <diff>@@ -72,7 +72,7 @@
 -include(&quot;jlib.hrl&quot;).
 -include(&quot;mod_muc_room.hrl&quot;).
 
--define(DEFAULT_HANDLER, muc_room_default).
+-define(DEFAULT_HANDLER, minimal_muc).
 
 -define(DBGFSM, true).
 
@@ -168,8 +168,8 @@ init([Host, ServerHost, Access, Room, HistorySize, RoomShaper, Opts, Handler, St
 				  room_shaper = Shaper},
     case handler_call(init, [Opts], State) of
         {result, ok, State1}-&gt;
-            ?INFO_MSG(&quot;Fetched MUC room ~s@~s (Handler ~s)&quot;, 
-	            [Room, Host, Handler]),
+            ?INFO_MSG(&quot;Fetched MUC room ~s@~s (State ~s)&quot;, 
+	            [Room, Host, Opts]),
 	        {ok, normal_state, State1};
         {error, Why, State1}-&gt;
             ?ERROR_MSG(&quot;Handler ~p returned an error for ~p : ~p&quot;,[Handler, Room, Why]),
@@ -2299,12 +2299,12 @@ handler_call(Function, Args, State, Handler) when is_record(State, state) -&gt;
 	Result -&gt; {result, Result, State}
     end.
 maybe_persist(_Handler, O, O) -&gt; ok; %No change
-maybe_persist(Handler, O, N) -&gt;
+maybe_persist(Handler, O, #headers{storage=S}=N) -&gt;
     case {catch Handler:is_persistent(O), catch Handler:is_persistent(N), O /= N} of
 	{_, true, true} -&gt;
-	    mod_muc:store_room(N#headers.server_host, N#headers.host, N#headers.room, Handler, Handler:make_opts(N));
+	    S:store_room(N#headers.server_host, N#headers.host, N#headers.room, Handler, Handler:make_opts(N));
 	{true, false, _} -&gt;
-	    mod_muc:forget_room(N#headers.server_host, N#headers.host, N#headers.room);
+	    S:forget_room(N#headers.server_host, N#headers.host, N#headers.room);
 	{_, _, _} -&gt;
 	    ok
     end.</diff>
      <filename>src/mod_muc_room.erl</filename>
    </modified>
    <modified>
      <diff>@@ -467,6 +467,7 @@ is_visitor(Jid, Headers) -&gt;
 	Opt -&gt; Headers#headers{config = (Headers#headers.config)#config{Opt = Val}}).
 
 set_opts([], Headers) -&gt;
+    ?DEBUG(&quot;Headers after applying opts : ~p&quot;, [Headers]),
     Headers;
 set_opts([{Opt, Val} | Opts], Headers) -&gt;
     NH = case Opt of</diff>
      <filename>src/muc_room_default.erl</filename>
    </modified>
    <modified>
      <diff>@@ -5,10 +5,9 @@
 
 -behaviour(gen_muc_storage).
 
--record(muc_room, {name_host, type, opts}).
 -include(&quot;ejabberd.hrl&quot;).
 -include(&quot;jlib.hrl&quot;).
--include(&quot;mod_muc_room.hrl&quot;). 
+-include(&quot;mod_muc.hrl&quot;). 
 -export([init/3,
          store_room/5,
          restore_room/3,</diff>
      <filename>src/muc_storage_default.erl</filename>
    </modified>
    <modified>
      <diff>@@ -7,10 +7,10 @@
 
 -behaviour(gen_muc_storage).
 
--record(muc_room, {name_host, type, opts}).
+
 -include(&quot;ejabberd.hrl&quot;).
 -include(&quot;jlib.hrl&quot;).
--include(&quot;mod_muc_room.hrl&quot;). 
+-include(&quot;mod_muc.hrl&quot;). 
 -export([init/3,
          store_room/5,
          restore_room/3,
@@ -37,10 +37,15 @@ init(_Host, _ServerHost, Opts)-&gt;
 % @doc Stores room.
 % Called on configuration change when MUC is persistent.  
 store_room(Host,ServerHost, Name, Type, Opts)-&gt;
-    ?DEBUG(&quot;store_room S3&quot;, []),
-    s3:write_object(get_bucket(), build_key(Host, Name), term_to_binary({Type, Opts}), &quot;application/erlang&quot;).
+    Bucket = get_bucket(),
+    Key = build_key(Host, Name),
+    Data = {Type, Opts},
+    Res = s3:write_term(Bucket, Key, Data),
+    ?DEBUG(&quot;~p = s3:write_term(~p, ~p, ~p) &quot;, [Res,Bucket, Key, Data]),
+    Res.
+    
 
-% @spec (Host,ServerHost, Name)-&gt; Config
+% @spec (Host,ServerHost, Name)-&gt; {Handler, Config}
 % @doc restores room from storage
 restore_room(Host,ServerHost, Name)-&gt;
     ?DEBUG(&quot;restore_room S3&quot;, []),
@@ -61,16 +66,17 @@ forget_room(Host, ServerHost, Name) -&gt;
 % @doc Used for disco
 fetch_all_rooms(ServerHost, Host)-&gt;
     ?DEBUG(&quot;fetch_all_rooms muc_s3&quot;, []),
-    case s3:get_objects(get_bucket(),[{prefix,&quot;muc@&quot;++Host}] ) of
+    case s3:get_objects(get_bucket(),[{prefix,build_key(Host,&quot;&quot;)}] ) of
 	{'EXIT', Reason} -&gt;
 	    ?ERROR_MSG(&quot;~p&quot;, [Reason]),
 	    [];
 	{error, timeout} -&gt;
 	    ?ERROR_MSG(&quot;Timeout on S3&quot;, []),
 	    [];
-	{ok, Rs}-&gt;
-	    lists:map(fun({Key, Value})-&gt;
-	        #muc_room{name_host = split_key(Key), opts=binary_to_term(list_to_binary(Value))}
+	Rs-&gt;
+	    lists:map(fun({Key, Value, Headers})-&gt;
+	        {Type, Opts} = binary_to_term(list_to_binary(Value)),
+	        #muc_room{name_host = split_key(Key), opts=Opts, type=Type}
 	    end, Rs)
 	end.
     </diff>
      <filename>src/s3_muc_storage.erl</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ab448c1589d5814ab5a87f9e4e9e04f0d4899e70</id>
    </parent>
  </parents>
  <author>
    <name>Eric Cestari</name>
    <email>ecestari@mac.com</email>
  </author>
  <url>http://github.com/cstar/modular_muc/commit/af74c96428c613acca002d240be86a46bed0c822</url>
  <id>af74c96428c613acca002d240be86a46bed0c822</id>
  <committed-date>2009-05-07T01:32:04-07:00</committed-date>
  <authored-date>2009-05-07T01:32:04-07:00</authored-date>
  <message>Corrected bugs 
- loading from storage fine
- extracted #muc_room{} into mod_muc.hrl 
- corrected bugs in s3_muc_storage
- added traces
Know bugs :
- All persistent data is erased on loading muc room and replaced by defaults.</message>
  <tree>f4fbb589f1ebbbee2dce23abb076c7ae2c5814a7</tree>
  <committer>
    <name>Eric Cestari</name>
    <email>ecestari@mac.com</email>
  </committer>
</commit>
