mod_admin_extra

Hi!

mod_admin_extra highly extends indirect administrative features, but I've found that of SVN(v.815) the send_message doesn't post messages to offline contacts(mod_offline_odbc is enabled and works properly for regular clients).

If it was fixed(or realized), that would be very nice.

Thanks.

ejabberd doesn't store "headline"; try change to send "normal"

xyu wrote:

the send_message doesn't post messages to offline contacts

send_message is described: "Send a headline message to a local or remote bare of full JID". So, this command sends a message stanza of type "headline".

As explained in XMPP-IM 5.2.2. Type Attribute:

Quote:

headline -- The message provides an alert, a notification, or other information to which no reply is expected (e.g., news headlines, sports updates, near-real-time market data, and syndicated content). Because no reply to the message is expected, typically a receiving client will present a message of type "headline" in an interface that appropriately differentiates the message from standalone messages, chat messages, or groupchat messages (e.g., by not providing the recipient with the ability to reply). The receiving server SHOULD deliver the message to all of the recipient's available resources.

XMPP-IM 8.3.2.1. Message explains regarding offline storage:

Quote:

For a message stanza of type "headline", according to local service policies the server MUST either (1) add the message to offline storage or (2) silently discard the message (i.e., neither deliver it to the intended recipient nor return an error to the sender).

So ejabberd implements (2) and this is compliant with the protocol.

You would like it to implement (1), but it doesn't.

Another solution is to send a message stanza of type "normal":

Quote:

For a message stanza of type "chat" or "normal", the server SHOULD add the message to offline storage or forward the message to the user via a non-XMPP messaging system (e.g., to the user's email account).

In this case, if mod_offline is enabled, it will be used.

To send a message of type "normal", replace this function with this code:

build_send_message(Subject, Body) ->
    {xmlelement, "message",
     [],
     [{xmlelement, "subject", [], [{xmlcdata, Subject}]},
      {xmlelement, "body", [], [{xmlcdata, Body}]}
     ]
    }.

Patch. For interested :-)

Hi!

Thanks for Your advice! It helped!
I've created a small patch, leaving functionality for headline messages as send_headline, and changed send_message syntax, removing 'Subject'-field.
I really do not know, how it corresponds to XMPP and other standards, but I found such a function useful for me. Maybe I'm not alone :-)))
So, patch was created for ejabberd-modules SVN version 815.
It's a pity, but simple copying of code doesn't work :-)) because of text transformations while posting so, You have 2 ways:
1) see the changes, and make them manually
or
2) download it from
http://rapidshare.com/files/161264241/mod_admin_extra_send_message.patch...
or
http://www.megaupload.com/?d=N2D3CJ9J
filesize: 5234 bytes
md5: e732d580274029182f13a076628bf3d7)

--- mod_admin_extra.erl Thu Nov  6 12:53:49 2008
+++ /home/misc/trunk/src/mod_admin_extra.erl Thu Nov  6 13:24:28 2008
@@ -71,7 +71,8 @@
srg_user_add/4,
srg_user_del/4,
%% Stanza
- send_message/4,
+ send_headline/4,
+ send_message/3,
%% Stats
stats/1, stats/2
]).
@@ -380,13 +381,19 @@
args = [{user, string}, {host, string}, {group, string}, {grouphost, string}],
result = {res, rescode}},
-     #ejabberd_commands{name = send_message, tags = [stanza],
+     #ejabberd_commands{name = send_headline, tags = [stanza],
desc = "Send a headline message to a local or remote bare of full JID",
- module = ?MODULE, function = send_message,
+ module = ?MODULE, function = send_headline,
args = [{from, string}, {to, string},
{subject, string}, {body, string}],
result = {res, rescode}},
+     #ejabberd_commands{name = send_message, tags = [stanza],
+ desc = "Send a chat message to a local or remote bare of full JID",
+ module = ?MODULE, function = send_message,
+ args = [{from, string}, {to, string}, {body, string}],
+ result = {res, rescode}},
+
      #ejabberd_commands{name = stats, tags = [stats],
