summaryrefslogtreecommitdiff
path: root/ACE/apps/JAWS/clients/Caching/http_handler.h
blob: d6482dee30e04459810f651220432e6e7f0d3b16 (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
/* -*- c++ -*- */

//=============================================================================
/**
 *  @file    http_handler.h
 *
 *  @author James Hu
 */
//=============================================================================


#include "ace/SOCK_Connector.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Connector.h"
#include "ace/Svc_Handler.h"

/**
 * @class HTTP_Handler
 *
 * @brief A simple HTTP protocol handler for clients.
 *
 * Checks to see if the requested file is already cached.  If
 * so, it says so.  If not, the request is issued to the
 * connection.  The fetched file is cached.
 */
class HTTP_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
{
public:
  HTTP_Handler (void);
  HTTP_Handler (const char * path);

  /// Open hook.
  virtual int open (void *);

  /// Entry points defined by the abstract Svc_Handler.
  virtual int svc ();

  /// Accessor to the file being fetched.
  const char *filename (void) const;

private:
  char request_[BUFSIZ];
  size_t request_size_;

  char filename_[BUFSIZ];
  size_t response_size_;
};

/**
 * @class HTTP_Connector
 *
 * @brief A simple HTTP connector.
 *
 * Creates an HTTP Handler based on the URL, and then delegates
 * to to the SOCK_CONNECTOR.  Adapter pattern.
 */
class HTTP_Connector
{
public:
  /// User entry point into the HTTP connector.
  int connect (const char * url);

private:
  /// Helper function.
  int parseurl (const char *url,
                char *host,
                u_short *port,
                char *path);

private:
  /// Factory that actively establishes a connection with an HTTP
  /// server.
  ACE_Connector<HTTP_Handler, ACE_SOCK_CONNECTOR> connector_;
};