1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _UCBHELPER_PROXYDECIDER_HXX
25 #define _UCBHELPER_PROXYDECIDER_HXX
26 
27 #include <rtl/ustring.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include "ucbhelper/ucbhelperdllapi.h"
30 
31 namespace com { namespace sun { namespace star { namespace lang {
32     class XMultiServiceFactory;
33 } } } }
34 
35 namespace ucbhelper
36 {
37 
38 /**
39  * This struct describes a proxy server.
40  */
41 struct InternetProxyServer
42 {
43     /**
44       * The name of the proxy server.
45       */
46     ::rtl::OUString aName;
47 
48     /**
49       * The port of the proxy server.
50       */
51     sal_Int32 nPort;
52 
53     /**
54       * Constructor.
55       */
InternetProxyServerucbhelper::InternetProxyServer56     InternetProxyServer() : nPort( -1 ) {}
57 };
58 
59 namespace proxydecider_impl { class InternetProxyDecider_Impl; }
60 
61 /**
62  * This class is able to decide whether and which internet proxy server is to
63  * be used to access a given URI.
64  *
65  * The implementation reads the internet proxy settings from Office
66  * configuration. It listens for configuration changes and adapts itself
67  * accordingly. Because configuration data can change during runtime clients
68  * should not cache results obtained from InternetProxyDecider instances. One
69  * instance should be kept to be queried multiple times instead.
70  */
71 class UCBHELPER_DLLPUBLIC InternetProxyDecider
72 {
73 public:
74     /**
75       * Constructor.
76       *
77       * Note: Every instance should be held alive as long as possible because
78       *       because construction is quite expensive.
79       *
80       * @param rxSMgr is a Service Manager.
81       */
82     InternetProxyDecider( const ::com::sun::star::uno::Reference<
83                     ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr );
84 
85     /**
86       * Destructor.
87       */
88     ~InternetProxyDecider();
89 
90     /**
91       * Informs whether a proxy server should be used.
92       *
93       * @param rProtocol contains the internet protocol to be used to
94       *         access the server (i.e. "ftp", "http"). The protocol string
95       *         is handled case-insensitive and must not be empty.
96       * @param rHost contains the name of the server that should be accessed.
97       *         This parameter might be left empty. In this case the
98       *         implementation will return whether a proxy is configured
99       *         for the given protocol.
100       * @param nPort contains the port of the server that should be accessed.
101       *         If host is not empty this parameter must always contain a valid
102       *         port number, for instance the default port for the requested
103       *         protocol(i.e. 80 or http).
104       * @return true if a proxy server should be used, false otherwise.
105       */
106     bool
107     shouldUseProxy( const rtl::OUString & rProtocol,
108                     const rtl::OUString & rHost,
109                     sal_Int32 nPort ) const;
110 
111     /**
112       * Returns the proxy server to be used.
113       *
114       * @param rProtocol contains the internet protocol to be used to
115       *         access the server (i.e. "ftp", "http"). The protocol string
116       *         is handled case-insensitive and must not be empty.
117       * @param rHost contains the name of the server that should be accessed.
118       *         This parameter might be left empty. In this case the
119       *         implementation will return the proxy that is configured
120       *         for the given protocol.
121       * @param nPort contains the port of the server that should be accessed.
122       *         If host is not empty this parameter must always contain a valid
123       *         port number, for instance the default port for the requested
124       *         protocol(i.e. 80 or http).
125       * @return a InternetProxyServer reference. If member aName of the
126       *         InternetProxyServer is empty no proxy server is to be used.
127       */
128     const InternetProxyServer &
129     getProxy( const rtl::OUString & rProtocol,
130               const rtl::OUString & rHost,
131               sal_Int32 nPort ) const;
132 
133 private:
134     proxydecider_impl::InternetProxyDecider_Impl * m_pImpl;
135 };
136 
137 } // namespace ucbhelper
138 
139 #endif /* !_UCBHELPER_PROXYDECIDER_HXX */
140