Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
poezio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
204
Issues
204
List
Boards
Labels
Service Desk
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
poezio
poezio
Commits
8017b2d9
Commit
8017b2d9
authored
Jan 08, 2011
by
louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13
3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle authentication and connection errors. fixed
#1994
parent
af651cbc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
10 deletions
+42
-10
src/connection.py
src/connection.py
+6
-3
src/core.py
src/core.py
+34
-6
src/poezio.py
src/poezio.py
+2
-1
No files found.
src/connection.py
View file @
8017b2d9
...
...
@@ -50,7 +50,7 @@ class Connection(sleekxmpp.ClientXMPP):
sleekxmpp
.
ClientXMPP
.
__init__
(
self
,
jid
,
password
,
ssl
=
True
)
self
.
registerPlugin
(
'xep_0030'
)
self
.
registerPlugin
(
'xep_0045'
)
def
start
(
self
):
# TODO, try multiple servers
# With anon auth.
...
...
@@ -58,10 +58,13 @@ class Connection(sleekxmpp.ClientXMPP):
custom_host
=
config
.
get
(
'custom_host'
,
''
)
custom_port
=
config
.
get
(
'custom_port'
,
-
1
)
if
custom_host
and
custom_port
!=
-
1
:
self
.
connect
((
custom_host
,
custom_port
)
)
res
=
self
.
connect
((
custom_host
,
custom_port
),
reattempt
=
False
)
else
:
self
.
connect
()
res
=
self
.
connect
(
reattempt
=
False
)
if
not
res
:
return
False
self
.
process
(
threaded
=
True
)
return
True
# Global connection object
connection
=
Connection
()
src/core.py
View file @
8017b2d9
...
...
@@ -147,7 +147,10 @@ class Core(object):
}
# Add handlers
self
.
xmpp
.
add_event_handler
(
"session_start"
,
self
.
on_connected
)
self
.
xmpp
.
add_event_handler
(
'connected'
,
self
.
on_connected
)
self
.
xmpp
.
add_event_handler
(
'disconnected'
,
self
.
on_disconnected
)
self
.
xmpp
.
add_event_handler
(
'failed_auth'
,
self
.
on_failed_auth
)
self
.
xmpp
.
add_event_handler
(
"session_start"
,
self
.
on_session_start
)
self
.
xmpp
.
add_event_handler
(
"groupchat_presence"
,
self
.
on_groupchat_presence
)
self
.
xmpp
.
add_event_handler
(
"groupchat_message"
,
self
.
on_groupchat_message
)
self
.
xmpp
.
add_event_handler
(
"groupchat_subject"
,
self
.
on_groupchat_subject
)
...
...
@@ -157,6 +160,9 @@ class Core(object):
self
.
xmpp
.
add_event_handler
(
"roster_update"
,
self
.
on_roster_update
)
self
.
xmpp
.
add_event_handler
(
"changed_status"
,
self
.
on_presence
)
self
.
information
(
_
(
'Welcome to poezio!'
))
self
.
refresh_window
()
def
on_exception
(
self
,
typ
,
value
,
trace
):
"""
When an exception in raised, open a special tab
...
...
@@ -240,14 +246,36 @@ class Core(object):
if
tab
and
isinstance
(
tab
,
tabs
.
ConversationTab
):
self
.
add_message_to_text_buffer
(
tab
.
get_room
(),
msg
)
def
on_failed_connection
(
self
):
"""
We cannot contact the remote server
"""
self
.
information
(
_
(
"Connection to remote server failed"
))
def
on_disconnected
(
self
,
event
):
"""
When we are disconnected from remote server
"""
self
.
information
(
_
(
"Disconnected from server."
))
def
on_failed_auth
(
self
,
event
):
"""
Authentication failed
"""
self
.
information
(
_
(
"Authentication failed."
))
def
on_connected
(
self
,
event
):
"""
Remote host responded, but we are not yet authenticated
"""
self
.
information
(
_
(
"Connected to server."
))
def
on_session_start
(
self
,
event
):
"""
Called when we are connected and authenticated
"""
self
.
information
(
_
(
"
Welcome on Poezio \o/!
"
))
self
.
information
(
_
(
"
Authentication success.
"
))
self
.
information
(
_
(
"Your JID is %s"
)
%
self
.
xmpp
.
boundjid
.
full
)
if
not
self
.
xmpp
.
anon
:
# request the roster
self
.
xmpp
.
getRoster
()
...
...
@@ -598,15 +626,15 @@ class Core(object):
"""
main loop waiting for the user to press a key
"""
self
.
refresh_window
()
curses
.
ungetch
(
'
\n
'
)
# FIXME
while
self
.
running
:
self
.
doupdate
()
char
=
read_char
(
self
.
stdscr
)
char
=
read_char
(
self
.
stdscr
)
# search for keyboard shortcut
if
char
in
list
(
self
.
key_func
.
keys
()):
self
.
key_func
[
char
]()
else
:
self
.
do_command
(
char
)
self
.
doupdate
()
def
current_tab
(
self
):
"""
...
...
src/poezio.py
View file @
8017b2d9
...
...
@@ -34,7 +34,8 @@ if __name__ == '__main__':
signal
.
signal
(
signal
.
SIGINT
,
signal
.
SIG_IGN
)
# ignore ctrl-c
if
options
.
debug
:
logging
.
basicConfig
(
filename
=
options
.
debug
,
level
=
logging
.
DEBUG
)
connection
.
start
()
# Connect to remote server
if
not
connection
.
start
():
# Connect to remote server
core
.
on_failed_connection
()
# Disable any display of non-wanted text on the terminal
# by redirecting stderr to /dev/null
# sys.stderr = open('/dev/null', 'a')
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment