From b168cd7cf236e907a3b688390266c1b7de720199 Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Thu, 24 Sep 2009 19:47:01 +0000 Subject: [PATCH] fix EJAB-1044 and EJAB-1055 SVN Revision: 2628 --- src/mod_pubsub/mod_pubsub.erl | 19 +++++++++++++---- src/mod_pubsub/mod_pubsub_odbc.erl | 27 +++++++++++++++++------- src/mod_pubsub/node.template | 1 + src/mod_pubsub/node_buddy.erl | 1 + src/mod_pubsub/node_club.erl | 1 + src/mod_pubsub/node_dispatch.erl | 1 + src/mod_pubsub/node_flat.erl | 1 + src/mod_pubsub/node_flat_odbc.erl | 1 + src/mod_pubsub/node_hometree.erl | 1 + src/mod_pubsub/node_hometree_odbc.erl | 1 + src/mod_pubsub/node_mb.erl | 1 + src/mod_pubsub/node_pep.erl | 1 + src/mod_pubsub/node_pep_odbc.erl | 1 + src/mod_pubsub/node_private.erl | 1 + src/mod_pubsub/node_public.erl | 1 + src/mod_pubsub/pubsub_odbc.patch | 30 +++++++++++++-------------- 16 files changed, 62 insertions(+), 27 deletions(-) diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl index d58dd7f3e..53c4e8569 100644 --- a/src/mod_pubsub/mod_pubsub.erl +++ b/src/mod_pubsub/mod_pubsub.erl @@ -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). @@ -483,7 +483,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; @@ -3087,10 +3087,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}) -> @@ -3335,6 +3339,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]), @@ -3466,6 +3472,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) -> @@ -3730,6 +3738,9 @@ itemsEls(Items) -> #xmlel{ns = ?NS_PUBSUB, name = 'item', attrs = itemAttr(ItemId), children = Payload} end, Items). +add_message_type(#xmlel{name='message'} = El, Type) -> exmpp_stanza:set_type(El, Type); +add_message_type(El, _Type) -> El. + add_headers(#xmlel{} = El, HeaderEls) -> HeaderEl = #xmlel{ns = ?NS_SHIM, name = 'headers', children = HeaderEls}, exmpp_xml:prepend_child(El, HeaderEl). diff --git a/src/mod_pubsub/mod_pubsub_odbc.erl b/src/mod_pubsub/mod_pubsub_odbc.erl index 21d7f5ba7..303fd0cfc 100644 --- a/src/mod_pubsub/mod_pubsub_odbc.erl +++ b/src/mod_pubsub/mod_pubsub_odbc.erl @@ -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). @@ -305,14 +305,14 @@ send_loop(State) -> %% and if the node is so configured, send the last published item to From lists:foreach(fun(PType) -> Subscriptions = case catch node_action(Host, PType, get_entity_subscriptions_for_send_last, [Host, JID]) of - {result, S} -> S; - _ -> [] - end, + {result, S} -> S; + _ -> [] + end, lists:foreach( 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); + #pubsub_node{nodeid = {H, N}, type = Type, id = NodeId} = Node, + send_items(H, N, NodeId, Type, LJID, last); true -> % resource not concerned about that subscription ok @@ -2918,10 +2918,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}) -> @@ -3190,6 +3194,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]), @@ -3321,6 +3327,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) -> @@ -3617,6 +3625,9 @@ itemsEls(Items) -> #xmlel{ns = ?NS_PUBSUB, name = 'item', attrs = itemAttr(ItemId), children = Payload} end, Items). +add_message_type(#xmlel{name='message'} = El, Type) -> exmpp_stanza:set_type(El, Type); +add_message_type(El, _Type) -> El. + add_headers(#xmlel{} = El, HeaderEls) -> HeaderEl = #xmlel{ns = ?NS_SHIM, name = 'headers', children = HeaderEls}, exmpp_xml:prepend_child(El, HeaderEl). diff --git a/src/mod_pubsub/node.template b/src/mod_pubsub/node.template index a83408110..a6c8a9477 100644 --- a/src/mod_pubsub/node.template +++ b/src/mod_pubsub/node.template @@ -86,6 +86,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}, diff --git a/src/mod_pubsub/node_buddy.erl b/src/mod_pubsub/node_buddy.erl index 0639e1dee..0d672a748 100644 --- a/src/mod_pubsub/node_buddy.erl +++ b/src/mod_pubsub/node_buddy.erl @@ -90,6 +90,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}, diff --git a/src/mod_pubsub/node_club.erl b/src/mod_pubsub/node_club.erl index 579ba7ba2..3e27e2013 100644 --- a/src/mod_pubsub/node_club.erl +++ b/src/mod_pubsub/node_club.erl @@ -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}, diff --git a/src/mod_pubsub/node_dispatch.erl b/src/mod_pubsub/node_dispatch.erl index ad6778f31..2dc1d3f30 100644 --- a/src/mod_pubsub/node_dispatch.erl +++ b/src/mod_pubsub/node_dispatch.erl @@ -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}, diff --git a/src/mod_pubsub/node_flat.erl b/src/mod_pubsub/node_flat.erl index b6bf4d1c9..6e5c2372a 100644 --- a/src/mod_pubsub/node_flat.erl +++ b/src/mod_pubsub/node_flat.erl @@ -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}, diff --git a/src/mod_pubsub/node_flat_odbc.erl b/src/mod_pubsub/node_flat_odbc.erl index 4a7d360fd..08d818a41 100644 --- a/src/mod_pubsub/node_flat_odbc.erl +++ b/src/mod_pubsub/node_flat_odbc.erl @@ -81,6 +81,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}, diff --git a/src/mod_pubsub/node_hometree.erl b/src/mod_pubsub/node_hometree.erl index e707ceaea..11b076a92 100644 --- a/src/mod_pubsub/node_hometree.erl +++ b/src/mod_pubsub/node_hometree.erl @@ -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}, diff --git a/src/mod_pubsub/node_hometree_odbc.erl b/src/mod_pubsub/node_hometree_odbc.erl index 75cb0f10f..c3ee1cf28 100644 --- a/src/mod_pubsub/node_hometree_odbc.erl +++ b/src/mod_pubsub/node_hometree_odbc.erl @@ -145,6 +145,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}, diff --git a/src/mod_pubsub/node_mb.erl b/src/mod_pubsub/node_mb.erl index 8debc41c1..6fdebef43 100644 --- a/src/mod_pubsub/node_mb.erl +++ b/src/mod_pubsub/node_mb.erl @@ -93,6 +93,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}, diff --git a/src/mod_pubsub/node_pep.erl b/src/mod_pubsub/node_pep.erl index 0a153fc1a..00d0c4095 100644 --- a/src/mod_pubsub/node_pep.erl +++ b/src/mod_pubsub/node_pep.erl @@ -88,6 +88,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}, diff --git a/src/mod_pubsub/node_pep_odbc.erl b/src/mod_pubsub/node_pep_odbc.erl index e297f5822..0b16eaa60 100644 --- a/src/mod_pubsub/node_pep_odbc.erl +++ b/src/mod_pubsub/node_pep_odbc.erl @@ -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}, diff --git a/src/mod_pubsub/node_private.erl b/src/mod_pubsub/node_private.erl index e6d605089..1cff4c11b 100644 --- a/src/mod_pubsub/node_private.erl +++ b/src/mod_pubsub/node_private.erl @@ -90,6 +90,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}, diff --git a/src/mod_pubsub/node_public.erl b/src/mod_pubsub/node_public.erl index 75112e905..d227f6b89 100644 --- a/src/mod_pubsub/node_public.erl +++ b/src/mod_pubsub/node_public.erl @@ -91,6 +91,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}, diff --git a/src/mod_pubsub/pubsub_odbc.patch b/src/mod_pubsub/pubsub_odbc.patch index 40104ed62..f5d5d2895 100644 --- a/src/mod_pubsub/pubsub_odbc.patch +++ b/src/mod_pubsub/pubsub_odbc.patch @@ -1,5 +1,5 @@ ---- mod_pubsub.erl 2009-09-23 18:18:35.000000000 +0200 -+++ mod_pubsub_odbc.erl 2009-09-23 18:26:41.000000000 +0200 +--- mod_pubsub.erl 2009-09-24 21:40:32.000000000 +0200 ++++ mod_pubsub_odbc.erl 2009-09-24 21:46:01.000000000 +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'). @@ -58,9 +58,9 @@ -include("adhoc.hrl"). @@ -233,21 +233,21 @@ lists:foreach(fun(PType) -> - {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, JID]), + Subscriptions = case catch node_action(Host, PType, get_entity_subscriptions_for_send_last, [Host, JID]) of -+ {result, S} -> S; -+ _ -> [] -+ end, ++ {result, S} -> S; ++ _ -> [] ++ end, lists:foreach( fun({Node, subscribed, _, SubJID}) -> if (SubJID == LJID) or (SubJID == BJID) -> - #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); ++ #pubsub_node{nodeid = {H, N}, type = Type, id = NodeId} = Node, ++ send_items(H, N, NodeId, Type, LJID, last); true -> % resource not concerned about that subscription ok @@ -622,7 +622,7 @@ _ -> Acc end; (_, Acc) -> -@@ -3257,6 +3088,30 @@ +@@ -3261,6 +3092,30 @@ Result end. @@ -653,7 +653,7 @@ %% @spec (Host, Options) -> MaxItems %% Host = host() %% Options = [Option] -@@ -3642,7 +3497,13 @@ +@@ -3650,7 +3505,13 @@ tree_action(Host, Function, Args) -> ?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]), Fun = fun() -> tree_call(Host, Function, Args) end, @@ -668,7 +668,7 @@ %% @doc

node plugin call.

node_call(Type, Function, Args) -> -@@ -3662,13 +3523,13 @@ +@@ -3670,13 +3531,13 @@ node_action(Host, Type, Function, Args) -> ?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]), @@ -684,7 +684,7 @@ case tree_call(Host, get_node, [Host, Node]) of N when is_record(N, pubsub_node) -> case Action(N) of -@@ -3681,8 +3542,15 @@ +@@ -3689,8 +3550,15 @@ end end, Trans). @@ -702,7 +702,7 @@ {result, Result} -> {result, Result}; {error, Error} -> {error, Error}; {atomic, {result, Result}} -> {result, Result}; -@@ -3690,6 +3558,15 @@ +@@ -3698,6 +3566,15 @@ {aborted, Reason} -> ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]), {error, 'internal-server-error'}; @@ -718,7 +718,7 @@ {'EXIT', Reason} -> ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]), {error, 'internal-server-error'}; -@@ -3698,6 +3575,16 @@ +@@ -3706,6 +3583,16 @@ {error, 'internal-server-error'} end.