-module(mod_pubsub).
-author('christophe.romain@process-one.net').
--version('1.12-06').
+-version('1.13-0').
-behaviour(gen_server).
-behaviour(gen_mod).
#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;
% {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}) ->
?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]),
?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) ->
{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]}.
-module(mod_pubsub_odbc).
-author('christophe.romain@process-one.net').
--version('1.12-06').
+-version('1.13-0').
-behaviour(gen_server).
-behaviour(gen_mod).
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
% {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}) ->
?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]),
?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) ->
{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]}.
{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},
{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},
{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},
{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},
{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},
{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},
{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},
{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},
{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},
{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},
{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},
{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},
{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},
---- 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)
--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.