annotate libgaim/gaim-url-handler @ 15204:f814b2df9cce

[gaim-migrate @ 17993] Blocking on Google Talk. Our Privacy API sucks so bad that even with no prior support for blocking in Jabber, this has no interface changes. If someone wanted to implement the deprecated Jabber privacy lists API, though, that would be ok by me. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Thu, 14 Dec 2006 04:56:54 +0000
parents 5d71039b20eb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
1 #!/usr/bin/python
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
2
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
3 import dbus
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
4 import re
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
5 import sys
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
6 import time
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
7 import urllib
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
8
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
9 obj = dbus.SessionBus().get_object("net.sf.gaim.GaimService", "/net/sf/gaim/GaimObject")
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
10 gaim = dbus.Interface(obj, "net.sf.gaim.GaimInterface")
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
11
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
12 class CheckedObject:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
13 def __init__(self, obj):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
14 self.obj = obj
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
15
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
16 def __getattr__(self, attr):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
17 return CheckedAttribute(self, attr)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
18
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
19 class CheckedAttribute:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
20 def __init__(self, cobj, attr):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
21 self.cobj = cobj
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
22 self.attr = attr
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
23
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
24 def __call__(self, *args):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
25 result = self.cobj.obj.__getattr__(self.attr)(*args)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
26 if result == 0:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
27 raise "Error: " + self.attr + " " + str(args) + " returned " + str(result)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
28 return result
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
29
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
30 cgaim = CheckedObject(gaim)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
31
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
32 def extendlist(list, length, fill):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
33 if len(list) < length:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
34 return list + [fill] * (length - len(list))
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
35 else:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
36 return list
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
37
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
38 def convert(value):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
39 try:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
40 return int(value)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
41 except:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
42 return value
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
43
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
44 def findaccount(protocolname, accountname=""):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
45 try:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
46 # prefer connected accounts
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
47 account = cgaim.GaimAccountsFindConnected(accountname, protocolname)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
48 return account
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
49 except:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
50 # try to get any account and connect it
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
51 account = cgaim.GaimAccountsFindAny(accountname, protocolname)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
52 gaim.GaimAccountSetStatusVargs(account, "online", 1)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
53 gaim.GaimAccountConnect(account)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
54 return account
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
55
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
56 def goim(account, screenname, message=None):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
57 # XXX: 1 == GAIM_CONV_TYPE_IM
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
58 conversation = cgaim.GaimConversationNew(1, account, screenname)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
59 if message:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
60 gaim.GaimConvSendConfirm(conversation, message)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
61
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
62 def gochat(account, params, message=None):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
63 connection = cgaim.GaimAccountGetConnection(account)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
64 gaim.ServJoinChat(connection, params)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
65
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
66 if message != None:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
67 for i in range(20):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
68 # XXX: 2 == GAIM_CONV_TYPE_CHAT
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
69 conversation = gaim.GaimFindConversationWithAccount(2, params.get("channel", params.get("room")), account)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
70 if conversation:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
71 gaim.GaimConvSendConfirm(conversation, message)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
72 break
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
73 else:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
74 time.sleep(0.5)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
75
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
76 def addbuddy(account, screenname, group="", alias=""):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
77 cgaim.GaimBlistRequestAddBuddy(account, screenname, group, alias)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
78
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
79
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
80 def aim(uri):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
81 protocol = "prpl-oscar"
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
82 match = re.match(r"^(aim|icq):([^?]*)(\?(.*))", uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
83 if not match:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
84 print "Invalid aim URI: %s" % uri
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
85 return
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
86
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
87 command = urllib.unquote_plus(match.group(2))
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
88 paramstring = match.group(4)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
89 params = {}
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
90 if paramstring:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
91 for param in paramstring.split("&"):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
92 key, value = extendlist(param.split("=", 1), 2, "")
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
93 params[key] = urllib.unquote_plus(value)
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
94 accountname = params.get("account", "")
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
95 screenname = params.get("screenname", "")
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
96
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
97 account = findaccount(protocol, accountname)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
98
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
99 if command.lower() == "goim":
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
100 goim(account, screenname, params.get("message"))
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
101 elif command.lower() == "gochat":
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
102 gochat(account, params)
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
103 elif command.lower() == "addbuddy":
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
104 addbuddy(account, screenname, params.get("group", ""))
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
105
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
106 def gg(uri):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
107 protocol = "prpl-gg"
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
108 match = re.match(r"^gg:(.*)", uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
109 if not match:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
110 print "Invalid gg URI: %s" % uri
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
111 return
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
112
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
113 screenname = urllib.unquote_plus(match.group(1))
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
114 account = findaccount(protocol)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
115 goim(account, screenname)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
116
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
117 def icq(uri):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
118 aim(uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
119
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
120 def irc(uri):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
121 protocol = "prpl-irc"
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
122 match = re.match(r"^irc:(//([^/]*)/)?([^?]*)(\?(.*))?", uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
123 if not match:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
124 print "Invalid irc URI: %s" % uri
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
125 return
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
126
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
127 server = urllib.unquote_plus(match.group(2)) or ""
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
128 target = match.group(3) or ""
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
129 query = match.group(5) or ""
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
130
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
131 modifiers = {}
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
132 if target:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
133 for modifier in target.split(",")[1:]:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
134 modifiers[modifier] = True
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
135
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
136 isnick = modifiers.has_key("isnick")
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
137
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
138 paramstring = match.group(5)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
139 params = {}
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
140 if paramstring:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
141 for param in paramstring.split("&"):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
142 key, value = extendlist(param.split("=", 1), 2, "")
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
143 params[key] = urllib.unquote_plus(value)
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
144
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
145 account = findaccount(protocol)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
146
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
147 if (target != ""):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
148 if (isnick):
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
149 goim(account, urllib.unquote_plus(target.split(",")[0]), params.get("msg"))
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
150 else:
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
151 channel = urllib.unquote_plus(target.split(",")[0])
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
152 if channel[0] != "#":
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
153 channel = "#" + channel
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
154 gochat(account, {"server": server, "channel": channel, "password": params.get("key", "")}, params.get("msg"))
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
155
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
156 def msnim(uri):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
157 protocol = "prpl-msn"
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
158 match = re.match(r"^msnim:([^?]*)(\?(.*))", uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
159 if not match:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
160 print "Invalid msnim URI: %s" % uri
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
161 return
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
162
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
163 command = urllib.unquote_plus(match.group(1))
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
164 paramstring = match.group(3)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
165 params = {}
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
166 if paramstring:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
167 for param in paramstring.split("&"):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
168 key, value = extendlist(param.split("=", 1), 2, "")
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
169 params[key] = urllib.unquote_plus(value)
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
170 screenname = params.get("contact", "")
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
171
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
172 account = findaccount(protocol)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
173
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
174 if command.lower() == "chat":
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
175 goim(account, screenname)
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
176 elif command.lower() == "add":
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
177 addbuddy(account, screenname)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
178
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
179 def sip(uri):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
180 protocol = "prpl-simple"
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
181 match = re.match(r"^sip:(.*)", uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
182 if not match:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
183 print "Invalid sip URI: %s" % uri
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
184 return
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
185
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
186 screenname = urllib.unquote_plus(match.group(1))
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
187 account = findaccount(protocol)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
188 goim(account, screenname)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
189
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
190 def xmpp(uri):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
191 protocol = "prpl-jabber"
14995
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
192 match = re.match(r"^xmpp:((//)?([^/?#]*))?(/?([^?#]*))(\?([^;#]*)(;([^#]*))?)?(#(.*))?", uri)
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
193 if not match:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
194 print "Invalid xmpp URI: %s" % uri
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
195 return
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
196
14995
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
197 tmp = match.group(3)
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
198 if (tmp):
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
199 accountname = urllib.unquote_plus(tmp)
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
200 else:
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
201 accountname = ""
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
202
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
203 screenname = urllib.unquote_plus(match.group(5))
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
204
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
205 tmp = match.group(7)
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
206 if (tmp):
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
207 command = urllib.unquote_plus(tmp)
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
208 else:
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
209 command = ""
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
210
5d71039b20eb [gaim-migrate @ 17773]
Richard Laager <rlaager@wiktel.com>
parents: 14539
diff changeset
211 paramstring = match.group(9)
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
212 params = {}
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
213 if paramstring:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
214 for param in paramstring.split(";"):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
215 key, value = extendlist(param.split("=", 1), 2, "")
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
216 params[key] = urllib.unquote_plus(value)
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
217
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
218 account = findaccount(protocol, accountname)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
219
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
220 if command.lower() == "message":
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
221 goim(account, screenname, params.get("body"))
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
222 elif command.lower() == "join":
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
223 room, server = screenname.split("@")
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
224 gochat(account, {"room": room, "server": server})
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
225 elif command.lower() == "roster":
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
226 addbuddy(account, screenname, params.get("group", ""), params.get("name", ""))
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
227 else:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
228 goim(account, screenname)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
229
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
230 def ymsgr(uri):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
231 protocol = "prpl-yahoo"
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
232 match = re.match(r"^ymsgr:([^?]*)(\?([^&]*)(&(.*))?)", uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
233 if not match:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
234 print "Invalid ymsgr URI: %s" % uri
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
235 return
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
236
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
237 command = urllib.unquote_plus(match.group(1))
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
238 screenname = urllib.unquote_plus(match.group(3))
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
239 paramstring = match.group(5)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
240 params = {}
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
241 if paramstring:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
242 for param in paramstring.split("&"):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
243 key, value = extendlist(param.split("=", 1), 2, "")
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
244 params[key] = urllib.unquote_plus(value)
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
245
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
246 account = findaccount(protocol)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
247
14539
b007392d72ff [gaim-migrate @ 17260]
Richard Laager <rlaager@wiktel.com>
parents: 14535
diff changeset
248 if command.lower() == "sendim":
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
249 goim(account, screenname, params.get("m"))
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
250 elif command.lower() == "chat":
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
251 gochat(account, {"room": screenname})
14535
e3a640372b6e [gaim-migrate @ 17256]
Richard Laager <rlaager@wiktel.com>
parents: 14520
diff changeset
252 elif command.lower() == "addfriend":
14520
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
253 addbuddy(account, screenname)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
254
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
255
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
256 def main(argv=sys.argv):
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
257 if len(argv) != 2:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
258 print "Usage: %s URI" % argv[0]
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
259 print "Example: %s \"xmpp:romeo@montague.net?message\"" % argv[0]
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
260 return
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
261
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
262 uri = argv[1]
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
263 type = uri.split(":")[0]
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
264
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
265 if type == "aim":
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
266 aim(uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
267 elif type == "gg":
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
268 gg(uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
269 elif type == "icq":
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
270 icq(uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
271 elif type == "irc":
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
272 irc(uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
273 elif type == "msnim":
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
274 msnim(uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
275 elif type == "sip":
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
276 sip(uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
277 elif type == "xmpp":
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
278 xmpp(uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
279 elif type == "ymsgr":
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
280 ymsgr(uri)
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
281 else:
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
282 print "Unkown protocol: %s" % type
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
283
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
284 if __name__ == "__main__":
82b59abcaee4 [gaim-migrate @ 17240]
Richard Laager <rlaager@wiktel.com>
parents:
diff changeset
285 main()