Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Bug fix for getInfo(), implement Location service error detection, an…

…d add method for disconnecting from the server
  • Loading branch information...
commit 79355fe2f41123ad3324e03692e63d3d0c770326 1 parent ec97ec5
Brian White authored

Showing 2 changed files with 181 additions and 93 deletions. Show diff stats Hide diff stats

  1. 2  README.md
  2. 272  oscar.js
2  README.md
Source Rendered
@@ -128,6 +128,8 @@ OscarConnection Functions
128 128
 
129 129
 * **connect**(Function) - _(void)_ - Connects to the OSCAR server. The Function parameter is the callback with one argument: the error (undefined if none).
130 130
 
  131
+* **end**() - _(void)_ - Disconnects from the OSCAR server.
  132
+
131 133
 * **setIdle**(Integer/Boolean) - _(void)_ - If an Integer is supplied, your idle time is set to that many seconds. If Boolean false is given, then you are no longer set as idle. Note: setIdle only needs to be called once when you are idle and again when you are no longer idle. The server will automatically increment the idle time for you, so don't call setIdle every second.
132 134
 
133 135
 * **sendIM**(String, String[, Integer[, Function]]) - _(void)_ - Sends an instant message. The first parameter is the recipient's user name, the second is the message text. The third parameter is an optional bit field containing message flags to use (see the IM\_FLAGS constants). The Function parameter is an optional callback (with one argument: the error (undefined if none) containing relevant code and subcode properties (see the MSG_ERRORS AND MSG_SUBERRORS constants)) that if supplied, will request an acknowledgement from the server that the message was sent ok.
272  oscar.js
... ...
@@ -1,6 +1,13 @@
1  
-var net = require('net'), sys = require('sys'), EventEmitter = require('events').EventEmitter, crypto = require('crypto'), http = require('http');
  1
+var net = require('net'), util = require('util'),
  2
+    EventEmitter = require('events').EventEmitter, crypto = require('crypto');
2 3
 var fnEmpty = function() {};
3  
-var debug = fnEmpty/*console.error, hexy = require('./hexy').hexy*/, hexyFormat = { caps: 'upper', format: 'twos', numbering: 'none', groupSpacing: 2 };
  4
+var debug = fnEmpty, hexy, inspectMutated = false,
  5
+    hexyFormat = {
  6
+      caps: 'upper',
  7
+      format: 'twos',
  8
+      numbering: 'none',
  9
+      groupSpacing: 2
  10
+    };
4 11
 
5 12
 function OscarConnection(options) {
6 13
   if (!(this instanceof OscarConnection))
@@ -14,14 +21,24 @@ function OscarConnection(options) {
14 21
       host: SERVER_AOL,
15 22
       port: 5190,
16 23
       connTimeout: 10000, // connection timeout in msecs
17  
-      allowMultiLogin: true
  24
+      allowMultiLogin: true,
  25
+      debug: false
18 26
     }, other: {
19 27
       initialStatus: USER_STATUSES.ONLINE,
20 28
       initialFlags: USER_FLAGS.DCDISABLED
21 29
     }
22 30
   };
23 31
   this._options = extend(true, this._options, options);
24  
-
  32
+  if (typeof this._options.connection.debug === 'function') {
  33
+    debug = this._options.connection.debug;
  34
+    if (!inspectMutated) {
  35
+      inspectMutated = true;
  36
+      hexy = require('./hexy').hexy;
  37
+      Buffer.prototype.inspect = function () {
  38
+        return hexy(this, hexyFormat);
  39
+      };
  40
+    }
  41
+  }
25 42
   this._state = {
26 43
     connections: {},
27 44
     serviceMap: {},
@@ -36,15 +53,16 @@ function OscarConnection(options) {
36 53
     svcPaused: {},
37 54
     SSI: {},
38 55
     iconQueue: {},
39  
-    rndvCookies: {},
40  
-    chatrooms: {}
  56
+    rndvCookies: { out: {}, in: {} },
  57
+    chatrooms: {},
  58
+    p2p: {}
41 59
   };
42 60
 
43 61
   this.icon = { datetime: undefined, data: undefined }; // my 'buddy' icon
44 62
   this.me = undefined;
45 63
   this.contacts = { lastModified: undefined, list: undefined, permit: undefined, deny: undefined, prefs: undefined, _totalSSICount: 0, _usedIDs: {} };
46 64
 }
