fix EJAB-1044 and EJAB-1055
authorChristophe Romain <christophe.romain@process-one.net>
Thu, 24 Sep 2009 19:28:43 +0000 (19:28 +0000)
committerChristophe Romain <christophe.romain@process-one.net>
Thu, 24 Sep 2009 19:28:43 +0000 (19:28 +0000)
SVN Revision: 2626

16 files changed:
src/mod_pubsub/mod_pubsub.erl
src/mod_pubsub/mod_pubsub_odbc.erl
src/mod_pubsub/node.template
src/mod_pubsub/node_buddy.erl
src/mod_pubsub/node_club.erl
src/mod_pubsub/node_dispatch.erl
src/mod_pubsub/node_flat.erl
src/mod_pubsub/node_flat_odbc.erl
src/mod_pubsub/node_hometree.erl
src/mod_pubsub/node_hometree_odbc.erl
src/mod_pubsub/node_mb.erl
src/mod_pubsub/node_pep.erl
src/mod_pubsub/node_pep_odbc.erl
src/mod_pubsub/node_private.erl
src/mod_pubsub/node_public.erl
src/mod_pubsub/pubsub_odbc.patch

index 794c44e6e97ad25a2f03fdb39da4692cd86317ba..6b21f45851ecd36858cd81aeb976277b5ccb7285 100644 (file)
@@ -47,7 +47,7 @@
 
 -module(mod_pubsub).
 -author('christophe.romain@process-one.net').
--version('1.12-06').
+-version('1.13-0').
 
 -behaviour(gen_server).
 -behaviour(gen_mod).
@@ -474,7 +474,7 @@ send_loop(State) ->
                        #pubsub_node{nodeid = {H, N}, type = Type, id = NodeId, options = Options} = Node,
                        case get_option(Options, send_last_published_item) of
                            on_sub_and_presence ->
-                               send_items(H, N, NodeId, Type, SubJID, last);
+                               send_items(H, N, NodeId, Type, LJID, last);
                            _ ->
                                ok
                        end;
@@ -3030,10 +3030,14 @@ get_options_for_subs(NodeID, Subs) ->
 %          {result, false}
 %    end
 
-broadcast_stanza(Host, Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyType, Stanza) ->
-    %AccessModel = get_option(NodeOptions, access_model),
+broadcast_stanza(Host, Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyType, BaseStanza) ->
+    NotificationType = get_option(NodeOptions, notification_type),
     BroadcastAll = get_option(NodeOptions, broadcast_all_resources), %% XXX this is not standard, but usefull
     From = service_jid(Host),
+    Stanza = case NotificationType of
+       normal -> BaseStanza;
+       MsgType -> add_message_type(BaseStanza, atom_to_list(MsgType))
+       end,
     %% Handles explicit subscriptions
     NodesByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth),
     lists:foreach(fun ({LJID, Nodes}) ->
@@ -3277,6 +3281,8 @@ get_configure_xfields(_Type, Options, Lang, Groups) ->
      ?LISTM_CONFIG_FIELD("Roster groups allowed to subscribe", roster_groups_allowed, Groups),
      ?ALIST_CONFIG_FIELD("Specify the publisher model", publish_model,
                         [publishers, subscribers, open]),
+     ?ALIST_CONFIG_FIELD("Specify the event message type", notification_type,
+                        [headline, normal]),
      ?INTEGER_CONFIG_FIELD("Max payload size in bytes", max_payload_size),
      ?ALIST_CONFIG_FIELD("When to send the last published item", send_last_published_item,
                         [never, on_sub, on_sub_and_presence]),
@@ -3408,6 +3414,8 @@ set_xoption(Host, [{"pubsub#access_model", [Val]} | Opts], NewOpts) ->
     ?SET_ALIST_XOPT(access_model, Val, [open, authorize, presence, roster, whitelist]);
 set_xoption(Host, [{"pubsub#publish_model", [Val]} | Opts], NewOpts) ->
     ?SET_ALIST_XOPT(publish_model, Val, [publishers, subscribers, open]);
+set_xoption(Host, [{"pubsub#notification_type", [Val]} | Opts], NewOpts) ->
+    ?SET_ALIST_XOPT(notification_type, Val, [headline, normal]);
 set_xoption(Host, [{"pubsub#node_type", [Val]} | Opts], NewOpts) ->
     ?SET_ALIST_XOPT(node_type, Val, [leaf, collection]);
 set_xoption(Host, [{"pubsub#max_payload_size", [Val]} | Opts], NewOpts) ->
@@ -3670,6 +3678,11 @@ itemsEls(Items) ->
        {xmlelement, "item", itemAttr(ItemId), Payload}
     end, Items).
 
