29 #include <config_lgpl.h>
41 struct LockSequenceParseContext
43 std::unique_ptr<ucb::Lock> pLock;
50 LockSequenceParseContext()
51 : hasLockScope( false ), hasLockType( false ),
52 hasDepth( false ), hasHREF( false ), hasTimeout( false ) {}
59 #define STATE_ACTIVELOCK (STATE_TOP)
60 #define STATE_LOCKSCOPE (STATE_TOP + 1)
61 #define STATE_LOCKTYPE (STATE_TOP + 2)
62 #define STATE_DEPTH (STATE_TOP + 3)
63 #define STATE_OWNER (STATE_TOP + 4)
64 #define STATE_TIMEOUT (STATE_TOP + 5)
65 #define STATE_LOCKTOKEN (STATE_TOP + 6)
66 #define STATE_EXCLUSIVE (STATE_TOP + 7)
67 #define STATE_SHARED (STATE_TOP + 8)
68 #define STATE_WRITE (STATE_TOP + 9)
69 #define STATE_HREF (STATE_TOP + 10)
81 if ( name !=
nullptr )
85 case NE_XML_STATEROOT:
86 if ( strcmp( name,
"activelock" ) == 0 )
91 if ( strcmp( name,
"lockscope" ) == 0 )
93 else if ( strcmp( name,
"locktype" ) == 0 )
95 else if ( strcmp( name,
"depth" ) == 0 )
97 else if ( strcmp( name,
"owner" ) == 0 )
99 else if ( strcmp( name,
"timeout" ) == 0 )
101 else if ( strcmp( name,
"locktoken" ) == 0 )
106 if ( strcmp( name,
"exclusive" ) == 0 )
108 else if ( strcmp( name,
"shared" ) == 0 )
113 if ( strcmp( name,
"write" ) == 0 )
118 if ( strcmp( name,
"href" ) == 0 )
127 return NE_XML_DECLINE;
137 LockSequenceParseContext * pCtx
138 =
static_cast< LockSequenceParseContext *
>( userdata );
140 pCtx->pLock.reset(
new ucb::Lock );
143 if ( buf[ len - 1 ] == 0x0a )
149 if ( rtl_str_compareIgnoreAsciiCase_WithLength(
150 buf, len,
"0", 1 ) == 0 )
152 pCtx->pLock->Depth = ucb::LockDepth_ZERO;
153 pCtx->hasDepth =
true;
155 else if ( rtl_str_compareIgnoreAsciiCase_WithLength(
156 buf, len,
"1", 1 ) == 0 )
158 pCtx->pLock->Depth = ucb::LockDepth_ONE;
159 pCtx->hasDepth =
true;
161 else if ( rtl_str_compareIgnoreAsciiCase_WithLength(
162 buf, len,
"infinity", 8 ) == 0 )
164 pCtx->pLock->Depth = ucb::LockDepth_INFINITY;
165 pCtx->hasDepth =
true;
168 SAL_WARN(
"ucb.ucp.webdav",
"LockSequence_chardata_callback - Unknown depth!" );
175 pCtx->pLock->Owner >>= aValue;
176 aValue += OUString( buf, len, RTL_TEXTENCODING_ASCII_US );
177 pCtx->pLock->Owner <<= aValue;
197 if ( rtl_str_compareIgnoreAsciiCase_WithLength(
198 buf, len,
"Infinite", 8 ) == 0 )
200 pCtx->pLock->Timeout = sal_Int64( -1 );
201 pCtx->hasTimeout =
true;
203 else if ( rtl_str_shortenedCompareIgnoreAsciiCase_WithLength(
204 buf, len,
"Second-", 7, 7 ) == 0 )
207 = OString( buf + 7, len - 7 ).toInt64();
208 pCtx->hasTimeout =
true;
217 pCtx->pLock->Timeout = sal_Int64( -1 );
218 pCtx->hasTimeout =
true;
219 SAL_WARN(
"ucb.ucp.webdav",
"LockSequence_chardata_callback - Unknown timeout!" );
226 sal_Int32
nPos = pCtx->pLock->LockTokens.getLength();
227 pCtx->pLock->LockTokens.realloc( nPos + 1 );
228 pCtx->pLock->LockTokens[ nPos ]
229 = OUString( buf, len, RTL_TEXTENCODING_ASCII_US );
230 pCtx->hasHREF =
true;
246 LockSequenceParseContext * pCtx
247 =
static_cast< LockSequenceParseContext *
>( userdata );
249 pCtx->pLock.reset(
new ucb::Lock );
254 pCtx->pLock->Scope = ucb::LockScope_EXCLUSIVE;
255 pCtx->hasLockScope =
true;
259 pCtx->pLock->Scope = ucb::LockScope_SHARED;
260 pCtx->hasLockScope =
true;
264 pCtx->pLock->Type = ucb::LockType_WRITE;
265 pCtx->hasLockType =
true;
269 if ( !pCtx->hasDepth )
274 if ( !pCtx->hasHREF )
279 if ( !pCtx->hasTimeout )
284 if ( !pCtx->hasLockScope )
289 if ( !pCtx->hasLockType )
294 if ( !pCtx->hasLockType || !pCtx->hasDepth )
308 uno::Sequence< ucb::Lock > & rOutData )
310 const sal_Int32 TOKEN_LENGTH = 13;
315 sal_Int32 nStart = 0;
316 sal_Int32 nEnd = rInData.indexOf(
"</activelock>" );
319 ne_xml_parser *
parser = ne_xml_create();
326 LockSequenceParseContext aCtx;
327 ne_xml_push_handler( parser,
333 ne_xml_parse( parser,
334 rInData.getStr() + nStart,
335 nEnd - nStart + TOKEN_LENGTH );
337 success = !ne_xml_failed( parser );
339 ne_xml_destroy( parser );
347 if ( nCount > rOutData.getLength() )
348 rOutData.realloc( rOutData.getLength() + 1 );
350 rOutData[ nCount - 1 ] = *aCtx.pLock;
353 nStart = nEnd + TOKEN_LENGTH;
354 nEnd = rInData.indexOf(
"</activelock>", nStart );
static int LockSequence_chardata_callback(void *userdata, int state, const char *buf, size_t len)
static bool createFromXML(const OString &rInData, css::uno::Sequence< css::ucb::Lock > &rOutData)
#define SAL_WARN(area, stream)
static int LockSequence_endelement_callback(void *userdata, int state, const char *, const char *)
static int LockSequence_startelement_callback(void *, int parent, const char *, const char *name, const char **)