Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gajim-plugins
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
Evert Mouw
gajim-plugins
Commits
c66cb370
Commit
c66cb370
authored
11 years ago
by
zimio
Browse files
Options
Downloads
Patches
Plain Diff
file sharing. Fix request; Include unit testing.
parent
82c86859
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
file_sharing/fshare_protocol.py
+78
-60
78 additions, 60 deletions
file_sharing/fshare_protocol.py
file_sharing/manifest.ini
+1
-1
1 addition, 1 deletion
file_sharing/manifest.ini
file_sharing/tests/TestProtocol.py
+32
-0
32 additions, 0 deletions
file_sharing/tests/TestProtocol.py
with
111 additions
and
61 deletions
file_sharing/fshare_protocol.py
+
78
−
60
View file @
c66cb370
from
common
import
xmpp
from
common
import
helpers
from
common
import
gajim
from
common
import
XMPPDispatcher
from
common.xmpp
import
Hashes
import
nbxmpp
from
nbxmpp
import
Hashes
try
:
from
common
import
helpers
from
common
import
gajim
except
ImportError
:
print
"
Import Error: Ignore if we are testing
"
# Namespace for file sharing
NS_FILE_SHARING
=
'
http://gajim.org/protocol/filesharing
'
class
Protocol
():
'''
Creates and extracts information from stanzas
'''
def
__init__
(
self
,
ourjid
):
# set our jid with resource
self
.
ourjid
=
ourjid
def
request
(
self
,
contact
,
stanzaID
,
path
=
None
):
iq
=
nbxmpp
.
Iq
(
typ
=
'
get
'
,
to
=
contact
,
frm
=
self
.
ourjid
)
iq
.
setID
(
stanzaID
)
query
=
iq
.
setQuery
()
query
.
setNamespace
(
NS_FILE_SHARING
)
query
.
setAttr
(
'
node
'
,
path
)
return
iq
def
buildReply
(
self
,
typ
,
stanza
):
iq
=
nbxmpp
.
Iq
(
typ
,
to
=
stanza
.
getFrom
(),
frm
=
stanza
.
getTo
(),
attrs
=
{
'
id
'
:
stanza
.
getID
()})
iq
.
addChild
(
name
=
'
match
'
,
namespace
=
NS_FILE_SHARING
)
return
iq
def
offer
(
self
,
id_
,
contact
,
items
):
iq
=
nbxmpp
.
Iq
(
typ
=
'
result
'
,
to
=
contact
,
frm
=
self
.
ourjid
,
attrs
=
{
'
id
'
:
id_
})
match
=
iq
.
addChild
(
name
=
'
match
'
,
namespace
=
NS_FILE_SHARING
)
offer
=
match
.
addChild
(
name
=
'
offer
'
)
if
len
(
items
)
==
0
:
offer
.
addChild
(
name
=
'
directory
'
)
else
:
for
i
in
items
:
# if it is a directory
if
i
[
5
]
==
True
:
item
=
offer
.
addChild
(
name
=
'
directory
'
)
name
=
item
.
addChild
(
'
name
'
)
name
.
setData
(
'
/
'
+
i
[
0
])
else
:
item
=
offer
.
addChild
(
name
=
'
file
'
)
item
.
addChild
(
'
name
'
).
setData
(
'
/
'
+
i
[
0
])
if
i
[
1
]
!=
''
:
h
=
Hashes
()
h
.
addHash
(
i
[
1
],
'
sha-1
'
)
item
.
addChild
(
node
=
h
)
item
.
addChild
(
'
size
'
).
setData
(
i
[
2
])
item
.
addChild
(
'
desc
'
).
setData
(
i
[
3
])
item
.
addChild
(
'
date
'
).
setData
(
i
[
4
])
return
iq
class
ProtocolDispatcher
():
'''
Sends and receives stanzas
'''
def
__init__
(
self
,
account
,
plugin
):
self
.
account
=
account
...
...
@@ -16,27 +75,24 @@ class Protocol():
self
.
ourjid
=
gajim
.
get_jid_from_account
(
self
.
account
)
self
.
fsw
=
None
def
set_window
(
self
,
fsw
):
self
.
fsw
=
fsw
def
set_window
(
self
,
window
):
self
.
fsw
=
window
def
request
(
self
,
contact
,
name
=
None
,
isFile
=
False
):
iq
=
xmpp
.
Iq
(
typ
=
'
get
'
,
to
=
contact
,
frm
=
self
.
ourjid
)
match
=
iq
.
addChild
(
name
=
'
match
'
,
namespace
=
NS_FILE_SHARING
)
request
=
match
.
addChild
(
name
=
'
request
'
)
if
not
isFile
and
name
is
None
:
request
.
addChild
(
name
=
'
directory
'
)
elif
not
isFile
and
name
is
not
None
:
dir_
=
request
.
addChild
(
name
=
'
directory
'
)
dir_
.
addChild
(
name
=
'
name
'
).
addData
(
'
/
'
+
name
)
elif
isFile
:
pass
return
iq
def
__buildReply
(
self
,
typ
,
stanza
):
iq
=
xmpp
.
Iq
(
typ
,
to
=
stanza
.
getFrom
(),
frm
=
stanza
.
getTo
(),
attrs
=
{
'
id
'
:
stanza
.
getID
()})
iq
.
addChild
(
name
=
'
match
'
,
namespace
=
NS_FILE_SHARING
)
return
iq
def
handler
(
self
,
stanza
):
# handles incoming match stanza
if
stanza
.
getTag
(
'
match
'
).
getTag
(
'
offer
'
):
self
.
on_offer
(
stanza
)
elif
stanza
.
getTag
(
'
match
'
).
getTag
(
'
request
'
):
self
.
on_request
(
stanza
)
else
:
# TODO: reply with malformed stanza error
pass
def
on_request
(
self
,
stanza
):
try
:
...
...
@@ -98,44 +154,6 @@ class Protocol():
row
=
self
.
fsw
.
ts_search
.
append
(
parent
,
(
''
,))
self
.
fsw
.
empty_row_child
[
dir_
]
=
row
def
handler
(
self
,
stanza
):
# handles incoming match stanza
if
stanza
.
getTag
(
'
match
'
).
getTag
(
'
offer
'
):
self
.
on_offer
(
stanza
)
elif
stanza
.
getTag
(
'
match
'
).
getTag
(
'
request
'
):
self
.
on_request
(
stanza
)
else
:
# TODO: reply with malformed stanza error
pass
def
offer
(
self
,
id_
,
contact
,
items
):
iq
=
xmpp
.
Iq
(
typ
=
'
result
'
,
to
=
contact
,
frm
=
self
.
ourjid
,
attrs
=
{
'
id
'
:
id_
})
match
=
iq
.
addChild
(
name
=
'
match
'
,
namespace
=
NS_FILE_SHARING
)
offer
=
match
.
addChild
(
name
=
'
offer
'
)
if
len
(
items
)
==
0
:
offer
.
addChild
(
name
=
'
directory
'
)
else
:
for
i
in
items
:
# if it is a directory
if
i
[
5
]
==
True
:
item
=
offer
.
addChild
(
name
=
'
directory
'
)
name
=
item
.
addChild
(
'
name
'
)
name
.
setData
(
'
/
'
+
i
[
0
])
else
:
item
=
offer
.
addChild
(
name
=
'
file
'
)
item
.
addChild
(
'
name
'
).
setData
(
'
/
'
+
i
[
0
])
if
i
[
1
]
!=
''
:
h
=
Hashes
()
h
.
addHash
(
i
[
1
],
'
sha-1
'
)
item
.
addChild
(
node
=
h
)
item
.
addChild
(
'
size
'
).
setData
(
i
[
2
])
item
.
addChild
(
'
desc
'
).
setData
(
i
[
3
])
item
.
addChild
(
'
date
'
).
setData
(
i
[
4
])
return
iq
def
set_window
(
self
,
fsw
):
self
.
fsw
=
fsw
def
get_files_info
(
stanza
):
...
...
This diff is collapsed.
Click to expand it.
file_sharing/manifest.ini
+
1
−
1
View file @
c66cb370
...
...
@@ -4,6 +4,6 @@ short_name: fshare
#version: 0.1.1
description:
This
plugin
allows
you
to
share
folders
with
your
peers
using
jingle
file
transfer.
authors:
Jefry
Lagrange
<jefry.reyes@gmail.com>
homepage:
www.g
oogle.com
homepage:
www.g
ajim.org
max_gajim_version:
0.16.9
This diff is collapsed.
Click to expand it.
file_sharing/tests/TestProtocol.py
0 → 100644
+
32
−
0
View file @
c66cb370
#/usr/bin/python
import
unittest
import
sys
,
os
sys
.
path
.
append
(
os
.
path
.
abspath
(
sys
.
path
[
0
])
+
'
/../
'
)
import
fshare_protocol
class
TestProtocol
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
protocol
=
fshare_protocol
.
Protocol
(
'
test@gajim.org/test
'
)
def
test_request
(
self
):
iq
=
self
.
protocol
.
request
(
'
peer@gajim.org/test
'
,
'
1234
'
,
'
documents/test2.txt
'
)
self
.
assertEqual
(
iq
.
getType
(),
'
get
'
)
self
.
assertNotEqual
(
iq
.
getID
(),
None
)
self
.
assertEqual
(
iq
.
getQuery
().
getName
(),
'
query
'
)
self
.
assertEqual
(
iq
.
getQuery
().
getNamespace
(),
fshare_protocol
.
NS_FILE_SHARING
)
self
.
assertEqual
(
iq
.
getQuery
().
getAttr
(
'
node
'
),
'
documents/test2.txt
'
)
def
test_offer
(
self
):
pass
def
test_reply
(
self
):
pass
if
__name__
==
'
__main__
'
:
unittest
.
main
()
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