summaryrefslogtreecommitdiff
path: root/ACE/protocols/ace/INet/URLBase.h
blob: fff34cfd26945cfdbb272106e3d191fd105f29e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
// $Id$

/**
 * @file URLBase.h
 *
 * @author Martin Corino <mcorino@remedy.nl>
 */

#ifndef ACE_INET_URL_BASE_H
#define ACE_INET_URL_BASE_H

#include /**/ "ace/pre.h"

#include "ace/SString.h"
#include "ace/Map_Manager.h"
#include "ace/Singleton.h"
#include "ace/Null_Mutex.h"
#include "ace/Recursive_Thread_Mutex.h"
#include "ace/Refcounted_Auto_Ptr.h"
#include "ace/INet/INet_Export.h"
#include "ace/INet/AuthenticationBase.h"
#include "ace/INet/ClientRequestHandler.h"
#include <iosfwd>

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

namespace ACE
  {
    namespace INet
      {

        /**
        * @class ACE_INet_URLStream
        *
        * @brief Provides abstracted wrapper class for the resulting
        *   stream of an URL <open> operation.
        *
        * Provides proper life cycle management for either factory provided
        * or user provided request handlers.
        */
        class ACE_INET_Export URLStream
          {
            public:
              URLStream (const URLStream& url_stream);
              ~URLStream ();

              bool operator ! ();

              operator bool ();

              std::istream& operator * ();

              std::istream* operator -> ();

            private:
              friend class URL_Base;

              URLStream (ClientRequestHandler& rh);
              URLStream (ClientRequestHandler* rh);

              typedef ACE_Refcounted_Auto_Ptr<ClientRequestHandler,
                                              ACE_Null_Mutex> TRequestHandlerRef;

              TRequestHandlerRef request_handler_ref_;
              ClientRequestHandler* request_handler_;
          };

        /**
        * @class ACE_INet_URL_Base
        *
        * @brief Base class for URL/URI addresses conforming to RFC3986.
        *
        */
        class ACE_INET_Export URL_Base
          {
            public:
              URL_Base ();
              virtual ~URL_Base ();

              virtual bool parse (const ACE_CString& url_string);

              void set_path (const ACE_CString& path);

              virtual void set_query (const ACE_CString& query);

              virtual void set_fragment (const ACE_CString& fragment);

              virtual const ACE_CString& get_scheme () const = 0;

              const ACE_CString& get_protocol () const;

              virtual ACE_CString get_authority () const;

              const ACE_CString& get_path () const;

              virtual const ACE_CString& get_query () const;

              virtual const ACE_CString& get_fragment () const;

              virtual URLStream open () const;

              virtual URLStream open (ClientRequestHandler& rh) const;

              virtual ACE_CString to_string () const = 0;

              static URL_Base* create_from_string (const ACE_CString& url_string);

#if defined (ACE_HAS_WCHAR)
              virtual bool parse (const ACE_WString& url_string);

              virtual ACE_WString to_wstring () const;

              static URL_Base* create_from_wstring (const ACE_WString& url_string);
#endif

              virtual bool validate ();

            protected:
              static const ACE_CString empty_;

              bool strip_scheme (ACE_CString& url_string);

              virtual int parse_authority (std::istream& is);

              virtual bool has_authority ();

              virtual ClientRequestHandler* create_default_request_handler () const = 0;

            private:
              ACE_CString path_;

            public:
              class ACE_INET_Export Factory
                {
                  public:
                    Factory ();
                    virtual ~Factory ();
                    virtual const ACE_CString& protocol () = 0;
                    virtual URL_Base* create_from_string (const ACE_CString& url_string) = 0;
                };

              static void register_factory (Factory* url_factory);
              static void deregister_factory (Factory* url_factory);

            private:
              typedef ACE_Map_Manager<ACE_CString,
                                      Factory*,
                                      ACE_SYNCH::MUTEX> TURLFactoryMap;
              typedef ACE_Singleton<TURLFactoryMap,
                                    ACE_SYNCH::NULL_MUTEX> TURLFactorySingleton;
              static TURLFactoryMap* factories_;
          };

        /**
        * @class ACE_INet_URL_INetBase
        *
        * @brief Base class for internet protocol based URL/URI
        *        addresses supporting host(name) and port specification.
        *
        */
        class ACE_INET_Export URL_INetBase
          : public URL_Base
          {
            public:
              URL_INetBase(u_short port);
              virtual ~URL_INetBase ();

              void set_host (const ACE_CString& host);

              void set_port (u_short port);

              const ACE_CString& get_host () const;

              u_short get_port () const;

              virtual u_short default_port () const = 0;

              virtual ACE_CString get_authority () const;

              virtual bool validate ();

            protected:
              virtual int parse_authority (std::istream& is);

              virtual bool has_authority ();

              int parse_authority_i (std::istream& is,
                                     std::ostream& os,
                                     int lastch);

            private:
              ACE_CString host_;
              u_short port_;
          };


        /**
        * @class ACE_INet_URL_INetAuthBase
        *
        * @brief Base class for internet protocol based URL/URI
        *        addresses supporting authentication information.
        *
        * This implementation does *not* support the specification
        * of passwords in user_info field of the URL (deprecated as
        * of RFC3986).
        */
        class ACE_INET_Export URL_INetAuthBase
          : public URL_INetBase
          {
            public:
              URL_INetAuthBase(u_short port);
              virtual ~URL_INetAuthBase ();

              const ACE_CString& get_user_info () const;

              void set_user_info (const ACE_CString& userinfo);

              virtual ACE_CString get_authority () const;

            protected:
              virtual int parse_authority (std::istream& is);

            private:
              ACE_CString userinfo_;

            public:
              static bool add_authenticator (const ACE_CString& auth_id, AuthenticatorBase* authenticator);

              static bool has_authenticator (const ACE_CString& auth_id);

              static AuthenticatorBase* remove_authenticator (const ACE_CString& auth_id);

              static bool authenticate (AuthenticationBase& authentication);

            private:
              typedef ACE_Refcounted_Auto_Ptr<AuthenticatorBase,
                                              ACE_SYNCH::NULL_MUTEX> authenticator_ptr;
              typedef ACE_Map_Manager<ACE_CString,
                                      authenticator_ptr,
                                      ACE_SYNCH::RECURSIVE_MUTEX>  authenticator_map;

              static authenticator_map authenticators_;
          };

      }
  }

ACE_END_VERSIONED_NAMESPACE_DECL

#if defined (__ACE_INLINE__)
#include "ace/INet/URLBase.inl"
#endif

#include /**/ "ace/post.h"
#endif /* ACE_INET_URL_BASE_H */