-
Notifications
You must be signed in to change notification settings - Fork 1
/
yahoo_helpers.py
95 lines (89 loc) · 3.06 KB
/
yahoo_helpers.py
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
# Yahoo Definitions
import struct
#Packet Types
Y_online = 1 # User online
Y_offline = 2 # User offline
Y_away = 3 # Friend Away
Y_available = 4 # Friend Available
Y_msg = 6 # Instant Message
Y_setaway = 7 # User Away
Y_status = 10 # Friend Status
Y_mail = 11 # Mail
Y_calendar = 13 # A calendar event
Y_roster = 15 # Friend List Change
Y_ping2 = 18 # Secondary Ping
Y_imvset = 21 # IMVironment Setting
Y_invfail = 23 # Invite Failed
Y_confinv = 24 # Conference Invite
Y_confacc = 25 # Conference Accept
Y_conftxt = 26 # Conference Text
Y_confmsg = 27 # Conference Message
Y_confon = 30 # Conference User Online
Y_confoff = 31 # Conference User Offline
Y_confpm = 32 # Conference Instant Message
Y_fileup = 70 # File Transfer Upload
Y_voiceinv = 74 # Voice Chat Invite
Y_notify = 75 # Notification
Y_init = 76 # Initiation
Y_feature = 77 # Extra features
Y_challenge = 84 # Challenge Packet
Y_login = 85 # Login
Y_chalreq = 87 # Challenge Request Packet
Y_rosteradd = 131 # Add Friend
Y_rosterdel = 132 # Remove Friend
Y_ignore = 133 # Ignore
Y_reqroom = 150 # Request Room
Y_gotoroom = 151 # Goto Room
Y_joinroom = 152 # Join Room
Y_leaveroom = 155 # Leave Room
Y_inviteroom = 157 # Invite Room
Y_chatlogout = 160 # Logout
Y_ping = 161 # Primary Ping
Y_chtmsg = 168 # Chat Message
Y_avatar = 188 # Avatar Image update
Y_statusupdate = 198 # update of status (like away/back etc)
Y_advstatusupdate = 199 # update of advanced status (like avatar etc)
Y_changegroup = 231 # Protocol 15: change buddy group
Y_statusupdate15 = 240 # Protocol 15: status update (away/back, etc.)
Y_buddylist15 = 241 # Protocol 15: buddy list (groups, friends, blocked contacts)
YB_type = 300
YBT_group = 318
YBT_buddy = 319
YBT_blocked = 320
YB_groupname = 65
YB_buddyname = 7
YB_status = 10
YB_statusmessage = 19
YB_cloud = 241 # missing/0 = Yahoo!, 1 = LCS/OCS, 2 = MSN/WLM, 9 = IBM/Sametime, 100 = Yahoo! Pingbox
Yahoosep = '\xc0\x80'
def ymsg_mkhdr(version, length, packettype, status, sessionid):
# Make 20 byte yahoo header
return struct.pack("!4slhhll", "YMSG", version, length, packettype, status, sessionid)
def ymsg_dehdr(text):
# Unpack yahoo header into list
return [struct.unpack("!4slhhll", text[0:20]),text[20:]]
def ymsg_deargu(text):
# Unpack arguments into dict
list = text.split(Yahoosep)
d = {0:{}}
count = 0
while list:
try:
n = int(list.pop(0))
except:
pass
if list:
if d[count].has_key(n):
## if type(d[n]) != type([]):
## d[n] = [d[n]]
## d[n].append(list.pop(0))
count = count + 1
d[count]={}
d[count][n]=list.pop(0)
return d
def ymsg_mkargu(dict):
# Turn dict into Yahoo Argument string.
s=''
for each in dict.keys():
s=s+'%d%s%s%s' %(each,Yahoosep,dict[each],Yahoosep)
return s