Mercurial > psgxs
annotate psgxs.js @ 34:dcf1f09f8cee
Add message to publish module and various fixes.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 05 Nov 2010 15:31:13 +0100 |
parents | 13011b26181c |
children | 6697f394301f |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env node |
2 | |
3 /* | |
4 * Copyright (C) 2010 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | |
5 * | |
6 * This file is part of PSĜS, a PubSub server written in JavaScript. | |
7 * | |
8 * PSĜS is free software: you can redistribute it and/or modify | |
9 * it under the terms of the GNU Affero General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License. | |
12 * | |
13 * PSĜS is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU Affero General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Affero General Public License | |
19 * along with PSĜS. If not, see <http://www.gnu.org/licenses/>. | |
20 */ | |
21 | |
22 var xmpp = require('xmpp'); | |
23 var sha1 = require('sha1'); | |
24 require('./iso8601'); | |
25 var storage = require('./storage'); | |
26 var errors = require('./errors'); | |
23
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
22
diff
changeset
|
27 var makeError = errors.makeError; |
0 | 28 var utils = require('./util'); |
29 var toBareJID = utils.toBareJID; | |
30 var config = require('./configuration'); | |
31 var forms = require('./forms'); | |
32 var conn = new xmpp.Connection(); | |
33 | |
23
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
22
diff
changeset
|
34 var notifs = require('./notifs'); |
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
22
diff
changeset
|
35 notifs.setConnection(conn); |
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
22
diff
changeset
|
36 |
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
22
diff
changeset
|
37 var modules = require('./modules'); |
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
22
diff
changeset
|
38 |
0 | 39 var service_configuration = config.service_configuration; |
40 var componentJID = config.jid; | |
41 var componentPassword = config.password; | |
42 | |
12
9a6b8b3357c6
Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
43 conn.log = function (_, m) { console.log(m); }; |
0 | 44 |
12
9a6b8b3357c6
Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
45 function _(obj, color) { |
9a6b8b3357c6
Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
46 var str = require('sys').inspect(obj, false, null); |
9a6b8b3357c6
Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
47 if (color) |
9a6b8b3357c6
Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
48 console.log('\033['+c+';1m' + str + '\033[0m'); |
9a6b8b3357c6
Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
49 else |
9a6b8b3357c6
Use new functions like console.log instead of sys.puts, and aerate a bit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
11
diff
changeset
|
50 console.log(str); |
0 | 51 }; |
52 | |
11
0ed3c06c5191
Add an uncaught exceptions caughter to prevent the server from crashing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
10
diff
changeset
|
53 process.addListener('uncaughtException', function (err) { |
17
ec7cea92fe8a
Show stack on unhandled error.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12
diff
changeset
|
54 console.log('\033[41;1mUncaught exception (' + err + '), this should never happen:\033[0m\n' + err.stack); |
11
0ed3c06c5191
Add an uncaught exceptions caughter to prevent the server from crashing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
10
diff
changeset
|
55 }); |
0ed3c06c5191
Add an uncaught exceptions caughter to prevent the server from crashing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
10
diff
changeset
|
56 |
8
efe8dbd34780
Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
57 if (typeof xmpp.StanzaBuilder.cnode != 'function' || typeof xmpp.StanzaBuilder.prototype.cnode != 'function') { |
efe8dbd34780
Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
58 xmpp.StanzaBuilder.prototype.cnode = function (stanza) |
efe8dbd34780
Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
59 { |
23
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
22
diff
changeset
|
60 var parent = this.last_node[this.last_node.length-1]; |
8
efe8dbd34780
Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
61 parent.tags.push(stanza); |
efe8dbd34780
Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
62 parent.children.push(stanza); |
23
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
22
diff
changeset
|
63 this.last_node.push(stanza); |
8
efe8dbd34780
Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
64 return this; |
efe8dbd34780
Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
65 }; |
efe8dbd34780
Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
66 } |
efe8dbd34780
Rename cx method to cnode and define it if xmpp.js didn’t.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
67 |
0 | 68 function onIq(stanza) { |
69 var type = stanza.getAttribute('type'); | |
70 var from = stanza.getAttribute('to'); | |
71 var to = stanza.getAttribute('from'); | |
72 var id = stanza.getAttribute('id'); | |
73 | |
74 var response; | |
75 if (id) | |
76 response = xmpp.iq({to: to, from: from, type: 'result', id: id}); | |
77 else | |
78 response = xmpp.iq({to: to, from: from, type: 'result'}); | |
79 | |
30
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
80 var send = false; |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
81 |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
82 for (var i in stanza.tags) { |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
83 var child1 = stanza.tags[i]; |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
84 if (child1.name == 'pubsub') { |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
85 for (var j in child1.tags) { |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
86 var child2 = child1.tags[j]; |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
87 |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
88 for (var k in modules) { |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
89 var module = modules[k]; |
0 | 90 |
34
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
91 if (module.stanza && (module.stanza != 'iq')) |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
92 continue; |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
93 |
30
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
94 if (module.type && (module.type != type)) |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
95 continue; |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
96 |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
97 if (module.child2 && (module.child2 != child2.name)) |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
98 continue; |
0 | 99 |
30
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
100 if (module.ns && (module.ns != child2.attr.xmlns)) |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
101 continue; |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
102 |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
103 if (module.number && (module.number != j)) |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
104 continue; |
9
a6429f48e403
First implementation of XEP-0050 (ad-hoc commands).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8
diff
changeset
|
105 |
34
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
106 var toSend = module.func(response, stanza, child2, to, from); |
30
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
107 if (toSend) { |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
108 response = toSend; |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
109 send = true; |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
110 delete toSend; |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
111 } |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
112 } |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
113 } |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
114 } else { |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
115 for (var k in modules) { |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
116 var module = modules[k]; |
0 | 117 |
34
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
118 if (module.stanza && (module.stanza != 'iq')) |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
119 continue; |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
120 |
30
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
121 if (module.type && (module.type != type)) |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
122 continue; |
0 | 123 |
30
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
124 if (module.child && (module.child != child1.name)) |
23
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
22
diff
changeset
|
125 continue; |
30
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
126 |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
127 if (module.ns && (module.ns != child1.attr.xmlns)) |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
128 continue; |
0 | 129 |
30
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
130 if (module.number && (module.number != k)) |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
131 continue; |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
132 |
34
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
133 var toSend = module.func(response, stanza, child1, to, from); |
30
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
134 if (toSend) { |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
135 response = toSend; |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
136 send = true; |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
137 delete toSend; |
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
138 } |
0 | 139 } |
23
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
22
diff
changeset
|
140 } |
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
22
diff
changeset
|
141 } |
0 | 142 |
30
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
25
diff
changeset
|
143 conn.send(send? response: makeError(response, errors.feature_not_implemented.n)); |
0 | 144 } |
145 | |
146 function onMessage(stanza) { | |
147 var from = stanza.getAttribute('to'); | |
148 var to = stanza.getAttribute('from'); | |
149 var id = stanza.getAttribute('id'); | |
150 | |
151 var response; | |
152 if (id) | |
153 response = xmpp.message({to: to, from: from, id: id}); | |
154 else | |
155 response = xmpp.message({to: to, from: from}); | |
156 | |
34
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
157 var send = false; |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
158 |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
159 for (var i in stanza.tags) { |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
160 var child = stanza.tags[i]; |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
161 for (var k in modules) { |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
162 var module = modules[k]; |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
163 |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
164 if (module.stanza !== 'message') |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
165 continue; |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
166 |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
167 if (module.type && (module.type != type)) |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
168 continue; |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
169 |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
170 if (module.child && (module.child != child.name)) |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
171 continue; |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
172 |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
173 if (module.ns && (module.ns != child.attr.xmlns)) |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
174 continue; |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
175 |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
176 if (module.number && (module.number != k)) |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
177 continue; |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
178 |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
179 var toSend = module.func(response, stanza, child, to, from); |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
180 if (toSend) { |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
181 response = toSend; |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
182 send = true; |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
183 delete toSend; |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
184 } |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
185 } |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
186 } |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
187 |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
188 conn.send(send? response: makeError(response, errors.feature_not_implemented.n)); |
dcf1f09f8cee
Add message to publish module and various fixes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
31
diff
changeset
|
189 |
0 | 190 var x = stanza.getChild('x', 'jabber:x:data'); |
191 if (x) { | |
192 var form = forms.parse(x); | |
193 if (form.type == 'submit' && form.fields.FORM_TYPE.value == 'subscribe_authorization') { | |
194 if (form.fields.subid && form.fields.subid.value) | |
195 var subID = form.fields.subid.value; | |
196 if (form.fields.node && form.fields.node.value) | |
197 var nodeID = form.fields.node.value; | |
198 if (form.fields.subscriber_jid && form.fields.subscriber_jid.value) | |
199 var jid = form.fields.subscriber_jid.value; | |
200 if (form.fields.allow && form.fields.allow.value) | |
201 var allow = form.fields.allow.value; | |
202 | |
203 var type = allow? 'subscribed': 'none'; | |
204 var set = storage.subscribe(nodeID, jid, type) | |
205 //if (set.subid != subID) //TODO: support the multi-subscribe feature | |
23
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
22
diff
changeset
|
206 notifs.send(jid, 'subscription', nodeID, {jid: jid, subscription: type}); |
0 | 207 } else |
208 return makeError(response, errors.feature_not_implemented.n); | |
209 } else | |
210 return makeError(response, errors.feature_not_implemented.n); | |
211 conn.send(response) | |
212 } | |
213 | |
214 function onPresence(stanza) { | |
215 var from = stanza.getAttribute('to'); | |
216 var to = stanza.getAttribute('from'); | |
217 var id = stanza.getAttribute('id'); | |
218 | |
219 var response; | |
220 if (id) | |
221 response = xmpp.presence({to: to, from: from, id: id}); | |
222 else | |
223 response = xmpp.presence({to: to, from: from}); | |
224 | |
225 makeError(response, errors.feature_not_implemented.n); | |
226 } | |
227 | |
228 conn.connect(componentJID, componentPassword, function (status, condition) { | |
229 if (status == xmpp.Status.CONNECTED) { | |
230 conn.addHandler(onMessage, null, 'message', null, null, null); | |
231 conn.addHandler(onIq, null, 'iq', null, null, null); | |
232 conn.addHandler(onPresence, null, 'presence', null, null, null); | |
233 | |
234 if (process.argv.length >= 3) | |
235 storage.load(process.argv[2]); | |
236 else | |
237 storage.load(); | |
238 | |
239 var stdin = process.openStdin(); | |
240 stdin.setEncoding('utf8'); | |
241 stdin.addListener('data', storage.debug); | |
242 } else | |
243 conn.log(xmpp.LogLevel.DEBUG, 'New connection status: ' + status + (condition? (' ('+condition+')'): '')); | |
244 }); |