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
b1d206d2
Commit
b1d206d2
authored
12 years ago
by
zimio
Browse files
Options
Downloads
Patches
Plain Diff
refactoring
parent
004c0fbd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/common/jingle.py
+1
-1
1 addition, 1 deletion
src/common/jingle.py
src/common/jingle_ft.py
+4
-7
4 additions, 7 deletions
src/common/jingle_ft.py
src/common/jingle_session.py
+26
-23
26 additions, 23 deletions
src/common/jingle_session.py
src/gui_interface.py
+3
-3
3 additions, 3 deletions
src/gui_interface.py
with
34 additions
and
34 deletions
src/common/jingle.py
+
1
−
1
View file @
b1d206d2
...
...
@@ -163,7 +163,7 @@ class ConnectionJingle(object):
transport
=
JingleTransportIBB
()
c
=
JingleFileTransfer
(
jingle
,
transport
=
transport
,
file_props
=
file_props
,
use_security
=
use_security
)
jingle
.
hash_
algo
=
self
.
__hash_support
(
contact
)
file_props
.
algo
=
self
.
__hash_support
(
contact
)
jingle
.
add_content
(
'
file
'
+
helpers
.
get_random_string_16
(),
c
)
jingle
.
start_session
()
return
c
.
transport
.
sid
...
...
This diff is collapsed.
Click to expand it.
src/common/jingle_ft.py
+
4
−
7
View file @
b1d206d2
...
...
@@ -117,12 +117,9 @@ class JingleFileTransfer(JingleContent):
conn
=
self
.
session
.
connection
,
stanza
=
stanza
,
jingle_content
=
content
,
FT_content
=
self
))
self
.
_listen_host
()
# Delete this after file_props refactoring this shouldn't be necesary
self
.
session
.
file_hash
=
self
.
file_props
.
hash_
self
.
session
.
hash_algo
=
self
.
file_props
.
algo
def
__on_session_initiate_sent
(
self
,
stanza
,
content
,
error
,
action
):
# Calculate file
_
hash in a new thread
# Calculate file
hash in a new thread
# if we haven't sent the hash already.
if
self
.
file_props
.
hash_
is
None
:
self
.
hashThread
=
threading
.
Thread
(
target
=
self
.
__send_hash
)
...
...
@@ -137,7 +134,7 @@ class JingleFileTransfer(JingleContent):
def
_calcHash
(
self
):
# Caculates the hash and returns a xep-300 hash stanza
if
self
.
session
.
hash_
algo
==
None
:
if
self
.
file_props
.
algo
==
None
:
return
try
:
file_
=
open
(
self
.
file_props
.
file_name
,
'
r
'
)
...
...
@@ -145,14 +142,14 @@ class JingleFileTransfer(JingleContent):
# can't open file
return
h
=
xmpp
.
Hashes
()
hash_
=
h
.
calculateHash
(
self
.
session
.
hash_
algo
,
file_
)
hash_
=
h
.
calculateHash
(
self
.
file_props
.
algo
,
file_
)
# DEBUG
#hash_ = '1294809248109223'
if
not
hash_
:
# Hash alogrithm not supported
return
self
.
file_props
.
hash_
=
hash_
h
.
addHash
(
hash_
,
self
.
session
.
hash_
algo
)
h
.
addHash
(
hash_
,
self
.
file_props
.
algo
)
return
h
def
__on_session_accept
(
self
,
stanza
,
content
,
error
,
action
):
...
...
This diff is collapsed.
Click to expand it.
src/common/jingle_session.py
+
26
−
23
View file @
b1d206d2
...
...
@@ -98,34 +98,33 @@ class JingleSession(object):
else
:
self
.
iq_ids
=
[]
self
.
accepted
=
True
# is this session accepted by user
# Hash algorithm that we are using to calculate the integrity of the
# file. Could be 'md5', 'sha-1', etc...
self
.
hash_algo
=
None
self
.
file_hash
=
None
# Tells whether this session is a file transfer or not
self
.
session_type_FT
=
False
# callbacks to call on proper contents
# use .prepend() to add new callbacks, especially when you're going
# to send error instead of ack
self
.
callbacks
=
{
'
content-accept
'
:
[
self
.
__on_content_accept
,
self
.
__broadcast
,
self
.
__ack
],
'
content-accept
'
:
[
self
.
__on_content_accept
,
self
.
__broadcast
,
self
.
__ack
],
'
content-add
'
:
[
self
.
__on_content_add
,
self
.
__broadcast
,
self
.
__ack
],
#TODO
self
.
__ack
],
#TODO
'
content-modify
'
:
[
self
.
__ack
],
#TODO
'
content-reject
'
:
[
self
.
__ack
,
self
.
__on_content_remove
],
#TODO
'
content-reject
'
:
[
self
.
__ack
,
self
.
__on_content_remove
],
'
content-remove
'
:
[
self
.
__ack
,
self
.
__on_content_remove
],
'
description-info
'
:
[
self
.
__broadcast
,
self
.
__ack
],
#TODO
'
security-info
'
:
[
self
.
__ack
],
#TODO
'
session-accept
'
:
[
self
.
__on_session_accept
,
self
.
__on_content_accept
,
self
.
__broadcast
],
'
session-info
'
:
[
self
.
__broadcast
,
self
.
__on_session_info
,
self
.
__ack
],
'
session-initiate
'
:
[
self
.
__on_session_initiate
,
self
.
__broadcast
,
self
.
__ack
],
'
session-terminate
'
:
[
self
.
__on_session_terminate
,
self
.
__broadcast_all
,
self
.
__ack
],
'
session-accept
'
:
[
self
.
__on_session_accept
,
self
.
__on_content_accept
,
self
.
__broadcast
],
'
session-info
'
:
[
self
.
__broadcast
,
self
.
__on_session_info
,
self
.
__ack
],
'
session-initiate
'
:
[
self
.
__on_session_initiate
,
self
.
__broadcast
,
self
.
__ack
],
'
session-terminate
'
:
[
self
.
__on_session_terminate
,
self
.
__broadcast_all
,
self
.
__ack
],
'
transport-info
'
:
[
self
.
__broadcast
,
self
.
__ack
],
'
transport-replace
'
:
[
self
.
__broadcast
,
self
.
__on_transport_replace
],
#TODO
'
transport-replace
'
:
[
self
.
__broadcast
,
self
.
__on_transport_replace
],
#TODO
'
transport-accept
'
:
[
self
.
__ack
],
#TODO
'
transport-reject
'
:
[
self
.
__ack
],
#TODO
'
iq-result
'
:
[
self
.
__broadcast
],
...
...
@@ -327,7 +326,8 @@ class JingleSession(object):
self
.
__send_error
(
stanza
,
'
bad-request
'
)
return
# FIXME: If we aren't initiated and it's not a session-initiate...
if
action
not
in
[
'
session-initiate
'
,
'
session-terminate
'
]
and
self
.
state
==
JingleStates
.
ended
:
if
action
not
in
[
'
session-initiate
'
,
'
session-terminate
'
]
\
and
self
.
state
==
JingleStates
.
ended
:
self
.
__send_error
(
stanza
,
'
item-not-found
'
,
'
unknown-session
'
)
return
else
:
...
...
@@ -364,6 +364,7 @@ class JingleSession(object):
elif
child
.
getNamespace
()
==
xmpp
.
NS_STANZAS
:
error_name
=
child
.
getName
()
self
.
__dispatch_error
(
error_name
,
text
,
error
.
getAttr
(
'
type
'
))
# FIXME: Not sure when we would want to do that...
def
transport_replace
(
self
):
transport
=
JingleTransportIBB
()
...
...
@@ -416,6 +417,8 @@ class JingleSession(object):
def
__on_session_info
(
self
,
stanza
,
jingle
,
error
,
action
):
# TODO: ringing, active, (un)hold, (un)mute
if
self
.
state
!=
JingleStates
.
active
:
raise
OutOfOrder
payload
=
jingle
.
getPayload
()
for
p
in
payload
:
if
p
.
getName
()
==
'
checksum
'
:
...
...
@@ -423,13 +426,13 @@ class JingleSession(object):
namespace
=
xmpp
.
NS_HASHES
)
algo
=
hash_
.
getAttr
(
'
algo
'
)
if
algo
in
xmpp
.
Hashes
.
supported
:
self
.
hash_algo
=
algo
data
=
hash_
.
getData
()
# This only works because there is only one session
# per file in jingleFT
self
.
file_hash
=
data
file_props
=
FilesProp
.
getFileProp
(
self
.
connection
.
name
,
self
.
sid
)
file_props
.
algo
=
algo
file_props
.
hash_
=
hash_
.
getData
()
raise
xmpp
.
NodeProcessed
self
.
__send_error
(
stanza
,
'
feature-not-implemented
'
,
'
unsupported-info
'
,
type_
=
'
modify
'
)
self
.
__send_error
(
stanza
,
'
feature-not-implemented
'
,
'
unsupported-info
'
,
type_
=
'
modify
'
)
raise
xmpp
.
NodeProcessed
def
__on_content_remove
(
self
,
stanza
,
jingle
,
error
,
action
):
...
...
This diff is collapsed.
Click to expand it.
src/gui_interface.py
+
3
−
3
View file @
b1d206d2
...
...
@@ -938,7 +938,7 @@ class Interface:
session
=
gajim
.
connections
[
account
].
get_jingle_session
(
jid
=
None
,
sid
=
file_props
.
session_sid
)
ft_win
=
self
.
instances
[
'
file_transfers
'
]
if
not
session
.
file_
hash
:
if
not
file_props
.
hash
_
:
# We disn't get the hash, sender probably don't support that
jid
=
unicode
(
file_props
.
sender
)
self
.
popup_ft_result
(
account
,
jid
,
file_props
)
...
...
@@ -948,12 +948,12 @@ class Interface:
file_
=
open
(
file_props
.
file_name
,
'
r
'
)
except
:
return
hash_
=
h
.
calculateHash
(
session
.
hash_
algo
,
file_
)
hash_
=
h
.
calculateHash
(
file_props
.
algo
,
file_
)
file_
.
close
()
# If the hash we received and the hash of the file are the same,
# then the file is not corrupt
jid
=
unicode
(
file_props
.
sender
)
if
session
.
file_
hash
==
hash_
:
if
file_props
.
hash
_
==
hash_
:
gobject
.
idle_add
(
self
.
popup_ft_result
,
account
,
jid
,
file_props
)
gobject
.
idle_add
(
ft_win
.
set_status
,
file_props
,
'
ok
'
)
else
:
...
...
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