2
Copyright (c) 2013 by Jakob Schroeter <js@camaya.net>
3
This file is part of the gloox library. http://camaya.net/gloox
5
This software is distributed under a license. The full license
6
agreement can be found in the file LICENSE in this distribution.
7
This software may not be copied, modified, sold or distributed
8
other than expressed in the named license agreement.
10
This software is distributed without any warranty.
14
#include "jinglefiletransfer.h"
28
static const char* typeValues [] = {
36
FileTransfer::FileTransfer( Type type, const FileList& files )
37
: m_type( type ), m_files( files )
41
FileTransfer::FileTransfer( const Tag* tag )
44
if( !tag || tag->xmlns() != XMLNS_JINGLE_FILE_TRANSFER )
47
std::string name = tag->name();
48
if( name == "description" )
50
const Tag* c = tag->findTag( "description/offer|description/request" );
53
parseFileList( c->findChildren( "file" ) );
57
else if( name == "checksum" || name == "abort" || name == "received" )
59
parseFileList( tag->findChildren( "file" ) );
62
m_type = (Type)util::lookup( name, typeValues );
65
void FileTransfer::parseFileList( const TagList& files )
67
TagList::const_iterator it = files.begin();
68
for( ; it != files.end(); ++it )
71
Tag *t = (*it)->findChild( "name" );
72
f.name = t ? t->cdata() : EmptyString;
73
t = (*it)->findChild( "desc" );
74
f.desc = t ? t->cdata() : EmptyString;
75
t = (*it)->findChild( "date" );
76
f.date = t ? t->cdata() : EmptyString;
77
t = (*it)->findChild( "size" );
78
f.size = t ? atoi( t->cdata().c_str() ) : -1;
79
t = (*it)->findChild( "range" );
83
f.offset = t->hasAttribute( "offset" ) ? atoi( t->findAttribute( "offset" ).c_str() ) : -1;
85
t = (*it)->findChild( "hash", XMLNS, XMLNS_HASHES );
88
f.hash_algo = t->findAttribute( "algo" );
91
m_files.push_back( f );
95
const StringList FileTransfer::features() const
98
sl.push_back( XMLNS_JINGLE_FILE_TRANSFER );
102
const std::string& FileTransfer::filterString() const
104
static const std::string filter = "content/description[@xmlns='" + XMLNS_JINGLE_FILE_TRANSFER + "']"
105
"|jingle/abort[@xmlns='" + XMLNS_JINGLE_FILE_TRANSFER + "']"
106
"|jingle/received[@xmlns='" + XMLNS_JINGLE_FILE_TRANSFER + "']"
107
"|jingle/checksum[@xmlns='" + XMLNS_JINGLE_FILE_TRANSFER + "']";
111
Plugin* FileTransfer::newInstance( const Tag* tag ) const
113
return new FileTransfer( tag );
116
Tag* FileTransfer::tag() const
118
if( m_type == Invalid )
128
r = new Tag( "description", XMLNS, XMLNS_JINGLE_FILE_TRANSFER );
129
Tag* o = new Tag( r, util::lookup( m_type, typeValues ) );
130
FileList::const_iterator it = m_files.begin();
131
for( ; it != m_files.end(); ++it )
133
Tag* f = new Tag( o, "file" );
134
new Tag( f, "date", (*it).date );
135
new Tag( f, "name", (*it).name );
136
new Tag( f, "desc", (*it).desc );
137
new Tag( f, "size", util::long2string( (*it).size ) );
138
Tag* h = new Tag( f, "hash", XMLNS, XMLNS_HASHES );
139
h->addAttribute( "algo", (*it).hash_algo );
140
h->setCData( (*it).hash );
142
new Tag( f, "range", "offset", (*it).offset ? util::long2string( (*it).offset ) : EmptyString );
150
r = new Tag( util::lookup( m_type, typeValues ), XMLNS, XMLNS_JINGLE_FILE_TRANSFER );
151
FileList::const_iterator it = m_files.begin();
152
Tag* f = new Tag( r, "file" );
153
new Tag( f, "date", (*it).date );
154
new Tag( f, "name", (*it).name );
155
new Tag( f, "desc", (*it).desc );
156
new Tag( f, "size", util::long2string( (*it).size ) );
157
Tag* h = new Tag( f, "hash", XMLNS, XMLNS_HASHES );
158
h->addAttribute( "algo", (*it).hash_algo );
159
h->setCData( (*it).hash );
161
new Tag( f, "range" );