+add_message_type({xmlelement, "message", Attrs, Els}, Type) ->
+    {xmlelement, "message", [{"type", Type}|Attrs], Els};
+add_message_type(XmlEl, _Type) ->
+    XmlEl.
+
 add_headers({xmlelement, Name, Attrs, Els}, HeaderEls) ->
     HeaderEl = {xmlelement, "headers", [{"xmlns", ?NS_SHIM}], HeaderEls},
     {xmlelement, Name, Attrs, [HeaderEl | Els]}.
index b95f6ea4b6c37aea03a19b946f491a8e8d7af672..0e8c3c3fe38010db7fe06d1474151ba3e2d416f6 100644 (file)
@@ -47,7 +47,7 @@
 
 -module(mod_pubsub_odbc).
 -author('christophe.romain@process-one.net').
--version('1.12-06').
+-version('1.13-0').
 
 -behaviour(gen_server).
 -behaviour(gen_mod).
@@ -301,7 +301,7 @@ send_loop(State) ->
                fun({Node, subscribed, _, SubJID}) -> 
                    if (SubJID == LJID) or (SubJID == BJID) ->
                        #pubsub_node{nodeid = {H, N}, type = Type, id = NodeId} = Node,
-                       send_items(H, N, NodeId, Type, SubJID, last);
+                       send_items(H, N, NodeId, Type, LJID, last);
                    true ->
                        % resource not concerned about that subscription
                        ok
@@ -2860,10 +2860,14 @@ get_options_for_subs(NodeID, Subs) ->
 %          {result, false}
 %    end
 
-broadcast_stanza(Host, Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyType, Stanza) ->
-    %AccessModel = get_option(NodeOptions, access_model),
+broadcast_stanza(Host, Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyType, BaseStanza) ->
+    NotificationType = get_option(NodeOptions, notification_type),
     BroadcastAll = get_option(NodeOptions, broadcast_all_resources), %% XXX this is not standard, but usefull
     From = service_jid(Host),
+    Stanza = case NotificationType of
+       normal -> BaseStanza;
+       MsgType -> add_message_type(BaseStanza, atom_to_list(MsgType))
+       end,
     %% Handles explicit subscriptions
     NodesByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth),
     lists:foreach(fun ({LJID, Nodes}) ->
@@ -3131,6 +3135,8 @@ get_configure_xfields(_Type, Options, Lang, Groups) ->
      ?LISTM_CONFIG_FIELD("Roster groups allowed to subscribe", roster_groups_allowed, Groups),
      ?ALIST_CONFIG_FIELD("Specify the publisher model", publish_model,
                         [publishers, subscribers, open]),
+     ?ALIST_CONFIG_FIELD("Specify the event message type", notification_type,
+                        [headline, normal]),
      ?INTEGER_CONFIG_FIELD("Max payload size in bytes", max_payload_size),
      ?ALIST_CONFIG_FIELD("When to send the last published item", send_last_published_item,
                         [never, on_sub, on_sub_and_presence]),
@@ -3262,6 +3268,8 @@ set_xoption(Host, [{"pubsub#access_model", [Val]} | Opts], NewOpts) ->
     ?SET_ALIST_XOPT(access_model, Val, [open, authorize, presence, roster, whitelist]);
 set_xoption(Host, [{"pubsub#publish_model", [Val]} | Opts], NewOpts) ->
     ?SET_ALIST_XOPT(publish_model, Val, [publishers, subscribers, open]);
+set_xoption(Host, [{"pubsub#notification_type", [Val]} | Opts], NewOpts) ->
+    ?SET_ALIST_XOPT(notification_type, Val, [headline, normal]);
 set_xoption(Host, [{"pubsub#node_type", [Val]} | Opts], NewOpts) ->
     ?SET_ALIST_XOPT(node_type, Val, [leaf, collection]);
 set_xoption(Host, [{"pubsub#max_payload_size", [Val]} | Opts], NewOpts) ->
@@ -3556,6 +3564,11 @@ itemsEls(Items) ->
        {xmlelement, "item", itemAttr(ItemId), Payload}
     end, Items).
 
+add_message_type({xmlelement, "message", Attrs, Els}, Type) ->
+    {xmlelement, "message", [{"type", Type}|Attrs], Els};
+add_message_type(XmlEl, _Type) ->
+    XmlEl.
+
 add_headers({xmlelement, Name, Attrs, Els}, HeaderEls) ->
     HeaderEl = {xmlelement, "headers", [{"xmlns", ?NS_SHIM}], HeaderEls},
     {xmlelement, Name, Attrs, [HeaderEl | Els]}.
index e70febb8c29e712a85ea06702e9304939333f0e7..e0c743d38e311efcdf5099389af35bb088cc75e5 100644 (file)
@@ -88,6 +88,7 @@ options() ->
      {access_model, open},
      {roster_groups_allowed, []},
      {publish_model, publishers},
