summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/connection.py6
-rw-r--r--src/core.py12
-rw-r--r--src/multiuserchat.py12
-rw-r--r--src/tabs.py16
4 files changed, 32 insertions, 14 deletions
diff --git a/src/connection.py b/src/connection.py
index 30e0b552..b712004b 100644
--- a/src/connection.py
+++ b/src/connection.py
@@ -21,6 +21,7 @@ import sleekxmpp
from config import config, options
from logger import logger
import common
+from common import safeJID
class Connection(sleekxmpp.ClientXMPP):
"""
@@ -40,8 +41,11 @@ class Connection(sleekxmpp.ClientXMPP):
password = config.get('password', '') or getpass.getpass()
else: # anonymous auth
self.anon = True
- jid = '%s/%s' % (config.get('server', 'anon.louiz.org'), resource)
+ jid = config.get('server', 'anon.louiz.org')
+ if resource:
+ jid = '%s/%s' % (jid, resource)
password = None
+ jid = safeJID(jid)
sleekxmpp.ClientXMPP.__init__(self, jid, password)
self.core = None
self.auto_reconnect = True if config.get('auto_reconnect', 'false').lower() in ('true', '1') else False
diff --git a/src/core.py b/src/core.py
index 519e82a3..5ed1cd17 100644
--- a/src/core.py
+++ b/src/core.py
@@ -826,7 +826,7 @@ class Core(object):
Disable private tabs when leaving a room
"""
for tab in self.tabs:
- if tab.get_name().startswith(room_name) and isinstance(tab, tabs.PrivateTab):
+ if isinstance(tab, tabs.PrivateTab) and tab.get_name().startswith(room_name):
tab.deactivate(reason=reason)
def enable_private_tabs(self, room_name, reason='\x195}You joined the chatroom\x193}'):
@@ -1909,8 +1909,8 @@ class Core(object):
if len(args) < 2:
return
reason = args[2] if len(args) > 2 else ''
- to = args[0]
- room = args[1]
+ to = safeJID(args[0])
+ room = safeJID(args[1])
self.xmpp.plugin['xep_0045'].invite(room, to, reason)
def completion_invite(self, the_input):
@@ -2058,8 +2058,10 @@ class Core(object):
if len(args) < 1:
self.command_help('message')
return
- jid = args[0]
- tab = self.open_conversation_window(jid, focus=True)
+ jid = safeJID(args[0])
+ if not jid.user and not jid.domain and not jid.resource:
+ return self.information('Invalid JID.', 'Error')
+ tab = self.open_conversation_window(jid.full, focus=True)
if len(args) > 1:
tab.command_say(args[1])
diff --git a/src/multiuserchat.py b/src/multiuserchat.py
index 53bf4987..273a8dea 100644
--- a/src/multiuserchat.py
+++ b/src/multiuserchat.py
@@ -13,6 +13,7 @@ sleek plugin
from xml.etree import cElementTree as ET
+from common import safeJID
import logging
log = logging.getLogger(__name__)
@@ -22,18 +23,21 @@ def send_private_message(xmpp, jid, line):
"""
Send a private message
"""
+ jid = safeJID(jid)
xmpp.send_message(mto=jid, mbody=line, mtype='chat')
def send_groupchat_message(xmpp, jid, line):
"""
Send a message to the groupchat
"""
+ jid = safeJID(jid)
xmpp.send_message(mto=jid, mbody=line, mtype='groupchat')
def change_show(xmpp, jid, own_nick, show, status):
"""
Change our 'Show'
"""
+ jid = safeJID(jid)
pres = xmpp.make_presence(pto='%s/%s' % (jid, own_nick))
if show: # if show is None, don't put a <show /> tag. It means "available"
pres['type'] = show
@@ -45,6 +49,7 @@ def change_subject(xmpp, jid, subject):
"""
Change the room subject
"""
+ jid = safeJID(jid)
msg = xmpp.make_message(jid)
msg['type'] = 'groupchat'
msg['subject'] = subject
@@ -54,9 +59,10 @@ def change_nick(xmpp, jid, nick, status=None, show=None):
"""
Change our own nick in a room
"""
- xmpp.make_presence(pshow=show, pstatus=status, pto='%s/%s' % (jid, nick)).send()
+ xmpp.make_presence(pshow=show, pstatus=status, pto=safeJID('%s/%s' % (jid, nick))).send()
def join_groupchat(xmpp, jid, nick, passwd='', maxhistory=None, status=None, show=None, seconds=0):
+ jid = safeJID(jid)
if not seconds:
xmpp.plugin['xep_0045'].joinMUC(jid, nick, maxhistory=maxhistory, password=passwd, pstatus=status, pshow=show)
else:
@@ -79,6 +85,7 @@ def leave_groupchat(xmpp, jid, own_nick, msg):
"""
Leave the groupchat
"""
+ jid = safeJID(jid)
try:
xmpp.plugin['xep_0045'].leaveMUC(jid, own_nick, msg)
except KeyError:
@@ -89,6 +96,7 @@ def set_user_role(xmpp, jid, nick, reason, role):
(try to) Set the role of a MUC user
(role = 'none': eject user)
"""
+ jid = safeJID(jid)
iq = xmpp.makeIqSet()
query = ET.Element('{%s}query' % NS_MUC_ADMIN)
item = ET.Element('{%s}item' % NS_MUC_ADMIN, {'nick':nick, 'role':role})
@@ -108,6 +116,8 @@ def set_user_affiliation(xmpp, muc_jid, affiliation, nick=None, jid=None, reason
"""
(try to) Set the affiliation of a MUC user
"""
+ jid = safeJID(jid)
+ muc_jid = safeJID(muc_jid)
try:
return xmpp.plugin['xep_0045'].set_affiliation(muc_jid, jid, nick, affiliation)
except:
diff --git a/src/tabs.py b/src/tabs.py
index ecfa3e40..9291654f 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -805,8 +805,8 @@ class MucTab(ChatTab):
if not arg:
return self.core.command_help('version')
if arg in [user.nick for user in self.users]:
- jid = safeJID(self.name)
- jid.resource = arg
+ jid = safeJID(self.name).bare
+ jid = safeJID(jid + '/' + arg)
else:
jid = safeJID(arg)
self.core.xmpp.plugin['xep_0092'].get_version(jid, callback=callback)
@@ -821,6 +821,8 @@ class MucTab(ChatTab):
if not self.joined:
return self.core.information('/nick only works in joined rooms', 'Info')
current_status = self.core.get_status()
+ if not safeJID(self.get_name() + '/' + nick):
+ return self.core.information('Invalid nick', 'Info')
muc.change_nick(self.core.xmpp, self.name, nick, current_status.message, current_status.show)
def command_part(self, arg):
@@ -968,7 +970,6 @@ class MucTab(ChatTab):
msg = ''
self.command_affiliation('"'+args[0]+ '" outcast'+msg)
-
def command_role(self, arg):
"""
/role <nick> <role> [reason]
@@ -987,6 +988,8 @@ class MucTab(ChatTab):
if not self.joined or \
not role in ('none', 'visitor', 'participant', 'moderator'):
return
+ if not safeJID(self.get_name() + '/' + nick):
+ return self.core('Invalid nick', 'Info')
res = muc.set_user_role(self.core.xmpp, self.get_name(), nick, reason, role)
if res['type'] == 'error':
self.core.room_error(res, self.get_name())
@@ -1010,7 +1013,7 @@ class MucTab(ChatTab):
if nick in [user.nick for user in self.users]:
res = muc.set_user_affiliation(self.core.xmpp, self.get_name(), affiliation, nick=nick)
else:
- res = muc.set_user_affiliation(self.core.xmpp, self.get_name(), affiliation, jid=nick)
+ res = muc.set_user_affiliation(self.core.xmpp, self.get_name(), affiliation, jid=safeJID(nick))
if not res:
self.core.information('Could not set affiliation', 'Error')
@@ -1676,7 +1679,7 @@ class PrivateTab(ChatTab):
self.core.information(version, 'Info')
if arg:
return self.core.command_version(arg)
- jid = self.name
+ jid = safeJID(self.name)
self.core.xmpp.plugin['xep_0092'].get_version(jid, callback=callback)
def command_info(self, arg):
@@ -2774,8 +2777,7 @@ class ConversationTab(ChatTab):
self.core.information(version, 'Info')
if arg:
return self.core.command_version(arg)
- jid = self.name
- jid = safeJID(jid)
+ jid = safeJID(self.name)
if not jid.resource:
if jid in roster:
resource = roster[jid].get_highest_priority_resource()