Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Weblate
gajim
Commits
28e28748
Commit
28e28748
authored
15 years ago
by
Yann Leboulanger
Browse files
Options
Downloads
Patches
Plain Diff
ability to send jabber:iq:last query over zeroconf. Fixes #5644
parent
f0dde42f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/common/connection.py
+17
-22
17 additions, 22 deletions
src/common/connection.py
src/common/connection_handlers.py
+33
-26
33 additions, 26 deletions
src/common/connection_handlers.py
src/common/zeroconf/client_zeroconf.py
+10
-2
10 additions, 2 deletions
src/common/zeroconf/client_zeroconf.py
with
60 additions
and
50 deletions
src/common/connection.py
+
17
−
22
View file @
28e28748
...
...
@@ -509,11 +509,25 @@ class CommonConnection:
def
account_changed
(
self
,
new_name
):
self
.
name
=
new_name
def
request_last_status_time
(
self
,
jid
,
resource
):
def
request_last_status_time
(
self
,
jid
,
resource
,
groupchat_jid
=
None
):
"""
To be implemented by derivated classes
groupchat_jid is used when we want to send a request to a real jid and
act as if the answer comes from the groupchat_jid
"""
raise
NotImplementedError
print
'
request_last_status_time
'
,
self
.
connection
if
not
self
.
connection
:
return
to_whom_jid
=
jid
if
resource
:
to_whom_jid
+=
'
/
'
+
resource
iq
=
common
.
xmpp
.
Iq
(
to
=
to_whom_jid
,
typ
=
'
get
'
,
queryNS
=
\
common
.
xmpp
.
NS_LAST
)
id_
=
self
.
connection
.
getAnID
()
iq
.
setID
(
id_
)
if
groupchat_jid
:
self
.
groupchat_jids
[
id_
]
=
groupchat_jid
self
.
last_ids
.
append
(
id_
)
self
.
connection
.
send
(
iq
)
def
request_os_info
(
self
,
jid
,
resource
):
"""
...
...
@@ -1756,25 +1770,6 @@ class Connection(CommonConnection, ConnectionHandlers):
self
.
connection
=
con
common
.
xmpp
.
features_nb
.
getRegInfo
(
con
,
self
.
_hostname
)
def
request_last_status_time
(
self
,
jid
,
resource
,
groupchat_jid
=
None
):
"""
groupchat_jid is used when we want to send a request to a real jid and
act as if the answer comes from the groupchat_jid
"""
if
not
self
.
connection
:
return
to_whom_jid
=
jid
if
resource
:
to_whom_jid
+=
'
/
'
+
resource
iq
=
common
.
xmpp
.
Iq
(
to
=
to_whom_jid
,
typ
=
'
get
'
,
queryNS
=
\
common
.
xmpp
.
NS_LAST
)
id_
=
self
.
connection
.
getAnID
()
iq
.
setID
(
id_
)
if
groupchat_jid
:
self
.
groupchat_jids
[
id_
]
=
groupchat_jid
self
.
last_ids
.
append
(
id_
)
self
.
connection
.
send
(
iq
)
def
request_os_info
(
self
,
jid
,
resource
,
groupchat_jid
=
None
):
"""
groupchat_jid is used when we want to send a request to a real jid and
...
...
This diff is collapsed.
Click to expand it.
src/common/connection_handlers.py
+
33
−
26
View file @
28e28748
...
...
@@ -782,10 +782,42 @@ class ConnectionHandlersBase:
# keep the jids we auto added (transports contacts) to not send the
# SUBSCRIBED event to gui
self
.
automatically_added
=
[]
# IDs of jabber:iq:last requests
self
.
last_ids
=
[]
# keep track of sessions this connection has with other JIDs
self
.
sessions
=
{}
def
_ErrorCB
(
self
,
con
,
iq_obj
):
log
.
debug
(
'
ErrorCB
'
)
jid_from
=
helpers
.
get_full_jid_from_iq
(
iq_obj
)
jid_stripped
,
resource
=
gajim
.
get_room_and_nick_from_fjid
(
jid_from
)
id_
=
unicode
(
iq_obj
.
getID
())
if
id_
in
self
.
last_ids
:
self
.
dispatch
(
'
LAST_STATUS_TIME
'
,
(
jid_stripped
,
resource
,
-
1
,
''
))
self
.
last_ids
.
remove
(
id_
)
return
def
_LastResultCB
(
self
,
con
,
iq_obj
):
log
.
debug
(
'
LastResultCB
'
)
qp
=
iq_obj
.
getTag
(
'
query
'
)
seconds
=
qp
.
getAttr
(
'
seconds
'
)
status
=
qp
.
getData
()
try
:
seconds
=
int
(
seconds
)
except
Exception
:
return
id_
=
iq_obj
.
getID
()
if
id_
in
self
.
groupchat_jids
:
who
=
self
.
groupchat_jids
[
id_
]
del
self
.
groupchat_jids
[
id_
]
else
:
who
=
helpers
.
get_full_jid_from_iq
(
iq_obj
)
if
id_
in
self
.
last_ids
:
self
.
last_ids
.
remove
(
id_
)
jid_stripped
,
resource
=
gajim
.
get_room_and_nick_from_fjid
(
who
)
self
.
dispatch
(
'
LAST_STATUS_TIME
'
,
(
jid_stripped
,
resource
,
seconds
,
status
))
def
get_sessions
(
self
,
jid
):
"""
Get all sessions for the given full jid
...
...
@@ -936,8 +968,6 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
# keep the latest subscribed event for each jid to prevent loop when we
# acknowledge presences
self
.
subscribed_events
=
{}
# IDs of jabber:iq:last requests
self
.
last_ids
=
[]
# IDs of jabber:iq:version requests
self
.
version_ids
=
[]
# IDs of urn:xmpp:time requests
...
...
@@ -981,6 +1011,7 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
def
_ErrorCB
(
self
,
con
,
iq_obj
):
log
.
debug
(
'
ErrorCB
'
)
ConnectionHandlersBase
.
_ErrorCB
(
self
,
con
,
iq_obj
)
jid_from
=
helpers
.
get_full_jid_from_iq
(
iq_obj
)
jid_stripped
,
resource
=
gajim
.
get_room_and_nick_from_fjid
(
jid_from
)
id_
=
unicode
(
iq_obj
.
getID
())
...
...
@@ -988,10 +1019,6 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
self
.
dispatch
(
'
OS_INFO
'
,
(
jid_stripped
,
resource
,
''
,
''
))
self
.
version_ids
.
remove
(
id_
)
return
if
id_
in
self
.
last_ids
:
self
.
dispatch
(
'
LAST_STATUS_TIME
'
,
(
jid_stripped
,
resource
,
-
1
,
''
))
self
.
last_ids
.
remove
(
id_
)
return
if
id_
in
self
.
entity_time_ids
:
self
.
dispatch
(
'
ENTITY_TIME
'
,
(
jid_stripped
,
resource
,
''
))
self
.
entity_time_ids
.
remove
(
id_
)
...
...
@@ -1132,26 +1159,6 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
self
.
connection
.
send
(
iq_obj
)
raise
common
.
xmpp
.
NodeProcessed
def
_LastResultCB
(
self
,
con
,
iq_obj
):
log
.
debug
(
'
LastResultCB
'
)
qp
=
iq_obj
.
getTag
(
'
query
'
)
seconds
=
qp
.
getAttr
(
'
seconds
'
)
status
=
qp
.
getData
()
try
:
seconds
=
int
(
seconds
)
except
Exception
:
return
id_
=
iq_obj
.
getID
()
if
id_
in
self
.
groupchat_jids
:
who
=
self
.
groupchat_jids
[
id_
]
del
self
.
groupchat_jids
[
id_
]
else
:
who
=
helpers
.
get_full_jid_from_iq
(
iq_obj
)
if
id_
in
self
.
last_ids
:
self
.
last_ids
.
remove
(
id_
)
jid_stripped
,
resource
=
gajim
.
get_room_and_nick_from_fjid
(
who
)
self
.
dispatch
(
'
LAST_STATUS_TIME
'
,
(
jid_stripped
,
resource
,
seconds
,
status
))
def
_VersionResultCB
(
self
,
con
,
iq_obj
):
log
.
debug
(
'
VersionResultCB
'
)
client_info
=
''
...
...
This diff is collapsed.
Click to expand it.
src/common/zeroconf/client_zeroconf.py
+
10
−
2
View file @
28e28748
...
...
@@ -30,6 +30,8 @@ from common.xmpp.protocol import *
import
socket
import
errno
import
sys
import
string
from
random
import
Random
import
logging
log
=
logging
.
getLogger
(
'
gajim.c.z.client_zeroconf
'
)
...
...
@@ -412,7 +414,6 @@ class P2PConnection(IdleObject, PlugIn):
If supplied data is unicode string, encode it to UTF-8.
"""
print
'
ici
'
if
self
.
state
<=
0
:
return
...
...
@@ -726,7 +727,8 @@ class ClientZeroconf:
def
send
(
self
,
stanza
,
is_message
=
False
,
now
=
False
,
on_ok
=
None
,
on_not_ok
=
None
):
stanza
.
setFrom
(
self
.
roster
.
zeroconf
.
name
)
to
=
stanza
.
getTo
()
to
=
unicode
(
stanza
.
getTo
())
to
=
gajim
.
get_jid_without_resource
(
to
)
try
:
item
=
self
.
roster
[
to
]
...
...
@@ -759,6 +761,12 @@ class ClientZeroconf:
P2PClient
(
None
,
item
[
'
address
'
],
item
[
'
port
'
],
self
,
[(
stanza
,
is_message
)],
to
,
on_ok
=
on_ok
,
on_not_ok
=
on_not_ok
)
def
getAnID
(
self
):
"""
Generate a random id
"""
''
.
join
(
Random
().
sample
(
string
.
letters
+
string
.
digits
,
6
))
def
RegisterDisconnectHandler
(
self
,
handler
):
"""
Register handler that will be called on disconnect
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment