summaryrefslogtreecommitdiff
path: root/apps/JAWS2/HTTP_10_Request.cpp
blob: 8acb19219075088159dc9501fcaf7d414ac3f432 (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
// $Id$

#include "JAWS/JAWS.h"
#include "HTTP_10_Request.h"
#include "ace/OS_NS_pwd.h"

ACE_RCSID(PROTOTYPE, HTTP_10_Request, "$Id$")

static int dummy;

JAWS_HTTP_10_Request::JAWS_HTTP_10_Request (void)
  : path_ (0)
{
}

JAWS_HTTP_10_Request::~JAWS_HTTP_10_Request (void)
{
  ACE_OS::free (this->path_);
  this->path_ = 0;
}

const char *
JAWS_HTTP_10_Request::method (void) const
{
  return this->request_line ()->method_str ();
}

const char *
JAWS_HTTP_10_Request::uri (void) const
{
  return this->request_line ()->url ();
}

const char *
JAWS_HTTP_10_Request::version (void) const
{
  return this->request_line ()->version ();
}

int
JAWS_HTTP_10_Request::type (void) const
{
  return this->request_line ()->method ();
}

const char *
JAWS_HTTP_10_Request::path (void) const
{
  if (this->path_ == 0)
    {
      JAWS_HTTP_10_Request *mutable_this = (JAWS_HTTP_10_Request *)this;
      mutable_this->path (this->uri ());
    }
  return this->path_;
}

void
JAWS_HTTP_10_Request::set_status (int s)
{
  HTTP_Request::set_status (s);
}

void
JAWS_HTTP_10_Request::path (const char *uri_string)
{
  char const *file_name = uri_string;
  char buf[MAXPATHLEN + 1];
  buf[0] = '\0';

  if (file_name == 0) return;

  if (*file_name == '/')
    {
      file_name++;
      if (*file_name == '~')
        {
          char *ptr = buf;

          while (*++file_name && *file_name != '/')
            *ptr++ = *file_name;

          *ptr = '\0';

          if (ptr == buf)
            ACE_OS::strcpy (buf, ACE_OS::getenv ("HOME"));
          else
            {
#if !defined (ACE_WIN32) && !defined (VXWORKS)
              char pw_buf[BUFSIZ];
              struct passwd pw_struct;
              if (ACE_OS::getpwnam_r (buf, &pw_struct, pw_buf, sizeof (pw_buf))
                  == 0)
                return;
              ACE_OS::strcpy (buf, pw_struct.pw_dir);
#endif /* NOT ACE_WIN32 AND NOT VXWORKS */
            }

          ACE_OS::strcat (buf, "/");
#if 0
          ACE_OS::strcat (buf, HTTP_Config::instance ()->user_dir ());
#else
          ACE_OS::strcat (buf, ".www-docs");
#endif
          ACE_OS::strcat (buf, file_name);
        }
      else
        {
          // With a starting '/' but no '~'
#if 0
          ACE_OS::strcat (buf, HTTP_Config::instance ()->document_root ());
#else
          ACE_OS::strcat (buf, ".");
#endif
          ACE_OS::strcat (buf, file_name - 1);
        }
    }

  if (*buf != '\0')
    this->path_ = ACE_OS::strdup (buf);
}