1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <config_lgpl.h>
32 #include "LockEntrySequence.hxx"
34 using namespace webdav_ucp
;
35 using namespace com::sun::star
;
39 struct LockEntrySequenceParseContext
41 ucb::LockEntry
* pEntry
;
45 LockEntrySequenceParseContext()
46 : pEntry( 0 ), hasScope( false ), hasType( false ) {}
47 ~LockEntrySequenceParseContext() { delete pEntry
; }
52 #define STATE_LOCKENTRY (STATE_TOP)
53 #define STATE_LOCKSCOPE (STATE_TOP + 1)
54 #define STATE_EXCLUSIVE (STATE_TOP + 2)
55 #define STATE_SHARED (STATE_TOP + 3)
56 #define STATE_LOCKTYPE (STATE_TOP + 4)
57 #define STATE_WRITE (STATE_TOP + 5)
60 extern "C" int LockEntrySequence_startelement_callback(
63 const char * /*nspace*/,
71 case NE_XML_STATEROOT
:
72 if ( strcmp( name
, "lockentry" ) == 0 )
73 return STATE_LOCKENTRY
;
77 if ( strcmp( name
, "lockscope" ) == 0 )
78 return STATE_LOCKSCOPE
;
79 else if ( strcmp( name
, "locktype" ) == 0 )
80 return STATE_LOCKTYPE
;
82 #define IIS_BUGS_WORKAROUND
84 #ifdef IIS_BUGS_WORKAROUND
85 /* IIS (6) returns XML violating RFC 4918
86 for DAV:supportedlock property value.
94 <exclusive></exclusive>
99 else if ( strcmp( name
, "exclusive" ) == 0 )
100 return STATE_EXCLUSIVE
;
101 else if ( strcmp( name
, "shared" ) == 0 )
103 else if ( strcmp( name
, "write" ) == 0 )
108 case STATE_LOCKSCOPE
:
109 if ( strcmp( name
, "exclusive" ) == 0 )
110 return STATE_EXCLUSIVE
;
111 else if ( strcmp( name
, "shared" ) == 0 )
116 if ( strcmp( name
, "write" ) == 0 )
121 return NE_XML_DECLINE
;
125 extern "C" int LockEntrySequence_chardata_callback(
131 return 0; // zero to continue, non-zero to abort parsing
135 extern "C" int LockEntrySequence_endelement_callback(
141 LockEntrySequenceParseContext
* pCtx
142 = static_cast< LockEntrySequenceParseContext
* >( userdata
);
144 pCtx
->pEntry
= new ucb::LockEntry
;
148 case STATE_EXCLUSIVE
:
149 pCtx
->pEntry
->Scope
= ucb::LockScope_EXCLUSIVE
;
150 pCtx
->hasScope
= true;
154 pCtx
->pEntry
->Scope
= ucb::LockScope_SHARED
;
155 pCtx
->hasScope
= true;
159 pCtx
->pEntry
->Type
= ucb::LockType_WRITE
;
160 pCtx
->hasType
= true;
163 case STATE_LOCKSCOPE
:
164 if ( !pCtx
->hasScope
)
169 if ( !pCtx
->hasType
)
173 case STATE_LOCKENTRY
:
174 if ( !pCtx
->hasType
|| !pCtx
->hasScope
)
181 return 0; // zero to continue, non-zero to abort parsing
186 bool LockEntrySequence::createFromXML( const OString
& rInData
,
188 ucb::LockEntry
> & rOutData
)
190 const sal_Int32 TOKEN_LENGTH
= 12; // </lockentry>
193 // rInData may contain multiple <lockentry>...</lockentry> tags.
194 sal_Int32 nCount
= 0;
195 sal_Int32 nStart
= 0;
196 sal_Int32 nEnd
= rInData
.indexOf( "</lockentry>" );
199 ne_xml_parser
* parser
= ne_xml_create();
206 LockEntrySequenceParseContext aCtx
;
207 ne_xml_push_handler( parser
,
208 LockEntrySequence_startelement_callback
,
209 LockEntrySequence_chardata_callback
,
210 LockEntrySequence_endelement_callback
,
213 ne_xml_parse( parser
,
214 rInData
.getStr() + nStart
,
215 nEnd
- nStart
+ TOKEN_LENGTH
);
217 success
= !ne_xml_failed( parser
);
219 ne_xml_destroy( parser
);
227 if ( nCount
> rOutData
.getLength() )
228 rOutData
.realloc( rOutData
.getLength() + 2 );
230 rOutData
[ nCount
- 1 ] = *aCtx
.pEntry
;
233 nStart
= nEnd
+ TOKEN_LENGTH
;
234 nEnd
= rInData
.indexOf( "</lockentry>", nStart
);
237 rOutData
.realloc( nCount
);
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */