Sat, 20 Aug 2016 11:36:31 +0100
Fix xmpp:jid?join URIs in purple-uri-handler.
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
1 | #!/usr/bin/env python |
|
37440
23aa214a723e
Import the print function to make
Daniël van Eeden <hg@myname.nl>
parents:
37439
diff
changeset
|
2 | from __future__ import print_function |
| 14582 | 3 | import dbus |
| 4 | import re | |
| 5 | import sys | |
| 6 | import time | |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
7 | try: |
|
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
8 | from urllib.parse import unquote_plus |
|
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
9 | except ImportError: |
|
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
10 | from urllib import unquote_plus |
| 14582 | 11 | |
|
23562
312323547538
Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents:
23237
diff
changeset
|
12 | bus = dbus.SessionBus() |
|
312323547538
Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents:
23237
diff
changeset
|
13 | obj = None |
|
312323547538
Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents:
23237
diff
changeset
|
14 | try: |
|
312323547538
Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents:
23237
diff
changeset
|
15 | obj = bus.get_object("im.pidgin.purple.PurpleService", |
|
312323547538
Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents:
23237
diff
changeset
|
16 | "/im/pidgin/purple/PurpleObject") |
|
37438
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
17 | except dbus.DBusException as e: |
|
23562
312323547538
Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents:
23237
diff
changeset
|
18 | if e._dbus_error_name == "org.freedesktop.DBus.Error.ServiceUnknown": |
|
37438
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
19 | print("Error: no libpurple-powered client is running. Try starting Pidgin or Finch.") |
|
23562
312323547538
Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents:
23237
diff
changeset
|
20 | sys.exit(1) |
|
16205
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
21 | purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface") |
| 14582 | 22 | |
| 23 | class CheckedObject: | |
| 24 | def __init__(self, obj): | |
| 25 | self.obj = obj | |
| 26 | ||
| 27 | def __getattr__(self, attr): | |
| 28 | return CheckedAttribute(self, attr) | |
| 29 | ||
| 30 | class CheckedAttribute: | |
| 31 | def __init__(self, cobj, attr): | |
| 32 | self.cobj = cobj | |
| 33 | self.attr = attr | |
| 34 | ||
| 35 | def __call__(self, *args): | |
|
16207
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
36 | # Redirect stderr to suppress the printing of an " Introspect error" |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
37 | # message if nothing is listening on the bus. We print a friendly |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
38 | # error message ourselves. |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
39 | real_stderr = sys.stderr |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
40 | sys.stderr = None |
| 14582 | 41 | result = self.cobj.obj.__getattr__(self.attr)(*args) |
|
16207
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
42 | sys.stderr = real_stderr |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
43 | |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
44 | # This can be useful for debugging. |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
45 | # if (result == 0): |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
46 | # print "Error: " + self.attr + " " + str(args) + " returned " + str(result) |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
47 | |
| 14582 | 48 | return result |
| 49 | ||
|
16205
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
50 | cpurple = CheckedObject(purple) |
| 14582 | 51 | |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
52 | def extendlist(list, length, fill): |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
53 | if len(list) < length: |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
54 | return list + [fill] * (length - len(list)) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
55 | else: |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
56 | return list |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
57 | |
| 14582 | 58 | def convert(value): |
| 59 | try: | |
| 60 | return int(value) | |
| 61 | except: | |
| 62 | return value | |
| 63 | ||
|
23563
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
64 | def account_not_found(): |
|
37438
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
65 | print("No matching account found.") |
|
23563
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
66 | sys.exit(1) |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
67 | |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
68 | def bring_account_online(account): |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
69 | if not cpurple.PurpleAccountIsConnected(account): |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
70 | # The last argument is meant to be a GList * but the D-Bus binding |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
71 | # generator thing just wants a UInt32, which is pretty failing. |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
72 | # Happily, passing a 0 to mean an empty list turns out to work anyway. |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
73 | purple.PurpleAccountSetStatusList(account, "online", 1, 0) |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
74 | purple.PurpleAccountConnect(account) |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
75 | |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
76 | def findaccount(protocolname, accountname="", matcher=None): |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
77 | if matcher: |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
78 | for account in cpurple.PurpleAccountsGetAll(): |
|
31582
c561e11657b0
Fix some issues with purple-url-handler.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30530
diff
changeset
|
79 | if (protocolname != cpurple.PurpleAccountGetProtocolId(account)) or \ |
|
30530
8f5fecc9b6c8
Some fixes to IRC handling in purple-url-handler, mainly to fix
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
26065
diff
changeset
|
80 | (accountname != "" and accountname != cpurple.PurpleAccountGetUsername(account)): |
|
23563
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
81 | continue |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
82 | if matcher(account): |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
83 | bring_account_online(account) |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
84 | return account |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
85 | account_not_found() |
|
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
86 | |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
87 | # prefer connected accounts |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
88 | account = cpurple.PurpleAccountsFindConnected(accountname, protocolname) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
89 | if (account != 0): |
|
23563
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
90 | return account |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
91 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
92 | # try to get any account and connect it |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
93 | account = cpurple.PurpleAccountsFindAny(accountname, protocolname) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
94 | if (account == 0): |
|
23563
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
95 | account_not_found() |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
96 | |
|
23563
04877760aaf1
Give findaccount an option 'matcher' callback parameter, to match arbitrary
Will Thompson <resiak@pidgin.im>
parents:
23562
diff
changeset
|
97 | bring_account_online(account) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
98 | return account |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
99 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
100 | def goim(account, screenname, message=None): |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
101 | # XXX: 1 == PURPLE_CONV_TYPE_IM |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
102 | conversation = cpurple.PurpleConversationNew(1, account, screenname) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
103 | if message: |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
104 | purple.PurpleConvSendConfirm(conversation, message) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
105 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
106 | def gochat(account, params, message=None): |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
107 | connection = cpurple.PurpleAccountGetConnection(account) |
|
37900
07caaa17a5a6
Fix xmpp:jid?join URIs in purple-uri-handler.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
37441
diff
changeset
|
108 | purple.PurpleServJoinChat(connection, params) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
109 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
110 | if message != None: |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
111 | for i in range(20): |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
112 | # XXX: 2 == PURPLE_CONV_TYPE_CHAT |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
113 | conversation = purple.PurpleFindConversationWithAccount(2, params.get("channel", params.get("room")), account) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
114 | if conversation: |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
115 | purple.PurpleConvSendConfirm(conversation, message) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
116 | break |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
117 | else: |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
118 | time.sleep(0.5) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
119 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
120 | def addbuddy(account, screenname, group="", alias=""): |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
121 | cpurple.PurpleBlistRequestAddBuddy(account, screenname, group, alias) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
122 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
123 | |
| 14582 | 124 | def aim(uri): |
|
16205
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
125 | protocol = "prpl-aim" |
| 16502 | 126 | match = re.match(r"^aim:([^?]*)(\?(.*))", uri) |
| 14582 | 127 | if not match: |
|
37438
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
128 | print("Invalid aim URI: %s" % uri) |
| 14582 | 129 | return |
| 130 | ||
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
131 | command = unquote_plus(match.group(1)) |
| 16502 | 132 | paramstring = match.group(3) |
| 14582 | 133 | params = {} |
| 134 | if paramstring: | |
| 135 | for param in paramstring.split("&"): | |
| 136 | key, value = extendlist(param.split("=", 1), 2, "") | |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
137 | params[key] = unquote_plus(value) |
| 14582 | 138 | accountname = params.get("account", "") |
| 139 | screenname = params.get("screenname", "") | |
| 140 | ||
| 141 | account = findaccount(protocol, accountname) | |
| 142 | ||
|
14597
f6b179d6babb
[gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents:
14582
diff
changeset
|
143 | if command.lower() == "goim": |
| 14582 | 144 | goim(account, screenname, params.get("message")) |
|
14597
f6b179d6babb
[gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents:
14582
diff
changeset
|
145 | elif command.lower() == "gochat": |
| 14582 | 146 | gochat(account, params) |
|
14597
f6b179d6babb
[gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents:
14582
diff
changeset
|
147 | elif command.lower() == "addbuddy": |
| 14582 | 148 | addbuddy(account, screenname, params.get("group", "")) |
| 149 | ||
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
150 | def gg(uri): |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
151 | protocol = "prpl-gg" |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
152 | match = re.match(r"^gg:(.*)", uri) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
153 | if not match: |
|
37438
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
154 | print("Invalid gg URI: %s" % uri) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
155 | return |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
156 | |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
157 | screenname = unquote_plus(match.group(1)) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
158 | account = findaccount(protocol) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
159 | goim(account, screenname) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
160 | |
| 14582 | 161 | def icq(uri): |
|
16205
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
162 | protocol = "prpl-icq" |
| 16502 | 163 | match = re.match(r"^icq:([^?]*)(\?(.*))", uri) |
|
16205
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
164 | if not match: |
|
37438
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
165 | print("Invalid icq URI: %s" % uri) |
|
16205
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
166 | return |
|
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
167 | |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
168 | command = unquote_plus(match.group(1)) |
| 16502 | 169 | paramstring = match.group(3) |
|
16205
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
170 | params = {} |
|
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
171 | if paramstring: |
|
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
172 | for param in paramstring.split("&"): |
|
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
173 | key, value = extendlist(param.split("=", 1), 2, "") |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
174 | params[key] = unquote_plus(value) |
|
16205
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
175 | accountname = params.get("account", "") |
|
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
176 | screenname = params.get("screenname", "") |
|
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
177 | |
|
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
178 | account = findaccount(protocol, accountname) |
|
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
179 | |
|
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
180 | if command.lower() == "goim": |
|
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
181 | goim(account, screenname, params.get("message")) |
|
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
182 | elif command.lower() == "gochat": |
|
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
183 | gochat(account, params) |
|
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
184 | elif command.lower() == "addbuddy": |
|
397be242f4a4
Trac Ticket #149 from JensenDied
Richard Laager <rlaager@pidgin.im>
parents:
15987
diff
changeset
|
185 | addbuddy(account, screenname, params.get("group", "")) |
| 14582 | 186 | |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
187 | def irc(uri): |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
188 | protocol = "prpl-irc" |
|
30530
8f5fecc9b6c8
Some fixes to IRC handling in purple-url-handler, mainly to fix
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
26065
diff
changeset
|
189 | match = re.match(r"^irc:(//([^/]*))?/?([^?]*)(\?(.*))?", uri) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
190 | if not match: |
|
37438
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
191 | print("Invalid irc URI: %s" % uri) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
192 | return |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
193 | |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
194 | server = unquote_plus(match.group(2) or "") |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
195 | target = match.group(3) or "" |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
196 | query = match.group(5) or "" |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
197 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
198 | modifiers = {} |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
199 | if target: |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
200 | for modifier in target.split(",")[1:]: |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
201 | modifiers[modifier] = True |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
202 | |
|
37441
2f8eb8108b63
Make irc work with Python3
Daniël van Eeden <hg@myname.nl>
parents:
37440
diff
changeset
|
203 | isnick = True if "isnick" in modifiers else False |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
204 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
205 | paramstring = match.group(5) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
206 | params = {} |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
207 | if paramstring: |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
208 | for param in paramstring.split("&"): |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
209 | key, value = extendlist(param.split("=", 1), 2, "") |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
210 | params[key] = unquote_plus(value) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
211 | |
|
23564
9ccc8c1ddc6b
Make irc:// URLs use an account on the right server, not just the first IRC
Will Thompson <resiak@pidgin.im>
parents:
23563
diff
changeset
|
212 | def correct_server(account): |
|
9ccc8c1ddc6b
Make irc:// URLs use an account on the right server, not just the first IRC
Will Thompson <resiak@pidgin.im>
parents:
23563
diff
changeset
|
213 | username = cpurple.PurpleAccountGetUsername(account) |
|
30530
8f5fecc9b6c8
Some fixes to IRC handling in purple-url-handler, mainly to fix
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
26065
diff
changeset
|
214 | return ((server == "") or ("@" in username) and (server == (username.split("@"))[1])) |
|
23564
9ccc8c1ddc6b
Make irc:// URLs use an account on the right server, not just the first IRC
Will Thompson <resiak@pidgin.im>
parents:
23563
diff
changeset
|
215 | |
|
9ccc8c1ddc6b
Make irc:// URLs use an account on the right server, not just the first IRC
Will Thompson <resiak@pidgin.im>
parents:
23563
diff
changeset
|
216 | account = findaccount(protocol, matcher=correct_server) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
217 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
218 | if (target != ""): |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
219 | if (isnick): |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
220 | goim(account, unquote_plus(target.split(",")[0]), params.get("msg")) |
|
23564
9ccc8c1ddc6b
Make irc:// URLs use an account on the right server, not just the first IRC
Will Thompson <resiak@pidgin.im>
parents:
23563
diff
changeset
|
221 | else: |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
222 | channel = unquote_plus(target.split(",")[0]) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
223 | if channel[0] != "#": |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
224 | channel = "#" + channel |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
225 | gochat(account, {"server": server, "channel": channel, "password": params.get("key", "")}, params.get("msg")) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
226 | |
| 14582 | 227 | def msnim(uri): |
| 228 | protocol = "prpl-msn" | |
| 229 | match = re.match(r"^msnim:([^?]*)(\?(.*))", uri) | |
| 230 | if not match: | |
|
37438
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
231 | print("Invalid msnim URI: %s" % uri) |
| 14582 | 232 | return |
| 233 | ||
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
234 | command = unquote_plus(match.group(1)) |
| 14582 | 235 | paramstring = match.group(3) |
| 236 | params = {} | |
| 237 | if paramstring: | |
| 238 | for param in paramstring.split("&"): | |
| 239 | key, value = extendlist(param.split("=", 1), 2, "") | |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
240 | params[key] = unquote_plus(value) |
| 14582 | 241 | screenname = params.get("contact", "") |
| 242 | ||
| 243 | account = findaccount(protocol) | |
| 244 | ||
|
14597
f6b179d6babb
[gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents:
14582
diff
changeset
|
245 | if command.lower() == "chat": |
| 14582 | 246 | goim(account, screenname) |
|
14597
f6b179d6babb
[gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents:
14582
diff
changeset
|
247 | elif command.lower() == "add": |
| 14582 | 248 | addbuddy(account, screenname) |
| 249 | ||
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
250 | def sip(uri): |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
251 | protocol = "prpl-simple" |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
252 | match = re.match(r"^sip:(.*)", uri) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
253 | if not match: |
|
37438
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
254 | print("Invalid sip URI: %s" % uri) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
255 | return |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
256 | |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
257 | screenname = unquote_plus(match.group(1)) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
258 | account = findaccount(protocol) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
259 | goim(account, screenname) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
260 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
261 | def xmpp(uri): |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
262 | protocol = "prpl-jabber" |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
263 | match = re.match(r"^xmpp:(//([^/?#]*)/?)?([^?#]*)(\?([^;#]*)(;([^#]*))?)?(#(.*))?", uri) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
264 | if not match: |
|
37438
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
265 | print("Invalid xmpp URI: %s" % uri) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
266 | return |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
267 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
268 | tmp = match.group(2) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
269 | if (tmp): |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
270 | accountname = unquote_plus(tmp) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
271 | else: |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
272 | accountname = "" |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
273 | |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
274 | screenname = unquote_plus(match.group(3)) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
275 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
276 | tmp = match.group(5) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
277 | if (tmp): |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
278 | command = unquote_plus(tmp) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
279 | else: |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
280 | command = "" |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
281 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
282 | paramstring = match.group(7) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
283 | params = {} |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
284 | if paramstring: |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
285 | for param in paramstring.split(";"): |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
286 | key, value = extendlist(param.split("=", 1), 2, "") |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
287 | params[key] = unquote_plus(value) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
288 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
289 | account = findaccount(protocol, accountname) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
290 | |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
291 | if command.lower() == "message": |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
292 | goim(account, screenname, params.get("body")) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
293 | elif command.lower() == "join": |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
294 | room, server = screenname.split("@") |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
295 | gochat(account, {"room": room, "server": server}) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
296 | elif command.lower() == "roster": |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
297 | addbuddy(account, screenname, params.get("group", ""), params.get("name", "")) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
298 | else: |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
299 | goim(account, screenname) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
300 | |
|
25327
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
301 | def gtalk(uri): |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
302 | protocol = "prpl-jabber" |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
303 | match = re.match(r"^gtalk:([^?]*)(\?(.*))", uri) |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
304 | if not match: |
|
37438
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
305 | print("Invalid gtalk URI: %s" % uri) |
|
25327
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
306 | return |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
307 | |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
308 | command = unquote_plus(match.group(1)) |
|
25327
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
309 | paramstring = match.group(3) |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
310 | params = {} |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
311 | if paramstring: |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
312 | for param in paramstring.split("&"): |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
313 | key, value = extendlist(param.split("=", 1), 2, "") |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
314 | params[key] = unquote_plus(value) |
|
25327
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
315 | accountname = params.get("from_jid", "") |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
316 | jid = params.get("jid", "") |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
317 | |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
318 | account = findaccount(protocol, accountname) |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
319 | |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
320 | if command.lower() == "chat": |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
321 | goim(account, jid) |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
322 | elif command.lower() == "call": |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
323 | # XXX V&V prompt to establish call |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
324 | goim(account, jid) |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
325 | |
| 14582 | 326 | def ymsgr(uri): |
| 327 | protocol = "prpl-yahoo" | |
| 328 | match = re.match(r"^ymsgr:([^?]*)(\?([^&]*)(&(.*))?)", uri) | |
| 329 | if not match: | |
|
37438
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
330 | print("Invalid ymsgr URI: %s" % uri) |
| 14582 | 331 | return |
| 332 | ||
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
333 | command = unquote_plus(match.group(1)) |
|
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
334 | screenname = unquote_plus(match.group(3)) |
| 14582 | 335 | paramstring = match.group(5) |
| 336 | params = {} | |
| 337 | if paramstring: | |
| 338 | for param in paramstring.split("&"): | |
| 339 | key, value = extendlist(param.split("=", 1), 2, "") | |
|
37439
a6f8c7cbdb24
Ensure backwards compatibility with Python 2
Daniël van Eeden <hg@myname.nl>
parents:
37438
diff
changeset
|
340 | params[key] = unquote_plus(value) |
| 14582 | 341 | |
| 342 | account = findaccount(protocol) | |
| 343 | ||
|
14601
8aa717885b14
[gaim-migrate @ 17260]
Richard Laager <rlaager@pidgin.im>
parents:
14597
diff
changeset
|
344 | if command.lower() == "sendim": |
| 14582 | 345 | goim(account, screenname, params.get("m")) |
|
14597
f6b179d6babb
[gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents:
14582
diff
changeset
|
346 | elif command.lower() == "chat": |
| 14582 | 347 | gochat(account, {"room": screenname}) |
|
14597
f6b179d6babb
[gaim-migrate @ 17256]
Richard Laager <rlaager@pidgin.im>
parents:
14582
diff
changeset
|
348 | elif command.lower() == "addfriend": |
| 14582 | 349 | addbuddy(account, screenname) |
| 350 | ||
| 351 | ||
| 352 | def main(argv=sys.argv): | |
|
23237
7ec42e06496f
Import a patch (with changes) from Debian:
Ari Pollak <ari@debian.org>
parents:
22141
diff
changeset
|
353 | if len(argv) != 2 or argv[1] == "--help" or argv[1] == "-h": |
|
37438
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
354 | print("Usage: %s URI" % argv[0]) |
|
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
355 | print("Example: %s \"xmpp:romeo@montague.net?message\"" % argv[0]) |
|
23237
7ec42e06496f
Import a patch (with changes) from Debian:
Ari Pollak <ari@debian.org>
parents:
22141
diff
changeset
|
356 | |
|
7ec42e06496f
Import a patch (with changes) from Debian:
Ari Pollak <ari@debian.org>
parents:
22141
diff
changeset
|
357 | if len(argv) != 2: |
|
7ec42e06496f
Import a patch (with changes) from Debian:
Ari Pollak <ari@debian.org>
parents:
22141
diff
changeset
|
358 | sys.exit(1) |
|
7ec42e06496f
Import a patch (with changes) from Debian:
Ari Pollak <ari@debian.org>
parents:
22141
diff
changeset
|
359 | else: |
|
7ec42e06496f
Import a patch (with changes) from Debian:
Ari Pollak <ari@debian.org>
parents:
22141
diff
changeset
|
360 | return 0 |
| 14582 | 361 | |
| 362 | uri = argv[1] | |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
363 | type = uri.split(":")[0] |
| 14582 | 364 | |
|
16207
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
365 | try: |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
366 | if type == "aim": |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
367 | aim(uri) |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
368 | elif type == "gg": |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
369 | gg(uri) |
|
16207
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
370 | elif type == "icq": |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
371 | icq(uri) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
372 | elif type == "irc": |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
373 | irc(uri) |
|
16207
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
374 | elif type == "msnim": |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
375 | msnim(uri) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
376 | elif type == "sip": |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
377 | sip(uri) |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
378 | elif type == "xmpp": |
|
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
379 | xmpp(uri) |
|
25327
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
380 | elif type == "gtalk": |
|
f24162b33a66
Extend purple-url-handler to handle "gtalk" URIs. Fixes #7889
Paul Aurich <darkrain42@pidgin.im>
parents:
23565
diff
changeset
|
381 | gtalk(uri) |
|
16207
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
382 | elif type == "ymsgr": |
|
b4b168c28673
Print decent error messages instead of stack traces if there's a problem.
Richard Laager <rlaager@pidgin.im>
parents:
16205
diff
changeset
|
383 | ymsgr(uri) |
|
17323
f92574b24329
Restore the protocol specific URL handlers in purple-url-handler for those
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17145
diff
changeset
|
384 | else: |
|
37438
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
385 | print("Unknown protocol: %s" % type) |
|
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
386 | except dbus.DBusException as e: |
|
0a113082ec3a
Make purlpe-url-handler work with Python 3
Daniël van Eeden <hg@myname.nl>
parents:
37115
diff
changeset
|
387 | print("Error: %s" % e.message) |
|
23562
312323547538
Handle D-Bus errors more helpfully in purple-url-handler.
Will Thompson <resiak@pidgin.im>
parents:
23237
diff
changeset
|
388 | sys.exit(1) |
| 14582 | 389 | |
| 390 | if __name__ == "__main__": | |
| 391 | main() |