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 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
|
/* -*- C++ -*- */
//=============================================================================
/**
* @file URL_Visitor.h
*
* $Id: URL_Visitor.h 93639 2011-03-24 13:32:13Z johnnyw $
*
* @author Douglas C.Schmidt <schmidt@cs.wustl.edu> Kirthika Parameswaran <kirthika@cs.wustl.edu>
*/
//=============================================================================
#ifndef _URL_VISITOR_H
#define _URL_VISITOR_H
#include /**/ "ace/pre.h"
#include "ace/Strategies_T.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
#pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
#include "HTTP_URL.h"
#include "Iterators.h"
#include "ace/Hash_Map_Manager_T.h"
#include "ace/Caching_Strategies_T.h"
#include "ace/Cached_Connect_Strategy_T.h"
#include "Options.h"
// Forward declarations.
class URL_Validation_Visitor;
/**
* @class URL_Processing_Strategy
*
* @brief Abstract base class for the URL processing strategy.
*
*/
class URL_Processing_Strategy
{
public:
/// Constructor.
URL_Processing_Strategy (URL &,
URL_Iterator &);
virtual ~URL_Processing_Strategy (void);
/// Perform the strategy.
virtual int execute (void) = 0;
virtual int destroy (void);
// Close down the resources.
protected:
/// A reference to the URL "context" that we're processing.
URL &url_;
/// Iterator for the URL that we're processing.
URL_Iterator &iterator_;
};
/**
* @class HTTP_Header_Processing_Strategy
*
* @brief Defines the HTTP header processing strategy.
*
*/
class HTTP_Header_Processing_Strategy : public URL_Processing_Strategy
{
public:
/// Constructor.
HTTP_Header_Processing_Strategy (URL &,
URL_Iterator &);
/// Perform the strategy for processing an HTTP header.
virtual int execute (void);
};
/**
* @class HTML_Body_Validation_Strategy
*
* @brief Defines the HTML body processing strategy.
*
* This class iterates through the body of an HTML file and
* recursively visits embedded links.
*/
class HTML_Body_Validation_Strategy : public URL_Processing_Strategy
{
public:
/// Constructor.
HTML_Body_Validation_Strategy (URL &,
URL_Iterator &,
URL_Validation_Visitor &);
/**
* Perform the strategy for processing an HTML file. This strategy
* iterates over the HTML file and recursively visits embedded links
* to process them, as well.
*/
virtual int execute (void);
private:
/// This is the context of the visit.
URL_Validation_Visitor &visitor_context_;
};
/**
* @class URL_Download_Strategy
*
* @brief Defines a URL downloading strategy.
*
* This class downloads a URL's contents into a temporary file.
*/
class URL_Download_Strategy : public URL_Processing_Strategy
{
public:
/// Constructor.
URL_Download_Strategy (URL &,
URL_Iterator &);
/// Perform the strategy for downloading a URL to a temporary file.
virtual int execute (void);
};
/**
* @class URL_Visitation_Strategy_Factory
*
* @brief Abstract Factory for the URL visitation strategy.
*
*/
class URL_Visitation_Strategy_Factory
{
public:
URL_Visitation_Strategy_Factory (URL *);
/// Destructor.
virtual ~URL_Visitation_Strategy_Factory (void);
// = Factory Methods.
/// Factory Method that makes the header iterator.
virtual URL_Iterator *make_header_iterator (void) = 0;
/// Factory Method that makes the body iterator.
virtual URL_Iterator *make_body_iterator (void) = 0;
/// Factory Method that makes the header processing strategy.
virtual URL_Processing_Strategy *make_header_strategy (URL_Iterator &) = 0;
/// Factory Method that makes the body processing strategy .
virtual URL_Processing_Strategy *make_body_strategy (URL_Iterator &) = 0;
/// Close down the resources.
virtual int destroy (void) = 0;
protected:
/// Stash the URL so we don't have to pass it around.
URL *url_;
};
/**
* @class URL_Download_Visitation_Strategy_Factory
*
* @brief Concrete Factory for the URL validation visitation strategy.
*
*/
class URL_Download_Visitation_Strategy_Factory : public URL_Visitation_Strategy_Factory
{
public:
/// Constructor.
URL_Download_Visitation_Strategy_Factory (URL *);
// = Factory Methods.
/// Factory Method that makes an <HTTP_Header_Iterator>.
virtual URL_Iterator *make_header_iterator (void);
/// Factory Method that makes an <HTML_Body_Iterator>.
virtual URL_Iterator *make_body_iterator (void);
/// Factory Method that makes the header processing strategy.
virtual URL_Processing_Strategy *make_header_strategy (URL_Iterator &);
/// Factory Method that makes the body processing strategy .
virtual URL_Processing_Strategy *make_body_strategy (URL_Iterator &);
/// Close down the resources.
virtual int destroy (void);
};
/**
* @class URL_Validation_Visitation_Strategy_Factory
*
* @brief Concrete Factory for the URL validation visitation strategy.
*
*/
class URL_Validation_Visitation_Strategy_Factory : public URL_Visitation_Strategy_Factory
{
public:
/// Constructor.
URL_Validation_Visitation_Strategy_Factory (URL *,
URL_Validation_Visitor &);
// = Factory Methods.
/// Factory Method that makes an <HTTP_Header_Iterator>.
virtual URL_Iterator *make_header_iterator (void);
/// Factory Method that makes an <HTML_Body_Iterator>.
virtual URL_Iterator *make_body_iterator (void);
/// Factory Method that makes the header processing strategy.
virtual URL_Processing_Strategy *make_header_strategy (URL_Iterator &);
/// Factory Method that makes the body processing strategy .
virtual URL_Processing_Strategy *make_body_strategy (URL_Iterator &);
/// Close down the resources.
virtual int destroy (void);
private:
/// Context of the visitor.
URL_Validation_Visitor &visitor_context_;
};
/**
* @class URL_Visitor
*
* @brief Base class for the URL Visitor.
*
* This class plays the "visitor" role in the Visitor pattern.
*/
class URL_Visitor
{
public:
virtual ~URL_Visitor (void);
/// Visit an <HTTP_URL>.
virtual int visit (HTTP_URL &http_url) = 0;
// @@
// virtual int visit (FTP_URL &http_url) = 0;
/// Cleanup the resources.
virtual int destroy (void) = 0;
protected:
/// Make the appropriate <URL_Visitation_Strategy_Factory>.
virtual URL_Visitation_Strategy_Factory *make_visitation_strategy_factory (URL &) = 0;
};
typedef int ATTRIBUTES;
typedef ACE_Svc_Handler <ACE_SOCK_STREAM, ACE_NULL_SYNCH>
Client_Svc_Handler;
typedef std::pair<Client_Svc_Handler *, ATTRIBUTES>
CACHED_HANDLER;
typedef ACE_Refcounted_Hash_Recyclable<ACE_INET_Addr>
ACE_ADDR;
typedef ACE_Hash<ACE_ADDR> H_KEY;
typedef ACE_Equal_To<ACE_ADDR> C_KEYS;
typedef ACE_Hash_Map_Manager_Ex<ACE_ADDR, CACHED_HANDLER, H_KEY, C_KEYS, ACE_Null_Mutex>
HASH_MAP;
typedef ACE_Hash_Map_Iterator_Ex<ACE_ADDR, CACHED_HANDLER, H_KEY, C_KEYS, ACE_Null_Mutex>
HASH_MAP_ITERATOR;
typedef ACE_Hash_Map_Reverse_Iterator_Ex<ACE_ADDR, CACHED_HANDLER, H_KEY, C_KEYS, ACE_Null_Mutex>
HASH_MAP_REVERSE_ITERATOR;
typedef ACE_Recyclable_Handler_Cleanup_Strategy<ACE_ADDR, CACHED_HANDLER, HASH_MAP>
CLEANUP_STRATEGY;
typedef ACE_Recyclable_Handler_Caching_Utility<ACE_ADDR, CACHED_HANDLER, HASH_MAP, HASH_MAP_ITERATOR, ATTRIBUTES>
CACHING_UTILITY;
typedef ACE_LRU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>
LRU_CACHING_STRATEGY;
typedef LRU_CACHING_STRATEGY
CACHING_STRATEGY;
typedef ACE_Strategy_Connector<Client_Svc_Handler, ACE_SOCK_CONNECTOR>
STRATEGY_CONNECTOR;
typedef ACE_NOOP_Creation_Strategy<Client_Svc_Handler>
NULL_CREATION_STRATEGY;
typedef ACE_NOOP_Concurrency_Strategy<Client_Svc_Handler>
NULL_ACTIVATION_STRATEGY;
typedef ACE_Cached_Connect_Strategy_Ex<Client_Svc_Handler, ACE_SOCK_CONNECTOR, CACHING_STRATEGY, ATTRIBUTES, ACE_SYNCH_NULL_MUTEX>
CACHED_CONNECT_STRATEGY;
/**
* @class URL_Validation_Visitor
*
* @brief Subclass that defines the URL validation visitor.
*
* This class checks to make sure that the <HTTP_URL> is valid.
* If the <HTTP_URL> is an <HTML> file, it can also be used to
* recursively check that all embedded links in this file are
* valid.
*/
class URL_Validation_Visitor : public URL_Visitor
{
public:
typedef ACE_Hash_Map_Manager <ACE_URL_Addr, URL_Status, ACE_Null_Mutex>
URL_CACHE;
/**
* Visit an <HTTP_URL> to make sure that it's valid. If the content
* type of the <HTTP_URL> is "text/html" and the <recursion> option
* is enabled then <visit> recursively checks each link embedded in
* the HTML page.
*/
virtual int visit (HTTP_URL &http_url);
// @@
// virtual int visit (FTP_URL &http_url);
/// Cleanup the resources.
URL_Validation_Visitor (void);
virtual int destroy (void);
/// Returns a reference to the URL cache.
URL_CACHE &url_cache (void);
protected:
/// Factory Method that makes a
/// <URL_Validation_Visitation_Strategy_Factory>.
virtual ~URL_Validation_Visitor (void);
virtual URL_Visitation_Strategy_Factory *make_visitation_strategy_factory (URL &);
/// Cache the status of URLs we've already validated.
URL_CACHE url_cache_;
/// Check to see if the reply status of this <url_addr> is in the
/// cache. Returns 1 if so, 0 if not.
int in_cache (const ACE_URL_Addr &url_addr);
NULL_CREATION_STRATEGY creation_strategy_;
NULL_ACTIVATION_STRATEGY activation_strategy_;
// Configure the Strategy Connector with a strategy that caches
// connection.
CACHED_CONNECT_STRATEGY *caching_connect_strategy_;
STRATEGY_CONNECTOR *strat_connector_;
CACHING_STRATEGY caching_strategy_;
};
/**
* @class URL_Download_Visitor
*
* @brief Subclass for the URL validtion visitor.
*
* This class checks to make sure that the <HTTP_URL> is valid.
*/
class URL_Download_Visitor : public URL_Visitor
{
public:
/**
* Visit an <HTTP_URL> to make sure that it's valid. If the content
* type of the <HTTP_URL> is "text/html" and the <recursion> option
* is enabled then <visit> recursively checks each link embedded in
* the HTML page.
*/
virtual int visit (HTTP_URL &http_url);
// @@
// virtual int visit (FTP_URL &http_url);
/// Cleanup the resources.
virtual int destroy (void);
protected:
/// Factory Method that makes a <URL_Download_Visitation_Strategy_Factory>.
URL_Visitation_Strategy_Factory *make_visitation_strategy_factory (URL &);
};
/**
* @class Auto_Destroyer
*
* @brief Simple class that ensures the <destroy> method is called on our
* <URL_*> objects when they go out of scope.
*
* This class is similar to an auto_ptr<> and should be used to
* simplify blocks of code that must create/destroy pointers to
* various <URL_*> related strategies and iterators.
*/
template <class T>
class Auto_Destroyer
{
public:
Auto_Destroyer (T *t): t_ (t) {}
T *operator-> (void) { return this->t_; }
T *operator *(void) { return this->t_; }
void operator= (T *t)
{
if (this->t_ != 0)
this->t_->destroy ();
this->t_ = t;
}
~Auto_Destroyer (void)
{
if (this->t_ != 0)
t_->destroy ();
}
private:
T *t_;
};
#include /**/ "ace/post.h"
#endif /* _URL_VISITOR_H */
|