+     {notification_type, headline},
      {max_payload_size, ?MAX_PAYLOAD_SIZE},
      {send_last_published_item, on_sub_and_presence},
      {deliver_notifications, true},
index ee804b34cf7d7d09002796f76ab3419b8477ec4b..20b679ca792a8d855a4c047c54b0f2c67d0e6ec5 100644 (file)
@@ -89,6 +89,7 @@ options() ->
      {access_model, presence},
      {roster_groups_allowed, []},
      {publish_model, publishers},
+     {notification_type, headline},
      {max_payload_size, ?MAX_PAYLOAD_SIZE},
      {send_last_published_item, never},
      {deliver_notifications, true},
index 8f14387c03d5cee687289468bb51454b4ded8265..3c1596cd6e8e21957c24b4217a88e3ea153ff8a1 100644 (file)
@@ -89,6 +89,7 @@ options() ->
      {access_model, authorize},
      {roster_groups_allowed, []},
      {publish_model, publishers},
+     {notification_type, headline},
      {max_payload_size, ?MAX_PAYLOAD_SIZE},
      {send_last_published_item, never},
      {deliver_notifications, true},
index 2ce01b23800b3365fc3724ab0775c0d8a995fe9c..8c2c7d0f4d98f2ee6cd20b7d8f222e17afa607ef 100644 (file)
@@ -87,6 +87,7 @@ options() ->
      {access_model, open},
      {roster_groups_allowed, []},
      {publish_model, publishers},
+     {notification_type, headline},
      {max_payload_size, ?MAX_PAYLOAD_SIZE},
      {send_last_published_item, never},
      {deliver_notifications, true},
index 0088034d143525a5f8d2fef8d5d1d4bd089e6ca2..67b95973abf26a610b1f977d45d826f7233d38db 100644 (file)
@@ -80,6 +80,7 @@ options() ->
      {access_model, open},
      {roster_groups_allowed, []},
      {publish_model, publishers},
+     {notification_type, headline},
      {max_payload_size, ?MAX_PAYLOAD_SIZE},
      {send_last_published_item, on_sub_and_presence},
      {deliver_notifications, true},
index 6aed3fbc2b09b6deec9be17705dc69f0c2315081..f073c70a8aa7e198d15a0becaa8664d63b972b32 100644 (file)
@@ -85,6 +85,7 @@ options() ->
      {access_model, open},
      {roster_groups_allowed, []},
      {publish_model, publishers},
+     {notification_type, headline},
      {max_payload_size, ?MAX_PAYLOAD_SIZE},
      {send_last_published_item, on_sub_and_presence},
      {deliver_notifications, true},
index 38453e4ee61f395e8b9eb7c2c06afb4267aed0b1..c1c2a55f63b8c7dcb85daaf51651f7c708be0d76 100644 (file)
@@ -143,6 +143,7 @@ options() ->
      {access_model, open},
      {roster_groups_allowed, []},
      {publish_model, publishers},
+     {notification_type, headline},
      {max_payload_size, ?MAX_PAYLOAD_SIZE},
      {send_last_published_item, on_sub_and_presence},
      {deliver_notifications, true},
index 0d6cefe22c76ec8dda66aeaeeef997e5f8a673e2..d9e2a815a76a6b3cbd663673bc714fe222db10e7 100644 (file)
@@ -147,6 +147,7 @@ options() ->
      {access_model, open},
      {roster_groups_allowed, []},
      {publish_model, publishers},
+     {notification_type, headline},
      {max_payload_size, ?MAX_PAYLOAD_SIZE},
      {send_last_published_item, on_sub_and_presence},
      {deliver_notifications, true},
index beef44996cd5ffe7c9d84d3fe63c4823203fe2da..c1accca3c83c266b07bc56b91e282fcf76ae6f41 100644 (file)
@@ -92,6 +92,7 @@ options() ->
      {access_model, presence},
      {roster_groups_allowed, []},
      {publish_model, publishers},
+     {notification_type, headline},
      {max_payload_size, ?MAX_PAYLOAD_SIZE},
      {send_last_published_item, on_sub_and_presence},
      {deliver_notifications, true},
index 7b7794a8a80ef0386a80155a77c39ca9389f7f94..754312b83609a04eacde59a37e9dd5886ac09e0e 100644 (file)
@@ -87,6 +87,7 @@ options() ->
      {access_model, presence},
      {roster_groups_allowed, []},
      {publish_model, publishers},
+     {notification_type, headline},
      {max_payload_size, ?MAX_PAYLOAD_SIZE},
      {send_last_published_item, on_sub_and_presence},
      {deliver_notifications, true},