47  
-sys.inherits(OscarConnection, EventEmitter);
  65
+util.inherits(OscarConnection, EventEmitter);
48 66
 
49 67
 // setIdle only needs to be called once when you are idle and again when you are no longer idle.
50 68
 // The server will automatically increment the idle time for you, so don't call setIdle every second
@@ -63,8 +81,6 @@ OscarConnection.prototype.setIdle = function(amount) { // amount is in seconds i
63 81
   ));
64 82
 };
65 83
 
66  
-// 32-bit little endian conversion
67  
-//((x & 0xFF) << 24) + ((x >> 8 & 0xFF) << 16) + ((x >> 16 & 0xFF) << 8) + (x >> 24 & 0xFF)
68 84
 OscarConnection.prototype.sendIM = function(who, message, flags, cb) {
69 85
   var msgData, cookie, msgLen, self = this, features = (self._state.isAOL ? [0x01, 0x01, 0x01, 0x02] : [0x01]),
70 86
       featLen = features.length, charset = ICBM_MSG_CHARSETS.ASCII, isSMS;
@@ -502,7 +518,7 @@ OscarConnection.prototype.renameGroup = function(group, newName, cb) {
502 518
 
503 519
 OscarConnection.prototype.getInfo = function(who, cb) {
504 520
   // requests profile, away msg, capabilities
505  
-  this._send(this._createFLAP(self._state.connections.main, FLAP_CHANNELS.SNAC,
  521
+  this._send(this._createFLAP(this._state.connections.main, FLAP_CHANNELS.SNAC,
506 522
     this._createSNAC(SNAC_SERVICES.LOCATION, 0x15, NO_FLAGS,
507 523
       [0x00, 0x00, 0x00, 0x07,  who.length]
508 524
       .concat(str2bytes(who))
@@ -669,6 +685,13 @@ OscarConnection.prototype.connect = function(cb) {
669 685
   });
670 686
 };
671 687
 
  688
+OscarConnection.prototype.end = function() {
  689
+  var ids = Object.keys(this._state.connections);
  690
+  for (var i=0,len=ids.length; i<len; ++i)
  691
+    this._state.connections[ids[i]].end();
  692
+  this._resetState();
  693
+};
  694
+
672 695
 // Connection handlers -------------------------------------------------------------------------------
673 696
 
674 697
 function connect_handler(oscar) {
@@ -691,7 +714,7 @@ function connect_handler(oscar) {
691 714
 
692 715
 function data_handler(oscar, data, cb) {
693 716
   var self = oscar, conn = this;
694  
-  //debug('(' + conn.remoteAddress + ') RECEIVED: \n' + sys.inspect(data)) + '\n';
  717
+  //debug('(' + conn.remoteAddress + ') RECEIVED: \n' + util.inspect(data)) + '\n';
695 718
   if (conn.curData)
696 719
     conn.curData = conn.curData.append(data);
697 720
   else
@@ -764,6 +787,7 @@ function end_handler(oscar) {
764 787
   var self = oscar, conn = this;
765 788
   conn.isConnected = false;
766 789
   if (!conn.isTransferring) {
  790
+    self._resetState();
767 791
     debug('(' + conn.remoteAddress + ') FIN packet received. Disconnecting...');
768 792
     self.emit('end');
769 793
   }
@@ -784,6 +808,7 @@ function close_handler(oscar, had_error) {
784 808
   var self = oscar, conn = this;
785 809
   conn.isConnected = false;
786 810
   if (!conn.isTransferring || had_error) {
  811
+    self._resetState();
787 812
     debug('(' + conn.remoteAddress + ') Connection forcefully closed.');
788 813
     self.emit('close', had_error);
789 814
   }
@@ -791,6 +816,27 @@ function close_handler(oscar, had_error) {
791 816
 
792 817
 // Private methods -----------------------------------------------------------------------------------
793 818
 
  819
+OscarConnection.prototype._resetState = function() {
  820
+  this._state = {
  821
+    connections: {},
  822
+    serviceMap: {},
  823
+    reqID: 0, // 32-bit number that identifies a single SNAC request
  824
+    status: this._options.other.initialStatus,
  825
+    flags: this._options.other.initialFlags,
  826
+    requests: {},
  827
+    isAOL: (this._options.connection.host.substr(this._options.connection.host.length-7).toUpperCase() === 'AOL.COM'),
  828
+    rateLimitGroups: {},
  829
+    rateLimits: {},
  830
+    svcInfo: {},
  831
+    svcPaused: {},
  832
+    SSI: {},
  833
+    iconQueue: {},
  834
+    rndvCookies: { out: {}, in: {} },
  835
+    chatrooms: {},
  836
+    p2p: {}
  837
+  };
  838
+};
  839
+
794 840
 OscarConnection.prototype._addConnection = function(id, services, host, port, cb) {
795 841
   var self = this;
796 842
   self._state.connections[id] = net.createConnection(port, host);
@@ -1065,7 +1111,7 @@ OscarConnection.prototype._send = function(conn, payload, cb) {
1065 1111
     }
1066 1112
   }
1067 1113
   payload = new Buffer(payload);
1068  
-  debug('(' + conn.remoteAddress + ') SENDING: \n' + sys.inspect(payload) + '\n');
  1114
+  debug('(' + conn.remoteAddress + ') SENDING: \n' + util.inspect(payload) + '\n');
1069 1115
   conn.write(payload);
1070 1116
 };
1071 1117
 
@@ -1077,7 +1123,7 @@ OscarConnection.prototype._dispatch = function(reqID) {
1077 1123
   }
1078 1124
 };
1079 1125
 
1080  
-OscarConnection.prototype._incomingFile = function(info, data) {
  1126
+OscarConnection.prototype._incomingFile = function(data) {
1081 1127
   var fileInfo = {}, i = 0, len;
1082 1128
   fileInfo.subtype = (data[i++] << 8) + data[i++]; // 0x0001 === 'one file', 0x0002 === 'more than one file'
1083 1129
   fileInfo.numFiles = (data[i++] << 8) + data[i++];
@@ -1086,14 +1132,14 @@ OscarConnection.prototype._incomingFile = function(info, data) {
1086 1132
   return fileInfo;
1087 1133
 };
1088 1134
 
1089  
-OscarConnection.prototype._incomingIcon = function(info, data) {
  1135
+OscarConnection.prototype._incomingIcon = function(data) {
1090 1136
   var i = 0, hash = (data[i++] << 24) + (data[i++] << 16) + (data[i++] << 8) + data[i++],
1091 1137
       len = (data[i++] << 24) + (data[i++] << 16) + (data[i++] << 8) + data[i++],
1092 1138
       datetime = (data[i++] << 24) + (data[i++] << 16) + (data[i++] << 8) + data[i++];
1093 1139
   return { hash: hash, datetime: datetime, data: data.slice(i, i+len) };
1094 1140
 };
1095 1141
 
1096  
-OscarConnection.prototype._incomingChat = function(info, data) {
  1142
+OscarConnection.prototype._incomingChat = function(data) {
1097 1143
   var roomInfo = {}, i = 0, len;
1098 1144
   roomInfo.exchange = (data[i++] << 8) + data[i++];
1099 1145
   len = data[i++];
@@ -1103,7 +1149,7 @@ OscarConnection.prototype._incomingChat = function(info, data) {
1103 1149
   return roomInfo;
1104 1150
 };
1105 1151
 
1106  
-OscarConnection.prototype._incomingList = function(info, data) {
  1152
+OscarConnection.prototype._incomingList = function(data) {
1107 1153
   var list = {};
1108 1154
   for (var i=0,len=data.length,group,namelen,numContacts; i<len;) {
1109 1155
     namelen = (data[i++] << 8) + data[i++];
@@ -1161,21 +1207,34 @@ OscarConnection.prototype._sendIcon = function(who) {
1161 1207
   }
1162 1208
 };
1163 1209
 
1164  
-OscarConnection.prototype._cancelRendezvous = function(cookie, cb) {
  1210
+OscarConnection.prototype.sendFile = function(who, file, ip, port, cb) {
  1211
+  
  1212
+};
  1213
+
  1214
+OscarConnection.prototype._cancelRendezvous = function(inout, cookie, cb) {
1165 1215
   cookie = ''+cookie;
1166  
-  var info = rndvCookies[cookie];
  1216
+  var info = rndvCookies[inout][cookie];
1167 1217
   if (typeof info !== 'undefined') {
1168 1218
     var content, type;
1169 1219
     cookie = info.cookie;
1170 1220
     if (info.type === 'chat')
1171 1221
       type = CAPABILITIES.CHAT;
1172  
-    content = cookie.concat[0x00, 0x02, who.length].concat(who).concat(this._createTLV(0x03))
1173  
-                    .concat(this._createTLV(0x05, [0x00, 0x01].concat(cookie).concat(type).concat(this._createTLV(0x0B))));
1174  
-    this._send(this._createFLAP(self._state.connections.main, FLAP_CHANNELS.SNAC,
1175  
-      this._createSNAC(SNAC_SERVICES.ICBM, 0x06, NO_FLAGS,
1176  
-        content
1177  
-      )
1178  
-    ), cb);
  1222
+    else if (info.type === 'file')
  1223
+      type = CAPABILITIES.SEND_FILE;
  1224
+    if (inout === 'out') {
  1225
+      content = cookie.concat[0x00, 0x02, who.length].concat(who).concat(this._createTLV(0x03))
  1226
+                      .concat(this._createTLV(0x05, [0x00, 0x01].concat(cookie).concat(type).concat(this._createTLV(0x0B))));
  1227
+      this._send(this._createFLAP(self._state.connections.main, FLAP_CHANNELS.SNAC,
  1228
+        this._createSNAC(SNAC_SERVICES.ICBM, 0x06, NO_FLAGS,
  1229
+          content
  1230
+        )
  1231
+      ), cb);
  1232
+    } else if (inout === 'in') {
  1233
+      if (info.type === 'file') {
  1234
+        
  1235
+      }
  1236
+    }
  1237
+    delete rndvCookies[inout][cookie];
1179 1238
   }
1180 1239
 };
1181 1240
 
@@ -1187,7 +1246,7 @@ OscarConnection.prototype._chatInvite = function(who, msg, roomInfo) {
1187 1246
   exchange = splitNum(roomInfo.exchange, 2);
1188 1247
   instance = splitNum(roomInfo.instance, 2);
1189 1248
   cookie = splitNum(Date.now(), 4).concat(splitNum(Date.now()+1, 4));
1190  
-  this._state.rndvCookies[cookie.join('')] = {
  1249
+  this._state.rndvCookies.out[cookie.join('')] = {
1191 1250
     cookie: cookie,
1192 1251
     type: 'chat',
1193 1252
     user: who,
@@ -1209,7 +1268,7 @@ OscarConnection.prototype._chatInvite = function(who, msg, roomInfo) {
1209 1268
 };
1210 1269
 
1211 1270
 OscarConnection.prototype._parseSNAC = function(conn, snac, cb) {
1212  
-  //debug('(' + conn.remoteAddress + ') SNAC response follows:\n' + sys.inspect(snac));
  1271
+  //debug('(' + conn.remoteAddress + ') SNAC response follows:\n' + util.inspect(snac));
1213 1272
   var serviceID, subtypeID, flags, reqID, tlvs, idx, isServerOrig, moreFollows,
1214 1273
       debugtext, self = this;
1215 1274
   serviceID = (snac[0] << 8) + snac[1];
@@ -1235,14 +1294,14 @@ OscarConnection.prototype._parseSNAC = function(conn, snac, cb) {
1235 1294
           tlvs = extractTLVs(snac);
1236 1295
           if (tlvs[TLV_TYPES.ERROR]) {
1237 1296
             var err = new Error(AUTH_ERRORS_TEXT[(tlvs[TLV_TYPES.ERROR][0] << 8) + tlvs[TLV_TYPES.ERROR][1]]);
1238  
-            debugtext += '(error: ' + err + ')';
  1297
+            debugtext += ' (error: ' + err + ')';
1239 1298
             if (typeof cb === 'function')
1240 1299
               cb(err);
1241 1300
             else
1242 1301
               throw err;
1243 1302
           } else {
1244 1303
             self._dispatch(reqID, undefined, tlvs[TLV_TYPES.BOS_SERVER].toString(), tlvs[TLV_TYPES.AUTH_COOKIE].toArray());
1245  
-            debugtext += '(no error)';
  1304
+            debugtext += ' (no error)';
1246 1305
           }
1247 1306
         break;
1248 1307
         case 0x07: // md5 salt
@@ -1454,6 +1513,14 @@ OscarConnection.prototype._parseSNAC = function(conn, snac, cb) {
1454 1513
     case SNAC_SERVICES.LOCATION:
1455 1514
       debugtext += 'LOCATION > ';
1456 1515
       switch (subtypeID) {
  1516
+        case 0x01: // error
  1517
+          debugtext += 'Error';
  1518
+          var code = (snac[idx++] << 8) + snac[idx++], msg = GLOBAL_ERRORS_TEXT[code] || 'Unknown error code received: ' + code,
  1519
+              err = new Error(msg);
  1520
+          err.code = code;
  1521
+          debugtext += ': ' + msg;
  1522
+          self._dispatch(reqID, err);
  1523
+        break;
1457 1524
         case 0x03: // limits response
1458 1525
           debugtext += 'Service limits';
1459 1526
           tlvs = extractTLVs(snac);
@@ -1597,7 +1664,7 @@ OscarConnection.prototype._parseSNAC = function(conn, snac, cb) {
1597 1664
           sender = sender[0];
1598 1665
           tlvs = extractTLVs(snac, idx);
1599 1666
           if (channel === 1) { // normal IMs
1600  
-            debugtext += 'IM. Sender: ' + sys.inspect(sender.name);
  1667
+            debugtext += 'IM. Sender: ' + util.inspect(sender.name);
1601 1668
             var msgText, charset, msgData = tlvs[0x02], flags = 0, datetime;
1602 1669
             for (var i=0,len=msgData.length,fragID,fragLen; i<len;) {
1603 1670
               fragID = msgData[i++];
@@ -1648,63 +1715,88 @@ OscarConnection.prototype._parseSNAC = function(conn, snac, cb) {
1648 1715
                   rndvCookie = [msgData[i++], msgData[i++], msgData[i++], msgData[i++],
1649 1716
                                msgData[i++], msgData[i++], msgData[i++], msgData[i++]];
1650 1717
               if (arraysEqual(rndvCookie, cookie)) { // cookie values _should_ match
1651  
-                var type = msgData.slice(idx, idx+16).toArray(), info = {};
1652  
-                idx += 16;
1653  
-                tlvs = extractTLVs(msgData, idx);
1654  
-                if (tlvs[0x02] && tlvs[0x02].length === 4)
1655  
-                  info.proxyIP = '' + tlvs[0x02][0] + '.' + tlvs[0x02][1] + '.' + tlvs[0x02][2] + '.' + tlvs[0x02][3];
1656  
-                if (tlvs[0x03] && tlvs[0x03].length === 4)
1657  
-                  info.clientIP = '' + tlvs[0x03][0] + '.' + tlvs[0x03][1] + '.' + tlvs[0x03][2] + '.' + tlvs[0x03][3];
1658  
-                if (tlvs[0x04] && tlvs[0x04].length === 4)
1659  
-                  info.verifiedIP = '' + tlvs[0x04][0] + '.' + tlvs[0x04][1] + '.' + tlvs[0x04][2] + '.' + tlvs[0x04][3];
1660  
-                if (tlvs[0x05])
1661  
-                  info.port = (tlvs[0x05][0] << 8) + tlvs[0x05][1];
1662  
-                if (tlvs[0x0A]) {
1663  
-                  info.reqNum = (tlvs[0x0A][0] << 8) + tlvs[0x0A][1];
1664  
-                  // reqNum === 1 -> Initial file xfer request for no/stage 1 proxy
1665  
-                  // reqNum === 2 -> reply request for stage 2 proxy (receiver wants to use a proxy)
1666  
-                  // reqNum === 3 -> third request -- only for stage 3 proxy
1667  
-                }
1668  
-                if (tlvs[0x0B])
1669  
-                  info.err = (tlvs[0x0B][0] << 8) + tlvs[0x0B][1];
1670  
-                if (tlvs[0x0C])
1671  
-                  info.msg = tlvs[0x0C].toString();
1672  
-                if (tlvs[0x0D])
1673  
-                  info.charset = tlvs[0x0D].toString();
1674  
-                if (tlvs[0x0E])
1675  
-                  info.lang = tlvs[0x0E].toString();
1676  
-                if (tlvs[0x10])
1677  
-                  info.useProxy = true;
1678  
-
1679  
-                if (tlvs[0x2711]) {
1680  
-                  if (arraysEqual(type, CAPABILITIES.SEND_FILE)) {
1681  
-                    if (tlvs[0x2712])
1682  
-                      info.fnameCharset = tlvs[0x2712].toString(); // i.e. 'us-ascii'
1683  
-                    var fileInfo = self._incomingFile(info, tlvs[0x2711]);
1684  
-                    //debug('Incoming file transfer request ... Sender: ' + sys.inspect(sender) + ' File info: ' + sys.inspect(fileInfo));
1685  
-                    debugtext += ': File xfer request. Sender: ' + sys.inspect(sender.name) + ' File info: ' + sys.inspect(fileInfo);
1686  
-                    self.emit('filexfer', sender, fileInfo);
1687  
-                  } else if (arraysEqual(type, CAPABILITIES.BUDDY_ICON)) {
1688  
-                    var iconInfo = self._incomingIcon(info, tlvs[0x2711]);
1689  
-                    //debug('Incoming icon data ... Sender: ' + sys.inspect(sender) + ' Icon info: ' + sys.inspect(iconInfo));
1690  
-                    debugtext += ': Icon data. Sender: ' + sys.inspect(sender.name) + ' Icon info: ' + sys.inspect(iconInfo);
1691  
-                    self.emit('icon', sender, iconInfo.data);
1692  
-                  } else if (arraysEqual(type, CAPABILITIES.CHAT)) {
1693  
-                    var roomInfo = self._incomingChat(info, tlvs[0x2711]);
1694  
-                    //debug('Incoming chat invitation ... Sender: ' + sys.inspect(sender) + ' Chat room info: ' + sys.inspect(roomInfo));
1695  
-                    debugtext += ': Chat invitation. Sender: ' + sys.inspect(sender.name) + ' Chat room info: ' + sys.inspect(roomInfo);
1696  
-                    self.emit('chatinvite', sender, roomInfo.name, info.msg);
1697  
-                  } else if (arraysEqual(type, CAPABILITIES.SEND_CONTACT_LIST)) {
1698  
-                    var list = self._incomingList(info, tlvs[0x2711]);
1699  
-                    //debug('Incoming contact list ... Sender: ' + sys.inspect(sender) + ' List: ' + sys.inspect(list));
1700  
-                    debugtext += ': Contact list. Sender: ' + sys.inspect(sender.name) + ' List: ' + sys.inspect(list);
1701  
-                    self.emit('contactlist', sender, list);
  1718
+                if (status === ICBM_RENDEZVOUS_STATUSES.REQUEST) {
  1719
+                  var type = msgData.slice(idx, idx+16).toArray(), info = {};
  1720
+                  idx += 16;
  1721
+                  tlvs = extractTLVs(msgData, idx);
  1722
+                  if (tlvs[0x02] && tlvs[0x02].length === 4)
  1723
+                    info.proxyIP = tlvs[0x02][0] + '.' + tlvs[0x02][1] + '.' + tlvs[0x02][2] + '.' + tlvs[0x02][3];
  1724
+                  if (tlvs[0x03] && tlvs[0x03].length === 4)
  1725
+                    info.clientIP = tlvs[0x03][0] + '.' + tlvs[0x03][1] + '.' + tlvs[0x03][2] + '.' + tlvs[0x03][3];
  1726
+                  if (tlvs[0x04] && tlvs[0x04].length === 4)
  1727
+                    info.verifiedIP = tlvs[0x04][0] + '.' + tlvs[0x04][1] + '.' + tlvs[0x04][2] + '.' + tlvs[0x04][3];
  1728
+                  if (tlvs[0x05])
  1729
+                    info.port = (tlvs[0x05][0] << 8) + tlvs[0x05][1];
  1730
+                  if (tlvs[0x0A]) {
  1731
+                    info.reqNum = (tlvs[0x0A][0] << 8) + tlvs[0x0A][1];
  1732
+                    // reqNum === 1 -> Initial file xfer request for no/stage 1 proxy
  1733
+                    // reqNum === 2 -> reply request for stage 2 proxy (receiver wants to use a proxy)
  1734
+                    // reqNum === 3 -> third request -- only for stage 3 proxy
  1735
+                  }
  1736
+                  if (tlvs[0x0B])
  1737
+                    info.err = (tlvs[0x0B][0] << 8) + tlvs[0x0B][1];
  1738
+                  if (tlvs[0x0C])
  1739
+                    info.msg = tlvs[0x0C].toString();
  1740
+                  if (tlvs[0x0D])
  1741
+                    info.charset = tlvs[0x0D].toString();
  1742
+                  if (tlvs[0x0E])
  1743
+                    info.lang = tlvs[0x0E].toString();
  1744
+                  if (typeof tlvs[0x10] !== 'undefined')
  1745
+                    info.useProxy = true;
  1746
+
  1747
+                  if (tlvs[0x2711]) {
  1748
+                    if (arraysEqual(type, CAPABILITIES.SEND_FILE)) {
  1749
+                      if (tlvs[0x2712])
  1750
+                        info.fnameCharset = tlvs[0x2712].toString(); // i.e. 'us-ascii'
  1751
+                      var fileInfo = self._incomingFile(tlvs[0x2711]);
  1752
+                      //debug('Incoming file transfer request ... Sender: ' + util.inspect(sender) + ' File info: ' + util.inspect(fileInfo));
  1753
+                      debugtext += ': File xfer request. Sender: ' + util.inspect(sender.name) + ' File info: ' + util.inspect(fileInfo);
  1754
+                      info.fileInfo = fileInfo;
  1755
+                      self._state.rndvCookies.in[rndvCookie] = {
  1756
+                        cookie: rndvCookie,
  1757
+                        type: 'file',
  1758
+                        user: sender.name,
  1759
+                        info: info
  1760
+                      };
  1761
+                      self.emit('filexfer', sender, rndvCookie, fileInfo);
  1762
+                    } else if (arraysEqual(type, CAPABILITIES.BUDDY_ICON)) {
  1763
+                      var iconInfo = self._incomingIcon(tlvs[0x2711]);
  1764
+                      //debug('Incoming icon data ... Sender: ' + util.inspect(sender) + ' Icon info: ' + util.inspect(iconInfo));
  1765
+                      debugtext += ': Icon data. Sender: ' + util.inspect(sender.name) + ' Icon info: ' + util.inspect(iconInfo);
  1766
+                      info.iconInfo = iconInfo;
  1767
+                      self.emit('icon', sender, iconInfo.data);
  1768
+                    } else if (arraysEqual(type, CAPABILITIES.CHAT)) {
  1769
+                      var roomInfo = self._incomingChat(tlvs[0x2711]);
  1770
+                      //debug('Incoming chat invitation ... Sender: ' + util.inspect(sender) + ' Chat room info: ' + util.inspect(roomInfo));
  1771
+                      debugtext += ': Chat invitation. Sender: ' + util.inspect(sender.name) + ' Chat room info: ' + util.inspect(roomInfo);
  1772
+                      info.roomInfo = roomInfo;
  1773
+                      self._state.rndvCookies.in[rndvCookie] = {
  1774
+                        cookie: rndvCookie,
  1775
+                        type: 'chat',
  1776
+                        user: sender.name,
  1777
+                        info: info
  1778
+                      };
  1779
+                      self.emit('chatinvite', sender, roomInfo.name, info.msg);
  1780
+                    } else if (arraysEqual(type, CAPABILITIES.SEND_CONTACT_LIST)) {
  1781
+                      var list = self._incomingList(tlvs[0x2711]);
  1782
+                      //debug('Incoming contact list ... Sender: ' + util.inspect(sender) + ' List: ' + util.inspect(list));
  1783
+                      debugtext += ': Contact list. Sender: ' + util.inspect(sender.name) + ' List: ' + util.inspect(list);
  1784
+                      info.listInfo = list;
  1785
+                      self.emit('contactlist', sender, list);
  1786
+                    }
  1787
+                  }
  1788
+                } else if (status === ICBM_RENDEZVOUS_STATUSES.ACCEPT) {
  1789
+                } else if (status === ICBM_RENDEZVOUS_STATUSES.CANCEL) {
  1790
+                  if (self._state.p2p[rndvCookie]) {
  1791
+                    self._state.p2p[rndvCookie].conn.end();
  1792
+                    delete self._state.p2p[rndvCookie];
  1793
+                    // TODO: emit event or let the module user that the other side canceled?
1702 1794
                   }
1703 1795
                 }
1704 1796
               }
1705 1797
             }
1706 1798
           } else if (channel === 4)
1707  
-            debugtext += 'Unknown (channel 4). Sender: ' + sys.inspect(sender.name);
  1799
+            debugtext += 'Unknown (channel 4). Sender: ' + util.inspect(sender.name);
1708 1800
         break;
1709 1801
         case 0x08: // warn request ACK
1710 1802
           debugtext += 'Warn request ACK';
@@ -1852,7 +1944,7 @@ OscarConnection.prototype._parseSNAC = function(conn, snac, cb) {
1852 1944
               if (exgTLVs[0xD9])
1853 1945
                 self._state.svcInfo[SNAC_SERVICES.CHAT_NAV].exchanges[id].lang2 = exgTLVs[0xD9].toString();
1854 1946
             }
1855  
-            //debug('exchange info: ' + sys.inspect(self._state.svcInfo[SNAC_SERVICES.CHAT_NAV].exchanges, false, 4));
  1947
+            //debug('exchange info: ' + util.inspect(self._state.svcInfo[SNAC_SERVICES.CHAT_NAV].exchanges, false, 4));
1856 1948
             debugtext += ';';
1857 1949
           }
1858 1950
           if (tlvs[0x04]) { // room info
@@ -2822,7 +2914,7 @@ OscarConnection.prototype._createFLAP = function(conn, channel, value) {
2822 2914
           if (!isNaN(parseInt(''+value[i])))
2823 2915
             value[i] = parseInt(''+value[i]);
2824 2916
           else
2825  
-            throw new Error('_createFLAP :: Only numbers can be in an Array value. Found a(n) ' + typeof value[i] + ' at index ' + i + ': ' + sys.inspect(value[i]));
  2917
+            throw new Error('_createFLAP :: Only numbers can be in an Array value. Found a(n) ' + typeof value[i] + ' at index ' + i + ': ' + util.inspect(value[i]));
2826 2918
         }
2827 2919
         if (value[i] > 0xFF)
2828 2920
           Array.prototype.splice.apply(value, [i, 1].concat(splitNum(value[i])));
@@ -2856,7 +2948,7 @@ OscarConnection.prototype._createSNAC = function(serviceID, subtypeID, flags, va
2856 2948
           if (!isNaN(parseInt(''+value[i])))
2857 2949
             value[i] = parseInt(''+value[i]);
2858 2950
           else
2859  
-            throw new Error('_createSNAC :: Only numbers can be in an Array value. Found a(n) ' + typeof value[i] + ' at index ' + i + ': ' + sys.inspect(value[i]));
  2951
+            throw new Error('_createSNAC :: Only numbers can be in an Array value. Found a(n) ' + typeof value[i] + ' at index ' + i + ': ' + util.inspect(value[i]));
2860 2952
         }
2861 2953
         if (value[i] > 0xFF)
2862 2954
           Array.prototype.splice.apply(value, [i, 1].concat(splitNum(value[i])));
@@ -2891,7 +2983,7 @@ OscarConnection.prototype._createTLV = function(type, value) {
2891 2983
           if (!isNaN(parseInt(''+value[i])))
2892 2984
             value[i] = parseInt(''+value[i]);
2893 2985
           else
2894  
-            throw new Error('_createTLV :: Only numbers can be in an Array value. Found a(n) ' + typeof value[i] + ' at index ' + i + ': ' + sys.inspect(value[i]));
  2986
+            throw new Error('_createTLV :: Only numbers can be in an Array value. Found a(n) ' + typeof value[i] + ' at index ' + i + ': ' + util.inspect(value[i]));
2895 2987
         }
2896 2988
         if (value[i] > 0xFF)
2897 2989
           Array.prototype.splice.apply(value, [i, 1].concat(splitNum(value[i])));
@@ -3047,12 +3139,6 @@ Buffer.prototype.append = function(buf) {
3047 3139
   return newBuf;
3048 3140
 };
3049 3141
 
3050  
-if (typeof hexy !== 'undefined') {
3051  
-  Buffer.prototype.inspect = function () {
3052  
-    return hexy(this, hexyFormat);
3053  
-  }
3054  
-}
3055  
-
3056 3142
 Buffer.prototype.toArray = function() {
3057 3143
   return Array.prototype.slice.call(this);
3058 3144
 };
@@ -3594,4 +3680,4 @@ exports.CAPABILITIES = CAPABILITIES;
3594 3680
 exports.TYPING_NOTIFY = TYPING_NOTIFY;
3595 3681
 exports.MOTD_TYPES = MOTD_TYPES;
3596 3682
 exports.IM_FLAGS = ICBM_MSG_FLAGS;
3597  
-exports.IM_MISSED_REASONS = ICBM_MISSED_REASONS;
  3683
+exports.IM_MISSED_REASONS = ICBM_MISSED_REASONS;

0 notes on commit 79355fe

Please sign in to comment.
Something went wrong with that request. Please try again.