xmppify 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/xmpp/index.js +0 -0
- data/app/assets/javascripts/xmpp/scripts/checkplayer.js +12 -0
- data/app/assets/javascripts/xmpp/scripts/crossdomain.xml +7 -0
- data/app/assets/javascripts/xmpp/scripts/flXHR.js +2 -0
- data/app/assets/javascripts/xmpp/scripts/flXHR.swf +0 -0
- data/app/assets/javascripts/xmpp/scripts/flXHR.vbs +44 -0
- data/app/assets/javascripts/xmpp/scripts/flensed.js +12 -0
- data/app/assets/javascripts/xmpp/scripts/strophe.flxhr.js +31 -0
- data/app/assets/javascripts/xmpp/scripts/strophe.js +3538 -0
- data/app/assets/javascripts/xmpp/scripts/swfobject.js +5 -0
- data/app/assets/javascripts/xmpp/scripts/updateplayer.swf +0 -0
- data/app/assets/javascripts/xmpp/scripts/xmpp.js.coffee +386 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/LICENSE.txt +19 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/README.markdown +95 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/archive/README.markdown +14 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/archive/iso8601_support.js +32 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/archive/strophe.archive.js +88 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/README.markdown +53 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/sha1.js +202 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.coffee +153 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.js +88 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.caps.jsonly.js +240 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/chatstates/strophe.chatstates.js +80 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/README.markdown +47 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/GetUrlComamndSpec.js +66 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/strophe.cmds.spec.coffee +145 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/support/jasmine.json +16 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.coffee +265 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.js +403 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/README.markdown +82 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/spec/strophe.x.coffee +715 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.coffee +443 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.js +854 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/.gitignore +1 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/README.markdown +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/convert.js +13 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/jasmine.json +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/lib/strophe.disco.js +137 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/public/javascript/strophe.disco.js +137 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/01_querying_information.xml +6 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/02_result_set_for_information_request.xml +22 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/03_target_entity_does_not_exist.xml +10 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/04_service_unavailable.xml +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/09_querying_specific_jid_and_node_combination.xml +7 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/10_jid_and_node_result.xml +12 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/11_requesting_all_items.xml +6 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/12_result_set_for_all_items.xml +23 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/13_empty_result_set.xml +7 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/17_service_returns_nodes.xml +16 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/18_requesting_further_nodes.xml +7 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/24_jid_and_node_error.xml +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/DiscoNodeSpec.js +50 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/SpecHelper.js +51 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/Stanzas.js +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.helper.js +54 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.js +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/support/jasmine.json +13 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/strophe.disco.js +232 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/public/javascript/jquery.epic.js +61 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/SpecHelper.js +9 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/jquery.epic.js +39 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/support/jasmine.json +22 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/iexdomain/iexdomain.js +36 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/README.markdown +117 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/buster.js +23 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.coffee +64 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.js +92 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/browserSetup.coffee +1 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/jid.spec.coffee +96 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/strophe.joap.spec.coffee +461 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.coffee +304 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.js +522 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/mam/LICENSE.txt +19 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/mam/README.markdown +52 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/mam/strophe.mam.js +62 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/muc/LICENSE.txt +20 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/muc/strophe.muc.js +1003 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/ping/README.markdown +28 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/ping/strophe.ping.js +68 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/private/README.markdown +16 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/private/strophe.private.js +192 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/pubsub/strophe.pubsub.js +555 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/receipts/strophe.receipts.js +155 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/register/README.markdown +44 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/register/strophe.register.js +431 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/public/javascript/strophe.roster.js +40 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/strophe.roster.spec.js +65 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/support/jasmine.json +15 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/strophe.roster.js +438 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/.gitignore +6 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/README.md +113 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/buster.js +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/lib/strophe.js +4198 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.helper.js +38 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.js +262 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/strophe.rpc.js +464 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rsm/strophe.rsm.js +52 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/serverdate/strophe.serverdate.js +58 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/index.html +17 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/strophevcard.js +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.coffee +44 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.js +66 -0
- data/app/assets/stylesheets/xmpp/index.css +0 -0
- data/app/controllers/omniauth_callbacks_controller.rb +15 -0
- data/app/controllers/ruby_bosh.rb +221 -0
- data/app/models/identity.rb +3 -0
- data/app/models/user.rb +40 -0
- data/bin/rails +8 -0
- data/db/migrate/20140329065635_create_users.rb +10 -0
- data/db/migrate/20140329070238_create_identities.rb +11 -0
- data/lib/xmppify/version.rb +3 -0
- data/lib/xmppify.rb +6 -0
- data/xmppify.gemspec +23 -0
- metadata +197 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
# Strophe.CAPS.js
|
2
|
+
|
3
|
+
Strophe.caps.js is a plugin to provide XMPP Entity Capabilities
|
4
|
+
( [ XEP-0115 ]( http://xmpp.org/extensions/xep-0115.html ) ).
|
5
|
+
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
### Adding features
|
10
|
+
|
11
|
+
connection.caps.add( "myfeature" );
|
12
|
+
|
13
|
+
### Removing features
|
14
|
+
|
15
|
+
connection.caps.remove( "myfeature" );
|
16
|
+
|
17
|
+
### Sending presence
|
18
|
+
|
19
|
+
conncection.caps.pres( attrs );
|
20
|
+
|
21
|
+
## Dependencies
|
22
|
+
|
23
|
+
- strophe.disco.js (by François de Metz)
|
24
|
+
- sha1.js
|
25
|
+
|
26
|
+
## ToDo
|
27
|
+
|
28
|
+
- write specs
|
29
|
+
- support service discovery data forms
|
30
|
+
|
31
|
+
## Authors
|
32
|
+
|
33
|
+
- Markus Kohlhase
|
34
|
+
|
35
|
+
# Strophe.caps.jsonly.js
|
36
|
+
|
37
|
+
Strophe.caps.jsonly.js is a similar plugin as Strophe.CAPS.js but isn't developed in coffeescript.
|
38
|
+
In order to prevent naming conflicts, it has been renamed to this.
|
39
|
+
|
40
|
+
It uses strophe.disco.js to add features etc.
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
See [strophe.disco.js](https://github.com/metajack/strophejs-plugins/tree/master/disco) for more info.
|
45
|
+
|
46
|
+
## Dependencies
|
47
|
+
|
48
|
+
- strophe.disco.js (by François de Metz)
|
49
|
+
- sha1.js
|
50
|
+
|
51
|
+
## Authors
|
52
|
+
|
53
|
+
- [Michael Weibel](http://github.com/mweibel)
|
@@ -0,0 +1,202 @@
|
|
1
|
+
/*
|
2
|
+
* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
|
3
|
+
* in FIPS PUB 180-1
|
4
|
+
* Version 2.1a Copyright Paul Johnston 2000 - 2002.
|
5
|
+
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
6
|
+
* Distributed under the BSD License
|
7
|
+
* See http://pajhome.org.uk/crypt/md5 for details.
|
8
|
+
*/
|
9
|
+
|
10
|
+
/*
|
11
|
+
* Configurable variables. You may need to tweak these to be compatible with
|
12
|
+
* the server-side, but the defaults work in most cases.
|
13
|
+
*/
|
14
|
+
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
|
15
|
+
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
|
16
|
+
var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
|
17
|
+
|
18
|
+
/*
|
19
|
+
* These are the functions you'll usually want to call
|
20
|
+
* They take string arguments and return either hex or base-64 encoded strings
|
21
|
+
*/
|
22
|
+
function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}
|
23
|
+
function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}
|
24
|
+
function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}
|
25
|
+
function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}
|
26
|
+
function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}
|
27
|
+
function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}
|
28
|
+
|
29
|
+
/*
|
30
|
+
* Perform a simple self-test to see if the VM is working
|
31
|
+
*/
|
32
|
+
function sha1_vm_test()
|
33
|
+
{
|
34
|
+
return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
|
35
|
+
}
|
36
|
+
|
37
|
+
/*
|
38
|
+
* Calculate the SHA-1 of an array of big-endian words, and a bit length
|
39
|
+
*/
|
40
|
+
function core_sha1(x, len)
|
41
|
+
{
|
42
|
+
/* append padding */
|
43
|
+
x[len >> 5] |= 0x80 << (24 - len % 32);
|
44
|
+
x[((len + 64 >> 9) << 4) + 15] = len;
|
45
|
+
|
46
|
+
var w = Array(80);
|
47
|
+
var a = 1732584193;
|
48
|
+
var b = -271733879;
|
49
|
+
var c = -1732584194;
|
50
|
+
var d = 271733878;
|
51
|
+
var e = -1009589776;
|
52
|
+
|
53
|
+
for(var i = 0; i < x.length; i += 16)
|
54
|
+
{
|
55
|
+
var olda = a;
|
56
|
+
var oldb = b;
|
57
|
+
var oldc = c;
|
58
|
+
var oldd = d;
|
59
|
+
var olde = e;
|
60
|
+
|
61
|
+
for(var j = 0; j < 80; j++)
|
62
|
+
{
|
63
|
+
if(j < 16) w[j] = x[i + j];
|
64
|
+
else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
|
65
|
+
var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
|
66
|
+
safe_add(safe_add(e, w[j]), sha1_kt(j)));
|
67
|
+
e = d;
|
68
|
+
d = c;
|
69
|
+
c = rol(b, 30);
|
70
|
+
b = a;
|
71
|
+
a = t;
|
72
|
+
}
|
73
|
+
|
74
|
+
a = safe_add(a, olda);
|
75
|
+
b = safe_add(b, oldb);
|
76
|
+
c = safe_add(c, oldc);
|
77
|
+
d = safe_add(d, oldd);
|
78
|
+
e = safe_add(e, olde);
|
79
|
+
}
|
80
|
+
return Array(a, b, c, d, e);
|
81
|
+
|
82
|
+
}
|
83
|
+
|
84
|
+
/*
|
85
|
+
* Perform the appropriate triplet combination function for the current
|
86
|
+
* iteration
|
87
|
+
*/
|
88
|
+
function sha1_ft(t, b, c, d)
|
89
|
+
{
|
90
|
+
if(t < 20) return (b & c) | ((~b) & d);
|
91
|
+
if(t < 40) return b ^ c ^ d;
|
92
|
+
if(t < 60) return (b & c) | (b & d) | (c & d);
|
93
|
+
return b ^ c ^ d;
|
94
|
+
}
|
95
|
+
|
96
|
+
/*
|
97
|
+
* Determine the appropriate additive constant for the current iteration
|
98
|
+
*/
|
99
|
+
function sha1_kt(t)
|
100
|
+
{
|
101
|
+
return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
|
102
|
+
(t < 60) ? -1894007588 : -899497514;
|
103
|
+
}
|
104
|
+
|
105
|
+
/*
|
106
|
+
* Calculate the HMAC-SHA1 of a key and some data
|
107
|
+
*/
|
108
|
+
function core_hmac_sha1(key, data)
|
109
|
+
{
|
110
|
+
var bkey = str2binb(key);
|
111
|
+
if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz);
|
112
|
+
|
113
|
+
var ipad = Array(16), opad = Array(16);
|
114
|
+
for(var i = 0; i < 16; i++)
|
115
|
+
{
|
116
|
+
ipad[i] = bkey[i] ^ 0x36363636;
|
117
|
+
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
118
|
+
}
|
119
|
+
|
120
|
+
var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
|
121
|
+
return core_sha1(opad.concat(hash), 512 + 160);
|
122
|
+
}
|
123
|
+
|
124
|
+
/*
|
125
|
+
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
126
|
+
* to work around bugs in some JS interpreters.
|
127
|
+
*/
|
128
|
+
function safe_add(x, y)
|
129
|
+
{
|
130
|
+
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
|
131
|
+
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
132
|
+
return (msw << 16) | (lsw & 0xFFFF);
|
133
|
+
}
|
134
|
+
|
135
|
+
/*
|
136
|
+
* Bitwise rotate a 32-bit number to the left.
|
137
|
+
*/
|
138
|
+
function rol(num, cnt)
|
139
|
+
{
|
140
|
+
return (num << cnt) | (num >>> (32 - cnt));
|
141
|
+
}
|
142
|
+
|
143
|
+
/*
|
144
|
+
* Convert an 8-bit or 16-bit string to an array of big-endian words
|
145
|
+
* In 8-bit function, characters >255 have their hi-byte silently ignored.
|
146
|
+
*/
|
147
|
+
function str2binb(str)
|
148
|
+
{
|
149
|
+
var bin = Array();
|
150
|
+
var mask = (1 << chrsz) - 1;
|
151
|
+
for(var i = 0; i < str.length * chrsz; i += chrsz)
|
152
|
+
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32);
|
153
|
+
return bin;
|
154
|
+
}
|
155
|
+
|
156
|
+
/*
|
157
|
+
* Convert an array of big-endian words to a string
|
158
|
+
*/
|
159
|
+
function binb2str(bin)
|
160
|
+
{
|
161
|
+
var str = "";
|
162
|
+
var mask = (1 << chrsz) - 1;
|
163
|
+
for(var i = 0; i < bin.length * 32; i += chrsz)
|
164
|
+
str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask);
|
165
|
+
return str;
|
166
|
+
}
|
167
|
+
|
168
|
+
/*
|
169
|
+
* Convert an array of big-endian words to a hex string.
|
170
|
+
*/
|
171
|
+
function binb2hex(binarray)
|
172
|
+
{
|
173
|
+
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
|
174
|
+
var str = "";
|
175
|
+
for(var i = 0; i < binarray.length * 4; i++)
|
176
|
+
{
|
177
|
+
str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
|
178
|
+
hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF);
|
179
|
+
}
|
180
|
+
return str;
|
181
|
+
}
|
182
|
+
|
183
|
+
/*
|
184
|
+
* Convert an array of big-endian words to a base-64 string
|
185
|
+
*/
|
186
|
+
function binb2b64(binarray)
|
187
|
+
{
|
188
|
+
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
189
|
+
var str = "";
|
190
|
+
for(var i = 0; i < binarray.length * 4; i += 3)
|
191
|
+
{
|
192
|
+
var triplet = (((binarray[i >> 2] >> 8 * (3 - i %4)) & 0xFF) << 16)
|
193
|
+
| (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 )
|
194
|
+
| ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF);
|
195
|
+
for(var j = 0; j < 4; j++)
|
196
|
+
{
|
197
|
+
if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
|
198
|
+
else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
|
199
|
+
}
|
200
|
+
}
|
201
|
+
return str;
|
202
|
+
}
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# This plugin is distributed under the terms of the MIT licence.
|
2
|
+
# Please see the LICENCE file for details.
|
3
|
+
#
|
4
|
+
# Copyright (c) Markus Kohlhase, 2011
|
5
|
+
|
6
|
+
# File: strophe.caps.js
|
7
|
+
# A Strophe plugin for ( http://xmpp.org/extensions/xep-0115.html )
|
8
|
+
|
9
|
+
# NOTE: This plugin has following dependencies:
|
10
|
+
#
|
11
|
+
# - strophe.disco.js (by François de Metz)
|
12
|
+
# - sha1.js
|
13
|
+
|
14
|
+
Strophe.addConnectionPlugin 'caps', (->
|
15
|
+
|
16
|
+
conn = null
|
17
|
+
|
18
|
+
init = ( c ) ->
|
19
|
+
conn = c
|
20
|
+
Strophe.addNamespace 'CAPS', "http://jabber.org/protocol/caps"
|
21
|
+
if conn.disco is undefined
|
22
|
+
throw new Error "disco plugin required!"
|
23
|
+
if b64_sha1 is undefined
|
24
|
+
throw new Error "SHA-1 library required!"
|
25
|
+
conn.disco.addFeature Strophe.NS.CAPS
|
26
|
+
conn.disco.addFeature Strophe.NS.DISCO_INFO
|
27
|
+
|
28
|
+
# chek if there are identities
|
29
|
+
if conn.disco._identities.length is 0
|
30
|
+
conn.disco.addIdentity "client","pc", "strophejs", ""
|
31
|
+
|
32
|
+
|
33
|
+
addFeature = (feature) -> conn.disco.addFeature feature
|
34
|
+
|
35
|
+
removeFeature = (feature) -> conn.disco.removeFeature feature
|
36
|
+
|
37
|
+
sendPres = -> conn.send $pres().cnode( createCapsNode().tree() )
|
38
|
+
|
39
|
+
createCapsNode = ->
|
40
|
+
|
41
|
+
if conn.disco._identities.length > 0
|
42
|
+
node = conn.disco._identities[0].name || ""
|
43
|
+
else
|
44
|
+
node = dummyId.name
|
45
|
+
|
46
|
+
$build "c",
|
47
|
+
xmlns: Strophe.NS.CAPS
|
48
|
+
hash: "sha-1"
|
49
|
+
node: node
|
50
|
+
ver: generateVerificationString()
|
51
|
+
|
52
|
+
propertySort = (array, property) ->
|
53
|
+
array.sort (a,b) ->
|
54
|
+
if (a[property] > b[property]) then -1 else 1
|
55
|
+
|
56
|
+
generateVerificationString = ->
|
57
|
+
|
58
|
+
## Prepare
|
59
|
+
|
60
|
+
# copy the original identities
|
61
|
+
ids = []
|
62
|
+
ids.push(i) for i in conn.disco._identities
|
63
|
+
|
64
|
+
# copy the original features
|
65
|
+
features = []
|
66
|
+
features.push(k) for k in conn.disco._features
|
67
|
+
|
68
|
+
## Generate string
|
69
|
+
|
70
|
+
# 1. Initialize an empty string S.
|
71
|
+
|
72
|
+
S = ""
|
73
|
+
|
74
|
+
# 2. Sort the service discovery identities by category and then by type and
|
75
|
+
# then by xml:lang (if it exists), formatted as CATEGORY '/' [TYPE] '/' [LANG]
|
76
|
+
# '/' [NAME]. Note that each slash is included even if the LANG or NAME is not
|
77
|
+
# included (in accordance with XEP-0030, the category and type MUST be
|
78
|
+
# included.
|
79
|
+
|
80
|
+
propertySort( ids, "category" )
|
81
|
+
propertySort( ids, "type" )
|
82
|
+
propertySort( ids, "lang" )
|
83
|
+
|
84
|
+
# 3. For each identity, append the 'category/type/lang/name' to S, followed by
|
85
|
+
# the '<' character.
|
86
|
+
|
87
|
+
for key, id of ids
|
88
|
+
S += "#{id.category}/#{id.type}/#{id.lang}/#{id.name}<"
|
89
|
+
|
90
|
+
# 4. Sort the supported service discovery features.
|
91
|
+
|
92
|
+
features.sort()
|
93
|
+
|
94
|
+
# 5. For each feature, append the feature to S, followed by the '<' character.
|
95
|
+
|
96
|
+
for ns in features
|
97
|
+
S += "#{ns}<"
|
98
|
+
|
99
|
+
# 6. If the service discovery information response includes XEP-0128 data forms,
|
100
|
+
# sort the forms by the FORM_TYPE (i.e., by the XML character data of the
|
101
|
+
# <value/> element).
|
102
|
+
|
103
|
+
# not implemented yet
|
104
|
+
|
105
|
+
# 7. For each extended service discovery information form:
|
106
|
+
|
107
|
+
# a) Append the XML character data of the FORM_TYPE field's <value/> element,
|
108
|
+
# followed by the '<' character.
|
109
|
+
|
110
|
+
# not implemented yet
|
111
|
+
|
112
|
+
# b) Sort the fields by the value of the "var" attribute.
|
113
|
+
|
114
|
+
# not implemented yet
|
115
|
+
|
116
|
+
# c) For each field other than FORM_TYPE:
|
117
|
+
|
118
|
+
# i. Append the value of the "var" attribute, followed by the '<'
|
119
|
+
# character.
|
120
|
+
|
121
|
+
# not implemented yet
|
122
|
+
|
123
|
+
# ii. Sort values by the XML character data of the <value/> element.
|
124
|
+
|
125
|
+
# not implemented yet
|
126
|
+
|
127
|
+
# iii. For each <value/> element, append the XML character data, followed by
|
128
|
+
# the '<' character.
|
129
|
+
|
130
|
+
# not implemented yet
|
131
|
+
|
132
|
+
# 8. Ensure that S is encoded according to the UTF-8 encoding.
|
133
|
+
|
134
|
+
# not implemented yet
|
135
|
+
|
136
|
+
# 9. Compute the verification string by hashing S using the algorithm
|
137
|
+
# specified in the 'hash' attribute (e.g., SHA-1 as defined in RFC 3174 [19]).
|
138
|
+
# The hashed data MUST be generated with binary output and encoded using
|
139
|
+
# Base64 as specified in Section 4 of RFC 4648 [20] (note: the Base64 output
|
140
|
+
# MUST NOT include whitespace and MUST set padding bits to zero).
|
141
|
+
|
142
|
+
"#{b64_sha1 S}="
|
143
|
+
|
144
|
+
# Public API
|
145
|
+
|
146
|
+
init: init
|
147
|
+
removeFeature: removeFeature
|
148
|
+
addFeature: addFeature
|
149
|
+
sendPres: sendPres
|
150
|
+
generateVerificationString: generateVerificationString
|
151
|
+
createCapsNode: createCapsNode
|
152
|
+
|
153
|
+
)()
|
@@ -0,0 +1,88 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
Strophe.addConnectionPlugin('caps', (function() {
|
4
|
+
var addFeature, conn, createCapsNode, generateVerificationString, init, propertySort, removeFeature, sendPres;
|
5
|
+
conn = null;
|
6
|
+
init = function(c) {
|
7
|
+
conn = c;
|
8
|
+
Strophe.addNamespace('CAPS', "http://jabber.org/protocol/caps");
|
9
|
+
if (conn.disco === void 0) throw new Error("disco plugin required!");
|
10
|
+
if (b64_sha1 === void 0) throw new Error("SHA-1 library required!");
|
11
|
+
conn.disco.addFeature(Strophe.NS.CAPS);
|
12
|
+
conn.disco.addFeature(Strophe.NS.DISCO_INFO);
|
13
|
+
if (conn.disco._identities.length === 0) {
|
14
|
+
return conn.disco.addIdentity("client", "pc", "strophejs", "");
|
15
|
+
}
|
16
|
+
};
|
17
|
+
addFeature = function(feature) {
|
18
|
+
return conn.disco.addFeature(feature);
|
19
|
+
};
|
20
|
+
removeFeature = function(feature) {
|
21
|
+
return conn.disco.removeFeature(feature);
|
22
|
+
};
|
23
|
+
sendPres = function() {
|
24
|
+
return conn.send($pres().cnode(createCapsNode().tree()));
|
25
|
+
};
|
26
|
+
createCapsNode = function() {
|
27
|
+
var node;
|
28
|
+
if (conn.disco._identities.length > 0) {
|
29
|
+
node = conn.disco._identities[0].name || "";
|
30
|
+
} else {
|
31
|
+
node = dummyId.name;
|
32
|
+
}
|
33
|
+
return $build("c", {
|
34
|
+
xmlns: Strophe.NS.CAPS,
|
35
|
+
hash: "sha-1",
|
36
|
+
node: node,
|
37
|
+
ver: generateVerificationString()
|
38
|
+
});
|
39
|
+
};
|
40
|
+
propertySort = function(array, property) {
|
41
|
+
return array.sort(function(a, b) {
|
42
|
+
if (a[property] > b[property]) {
|
43
|
+
return -1;
|
44
|
+
} else {
|
45
|
+
return 1;
|
46
|
+
}
|
47
|
+
});
|
48
|
+
};
|
49
|
+
generateVerificationString = function() {
|
50
|
+
var S, features, i, id, ids, k, key, ns, _i, _j, _k, _len, _len2, _len3, _ref, _ref2;
|
51
|
+
ids = [];
|
52
|
+
_ref = conn.disco._identities;
|
53
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
54
|
+
i = _ref[_i];
|
55
|
+
ids.push(i);
|
56
|
+
}
|
57
|
+
features = [];
|
58
|
+
_ref2 = conn.disco._features;
|
59
|
+
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
60
|
+
k = _ref2[_j];
|
61
|
+
features.push(k);
|
62
|
+
}
|
63
|
+
S = "";
|
64
|
+
propertySort(ids, "category");
|
65
|
+
propertySort(ids, "type");
|
66
|
+
propertySort(ids, "lang");
|
67
|
+
for (key in ids) {
|
68
|
+
id = ids[key];
|
69
|
+
S += "" + id.category + "/" + id.type + "/" + id.lang + "/" + id.name + "<";
|
70
|
+
}
|
71
|
+
features.sort();
|
72
|
+
for (_k = 0, _len3 = features.length; _k < _len3; _k++) {
|
73
|
+
ns = features[_k];
|
74
|
+
S += "" + ns + "<";
|
75
|
+
}
|
76
|
+
return "" + (b64_sha1(S)) + "=";
|
77
|
+
};
|
78
|
+
return {
|
79
|
+
init: init,
|
80
|
+
removeFeature: removeFeature,
|
81
|
+
addFeature: addFeature,
|
82
|
+
sendPres: sendPres,
|
83
|
+
generateVerificationString: generateVerificationString,
|
84
|
+
createCapsNode: createCapsNode
|
85
|
+
};
|
86
|
+
})());
|
87
|
+
|
88
|
+
}).call(this);
|