Remove spaces at EOL.
This commit is contained in:
parent
2327600745
commit
086d031374
26 changed files with 276 additions and 276 deletions
|
@ -3,7 +3,7 @@ SUBDIRS = osx
|
||||||
CLEANFILES = \
|
CLEANFILES = \
|
||||||
trayicon.c
|
trayicon.c
|
||||||
INCLUDES = \
|
INCLUDES = \
|
||||||
$(PYTHON_INCLUDES)
|
$(PYTHON_INCLUDES)
|
||||||
export MACOSX_DEPLOYMENT_TARGET=10.4
|
export MACOSX_DEPLOYMENT_TARGET=10.4
|
||||||
|
|
||||||
if BUILD_TRAYICON
|
if BUILD_TRAYICON
|
||||||
|
@ -18,10 +18,10 @@ nodist_trayicon_la_SOURCES = \
|
||||||
trayicon.c
|
trayicon.c
|
||||||
|
|
||||||
trayicon_la_LDFLAGS = \
|
trayicon_la_LDFLAGS = \
|
||||||
-module -avoid-version
|
-module -avoid-version
|
||||||
trayicon_la_CFLAGS = $(PYGTK_CFLAGS)
|
trayicon_la_CFLAGS = $(PYGTK_CFLAGS)
|
||||||
|
|
||||||
trayicon.c:
|
trayicon.c:
|
||||||
pygtk-codegen-2.0 --prefix trayicon \
|
pygtk-codegen-2.0 --prefix trayicon \
|
||||||
--register $(PYGTK_DEFS)/gdk-types.defs \
|
--register $(PYGTK_DEFS)/gdk-types.defs \
|
||||||
--register $(PYGTK_DEFS)/gtk-types.defs \
|
--register $(PYGTK_DEFS)/gtk-types.defs \
|
||||||
|
@ -29,21 +29,21 @@ trayicon.c:
|
||||||
$(srcdir)/trayicon.defs > $@
|
$(srcdir)/trayicon.defs > $@
|
||||||
endif
|
endif
|
||||||
gajimsrcdir = $(pkgdatadir)/src
|
gajimsrcdir = $(pkgdatadir)/src
|
||||||
gajimsrc_PYTHON = $(srcdir)/*.py
|
gajimsrc_PYTHON = $(srcdir)/*.py
|
||||||
|
|
||||||
gajimsrc1dir = $(pkgdatadir)/src/common
|
gajimsrc1dir = $(pkgdatadir)/src/common
|
||||||
gajimsrc1_PYTHON = \
|
gajimsrc1_PYTHON = \
|
||||||
$(srcdir)/common/*.py
|
$(srcdir)/common/*.py
|
||||||
|
|
||||||
gajimsrc2dir = $(pkgdatadir)/src/common/xmpp
|
gajimsrc2dir = $(pkgdatadir)/src/common/xmpp
|
||||||
gajimsrc2_PYTHON = \
|
gajimsrc2_PYTHON = \
|
||||||
$(srcdir)/common/xmpp/*.py
|
$(srcdir)/common/xmpp/*.py
|
||||||
|
|
||||||
gajimsrc3dir = $(pkgdatadir)/src/common/zeroconf
|
gajimsrc3dir = $(pkgdatadir)/src/common/zeroconf
|
||||||
gajimsrc3_PYTHON = \
|
gajimsrc3_PYTHON = \
|
||||||
$(srcdir)/common/zeroconf/*.py
|
$(srcdir)/common/zeroconf/*.py
|
||||||
|
|
||||||
DISTCLEANFILES =
|
DISTCLEANFILES =
|
||||||
|
|
||||||
EXTRA_DIST = $(gajimsrc_PYTHON) \
|
EXTRA_DIST = $(gajimsrc_PYTHON) \
|
||||||
$(gajimsrc1_PYTHON) \
|
$(gajimsrc1_PYTHON) \
|
||||||
|
@ -53,7 +53,7 @@ EXTRA_DIST = $(gajimsrc_PYTHON) \
|
||||||
trayiconmodule.c \
|
trayiconmodule.c \
|
||||||
eggtrayicon.h \
|
eggtrayicon.h \
|
||||||
trayicon.defs \
|
trayicon.defs \
|
||||||
trayicon.override
|
trayicon.override
|
||||||
|
|
||||||
dist-hook:
|
dist-hook:
|
||||||
rm -f $(distdir)/ipython_view.py
|
rm -f $(distdir)/ipython_view.py
|
||||||
|
|
|
@ -268,14 +268,14 @@ class AdvancedConfigurationWindow(object):
|
||||||
|
|
||||||
def visible_func(self, model, treeiter):
|
def visible_func(self, model, treeiter):
|
||||||
search_string = self.entry.get_text().lower()
|
search_string = self.entry.get_text().lower()
|
||||||
for it in tree_model_pre_order(model,treeiter):
|
for it in tree_model_pre_order(model,treeiter):
|
||||||
if model[it][C_TYPE] != '':
|
if model[it][C_TYPE] != '':
|
||||||
opt_path = self.get_option_path(model, it)
|
opt_path = self.get_option_path(model, it)
|
||||||
if len(opt_path) == 3:
|
if len(opt_path) == 3:
|
||||||
desc = gajim.config.get_desc_per(opt_path[2], opt_path[1],
|
desc = gajim.config.get_desc_per(opt_path[2], opt_path[1],
|
||||||
opt_path[0])
|
opt_path[0])
|
||||||
elif len(opt_path) == 1:
|
elif len(opt_path) == 1:
|
||||||
desc = gajim.config.get_desc(opt_path[0])
|
desc = gajim.config.get_desc(opt_path[0])
|
||||||
if search_string in model[it][C_PREFNAME] or (desc and \
|
if search_string in model[it][C_PREFNAME] or (desc and \
|
||||||
search_string in desc.lower()):
|
search_string in desc.lower()):
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -727,11 +727,11 @@ class Connection(ConnectionHandlers):
|
||||||
gajim.config.set_per('accounts', self.name, 'ssl_fingerprint_sha1',
|
gajim.config.set_per('accounts', self.name, 'ssl_fingerprint_sha1',
|
||||||
con.Connection.ssl_fingerprint_sha1)
|
con.Connection.ssl_fingerprint_sha1)
|
||||||
self._register_handlers(con, con_type)
|
self._register_handlers(con, con_type)
|
||||||
con.auth(
|
con.auth(
|
||||||
user=name,
|
user=name,
|
||||||
password=self.password,
|
password=self.password,
|
||||||
resource=self.server_resource,
|
resource=self.server_resource,
|
||||||
sasl=1,
|
sasl=1,
|
||||||
on_auth=self.__on_auth)
|
on_auth=self.__on_auth)
|
||||||
|
|
||||||
def ssl_certificate_accepted(self):
|
def ssl_certificate_accepted(self):
|
||||||
|
|
|
@ -104,7 +104,7 @@ class DataField(ExtendedNode):
|
||||||
""" Keeps data about one field - var, field type, labels, instructions...
|
""" Keeps data about one field - var, field type, labels, instructions...
|
||||||
Base class for different kinds of fields. Use Field() function to
|
Base class for different kinds of fields. Use Field() function to
|
||||||
construct one of these. """
|
construct one of these. """
|
||||||
|
|
||||||
def __init__(self, typ=None, var=None, value=None, label=None, desc=None,
|
def __init__(self, typ=None, var=None, value=None, label=None, desc=None,
|
||||||
required=False, options=None, extend=None):
|
required=False, options=None, extend=None):
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ class DataField(ExtendedNode):
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
assert isinstance(value, basestring)
|
assert isinstance(value, basestring)
|
||||||
self.setAttr('type', value)
|
self.setAttr('type', value)
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
@nested_property
|
@nested_property
|
||||||
|
@ -152,7 +152,7 @@ class DataField(ExtendedNode):
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
self.delAttr('var')
|
self.delAttr('var')
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
@nested_property
|
@nested_property
|
||||||
|
@ -163,15 +163,15 @@ class DataField(ExtendedNode):
|
||||||
if not l:
|
if not l:
|
||||||
l = self.var
|
l = self.var
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
assert isinstance(value, basestring)
|
assert isinstance(value, basestring)
|
||||||
self.setAttr('label', value)
|
self.setAttr('label', value)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
if self.getAttr('label'):
|
if self.getAttr('label'):
|
||||||
self.delAttr('label')
|
self.delAttr('label')
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
@nested_property
|
@nested_property
|
||||||
|
@ -179,19 +179,19 @@ class DataField(ExtendedNode):
|
||||||
'''Human-readable description of field meaning.'''
|
'''Human-readable description of field meaning.'''
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return self.getTagData('desc') or u''
|
return self.getTagData('desc') or u''
|
||||||
|
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
assert isinstance(value, basestring)
|
assert isinstance(value, basestring)
|
||||||
if value == '':
|
if value == '':
|
||||||
fdel(self)
|
fdel(self)
|
||||||
else:
|
else:
|
||||||
self.setTagData('desc', value)
|
self.setTagData('desc', value)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
t = self.getTag('desc')
|
t = self.getTag('desc')
|
||||||
if t is not None:
|
if t is not None:
|
||||||
self.delChild(t)
|
self.delChild(t)
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
@nested_property
|
@nested_property
|
||||||
|
@ -199,14 +199,14 @@ class DataField(ExtendedNode):
|
||||||
'''Controls whether this field required to fill. Boolean.'''
|
'''Controls whether this field required to fill. Boolean.'''
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return bool(self.getTag('required'))
|
return bool(self.getTag('required'))
|
||||||
|
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
t = self.getTag('required')
|
t = self.getTag('required')
|
||||||
if t and not value:
|
if t and not value:
|
||||||
self.delChild(t)
|
self.delChild(t)
|
||||||
elif not t and value:
|
elif not t and value:
|
||||||
self.addChild('required')
|
self.addChild('required')
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
class BooleanField(DataField):
|
class BooleanField(DataField):
|
||||||
|
@ -222,15 +222,15 @@ class BooleanField(DataField):
|
||||||
if v is None:
|
if v is None:
|
||||||
return False # default value is False
|
return False # default value is False
|
||||||
raise WrongFieldValue
|
raise WrongFieldValue
|
||||||
|
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
self.setTagData('value', value and '1' or '0')
|
self.setTagData('value', value and '1' or '0')
|
||||||
|
|
||||||
def fdel(self, value):
|
def fdel(self, value):
|
||||||
t = self.getTag('value')
|
t = self.getTag('value')
|
||||||
if t is not None:
|
if t is not None:
|
||||||
self.delChild(t)
|
self.delChild(t)
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
class StringField(DataField):
|
class StringField(DataField):
|
||||||
|
@ -240,19 +240,19 @@ class StringField(DataField):
|
||||||
'''Value of field. May be any unicode string.'''
|
'''Value of field. May be any unicode string.'''
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return self.getTagData('value') or u''
|
return self.getTagData('value') or u''
|
||||||
|
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
assert isinstance(value, basestring)
|
assert isinstance(value, basestring)
|
||||||
if value == '':
|
if value == '':
|
||||||
return fdel(self)
|
return fdel(self)
|
||||||
self.setTagData('value', value)
|
self.setTagData('value', value)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
try:
|
try:
|
||||||
self.delChild(self.getTag('value'))
|
self.delChild(self.getTag('value'))
|
||||||
except ValueError: # if there already were no value tag
|
except ValueError: # if there already were no value tag
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
class ListField(DataField):
|
class ListField(DataField):
|
||||||
|
@ -271,16 +271,16 @@ class ListField(DataField):
|
||||||
l = v
|
l = v
|
||||||
options.append((l, v))
|
options.append((l, v))
|
||||||
return options
|
return options
|
||||||
|
|
||||||
def fset(self, values):
|
def fset(self, values):
|
||||||
fdel(self)
|
fdel(self)
|
||||||
for value, label in values:
|
for value, label in values:
|
||||||
self.addChild('option', {'label': label}).setTagData('value', value)
|
self.addChild('option', {'label': label}).setTagData('value', value)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
for element in self.getTags('option'):
|
for element in self.getTags('option'):
|
||||||
self.delChild(element)
|
self.delChild(element)
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
def iter_options(self):
|
def iter_options(self):
|
||||||
|
@ -307,16 +307,16 @@ class ListMultiField(ListField):
|
||||||
for element in self.getTags('value'):
|
for element in self.getTags('value'):
|
||||||
values.append(element.getData())
|
values.append(element.getData())
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def fset(self, values):
|
def fset(self, values):
|
||||||
fdel(self)
|
fdel(self)
|
||||||
for value in values:
|
for value in values:
|
||||||
self.addChild('value').setData(value)
|
self.addChild('value').setData(value)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
for element in self.getTags('value'):
|
for element in self.getTags('value'):
|
||||||
self.delChild(element)
|
self.delChild(element)
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
def iter_values(self):
|
def iter_values(self):
|
||||||
|
@ -332,18 +332,18 @@ class TextMultiField(DataField):
|
||||||
for element in self.iterTags('value'):
|
for element in self.iterTags('value'):
|
||||||
value += '\n' + element.getData()
|
value += '\n' + element.getData()
|
||||||
return value[1:]
|
return value[1:]
|
||||||
|
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
fdel(self)
|
fdel(self)
|
||||||
if value == '':
|
if value == '':
|
||||||
return
|
return
|
||||||
for line in value.split('\n'):
|
for line in value.split('\n'):
|
||||||
self.addChild('value').setData(line)
|
self.addChild('value').setData(line)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
for element in self.getTags('value'):
|
for element in self.getTags('value'):
|
||||||
self.delChild(element)
|
self.delChild(element)
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
class DataRecord(ExtendedNode):
|
class DataRecord(ExtendedNode):
|
||||||
|
@ -376,18 +376,18 @@ class DataRecord(ExtendedNode):
|
||||||
'''List of fields in this record.'''
|
'''List of fields in this record.'''
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return self.getTags('field')
|
return self.getTags('field')
|
||||||
|
|
||||||
def fset(self, fields):
|
def fset(self, fields):
|
||||||
fdel(self)
|
fdel(self)
|
||||||
for field in fields:
|
for field in fields:
|
||||||
if not isinstance(field, DataField):
|
if not isinstance(field, DataField):
|
||||||
ExtendField(extend=field)
|
ExtendField(extend=field)
|
||||||
self.addChild(node=field)
|
self.addChild(node=field)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
for element in self.getTags('field'):
|
for element in self.getTags('field'):
|
||||||
self.delChild(element)
|
self.delChild(element)
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
def iter_fields(self):
|
def iter_fields(self):
|
||||||
|
@ -425,11 +425,11 @@ class DataForm(ExtendedNode):
|
||||||
filledform = DataForm(replyto=thisform)...'''
|
filledform = DataForm(replyto=thisform)...'''
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return self.getAttr('type')
|
return self.getAttr('type')
|
||||||
|
|
||||||
def fset(self, type_):
|
def fset(self, type_):
|
||||||
assert type_ in ('form', 'submit', 'cancel', 'result')
|
assert type_ in ('form', 'submit', 'cancel', 'result')
|
||||||
self.setAttr('type', type_)
|
self.setAttr('type', type_)
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
@nested_property
|
@nested_property
|
||||||
|
@ -437,16 +437,16 @@ class DataForm(ExtendedNode):
|
||||||
''' Title of the form. Human-readable, should not contain any \\r\\n.'''
|
''' Title of the form. Human-readable, should not contain any \\r\\n.'''
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return self.getTagData('title')
|
return self.getTagData('title')
|
||||||
|
|
||||||
def fset(self, title):
|
def fset(self, title):
|
||||||
self.setTagData('title', title)
|
self.setTagData('title', title)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
try:
|
try:
|
||||||
self.delChild('title')
|
self.delChild('title')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
@nested_property
|
@nested_property
|
||||||
|
@ -458,17 +458,17 @@ class DataForm(ExtendedNode):
|
||||||
for valuenode in self.getTags('instructions'):
|
for valuenode in self.getTags('instructions'):
|
||||||
value += '\n' + valuenode.getData()
|
value += '\n' + valuenode.getData()
|
||||||
return value[1:]
|
return value[1:]
|
||||||
|
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
fdel(self)
|
fdel(self)
|
||||||
if value == '': return
|
if value == '': return
|
||||||
for line in value.split('\n'):
|
for line in value.split('\n'):
|
||||||
self.addChild('instructions').setData(line)
|
self.addChild('instructions').setData(line)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
for value in self.getTags('instructions'):
|
for value in self.getTags('instructions'):
|
||||||
self.delChild(value)
|
self.delChild(value)
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
class SimpleDataForm(DataForm, DataRecord):
|
class SimpleDataForm(DataForm, DataRecord):
|
||||||
|
@ -523,18 +523,18 @@ class MultipleDataForm(DataForm):
|
||||||
''' A list of all records. '''
|
''' A list of all records. '''
|
||||||
def fget(self):
|
def fget(self):
|
||||||
return list(self.iter_records())
|
return list(self.iter_records())
|
||||||
|
|
||||||
def fset(self, records):
|
def fset(self, records):
|
||||||
fdel(self)
|
fdel(self)
|
||||||
for record in records:
|
for record in records:
|
||||||
if not isinstance(record, DataRecord):
|
if not isinstance(record, DataRecord):
|
||||||
DataRecord(extend=record)
|
DataRecord(extend=record)
|
||||||
self.addChild(node=record)
|
self.addChild(node=record)
|
||||||
|
|
||||||
def fdel(self):
|
def fdel(self):
|
||||||
for record in self.getTags('item'):
|
for record in self.getTags('item'):
|
||||||
self.delChild(record)
|
self.delChild(record)
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
def iter_records(self):
|
def iter_records(self):
|
||||||
|
|
|
@ -618,7 +618,7 @@ class OptionsParser:
|
||||||
replace(' xmpp', '')
|
replace(' xmpp', '')
|
||||||
gajim.config.set('uri_schemes', new_values)
|
gajim.config.set('uri_schemes', new_values)
|
||||||
gajim.config.set('version', '0.12.0.1')
|
gajim.config.set('version', '0.12.0.1')
|
||||||
|
|
||||||
def update_config_to_01211(self):
|
def update_config_to_01211(self):
|
||||||
if 'trayicon' in self.old_values:
|
if 'trayicon' in self.old_values:
|
||||||
if self.old_values['trayicon'] == 'False':
|
if self.old_values['trayicon'] == 'False':
|
||||||
|
|
|
@ -34,7 +34,7 @@ host_pattern = re.compile('^[a-z0-9\-._]*[a-z0-9]\.[a-z]{2,}$')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
#raise ImportError("Manually disabled libasync")
|
#raise ImportError("Manually disabled libasync")
|
||||||
import libasyncns
|
import libasyncns
|
||||||
USE_LIBASYNCNS = True
|
USE_LIBASYNCNS = True
|
||||||
log.info("libasyncns-python loaded")
|
log.info("libasyncns-python loaded")
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -75,7 +75,7 @@ class CommonResolver():
|
||||||
return
|
return
|
||||||
if self.handlers.has_key(host+type):
|
if self.handlers.has_key(host+type):
|
||||||
# host is about to be resolved by another connection,
|
# host is about to be resolved by another connection,
|
||||||
# attach our callback
|
# attach our callback
|
||||||
self.handlers[host+type].append(on_ready)
|
self.handlers[host+type].append(on_ready)
|
||||||
else:
|
else:
|
||||||
# host has never been resolved, start now
|
# host has never been resolved, start now
|
||||||
|
@ -97,10 +97,10 @@ class CommonResolver():
|
||||||
# FIXME: API usage is not consistent! This one requires that process is called
|
# FIXME: API usage is not consistent! This one requires that process is called
|
||||||
class LibAsyncNSResolver(CommonResolver):
|
class LibAsyncNSResolver(CommonResolver):
|
||||||
'''
|
'''
|
||||||
Asynchronous resolver using libasyncns-python. process() method has to be
|
Asynchronous resolver using libasyncns-python. process() method has to be
|
||||||
called in order to proceed the pending requests.
|
called in order to proceed the pending requests.
|
||||||
Based on patch submitted by Damien Thebault.
|
Based on patch submitted by Damien Thebault.
|
||||||
'''
|
'''
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.asyncns = libasyncns.Asyncns()
|
self.asyncns = libasyncns.Asyncns()
|
||||||
CommonResolver.__init__(self)
|
CommonResolver.__init__(self)
|
||||||
|
@ -163,16 +163,16 @@ class NSLookupResolver(CommonResolver):
|
||||||
self.idlequeue = idlequeue
|
self.idlequeue = idlequeue
|
||||||
self.process = False
|
self.process = False
|
||||||
CommonResolver.__init__(self)
|
CommonResolver.__init__(self)
|
||||||
|
|
||||||
def parse_srv_result(self, fqdn, result):
|
def parse_srv_result(self, fqdn, result):
|
||||||
''' parse the output of nslookup command and return list of
|
''' parse the output of nslookup command and return list of
|
||||||
properties: 'host', 'port','weight', 'priority' corresponding to the found
|
properties: 'host', 'port','weight', 'priority' corresponding to the found
|
||||||
srv hosts '''
|
srv hosts '''
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
return self._parse_srv_result_nt(fqdn, result)
|
return self._parse_srv_result_nt(fqdn, result)
|
||||||
elif os.name == 'posix':
|
elif os.name == 'posix':
|
||||||
return self._parse_srv_result_posix(fqdn, result)
|
return self._parse_srv_result_posix(fqdn, result)
|
||||||
|
|
||||||
def _parse_srv_result_nt(self, fqdn, result):
|
def _parse_srv_result_nt(self, fqdn, result):
|
||||||
# output from win32 nslookup command
|
# output from win32 nslookup command
|
||||||
if not result:
|
if not result:
|
||||||
|
@ -195,7 +195,7 @@ class NSLookupResolver(CommonResolver):
|
||||||
hosts.append(current_host)
|
hosts.append(current_host)
|
||||||
current_host = None
|
current_host = None
|
||||||
continue
|
continue
|
||||||
prop_type = res[0].strip()
|
prop_type = res[0].strip()
|
||||||
prop_value = res[1].strip()
|
prop_value = res[1].strip()
|
||||||
if prop_type.find('prio') > -1:
|
if prop_type.find('prio') > -1:
|
||||||
try:
|
try:
|
||||||
|
@ -221,7 +221,7 @@ class NSLookupResolver(CommonResolver):
|
||||||
hosts.append(current_host)
|
hosts.append(current_host)
|
||||||
current_host = None
|
current_host = None
|
||||||
return hosts
|
return hosts
|
||||||
|
|
||||||
def _parse_srv_result_posix(self, fqdn, result):
|
def _parse_srv_result_posix(self, fqdn, result):
|
||||||
# typical output of bind-tools nslookup command:
|
# typical output of bind-tools nslookup command:
|
||||||
# _xmpp-client._tcp.jabber.org service = 30 30 5222 jabber.org.
|
# _xmpp-client._tcp.jabber.org service = 30 30 5222 jabber.org.
|
||||||
|
@ -261,12 +261,12 @@ class NSLookupResolver(CommonResolver):
|
||||||
hosts.append({'host': host, 'port': port, 'weight': weight,
|
hosts.append({'host': host, 'port': port, 'weight': weight,
|
||||||
'prio': prio})
|
'prio': prio})
|
||||||
return hosts
|
return hosts
|
||||||
|
|
||||||
def _on_ready(self, host, type, result):
|
def _on_ready(self, host, type, result):
|
||||||
# nslookup finished, parse the result and call the handlers
|
# nslookup finished, parse the result and call the handlers
|
||||||
result_list = self.parse_srv_result(host, result)
|
result_list = self.parse_srv_result(host, result)
|
||||||
CommonResolver._on_ready(self, host, type, result_list)
|
CommonResolver._on_ready(self, host, type, result_list)
|
||||||
|
|
||||||
def start_resolve(self, host, type):
|
def start_resolve(self, host, type):
|
||||||
''' spawn new nslookup process and start waiting for results '''
|
''' spawn new nslookup process and start waiting for results '''
|
||||||
ns = NsLookup(self._on_ready, host, type)
|
ns = NsLookup(self._on_ready, host, type)
|
||||||
|
@ -278,7 +278,7 @@ class NSLookupResolver(CommonResolver):
|
||||||
class NsLookup(IdleCommand):
|
class NsLookup(IdleCommand):
|
||||||
def __init__(self, on_result, host='_xmpp-client', type='srv'):
|
def __init__(self, on_result, host='_xmpp-client', type='srv'):
|
||||||
IdleCommand.__init__(self, on_result)
|
IdleCommand.__init__(self, on_result)
|
||||||
self.commandtimeout = 10
|
self.commandtimeout = 10
|
||||||
self.host = host.lower()
|
self.host = host.lower()
|
||||||
self.type = type.lower()
|
self.type = type.lower()
|
||||||
if not host_pattern.match(self.host):
|
if not host_pattern.match(self.host):
|
||||||
|
@ -290,24 +290,24 @@ class NsLookup(IdleCommand):
|
||||||
log.error('Invalid querytype: %s' % self.type)
|
log.error('Invalid querytype: %s' % self.type)
|
||||||
self.canexecute = False
|
self.canexecute = False
|
||||||
return
|
return
|
||||||
|
|
||||||
def _compose_command_args(self):
|
def _compose_command_args(self):
|
||||||
return ['nslookup', '-type=' + self.type , self.host]
|
return ['nslookup', '-type=' + self.type , self.host]
|
||||||
|
|
||||||
def _return_result(self):
|
def _return_result(self):
|
||||||
if self.result_handler:
|
if self.result_handler:
|
||||||
self.result_handler(self.host, self.type, self.result)
|
self.result_handler(self.host, self.type, self.result)
|
||||||
self.result_handler = None
|
self.result_handler = None
|
||||||
|
|
||||||
# below lines is on how to use API and assist in testing
|
# below lines is on how to use API and assist in testing
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import gobject
|
import gobject
|
||||||
import gtk
|
import gtk
|
||||||
from xmpp import idlequeue
|
from xmpp import idlequeue
|
||||||
|
|
||||||
idlequeue = idlequeue.get_idlequeue()
|
idlequeue = idlequeue.get_idlequeue()
|
||||||
resolver = get_resolver(idlequeue)
|
resolver = get_resolver(idlequeue)
|
||||||
|
|
||||||
def clicked(widget):
|
def clicked(widget):
|
||||||
global resolver
|
global resolver
|
||||||
host = text_view.get_text()
|
host = text_view.get_text()
|
||||||
|
|
|
@ -127,7 +127,7 @@ class SASL(PlugIn):
|
||||||
self.password = password
|
self.password = password
|
||||||
self.on_sasl = on_sasl
|
self.on_sasl = on_sasl
|
||||||
self.realm = None
|
self.realm = None
|
||||||
|
|
||||||
def plugin(self, owner):
|
def plugin(self, owner):
|
||||||
if 'version' not in self._owner.Dispatcher.Stream._document_attrs:
|
if 'version' not in self._owner.Dispatcher.Stream._document_attrs:
|
||||||
self.startsasl = SASL_UNSUPPORTED
|
self.startsasl = SASL_UNSUPPORTED
|
||||||
|
@ -257,11 +257,11 @@ class SASL(PlugIn):
|
||||||
self.startsasl = SASL_SUCCESS
|
self.startsasl = SASL_SUCCESS
|
||||||
log.info('Successfully authenticated with remote server.')
|
log.info('Successfully authenticated with remote server.')
|
||||||
handlers = self._owner.Dispatcher.dumpHandlers()
|
handlers = self._owner.Dispatcher.dumpHandlers()
|
||||||
|
|
||||||
# Bosh specific dispatcher replugging
|
# Bosh specific dispatcher replugging
|
||||||
# save old features. They will be used in case we won't get response on
|
# save old features. They will be used in case we won't get response on
|
||||||
# stream restart after SASL auth (happens with XMPP over BOSH with
|
# stream restart after SASL auth (happens with XMPP over BOSH with
|
||||||
# Openfire)
|
# Openfire)
|
||||||
old_features = self._owner.Dispatcher.Stream.features
|
old_features = self._owner.Dispatcher.Stream.features
|
||||||
self._owner.Dispatcher.PlugOut()
|
self._owner.Dispatcher.PlugOut()
|
||||||
dispatcher_nb.Dispatcher.get_instance().PlugIn(self._owner,
|
dispatcher_nb.Dispatcher.get_instance().PlugIn(self._owner,
|
||||||
|
@ -294,7 +294,7 @@ class SASL(PlugIn):
|
||||||
self._owner.send(Node('response', attrs={'xmlns':NS_SASL},
|
self._owner.send(Node('response', attrs={'xmlns':NS_SASL},
|
||||||
payload=response).__str__())
|
payload=response).__str__())
|
||||||
raise NodeProcessed
|
raise NodeProcessed
|
||||||
|
|
||||||
# magic foo...
|
# magic foo...
|
||||||
chal = challenge_splitter(data)
|
chal = challenge_splitter(data)
|
||||||
if not self.realm and 'realm' in chal:
|
if not self.realm and 'realm' in chal:
|
||||||
|
@ -325,7 +325,7 @@ class SASL(PlugIn):
|
||||||
if self.on_sasl:
|
if self.on_sasl:
|
||||||
self.on_sasl()
|
self.on_sasl()
|
||||||
raise NodeProcessed
|
raise NodeProcessed
|
||||||
|
|
||||||
def set_password(self, password):
|
def set_password(self, password):
|
||||||
if password is None:
|
if password is None:
|
||||||
self.password = ''
|
self.password = ''
|
||||||
|
@ -450,7 +450,7 @@ class NonBlockingBind(PlugIn):
|
||||||
''' Start resource binding, if allowed at this time. Used internally. '''
|
''' Start resource binding, if allowed at this time. Used internally. '''
|
||||||
if self._owner.Dispatcher.Stream.features:
|
if self._owner.Dispatcher.Stream.features:
|
||||||
try:
|
try:
|
||||||
self.FeaturesHandler(self._owner.Dispatcher,
|
self.FeaturesHandler(self._owner.Dispatcher,
|
||||||
self._owner.Dispatcher.Stream.features)
|
self._owner.Dispatcher.Stream.features)
|
||||||
except NodeProcessed:
|
except NodeProcessed:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
## bosh.py
|
## bosh.py
|
||||||
##
|
##
|
||||||
##
|
##
|
||||||
## Copyright (C) 2008 Tomas Karasek <tom.to.the.k@gmail.com>
|
## Copyright (C) 2008 Tomas Karasek <tom.to.the.k@gmail.com>
|
||||||
|
@ -83,12 +83,12 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
self.proxy_dict = {}
|
self.proxy_dict = {}
|
||||||
if self.over_proxy and self.estabilish_tls:
|
if self.over_proxy and self.estabilish_tls:
|
||||||
self.proxy_dict['type'] = 'http'
|
self.proxy_dict['type'] = 'http'
|
||||||
# with SSL over proxy, we do HTTP CONNECT to proxy to open a channel to
|
# with SSL over proxy, we do HTTP CONNECT to proxy to open a channel to
|
||||||
# BOSH Connection Manager
|
# BOSH Connection Manager
|
||||||
self.proxy_dict['xmpp_server'] = (urisplit(self.bosh_uri)[1], self.bosh_port)
|
self.proxy_dict['xmpp_server'] = (urisplit(self.bosh_uri)[1], self.bosh_port)
|
||||||
self.proxy_dict['credentials'] = self.proxy_creds
|
self.proxy_dict['credentials'] = self.proxy_creds
|
||||||
|
|
||||||
|
|
||||||
def connect(self, conn_5tuple, on_connect, on_connect_failure):
|
def connect(self, conn_5tuple, on_connect, on_connect_failure):
|
||||||
NonBlockingTransport.connect(self, conn_5tuple, on_connect, on_connect_failure)
|
NonBlockingTransport.connect(self, conn_5tuple, on_connect, on_connect_failure)
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
else:
|
else:
|
||||||
self.send_BOSH(None)
|
self.send_BOSH(None)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_socket_in(self, state):
|
def get_socket_in(self, state):
|
||||||
''' gets sockets in desired state '''
|
''' gets sockets in desired state '''
|
||||||
|
@ -177,12 +177,12 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
|
|
||||||
def send_BOSH(self, payload):
|
def send_BOSH(self, payload):
|
||||||
'''
|
'''
|
||||||
Tries to send a stanza in payload by appeding it to a buffer and plugging a
|
Tries to send a stanza in payload by appeding it to a buffer and plugging a
|
||||||
free socket for writing.
|
free socket for writing.
|
||||||
'''
|
'''
|
||||||
total_pending_reqs = sum([s.pending_requests for s in self.http_socks])
|
total_pending_reqs = sum([s.pending_requests for s in self.http_socks])
|
||||||
|
|
||||||
# when called after HTTP response (Payload=None) and when there are already
|
# when called after HTTP response (Payload=None) and when there are already
|
||||||
# some pending requests and no data to send, or when the socket is
|
# some pending requests and no data to send, or when the socket is
|
||||||
# disconnected, we do nothing
|
# disconnected, we do nothing
|
||||||
if payload is None and \
|
if payload is None and \
|
||||||
|
@ -199,7 +199,7 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
# sent after HTTP response from CM, exception is when we're disconnecting - then we
|
# sent after HTTP response from CM, exception is when we're disconnecting - then we
|
||||||
# send anyway
|
# send anyway
|
||||||
if total_pending_reqs >= self.bosh_requests and self.get_state()!=DISCONNECTING:
|
if total_pending_reqs >= self.bosh_requests and self.get_state()!=DISCONNECTING:
|
||||||
log.warn('attemp to make more requests than allowed by Connection Manager:\n%s' %
|
log.warn('attemp to make more requests than allowed by Connection Manager:\n%s' %
|
||||||
self.get_current_state())
|
self.get_current_state())
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
# if there is a connecting socket, we just wait for when it connects,
|
# if there is a connecting socket, we just wait for when it connects,
|
||||||
# payload will be sent in a sec when the socket connects
|
# payload will be sent in a sec when the socket connects
|
||||||
if self.get_socket_in(CONNECTING): return
|
if self.get_socket_in(CONNECTING): return
|
||||||
|
|
||||||
# being here means there are either DISCONNECTED sockets or all sockets are
|
# being here means there are either DISCONNECTED sockets or all sockets are
|
||||||
# CONNECTED with too many pending requests
|
# CONNECTED with too many pending requests
|
||||||
s = self.get_socket_in(DISCONNECTED)
|
s = self.get_socket_in(DISCONNECTED)
|
||||||
|
@ -240,8 +240,8 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
Builds a BOSH body tag from data in buffers and adds key, rid and ack
|
Builds a BOSH body tag from data in buffers and adds key, rid and ack
|
||||||
attributes to it.
|
attributes to it.
|
||||||
This method is called from _do_send() of underlying transport. This is to
|
This method is called from _do_send() of underlying transport. This is to
|
||||||
ensure rid and keys will be processed in correct order. If I generate them
|
ensure rid and keys will be processed in correct order. If I generate them
|
||||||
before plugging a socket for write (and did it for two sockets/HTTP
|
before plugging a socket for write (and did it for two sockets/HTTP
|
||||||
connections) in parallel, they might be sent in wrong order, which results
|
connections) in parallel, they might be sent in wrong order, which results
|
||||||
in violating the BOSH session and server-side disconnect.
|
in violating the BOSH session and server-side disconnect.
|
||||||
'''
|
'''
|
||||||
|
@ -299,7 +299,7 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
else:
|
else:
|
||||||
socket.disconnect()
|
socket.disconnect()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def handle_body_attrs(self, stanza_attrs):
|
def handle_body_attrs(self, stanza_attrs):
|
||||||
'''
|
'''
|
||||||
|
@ -322,7 +322,7 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
ack = None
|
ack = None
|
||||||
if stanza_attrs.has_key('ack'):
|
if stanza_attrs.has_key('ack'):
|
||||||
ack = stanza_attrs['ack']
|
ack = stanza_attrs['ack']
|
||||||
self.ack_checker.process_incoming_ack(ack=ack,
|
self.ack_checker.process_incoming_ack(ack=ack,
|
||||||
socket=self.current_recv_socket)
|
socket=self.current_recv_socket)
|
||||||
|
|
||||||
if stanza_attrs.has_key('type'):
|
if stanza_attrs.has_key('type'):
|
||||||
|
@ -359,7 +359,7 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
self.send_BOSH(stanza)
|
self.send_BOSH(stanza)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_current_state(self):
|
def get_current_state(self):
|
||||||
t = '------ SOCKET_ID\tSOCKET_STATE\tPENDING_REQS\n'
|
t = '------ SOCKET_ID\tSOCKET_STATE\tPENDING_REQS\n'
|
||||||
for s in self.http_socks:
|
for s in self.http_socks:
|
||||||
|
@ -368,11 +368,11 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
% (t, self.prio_bosh_stanzas, self.stanza_buffer,
|
% (t, self.prio_bosh_stanzas, self.stanza_buffer,
|
||||||
self.ack_checker.get_not_acked_rids())
|
self.ack_checker.get_not_acked_rids())
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
|
||||||
def connect_and_flush(self, socket):
|
def connect_and_flush(self, socket):
|
||||||
socket.connect(
|
socket.connect(
|
||||||
conn_5tuple = self.conn_5tuple,
|
conn_5tuple = self.conn_5tuple,
|
||||||
on_connect = self.on_http_request_possible,
|
on_connect = self.on_http_request_possible,
|
||||||
on_connect_failure = self.disconnect)
|
on_connect_failure = self.disconnect)
|
||||||
|
|
||||||
|
@ -415,7 +415,7 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
|
|
||||||
|
|
||||||
def get_new_http_socket(self):
|
def get_new_http_socket(self):
|
||||||
http_dict = {'http_uri': self.bosh_uri,
|
http_dict = {'http_uri': self.bosh_uri,
|
||||||
'http_port': self.bosh_port,
|
'http_port': self.bosh_port,
|
||||||
'http_version': self.http_version,
|
'http_version': self.http_version,
|
||||||
'http_persistent': self.http_persistent,
|
'http_persistent': self.http_persistent,
|
||||||
|
@ -461,13 +461,13 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
|
|
||||||
def get_rand_number():
|
def get_rand_number():
|
||||||
# with 50-bit random initial rid, session would have to go up
|
# with 50-bit random initial rid, session would have to go up
|
||||||
# to 7881299347898368 messages to raise rid over 2**53
|
# to 7881299347898368 messages to raise rid over 2**53
|
||||||
# (see http://www.xmpp.org/extensions/xep-0124.html#rids)
|
# (see http://www.xmpp.org/extensions/xep-0124.html#rids)
|
||||||
# it's also used for sequence key initialization
|
# it's also used for sequence key initialization
|
||||||
r = random.Random()
|
r = random.Random()
|
||||||
r.seed()
|
r.seed()
|
||||||
return r.getrandbits(50)
|
return r.getrandbits(50)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AckChecker():
|
class AckChecker():
|
||||||
|
@ -507,11 +507,11 @@ class AckChecker():
|
||||||
|
|
||||||
self.ack = ack
|
self.ack = ack
|
||||||
|
|
||||||
|
|
||||||
def get_rid(self):
|
def get_rid(self):
|
||||||
self.rid = self.rid + 1
|
self.rid = self.rid + 1
|
||||||
return self.rid
|
return self.rid
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -537,7 +537,7 @@ class KeyStack():
|
||||||
if self.first_call:
|
if self.first_call:
|
||||||
self.first_call = False
|
self.first_call = False
|
||||||
return (None, self.keys.pop())
|
return (None, self.keys.pop())
|
||||||
|
|
||||||
if len(self.keys)>1:
|
if len(self.keys)>1:
|
||||||
return (self.keys.pop(), None)
|
return (self.keys.pop(), None)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -40,7 +40,7 @@ class NonBlockingClient:
|
||||||
|
|
||||||
:param domain: domain - for to: attribute (from account info)
|
:param domain: domain - for to: attribute (from account info)
|
||||||
:param idlequeue: processing idlequeue
|
:param idlequeue: processing idlequeue
|
||||||
:param caller: calling object - it has to implement methods
|
:param caller: calling object - it has to implement methods
|
||||||
_event_dispatcher which is called from dispatcher instance
|
_event_dispatcher which is called from dispatcher instance
|
||||||
'''
|
'''
|
||||||
self.Namespace = protocol.NS_CLIENT
|
self.Namespace = protocol.NS_CLIENT
|
||||||
|
@ -100,7 +100,7 @@ class NonBlockingClient:
|
||||||
|
|
||||||
self.connected = ''
|
self.connected = ''
|
||||||
self.stream_started = False
|
self.stream_started = False
|
||||||
|
|
||||||
self.disconnecting = True
|
self.disconnecting = True
|
||||||
|
|
||||||
log.debug('Client disconnected..')
|
log.debug('Client disconnected..')
|
||||||
|
@ -117,7 +117,7 @@ class NonBlockingClient:
|
||||||
else:
|
else:
|
||||||
# we are connected to XMPP server
|
# we are connected to XMPP server
|
||||||
if not stream_started:
|
if not stream_started:
|
||||||
# if error occur before XML stream was opened, e.g. no response on
|
# if error occur before XML stream was opened, e.g. no response on
|
||||||
# init request, we call the on_connect_failure callback because
|
# init request, we call the on_connect_failure callback because
|
||||||
# proper connection is not established yet and it's not a proxy
|
# proper connection is not established yet and it's not a proxy
|
||||||
# issue
|
# issue
|
||||||
|
@ -133,12 +133,12 @@ class NonBlockingClient:
|
||||||
|
|
||||||
def connect(self, on_connect, on_connect_failure, hostname=None, port=5222,
|
def connect(self, on_connect, on_connect_failure, hostname=None, port=5222,
|
||||||
on_proxy_failure=None, proxy=None, secure_tuple=('plain', None, None)):
|
on_proxy_failure=None, proxy=None, secure_tuple=('plain', None, None)):
|
||||||
'''
|
'''
|
||||||
Open XMPP connection (open XML streams in both directions).
|
Open XMPP connection (open XML streams in both directions).
|
||||||
|
|
||||||
:param on_connect: called after stream is successfully opened
|
:param on_connect: called after stream is successfully opened
|
||||||
:param on_connect_failure: called when error occures during connection
|
:param on_connect_failure: called when error occures during connection
|
||||||
:param hostname: hostname of XMPP server from SRV request
|
:param hostname: hostname of XMPP server from SRV request
|
||||||
:param port: port number of XMPP server
|
:param port: port number of XMPP server
|
||||||
:param on_proxy_failure: called if error occurres during TCP connection to
|
:param on_proxy_failure: called if error occurres during TCP connection to
|
||||||
proxy server or during proxy connecting process
|
proxy server or during proxy connecting process
|
||||||
|
@ -163,10 +163,10 @@ class NonBlockingClient:
|
||||||
self.xmpp_hostname = hostname
|
self.xmpp_hostname = hostname
|
||||||
else:
|
else:
|
||||||
self.xmpp_hostname = self.Server
|
self.xmpp_hostname = self.Server
|
||||||
|
|
||||||
# We only check for SSL here as for TLS we will first have to start a
|
# We only check for SSL here as for TLS we will first have to start a
|
||||||
# PLAIN connection and negotiate TLS afterwards.
|
# PLAIN connection and negotiate TLS afterwards.
|
||||||
# establish_tls will instruct transport to start secure connection
|
# establish_tls will instruct transport to start secure connection
|
||||||
# directly
|
# directly
|
||||||
establish_tls = self.desired_security == 'ssl'
|
establish_tls = self.desired_security == 'ssl'
|
||||||
certs = (self.cacerts, self.mycerts)
|
certs = (self.cacerts, self.mycerts)
|
||||||
|
@ -182,7 +182,7 @@ class NonBlockingClient:
|
||||||
# (DNS request will be done for proxy or BOSH CM hostname)
|
# (DNS request will be done for proxy or BOSH CM hostname)
|
||||||
tcp_host, tcp_port, proxy_user, proxy_pass = \
|
tcp_host, tcp_port, proxy_user, proxy_pass = \
|
||||||
transports_nb.get_proxy_data_from_dict(proxy)
|
transports_nb.get_proxy_data_from_dict(proxy)
|
||||||
|
|
||||||
if proxy['type'] == 'bosh':
|
if proxy['type'] == 'bosh':
|
||||||
# Setup BOSH transport
|
# Setup BOSH transport
|
||||||
self.socket = bosh.NonBlockingBOSH.get_instance(
|
self.socket = bosh.NonBlockingBOSH.get_instance(
|
||||||
|
@ -238,8 +238,8 @@ class NonBlockingClient:
|
||||||
if err_message:
|
if err_message:
|
||||||
log.debug('While looping over DNS A records: %s' % err_message)
|
log.debug('While looping over DNS A records: %s' % err_message)
|
||||||
if self.ip_addresses == []:
|
if self.ip_addresses == []:
|
||||||
msg = 'Run out of hosts for name %s:%s.' % (self.Server, self.Port)
|
msg = 'Run out of hosts for name %s:%s.' % (self.Server, self.Port)
|
||||||
msg = msg + ' Error for last IP: %s' % err_message
|
msg = msg + ' Error for last IP: %s' % err_message
|
||||||
self.disconnect(msg)
|
self.disconnect(msg)
|
||||||
else:
|
else:
|
||||||
self.current_ip = self.ip_addresses.pop(0)
|
self.current_ip = self.ip_addresses.pop(0)
|
||||||
|
@ -374,7 +374,7 @@ class NonBlockingClient:
|
||||||
log.warn('While connecting with type = "tls": TLS unsupported ' +
|
log.warn('While connecting with type = "tls": TLS unsupported ' +
|
||||||
'by remote server')
|
'by remote server')
|
||||||
self._on_connect()
|
self._on_connect()
|
||||||
|
|
||||||
elif self.connected in ['ssl', 'tls']:
|
elif self.connected in ['ssl', 'tls']:
|
||||||
self._on_connect()
|
self._on_connect()
|
||||||
else:
|
else:
|
||||||
|
@ -434,14 +434,14 @@ class NonBlockingClient:
|
||||||
:param resource: resource that shall be used for auth/connecting
|
:param resource: resource that shall be used for auth/connecting
|
||||||
:param sasl: Boolean indicating if SASL shall be used. (default: True)
|
:param sasl: Boolean indicating if SASL shall be used. (default: True)
|
||||||
:param on_auth: Callback, called after auth. On auth failure, argument
|
:param on_auth: Callback, called after auth. On auth failure, argument
|
||||||
is None.
|
is None.
|
||||||
'''
|
'''
|
||||||
self._User, self._Password = user, password
|
self._User, self._Password = user, password
|
||||||
self._Resource, self._sasl = resource, sasl
|
self._Resource, self._sasl = resource, sasl
|
||||||
self.on_auth = on_auth
|
self.on_auth = on_auth
|
||||||
self._on_doc_attrs()
|
self._on_doc_attrs()
|
||||||
return
|
return
|
||||||
|
|
||||||
def _on_old_auth(self, res):
|
def _on_old_auth(self, res):
|
||||||
''' Callback used by NON-SASL auth. On auth failure, res is None. '''
|
''' Callback used by NON-SASL auth. On auth failure, res is None. '''
|
||||||
if res:
|
if res:
|
||||||
|
@ -472,7 +472,7 @@ class NonBlockingClient:
|
||||||
return
|
return
|
||||||
self.SASL.auth()
|
self.SASL.auth()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _on_start_sasl(self, data=None):
|
def _on_start_sasl(self, data=None):
|
||||||
''' Callback used by SASL, called on each auth step.'''
|
''' Callback used by SASL, called on each auth step.'''
|
||||||
if data:
|
if data:
|
||||||
|
@ -493,7 +493,7 @@ class NonBlockingClient:
|
||||||
auth_nb.NonBlockingBind.get_instance().PlugIn(self)
|
auth_nb.NonBlockingBind.get_instance().PlugIn(self)
|
||||||
self.onreceive(self._on_auth_bind)
|
self.onreceive(self._on_auth_bind)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _on_auth_bind(self, data):
|
def _on_auth_bind(self, data):
|
||||||
# FIXME: Why use this callback and not bind directly?
|
# FIXME: Why use this callback and not bind directly?
|
||||||
if data:
|
if data:
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Main xmpp decision making logic. Provides library with methods to assign
|
Main xmpp decision making logic. Provides library with methods to assign
|
||||||
different handlers to different XMPP stanzas and namespaces.
|
different handlers to different XMPP stanzas and namespaces.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -54,12 +54,12 @@ class Dispatcher():
|
||||||
BOSHDispatcher().PlugIn(client_obj, after_SASL, old_features)
|
BOSHDispatcher().PlugIn(client_obj, after_SASL, old_features)
|
||||||
else:
|
else:
|
||||||
assert False # should never be reached
|
assert False # should never be reached
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_instance(cls, *args, **kwargs):
|
def get_instance(cls, *args, **kwargs):
|
||||||
'''
|
'''
|
||||||
Factory Method for object creation.
|
Factory Method for object creation.
|
||||||
|
|
||||||
Use this instead of directly initializing the class in order to make
|
Use this instead of directly initializing the class in order to make
|
||||||
unit testing much easier.
|
unit testing much easier.
|
||||||
'''
|
'''
|
||||||
|
@ -70,7 +70,7 @@ class XMPPDispatcher(PlugIn):
|
||||||
'''
|
'''
|
||||||
Handles XMPP stream and is the first who takes control over a fresh stanza.
|
Handles XMPP stream and is the first who takes control over a fresh stanza.
|
||||||
|
|
||||||
Is plugged into NonBlockingClient but can be replugged to restart handled
|
Is plugged into NonBlockingClient but can be replugged to restart handled
|
||||||
stream headers (used by SASL f.e.).
|
stream headers (used by SASL f.e.).
|
||||||
'''
|
'''
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -84,7 +84,7 @@ class XMPPDispatcher(PlugIn):
|
||||||
self._exported_methods=[self.RegisterHandler, self.RegisterDefaultHandler,
|
self._exported_methods=[self.RegisterHandler, self.RegisterDefaultHandler,
|
||||||
self.RegisterEventHandler, self.UnregisterCycleHandler,
|
self.RegisterEventHandler, self.UnregisterCycleHandler,
|
||||||
self.RegisterCycleHandler, self.RegisterHandlerOnce,
|
self.RegisterCycleHandler, self.RegisterHandlerOnce,
|
||||||
self.UnregisterHandler, self.RegisterProtocol,
|
self.UnregisterHandler, self.RegisterProtocol,
|
||||||
self.SendAndWaitForResponse, self.SendAndCallForResponse,
|
self.SendAndWaitForResponse, self.SendAndCallForResponse,
|
||||||
self.getAnID, self.Event, self.send]
|
self.getAnID, self.Event, self.send]
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ class XMPPDispatcher(PlugIn):
|
||||||
def restoreHandlers(self, handlers):
|
def restoreHandlers(self, handlers):
|
||||||
'''
|
'''
|
||||||
Restores user-registered callbacks structure from dump previously
|
Restores user-registered callbacks structure from dump previously
|
||||||
obtained via dumpHandlers. Used within the library to carry user
|
obtained via dumpHandlers. Used within the library to carry user
|
||||||
handlers set over Dispatcher replugins.
|
handlers set over Dispatcher replugins.
|
||||||
'''
|
'''
|
||||||
self.handlers = handlers
|
self.handlers = handlers
|
||||||
|
@ -213,7 +213,7 @@ class XMPPDispatcher(PlugIn):
|
||||||
def RegisterNamespace(self, xmlns, order='info'):
|
def RegisterNamespace(self, xmlns, order='info'):
|
||||||
'''
|
'''
|
||||||
Creates internal structures for newly registered namespace.
|
Creates internal structures for newly registered namespace.
|
||||||
You can register handlers for this namespace afterwards. By default
|
You can register handlers for this namespace afterwards. By default
|
||||||
one namespace is already registered
|
one namespace is already registered
|
||||||
(jabber:client or jabber:component:accept depending on context.
|
(jabber:client or jabber:component:accept depending on context.
|
||||||
'''
|
'''
|
||||||
|
@ -226,7 +226,7 @@ class XMPPDispatcher(PlugIn):
|
||||||
'''
|
'''
|
||||||
Used to declare some top-level stanza name to dispatcher.
|
Used to declare some top-level stanza name to dispatcher.
|
||||||
Needed to start registering handlers for such stanzas.
|
Needed to start registering handlers for such stanzas.
|
||||||
|
|
||||||
Iq, message and presence protocols are registered by default.
|
Iq, message and presence protocols are registered by default.
|
||||||
'''
|
'''
|
||||||
if not xmlns:
|
if not xmlns:
|
||||||
|
@ -246,12 +246,12 @@ class XMPPDispatcher(PlugIn):
|
||||||
makefirst=False, system=False):
|
makefirst=False, system=False):
|
||||||
'''
|
'''
|
||||||
Register user callback as stanzas handler of declared type.
|
Register user callback as stanzas handler of declared type.
|
||||||
|
|
||||||
Callback must take (if chained, see later) arguments:
|
Callback must take (if chained, see later) arguments:
|
||||||
dispatcher instance (for replying), incoming return of previous handlers.
|
dispatcher instance (for replying), incoming return of previous handlers.
|
||||||
The callback must raise xmpp.NodeProcessed just before return if it wants
|
The callback must raise xmpp.NodeProcessed just before return if it wants
|
||||||
other callbacks to be called with the same stanza as argument _and_, more
|
other callbacks to be called with the same stanza as argument _and_, more
|
||||||
importantly library from returning stanza to sender with error set.
|
importantly library from returning stanza to sender with error set.
|
||||||
|
|
||||||
:param name: name of stanza. F.e. "iq".
|
:param name: name of stanza. F.e. "iq".
|
||||||
:param handler: user callback.
|
:param handler: user callback.
|
||||||
|
@ -279,13 +279,13 @@ class XMPPDispatcher(PlugIn):
|
||||||
if typ+ns not in self.handlers[xmlns][name]:
|
if typ+ns not in self.handlers[xmlns][name]:
|
||||||
self.handlers[xmlns][name][typ+ns]=[]
|
self.handlers[xmlns][name][typ+ns]=[]
|
||||||
if makefirst:
|
if makefirst:
|
||||||
self.handlers[xmlns][name][typ+ns].insert(0,{'func':handler,
|
self.handlers[xmlns][name][typ+ns].insert(0,{'func':handler,
|
||||||
'system':system})
|
'system':system})
|
||||||
else:
|
else:
|
||||||
self.handlers[xmlns][name][typ+ns].append({'func':handler,
|
self.handlers[xmlns][name][typ+ns].append({'func':handler,
|
||||||
'system':system})
|
'system':system})
|
||||||
|
|
||||||
def RegisterHandlerOnce(self, name, handler, typ='', ns='', xmlns=None,
|
def RegisterHandlerOnce(self, name, handler, typ='', ns='', xmlns=None,
|
||||||
makefirst=0, system=0):
|
makefirst=0, system=0):
|
||||||
''' Unregister handler after first call (not implemented yet). '''
|
''' Unregister handler after first call (not implemented yet). '''
|
||||||
# FIXME Drop or implement
|
# FIXME Drop or implement
|
||||||
|
@ -352,8 +352,8 @@ class XMPPDispatcher(PlugIn):
|
||||||
|
|
||||||
def Event(self, realm, event, data):
|
def Event(self, realm, event, data):
|
||||||
'''
|
'''
|
||||||
Raise some event.
|
Raise some event.
|
||||||
|
|
||||||
:param realm: scope of event. Usually a namespace.
|
:param realm: scope of event. Usually a namespace.
|
||||||
:param event: the event itself. F.e. "SUCCESSFUL SEND".
|
:param event: the event itself. F.e. "SUCCESSFUL SEND".
|
||||||
:param data: data that comes along with event. Depends on event.
|
:param data: data that comes along with event. Depends on event.
|
||||||
|
@ -453,7 +453,7 @@ class XMPPDispatcher(PlugIn):
|
||||||
|
|
||||||
def _WaitForData(self, data):
|
def _WaitForData(self, data):
|
||||||
'''
|
'''
|
||||||
Internal wrapper around ProcessNonBlocking. Will check for
|
Internal wrapper around ProcessNonBlocking. Will check for
|
||||||
'''
|
'''
|
||||||
if data is None:
|
if data is None:
|
||||||
return
|
return
|
||||||
|
@ -520,7 +520,7 @@ class XMPPDispatcher(PlugIn):
|
||||||
return ID
|
return ID
|
||||||
|
|
||||||
|
|
||||||
class BOSHDispatcher(XMPPDispatcher):
|
class BOSHDispatcher(XMPPDispatcher):
|
||||||
|
|
||||||
def PlugIn(self, owner, after_SASL=False, old_features=None):
|
def PlugIn(self, owner, after_SASL=False, old_features=None):
|
||||||
self.old_features = old_features
|
self.old_features = old_features
|
||||||
|
@ -543,7 +543,7 @@ class BOSHDispatcher(XMPPDispatcher):
|
||||||
if locale.getdefaultlocale()[0]:
|
if locale.getdefaultlocale()[0]:
|
||||||
self._metastream.setAttr('xml:lang',
|
self._metastream.setAttr('xml:lang',
|
||||||
locale.getdefaultlocale()[0].split('_')[0])
|
locale.getdefaultlocale()[0].split('_')[0])
|
||||||
|
|
||||||
self.restart = True
|
self.restart = True
|
||||||
self._owner.Connection.send_init(after_SASL=self.after_SASL)
|
self._owner.Connection.send_init(after_SASL=self.after_SASL)
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ def getRegInfo(disp, host, info={}, sync=True):
|
||||||
'''
|
'''
|
||||||
Gets registration form from remote host. Info dict can be prefilled
|
Gets registration form from remote host. Info dict can be prefilled
|
||||||
:param disp: plugged dispatcher instance
|
:param disp: plugged dispatcher instance
|
||||||
:param info: dict, like {'username':'joey'}.
|
:param info: dict, like {'username':'joey'}.
|
||||||
|
|
||||||
See JEP-0077 for details.
|
See JEP-0077 for details.
|
||||||
'''
|
'''
|
||||||
|
@ -79,7 +79,7 @@ def _ReceivedRegInfo(con, resp, agent):
|
||||||
def register(disp, host, info, cb):
|
def register(disp, host, info, cb):
|
||||||
'''
|
'''
|
||||||
Perform registration on remote server with provided info.
|
Perform registration on remote server with provided info.
|
||||||
|
|
||||||
If registration fails you can get additional info from the dispatcher's
|
If registration fails you can get additional info from the dispatcher's
|
||||||
owner attributes lastErrNode, lastErr and lastErrCode.
|
owner attributes lastErrNode, lastErr and lastErrCode.
|
||||||
'''
|
'''
|
||||||
|
@ -187,8 +187,8 @@ def setDefaultPrivacyList(disp, listname=None):
|
||||||
|
|
||||||
def setPrivacyList(disp, listname, tags):
|
def setPrivacyList(disp, listname, tags):
|
||||||
'''
|
'''
|
||||||
Set the ruleset.
|
Set the ruleset.
|
||||||
|
|
||||||
'list' should be the simpleXML node formatted according to RFC 3921 (XMPP-IM) I.e. Node('list',{'name':listname},payload=[...]). Returns true on success.
|
'list' should be the simpleXML node formatted according to RFC 3921 (XMPP-IM) I.e. Node('list',{'name':listname},payload=[...]). Returns true on success.
|
||||||
'''
|
'''
|
||||||
iq = Iq('set', NS_PRIVACY, xmlns = '')
|
iq = Iq('set', NS_PRIVACY, xmlns = '')
|
||||||
|
@ -196,7 +196,7 @@ def setPrivacyList(disp, listname, tags):
|
||||||
for item in tags:
|
for item in tags:
|
||||||
if 'type' in item and 'value' in item:
|
if 'type' in item and 'value' in item:
|
||||||
item_tag = list_query.setTag('item', {'action': item['action'],
|
item_tag = list_query.setTag('item', {'action': item['action'],
|
||||||
'order': item['order'], 'type': item['type'],
|
'order': item['order'], 'type': item['type'],
|
||||||
'value': item['value']})
|
'value': item['value']})
|
||||||
else:
|
else:
|
||||||
item_tag = list_query.setTag('item', {'action': item['action'],
|
item_tag = list_query.setTag('item', {'action': item['action'],
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
## GNU General Public License for more details.
|
## GNU General Public License for more details.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Idlequeues are Gajim's network heartbeat. Transports can be plugged as
|
Idlequeues are Gajim's network heartbeat. Transports can be plugged as
|
||||||
idle objects and be informed about possible IO.
|
idle objects and be informed about possible IO.
|
||||||
'''
|
'''
|
||||||
import os
|
import os
|
||||||
|
@ -35,13 +35,13 @@ elif os.name == 'posix':
|
||||||
import fcntl
|
import fcntl
|
||||||
|
|
||||||
FLAG_WRITE = 20 # write only
|
FLAG_WRITE = 20 # write only
|
||||||
FLAG_READ = 19 # read only
|
FLAG_READ = 19 # read only
|
||||||
FLAG_READ_WRITE = 23 # read and write
|
FLAG_READ_WRITE = 23 # read and write
|
||||||
FLAG_CLOSE = 16 # wait for close
|
FLAG_CLOSE = 16 # wait for close
|
||||||
|
|
||||||
PENDING_READ = 3 # waiting read event
|
PENDING_READ = 3 # waiting read event
|
||||||
PENDING_WRITE = 4 # waiting write event
|
PENDING_WRITE = 4 # waiting write event
|
||||||
IS_CLOSED = 16 # channel closed
|
IS_CLOSED = 16 # channel closed
|
||||||
|
|
||||||
|
|
||||||
def get_idlequeue():
|
def get_idlequeue():
|
||||||
|
@ -91,30 +91,30 @@ class IdleCommand(IdleObject):
|
||||||
IdleObject.__init__(self)
|
IdleObject.__init__(self)
|
||||||
# how long (sec.) to wait for result ( 0 - forever )
|
# how long (sec.) to wait for result ( 0 - forever )
|
||||||
# it is a class var, instead of a constant and we can override it.
|
# it is a class var, instead of a constant and we can override it.
|
||||||
self.commandtimeout = 0
|
self.commandtimeout = 0
|
||||||
# when we have some kind of result (valid, ot not) we call this handler
|
# when we have some kind of result (valid, ot not) we call this handler
|
||||||
self.result_handler = on_result
|
self.result_handler = on_result
|
||||||
# if it is True, we can safetely execute the command
|
# if it is True, we can safetely execute the command
|
||||||
self.canexecute = True
|
self.canexecute = True
|
||||||
self.idlequeue = None
|
self.idlequeue = None
|
||||||
self.result =''
|
self.result =''
|
||||||
|
|
||||||
def set_idlequeue(self, idlequeue):
|
def set_idlequeue(self, idlequeue):
|
||||||
self.idlequeue = idlequeue
|
self.idlequeue = idlequeue
|
||||||
|
|
||||||
def _return_result(self):
|
def _return_result(self):
|
||||||
if self.result_handler:
|
if self.result_handler:
|
||||||
self.result_handler(self.result)
|
self.result_handler(self.result)
|
||||||
self.result_handler = None
|
self.result_handler = None
|
||||||
|
|
||||||
def _compose_command_args(self):
|
def _compose_command_args(self):
|
||||||
return ['echo', 'da']
|
return ['echo', 'da']
|
||||||
|
|
||||||
def _compose_command_line(self):
|
def _compose_command_line(self):
|
||||||
''' return one line representation of command and its arguments '''
|
''' return one line representation of command and its arguments '''
|
||||||
return reduce(lambda left, right: left + ' ' + right,
|
return reduce(lambda left, right: left + ' ' + right,
|
||||||
self._compose_command_args())
|
self._compose_command_args())
|
||||||
|
|
||||||
def wait_child(self):
|
def wait_child(self):
|
||||||
if self.pipe.poll() is None:
|
if self.pipe.poll() is None:
|
||||||
# result timeout
|
# result timeout
|
||||||
|
@ -141,16 +141,16 @@ class IdleCommand(IdleObject):
|
||||||
self._start_nt()
|
self._start_nt()
|
||||||
elif os.name == 'posix':
|
elif os.name == 'posix':
|
||||||
self._start_posix()
|
self._start_posix()
|
||||||
|
|
||||||
def _start_nt(self):
|
def _start_nt(self):
|
||||||
# if gajim is started from noninteraactive shells stdin is closed and
|
# if gajim is started from noninteraactive shells stdin is closed and
|
||||||
# cannot be forwarded, so we have to keep it open
|
# cannot be forwarded, so we have to keep it open
|
||||||
self.pipe = Popen(self._compose_command_args(), stdout=PIPE,
|
self.pipe = Popen(self._compose_command_args(), stdout=PIPE,
|
||||||
bufsize = 1024, shell = True, stderr = STDOUT, stdin = PIPE)
|
bufsize = 1024, shell = True, stderr = STDOUT, stdin = PIPE)
|
||||||
if self.commandtimeout >= 0:
|
if self.commandtimeout >= 0:
|
||||||
self.endtime = self.idlequeue.current_time() + self.commandtimeout
|
self.endtime = self.idlequeue.current_time() + self.commandtimeout
|
||||||
self.idlequeue.set_alarm(self.wait_child, 0.1)
|
self.idlequeue.set_alarm(self.wait_child, 0.1)
|
||||||
|
|
||||||
def _start_posix(self):
|
def _start_posix(self):
|
||||||
self.pipe = os.popen(self._compose_command_line())
|
self.pipe = os.popen(self._compose_command_line())
|
||||||
self.fd = self.pipe.fileno()
|
self.fd = self.pipe.fileno()
|
||||||
|
@ -158,19 +158,19 @@ class IdleCommand(IdleObject):
|
||||||
self.idlequeue.plug_idle(self, False, True)
|
self.idlequeue.plug_idle(self, False, True)
|
||||||
if self.commandtimeout >= 0:
|
if self.commandtimeout >= 0:
|
||||||
self.idlequeue.set_read_timeout(self.fd, self.commandtimeout)
|
self.idlequeue.set_read_timeout(self.fd, self.commandtimeout)
|
||||||
|
|
||||||
def end(self):
|
def end(self):
|
||||||
self.idlequeue.unplug_idle(self.fd)
|
self.idlequeue.unplug_idle(self.fd)
|
||||||
try:
|
try:
|
||||||
self.pipe.close()
|
self.pipe.close()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def pollend(self):
|
def pollend(self):
|
||||||
self.idlequeue.remove_timeout(self.fd)
|
self.idlequeue.remove_timeout(self.fd)
|
||||||
self.end()
|
self.end()
|
||||||
self._return_result()
|
self._return_result()
|
||||||
|
|
||||||
def pollin(self):
|
def pollin(self):
|
||||||
try:
|
try:
|
||||||
res = self.pipe.read()
|
res = self.pipe.read()
|
||||||
|
@ -180,25 +180,25 @@ class IdleCommand(IdleObject):
|
||||||
return self.pollend()
|
return self.pollend()
|
||||||
else:
|
else:
|
||||||
self.result += res
|
self.result += res
|
||||||
|
|
||||||
def read_timeout(self):
|
def read_timeout(self):
|
||||||
self.end()
|
self.end()
|
||||||
self._return_result()
|
self._return_result()
|
||||||
|
|
||||||
|
|
||||||
class IdleQueue:
|
class IdleQueue:
|
||||||
'''
|
'''
|
||||||
IdleQueue provide three distinct time based features. Uses select.poll()
|
IdleQueue provide three distinct time based features. Uses select.poll()
|
||||||
|
|
||||||
1. Alarm timeout: Execute a callback after foo seconds
|
1. Alarm timeout: Execute a callback after foo seconds
|
||||||
2. Timeout event: Call read_timeout() of an plugged object if a timeout
|
2. Timeout event: Call read_timeout() of an plugged object if a timeout
|
||||||
has been set, but not removed in time.
|
has been set, but not removed in time.
|
||||||
3. Check file descriptor of plugged objects for read, write and error
|
3. Check file descriptor of plugged objects for read, write and error
|
||||||
events
|
events
|
||||||
'''
|
'''
|
||||||
# (timeout, boolean)
|
# (timeout, boolean)
|
||||||
# Boolean is True if timeout is specified in seconds, False means miliseconds
|
# Boolean is True if timeout is specified in seconds, False means miliseconds
|
||||||
PROCESS_TIMEOUT = (200, False)
|
PROCESS_TIMEOUT = (200, False)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.queue = {}
|
self.queue = {}
|
||||||
|
@ -219,7 +219,7 @@ class IdleQueue:
|
||||||
self.selector = select.poll()
|
self.selector = select.poll()
|
||||||
|
|
||||||
def set_alarm(self, alarm_cb, seconds):
|
def set_alarm(self, alarm_cb, seconds):
|
||||||
'''
|
'''
|
||||||
Sets up a new alarm. alarm_cb will be called after specified seconds.
|
Sets up a new alarm. alarm_cb will be called after specified seconds.
|
||||||
'''
|
'''
|
||||||
alarm_time = self.current_time() + seconds
|
alarm_time = self.current_time() + seconds
|
||||||
|
@ -230,24 +230,24 @@ class IdleQueue:
|
||||||
self.alarms[alarm_time] = [alarm_cb]
|
self.alarms[alarm_time] = [alarm_cb]
|
||||||
return alarm_time
|
return alarm_time
|
||||||
|
|
||||||
def remove_alarm(self, alarm_cb, alarm_time):
|
def remove_alarm(self, alarm_cb, alarm_time):
|
||||||
'''
|
'''
|
||||||
Removes alarm callback alarm_cb scheduled on alarm_time.
|
Removes alarm callback alarm_cb scheduled on alarm_time.
|
||||||
Returns True if it was removed sucessfully, otherwise False
|
Returns True if it was removed sucessfully, otherwise False
|
||||||
'''
|
'''
|
||||||
if not alarm_time in self.alarms:
|
if not alarm_time in self.alarms:
|
||||||
return False
|
return False
|
||||||
i = -1
|
i = -1
|
||||||
for i in range(len(self.alarms[alarm_time])):
|
for i in range(len(self.alarms[alarm_time])):
|
||||||
# let's not modify the list inside the loop
|
# let's not modify the list inside the loop
|
||||||
if self.alarms[alarm_time][i] is alarm_cb:
|
if self.alarms[alarm_time][i] is alarm_cb:
|
||||||
break
|
break
|
||||||
if i != -1:
|
if i != -1:
|
||||||
del self.alarms[alarm_time][i]
|
del self.alarms[alarm_time][i]
|
||||||
if self.alarms[alarm_time] == []:
|
if self.alarms[alarm_time] == []:
|
||||||
del self.alarms[alarm_time]
|
del self.alarms[alarm_time]
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def remove_timeout(self, fd, timeout=None):
|
def remove_timeout(self, fd, timeout=None):
|
||||||
|
@ -298,7 +298,7 @@ class IdleQueue:
|
||||||
log.debug('Calling %s for fd %s' % (func, fd))
|
log.debug('Calling %s for fd %s' % (func, fd))
|
||||||
func()
|
func()
|
||||||
else:
|
else:
|
||||||
log.debug('Calling read_timeout for fd %s' % fd)
|
log.debug('Calling read_timeout for fd %s' % fd)
|
||||||
self.queue[fd].read_timeout()
|
self.queue[fd].read_timeout()
|
||||||
self.remove_timeout(fd, timeout)
|
self.remove_timeout(fd, timeout)
|
||||||
|
|
||||||
|
@ -314,7 +314,7 @@ class IdleQueue:
|
||||||
|
|
||||||
def plug_idle(self, obj, writable=True, readable=True):
|
def plug_idle(self, obj, writable=True, readable=True):
|
||||||
'''
|
'''
|
||||||
Plug an IdleObject into idlequeue. Filedescriptor fd must be set.
|
Plug an IdleObject into idlequeue. Filedescriptor fd must be set.
|
||||||
|
|
||||||
:param obj: the IdleObject
|
:param obj: the IdleObject
|
||||||
:param writable: True if obj has data to sent
|
:param writable: True if obj has data to sent
|
||||||
|
@ -371,7 +371,7 @@ class IdleQueue:
|
||||||
obj.pollout()
|
obj.pollout()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
elif flags & IS_CLOSED:
|
elif flags & IS_CLOSED:
|
||||||
# io error, don't expect more events
|
# io error, don't expect more events
|
||||||
self.remove_timeout(obj.fd)
|
self.remove_timeout(obj.fd)
|
||||||
self.unplug_idle(obj.fd)
|
self.unplug_idle(obj.fd)
|
||||||
|
@ -472,7 +472,7 @@ class GlibIdleQueue(IdleQueue):
|
||||||
'''
|
'''
|
||||||
# (timeout, boolean)
|
# (timeout, boolean)
|
||||||
# Boolean is True if timeout is specified in seconds, False means miliseconds
|
# Boolean is True if timeout is specified in seconds, False means miliseconds
|
||||||
PROCESS_TIMEOUT = (2, True)
|
PROCESS_TIMEOUT = (2, True)
|
||||||
|
|
||||||
def _init_idle(self):
|
def _init_idle(self):
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -23,12 +23,12 @@ log = logging.getLogger('gajim.c.x.plugin')
|
||||||
|
|
||||||
class PlugIn:
|
class PlugIn:
|
||||||
'''
|
'''
|
||||||
Abstract xmpppy plugin infrastructure code, providing plugging in/out and
|
Abstract xmpppy plugin infrastructure code, providing plugging in/out and
|
||||||
debugging functionality.
|
debugging functionality.
|
||||||
|
|
||||||
Inherit to develop pluggable objects. No code change on the owner class
|
Inherit to develop pluggable objects. No code change on the owner class
|
||||||
required (the object where we plug into)
|
required (the object where we plug into)
|
||||||
|
|
||||||
For every instance of PlugIn class the 'owner' is the class in what the plug
|
For every instance of PlugIn class the 'owner' is the class in what the plug
|
||||||
was plugged.
|
was plugged.
|
||||||
'''
|
'''
|
||||||
|
@ -38,7 +38,7 @@ class PlugIn:
|
||||||
def PlugIn(self, owner):
|
def PlugIn(self, owner):
|
||||||
'''
|
'''
|
||||||
Attach to owner and register ourself and our _exported_methods in it.
|
Attach to owner and register ourself and our _exported_methods in it.
|
||||||
If defined by a subclass, call self.plugin(owner) to execute hook
|
If defined by a subclass, call self.plugin(owner) to execute hook
|
||||||
code after plugging.
|
code after plugging.
|
||||||
'''
|
'''
|
||||||
self._owner=owner
|
self._owner=owner
|
||||||
|
@ -57,7 +57,7 @@ class PlugIn:
|
||||||
owner.__dict__['Dispatcher']=self
|
owner.__dict__['Dispatcher']=self
|
||||||
else:
|
else:
|
||||||
owner.__dict__[self.__class__.__name__]=self
|
owner.__dict__[self.__class__.__name__]=self
|
||||||
|
|
||||||
# Execute hook
|
# Execute hook
|
||||||
if hasattr(self,'plugin'):
|
if hasattr(self,'plugin'):
|
||||||
return self.plugin(owner)
|
return self.plugin(owner)
|
||||||
|
@ -82,12 +82,12 @@ class PlugIn:
|
||||||
if hasattr(self,'plugout'):
|
if hasattr(self,'plugout'):
|
||||||
return self.plugout()
|
return self.plugout()
|
||||||
del self._owner
|
del self._owner
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_instance(cls, *args, **kwargs):
|
def get_instance(cls, *args, **kwargs):
|
||||||
'''
|
'''
|
||||||
Factory Method for object creation.
|
Factory Method for object creation.
|
||||||
|
|
||||||
Use this instead of directly initializing the class in order to make
|
Use this instead of directly initializing the class in order to make
|
||||||
unit testing easier. For testing, this method can be patched to inject
|
unit testing easier. For testing, this method can be patched to inject
|
||||||
mock objects.
|
mock objects.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
## proxy_connectors.py
|
## proxy_connectors.py
|
||||||
## based on transports_nb.py
|
## based on transports_nb.py
|
||||||
##
|
##
|
||||||
## Copyright (C) 2003-2004 Alexey "Snake" Nezhdanov
|
## Copyright (C) 2003-2004 Alexey "Snake" Nezhdanov
|
||||||
## modified by Dimitur Kirov <dkirov@gmail.com>
|
## modified by Dimitur Kirov <dkirov@gmail.com>
|
||||||
## modified by Tomas Karasek <tom.to.the.k@gmail.com>
|
## modified by Tomas Karasek <tom.to.the.k@gmail.com>
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
## GNU General Public License for more details.
|
## GNU General Public License for more details.
|
||||||
'''
|
'''
|
||||||
Module containing classes for proxy connecting. So far its HTTP CONNECT
|
Module containing classes for proxy connecting. So far its HTTP CONNECT
|
||||||
and SOCKS5 proxy.
|
and SOCKS5 proxy.
|
||||||
Authentication to NTLM (Microsoft implementation) proxies can be next.
|
Authentication to NTLM (Microsoft implementation) proxies can be next.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class ProxyConnector:
|
||||||
|
|
||||||
:param send_method: transport send method
|
:param send_method: transport send method
|
||||||
:param onreceive: method to set on_receive callbacks
|
:param onreceive: method to set on_receive callbacks
|
||||||
:param old_on_receive: on_receive callback that should be set when
|
:param old_on_receive: on_receive callback that should be set when
|
||||||
proxy connection was successful
|
proxy connection was successful
|
||||||
:param on_success: called after proxy connection was successfully opened
|
:param on_success: called after proxy connection was successfully opened
|
||||||
:param on_failure: called when errors occured while connecting
|
:param on_failure: called when errors occured while connecting
|
||||||
|
@ -55,12 +55,12 @@ class ProxyConnector:
|
||||||
self.old_on_receive = old_on_receive
|
self.old_on_receive = old_on_receive
|
||||||
|
|
||||||
self.start_connecting()
|
self.start_connecting()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_instance(cls, *args, **kwargs):
|
def get_instance(cls, *args, **kwargs):
|
||||||
'''
|
'''
|
||||||
Factory Method for object creation.
|
Factory Method for object creation.
|
||||||
|
|
||||||
Use this instead of directly initializing the class in order to make
|
Use this instead of directly initializing the class in order to make
|
||||||
unit testing much easier.
|
unit testing much easier.
|
||||||
'''
|
'''
|
||||||
|
@ -72,7 +72,7 @@ class ProxyConnector:
|
||||||
def connecting_over(self):
|
def connecting_over(self):
|
||||||
self.onreceive(self.old_on_receive)
|
self.onreceive(self.old_on_receive)
|
||||||
self.on_success()
|
self.on_success()
|
||||||
|
|
||||||
class HTTPCONNECTConnector(ProxyConnector):
|
class HTTPCONNECTConnector(ProxyConnector):
|
||||||
def start_connecting(self):
|
def start_connecting(self):
|
||||||
'''
|
'''
|
||||||
|
@ -93,14 +93,14 @@ class HTTPCONNECTConnector(ProxyConnector):
|
||||||
connector.append('\r\n')
|
connector.append('\r\n')
|
||||||
self.onreceive(self._on_headers_sent)
|
self.onreceive(self._on_headers_sent)
|
||||||
self.send('\r\n'.join(connector))
|
self.send('\r\n'.join(connector))
|
||||||
|
|
||||||
def _on_headers_sent(self, reply):
|
def _on_headers_sent(self, reply):
|
||||||
if reply is None:
|
if reply is None:
|
||||||
return
|
return
|
||||||
self.reply = reply.replace('\r', '')
|
self.reply = reply.replace('\r', '')
|
||||||
try:
|
try:
|
||||||
proto, code, desc = reply.split('\n')[0].split(' ', 2)
|
proto, code, desc = reply.split('\n')[0].split(' ', 2)
|
||||||
except:
|
except:
|
||||||
log.error("_on_headers_sent:", exc_info=True)
|
log.error("_on_headers_sent:", exc_info=True)
|
||||||
#traceback.print_exc()
|
#traceback.print_exc()
|
||||||
self.on_failure('Invalid proxy reply')
|
self.on_failure('Invalid proxy reply')
|
||||||
|
@ -117,7 +117,7 @@ class HTTPCONNECTConnector(ProxyConnector):
|
||||||
class SOCKS5Connector(ProxyConnector):
|
class SOCKS5Connector(ProxyConnector):
|
||||||
'''
|
'''
|
||||||
SOCKS5 proxy connection class. Allows to use SOCKS5 proxies with
|
SOCKS5 proxy connection class. Allows to use SOCKS5 proxies with
|
||||||
(optionally) simple authentication (only USERNAME/PASSWORD auth).
|
(optionally) simple authentication (only USERNAME/PASSWORD auth).
|
||||||
'''
|
'''
|
||||||
def start_connecting(self):
|
def start_connecting(self):
|
||||||
log.info('Proxy server contacted, performing authentification')
|
log.info('Proxy server contacted, performing authentification')
|
||||||
|
|
|
@ -30,7 +30,7 @@ log = logging.getLogger('gajim.c.x.roster_nb')
|
||||||
|
|
||||||
class NonBlockingRoster(PlugIn):
|
class NonBlockingRoster(PlugIn):
|
||||||
''' Defines a plenty of methods that will allow you to manage roster.
|
''' Defines a plenty of methods that will allow you to manage roster.
|
||||||
Also automatically track presences from remote JIDs taking into
|
Also automatically track presences from remote JIDs taking into
|
||||||
account that every JID can have multiple resources connected. Does not
|
account that every JID can have multiple resources connected. Does not
|
||||||
currently support 'error' presences.
|
currently support 'error' presences.
|
||||||
You can also use mapping interface for access to the internal representation of
|
You can also use mapping interface for access to the internal representation of
|
||||||
|
@ -44,7 +44,7 @@ class NonBlockingRoster(PlugIn):
|
||||||
self._exported_methods=[self.getRoster]
|
self._exported_methods=[self.getRoster]
|
||||||
|
|
||||||
def Request(self,force=0):
|
def Request(self,force=0):
|
||||||
''' Request roster from server if it were not yet requested
|
''' Request roster from server if it were not yet requested
|
||||||
(or if the 'force' argument is set). '''
|
(or if the 'force' argument is set). '''
|
||||||
if self.set is None: self.set=0
|
if self.set is None: self.set=0
|
||||||
elif not force: return
|
elif not force: return
|
||||||
|
@ -182,7 +182,7 @@ class NonBlockingRoster(PlugIn):
|
||||||
''' Authorise JID 'jid'. Works only if these JID requested auth previously. '''
|
''' Authorise JID 'jid'. Works only if these JID requested auth previously. '''
|
||||||
self._owner.send(Presence(jid,'subscribed'))
|
self._owner.send(Presence(jid,'subscribed'))
|
||||||
def Unauthorize(self,jid):
|
def Unauthorize(self,jid):
|
||||||
''' Unauthorise JID 'jid'. Use for declining authorisation request
|
''' Unauthorise JID 'jid'. Use for declining authorisation request
|
||||||
or for removing existing authorization. '''
|
or for removing existing authorization. '''
|
||||||
self._owner.send(Presence(jid,'unsubscribed'))
|
self._owner.send(Presence(jid,'unsubscribed'))
|
||||||
def getRaw(self):
|
def getRaw(self):
|
||||||
|
|
|
@ -438,7 +438,7 @@ class NodeBuilder:
|
||||||
def handle_namespace_start(self, prefix, uri):
|
def handle_namespace_start(self, prefix, uri):
|
||||||
'''XML Parser callback. Used internally'''
|
'''XML Parser callback. Used internally'''
|
||||||
self.check_data_buffer()
|
self.check_data_buffer()
|
||||||
|
|
||||||
def getDom(self):
|
def getDom(self):
|
||||||
''' Returns just built Node. '''
|
''' Returns just built Node. '''
|
||||||
self.check_data_buffer()
|
self.check_data_buffer()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
## tls_nb.py
|
## tls_nb.py
|
||||||
## based on transports_nb.py
|
## based on transports_nb.py
|
||||||
##
|
##
|
||||||
## Copyright (C) 2003-2004 Alexey "Snake" Nezhdanov
|
## Copyright (C) 2003-2004 Alexey "Snake" Nezhdanov
|
||||||
## modified by Dimitur Kirov <dkirov@gmail.com>
|
## modified by Dimitur Kirov <dkirov@gmail.com>
|
||||||
## modified by Tomas Karasek <tom.to.the.k@gmail.com>
|
## modified by Tomas Karasek <tom.to.the.k@gmail.com>
|
||||||
|
@ -228,7 +228,7 @@ class StdlibSSLWrapper(SSLWrapper):
|
||||||
class NonBlockingTLS(PlugIn):
|
class NonBlockingTLS(PlugIn):
|
||||||
'''
|
'''
|
||||||
TLS connection used to encrypts already estabilished tcp connection.
|
TLS connection used to encrypts already estabilished tcp connection.
|
||||||
|
|
||||||
Can be plugged into NonBlockingTCP and will make use of StdlibSSLWrapper or
|
Can be plugged into NonBlockingTCP and will make use of StdlibSSLWrapper or
|
||||||
PyOpenSSLWrapper.
|
PyOpenSSLWrapper.
|
||||||
'''
|
'''
|
||||||
|
@ -243,10 +243,10 @@ class NonBlockingTLS(PlugIn):
|
||||||
self.mycerts = mycerts
|
self.mycerts = mycerts
|
||||||
|
|
||||||
# from ssl.h (partial extract)
|
# from ssl.h (partial extract)
|
||||||
ssl_h_bits = { "SSL_ST_CONNECT": 0x1000, "SSL_ST_ACCEPT": 0x2000,
|
ssl_h_bits = { "SSL_ST_CONNECT": 0x1000, "SSL_ST_ACCEPT": 0x2000,
|
||||||
"SSL_CB_LOOP": 0x01, "SSL_CB_EXIT": 0x02,
|
"SSL_CB_LOOP": 0x01, "SSL_CB_EXIT": 0x02,
|
||||||
"SSL_CB_READ": 0x04, "SSL_CB_WRITE": 0x08,
|
"SSL_CB_READ": 0x04, "SSL_CB_WRITE": 0x08,
|
||||||
"SSL_CB_ALERT": 0x4000,
|
"SSL_CB_ALERT": 0x4000,
|
||||||
"SSL_CB_HANDSHAKE_START": 0x10, "SSL_CB_HANDSHAKE_DONE": 0x20}
|
"SSL_CB_HANDSHAKE_START": 0x10, "SSL_CB_HANDSHAKE_DONE": 0x20}
|
||||||
|
|
||||||
def plugin(self, owner):
|
def plugin(self, owner):
|
||||||
|
@ -281,7 +281,7 @@ class NonBlockingTLS(PlugIn):
|
||||||
typedict = {OpenSSL.crypto.TYPE_RSA: "RSA",
|
typedict = {OpenSSL.crypto.TYPE_RSA: "RSA",
|
||||||
OpenSSL.crypto.TYPE_DSA: "DSA"}
|
OpenSSL.crypto.TYPE_DSA: "DSA"}
|
||||||
print >> stream, "PKey bits:", pkey.bits()
|
print >> stream, "PKey bits:", pkey.bits()
|
||||||
print >> stream, "PKey type: %s (%d)" % (typedict.get(pkey.type(),
|
print >> stream, "PKey type: %s (%d)" % (typedict.get(pkey.type(),
|
||||||
"Unknown"), pkey.type())
|
"Unknown"), pkey.type())
|
||||||
|
|
||||||
def _startSSL(self):
|
def _startSSL(self):
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
## GNU General Public License for more details.
|
## GNU General Public License for more details.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Transports are objects responsible for connecting to XMPP server and putting
|
Transports are objects responsible for connecting to XMPP server and putting
|
||||||
data to wrapped sockets in in desired form (SSL, TLS, TCP, for HTTP proxy,
|
data to wrapped sockets in in desired form (SSL, TLS, TCP, for HTTP proxy,
|
||||||
for SOCKS5 proxy...)
|
for SOCKS5 proxy...)
|
||||||
|
|
||||||
|
@ -55,13 +55,13 @@ def get_proxy_data_from_dict(proxy):
|
||||||
tcp_host, tcp_port, proxy_user, proxy_pass = None, None, None, None
|
tcp_host, tcp_port, proxy_user, proxy_pass = None, None, None, None
|
||||||
proxy_type = proxy['type']
|
proxy_type = proxy['type']
|
||||||
if proxy_type == 'bosh' and not proxy['bosh_useproxy']:
|
if proxy_type == 'bosh' and not proxy['bosh_useproxy']:
|
||||||
# with BOSH not over proxy we have to parse the hostname from BOSH URI
|
# with BOSH not over proxy we have to parse the hostname from BOSH URI
|
||||||
tcp_host, tcp_port = urisplit(proxy['bosh_uri'])[1], proxy['bosh_port']
|
tcp_host, tcp_port = urisplit(proxy['bosh_uri'])[1], proxy['bosh_port']
|
||||||
tcp_host = tcp_host.split(':')[0]
|
tcp_host = tcp_host.split(':')[0]
|
||||||
else:
|
else:
|
||||||
# with proxy!=bosh or with bosh over HTTP proxy we're connecting to proxy
|
# with proxy!=bosh or with bosh over HTTP proxy we're connecting to proxy
|
||||||
# machine
|
# machine
|
||||||
tcp_host, tcp_port = proxy['host'], proxy['port']
|
tcp_host, tcp_port = proxy['host'], proxy['port']
|
||||||
if proxy['useauth']:
|
if proxy['useauth']:
|
||||||
proxy_user, proxy_pass = proxy['user'], proxy['pass']
|
proxy_user, proxy_pass = proxy['user'], proxy['pass']
|
||||||
return tcp_host, tcp_port, proxy_user, proxy_pass
|
return tcp_host, tcp_port, proxy_user, proxy_pass
|
||||||
|
@ -102,13 +102,13 @@ class NonBlockingTransport(PlugIn):
|
||||||
'''
|
'''
|
||||||
Each trasport class can have different constructor but it has to have at
|
Each trasport class can have different constructor but it has to have at
|
||||||
least all the arguments of NonBlockingTransport constructor.
|
least all the arguments of NonBlockingTransport constructor.
|
||||||
|
|
||||||
:param raise_event: callback for monitoring of sent and received data
|
:param raise_event: callback for monitoring of sent and received data
|
||||||
:param on_disconnect: callback called on disconnection during runtime
|
:param on_disconnect: callback called on disconnection during runtime
|
||||||
:param idlequeue: processing idlequeue
|
:param idlequeue: processing idlequeue
|
||||||
:param estabilish_tls: boolean whether to estabilish TLS connection after
|
:param estabilish_tls: boolean whether to estabilish TLS connection after
|
||||||
TCP connection is done
|
TCP connection is done
|
||||||
:param certs: tuple of (cacerts, mycerts) see constructor of
|
:param certs: tuple of (cacerts, mycerts) see constructor of
|
||||||
tls_nb.NonBlockingTLS for more details
|
tls_nb.NonBlockingTLS for more details
|
||||||
'''
|
'''
|
||||||
PlugIn.__init__(self)
|
PlugIn.__init__(self)
|
||||||
|
@ -121,10 +121,10 @@ class NonBlockingTransport(PlugIn):
|
||||||
self.server = None
|
self.server = None
|
||||||
self.port = None
|
self.port = None
|
||||||
self.conn_5tuple = None
|
self.conn_5tuple = None
|
||||||
self.set_state(DISCONNECTED)
|
self.set_state(DISCONNECTED)
|
||||||
self.estabilish_tls = estabilish_tls
|
self.estabilish_tls = estabilish_tls
|
||||||
self.certs = certs
|
self.certs = certs
|
||||||
# type of used ssl lib (if any) will be assigned to this member var
|
# type of used ssl lib (if any) will be assigned to this member var
|
||||||
self.ssl_lib = None
|
self.ssl_lib = None
|
||||||
self._exported_methods=[self.onreceive, self.set_send_timeout,
|
self._exported_methods=[self.onreceive, self.set_send_timeout,
|
||||||
self.set_send_timeout2, self.set_timeout, self.remove_timeout,
|
self.set_send_timeout2, self.set_timeout, self.remove_timeout,
|
||||||
|
@ -214,13 +214,13 @@ class NonBlockingTransport(PlugIn):
|
||||||
def _tcp_connecting_started(self):
|
def _tcp_connecting_started(self):
|
||||||
self.set_state(CONNECTING)
|
self.set_state(CONNECTING)
|
||||||
|
|
||||||
def read_timeout(self):
|
def read_timeout(self):
|
||||||
''' called when there's no response from server in defined timeout '''
|
''' called when there's no response from server in defined timeout '''
|
||||||
if self.on_timeout:
|
if self.on_timeout:
|
||||||
self.on_timeout()
|
self.on_timeout()
|
||||||
self.renew_send_timeout()
|
self.renew_send_timeout()
|
||||||
|
|
||||||
def read_timeout2(self):
|
def read_timeout2(self):
|
||||||
''' called when there's no response from server in defined timeout '''
|
''' called when there's no response from server in defined timeout '''
|
||||||
if self.on_timeout2:
|
if self.on_timeout2:
|
||||||
self.on_timeout2()
|
self.on_timeout2()
|
||||||
|
@ -289,7 +289,7 @@ class NonBlockingTCP(NonBlockingTransport, IdleObject):
|
||||||
|
|
||||||
self.proxy_dict = proxy_dict
|
self.proxy_dict = proxy_dict
|
||||||
self.on_remote_disconnect = self.disconnect
|
self.on_remote_disconnect = self.disconnect
|
||||||
|
|
||||||
# FIXME: transport should not be aware xmpp
|
# FIXME: transport should not be aware xmpp
|
||||||
def start_disconnect(self):
|
def start_disconnect(self):
|
||||||
NonBlockingTransport.start_disconnect(self)
|
NonBlockingTransport.start_disconnect(self)
|
||||||
|
@ -312,16 +312,16 @@ class NonBlockingTCP(NonBlockingTransport, IdleObject):
|
||||||
self._send = self._sock.send
|
self._send = self._sock.send
|
||||||
self._recv = self._sock.recv
|
self._recv = self._sock.recv
|
||||||
self.fd = self._sock.fileno()
|
self.fd = self._sock.fileno()
|
||||||
|
|
||||||
# we want to be notified when send is possible to connected socket because
|
# we want to be notified when send is possible to connected socket because
|
||||||
# it means the TCP connection is estabilished
|
# it means the TCP connection is estabilished
|
||||||
self._plug_idle(writable=True, readable=False)
|
self._plug_idle(writable=True, readable=False)
|
||||||
self.peerhost = None
|
self.peerhost = None
|
||||||
|
|
||||||
# variable for errno symbol that will be found from exception raised
|
# variable for errno symbol that will be found from exception raised
|
||||||
# from connect()
|
# from connect()
|
||||||
errnum = 0
|
errnum = 0
|
||||||
|
|
||||||
# set timeout for TCP connecting - if nonblocking connect() fails, pollend
|
# set timeout for TCP connecting - if nonblocking connect() fails, pollend
|
||||||
# is called. If if succeeds pollout is called.
|
# is called. If if succeeds pollout is called.
|
||||||
self.idlequeue.set_read_timeout(self.fd, CONNECT_TIMEOUT_SECONDS)
|
self.idlequeue.set_read_timeout(self.fd, CONNECT_TIMEOUT_SECONDS)
|
||||||
|
@ -334,12 +334,12 @@ class NonBlockingTCP(NonBlockingTransport, IdleObject):
|
||||||
|
|
||||||
if errnum in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK):
|
if errnum in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK):
|
||||||
# connecting in progress
|
# connecting in progress
|
||||||
log.info('After NB connect() of %s. "%s" raised => CONNECTING' %
|
log.info('After NB connect() of %s. "%s" raised => CONNECTING' %
|
||||||
(id(self), errstr))
|
(id(self), errstr))
|
||||||
self._tcp_connecting_started()
|
self._tcp_connecting_started()
|
||||||
return
|
return
|
||||||
|
|
||||||
# if there was some other exception, call failure callback and unplug
|
# if there was some other exception, call failure callback and unplug
|
||||||
# transport which will also remove read_timeouts for descriptor
|
# transport which will also remove read_timeouts for descriptor
|
||||||
self._on_connect_failure('Exception while connecting to %s:%s - %s %s' %
|
self._on_connect_failure('Exception while connecting to %s:%s - %s %s' %
|
||||||
(self.server, self.port, errnum, errstr))
|
(self.server, self.port, errnum, errstr))
|
||||||
|
@ -481,7 +481,7 @@ class NonBlockingTCP(NonBlockingTransport, IdleObject):
|
||||||
def _plug_idle(self, writable, readable):
|
def _plug_idle(self, writable, readable):
|
||||||
'''
|
'''
|
||||||
Plugs file descriptor of socket to Idlequeue.
|
Plugs file descriptor of socket to Idlequeue.
|
||||||
|
|
||||||
Plugged socket will be watched for "send possible" or/and "recv possible"
|
Plugged socket will be watched for "send possible" or/and "recv possible"
|
||||||
events. pollin() callback is invoked on "recv possible", pollout() on
|
events. pollin() callback is invoked on "recv possible", pollout() on
|
||||||
"send_possible".
|
"send_possible".
|
||||||
|
@ -618,7 +618,7 @@ class NonBlockingHTTP(NonBlockingTCP):
|
||||||
|
|
||||||
# buffer for partial responses
|
# buffer for partial responses
|
||||||
self.recvbuff = ''
|
self.recvbuff = ''
|
||||||
self.expected_length = 0
|
self.expected_length = 0
|
||||||
self.pending_requests = 0
|
self.pending_requests = 0
|
||||||
self.on_http_request_possible = on_http_request_possible
|
self.on_http_request_possible = on_http_request_possible
|
||||||
self.last_recv_time = 0
|
self.last_recv_time = 0
|
||||||
|
@ -641,7 +641,7 @@ class NonBlockingHTTP(NonBlockingTCP):
|
||||||
try:
|
try:
|
||||||
statusline, headers, self.recvbuff = self.parse_http_message(data)
|
statusline, headers, self.recvbuff = self.parse_http_message(data)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
return
|
return
|
||||||
if statusline[1] != '200':
|
if statusline[1] != '200':
|
||||||
log.error('HTTP Error: %s %s' % (statusline[1], statusline[2]))
|
log.error('HTTP Error: %s %s' % (statusline[1], statusline[2]))
|
||||||
|
|
|
@ -788,14 +788,14 @@ class PreferencesWindow:
|
||||||
gajim.config.set('trayicon', 'on_event')
|
gajim.config.set('trayicon', 'on_event')
|
||||||
else:
|
else:
|
||||||
gajim.config.set('trayicon', 'always')
|
gajim.config.set('trayicon', 'always')
|
||||||
|
|
||||||
def on_advanced_notifications_button_clicked(self, widget):
|
def on_advanced_notifications_button_clicked(self, widget):
|
||||||
dialogs.AdvancedNotificationsWindow()
|
dialogs.AdvancedNotificationsWindow()
|
||||||
|
|
||||||
def on_play_sounds_checkbutton_toggled(self, widget):
|
def on_play_sounds_checkbutton_toggled(self, widget):
|
||||||
self.on_checkbutton_toggled(widget, 'sounds_on',
|
self.on_checkbutton_toggled(widget, 'sounds_on',
|
||||||
[self.xml.get_widget('manage_sounds_button')])
|
[self.xml.get_widget('manage_sounds_button')])
|
||||||
|
|
||||||
def on_manage_sounds_button_clicked(self, widget):
|
def on_manage_sounds_button_clicked(self, widget):
|
||||||
if self.sounds_preferences is None:
|
if self.sounds_preferences is None:
|
||||||
self.sounds_preferences = ManageSoundsWindow()
|
self.sounds_preferences = ManageSoundsWindow()
|
||||||
|
@ -3558,7 +3558,7 @@ class ManageSoundsWindow:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.xml = gtkgui_helpers.get_glade('manage_sounds_window.glade')
|
self.xml = gtkgui_helpers.get_glade('manage_sounds_window.glade')
|
||||||
self.window = self.xml.get_widget('manage_sounds_window')
|
self.window = self.xml.get_widget('manage_sounds_window')
|
||||||
|
|
||||||
# sounds treeview
|
# sounds treeview
|
||||||
self.sound_tree = self.xml.get_widget('sounds_treeview')
|
self.sound_tree = self.xml.get_widget('sounds_treeview')
|
||||||
|
|
||||||
|
@ -3581,14 +3581,14 @@ class ManageSoundsWindow:
|
||||||
col.set_attributes(renderer, text = 1)
|
col.set_attributes(renderer, text = 1)
|
||||||
|
|
||||||
self.fill_sound_treeview()
|
self.fill_sound_treeview()
|
||||||
|
|
||||||
self.xml.signal_autoconnect(self)
|
self.xml.signal_autoconnect(self)
|
||||||
|
|
||||||
self.sound_tree.get_model().connect('row-changed',
|
self.sound_tree.get_model().connect('row-changed',
|
||||||
self.on_sounds_treemodel_row_changed)
|
self.on_sounds_treemodel_row_changed)
|
||||||
|
|
||||||
self.window.show_all()
|
self.window.show_all()
|
||||||
|
|
||||||
def on_sounds_treemodel_row_changed(self, model, path, iter_):
|
def on_sounds_treemodel_row_changed(self, model, path, iter_):
|
||||||
sound_event = model[iter_][3].decode('utf-8')
|
sound_event = model[iter_][3].decode('utf-8')
|
||||||
gajim.config.set_per('soundevents', sound_event, 'enabled',
|
gajim.config.set_per('soundevents', sound_event, 'enabled',
|
||||||
|
@ -3596,7 +3596,7 @@ class ManageSoundsWindow:
|
||||||
gajim.config.set_per('soundevents', sound_event, 'path',
|
gajim.config.set_per('soundevents', sound_event, 'path',
|
||||||
model[iter_][2].decode('utf-8'))
|
model[iter_][2].decode('utf-8'))
|
||||||
gajim.interface.save_config()
|
gajim.interface.save_config()
|
||||||
|
|
||||||
def sound_toggled_cb(self, cell, path):
|
def sound_toggled_cb(self, cell, path):
|
||||||
model = self.sound_tree.get_model()
|
model = self.sound_tree.get_model()
|
||||||
model[path][0] = not model[path][0]
|
model[path][0] = not model[path][0]
|
||||||
|
@ -3675,10 +3675,10 @@ class ManageSoundsWindow:
|
||||||
return
|
return
|
||||||
snd_event_config_name = model[iter_][3]
|
snd_event_config_name = model[iter_][3]
|
||||||
helpers.play_sound(snd_event_config_name)
|
helpers.play_sound(snd_event_config_name)
|
||||||
|
|
||||||
def on_close_button_clicked(self, widget):
|
def on_close_button_clicked(self, widget):
|
||||||
self.window.hide()
|
self.window.hide()
|
||||||
|
|
||||||
def on_manage_sounds_window_delete_event(self, widget, event):
|
def on_manage_sounds_window_delete_event(self, widget, event):
|
||||||
self.window.hide()
|
self.window.hide()
|
||||||
return True # do NOT destroy the window
|
return True # do NOT destroy the window
|
||||||
|
|
|
@ -2593,10 +2593,10 @@ class XMLConsoleWindow:
|
||||||
at_the_end = True
|
at_the_end = True
|
||||||
end_iter = buffer.get_end_iter()
|
end_iter = buffer.get_end_iter()
|
||||||
if kind == 'incoming':
|
if kind == 'incoming':
|
||||||
buffer.insert_with_tags_by_name(end_iter, '<!-- In -->\n',
|
buffer.insert_with_tags_by_name(end_iter, '<!-- In -->\n',
|
||||||
'in_comment')
|
'in_comment')
|
||||||
elif kind == 'outgoing':
|
elif kind == 'outgoing':
|
||||||
buffer.insert_with_tags_by_name(end_iter, '<!-- Out -->\n',
|
buffer.insert_with_tags_by_name(end_iter, '<!-- Out -->\n',
|
||||||
'out_comment')
|
'out_comment')
|
||||||
end_iter = buffer.get_end_iter()
|
end_iter = buffer.get_end_iter()
|
||||||
buffer.insert_with_tags_by_name(end_iter, stanza.replace('><', '>\n<') + \
|
buffer.insert_with_tags_by_name(end_iter, stanza.replace('><', '>\n<') + \
|
||||||
|
|
|
@ -259,7 +259,7 @@ egg_tray_icon_manager_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_
|
||||||
return GDK_FILTER_CONTINUE;
|
return GDK_FILTER_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
egg_tray_icon_unrealize (GtkWidget *widget)
|
egg_tray_icon_unrealize (GtkWidget *widget)
|
||||||
|
@ -568,7 +568,7 @@ egg_tray_icon_cancel_message (EggTrayIcon *icon,
|
||||||
{
|
{
|
||||||
g_return_if_fail (EGG_IS_TRAY_ICON (icon));
|
g_return_if_fail (EGG_IS_TRAY_ICON (icon));
|
||||||
g_return_if_fail (id > 0);
|
g_return_if_fail (id > 0);
|
||||||
#ifdef GDK_WINDOWING_X11
|
#ifdef GDK_WINDOWING_X11
|
||||||
egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_CANCEL_MESSAGE,
|
egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_CANCEL_MESSAGE,
|
||||||
(Window)gtk_plug_get_id (GTK_PLUG (icon)),
|
(Window)gtk_plug_get_id (GTK_PLUG (icon)),
|
||||||
id, 0, 0);
|
id, 0, 0);
|
||||||
|
|
|
@ -382,7 +382,7 @@ class ConsoleView(gtk.TextView):
|
||||||
def _showReturned(self, text):
|
def _showReturned(self, text):
|
||||||
'''
|
'''
|
||||||
Show returned text from last command and print new prompt.
|
Show returned text from last command and print new prompt.
|
||||||
|
|
||||||
@param text: Text to show.
|
@param text: Text to show.
|
||||||
@type text: string
|
@type text: string
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -119,7 +119,7 @@ class MessageTextView(gtk.TextView):
|
||||||
else:
|
else:
|
||||||
start, finish = buffer.get_bounds()
|
start, finish = buffer.get_bounds()
|
||||||
return (start, finish)
|
return (start, finish)
|
||||||
|
|
||||||
def set_tag(self, widget, tag):
|
def set_tag(self, widget, tag):
|
||||||
buffer = self.get_buffer()
|
buffer = self.get_buffer()
|
||||||
start, finish = self.get_active_iters()
|
start, finish = self.get_active_iters()
|
||||||
|
|
|
@ -39,17 +39,17 @@ def device_no_longer_active(self, *args):
|
||||||
'listen_to_network_manager') and connection.connected > 1:
|
'listen_to_network_manager') and connection.connected > 1:
|
||||||
connection._disconnectedReconnCB()
|
connection._disconnectedReconnCB()
|
||||||
|
|
||||||
def state_changed(state):
|
def state_changed(state):
|
||||||
'''For Network Manager 0.7'''
|
'''For Network Manager 0.7'''
|
||||||
if props.Get("org.freedesktop.NetworkManager", "State") == 3:
|
if props.Get("org.freedesktop.NetworkManager", "State") == 3:
|
||||||
for connection in gajim.connections.itervalues():
|
for connection in gajim.connections.itervalues():
|
||||||
if gajim.config.get_per('accounts', connection.name,
|
if gajim.config.get_per('accounts', connection.name,
|
||||||
'listen_to_network_manager') and connection.time_to_reconnect:
|
'listen_to_network_manager') and connection.time_to_reconnect:
|
||||||
connection._reconnect()
|
connection._reconnect()
|
||||||
else:
|
else:
|
||||||
for connection in gajim.connections.itervalues():
|
for connection in gajim.connections.itervalues():
|
||||||
if gajim.config.get_per('accounts', connection.name,
|
if gajim.config.get_per('accounts', connection.name,
|
||||||
'listen_to_network_manager') and connection.connected > 1:
|
'listen_to_network_manager') and connection.connected > 1:
|
||||||
connection._disconnectedReconnCB()
|
connection._disconnectedReconnCB()
|
||||||
|
|
||||||
supported = False
|
supported = False
|
||||||
|
@ -61,23 +61,23 @@ if sys.platform == 'darwin':
|
||||||
elif dbus_support.supported:
|
elif dbus_support.supported:
|
||||||
import dbus
|
import dbus
|
||||||
import dbus.glib
|
import dbus.glib
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from common.dbus_support import system_bus
|
from common.dbus_support import system_bus
|
||||||
|
|
||||||
bus = system_bus.bus()
|
bus = system_bus.bus()
|
||||||
|
|
||||||
if 'org.freedesktop.NetworkManager' in bus.list_names():
|
if 'org.freedesktop.NetworkManager' in bus.list_names():
|
||||||
nm_object = bus.get_object('org.freedesktop.NetworkManager',
|
nm_object = bus.get_object('org.freedesktop.NetworkManager',
|
||||||
'/org/freedesktop/NetworkManager')
|
'/org/freedesktop/NetworkManager')
|
||||||
props = dbus.Interface(nm_object,"org.freedesktop.DBus.Properties")
|
props = dbus.Interface(nm_object,"org.freedesktop.DBus.Properties")
|
||||||
bus.add_signal_receiver(state_changed,
|
bus.add_signal_receiver(state_changed,
|
||||||
'StateChanged',
|
'StateChanged',
|
||||||
'org.freedesktop.NetworkManager',
|
'org.freedesktop.NetworkManager',
|
||||||
'org.freedesktop.NetworkManager',
|
'org.freedesktop.NetworkManager',
|
||||||
'/org/freedesktop/NetworkManager')
|
'/org/freedesktop/NetworkManager')
|
||||||
supported = True
|
supported = True
|
||||||
|
|
||||||
except dbus.DBusException:
|
except dbus.DBusException:
|
||||||
try:
|
try:
|
||||||
if 'org.freedesktop.NetworkManager' in bus.list_names():
|
if 'org.freedesktop.NetworkManager' in bus.list_names():
|
||||||
|
|
|
@ -203,8 +203,8 @@ class Systray:
|
||||||
single_message_menuitem.set_sensitive(iskey)
|
single_message_menuitem.set_sensitive(iskey)
|
||||||
join_gc_menuitem.set_sensitive(iskey)
|
join_gc_menuitem.set_sensitive(iskey)
|
||||||
|
|
||||||
accounts_list = sorted(gajim.contacts.get_accounts())
|
accounts_list = sorted(gajim.contacts.get_accounts())
|
||||||
# items that get shown whether an account is zeroconf or not
|
# items that get shown whether an account is zeroconf or not
|
||||||
if connected_accounts > 1: # 2 or more connections? make submenus
|
if connected_accounts > 1: # 2 or more connections? make submenus
|
||||||
account_menu_for_chat_with = gtk.Menu()
|
account_menu_for_chat_with = gtk.Menu()
|
||||||
chat_with_menuitem.set_submenu(account_menu_for_chat_with)
|
chat_with_menuitem.set_submenu(account_menu_for_chat_with)
|
||||||
|
|
|
@ -29,12 +29,12 @@ DL_EXPORT(void)
|
||||||
inittrayicon(void)
|
inittrayicon(void)
|
||||||
{
|
{
|
||||||
PyObject *m, *d;
|
PyObject *m, *d;
|
||||||
|
|
||||||
init_pygobject ();
|
init_pygobject ();
|
||||||
|
|
||||||
m = Py_InitModule ("trayicon", trayicon_functions);
|
m = Py_InitModule ("trayicon", trayicon_functions);
|
||||||
d = PyModule_GetDict (m);
|
d = PyModule_GetDict (m);
|
||||||
|
|
||||||
trayicon_register_classes (d);
|
trayicon_register_classes (d);
|
||||||
|
|
||||||
if (PyErr_Occurred ()) {
|
if (PyErr_Occurred ()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue