You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
195 lines
5.7 KiB
195 lines
5.7 KiB
15 years ago
|
/*
|
||
13 years ago
|
This file is part of tdepim.
|
||
15 years ago
|
|
||
|
Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
|
||
|
Copyright (c) 2004 Till Adam <adam@kde.org>
|
||
|
Copyright (c) 2005 Reinhold Kainhofer <reinhold@kainhofer.com>
|
||
|
|
||
|
This program is free software; you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation; either version 2 of the License, or
|
||
|
(at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; if not, write to the Free Software
|
||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
15 years ago
|
#include <tqdatetime.h>
|
||
15 years ago
|
|
||
|
extern "C" {
|
||
14 years ago
|
#include <libical/ical.h>
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
#include "webdavhandler.h"
|
||
|
|
||
|
WebdavHandler::WebdavHandler()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
KURL WebdavHandler::toDAV( const KURL& url )
|
||
|
{
|
||
|
KURL result( url );
|
||
|
|
||
|
if ( result.protocol() == "http" ) {
|
||
|
if ( result.port() == 443 ) {
|
||
|
// OpenGroupware.org returns 'http://server:443' instead of 'https://server'
|
||
|
result.setProtocol( "webdavs" );
|
||
|
result.setPort( 0 );
|
||
|
} else
|
||
|
result.setProtocol( "webdav" );
|
||
|
} else if ( result.protocol() == "https" )
|
||
|
result.setProtocol( "webdavs" );
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
15 years ago
|
TQDomElement WebdavHandler::addElement( TQDomDocument &doc, TQDomNode &node,
|
||
|
const TQString &tag, const TQString &value )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomElement el = doc.createElement( tag );
|
||
15 years ago
|
node.appendChild( el );
|
||
|
if ( !value.isNull() ) {
|
||
15 years ago
|
TQDomText txt = doc.createTextNode( value );
|
||
15 years ago
|
el.appendChild( txt );
|
||
|
}
|
||
|
return el;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQDomElement WebdavHandler::addElementNS( TQDomDocument &doc, TQDomNode &node,
|
||
|
const TQString &ns, const TQString &tag, const TQString &value )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomElement el = doc.createElementNS( ns, tag );
|
||
15 years ago
|
node.appendChild( el );
|
||
|
if ( !value.isNull() ) {
|
||
15 years ago
|
TQDomText txt = doc.createTextNode( value );
|
||
15 years ago
|
el.appendChild( txt );
|
||
|
}
|
||
|
return el;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQDomElement WebdavHandler::addDavElement( TQDomDocument &doc, TQDomNode &node,
|
||
|
const TQString &tag, const TQString &value )
|
||
15 years ago
|
{
|
||
|
return addElementNS( doc, node, "DAV:", tag, value );
|
||
|
}
|
||
|
|
||
15 years ago
|
bool WebdavHandler::extractBool( const TQDomElement &node, const TQString &entry, bool &value )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomElement element = node.namedItem( entry ).toElement();
|
||
15 years ago
|
if ( !element.isNull() ) {
|
||
|
value = (element.text() != "0");
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool WebdavHandler::extractLong( const TQDomElement &node, const TQString &entry, long &value )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomElement element = node.namedItem( entry ).toElement();
|
||
15 years ago
|
if ( !element.isNull() ) {
|
||
|
value = element.text().toLong();
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool WebdavHandler::extractFloat( const TQDomElement &node, const TQString &entry, float &value )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomElement element = node.namedItem( entry ).toElement();
|
||
15 years ago
|
if ( !element.isNull() ) {
|
||
|
value = element.text().toFloat();
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool WebdavHandler::extractDateTime( const TQDomElement &node, const TQString &entry, TQDateTime &value )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomElement element = node.namedItem( entry ).toElement();
|
||
15 years ago
|
if ( !element.isNull() && !element.text().isEmpty() ) {
|
||
14 years ago
|
value = TQDateTime::fromString( element.text(), Qt::ISODate );
|
||
15 years ago
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool WebdavHandler::extractString( const TQDomElement &node, const TQString &entry, TQString &value )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomElement element = node.namedItem( entry ).toElement();
|
||
15 years ago
|
if ( !element.isNull() ) {
|
||
|
value = element.text();
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool WebdavHandler::extractStringList( const TQDomElement &node, const TQString &entry, TQStringList &value )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomElement element = node.namedItem( entry ).toElement();
|
||
15 years ago
|
if ( !element.isNull() ) {
|
||
|
value.clear();
|
||
15 years ago
|
TQDomNodeList list = element.elementsByTagNameNS( "xml:", "v" );
|
||
15 years ago
|
for( uint i=0; i < list.count(); i++ ) {
|
||
15 years ago
|
TQDomElement item = list.item(i).toElement();
|
||
15 years ago
|
value.append( item.text() );
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
const TQString WebdavHandler::getEtagFromHeaders( const TQString& headers )
|
||
15 years ago
|
{
|
||
14 years ago
|
int start = headers.find( "etag:", 0, false );
|
||
15 years ago
|
if ( start < 0 ) return TQString();
|
||
15 years ago
|
start += 6;
|
||
14 years ago
|
return headers.mid( start, headers.find( "\n", start ) - start );
|
||
15 years ago
|
}
|
||
|
|
||
|
//TODO: should not call libical functions directly -- better to make
|
||
|
// a new libkcal abstraction method.
|
||
15 years ago
|
TQDateTime WebdavHandler::utcAsZone( const TQDateTime& utc, const TQString& timeZoneId )
|
||
15 years ago
|
{
|
||
|
int daylight;
|
||
15 years ago
|
TQDateTime epoch;
|
||
15 years ago
|
epoch.setTime_t( 0 );
|
||
|
time_t v = epoch.secsTo( utc );
|
||
|
struct icaltimetype tt =
|
||
|
icaltime_from_timet_with_zone( v, 0 /*is_date*/,
|
||
|
icaltimezone_get_builtin_timezone( "UTC" ) );
|
||
|
int offset = icaltimezone_get_utc_offset(
|
||
|
icaltimezone_get_builtin_timezone( timeZoneId.latin1() ),
|
||
|
&tt, &daylight );
|
||
|
kdDebug() << "Calculated offset of: " << offset << " of timezone: " << timeZoneId << endl;
|
||
|
return utc.addSecs( offset );
|
||
|
}
|
||
|
|
||
|
//TODO: should not call libical functions directly -- better to make
|
||
|
// a new libkcal abstraction method.
|
||
15 years ago
|
TQDateTime WebdavHandler::zoneAsUtc( const TQDateTime& zone, const TQString& timeZoneId )
|
||
15 years ago
|
{
|
||
|
int daylight;
|
||
15 years ago
|
TQDateTime epoch;
|
||
15 years ago
|
epoch.setTime_t( 0 );
|
||
|
time_t v = epoch.secsTo( zone );
|
||
|
struct icaltimetype tt = icaltime_from_timet( v, 0 ); // 0: is_date=false
|
||
|
int offset = icaltimezone_get_utc_offset(
|
||
|
icaltimezone_get_builtin_timezone( timeZoneId.latin1() ),
|
||
|
&tt, &daylight );
|
||
|
return zone.addSecs( - offset );
|
||
|
}
|