• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • tdeio
  • tdeio
davjob.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include <kurl.h>
21
22#include <tqobject.h>
23#include <tqptrlist.h>
24#include <tqstring.h>
25#include <tqstringlist.h>
26#include <tqguardedptr.h>
27#include <tqdom.h>
28
29#include <sys/types.h>
30#include <sys/stat.h>
31
32#include <kdebug.h>
33#include <tdeio/jobclasses.h>
34#include <tdeio/global.h>
35#include <tdeio/http.h>
36#include <tdeio/davjob.h>
37#include <tdeio/job.h>
38#include <tdeio/slaveinterface.h>
39
40#define TDEIO_ARGS TQByteArray packedArgs; TQDataStream stream( packedArgs, IO_WriteOnly ); stream
41
42using namespace TDEIO;
43
44class DavJob::DavJobPrivate
45{
46public:
47 TQByteArray savedStaticData;
48 TQByteArray str_response; // replaces the TQString previously used in DavJob itself
49};
50
51DavJob::DavJob( const KURL& url, int method, const TQString& request, bool showProgressInfo )
52 : TransferJob( url, TDEIO::CMD_SPECIAL, TQByteArray(), TQByteArray(), showProgressInfo )
53{
54 d = new DavJobPrivate;
55 // We couldn't set the args when calling the parent constructor,
56 // so do it now.
57 TQDataStream stream( m_packedArgs, IO_WriteOnly );
58 stream << (int) 7 << url << method;
59 // Same for static data
60 if ( ! request.isEmpty() && ! request.isNull() ) {
61 staticData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + request.utf8();
62 staticData.truncate( staticData.size() - 1 );
63 d->savedStaticData = staticData.copy();
64 }
65}
66
67void DavJob::slotData( const TQByteArray& data )
68{
69 if(m_redirectionURL.isEmpty() || !m_redirectionURL.isValid() || m_error) {
70 unsigned int oldSize = d->str_response.size();
71 d->str_response.resize( oldSize + data.size() );
72 memcpy( d->str_response.data() + oldSize, data.data(), data.size() );
73 }
74}
75
76void DavJob::slotFinished()
77{
78 // kdDebug(7113) << "DavJob::slotFinished()" << endl;
79 // kdDebug(7113) << d->str_response << endl;
80 if (!m_redirectionURL.isEmpty() && m_redirectionURL.isValid() && (m_command == CMD_SPECIAL)) {
81 TQDataStream istream( m_packedArgs, IO_ReadOnly );
82 int s_cmd, s_method;
83 KURL s_url;
84 istream >> s_cmd;
85 istream >> s_url;
86 istream >> s_method;
87 // PROPFIND
88 if ( (s_cmd == 7) && (s_method == (int)TDEIO::DAV_PROPFIND) ) {
89 m_packedArgs.truncate(0);
90 TQDataStream stream( m_packedArgs, IO_WriteOnly );
91 stream << (int)7 << m_redirectionURL << (int)TDEIO::DAV_PROPFIND;
92 }
93 } else if ( ! m_response.setContent( d->str_response, true ) ) {
94 // An error occurred parsing the XML response
95 TQDomElement root = m_response.createElementNS( "DAV:", "error-report" );
96 m_response.appendChild( root );
97
98 TQDomElement el = m_response.createElementNS( "DAV:", "offending-response" );
99 TQDomText textnode = m_response.createTextNode( d->str_response );
100 el.appendChild( textnode );
101 root.appendChild( el );
102 delete d; // Should be in virtual destructor
103 d = 0;
104 } else {
105 delete d; // Should be in virtual destructor
106 d = 0;
107 }
108 // kdDebug(7113) << m_response.toString() << endl;
109 TransferJob::slotFinished();
110 if( d ) staticData = d->savedStaticData.copy(); // Need to send DAV request to this host too
111}
112
113/* Convenience methods */
114
115// KDE 4: Make it const TQString &
116DavJob* TDEIO::davPropFind( const KURL& url, const TQDomDocument& properties, TQString depth, bool showProgressInfo )
117{
118 DavJob *job = new DavJob( url, (int) TDEIO::DAV_PROPFIND, properties.toString(), showProgressInfo );
119 job->addMetaData( "davDepth", depth );
120 return job;
121}
122
123
124DavJob* TDEIO::davPropPatch( const KURL& url, const TQDomDocument& properties, bool showProgressInfo )
125{
126 return new DavJob( url, (int) TDEIO::DAV_PROPPATCH, properties.toString(), showProgressInfo );
127}
128
129DavJob* TDEIO::davSearch( const KURL& url, const TQString& nsURI, const TQString& qName, const TQString& query, bool showProgressInfo )
130{
131 TQDomDocument doc;
132 TQDomElement searchrequest = doc.createElementNS( "DAV:", "searchrequest" );
133 TQDomElement searchelement = doc.createElementNS( nsURI, qName );
134 TQDomText text = doc.createTextNode( query );
135 searchelement.appendChild( text );
136 searchrequest.appendChild( searchelement );
137 doc.appendChild( searchrequest );
138 return new DavJob( url, TDEIO::DAV_SEARCH, doc.toString(), showProgressInfo );
139}
140
141#include "davjob.moc"
TDEIO::DavJob
The transfer job pumps data into and/or out of a Slave.
Definition: davjob.h:56
TDEIO::Job::addMetaData
void addMetaData(const TQString &key, const TQString &value)
Definition: job.cpp:434
TDEIO::SimpleJob::url
const KURL & url() const
Returns the SimpleJob's URL.
Definition: jobclasses.h:548
TDEIO::TransferJob
The transfer job pumps data into and/or out of a Slave.
Definition: jobclasses.h:874
TDEIO::TransferJob::data
void data(TDEIO::Job *job, const TQByteArray &data)
Data from the slave has arrived.
TDEIO
A namespace for TDEIO globals.
Definition: authinfo.h:29
TDEIO::davPropFind
TDEIO_EXPORT DavJob * davPropFind(const KURL &url, const TQDomDocument &properties, TQString depth, bool showProgressInfo=true)
Creates a new DavJob that issues a PROPFIND command.
Definition: davjob.cpp:116
TDEIO::davSearch
TDEIO_EXPORT DavJob * davSearch(const KURL &url, const TQString &nsURI, const TQString &qName, const TQString &query, bool showProgressInfo=true)
Creates a new DavJob that issues a SEARCH command.
Definition: davjob.cpp:129
TDEIO::davPropPatch
TDEIO_EXPORT DavJob * davPropPatch(const KURL &url, const TQDomDocument &properties, bool showProgressInfo=true)
Creates a new DavJob that issues a PROPPATCH command.
Definition: davjob.cpp:124

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.9.4
This website is maintained by Timothy Pearson.