annotate xmpp.js @ 0:a2dab4544b2d default tip

Initial commit.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 28 Jan 2011 02:35:04 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 #!/usr/bin/env node
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 var nc = require('ncurses')
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 var consts = require('ncconsts')
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 var sys = require('sys');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 var fs = require('fs');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 var xmpp = require('clxmpp');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 var config = require('./config');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 var forms = require('./forms');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 var NS = require('./namespaces');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 var options = {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 xml: false,
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 command_parsing: false,
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 chr: false
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 var st = [
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 'Error',
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 'Connecting',
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 'Connfail',
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 'Authenticating',
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 'Authfail',
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 'Connected',
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 'Disconnected',
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 'Disconnecting'
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 ];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 var jid = config.jid.split('@');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 var user = jid[0];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 var server = jid[1];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 var history = [];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 process.addListener('SIGWINCH', function (err) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 win.resize(win.lines, win.cols);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 win.hline(win.height-2, 0, win.width);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 win.setscrreg(0, win.height-3);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 win.cursor(win.height-1, 0);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 win.clearok(true);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 win.refresh();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 appendLine('Window size changed to ' + win.lines + ' x ' + win.cols + '!');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 });
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 process.addListener('uncaughtException', function (err) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 appendLine('Uncaught exception (' + err + '), this should never happen:\n' + err.stack + '.');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 });
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 // ============================================================================
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 // FUNCTIONS
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 // ============================================================================
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 var getTimestamp = function() {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 var time = new Date();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 var hours = time.getHours();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 var mins = time.getMinutes();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 return '' + (hours < 10 ? '0' : '') + hours + ':' + (mins < 10 ? '0' : '') + mins;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 };
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 var appendLine = function(message) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 var curx=win.curx;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 win.scroll(1);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 win.cursor(win.height-3, 0);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 win.print('[' + getTimestamp() + '] ');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 if (arguments.length > 1 && arguments[1]) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 if (win.hasColors)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 win.attrset(win.colorPair(1));
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 win.print('== ');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 if (arguments.length > 2 && arguments[2] && win.hasColors)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 win.attrset(arguments[2]);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 win.print('' + message);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 if (arguments.length > 2 && arguments[2] && win.hasColors)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 win.attrset(win.colorPair(0));
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 if (arguments.length > 3) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 win.cursor(win.height-1, 0);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 win.clrtoeol();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 } else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 win.cursor(win.height-1, curx);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 win.refresh();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 };
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 var cleanup = function() {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 win.clear();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 win.refresh();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 win.close();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 process.exit(0);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 };
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 // ============================================================================
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 // HANDLERS
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 // ============================================================================
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 var on = {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 configure: function(stanza) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100 var pubsub = stanza.getChild('pubsub', NS.PUBSUB_OWNER);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 var configure = pubsub.getChild('configure', NS.PUBSUB_OWNER);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 var nodeID = configure.getAttribute('node');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104 if (nodeID)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 var text = 'Configuration of node “' + nodeID + '”:';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107 var text = 'Configuration of a new node:';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109 var x = configure.getChild('x', 'jabber:x:data');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 var form = forms.parse(x);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
111 text += forms.toString(form);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
112
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113 next.func = function() {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'set'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 .c('pubsub', {xmlns: NS.PUBSUB_OWNER})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116 .c('configure', {node: nodeID});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 var form = forms.build();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 stanza.cnode(form);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 return stanza;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
122 };
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
123
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
124 appendLine(text);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
127 default: function(stanza) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128 var pubsub = stanza.getChild('pubsub', NS.PUBSUB);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 var def = pubsub.getChild('default', NS.PUBSUB);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131 var nodeID = def.getAttribute('node');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132 if (nodeID)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 var text = 'Options of a new subscription on ' + nodeID + ':';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135 var text = 'Subscription options on a new node:';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137 var x = def.getChild('x', 'jabber:x:data');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
138 var form = forms.parse(x);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
139 text += '\nOptions:' + forms.toString(form);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
140
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
141 appendLine(text);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
142 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
143
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
144 'delete': function(stanza) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
145 appendLine('Node correctly deleted.');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
146 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
147
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
148 purge: function(stanza) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
149 appendLine('Node correctly purged.');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
150 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
151
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
152 info: function(stanza) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
153 var query = stanza.getChild('query', NS.DISCO_INFO);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
154 var list = query.tags;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
155
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
156 var nodeID = query.getAttribute('node');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
157
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
158 var text = '';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
159 for (var i in list) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
160 if (list[i].name == 'identity') {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
161 if (nodeID)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
162 text += '"' + nodeID + '"';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
163 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
164 text += '"' + list[i].getAttribute('name') + '"';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
165
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
166 text += ', ' + list[i].getAttribute('category')
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
167 + ' ' + list[i].getAttribute('type')
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
168 + ', features:';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
169 } else if (list[i].name == 'feature')
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
170 text += '\n\t' + list[i].getAttribute('var');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
171 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
172
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
173 var x = query.getChild('x', 'jabber:x:data');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
174 if (x) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
175 var form = forms.parse(x);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
176 text += '\nMetadata:' + forms.toString(form);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
177 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
178 appendLine(text);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
179 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
180
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
181 list: function(stanza) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
182 var query = stanza.getChild('query', NS.DISCO_ITEMS);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
183 var list = query.tags;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
184
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
185 var nodeID = query.getAttribute('node');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
186 if (nodeID)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
187 var text = 'Nodes in ' + nodeID + ':';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
188 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
189 var text = 'Nodes:';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
190
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
191 for (var i in list) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
192 var node = list[i].getAttribute('node');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
193 if (node) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
194 text += '\n\t' + list[i].getAttribute('node');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
195
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
196 var name = list[i].getAttribute('name');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
197 if (name)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
198 text += ' (' + name + ')';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
199 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
200 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
201
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
202 if (nodeID)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
203 text += '\nItems in ' + nodeID + ':';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
204 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
205 text += '\nItems:';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
206
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
207 for (var i in list) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
208 var node = list[i].getAttribute('node');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
209 if (!node)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
210 text += '\n\t' + list[i].getAttribute('name');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
211 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
212
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
213 appendLine(text);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
214 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
215
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
216 manage: function(stanza) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
217 var pubsub = stanza.getChild('pubsub', NS.PUBSUB_OWNER);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
218 var tag = pubsub.tags[0];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
219
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
220 if (tag.attr.xmlns != NS.PUBSUB_OWNER)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
221 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
222
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
223 var action = tag.name;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
224 if (action != 'subscriptions' && action != 'affiliations')
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
225 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
226
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
227 var nodeID = tag.getAttribute('node');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
228 if (!nodeID)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
229 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
230
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
231 var text = action[0].toUpperCase() + action.substr(1) + ' in ' + nodeID + ':';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
232
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
233 for (var i in tag.tags) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
234 var sub = tag.tags[i];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
235
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
236 var jid = sub.getAttribute('jid');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
237 text += '\n\t' + jid;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
238
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
239 if (action == 'subscriptions') {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
240 var subscription = sub.getAttribute('subscription');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
241 var subid = sub.getAttribute('subid');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
242
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
243 text += ' (' + subid + '): ' + subscription;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
244 } else {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
245 var affiliation = sub.getAttribute('affiliation');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
246
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
247 text += ': ' + affiliation;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
248 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
249 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
250
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
251 next.func = function() {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
252 var tag = this.tag;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
253 var name = tag.substr(0, tag.length-1);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
254
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
255 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'set'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
256 .c('pubsub', {xmlns: NS.PUBSUB_OWNER})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
257 .c(tag, {node: nodeID});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
258
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
259 for (var i in this) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
260 if (!(this[i] instanceof Array))
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
261 continue;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
262
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
263 if (this[i].length != 2)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
264 continue;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
265
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
266 var obj = {jid: this[i][0]};
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
267 obj[name] = this[i][1];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
268 stanza.c(name, obj).up();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
269 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
270
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
271 return stanza;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
272 };
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
273
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
274 next.tag = action;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
275
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
276 appendLine(text);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
277 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
278
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
279 options: function(stanza) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
280 var pubsub = stanza.getChild('pubsub', NS.PUBSUB);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
281 var options = pubsub.getChild('options', NS.PUBSUB);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
282
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
283 var nodeID = options.getAttribute('node');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
284 var jid = options.getAttribute('jid');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
285 var text = 'Options of ' + jid + ' on ' + nodeID + ':';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
286
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
287 var x = options.getChild('x', 'jabber:x:data');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
288 var form = forms.parse(x);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
289 text += '\nOptions:' + forms.toString(form);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
290
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
291 appendLine(text);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
292 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
293
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
294 error: function(stanza) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
295 var error = stanza.getChild('error');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
296 var type = error.getAttribute('type');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
297 var name = error.tags[0].name;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
298
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
299 var text = 'Got error of type ' + type + ': ' + name;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
300
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
301 if (error.tags[1]) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
302 var name2 = error.tags[1].name;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
303
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
304 text += ', ';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
305
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
306 var feature = error.tags[1].getAttribute('feature');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
307 if (feature)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
308 text += 'feature ' + feature + ' ';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
309
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
310 text += name2;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
311 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
312 text += '.';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
313
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
314 appendLine(text, false, win.colorPair(1));
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
315 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
316 };
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
317
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
318 // ============================================================================
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
319 // COMMANDS
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
320 // ============================================================================
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
321
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
322 var next = {};
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
323
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
324 var commands = {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
325 create: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
326 var nodeID = args[0];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
327 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'set'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
328 .c('pubsub', {xmlns: NS.PUBSUB})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
329 .c('create', {node: nodeID});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
330 conn.sendIQ(stanza, function(stanza) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
331 appendLine('Node correctly created.');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
332 }, on.error);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
333 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
334
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
335 configure: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
336 if (args < 1)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
337 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
338
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
339 var nodeID = args[0];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
340
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
341 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'get'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
342 .c('pubsub', {xmlns: NS.PUBSUB_OWNER})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
343 .c('configure', {node: nodeID});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
344
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
345 conn.sendIQ(stanza, on.configure, on.error);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
346 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
347
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
348 default: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
349 var nodeID = args[0];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
350
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
351 if (nodeID)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
352 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'get'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
353 .c('pubsub', {xmlns: NS.PUBSUB})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
354 .c('default', {node: nodeID});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
355 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
356 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'get'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
357 .c('pubsub', {xmlns: NS.PUBSUB})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
358 .c('default');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
359
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
360 conn.sendIQ(stanza, on.default, on.error);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
361 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
362
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
363 'delete': function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
364 var nodeID = args[0];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
365 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'set'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
366 .c('pubsub', {xmlns: NS.PUBSUB_OWNER})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
367 .c('delete', {node: nodeID});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
368
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
369 conn.sendIQ(stanza, on.delete, on.error);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
370 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
371
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
372 purge: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
373 var nodeID = args[0];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
374 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'set'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
375 .c('pubsub', {xmlns: NS.PUBSUB_OWNER})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
376 .c('purge', {node: nodeID});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
377
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
378 conn.sendIQ(stanza, on.purge, on.error);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
379 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
380
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
381 info: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
382 if (args.length)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
383 var disco = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'get'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
384 .c('query', {xmlns: NS.DISCO_INFO, node: args[0]});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
385 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
386 var disco = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'get'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
387 .c('query', {xmlns: NS.DISCO_INFO});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
388
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
389 conn.sendIQ(disco, on.info, on.error);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
390 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
391
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
392 help: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
393 if (args.length == 0) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
394 var text = 'Available commands:';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
395 for (var i in commands)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
396 text += '\n\t' + i;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
397 } else {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
398 var text = 'Commands:';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
399 for (var i in commands)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
400 for (var j in args)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
401 if (i == args[j])
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
402 text += '\n\t' + i;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
403 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
404 appendLine(text);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
405 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
406
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
407 list: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
408 if (args.length)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
409 var disco = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'get'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
410 .c('query', {xmlns: NS.DISCO_ITEMS, node: args[0]});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
411 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
412 var disco = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'get'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
413 .c('query', {xmlns: NS.DISCO_ITEMS});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
414
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
415 conn.sendIQ(disco, on.list, on.error);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
416 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
417
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
418 manage: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
419 if (args.length < 2)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
420 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
421
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
422 var action = args[0];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
423 var nodeID = args[1];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
424
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
425 if (!nodeID)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
426 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
427
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
428 if (action != 'subscriptions' && action != 'affiliations')
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
429 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
430
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
431 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'get'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
432 .c('pubsub', {xmlns: NS.PUBSUB_OWNER})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
433 .c(action, {node: nodeID});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
434
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
435 conn.sendIQ(stanza, on.manage, on.error);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
436 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
437
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
438 options: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
439 if (args.length < 1)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
440 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
441
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
442 var nodeID = args[0];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
443
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
444 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'get'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
445 .c('pubsub', {xmlns: NS.PUBSUB})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
446 .c('options', {node: nodeID, jid: config.jid});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
447
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
448 conn.sendIQ(stanza, on.opions, on.error);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
449 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
450
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
451 quit: function() {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
452 conn.send('</stream:stream>');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
453 cleanup();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
454 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
455
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
456 refresh: function() {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
457 win.clearok(true);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
458 appendLine('Refresh, done!');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
459 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
460
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
461 retrieve: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
462 if (args.length < 1)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
463 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
464
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
465 var action = args[0];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
466 var nodeID = args[1];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
467
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
468 if (action == 'subscriptions') {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
469 if (nodeID)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
470 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'get'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
471 .c('pubsub', {xmlns: NS.PUBSUB})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
472 .c('subscriptions', {node: nodeID});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
473 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
474 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'get'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
475 .c('pubsub', {xmlns: NS.PUBSUB})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
476 .c('subscriptions');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
477
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
478 conn.sendIQ(stanza, function(stanza) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
479 var pubsub = stanza.getChild('pubsub', NS.PUBSUB);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
480 var subscriptions = pubsub.getChild('subscriptions', NS.PUBSUB);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
481
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
482 var nodeID = subscriptions.getAttribute('node');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
483 if (nodeID)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
484 var text = 'Subscriptions in ' + nodeID + ':';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
485 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
486 var text = 'Subscriptions:';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
487
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
488 for (var i in subscriptions.tags) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
489 var sub = subscriptions.tags[i];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
490 text += '\n\t' + sub.getAttribute('jid') + ', ' + sub.getAttribute('subscription') + ' to node ' + sub.getAttribute('node') + ' (' + sub.getAttribute('subid') + ')';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
491 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
492
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
493 appendLine(text);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
494 }, on.error);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
495 } else if (action == 'affiliations') {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
496 if (nodeID)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
497 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'get'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
498 .c('pubsub', {xmlns: NS.PUBSUB})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
499 .c('affiliations', {node: nodeID});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
500 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
501 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'get'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
502 .c('pubsub', {xmlns: NS.PUBSUB})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
503 .c('affiliations');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
504
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
505 conn.sendIQ(stanza, function(stanza) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
506 var pubsub = stanza.getChild('pubsub', NS.PUBSUB);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
507 var affiliations = pubsub.getChild('affiliations', NS.PUBSUB);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
508
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
509 var text = 'Affiliations:';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
510
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
511 for (var i in affiliations.tags) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
512 var affil = affiliations.tags[i];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
513 text += '\n\t' + affil.getAttribute('affiliation') + ' of node ' + affil.getAttribute('node') + '.';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
514 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
515
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
516 appendLine(text);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
517 }, on.error);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
518 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
519 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
520
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
521 send: function() {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
522 var stanza = next.func();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
523 appendLine(sys.inspect(stanza, false, null));
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
524 conn.sendIQ(stanza, function() {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
525 next = {};
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
526 }, on.error);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
527 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
528
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
529 sendFile: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
530 if (args.length < 1)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
531 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
532
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
533 fs.readFile(args[0], function(err, data) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
534 if (err)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
535 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
536
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
537 conn.send(data.toString());
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
538 });
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
539 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
540
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
541 set: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
542 if (args.length < 1)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
543 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
544
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
545 var key = args.shift();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
546
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
547 if (!args.length)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
548 delete next[key];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
549 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
550 next[key] = args;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
551
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
552 appendLine(sys.inspect(next));
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
553 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
554
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
555 subscribe: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
556 if (args.length < 1)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
557 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
558
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
559 var nodeID = args[0];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
560 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'set'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
561 .c('pubsub', {xmlns: NS.PUBSUB})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
562 .c('subscribe', {node: nodeID, jid: config.jid});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
563
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
564 conn.sendIQ(stanza, function(stanza) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
565 var pubsub = stanza.getChild('pubsub', NS.PUBSUB);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
566 var subscription = pubsub.getChild('subscription', NS.PUBSUB);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
567
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
568 var text = subscription.getAttribute('jid') + ' ' + subscription.getAttribute('subscription') + ' to ' + subscription.getAttribute('node') + ': ' + subscription.getAttribute('subid') + '.';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
569
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
570 var subOpt = subscription.getChild('subscribe-options', NS.PUBSUB);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
571 if (subOpt && subOpt.getChild('required', NS.PUBSUB))
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
572 text += ' Warning: you should configure your subscription!';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
573
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
574 appendLine(text);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
575 }, on.error);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
576 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
577
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
578 unsubscribe: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
579 if (args.length < 1)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
580 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
581
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
582 var nodeID = args[0];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
583 var stanza = xmpp.iq({to: config.server, id: conn.getUniqueId(), type: 'set'})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
584 .c('pubsub', {xmlns: NS.PUBSUB})
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
585 .c('unsubscribe', {node: nodeID, jid: config.jid});
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
586
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
587 conn.sendIQ(stanza, function(stanza) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
588 appendLine('Node correctly unsubscribed.');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
589 }, on.error);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
590 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
591
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
592 activate: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
593 if (args[0] == 'xml')
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
594 conn.log = function(_, m) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
595 if (m.indexOf('--> ') == 0)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
596 appendLine(m.substr(4), false, COLOR_IN);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
597 else if (m.indexOf('<== ') == 0)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
598 appendLine(m.substr(4), false, COLOR_OUT);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
599 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
600 appendLine(m);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
601 };
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
602 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
603
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
604 deactivate: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
605 if (args[0] == 'xml')
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
606 conn.log = function(_, m) {};
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
607 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
608
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
609 toggle: function(args) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
610 if (args[0] == 'xml') {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
611 if (options.xml)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
612 conn.log = function(_, m) {};
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
613 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
614 conn.log = function(_, m) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
615 if (m.indexOf('--> ') == 0)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
616 appendLine(m.substr(4), false, COLOR_IN);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
617 else if (m.indexOf('<== ') == 0)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
618 appendLine(m.substr(4), false, COLOR_OUT);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
619 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
620 appendLine(m);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
621 };
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
622 options.xml = !options.xml;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
623 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
624 if (args[0] in options)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
625 options[args[0]] = !options[args[0]];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
626 appendLine(args[0] + ' ' + options[args[0]]);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
627 },
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
628 };
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
629
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
630 // ============================================================================
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
631
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
632 parseCommand = function(line) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
633 var all = line.split(' ');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
634 var command = all.shift().substr(1);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
635 var args = [];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
636 var multi = '';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
637 for (var i in all) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
638 if (all[i][0] == '"')
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
639 multi += all[i].substr(1)+' ';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
640 else {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
641 if (multi != '') {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
642 multi += all[i];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
643 if (all[i][all[i].length-1] == '"') {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
644 multi = multi.substr(0, multi.length-1);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
645 args.push(multi);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
646 multi = '';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
647 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
648 } else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
649 args.push(all[i]);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
650 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
651 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
652 return {command: command, args: args};
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
653 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
654
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
655 // ============================================================================
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
656
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
657 var win = new nc.ncWindow();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
658 var inputLine = '';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
659 var hline = 0;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
660 var pos = 0;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
661 win.addListener('inputChar', function (chr, intval) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
662 if (options.chr)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
663 appendLine(chr + ' ' + intval);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
664 if (intval == consts.keys['BACKSPACE'] || intval == 7 || intval == 127) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
665 win.delch();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
666 if (inputLine.length) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
667 inputLine = inputLine.substr(0, inputLine.length-1);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
668 if (pos > 0)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
669 pos--;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
670 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
671 } else if (chr == consts.DOWN || intval == 2) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
672 if (!history.length)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
673 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
674 if (hline > history.length-1);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
675 else if (hline == history.length-1) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
676 inputLine = '';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
677 hline++;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
678 } else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
679 inputLine = history[++hline];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
680 } else if (chr == consts.UP || intval == 3) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
681 if (!history.length)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
682 return;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
683 if (hline > 0)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
684 inputLine = history[--hline];
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
685 } else if (chr == consts.LEFT || intval == 4) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
686 if (inputLine.length && pos > 0)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
687 pos--;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
688 } else if (chr == consts.RIGHT || intval == 5) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
689 if (inputLine.length && pos < inputLine.length)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
690 pos++;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
691 } else if (chr == '\n') {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
692 if (inputLine[0] == '/') {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
693 var command = parseCommand(inputLine);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
694 if (options.command_parsing)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
695 appendLine(sys.inspect(command));
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
696 var notcommand = true;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
697 for (var i in commands) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
698 if (i == command.command) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
699 commands[i](command.args);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
700 notcommand = false;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
701 break;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
702 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
703 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
704 if (notcommand)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
705 appendLine('Command unknown.');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
706 } else if (inputLine[0] == '<') {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
707 conn.send(inputLine);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
708 } else if (!inputLine.length);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
709 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
710 appendLine('Only commands and XML are allowed.');
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
711 history.push(inputLine);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
712 hline = history.length;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
713 inputLine = '';
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
714 pos = 0;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
715 } else {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
716 if (inputLine.length == pos)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
717 inputLine += chr;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
718 else {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
719 var tmp = inputLine.substr(0, pos);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
720 tmp += chr;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
721 tmp += inputLine.substr(pos, inputLine.length);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
722 inputLine = tmp;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
723 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
724 pos++;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
725 }
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
726 win.deleteln();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
727 win.cursor(win.height-1, 0);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
728 win.print(inputLine);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
729 win.cursor(win.height-1, pos);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
730 win.refresh();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
731 });
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
732
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
733 // Setup colors
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
734 var COLOR_IN = win.colorPair(2);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
735 var COLOR_OUT = win.colorPair(3);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
736 var COLOR_QUIT = win.colorPair(6);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
737 var COLOR_ACTION = win.colorPair(5);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
738
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
739 // Setup window
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
740 win.clear();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
741 win.echo = false;
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
742 win.scrollok(true);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
743 win.hline(win.height-2, 0, win.width);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
744 win.setscrreg(0, win.height-3); // Leave one line at the top for the channel name and optional topic
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
745 win.cursor(win.height-1, 0);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
746 win.refresh();
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
747
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
748 var conn = new xmpp.Connection(server);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
749
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
750 conn.log = function(_, m) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
751 if (m.indexOf('--> ') == 0)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
752 appendLine(m.substr(4), false, COLOR_IN);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
753 else if (m.indexOf('<== ') == 0)
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
754 appendLine(m.substr(4), false, COLOR_OUT);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
755 else
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
756 appendLine(m);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
757 };
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
758
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
759 conn.connect(user, server, config.password, function (status, condition) {
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
760 appendLine(st[status] + (condition?(' ('+condition+')'):''), true, COLOR_ACTION);
a2dab4544b2d Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
761 });