desc = "Get statistical value: registeredusers onlineusers onlineusersnode uptimeseconds",
module = ?MODULE, function = stats,
@@ -1007,49 +1014,92 @@
%%% Stanza
%%%
-%% @doc Send a message to a Jabber account.
+%% @doc Send a (headline) message to a Jabber account.
%% If a resource was specified in the JID,
-%% the message is sent only to that specific resource.
+%% the (headline) message is sent only to that specific resource.
%% If no resource was specified in the JID,
%% and the user is remote or local but offline,
-%% the message is sent to the bare JID.
+%% the (headline) message is sent to the bare JID.
%% If the user is local and is online in several resources,
-%% the message is sent to all its resources.
-send_message(FromJIDString, ToJIDString, Subject, Body) ->
+%% the (headline) message is sent to all its resources.
+send_headline(FromJIDString, ToJIDString, Subject, Body) ->
     FromJID = jlib:string_to_jid(FromJIDString),
     ToJID = jlib:string_to_jid(ToJIDString),
     ToUser = ToJID#jid.user,
     ToServer = ToJID#jid.server,
     case ToJID#jid.resource of
"" ->
-     send_message(FromJID, ToUser, ToServer, Subject, Body);
+     send_headline(FromJID, ToUser, ToServer, Subject, Body);
Resource ->
-     send_message(FromJID, ToUser, ToServer, Resource, Subject, Body)
+     send_headline(FromJID, ToUser, ToServer, Resource, Subject, Body)
     end.
-send_message(FromJID, ToUser, ToServer, Subject, Body) ->
+send_headline(FromJID, ToUser, ToServer, Subject, Body) ->
     case ejabberd_sm:get_user_resources(ToUser, ToServer) of
[] ->
-     send_message(FromJID, ToUser, ToServer, "", Subject, Body);
+     send_headline(FromJID, ToUser, ToServer, "", Subject, Body);
ToResources ->
    lists:foreach(
      fun(ToResource) ->
-       send_message(FromJID, ToUser, ToServer, ToResource, Subject, Body)
+       send_headline(FromJID, ToUser, ToServer, ToResource, Subject, Body)
      end,
      ToResources)
     end.
-send_message(FromJID, ToU, ToS, ToR, Subject, Body) ->
-    MPacket = build_send_message(Subject, Body),
+send_headline(FromJID, ToU, ToS, ToR, Subject, Body) ->
+    MPacket = build_send_headline(Subject, Body),
     ToJID = jlib:make_jid(ToU, ToS, ToR),
     ejabberd_router:route(FromJID, ToJID, MPacket).
-build_send_message(Subject, Body) ->
+build_send_headline(Subject, Body) ->
     {xmlelement, "message",
      [{"type", "headline"}],
      [{xmlelement, "subject", [], [{xmlcdata, Subject}]},
       {xmlelement, "body", [], [{xmlcdata, Body}]}
      ]
+    }.
+
+%% @doc Send a (chat) message to a Jabber account.
+%% If a resource was specified in the JID,
+%% the (chat) message is sent only to that specific resource.
+%% If no resource was specified in the JID,
+%% and the user is remote or local but offline,
+%% the (chat) message is sent to the bare JID.
+%% If the user is local and is online in several resources,
+%% the (chat) message is sent to all its resources.
+send_message(FromJIDString, ToJIDString, Body) ->
+    FromJID = jlib:string_to_jid(FromJIDString),
+    ToJID = jlib:string_to_jid(ToJIDString),
+    ToUser = ToJID#jid.user,
+    ToServer = ToJID#jid.server,
+    case ToJID#jid.resource of
+ "" ->
+     send_message(FromJID, ToUser, ToServer, Body);
+ Resource ->
+     send_message(FromJID, ToUser, ToServer, Resource, Body)
+    end.
+
+send_message(FromJID, ToUser, ToServer, Body) ->
+    case ejabberd_sm:get_user_resources(ToUser, ToServer) of
+ [] ->
+     send_message(FromJID, ToUser, ToServer, "", Body);
+ ToResources ->
+     lists:foreach(
+       fun(ToResource) ->
+       send_message(FromJID, ToUser, ToServer, ToResource, Body)
+       end,
+       ToResources)
+    end.
+
+send_message(FromJID, ToU, ToS, ToR, Body) ->
+    MPacket = build_send_message(Body),
+    ToJID = jlib:make_jid(ToU, ToS, ToR),
+    ejabberd_router:route(FromJID, ToJID, MPacket).
+
+build_send_message(Body) ->
+    {xmlelement, "message",
+     [{"type", "chat"}],
+     [{xmlelement, "body", [], [{xmlcdata, Body}]}]
     }.

Then, put the file to [svn]/ejabberd-modules/mod_admin_extra/trunk/src,
run patch -p0 < FILE,
and rebuild module.

If mod_admin_extra-developers consider this function corresponds all standards, users' demand and their own ideology, and they suggest to implement it in native code, it would be very nice :-)))

Thanks.

Patch committed with changes

I've committed your patch with some changes: the command names are send_message_chat and send_message_headline.

Syndicate content