My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 74 attachment: pyicq20070823.patch (12.0 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
diff -Naur src1/globals.py src2/globals.py
--- src1/globals.py 2007-03-30 11:34:45.000000000 +0300
+++ src2/globals.py 2007-08-07 15:51:53.000000000 +0300
@@ -37,6 +37,7 @@
XAVATAR = "jabber:x:avatar"
XCONFERENCE = "jabber:x:conference"
XDATA = "jabber:x:data"
+XDELAY = "jabber:x:delay"
XEVENT = "jabber:x:event"
XHTML = "http://jabber.org/protocol/xhtml-im"
SAPO_NOERROR = "sapo:noerror"
diff -Naur src1/jabw.py src2/jabw.py
--- src1/jabw.py 2007-03-30 11:34:45.000000000 +0300
+++ src2/jabw.py 2007-07-26 16:04:19.000000000 +0300
@@ -22,7 +22,7 @@

if delay:
x = el.addElement("x")
- x.attributes["xmlns"] = globals.IQDELAY
+ x.attributes["xmlns"] = globals.XDELAY
x.attributes["from"] = fro
x.attributes["stamp"] = delay

@@ -105,7 +105,12 @@

pytrans.send(el)

-def sendErrorMessage(pytrans, to, fro, etype, condition, explanation, body=None, el=Element((None, "message"))):
+#http://hancke.name/jabber/doubleerror.patch
+#http://www.blathersource.org/bugs_view.php?projid=pyicq-t&bugid=281
+#def sendErrorMessage(pytrans, to, fro, etype, condition, explanation, body=None, el=Element((None, "message"))):
+def sendErrorMessage(pytrans, to, fro, etype, condition, explanation, body=None, el=None):
+ if el is None:
+ el = Element((None, "message"))
el.attributes["to"] = to
el.attributes["from"] = fro
el.attributes["type"] = "error"
diff -Naur src1/legacy/icqt.py src2/legacy/icqt.py
--- src1/legacy/icqt.py 2007-03-30 11:34:44.000000000 +0300
+++ src2/legacy/icqt.py 2007-08-07 15:54:03.000000000 +0300
@@ -153,6 +153,10 @@
status = status.decode("iso-8859-1", "replace")
if status == "Away" or status=="I am currently away from the computer." or status=="I am away from my computer right now.":
status = ""
+ try:
+ status = status.decode("utf16be", "replace")
+ except:
+ pass
if user.idleTime:
if user.idleTime>60*24:
idle_time = "Idle %d days"%(user.idleTime/(60*24))
@@ -176,7 +180,6 @@

if user.caps:
self.oscarcon.legacyList.setCapabilities(user.name, user.caps)
- status = status.encode("utf-8", "replace")
if user.flags.count("away"):
self.getAway(user.name).addCallback(self.sendAwayPresence, user)
else:
@@ -201,7 +204,7 @@
c.updatePresence(show=show, status=status, ptype=ptype)
self.oscarcon.legacyList.updateSSIContact(user.name, presence=ptype, show=show, status=status)

- def receiveMessage(self, user, multiparts, flags):
+ def receiveMessage(self, user, multiparts, flags, delay=None):
from glue import icq2jid

LogEvent(INFO, self.session.jabberID, "%s %s %s" % (user.name, multiparts, flags))
@@ -224,7 +227,7 @@
if "auto" in flags:
mtype = "headline"

- self.session.sendMessage(to=self.session.jabberID, fro=sourcejid, body=text, mtype=mtype, xhtml=xhtml)
+ self.session.sendMessage(to=self.session.jabberID, fro=sourcejid, body=text, mtype=mtype, delay=delay, xhtml=xhtml)
self.session.pytrans.serviceplugins['Statistics'].stats['IncomingMessages'] += 1
self.session.pytrans.serviceplugins['Statistics'].sessionUpdate(self.session.jabberID, 'IncomingMessages', 1)
if not config.disableAwayMessage and self.awayMessage and not "auto" in flags:
@@ -306,11 +309,12 @@
else:
show = 'away'

- status = oscar.dehtml(msg[1]) # Removes any HTML tags
+ #status = oscar.dehtml(msg[1]) # Removes any HTML tags
+ status = msg[1]
url = user.url

if status != None:
- charset = "iso-8859-1"
+ charset = config.encoding
m = None
if msg[0]:
m = re.search('charset="(.+)"', msg[0])
@@ -325,9 +329,18 @@
LogEvent(INFO, self.session.jabberID, "Unknown charset (%s) of buddy's away message" % msg[0]);
charset = config.encoding
status = msg[0] + ": " + status
-
- status = status.decode(charset, 'replace')
- LogEvent(INFO, self.session.jabberID, "Away (%s, %s) message %s" % (charset, msg[0], status))
+ if charset == config.encoding:
+ status = ""
+ else:
+ status = status.decode(charset, 'replace')
+ if charset == 'utf-16be':
+ status = status.encode(config.encoding, 'replace')
+ status = oscar.dehtml(status) # Removes any HTML tags
+ try:
+ LogEvent(INFO, self.session.jabberID, "Away (%s, %s) message %s" % (charset, msg[0], status))
+ except:
+ LogEvent(INFO, self.session.jabberID, "Away broken (%s, s) message s" % (charset))
+ pass

if status == "Away" or status=="I am currently away from the computer." or status=="I am away from my computer right now.":
status = ""
diff -Naur src1/main.py src2/main.py
--- src1/main.py 2007-03-30 11:34:45.000000000 +0300
+++ src2/main.py 2007-08-23 14:44:15.000000000 +0300
@@ -89,7 +89,10 @@
import signal
signal.signal(signal.SIGHUP, reloadConfig)
# Load scripts for PID and daemonizing
- from twisted.scripts import twistd
+ try:
+ from twisted.scripts import _twistd_unix as twistd
+ except:
+ from twisted.scripts import twistd

selectWarning = "Unable to install any good reactors (kqueue, cf, epoll, poll).\nWe fell back to using select. You may have scalability problems.\nThis reactor will not support more than 1024 connections +at a time. You may silence this message by choosing 'select' or 'default' as your reactor in the transport config."
if config.reactor and len(config.reactor) > 0:
@@ -137,7 +140,7 @@
import lang
import globals

-
+startTime = int(time.time())

class PyTransport(component.Service):
routewrap = 0
@@ -176,7 +179,7 @@
self.loadPlugins("src/legacy/services")

# Misc tracking variables
- self.startTime = int(time.time())
+# self.startTime = int(time.time())
self.xmlstream = None
self.sessions = {}
# Message IDs
@@ -217,7 +220,7 @@
def loopFunc(self):
numsessions = len(self.sessions)

- self.serviceplugins['Statistics'].stats["Uptime"] = int(time.time()) - self.startTime
+ self.serviceplugins['Statistics'].stats["Uptime"] = int(time.time()) - startTime
if numsessions > 0:
oldDict = self.sessions.copy()
self.sessions = {}
diff -Naur src1/services/LastActivity.py src2/services/LastActivity.py
--- src1/services/LastActivity.py 2007-03-30 11:34:41.000000000 +0300
+++ src2/services/LastActivity.py 2007-07-27 13:32:38.000000000 +0300
@@ -1,7 +1,7 @@
# Copyright 2004-2006 Daniel Henninger <jadestorm@nc.rr.com>
# Licensed for distribution under the GPL version 2, check COPYING for details

-import utils
+import utils, time, main
from twisted.words.xish.domish import Element
import config
from debug import LogEvent, INFO, WARN, ERROR
@@ -29,6 +29,6 @@
iq.attributes["id"] = el.getAttribute("id")
query = iq.addElement("query")
query.attributes["xmlns"] = globals.IQLAST
- query.attributes["seconds"] = "0"
+ query.attributes["seconds"] = str(int(time.time()) - main.startTime)

self.pytrans.send(iq)
diff -Naur src1/services/VersionTeller.py src2/services/VersionTeller.py
--- src1/services/VersionTeller.py 2007-03-30 11:34:41.000000000 +0300
+++ src2/services/VersionTeller.py 2007-08-23 14:50:36.000000000 +0300
@@ -17,7 +17,7 @@
self.pytrans.disco.addFeature(globals.IQVERSION, self.incomingIq, config.jid)
self.pytrans.disco.addFeature(globals.IQVERSION, self.incomingIq, "USER")
try:
- self.version = "%s - SVN r%s" % (legacy.version, svninfo.getSVNVersion())
+ self.version = "%s - SVN r%s + patchcyr-20070823" % (legacy.version, svninfo.getSVNVersion())
except:
self.version = legacy.version
self.os = "Python " + sys.version.split(' ')[0] + "/" + sys.platform + ", Twisted " + twisted.copyright.version
diff -Naur src1/tlib/oscar.py src2/tlib/oscar.py
--- src1/tlib/oscar.py 2007-06-18 16:49:35.000000000 +0300
+++ src2/tlib/oscar.py 2007-08-23 14:40:05.000000000 +0300
@@ -19,6 +19,7 @@

from scheduler import Scheduler

+import config
import struct
import md5
import string
@@ -199,7 +200,7 @@
# in the docutils extension module
# see http://docutils.sourceforge.net
# modified for better use here
-def guess_encoding(data, defaultencoding='iso-8859-1'):
+def guess_encoding(data, defaultencoding=config.encoding):
"""
Given a byte string, attempt to decode it.
Tries 'utf-16be, 'utf-8' and 'iso-8859-1' (or something else) encodings.
@@ -494,7 +495,7 @@
self.firstMessage = v # unix timestamp

def oscarRep(self):
- data = struct.pack(">H", len(self.name)) + self.name
+ data = struct.pack(">H", len(self.name)) + self.name.encode("utf-8")
tlvs = ""
if not self.authorized:
tlvs += TLV(0x0066) # awaiting authorization
@@ -870,7 +871,7 @@
self.connectPort = 5190
# Note that this is "no unicode" default encoding
# We use unicode if it's there
- self.defaultEncoding = 'iso-8859-1'
+ self.defaultEncoding = config.encoding

if not self.capabilities:
self.capabilities = [CAP_CHAT]
@@ -1312,7 +1313,7 @@
if messageLength > 0: multiparts.append(tuple(message))
else:
# Uh... what is this???
- log.msg("unknown message fragment %d %d: %v" % (fragtype, fragver, str(v)))
+ log.msg("unknown message fragment %d %d: %s" % (fragtype, fragver, str(v)))
v = v[4+fraglen:]
elif k == 0x03: # server ack requested
flags.append('acknowledge')
@@ -1641,12 +1642,12 @@
# Offline message
senderuin = struct.unpack('<I',v[10:14])[0]
#print "senderuin: "+str(senderuin)+"\n"
- msg_date = str( "%4d-%02d-%02d %02d:%02d"
- % struct.unpack('<HBBBB', v[14:20]) )
+ msg_date = str( "%4d-%02d-%02dT%02d:%02d:00Z" #XEP-091 date format
+ % struct.unpack('<HBBBB', v[14:20]) )
messagetype, messageflags,messagelen = struct.unpack('<BBH',v[20:24])
umessage, encoding = guess_encoding(v[24:24+messagelen-1],self.defaultEncoding)
log.msg("Converted message, encoding %r: %r" % (encoding, umessage))
- umessage = umessage + "\n\n/sent " + msg_date
+ #umessage = umessage + "\n\n/sent " + msg_date
message = [ umessage.encode("utf-16be"), "unicode" ]
#message = [ str( v[24:24+messagelen-1] )
# + "\n\n/sent " + msg_date ]
@@ -1657,7 +1658,7 @@
tlvs = dict()
multiparts.append(tuple(message))
user = OSCARUser(str(senderuin), None, tlvs)
- self.receiveMessage(user, multiparts, flags)
+ self.receiveMessage(user, multiparts, flags, msg_date)
elif (type == 0x42):
# End of offline messages
reqdata = '\x08\x00'+struct.pack("<I",int(self.username))+'\x3e\x00\x02\x00'
@@ -2022,14 +2023,14 @@
charSet = 0x0000
except:
try:
- part[0] = part[0].encode('iso-8859-1')
+ part[0] = part[0].encode(config.encoding)
charSet = 0x0003
except:
try:
part[0] = part[0].encode('utf-16be', 'replace')
charSet = 0x0002
except:
- part[0] = part[0].encode('iso-8859-1', 'replace')
+ part[0] = part[0].encode(config.encoding, 'replace')
charSet = 0x0003
if 'macintosh' in part[1:]:
charSubSet = 0x000b
@@ -2042,7 +2043,7 @@
# We'll investigate this in more detail later.
features = '\x01\x01\x02'
# Why do i need to encode this? I shouldn't .. it's data.
- data = data.encode('iso-8859-1', 'replace') + TLV(2, TLV(0x0501, features)+messageData)
+ data = data.encode(config.encoding, 'replace') + TLV(2, TLV(0x0501, features)+messageData)
if wantAck:
log.msg("sendMessage: Sending wanting ACK")
data = data + TLV(3)
Powered by Google Project Hosting