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

tdeio/tdeio

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

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.8.1.2
This website is maintained by Timothy Pearson.