Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / ucb / source / ucp / webdav-neon / NeonHeadRequest.cxx
blobe124bfd524dd23df00c156aa6aafc8e4fb2d6c7f
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 <osl/mutex.hxx>
30 #include <sal/log.hxx>
31 #include "NeonHeadRequest.hxx"
32 #include "NeonSession.hxx"
34 using namespace webdav_ucp;
35 using namespace com::sun::star;
37 namespace {
39 void process_headers( ne_request * req,
40 DAVResource & rResource,
41 const std::vector< OUString > & rHeaderNames )
43 void * cursor = nullptr;
44 const char * name, *value;
46 #if defined SAL_LOG_INFO
48 for ( const auto& rHeader : rHeaderNames )
50 SAL_INFO( "ucb.ucp.webdav", "HEAD - requested header: " << rHeader );
53 #endif
54 while ( ( cursor = ne_response_header_iterate( req, cursor,
55 &name, &value ) ) != nullptr ) {
56 OUString aHeaderName( OUString::createFromAscii( name ) );
57 OUString aHeaderValue( OUString::createFromAscii( value ) );
59 SAL_INFO( "ucb.ucp.webdav", "HEAD - received header: " << aHeaderName << ":" << aHeaderValue);
61 // Note: Empty vector means that all headers are requested.
62 bool bIncludeIt = rHeaderNames.empty();
64 if ( !bIncludeIt )
66 // Check whether this header was requested.
67 auto it = std::find_if(rHeaderNames.begin(), rHeaderNames.end(),
68 [&aHeaderName](const OUString& rName) {
69 // header names are case insensitive
70 return rName.equalsIgnoreAsciiCase( aHeaderName );
71 });
73 if ( it != rHeaderNames.end() )
75 aHeaderName = *it;
76 bIncludeIt = true;
80 if ( bIncludeIt )
82 // Create & set the PropertyValue
83 DAVPropertyValue thePropertyValue;
84 // header names are case insensitive, so are the
85 // corresponding property names
86 thePropertyValue.Name = aHeaderName.toAsciiLowerCase();
87 thePropertyValue.IsCaseSensitive = false;
88 thePropertyValue.Value <<= aHeaderValue;
90 // Add the newly created PropertyValue
91 rResource.properties.push_back( thePropertyValue );
96 } // namespace
98 NeonHeadRequest::NeonHeadRequest( HttpSession * inSession,
99 const OUString & inPath,
100 const std::vector< OUString > &
101 inHeaderNames,
102 DAVResource & ioResource,
103 int & nError )
105 ioResource.uri = inPath;
106 ioResource.properties.clear();
108 // Create and dispatch HEAD request. Install catcher for all response
109 // header fields.
110 ne_request * req = ne_request_create( inSession,
111 "HEAD",
112 OUStringToOString(
113 inPath,
114 RTL_TEXTENCODING_UTF8 ).getStr() );
117 osl::Guard< osl::Mutex > theGlobalGuard(getGlobalNeonMutex());
118 nError = ne_request_dispatch( req );
121 process_headers( req, ioResource, inHeaderNames );
123 if ( nError == NE_OK && ne_get_status( req )->klass != 2 )
124 nError = NE_ERROR;
126 ne_request_destroy( req );
129 NeonHeadRequest::~NeonHeadRequest()
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */