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
b0f9e19b
Commit
b0f9e19b
authored
11 years ago
by
zimio
Browse files
Options
Downloads
Patches
Plain Diff
file sharing. Fix offer
parent
c66cb370
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
file_sharing/fshare_protocol.py
+35
-25
35 additions, 25 deletions
file_sharing/fshare_protocol.py
file_sharing/tests/TestProtocol.py
+37
-1
37 additions, 1 deletion
file_sharing/tests/TestProtocol.py
with
72 additions
and
26 deletions
file_sharing/fshare_protocol.py
+
35
−
25
View file @
b0f9e19b
...
...
@@ -8,7 +8,7 @@ except ImportError:
print
"
Import Error: Ignore if we are testing
"
# Namespace for file sharing
NS_FILE_SHARING
=
'
http://gajim.org/protocol/filesharing
'
NS_FILE_SHARING
=
'
urn:xmpp:fis
'
class
Protocol
():
'''
...
...
@@ -25,7 +25,8 @@ class Protocol():
iq
.
setID
(
stanzaID
)
query
=
iq
.
setQuery
()
query
.
setNamespace
(
NS_FILE_SHARING
)
query
.
setAttr
(
'
node
'
,
path
)
if
path
:
query
.
setAttr
(
'
node
'
,
path
)
return
iq
def
buildReply
(
self
,
typ
,
stanza
):
...
...
@@ -34,31 +35,40 @@ class Protocol():
iq
.
addChild
(
name
=
'
match
'
,
namespace
=
NS_FILE_SHARING
)
return
iq
def
offer
(
self
,
id_
,
contact
,
items
):
def
buildFileNode
(
self
,
file_info
):
node
=
nbxmpp
.
Node
(
tag
=
'
file
'
)
node
.
setNamespace
(
nbxmpp
.
NS_JINGLE_FILE_TRANSFER
)
if
not
file_info
[
'
name
'
]:
raise
Exception
(
"
Child name is required.
"
)
node
.
addChild
(
name
=
'
name
'
).
setData
(
file_info
[
'
name
'
])
if
file_info
[
'
date
'
]:
node
.
addChild
(
name
=
'
date
'
).
setData
(
file_info
[
'
date
'
])
if
file_info
[
'
desc
'
]:
node
.
addChild
(
name
=
'
desc
'
).
setData
(
file_info
[
'
desc
'
])
if
file_info
[
'
size
'
]:
node
.
addChild
(
name
=
'
size
'
).
setData
(
file_info
[
'
size
'
])
if
file_info
[
'
hash
'
]:
h
=
Hashes
()
h
.
addHash
(
file_info
[
'
hash
'
],
'
sha-1
'
)
node
.
addChild
(
node
=
h
)
return
node
def
offer
(
self
,
id_
,
contact
,
node
,
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
])
query
=
iq
.
setQuery
()
query
.
setNamespace
(
NS_FILE_SHARING
)
if
node
:
query
.
setAttr
(
'
node
'
,
node
)
for
item
in
items
:
if
item
[
'
type
'
]
==
'
file
'
:
fn
=
self
.
buildFileNode
(
item
)
query
.
addChild
(
node
=
fn
)
elif
item
[
'
type
'
]
==
'
directory
'
:
query
.
addChild
(
name
=
'
directory
'
,
attrs
=
{
'
name
'
:
item
[
'
name
'
]})
else
:
raise
Exception
(
"
Unexpected Type
"
)
return
iq
class
ProtocolDispatcher
():
...
...
This diff is collapsed.
Click to expand it.
file_sharing/tests/TestProtocol.py
+
37
−
1
View file @
b0f9e19b
...
...
@@ -7,6 +7,7 @@ import sys, os
sys
.
path
.
append
(
os
.
path
.
abspath
(
sys
.
path
[
0
])
+
'
/../
'
)
import
fshare_protocol
import
nbxmpp
class
TestProtocol
(
unittest
.
TestCase
):
...
...
@@ -21,8 +22,43 @@ class TestProtocol(unittest.TestCase):
self
.
assertEqual
(
iq
.
getQuery
().
getNamespace
(),
fshare_protocol
.
NS_FILE_SHARING
)
self
.
assertEqual
(
iq
.
getQuery
().
getAttr
(
'
node
'
),
'
documents/test2.txt
'
)
def
test_buildFileNode
(
self
):
file_info
=
{
'
name
'
:
'
test2.text
'
,
'
date
'
:
'
00000
'
,
'
desc
'
:
'
test
'
,
'
hash
'
:
'
00000
'
,
'
size
'
:
'
00000
'
,
'
type
'
:
'
file
'
}
node
=
self
.
protocol
.
buildFileNode
(
file_info
)
self
.
assertEqual
(
node
.
getName
(),
'
file
'
)
self
.
assertEqual
(
node
.
getNamespace
(),
nbxmpp
.
NS_JINGLE_FILE_TRANSFER
)
self
.
assertEqual
(
len
(
node
.
getChildren
()),
5
)
def
test_offer
(
self
):
pass
items
=
[
{
'
name
'
:
'
test2.text
'
,
'
date
'
:
'
00000
'
,
'
desc
'
:
'
test
'
,
'
hash
'
:
'
00000
'
,
'
size
'
:
'
00000
'
,
'
type
'
:
'
file
'
},
{
'
name
'
:
'
secret docs
'
,
'
type
'
:
'
directory
'
}
]
iq
=
self
.
protocol
.
offer
(
'
1234
'
,
'
peer@gajim.org/test
'
,
'
documents
'
,
items
)
self
.
assertEqual
(
iq
.
getType
(),
'
result
'
)
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
'
)
node
=
iq
.
getQuery
()
self
.
assertEqual
(
len
(
node
.
getChildren
()),
2
)
def
test_reply
(
self
):
pass
...
...
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