Thu, 07 Jan 2010 22:25:28 +0000
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
25
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 | short_opts.h = "history"; |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | return function (opts, arg) |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | local function on_connect(conn) |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 | -- Allow selective bouncing |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | local only_node, only_server, only_resource; |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 | if opts.only_from then |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 | only_node, only_server, only_resource = jid.split(opts.only_from); |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 | end |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 | local function should_bounce(stanza) |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 | local node, server, resource = jid.split(stanza.attr.from); |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 | if only_node and (node ~= only_node) |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 | or only_server and (server ~= only_server) |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 | or only_resource and (resource ~= only_resource) then |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 | return false; |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 | end |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 | return true; |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | end |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | local function on_message(message) |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | local delay = message:get_child("delay", "urn:xmpp:delay"); |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | if (delay and not opts.history) or not should_bounce(message) then |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | return; |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | end |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | message.attr.from = nil; |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | message.attr.to = opts.to; |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | message.attr.type = opts.type or (opts.chatroom and "groupchat") or "chat"; |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | conn:send(message); |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 | end |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 | conn:hook("message", on_message); |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 | end |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 | return clix_connect(opts, on_connect); |
db6e92989c41
clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | end |