index 819bc1766025c00fa3ce552ddd14a7a29918a1d0..95c737a6ac0ac29d9b3ce4d842f8466ef50a8936 100644 (file)
@@ -95,6 +95,7 @@ options() ->
      {access_model, presence},
      {roster_groups_allowed, []},
      {publish_model, publishers},
+     {notification_type, headline},
      {max_payload_size, ?MAX_PAYLOAD_SIZE},
      {send_last_published_item, on_sub_and_presence},
      {deliver_notifications, true},
index 610ac7773fbafae4cdc3684e425081ea9ab6f75d..054485ef5c79896b1d11f7f1ca3a95d6ccf28ce8 100644 (file)
@@ -89,6 +89,7 @@ options() ->
      {access_model, whitelist},
      {roster_groups_allowed, []},
      {publish_model, publishers},
+     {notification_type, headline},
      {max_payload_size, ?MAX_PAYLOAD_SIZE},
      {send_last_published_item, never},
      {deliver_notifications, false},
index 0797af77862516a82ed1fe83cf3942f867ea24f1..ee440f933e6e3741e4c05a5d3723809fb5e31878 100644 (file)
@@ -89,6 +89,7 @@ options() ->
      {access_model, open},
      {roster_groups_allowed, []},
      {publish_model, publishers},
+     {notification_type, headline},
      {max_payload_size, ?MAX_PAYLOAD_SIZE},
      {send_last_published_item, never},
      {deliver_notifications, true},
index c59ec725d3ffa37c76f6d17c634a070bd142b199..400ec948bd550715401088805c95d9de23ed8b97 100644 (file)
@@ -1,5 +1,5 @@
---- mod_pubsub.erl     2009-09-23 17:53:47.000000000 +0200
-+++ mod_pubsub_odbc.erl        2009-09-23 17:54:27.000000000 +0200
+--- mod_pubsub.erl     2009-09-24 18:34:03.471785103 +0200
++++ mod_pubsub_odbc.erl        2009-09-24 18:35:20.256479455 +0200
 @@ -45,7 +45,7 @@
  %%% TODO
  %%% plugin: generate Reply (do not use broadcast atom anymore)
@@ -7,7 +7,7 @@
 --module(mod_pubsub).
 +-module(mod_pubsub_odbc).
  -author('christophe.romain@process-one.net').
- -version('1.12-06').
+ -version('1.13-0').
  
 @@ -57,9 +57,9 @@
  -include("jlib.hrl").
 -                      #pubsub_node{nodeid = {H, N}, type = Type, id = NodeId, options = Options} = Node,
 -                      case get_option(Options, send_last_published_item) of
 -                          on_sub_and_presence ->
--                              send_items(H, N, NodeId, Type, SubJID, last);
+-                              send_items(H, N, NodeId, Type, LJID, last);
 -                          _ ->
 -                              ok
 -                      end;
 +                      #pubsub_node{nodeid = {H, N}, type = Type, id = NodeId} = Node,
-+                      send_items(H, N, NodeId, Type, SubJID, last);
++                      send_items(H, N, NodeId, Type, LJID, last);
                    true ->
                        % resource not concerned about that subscription
                        ok
                            _ -> Acc
                        end;
                    (_, Acc) ->
-@@ -3199,6 +3029,30 @@
+@@ -3203,6 +3033,30 @@
            Result
      end.
  
  %% @spec (Host, Options) -> MaxItems
  %%     Host = host()
  %%     Options = [Option]
-@@ -3581,7 +3435,13 @@
+@@ -3589,7 +3443,13 @@
  tree_action(Host, Function, Args) ->
      ?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
      Fun = fun() -> tree_call(Host, Function, Args) end,
  
  %% @doc <p>node plugin call.</p>
  node_call(Type, Function, Args) ->
-@@ -3601,13 +3461,13 @@
+@@ -3609,13 +3469,13 @@
  
  node_action(Host, Type, Function, Args) ->
      ?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
                        case tree_call(Host, get_node, [Host, Node]) of
                            N when is_record(N, pubsub_node) ->
                                case Action(N) of
-@@ -3620,8 +3480,14 @@
+@@ -3628,8 +3488,14 @@
                        end
                end, Trans).
  
        {result, Result} -> {result, Result};
        {error, Error} -> {error, Error};
        {atomic, {result, Result}} -> {result, Result};
-@@ -3629,6 +3495,15 @@
+@@ -3637,6 +3503,15 @@
        {aborted, Reason} ->
            ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
            {error, ?ERR_INTERNAL_SERVER_ERROR};
        {'EXIT', Reason} ->
            ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
            {error, ?ERR_INTERNAL_SERVER_ERROR};
-@@ -3637,6 +3512,17 @@
+@@ -3645,6 +3520,17 @@
            {error, ?ERR_INTERNAL_SERVER_ERROR}
      end.