LibreOffice Module ucb (master)  1
NeonHeadRequest.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
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.
15  *
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).
21  *
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.
26  *
27  ************************************************************************/
28 
29 #include <osl/mutex.hxx>
30 #include <sal/log.hxx>
31 #include "NeonHeadRequest.hxx"
32 #include "NeonSession.hxx"
33 
34 using namespace webdav_ucp;
35 using namespace com::sun::star;
36 
37 namespace {
38 
39 void process_headers( ne_request * req,
40  DAVResource & rResource,
41  const std::vector< OUString > & rHeaderNames )
42 {
43  void * cursor = nullptr;
44  const char * name, *value;
45 
46 #if defined SAL_LOG_INFO
47  {
48  for ( const auto& rHeader : rHeaderNames )
49  {
50  SAL_INFO( "ucb.ucp.webdav", "HEAD - requested header: " << rHeader );
51  }
52  }
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 ) );
58 
59  SAL_INFO( "ucb.ucp.webdav", "HEAD - received header: " << aHeaderName << ":" << aHeaderValue);
60 
61  // Note: Empty vector means that all headers are requested.
62  bool bIncludeIt = rHeaderNames.empty();
63 
64  if ( !bIncludeIt )
65  {
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  });
72 
73  if ( it != rHeaderNames.end() )
74  {
75  aHeaderName = *it;
76  bIncludeIt = true;
77  }
78  }
79 
80  if ( bIncludeIt )
81  {
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;
89 
90  // Add the newly created PropertyValue
91  rResource.properties.push_back( thePropertyValue );
92  }
93  }
94 }
95 
96 } // namespace
97 
99  const OUString & inPath,
100  const std::vector< OUString > &
101  inHeaderNames,
102  DAVResource & ioResource,
103  int & nError )
104 {
105  ioResource.uri = inPath;
106  ioResource.properties.clear();
107 
108  // Create and dispatch HEAD request. Install catcher for all response
109  // header fields.
110  ne_request * req = ne_request_create( inSession,
111  "HEAD",
113  inPath,
114  RTL_TEXTENCODING_UTF8 ).getStr() );
115 
116  {
117  osl::Guard< osl::Mutex > theGlobalGuard(getGlobalNeonMutex());
118  nError = ne_request_dispatch( req );
119  }
120 
121  process_headers( req, ioResource, inHeaderNames );
122 
123  if ( nError == NE_OK && ne_get_status( req )->klass != 2 )
124  nError = NE_ERROR;
125 
126  ne_request_destroy( req );
127 }
128 
130 {
131 }
132 
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IJScriptValueObject VARIANT value
ne_session HttpSession
Definition: NeonTypes.hxx:47
NeonHeadRequest(HttpSession *inSession, const OUString &inPath, const std::vector< OUString > &inHeaderNames, DAVResource &ioResource, int &nError)
osl::Mutex & getGlobalNeonMutex()
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
std::vector< DAVPropertyValue > properties
#define SAL_INFO(area, stream)
const char * name