summaryrefslogtreecommitdiff
path: root/apps/JAWS/server/Parse_Headers.h
blob: 2baec2862f91aaa01a91eeeb08131ffbc76815e1 (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
/* -*- c++ -*- */
// Hey, Emacs!  This is a C++ file!
// $Id$

// ============================================================================
//
// = LIBRARY
//    apps
// 
// = FILENAME
//    Parse_Headers
//
// = AUTHOR
//    James Hu
// 
// ============================================================================

#if !defined (PARSE_HEADERS_H)
#define PARSE_HEADERS_H

#include <ace/OS.h>

class Headers_Map
{
public:
  Headers_Map (void);
  ~Headers_Map (void);

  class Map_Item
  {
  public:
    Map_Item ();
    ~Map_Item ();

    operator const char * (void) const;
    Map_Item & operator= (char *);
    Map_Item & operator= (const char *);
    Map_Item & operator= (const Map_Item &);

    const char *header_;
    const char *value_;

    const char *no_value_;
  };

  Map_Item & operator[] (const char * const header);
  const Map_Item & operator[] (const char * const header) const;

  enum { MAX_HEADERS = 100 };

  int mapped (const char * const header) const;

private:
  Map_Item * find (const char * const header) const;
  Map_Item * place (const char * const header);
  static int compare (const void *item1, const void *item2);

private:
  Map_Item map_[MAX_HEADERS];
  Map_Item garbage;

  int num_headers_;
};

class Headers
  // = TITLE
  //     A general mechanism to parse headers of Internet text headers.
  //
  // = DESCRIPTION
  //     Allow interesting headers to be inserted and later associated
  //     with values.  This implementation assumes the parsing of headers
  //     will be done from ACE_Message_Blocks.
{
public:
  Headers (void);
  ~Headers (void);

  void recognize (const char * const header);

  void parse_header_line (char * const header_line);
  int complete_header_line (char * const header_line);

  int end_of_headers (void) const;

  enum { MAX_HEADER_LINE_LENGTH = 8192 };

  Headers_Map::Map_Item & operator[] (const char * const header);
  const Headers_Map::Map_Item & operator[] (const char * const header) const;

private:
  int end_of_line (char * &line, int &offset) const;

private:
  Headers_Map map_;
  int done_;
};

#endif /* PARSE_HEADERS_H */