summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1997-07-03 02:07:32 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1997-07-03 02:07:32 +0000
commit55d0702b7bb42343d718660bb47daecb1ce7bfb0 (patch)
treed018338ab123131536c49f1ae9039435f6823da3
parent290b5b1a22a482febbda2257534771a397e32082 (diff)
downloadATCD-55d0702b7bb42343d718660bb47daecb1ce7bfb0.tar.gz
*** empty log message ***
-rw-r--r--ChangeLog-97a11
-rw-r--r--TAO/VERSION2
-rw-r--r--ace/Hash_Map_Manager.cpp10
-rw-r--r--apps/JAWS/server/ChangeLog5
-rw-r--r--apps/JAWS/server/HTTP_Config.cpp32
-rw-r--r--apps/JAWS/server/HTTP_Config.h42
-rw-r--r--apps/JAWS/server/HTTP_Handler.cpp31
-rw-r--r--apps/JAWS/server/HTTP_Handler.h30
-rw-r--r--apps/JAWS/server/HTTP_Helpers.cpp190
-rw-r--r--apps/JAWS/server/HTTP_Helpers.h40
-rw-r--r--apps/JAWS/server/HTTP_Request.cpp182
-rw-r--r--apps/JAWS/server/HTTP_Request.h73
-rw-r--r--apps/JAWS/server/HTTP_Response.cpp114
-rw-r--r--apps/JAWS/server/HTTP_Response.h16
-rw-r--r--apps/JAWS/server/HTTP_Server.cpp95
-rw-r--r--apps/JAWS/server/HTTP_Server.h13
-rw-r--r--apps/JAWS/server/HTTP_Server_T.h17
-rw-r--r--apps/JAWS/server/IO.cpp128
-rw-r--r--apps/JAWS/server/IO.h70
-rw-r--r--apps/JAWS/server/JAWS_File.cpp173
-rw-r--r--apps/JAWS/server/JAWS_File.h165
-rw-r--r--apps/JAWS/server/Parse_Headers.cpp151
-rw-r--r--apps/JAWS/server/Parse_Headers.h47
-rw-r--r--apps/JAWS/server/main.cpp10
-rw-r--r--apps/JAWS/server/test_HTTP_Request.cpp44
25 files changed, 1023 insertions, 668 deletions
diff --git a/ChangeLog-97a b/ChangeLog-97a
index 62ec57db13a..f7c30a637ab 100644
--- a/ChangeLog-97a
+++ b/ChangeLog-97a
@@ -1,3 +1,14 @@
+Wed Jul 2 17:37:09 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu>
+
+ * ace/Hash_Map_Manager.cpp: Clarified the behavior of close_i() a
+ bit more.
+
+Wed Jul 2 09:54:36 1997 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu>
+
+ * ace/Hash_Map_Manager.cpp: Fixed a couple more size_t->u_long
+ conversions for ACE_Hash_Map_Manager::hash(). This didn't harm
+ anything but it's good to be consistent.
+
Wed Jul 2 16:46:59 1997 Nanbor Wang <nw1@cumbia.cs.wustl.edu>
* performance-tests/Misc/childbirth_time.cpp: Added this program
diff --git a/TAO/VERSION b/TAO/VERSION
index 9568b9659f1..ec30bb3f377 100644
--- a/TAO/VERSION
+++ b/TAO/VERSION
@@ -1,4 +1,4 @@
-This is TAO version 0.0.1, released .
+This is TAO version 0.0.2
If you have any problems with TAO, please send email to Douglas
C. Schmidt (schmidt@cs.wustl.edu).
diff --git a/ace/Hash_Map_Manager.cpp b/ace/Hash_Map_Manager.cpp
index 95441fa8dd2..f62969adade 100644
--- a/ace/Hash_Map_Manager.cpp
+++ b/ace/Hash_Map_Manager.cpp
@@ -145,6 +145,8 @@ ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::close_i (void)
{
if (this->table_ != 0)
{
+ // Iterate through the entire map calling the destuctor of each
+ // <ACE_Hash_Map_Entry>.
for (size_t i = 0; i < this->total_size_; i++)
{
for (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *temp_ptr = this->table_[i];
@@ -209,7 +211,7 @@ template <class EXT_ID, class INT_ID, class LOCK> int
ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::bind_i (const EXT_ID &ext_id,
const INT_ID &int_id)
{
- size_t loc = this->hash (ext_id) % this->total_size_;
+ u_long loc = this->hash (ext_id) % this->total_size_;
ACE_Hash_Map_Entry<EXT_ID, INT_ID> *temp = this->table_[loc];
@@ -249,7 +251,7 @@ template <class EXT_ID, class INT_ID, class LOCK> int
ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::trybind_i (const EXT_ID &ext_id,
INT_ID &int_id)
{
- size_t loc = this->hash (ext_id) % this->total_size_;
+ u_long loc = this->hash (ext_id) % this->total_size_;
ACE_Hash_Map_Entry<EXT_ID, INT_ID> *temp = this->table_[loc];
@@ -293,7 +295,7 @@ template <class EXT_ID, class INT_ID, class LOCK> int
ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::unbind_i (const EXT_ID &ext_id,
INT_ID &int_id)
{
- size_t loc = this->hash (ext_id) % this->total_size_;
+ u_long loc = this->hash (ext_id) % this->total_size_;
ACE_Hash_Map_Entry<EXT_ID, INT_ID> *temp = this->table_[loc];
ACE_Hash_Map_Entry<EXT_ID, INT_ID> *prev = 0;
@@ -348,7 +350,7 @@ template <class EXT_ID, class INT_ID, class LOCK> int
ACE_Hash_Map_Manager<EXT_ID, INT_ID, LOCK>::shared_find (const EXT_ID &ext_id,
ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry)
{
- size_t loc = this->hash (ext_id) % this->total_size_;
+ u_long loc = this->hash (ext_id) % this->total_size_;
ACE_Hash_Map_Entry<EXT_ID, INT_ID> *temp = this->table_[loc];
diff --git a/apps/JAWS/server/ChangeLog b/apps/JAWS/server/ChangeLog
index 336b88957bb..37937be72c5 100644
--- a/apps/JAWS/server/ChangeLog
+++ b/apps/JAWS/server/ChangeLog
@@ -1,3 +1,8 @@
+Wed Jul 2 21:03:12 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu>
+
+ * Made a major pass through all the code and made the style
+ consistent with that found in ACE.
+
Wed Jul 2 14:33:27 1997 James C Hu <jxh@lambada.cs.wustl.edu>
* JAWS_File.cpp: Added double check locking pattern to the fetch
diff --git a/apps/JAWS/server/HTTP_Config.cpp b/apps/JAWS/server/HTTP_Config.cpp
index 99bc2fb369e..656de0b4738 100644
--- a/apps/JAWS/server/HTTP_Config.cpp
+++ b/apps/JAWS/server/HTTP_Config.cpp
@@ -2,18 +2,19 @@
// $Id$
#include "ace/OS.h"
-
#include "HTTP_Config.h"
+// James, is it possible to eliminate this static object? They are
+// non-portable.
static HTTP_Config_Info config_info;
-HTTP_Config_Info * HTTP_Config::instance_ = 0;
+HTTP_Config_Info *HTTP_Config::instance_ = 0;
HTTP_Config_Info *
HTTP_Config::instance (void)
{
if (HTTP_Config::instance_ == 0)
{
- HTTP_Config::instance_ = & ::config_info;
+ HTTP_Config::instance_ = &config_info;
HTTP_Config::instance_->document_root (0);
HTTP_Config::instance_->cgi_path (0);
@@ -71,11 +72,13 @@ HTTP_Config_Info::proxy_flag (void) const
char *
HTTP_Config_Info::document_root (char *dr_string)
{
- if (dr_string) this->document_root_ = dr_string;
+ if (dr_string)
+ this->document_root_ = dr_string;
else
{
this->document_root_ = ACE_OS::getenv ("JAWS_DOCUMENT_ROOT");
- if (! this->document_root_) this->document_root_ = ".";
+ if (!this->document_root_)
+ this->document_root_ = ".";
}
return this->document_root_;
@@ -84,11 +87,14 @@ HTTP_Config_Info::document_root (char *dr_string)
char *
HTTP_Config_Info::cgi_path (char *cp_string)
{
- if (cp_string) this->cgi_path_ = cp_string;
+ if (cp_string)
+ this->cgi_path_ = cp_string;
else
{
this->cgi_path_ = ACE_OS::getenv ("JAWS_CGI_PATH");
- if (! this->cgi_path_) this->cgi_path_ = "cgi-bin";
+
+ if (!this->cgi_path_)
+ this->cgi_path_ = "cgi-bin";
}
return this->cgi_path_;
@@ -97,11 +103,13 @@ HTTP_Config_Info::cgi_path (char *cp_string)
char *
HTTP_Config_Info::user_dir (char *ud_string)
{
- if (ud_string) this->user_dir_ = ud_string;
+ if (ud_string)
+ this->user_dir_ = ud_string;
else
{
this->user_dir_ = ACE_OS::getenv ("JAWS_USER_DIR");
- if (! this->user_dir_) this->user_dir_ = ".www";
+ if (!this->user_dir_)
+ this->user_dir_ = ".www";
}
return this->user_dir_;
@@ -110,11 +118,13 @@ HTTP_Config_Info::user_dir (char *ud_string)
char *
HTTP_Config_Info::dir_index (char *di_string)
{
- if (di_string) this->dir_index_ = di_string;
+ if (di_string)
+ this->dir_index_ = di_string;
else
{
this->dir_index_ = ACE_OS::getenv ("JAWS_DIR_INDEX");
- if (! this->dir_index_) this->dir_index_ = "index.html";
+ if (!this->dir_index_)
+ this->dir_index_ = "index.html";
}
return this->dir_index_;
diff --git a/apps/JAWS/server/HTTP_Config.h b/apps/JAWS/server/HTTP_Config.h
index 866e1d044fa..78b005758ee 100644
--- a/apps/JAWS/server/HTTP_Config.h
+++ b/apps/JAWS/server/HTTP_Config.h
@@ -5,7 +5,7 @@
// ============================================================================
//
// = LIBRARY
-// apps
+// jaws
//
// = FILENAME
// HTTP_Config.h
@@ -15,6 +15,7 @@
//
// ============================================================================
+// = Forward declaration.
class HTTP_Config_Info;
class HTTP_Config
@@ -28,59 +29,58 @@ class HTTP_Config
{
public:
static HTTP_Config_Info *instance (void);
-
+ // Access the Singleton.
+
private:
static HTTP_Config_Info *instance_;
+ // Store the Singleton.
};
class HTTP_Config_Info
// = TITLE
// This is where the information is really stored.
{
- // Who are my friends?
- friend HTTP_Config;
-
+friend HTTP_Config;
public:
HTTP_Config_Info (void);
~HTTP_Config_Info (void);
// Accessors to the information
- const char * document_root (void) const;
+ const char *document_root (void) const;
// Where the root of the document tree begins. This prevents
// clients from being able to examine your entire filesystem.
- const char * cgi_path (void) const;
+ const char *cgi_path (void) const;
// A search path for CGI files.
- const char * user_dir (void) const;
- // The directory which is appended to a home user directory,
- // e.g., ".www-docs" or "public_html".
+ const char *user_dir (void) const;
+ // The directory which is appended to a home user directory, e.g.,
+ // ".www-docs" or "public_html".
- const char * dir_index (void) const;
- // What is the default index file for a directory,
- // e.g., "index.html".
+ const char *dir_index (void) const;
+ // What is the default index file for a directory, e.g.,
+ // "index.html".
int proxy_flag (void) const;
// Will the server support proxy requests?
private:
- // Accesors which can set the data
+ // = Accesors that can set the data
- char * document_root (char *dr_string);
- char * cgi_path (char *cp_string);
- char * user_dir (char *ud_string);
- char * dir_index (char *di_string);
+ char *document_root (char *dr_string);
+ char *cgi_path (char *cp_string);
+ char *user_dir (char *ud_string);
+ char *dir_index (char *di_string);
int proxy_flag (int pf);
private:
- // Data members
-
+ // = Data members
+ // James, please document these.
char *document_root_;
char *cgi_path_;
char *user_dir_;
char *dir_index_;
-
int proxy_flag_;
};
diff --git a/apps/JAWS/server/HTTP_Handler.cpp b/apps/JAWS/server/HTTP_Handler.cpp
index d92fe8fcd53..e0d1df6ca3e 100644
--- a/apps/JAWS/server/HTTP_Handler.cpp
+++ b/apps/JAWS/server/HTTP_Handler.cpp
@@ -32,30 +32,27 @@ HTTP_Handler::open (ACE_HANDLE handle,
{
ACE_DEBUG ((LM_DEBUG, "(%t) New connection \n"));
- int sockbufsize = 64*1024;
+ // James, please define a macro for this (e.g., ACE_MAX_SOCKBUF).
+ int sockbufsize = 64 * 1024;
int result = ACE_OS::setsockopt (handle,
SOL_SOCKET,
SO_RCVBUF,
(char *) &sockbufsize,
- sizeof (sockbufsize));
+ sizeof sockbufsize);
- if (result < 0)
- {
- perror ("SO_RCVBUF");
- }
+ if (result == -1)
+ ACE_ERROR ((LM_ERROR, "%p\n", "SO_RCVBUF"));
- int sendsockbufsize = 64*1024;
+ // James, please define a macro for this (e.g., ACE_MAX_SOCKBUF).
+ sockbufsize = 64 * 1024;
result = ACE_OS::setsockopt (handle,
SOL_SOCKET,
SO_SNDBUF,
- (char *) &sendsockbufsize,
- sizeof (sendsockbufsize));
- if (result < 0)
- {
- perror ("SO_SNDBUF");
- }
-
+ (char *) &sockbufsize,
+ sizeof sockbufsize);
+ if (result == -1)
+ ACE_ERROR ((LM_ERROR, "%p\n", "SO_SNDBUF"));
this->handle_ = handle;
this->io_.handle (this->handle_);
@@ -171,10 +168,12 @@ HTTP_Handler::transmit_file_complete (void)
void
HTTP_Handler::transmit_file_error (int result)
{
- ACE_DEBUG ((LM_DEBUG, " (%t) %s error in transmitting file\n",
+ ACE_DEBUG ((LM_DEBUG,
+ " (%t) %s error in transmitting file\n",
request_.uri ()));
int status_code;
+
switch (result)
{
case JAWS_File::ACCESS_FAILED:
@@ -191,6 +190,7 @@ HTTP_Handler::transmit_file_error (int result)
status_code = HTTP_Status_Code::STATUS_INTERNAL_SERVER_ERROR;
break;
}
+
this->response_.error_response (status_code, "error in transmitting file");
}
@@ -287,5 +287,4 @@ Asynch_HTTP_Handler_Factory::create_http_handler (void)
{
return 0;
}
-
#endif /* ACE_WIN32 */
diff --git a/apps/JAWS/server/HTTP_Handler.h b/apps/JAWS/server/HTTP_Handler.h
index 871da137085..786efbf1a17 100644
--- a/apps/JAWS/server/HTTP_Handler.h
+++ b/apps/JAWS/server/HTTP_Handler.h
@@ -2,10 +2,23 @@
// Hey, Emacs! This is a C++ file!
// $Id$
+// ============================================================================
+//
+// = LIBRARY
+// jaws
+//
+// = FILENAME
+// HTTP_Handler.h
+//
+// = AUTHOR
+// James Hu and Irfan Pyarali
+//
+// ============================================================================
+
#if !defined (HTTP_HANDLER_H)
#define HTTP_HANDLER_H
-// Forward declarations
+// = Forward declarations
class Message_Block;
class HTTP_Handler_Factory;
@@ -15,7 +28,6 @@ class HTTP_Handler_Factory;
#include "IO.h"
class HTTP_Handler : protected JAWS_IO_Handler
- //
// = TITLE
//
// This class is used to implement the HTTP protocol
@@ -69,7 +81,7 @@ protected:
// Reference to the creating factory.
protected:
- // Methods inherited from JAWS_IO_Handler
+ // = Completion methods inherited from <JAWS_IO_Handler>.
void read_complete (ACE_Message_Block &data);
void read_error (void);
@@ -101,18 +113,16 @@ private:
JAWS_IO &io_;
// IO class used by the handler
-
};
class HTTP_Handler_Factory
- //
// = TITLE
//
// This class is used to create new HTTP handlers
//
// = DESCRIPTION
//
- // This is an abstract factory for creating new HTTP handlers
+ // This is an abstract factory for creating new HTTP handlers.
{
public:
virtual ~HTTP_Handler_Factory (void);
@@ -129,14 +139,12 @@ public:
};
class Synch_HTTP_Handler_Factory : public HTTP_Handler_Factory
- //
// = TITLE
//
// This class is used to create new HTTP handlers that will use
// Synch IO
//
// = DESCRIPTION
- //
{
public:
HTTP_Handler *create_http_handler (void);
@@ -152,6 +160,7 @@ public:
// This only works on Win32
#if defined (ACE_WIN32)
class Asynch_HTTP_Handler_Factory : public HTTP_Handler_Factory, public ACE_Service_Handler
+// James, please document this class.
{
public:
void destroy_http_handler (HTTP_Handler &handler,
@@ -164,9 +173,9 @@ public:
ACE_Message_Block &message_block);
// <open> is called by ACE_Asynch_Acceptor to initialize a new
// instance of ACE_Service_Handler that has been created after the a
- // new connection is accepted.
+ // new connection is accepted.
//
- // This will act as a creation point for new handlers
+ // This will act as a creation point for new handlers.
private:
HTTP_Handler *create_http_handler (void);
@@ -175,5 +184,4 @@ private:
// new client connections arrive.
};
#endif /* ACE_WIN32 */
-
#endif /* HTTP_HANDLER_H */
diff --git a/apps/JAWS/server/HTTP_Helpers.cpp b/apps/JAWS/server/HTTP_Helpers.cpp
index 081e38bc0c8..d23a13348e3 100644
--- a/apps/JAWS/server/HTTP_Helpers.cpp
+++ b/apps/JAWS/server/HTTP_Helpers.cpp
@@ -5,12 +5,14 @@
#include "HTTP_Helpers.h"
// = Static initialization.
-const char * const
-HTTP_Helper::months_[12]= { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
-char const *
-HTTP_Helper::alphabet_
-= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+const char *const
+HTTP_Helper::months_[12]=
+{
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+char const *HTTP_Helper::alphabet_ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
#if !defined (ACE_HAS_REENTRANT_LIBC)
#if defined (ACE_HAS_THREADS)
@@ -25,18 +27,24 @@ const char *HTTP_Status_Code::Reason[HTTP_Status_Code::MAX_STATUS_CODE + 1];
time_t
HTTP_Helper::HTTP_mktime (const char *httpdate)
{
- char *buf = new char[strlen(httpdate)+1];
+ char *buf;
+
+ ACE_NEW_RETURN (buf, char[ACE_OS::strlen (httpdate) + 1], (time_t) -1);
// Make spaces in the date be semi-colons so we can parse robustly
// with sscanf.
- {
- const char *ptr1 = httpdate;
- char *ptr2 = buf;
- do {
- if (*ptr1 == ' ') *ptr2++ = ';';
- else *ptr2++ = *ptr1;
- } while (*ptr1++ != '\0');
- }
+
+ const char *ptr1 = httpdate;
+ char *ptr2 = buf;
+
+ do
+ {
+ if (*ptr1 == ' ')
+ *ptr2++ = ';';
+ else
+ *ptr2++ = *ptr1;
+ }
+ while (*ptr1++ != '\0');
// In HTTP/1.0, there are three versions of an HTTP_date.
@@ -48,8 +56,8 @@ HTTP_Helper::HTTP_mktime (const char *httpdate)
const char *rfc850_date = "%s,;%2d-%3s-%2d;%2d:%2d:%2d;GMT";
const char *asctime_date = "%3s;%3s;%2d;%2d:%2d:%2d;%4d";
- // should also support other versions (such as from NNTP and SMTP) for
- // robustness, but it should be clear how to extend this.
+ // Should also support other versions (such as from NNTP and SMTP)
+ // for robustness, but it should be clear how to extend this.
struct tm tms;
char month[4];
@@ -57,33 +65,36 @@ HTTP_Helper::HTTP_mktime (const char *httpdate)
if (::sscanf(buf, rfc1123_date,
weekday,
- &tms.tm_mday, month, &tms.tm_year,
- &tms.tm_hour, &tms.tm_min, &tms.tm_sec)
- == 7) {
- }
+ &tms.tm_mday,
+ month,
+ &tms.tm_year,
+ &tms.tm_hour,
+ &tms.tm_min,
+ &tms.tm_sec) == 7)
+ ;
else if (::sscanf(buf, rfc850_date,
weekday,
&tms.tm_mday, month, &tms.tm_year,
- &tms.tm_hour, &tms.tm_min, &tms.tm_sec)
- == 7) {
- weekday[3] = '\0';
- ;
- }
+ &tms.tm_hour, &tms.tm_min, &tms.tm_sec) == 7)
+ {
+ weekday[3] = '\0';
+ }
else if (::sscanf(buf, asctime_date,
weekday,
month, &tms.tm_mday,
&tms.tm_hour, &tms.tm_min, &tms.tm_sec,
- &tms.tm_year)
- == 7) {
+ &tms.tm_year) == 7)
;
- }
+
delete buf;
tms.tm_year = HTTP_Helper::fixyear (tms.tm_year);
tms.tm_mon = HTTP_Helper::HTTP_month (month);
- if (tms.tm_mon == -1) return (time_t)(-1);
- /* mktime is a Standard C function */
+ if (tms.tm_mon == -1)
+ return (time_t) -1;
+
+ // mktime is a Standard C function.
{
#if !defined (ACE_HAS_REENTRANT_LIBC)
@@ -92,7 +103,7 @@ HTTP_Helper::HTTP_mktime (const char *httpdate)
#endif /* ACE_HAS_THREADS */
#endif /* NOT ACE_HAS_REENTRANT_LIBC */
- return ACE_OS::mktime(&tms);
+ return ACE_OS::mktime (&tms);
}
}
@@ -104,11 +115,12 @@ HTTP_Helper::HTTP_date (char * const date_string, int date_length)
if (date_string != 0)
{
- if (ACE_OS::time (&tloc) != (time_t)-1
+ if (ACE_OS::time (&tloc) != (time_t) -1
&& ACE_OS::gmtime_r (&tloc, &tms) != NULL)
ACE_OS::strftime (date_string, date_length,
"%a, %d %b %Y %T GMT", &tms);
- else return 0;
+ else
+ return 0;
}
return date_string;
@@ -117,7 +129,7 @@ HTTP_Helper::HTTP_date (char * const date_string, int date_length)
int
HTTP_Helper::HTTP_month (const char *month)
{
- for (int i = 0; i < 12; i++)
+ for (size_t i = 0; i < 12; i++)
if (ACE_OS::strcmp(month, HTTP_Helper::months_[i]) == 0)
return i;
@@ -127,28 +139,34 @@ HTTP_Helper::HTTP_month (const char *month)
const char *
HTTP_Helper::HTTP_month (int month)
{
- if (month < 0 || month >= 12) return 0;
+ if (month < 0 || month >= 12)
+ return 0;
return HTTP_Helper::months_[month];
}
+// Fix the path if it needs fixing/is fixable.
+
char *
HTTP_Helper::HTTP_decode_string (char *path)
- // fix the path if it needs fixing/is fixable
{
// replace the percentcodes with the actual character
- int i,j;
+ int i, j;
char percentcode[3];
- for (i = j = 0; path[i] != '\0'; i++,j++) {
- if (path[i] == '%') {
- percentcode[0] = path[++i];
- percentcode[1] = path[++i];
- percentcode[2] = '\0';
- path[j] = (char) ACE_OS::strtol (percentcode, (char **)0, 16);
+ for (i = j = 0; path[i] != '\0'; i++, j++)
+ {
+ if (path[i] == '%')
+ {
+ percentcode[0] = path[++i];
+ percentcode[1] = path[++i];
+ percentcode[2] = '\0';
+ path[j] = (char) ACE_OS::strtol (percentcode, (char **) 0, 16);
+ }
+ else
+ path[j] = path[i];
}
- else path[j] = path[i];
- }
+
path[j] = path[i];
return path;
@@ -157,23 +175,27 @@ HTTP_Helper::HTTP_decode_string (char *path)
char *
HTTP_Helper::HTTP_decode_base64 (char *data)
{
- char * indata, * outdata;
char inalphabet[256], decoder[256];
- int i, bits, c, char_count, errors = 0;
ACE_OS::memset (inalphabet, 0, sizeof (inalphabet));
ACE_OS::memset (decoder, 0, sizeof (decoder));
- for (i = ACE_OS::strlen (HTTP_Helper::alphabet_) - 1; i >= 0 ; i--)
+ for (int i = ACE_OS::strlen (HTTP_Helper::alphabet_) - 1;
+ i >= 0;
+ i--)
{
inalphabet[(unsigned int) HTTP_Helper::alphabet_[i]] = 1;
decoder[(unsigned int) HTTP_Helper::alphabet_[i]] = i;
}
- indata = data;
- outdata = data;
- char_count = 0;
- bits = 0;
+ char *indata = data;
+ char *outdata = data;
+
+ int bits = 0;
+ int c;
+ int char_count = 0;
+ int errors = 0;
+
while ((c = *indata++) != '\0')
{
if (c == '=')
@@ -191,9 +213,7 @@ HTTP_Helper::HTTP_decode_base64 (char *data)
char_count = 0;
}
else
- {
- bits <<= 6;
- }
+ bits <<= 6;
}
if (c == '\0')
@@ -208,7 +228,7 @@ HTTP_Helper::HTTP_decode_base64 (char *data)
}
else
{
- /* c == '=' */
+ // c == '='
switch (char_count)
{
case 1:
@@ -226,23 +246,25 @@ HTTP_Helper::HTTP_decode_base64 (char *data)
}
}
*outdata = '\0';
- return (errors ? 0 : data);
+ return errors ? 0 : data;
}
char *
HTTP_Helper::HTTP_encode_base64 (char *data)
{
char buf[BUFSIZ];
- char *indata, *outdata;
- int bits, c, char_count, error;
-
- char_count = 0;
- bits = 0;
+ int c;
+ int error;
+ int char_count = 0;
+ int bits = 0;
error = 0;
- indata = data;
- outdata = buf;
+ char *indata = data;
+ char *outdata = buf;
+
while ((c = *indata++) != '\0')
{
+ // James, can you please define a macro for this, e.g.,
+ // ACE_ASCII_MAX or something.
if (c > 255)
{
ACE_DEBUG ((LM_DEBUG, "encountered char > 255 (decimal %d)\n", c));
@@ -251,6 +273,7 @@ HTTP_Helper::HTTP_encode_base64 (char *data)
}
bits += c;
char_count++;
+
if (char_count == 3)
{
*outdata++ = HTTP_Helper::alphabet_[bits >> 18];
@@ -261,9 +284,7 @@ HTTP_Helper::HTTP_encode_base64 (char *data)
char_count = 0;
}
else
- {
bits <<= 8;
- }
}
if (!error)
@@ -273,6 +294,7 @@ HTTP_Helper::HTTP_encode_base64 (char *data)
bits <<= 16 - (8 * char_count);
*outdata++ = HTTP_Helper::alphabet_[bits >> 18];
*outdata++ = HTTP_Helper::alphabet_[(bits >> 12) & 0x3f];
+
if (char_count == 1)
{
*outdata++ = '=';
@@ -296,21 +318,29 @@ HTTP_Helper::fixyear (int year)
{
// Fix the year 2000 problem
- if (year > 1000) year -= 1900;
- else if (year < 100) {
- struct tm tms;
- time_t tloc;
+ if (year > 1000)
+ year -= 1900;
+ else if (year < 100)
+ {
+ struct tm tms;
+ time_t tloc;
+
+ if (ACE_OS::time (&tloc) != (time_t) -1)
+ {
+ ACE_OS::gmtime_r (&tloc, &tms);
+
+ if (tms.tm_year % 100 == year)
+ year = tms.tm_year;
- if (ACE_OS::time(&tloc) != (time_t)-1) {
- ACE_OS::gmtime_r(&tloc, &tms);
+ if ((year+1) % 100 == tms.tm_year % 100)
+ year = tms.tm_year - 1;
- if (tms.tm_year%100 == year) year = tms.tm_year;
- if ((year+1)%100 == tms.tm_year%100) year = tms.tm_year-1;
- if (year == (tms.tm_year+1)%100) year = tms.tm_year+1;
+ if (year == (tms.tm_year + 1) % 100)
+ year = tms.tm_year + 1;
- // What to do if none of the above?
+ // What to do if none of the above?
+ }
}
- }
return year;
}
@@ -324,7 +354,9 @@ HTTP_Status_Code::instance (void)
if (HTTP_Status_Code::instance_ == 0)
{
- for (size_t i = 0; i < HTTP_Status_Code::MAX_STATUS_CODE + 1; i++)
+ for (size_t i = 0;
+ i < HTTP_Status_Code::MAX_STATUS_CODE + 1;
+ i++)
{
switch (i)
{
diff --git a/apps/JAWS/server/HTTP_Helpers.h b/apps/JAWS/server/HTTP_Helpers.h
index 2de4dc7c130..c5c30f226a3 100644
--- a/apps/JAWS/server/HTTP_Helpers.h
+++ b/apps/JAWS/server/HTTP_Helpers.h
@@ -2,7 +2,18 @@
// Hey, Emacs! This is a C++ file!
// $Id$
-// HTTP_Helpers.h
+// ============================================================================
+//
+// = LIBRARY
+// apps
+//
+// = FILENAME
+// HTTP_Helpers.h
+//
+// = AUTHOR
+// James, please add the appropriate attribution here.
+//
+// ============================================================================
#if !defined (HTTP_HELPERS_H)
#define HTTP_HELPERS_H
@@ -18,23 +29,23 @@ public:
static time_t HTTP_mktime (const char *httpdate);
// Create today's date
- static const char * HTTP_date (char * const date_string, int date_length);
+ static const char *HTTP_date (char *const date_string, int date_length);
static int HTTP_month (const char *month);
- static const char * HTTP_month (int month);
+ static const char *HTTP_month (int month);
- static char * HTTP_decode_string (char *path);
+ static char *HTTP_decode_string (char *path);
- static char * HTTP_decode_base64 (char *data);
- static char * HTTP_encode_base64 (char *data);
+ static char *HTTP_decode_base64 (char *data);
+ static char *HTTP_encode_base64 (char *data);
private:
static int fixyear (int year);
private:
- static const char * const months_[12];
- static char const * alphabet_;
+ static const char *const months_[12];
+ static char const *alphabet_;
#if !defined (ACE_HAS_REENTRANT_LIBC)
#if defined (ACE_HAS_THREADS)
@@ -56,10 +67,11 @@ class HTTP_Status_Code
// Design around the Singleton pattern
{
public:
- static const char ** instance(void);
+ static const char **instance(void);
// Singleton access point.
- enum STATUS_CODE {
+ enum STATUS_CODE
+ {
STATUS_OK = 200,
STATUS_CREATED = 201,
STATUS_ACCEPTED = 202,
@@ -78,10 +90,14 @@ public:
STATUS_INSUFFICIENT_DATA = 399
};
- enum {MAX_STATUS_CODE=599};
+ enum
+ {
+ MAX_STATUS_CODE = 599
+ };
private:
- static const char * Reason[MAX_STATUS_CODE + 1];
+ // James, please add comments.
+ static const char *Reason[MAX_STATUS_CODE + 1];
static int instance_;
static ACE_SYNCH_MUTEX lock_;
};
diff --git a/apps/JAWS/server/HTTP_Request.cpp b/apps/JAWS/server/HTTP_Request.cpp
index d82041f2580..5ad6bca41db 100644
--- a/apps/JAWS/server/HTTP_Request.cpp
+++ b/apps/JAWS/server/HTTP_Request.cpp
@@ -1,24 +1,39 @@
// $Id$
#include "ace/Message_Block.h"
-
#include "HTTP_Request.h"
#include "HTTP_Helpers.h"
#include "HTTP_Config.h"
-const char * const
-HTTP_Request::static_header_strings_[HTTP_Request::NUM_HEADER_STRINGS]
-= { "Date", "Pragma",
- "Authorization", "From", "If-Modified-Since", "Referrer", "User-Agent",
- "Allow", "Content-Encoding", "Content-Length", "Content-Type",
- "Expires", "Last-Modified" };
-
-const char * const
-HTTP_Request::static_method_strings_[HTTP_Request::NUM_METHOD_STRINGS]
-= { "GET", "HEAD", "POST", "PUT" };
-
-// for reasons of efficiency, this class expects buffer to be
-// null-terminated, and buflen does NOT include the \0
+const char *const
+HTTP_Request::static_header_strings_[HTTP_Request::NUM_HEADER_STRINGS] =
+{
+ "Date",
+ "Pragma",
+ "Authorization",
+ "From",
+ "If-Modified-Since",
+ "Referrer",
+ "User-Agent",
+ "Allow",
+ "Content-Encoding",
+ "Content-Length",
+ "Content-Type",
+ "Expires",
+ "Last-Modified"
+};
+
+const char *const
+HTTP_Request::static_method_strings_[HTTP_Request::NUM_METHOD_STRINGS] =
+{
+ "GET",
+ "HEAD",
+ "POST",
+ "PUT"
+};
+
+// For reasons of efficiency, this class expects buffer to be
+// null-terminated, and buflen does NOT include the \0.
HTTP_Request::HTTP_Request (void)
: got_request_line_ (0),
@@ -34,7 +49,10 @@ HTTP_Request::HTTP_Request (void)
header_strings_ (HTTP_Request::static_header_strings_),
method_strings_ (HTTP_Request::static_method_strings_)
{
- for (int i = 0; i < HTTP_Request::NUM_HEADER_STRINGS; i++)
+
+ for (size_t i = 0;
+ i < HTTP_Request::NUM_HEADER_STRINGS;
+ i++)
this->headers_.recognize (this->header_strings_[i]);
}
@@ -58,9 +76,11 @@ HTTP_Request::parse_request (ACE_Message_Block &mb)
// Note that RFC 822 does not mention the maximum length of a header
// line. So in theory, there is no maximum length.
- // In Apache, they assume that each header line should not exceed 8K.
+ // In Apache, they assume that each header line should not exceed
+ // 8K.
int result = this->headers_.complete_header_line (mb.rd_ptr ());
+
if (result != 0)
{
if (!this->got_request_line ())
@@ -71,22 +91,21 @@ HTTP_Request::parse_request (ACE_Message_Block &mb)
}
else if (result > 0)
do
- {
- this->headers_.parse_header_line (mb.rd_ptr ());
- }
+ this->headers_.parse_header_line (mb.rd_ptr ());
while (this->headers_.complete_header_line (mb.rd_ptr ()) > 0);
}
mb.wr_ptr (strlen(mb.rd_ptr ()) - mb.length ());
- return ((this->headers_.end_of_headers ()
- || (this->got_request_line () && this->version () == 0))
- ? this->init (mb.rd_ptr (), mb.length ())
- : 0);
+ if (this->headers_.end_of_headers ()
+ || (this->got_request_line () && this->version () == 0))
+ return this->init (mb.rd_ptr (), mb.length ());
+ else
+ return 0;
}
void
-HTTP_Request::parse_request_line (char * const request_line)
+HTTP_Request::parse_request_line (char *const request_line)
{
char *ptr = request_line;
char *buf = request_line;
@@ -95,13 +114,16 @@ HTTP_Request::parse_request_line (char * const request_line)
this->status_ = HTTP_Status_Code::STATUS_OK;
ptr = ACE_OS::strchr (request_line, '\n');
+
if (ptr > request_line && ptr[-1] == '\r')
ptr--, offset++;
+
if (ptr == request_line)
{
this->status_ = HTTP_Status_Code::STATUS_BAD_REQUEST;
return;
}
+
*ptr = '\0';
ptr += offset;
@@ -115,16 +137,12 @@ HTTP_Request::parse_request_line (char * const request_line)
{
this->type (this->method ());
- if (this->version (ACE_OS::strtok_r (NULL, " \t", &lasts)) == 0)
- {
- if (this->type () != HTTP_Request::GET)
- this->status_ = HTTP_Status_Code::STATUS_NOT_IMPLEMENTED;
- }
+ if (this->version (ACE_OS::strtok_r (NULL, " \t", &lasts)) == 0
+ && this->type () != HTTP_Request::GET)
+ this->status_ = HTTP_Status_Code::STATUS_NOT_IMPLEMENTED;
if (this->path (this->uri ()) == 0)
- {
- this->status_ = HTTP_Status_Code::STATUS_NOT_FOUND;
- }
+ this->status_ = HTTP_Status_Code::STATUS_NOT_FOUND;
}
ACE_DEBUG ((LM_DEBUG, " (%t) request %s %s %s parsed\n",
@@ -136,7 +154,8 @@ HTTP_Request::parse_request_line (char * const request_line)
}
int
-HTTP_Request::init (char * const buffer, int buflen)
+HTTP_Request::init (char *const buffer,
+ int buflen)
{
// Initialize these every time.
content_length_ = -1;
@@ -231,10 +250,9 @@ const char *
HTTP_Request::header_strings (int index) const
{
const char *hs = 0;
+
if (0 <= index && index < NUM_HEADER_STRINGS)
- {
- hs = this->header_strings_[index];
- }
+ hs = this->header_strings_[index];
return hs;
}
@@ -274,6 +292,7 @@ HTTP_Request::content_length (void)
const char * clv = this->headers_["Content-length"];
this->content_length_ = (clv ? ACE_OS::atoi (clv) : 0);
}
+
return this->content_length_;
}
@@ -310,14 +329,16 @@ HTTP_Request::dump (void)
const char *
HTTP_Request::method (const char *method_string)
{
- if (this->method_) ACE_OS::free (this->method_);
+ if (this->method_)
+ ACE_OS::free (this->method_);
if (method_string == 0)
{
this->status_ = HTTP_Status_Code::STATUS_BAD_REQUEST;
this->method_ = 0;
}
- else this->method_ = ACE_OS::strdup (method_string);
+ else
+ this->method_ = ACE_OS::strdup (method_string);
return this->method_;
}
@@ -325,7 +346,8 @@ HTTP_Request::method (const char *method_string)
const char *
HTTP_Request::uri (char *uri_string)
{
- if (this->uri_) ACE_OS::free (this->uri_);
+ if (this->uri_)
+ ACE_OS::free (this->uri_);
if (uri_string == 0)
{
@@ -345,11 +367,13 @@ HTTP_Request::uri (char *uri_string)
const char *
HTTP_Request::version (const char *version_string)
{
- if (this->version_) ACE_OS::free (this->version_);
+ if (this->version_)
+ ACE_OS::free (this->version_);
- this->version_ = (version_string
- ? ACE_OS::strdup(version_string)
- : 0);
+ if (version_string)
+ this->version_ = ACE_OS::strdup (version_string);
+ else
+ this->version_ = 0;
return this->version_;
}
@@ -358,10 +382,15 @@ int
HTTP_Request::type (const char *type_string)
{
this->type_ = HTTP_Request::NO_TYPE;
- if (type_string == 0) return this->type_;
- for (int i = 0; i < HTTP_Request::NUM_METHOD_STRINGS; i++)
- if (ACE_OS::strcmp(type_string, this->method_strings_[i]) == 0)
+ if (type_string == 0)
+ return this->type_;
+
+ for (size_t i = 0;
+ i < HTTP_Request::NUM_METHOD_STRINGS;
+ i++)
+
+ if (ACE_OS::strcmp (type_string, this->method_strings_[i]) == 0)
{
this->type_ = i;
break;
@@ -373,6 +402,9 @@ HTTP_Request::type (const char *type_string)
return this->type_;
}
+// James, this function is *way* too long. Can you please break it
+// into multiple methods?
+
int
HTTP_Request::cgi (char *uri_string)
{
@@ -380,23 +412,33 @@ HTTP_Request::cgi (char *uri_string)
this->cgi_env_ = 0;
this->cgi_args_ = 0;
- if (uri_string == 0 || ACE_OS::strlen (uri_string) == 0) return 0;
+ if (uri_string == 0 || ACE_OS::strlen (uri_string) == 0)
+ return 0;
// There are 2 cases where a file could be a CGI script
//
// (1) the file has a CGI extension.
// (2) the file resides in a CGI bin directory.
- char *cgi_path = (HTTP_Config::instance ()->cgi_path ()
- ? ACE_OS::strdup (HTTP_Config::instance ()->cgi_path ())
- : ACE_OS::strdup (""));
- char *cgi_path_next, *lasts;
+ char *cgi_path;
+
+ if (HTTP_Config::instance ()->cgi_path ())
+ cgi_path = ACE_OS::strdup (HTTP_Config::instance ()->cgi_path ());
+ else
+ cgi_path = ACE_OS::strdup ("");
+
+ char *lasts;
+ char *cgi_path_next = ACE_OS::strtok_r (cgi_path, ":", &lasts);
char *extra_path_info = 0;
- if ((cgi_path_next = ACE_OS::strtok_r (cgi_path, ":", &lasts)))
+ if (cgi_path_next)
do
{
int len = ACE_OS::strlen (cgi_path_next);
+
+ // James, the following code is impossible to understand.
+ // Please simplify it to not use the ?: expression (i.e.,
+ // break it into several statements).
if ((*cgi_path_next == '/')
? ! ACE_OS::strncmp (extra_path_info = uri_string,
cgi_path_next, len)
@@ -410,9 +452,7 @@ HTTP_Request::cgi (char *uri_string)
// move past the executable name
do
- {
- extra_path_info++;
- }
+ extra_path_info++;
while (*extra_path_info != '/'
&& *extra_path_info != '?'
&& *extra_path_info != '\0');
@@ -424,18 +464,23 @@ HTTP_Request::cgi (char *uri_string)
}
}
extra_path_info = 0;
+
+ cgi_path_next = ACE_OS::strtok_r (NULL, ":", &lasts);
}
- while ((cgi_path_next = ACE_OS::strtok_r (NULL, ":", &lasts)));
+ while (cgi_path_next);
ACE_OS::free (cgi_path);
if (this->cgi_ == 0)
{
- // Nothing found searching through paths, what about CGI extension?
+ // Nothing found searching through paths, what about CGI
+ // extension?
extra_path_info = ACE_OS::strstr (uri_string, ".cgi");
+
while (extra_path_info != 0)
{
extra_path_info += 4;
+
switch (*extra_path_info)
{
case '\0':
@@ -454,45 +499,51 @@ HTTP_Request::cgi (char *uri_string)
}
char *cgi_question = 0;
+
if (extra_path_info)
cgi_question = ACE_OS::strchr (extra_path_info, '?');
+
if (extra_path_info == cgi_question)
extra_path_info = 0;
if (cgi_question)
{
*cgi_question++ = '\0';
+
if (*cgi_question != '\0')
{
- // We need the ``original'' QUERY_STRING for the environment.
- // We will substitute '+'s for spaces in the other copy.
+ // We need the ``original'' QUERY_STRING for the
+ // environment. We will substitute '+'s for spaces in the
+ // other copy.
this->query_string_ = ACE_OS::strdup (cgi_question);
char *ptr = cgi_question;
int count = 0;
do
- {
- if (*ptr == '+') *ptr = ' ';
- else if (*ptr == '&' || *ptr == '=') count++;
+ if (*ptr == '+')
+ *ptr = ' ';
+ else if (*ptr == '&' || *ptr == '=')
+ count++;
}
while (*++ptr);
+
count++;
if (ACE_OS::strchr (cgi_question, '='))
{
- this->cgi_env_ = new char *[count+1];
+ ACE_NEW_RETURN (this->cgi_env_, char *[count+1], -1);
int i = 0;
ptr = cgi_question;
do
{
this->cgi_env_ [i++] = ptr;
+
while (*ptr++)
- {
if (*ptr == '&' || *ptr == '=')
*ptr = '\0';
- }
+
HTTP_Helper::HTTP_decode_string (this->cgi_env_[i-1]);
}
while (i < count);
@@ -521,7 +572,6 @@ const char *
HTTP_Request::path (const char *uri_string)
{
char const *file_name = uri_string;
-
char buf[MAXPATHLEN+1];
buf[0] = '\0';
diff --git a/apps/JAWS/server/HTTP_Request.h b/apps/JAWS/server/HTTP_Request.h
index c9cffac980b..be4c46a278c 100644
--- a/apps/JAWS/server/HTTP_Request.h
+++ b/apps/JAWS/server/HTTP_Request.h
@@ -2,6 +2,19 @@
// Hey, Emacs! This is a C++ file!
// $Id$
+// ============================================================================
+//
+// = LIBRARY
+// jaws
+//
+// = FILENAME
+// HTTP_Request.h
+//
+// = AUTHOR
+// James Hu
+//
+// ============================================================================
+
#if !defined (HTTP_REQUEST_H)
#define HTTP_REQUEST_H
@@ -11,6 +24,7 @@ class ACE_Message_Block;
#include "Parse_Headers.h"
class HTTP_Request
+// James, please document this class.
{
public:
HTTP_Request (void);
@@ -22,37 +36,38 @@ public:
int parse_request (ACE_Message_Block &mb);
// parse an incoming request
- void parse_request_line (char * const request_line);
- // the first line of a request is the request line, which
- // is of the form: METHOD URI VERSION
+ void parse_request_line (char *const request_line);
+ // the first line of a request is the request line, which is of the
+ // form: METHOD URI VERSION.
- int init (char * const buffer, int buflen);
- // Initialize the request object. This will parse
- // the buffer and prepare for the accessors.
+ int init (char *const buffer,
+ int buflen);
+ // Initialize the request object. This will parse the buffer and
+ // prepare for the accessors.
public:
- // The Accessors
+ // = The Accessors.
+
+ // James, please document.
- const char * method (void) const;
- const char * uri (void) const;
- const char * version (void) const;
- const char * path (void) const;
+ const char *method (void) const;
+ const char *uri (void) const;
+ const char *version (void) const;
+ const char *path (void) const;
int cgi (void) const;
- const char * cgi_args (void) const;
- const char ** cgi_env (void) const;
+ const char *cgi_args (void) const;
+ const char **cgi_env (void) const;
- const char * query_string (void) const;
- const char * path_info (void) const;
+ const char *query_string (void) const;
+ const char *path_info (void) const;
int type (void) const;
- const Headers & headers (void) const;
- const char * header_strings (int index) const;
- const char * header_values (int index) const;
+ const Headers &headers (void) const;
+ const char *header_strings (int index) const;
+ const char *header_values (int index) const;
- // These are accessors I didn't implement, or don't
- // remember implementing, anyway.
char *data (void);
int data_length (void);
int content_length (void);
@@ -92,11 +107,11 @@ public:
};
private:
- // Private Accessors which can set values
- const char * method (const char *method_string);
- const char * uri (char *uri_string);
- const char * version (const char *version_string);
- const char * path (const char *uri_string);
+ // = Private Accessors which can set values
+ const char *method (const char *method_string);
+ const char *uri (char *uri_string);
+ const char *version (const char *version_string);
+ const char *path (const char *uri_string);
int cgi (char *uri_string);
@@ -121,11 +136,11 @@ private:
char *query_string_;
char *path_info_;
- const char * const * const header_strings_;
- static const char * const static_header_strings_[NUM_HEADER_STRINGS];
+ const char * const *const header_strings_;
+ static const char *const static_header_strings_[NUM_HEADER_STRINGS];
- const char * const * const method_strings_;
- static const char * const static_method_strings_[NUM_METHOD_STRINGS];
+ const char * const *const method_strings_;
+ static const char *const static_method_strings_[NUM_METHOD_STRINGS];
char *data_;
int datalen_;
diff --git a/apps/JAWS/server/HTTP_Response.cpp b/apps/JAWS/server/HTTP_Response.cpp
index 42ae0fef4bf..03067cb1517 100644
--- a/apps/JAWS/server/HTTP_Response.cpp
+++ b/apps/JAWS/server/HTTP_Response.cpp
@@ -1,19 +1,5 @@
// $Id$
-// ============================================================================
-//
-// = LIBRARY
-// apps
-//
-// = FILENAME
-// HTTP_Response
-//
-// = AUTHOR
-// James Hu
-//
-// ============================================================================
-
-
#include "ace/Process.h"
#include "ace/Mem_Map.h"
@@ -127,9 +113,7 @@ HTTP_Response::error_response (int status_code, const char *log_message)
if (this->request_.version () == 0
|| ACE_OS::strcmp ("HTTP/0.9", this->request_.version ()) == 0)
- {
- buf = buf2;
- }
+ buf = buf2;
else
{
length +=
@@ -165,7 +149,6 @@ HTTP_Response::normal_response (void)
this->HTTP_HEADER_LENGTH,
this->HTTP_TRAILER,
this->HTTP_TRAILER_LENGTH);
-
break;
case HTTP_Request::HEAD :
@@ -201,11 +184,14 @@ HTTP_Response::normal_response (void)
else
{
ACE_Mem_Map mmapfile;
- const char * hvv = hv + 6;
- char * buf = new char [ACE_OS::strlen (hv)];
- char * auth
+ // James, please document where the value 6 comes from (up above too).
+ const char *hvv = hv + 6;
+ char *buf = new char [ACE_OS::strlen (hv)];
+ char *auth
= HTTP_Helper::HTTP_decode_base64 (ACE_OS::strcpy (buf, hvv));
- if (mmapfile.map ("jaws.auth") != -1 && auth != 0
+
+ if (mmapfile.map ("jaws.auth") != -1
+ && auth != 0
&& ACE_OS::strstr((const char *) mmapfile.addr (), auth) != 0)
this->io_.receive_file (this->request_.path (),
this->request_.data (),
@@ -231,15 +217,11 @@ HTTP_Response::cgi_response (void)
ACE_Process_Options cgi_options;
if (this->request_.cgi_args ())
- {
- cgi_options.command_line ("%s %s",
- this->request_.path (),
- this->request_.cgi_args ());
- }
+ cgi_options.command_line ("%s %s",
+ this->request_.path (),
+ this->request_.cgi_args ());
else
- {
- cgi_options.command_line ("%s", this->request_.path ());
- }
+ cgi_options.command_line ("%s", this->request_.path ());
// Build environment variables
cgi_options.setenv ("SERVER_SOFTWARE", "%s", "JAWS/1.0");
@@ -256,49 +238,50 @@ HTTP_Response::cgi_response (void)
if (this->request_.path_info ())
{
- cgi_options.setenv ("PATH_INFO", "%s", this->request_.path_info ());
- cgi_options.setenv ("PATH_TRANSLATED", "%s/%s",
+ cgi_options.setenv ("PATH_INFO", "%s",
+ this->request_.path_info ());
+ cgi_options.setenv ("PATH_TRANSLATED",
+ "%s/%s",
HTTP_Config::instance ()->document_root (),
this->request_.path_info ());
}
- cgi_options.setenv ("SCRIPT_NAME", "%s", this->request_.uri ());
+ cgi_options.setenv ("SCRIPT_NAME",
+ "%s",
+ this->request_.uri ());
if (this->request_.query_string ())
- cgi_options.setenv ("QUERY_STRING", "%s", this->request_.query_string ());
+ cgi_options.setenv ("QUERY_STRING",
+ "%s",
+ this->request_.query_string ());
if (this->request_.cgi_env ())
- {
- int i = 0;
- while (this->request_.cgi_env ()[i])
- {
- cgi_options.setenv (this->request_.cgi_env ()[i],
- "%s", this->request_.cgi_env ()[i+1]);
- i += 2;
- }
- }
+ for (size_t i = 0; this->request_.cgi_env ()[i]; i += 2)
+ cgi_options.setenv (this->request_.cgi_env ()[i],
+ "%s",
+ this->request_.cgi_env ()[i+1]);
char buf[BUFSIZ];
char *p, *q;
ACE_OS::strcpy (buf, "HTTP_");
p = q = buf + ACE_OS::strlen (buf);
- for (int i = 0; i < HTTP_Request::NUM_HEADER_STRINGS; i++)
+ for (size_t i = 0; i < HTTP_Request::NUM_HEADER_STRINGS; i++)
{
int j = 0;
- char c;
- while ((c = this->request_.header_strings (i)[j++]) != '\0')
- {
- if (isalpha (c))
- *q++ = toupper (c);
- else if (c == '-')
- *q++ = '_';
- else
- *q++ = c;
- }
+
+ for (char c; (c = this->request_.header_strings (i)[j++]) != '\0'; )
+ if (isalpha (c))
+ *q++ = toupper (c);
+ else if (c == '-')
+ *q++ = '_';
+ else
+ *q++ = c;
+
*q = '\0';
const char *hv = this->request_.header_values (i);
+
if (hv && *hv)
cgi_options.setenv (buf, "%s", hv);
q = p;
@@ -314,7 +297,7 @@ HTTP_Response::cgi_response (void)
// ACE::send (this->io_.handle (),
// this->HTTP_HEADER, this->HTTP_HEADER_LENGTH);
- // Exec the cgi program
+ // Exec the CGI program.
ACE_Process cgi_process;
cgi_process.spawn (cgi_options);
// cgi_process.wait ();
@@ -326,8 +309,8 @@ HTTP_Response::build_headers (void)
// At this point, we should really determine the type of request
// this is, and build the appropriate header.
- // Let's assume this is HTML for now.
- // Unless the request is CGI, then do not include content-* headers.
+ // Let's assume this is HTML for now. Unless the request is CGI,
+ // then do not include content-* headers.
if (this->request_.version () == 0
|| ACE_OS::strcmp ("HTTP/0.9", this->request_.version ()) == 0)
@@ -348,23 +331,20 @@ HTTP_Response::build_headers (void)
this->request_.status (),
this->request_.status_string ());
+ // James, please document where the 40 comes from.
char date[40];
const char *date_ptr = HTTP_Helper::HTTP_date (date, sizeof(date)-1);
if (date_ptr != 0)
- {
- HTTP_HEADER_LENGTH +=
- ACE_OS::sprintf(HTTP_HEADER+HTTP_HEADER_LENGTH,
+ HTTP_HEADER_LENGTH +=
+ ACE_OS::sprintf(HTTP_HEADER+HTTP_HEADER_LENGTH,
"Date: %s\r\n", date_ptr);
- }
if (! this->request_.cgi ())
- {
- HTTP_HEADER_LENGTH +=
- ACE_OS::sprintf(HTTP_HEADER+HTTP_HEADER_LENGTH,
- "Content-type: %s\r\n\r\n",
- "text/html");
- }
+ HTTP_HEADER_LENGTH +=
+ ACE_OS::sprintf(HTTP_HEADER+HTTP_HEADER_LENGTH,
+ "Content-type: %s\r\n\r\n",
+ "text/html");
}
HTTP_TRAILER = "";
diff --git a/apps/JAWS/server/HTTP_Response.h b/apps/JAWS/server/HTTP_Response.h
index 359cce0fe8b..65dfd0c85f5 100644
--- a/apps/JAWS/server/HTTP_Response.h
+++ b/apps/JAWS/server/HTTP_Response.h
@@ -5,10 +5,10 @@
// ============================================================================
//
// = LIBRARY
-// apps
+// jaws
//
// = FILENAME
-// HTTP_Response
+// HTTP_Response.h
//
// = AUTHOR
// James Hu
@@ -32,17 +32,18 @@ class HTTP_Response
// the request.
{
public:
-
- HTTP_Response (JAWS_IO &io, HTTP_Request &request);
+ HTTP_Response (JAWS_IO &io,
+ HTTP_Request &request);
HTTP_Response (HTTP_Request &request, JAWS_IO &io);
~HTTP_Response (void);
void process_request (void);
// This is called by the handler to initiate a response.
- void error_response (int status, const char *log_message);
- // This returns an error response for cases where there is
- // a problem with the request, logging the log_message.
+ void error_response (int status,
+ const char *log_message);
+ // This returns an error response for cases where there is a problem
+ // with the request, logging the log_message.
private:
@@ -61,6 +62,7 @@ private:
// creates the appropriate header information for responses.
private:
+ // James, please document this.
JAWS_IO &io_;
HTTP_Request &request_;
diff --git a/apps/JAWS/server/HTTP_Server.cpp b/apps/JAWS/server/HTTP_Server.cpp
index 2275e4bede0..be03e8ef584 100644
--- a/apps/JAWS/server/HTTP_Server.cpp
+++ b/apps/JAWS/server/HTTP_Server.cpp
@@ -7,11 +7,24 @@
#include "IO.h"
#include "HTTP_Server.h"
-enum { POOL = 0, PER_REQUEST = 1 };
-enum { SYNCH = 0, ASYNCH = 2 };
+// James, please make sure that you don't have "free floating" enums
+// since they will inevitably cause portability problems.
+
+enum
+{
+ POOL = 0,
+ PER_REQUEST = 1
+};
+
+enum
+{
+ SYNCH = 0,
+ ASYNCH = 2
+};
void
-HTTP_Server::parse_args (int argc, char *argv[])
+HTTP_Server::parse_args (int argc,
+ char *argv[])
{
int c;
int thr_strategy = 0;
@@ -25,6 +38,7 @@ HTTP_Server::parse_args (int argc, char *argv[])
this->throttle_ = 0;
ACE_Get_Opt get_opt (argc, argv, "p:n:t:i:b:");
+
while ((c = get_opt ()) != -1)
switch (c)
{
@@ -66,16 +80,18 @@ HTTP_Server::parse_args (int argc, char *argv[])
break;
}
- if (this->port_ == 0) this->port_ = 5432;
- if (this->threads_ == 0) this->threads_ = 5;
- if (this->backlog_ == 0) this->backlog_ = this->threads_;
+ if (this->port_ == 0)
+ this->port_ = 5432;
+ if (this->threads_ == 0)
+ this->threads_ = 5;
+ if (this->backlog_ == 0)
+ this->backlog_ = this->threads_;
this->strategy_ = thr_strategy + io_strategy;
ACE_DEBUG ((LM_DEBUG,
"in HTTP_Server::init, %s port = %d, number of threads = %d\n",
prog, this->port_, this->threads_));
-
}
int
@@ -118,18 +134,23 @@ HTTP_Server::synch_thread_pool (void)
for (int i = 0; i < this->threads_; i++)
{
Synch_Thread_Pool_Task *t;
- ACE_NEW_RETURN (t, Synch_Thread_Pool_Task (this->acceptor_, this->tm_),
+
+ ACE_NEW_RETURN (t,
+ Synch_Thread_Pool_Task (this->acceptor_, this->tm_),
-1);
+
if (t->open () != 0)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "Thread_Pool_Task::open"), -1);
}
+
this->tm_.wait ();
return 0;
}
Synch_Thread_Pool_Task::Synch_Thread_Pool_Task (HTTP_Acceptor &acceptor,
ACE_Thread_Manager &tm)
- : ACE_Task<ACE_NULL_SYNCH> (&tm), acceptor_ (acceptor)
+ : ACE_Task<ACE_NULL_SYNCH> (&tm),
+ acceptor_ (acceptor)
{
}
@@ -149,9 +170,11 @@ int
Synch_Thread_Pool_Task::svc (void)
{
Synch_HTTP_Handler_Factory factory;
+
for (;;)
{
ACE_SOCK_Stream stream;
+
if (this->acceptor_.accept (stream) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "HTTP_Acceptor::accept"), -1);
@@ -167,8 +190,8 @@ Synch_Thread_Pool_Task::svc (void)
" (%t) in Synch_Thread_Pool_Task::svc, recycling\n"));
}
- // This stinks, because I am afraid that if I remove this line,
- // some compiler will issue a warning that this routine could exit
+ // This stinks, because I am afraid that if I remove this line, some
+ // compiler will issue a warning that this routine could exit
// without returning a value. But, leaving it in makes the VXWORKS
// compiler complain about an unreachable statement.
@@ -190,6 +213,7 @@ HTTP_Server::thread_per_request (void)
for (;;)
{
ACE_SOCK_Stream stream;
+
if (this->acceptor_.accept (stream) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "HTTP_Acceptor::accept"), -1);
@@ -203,18 +227,19 @@ HTTP_Server::thread_per_request (void)
"%p\n", "Thread_Per_Request_Task::open"),
-1);
- // Throttling is not allowing too many threads run away
- // Should really use some sort of condition variable here.
- if (! this->throttle_) continue;
+ // Throttling is not allowing too many threads run away Should
+ // really use some sort of condition variable here.
+ if (!this->throttle_)
+ continue;
+
const ACE_Time_Value wait_time (0,10);
+
while (this->tm_.num_tasks_in_group (grp_id) > this->threads_)
- {
- this->tm_.wait (&wait_time);
- }
+ this->tm_.wait (&wait_time);
}
- // This stinks, because I am afraid that if I remove this line,
- // some compiler will issue a warning that this routine could exit
+ // This stinks, because I am afraid that if I remove this line, some
+ // compiler will issue a warning that this routine could exit
// without returning a value. But, leaving it in makes the VXWORKS
// compiler complain about an unreachable statement.
@@ -236,7 +261,8 @@ Thread_Per_Request_Task::open (void *args)
int status = -1;
int *grp_id = &status;
- if (args != 0) grp_id = (int *) args;
+ if (args != 0)
+ grp_id = (int *) args;
if (*grp_id == -1)
status = *grp_id = this->activate ();
@@ -246,7 +272,6 @@ Thread_Per_Request_Task::open (void *args)
if (*grp_id == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "Thread_Per_Request_Task::open"),
-1);
-
return 0;
}
@@ -266,7 +291,8 @@ Thread_Per_Request_Task::svc (void)
int
Thread_Per_Request_Task::close (u_long)
{
- ACE_DEBUG ((LM_DEBUG, " (%t) Thread_Per_Request_Task::svc, dying\n"));
+ ACE_DEBUG ((LM_DEBUG,
+ " (%t) Thread_Per_Request_Task::svc, dying\n"));
delete this;
return 0;
}
@@ -291,33 +317,33 @@ HTTP_Server::asynch_thread_pool (void)
{
// This only works on Win32
#if defined (ACE_WIN32)
- // Create the appropriate acceptor for this concurrency strategy
- // and an appropriate handler for this I/O strategy
+ // Create the appropriate acceptor for this concurrency strategy and
+ // an appropriate handler for this I/O strategy
ACE_Asynch_Acceptor<Asynch_HTTP_Handler_Factory> acceptor;
// Tell the acceptor to listen on this->port_, which makes an
- // asynchronous I/O request to the OS
+ // asynchronous I/O request to the OS.
if (acceptor.open (ACE_INET_Addr (this->port_),
HTTP_Handler::MAX_REQUEST_SIZE + 1) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n",
"ACE_Asynch_Acceptor::open"), -1);
- // Create the thread pool
+ // Create the thread pool.
for (int i = 0; i < this->threads_; i++)
{
- // Register threads with the proactor and thread manager
+ // Register threads with the proactor and thread manager.
Asynch_Thread_Pool_Task *t;
- ACE_NEW_RETURN
- (t, Asynch_Thread_Pool_Task (*ACE_Service_Config::proactor (),
- this->tm_),
- -1);
+ ACE_NEW_RETURN (t,
+ Asynch_Thread_Pool_Task (*ACE_Service_Config::proactor (),
+ this->tm_),
+ -1);
if (t->open () != 0)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n",
"Thread_Pool_Task::open"), -1);
- // The proactor threads are waiting on the I/O Completion Port
+ // The proactor threads are waiting on the I/O Completion Port.
}
- // wait for the threads to finish
+ // Wait for the threads to finish.
return this->tm_.wait ();
#endif /* ACE_WIN32 */
return -1;
@@ -328,7 +354,8 @@ HTTP_Server::asynch_thread_pool (void)
Asynch_Thread_Pool_Task::Asynch_Thread_Pool_Task (ACE_Proactor &proactor,
ACE_Thread_Manager &tm)
- : ACE_Task<ACE_NULL_SYNCH> (&tm), proactor_ (proactor)
+ : ACE_Task<ACE_NULL_SYNCH> (&tm),
+ proactor_ (proactor)
{
}
diff --git a/apps/JAWS/server/HTTP_Server.h b/apps/JAWS/server/HTTP_Server.h
index d3ba2bdda65..6b6f9af1217 100644
--- a/apps/JAWS/server/HTTP_Server.h
+++ b/apps/JAWS/server/HTTP_Server.h
@@ -1,6 +1,19 @@
// -*- C++ -*-
// $Id$
+// ============================================================================
+//
+// = LIBRARY
+// jaws
+//
+// = FILENAME
+// HTTP_Server.h
+//
+// = AUTHOR
+// James Hu
+//
+// ============================================================================
+
#if !defined (HTTP_SERVER_H)
#define HTTP_SERVER_H
diff --git a/apps/JAWS/server/HTTP_Server_T.h b/apps/JAWS/server/HTTP_Server_T.h
index 733d88274ad..9b981f97a1f 100644
--- a/apps/JAWS/server/HTTP_Server_T.h
+++ b/apps/JAWS/server/HTTP_Server_T.h
@@ -1,13 +1,27 @@
// $Id$
+// ============================================================================
+//
+// = LIBRARY
+// jaws
+//
+// = FILENAME
+// HTTP_Server_T.h
+//
+// = AUTHOR
+// James Hu
+//
+// ============================================================================
+
#if !defined (HTTP_SERVER_T_H)
#define HTTP_SERVER_T_H
#include "ace/SOCK_Acceptor.h"
-// Specialize ACE_SOCK_Acceptor to lock around accept();
template <class LOCK>
class LOCK_SOCK_Acceptor : public ACE_SOCK_Acceptor
+ // = TITLE
+ // Specialize ACE_SOCK_Acceptor to lock around <accept>;
{
public:
int accept (ACE_SOCK_Stream &new_stream,
@@ -17,6 +31,7 @@ public:
private:
LOCK lock_;
+ // Type of locking mechanism.
};
#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
diff --git a/apps/JAWS/server/IO.cpp b/apps/JAWS/server/IO.cpp
index 60335e4872c..ce44d21248a 100644
--- a/apps/JAWS/server/IO.cpp
+++ b/apps/JAWS/server/IO.cpp
@@ -35,7 +35,6 @@ JAWS_IO::handler (JAWS_IO_Handler *handler)
}
JAWS_Synch_IO::JAWS_Synch_IO (void)
- : JAWS_IO ()
{
}
@@ -45,11 +44,13 @@ JAWS_Synch_IO::~JAWS_Synch_IO (void)
}
void
-JAWS_Synch_IO::read (ACE_Message_Block& mb, int size)
+JAWS_Synch_IO::read (ACE_Message_Block &mb,
+ int size)
{
ACE_SOCK_Stream stream;
stream.set_handle (this->handle_);
int result = stream.recv (mb.wr_ptr (), size);
+
if (result <= 0)
this->handler_->read_error ();
else
@@ -65,9 +66,9 @@ JAWS_Synch_IO::receive_file (const char *filename,
int initial_data_length,
int entire_length)
{
- JAWS_File_Handle jf (filename, entire_length);
+ JAWS_File_Handle handle (filename, entire_length);
- int result = jf.error ();
+ int result = handle.error ();
if (result == JAWS_File::OKIE_DOKIE)
{
@@ -75,11 +76,11 @@ JAWS_Synch_IO::receive_file (const char *filename,
stream.set_handle (this->handle_);
int bytes_to_memcpy = ACE_MIN (entire_length, initial_data_length);
- ACE_OS::memcpy (jf.address (), initial_data, bytes_to_memcpy);
+ ACE_OS::memcpy (handle.address (), initial_data, bytes_to_memcpy);
int bytes_to_read = entire_length - bytes_to_memcpy;
- int bytes = stream.recv_n ((char *) jf.address () + initial_data_length,
+ int bytes = stream.recv_n ((char *) handle.address () + initial_data_length,
bytes_to_read);
if (bytes == bytes_to_read)
this->handler_->receive_file_complete ();
@@ -98,23 +99,23 @@ JAWS_Synch_IO::transmit_file (const char *filename,
const char *trailer,
int trailer_size)
{
- JAWS_File_Handle jf (filename);
+ JAWS_File_Handle handle (filename);
- int result = jf.error ();
+ int result = handle.error ();
if (result == JAWS_File::OKIE_DOKIE)
{
ACE_SOCK_Stream stream;
stream.set_handle (this->handle_);
- if ((stream.send_n (header, header_size) == header_size) &&
- ((unsigned long) stream.send_n (jf.address (), jf.size ())
- == jf.size ()) &&
- (stream.send_n (trailer, trailer_size) == trailer_size))
+ if ((stream.send_n (header, header_size) == header_size)
+ && ((u_long) stream.send_n (handle.address (), handle.size ()) == handle.size ())
+ && (stream.send_n (trailer, trailer_size) == trailer_size))
this->handler_->transmit_file_complete ();
else
result = -1;
}
+
if (result != JAWS_File::OKIE_DOKIE)
this->handler_->transmit_file_error (result);
}
@@ -148,7 +149,6 @@ JAWS_Synch_IO::send_message (const char *buffer,
#if defined (ACE_WIN32)
JAWS_Asynch_IO::JAWS_Asynch_IO (void)
- : JAWS_IO ()
{
}
@@ -158,35 +158,37 @@ JAWS_Asynch_IO::~JAWS_Asynch_IO (void)
}
void
-JAWS_Asynch_IO::read (ACE_Message_Block& mb, int size)
+JAWS_Asynch_IO::read (ACE_Message_Block& mb,
+ int size)
{
ACE_Asynch_Read_Stream ar;
- if (ar.open (*this, this->handle_) == -1 ||
- ar.read (mb, size) == -1)
+
+ if (ar.open (*this, this->handle_) == -1
+ || ar.read (mb, size) == -1)
this->handler_->read_error ();
}
-// This method will be called when an asynchronous read completes on a stream.
+// This method will be called when an asynchronous read completes on a
+// stream.
+
void
JAWS_Asynch_IO::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result)
{
+ // This callback is for this->receive_file()
if (result.act () != 0)
- // This callback is for this->receive_file()
{
int code = 0;
if (result.success () && result.bytes_transferred () != 0)
{
- if (result.message_block ().length ()
- == result.message_block ().size ())
+ if (result.message_block ().length () == result.message_block ().size ())
code = JAWS_File::OKIE_DOKIE;
else
{
ACE_Asynch_Read_Stream ar;
- if (ar.open (*this, this->handle_) == -1 ||
- ar.read (result.message_block (),
- result.message_block ().size ()
- - result.message_block ().length (),
- result.act ()) == -1)
+ if (ar.open (*this, this->handle_) == -1
+ || ar.read (result.message_block (),
+ result.message_block ().size () - result.message_block ().length (),
+ result.act ()) == -1)
code = -1;
else
return;
@@ -206,7 +208,8 @@ JAWS_Asynch_IO::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result
else
{
// This callback is for this->read()
- if (result.success () && result.bytes_transferred () != 0)
+ if (result.success ()
+ && result.bytes_transferred () != 0)
this->handler_->read_complete (result.message_block ());
else
this->handler_->read_error ();
@@ -220,20 +223,38 @@ JAWS_Asynch_IO::receive_file (const char *filename,
int entire_length)
{
ACE_Message_Block *mb = 0;
- JAWS_File_Handle *jfp = new JAWS_File_Handle (filename, entire_length);
+ JAWS_File_Handle *handle;
- int result = jfp->error ();
+ // James, please fix this method so that it returns an int (i.e.,
+ // -1) if new fails. Then replace ACE_NEW with ACE_NEW_RETURN and
+ // make sure to update all the callers.
+ ACE_NEW (handle, JAWS_File_Handle (filename, entire_length));
+
+ int result = handle->error ();
if (result == JAWS_File::OKIE_DOKIE)
{
- ACE_OS::memcpy (jfp->address (), initial_data, initial_data_length);
+ ACE_OS::memcpy (handle->address (),
+ initial_data,
+ initial_data_length);
int bytes_to_read = entire_length - initial_data_length;
- mb = new ACE_Message_Block ((char *)jfp->address ()
- + initial_data_length, bytes_to_read);
+
+ mb = ACE_Message_Block ((char *)handle->address ()
+ + initial_data_length, bytes_to_read);
+
+ if (mb == 0)
+ {
+ delete handle;
+ errno = ENOMEM;
+ // James, make sure that we return -1...
+ return;
+ }
+
ACE_Asynch_Read_Stream ar;
+
if (ar.open (*this, this->handle_) == -1
- || ar.read (*mb, mb->size () - mb->length (), jfp) == -1)
+ || ar.read (*mb, mb->size () - mb->length (), handle) == -1)
result = -1;
}
@@ -241,7 +262,7 @@ JAWS_Asynch_IO::receive_file (const char *filename,
{
this->handler_->receive_file_error (result);
delete mb;
- delete jfp;
+ delete handle;
}
}
@@ -253,27 +274,30 @@ JAWS_Asynch_IO::transmit_file (const char *filename,
int trailer_size)
{
ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer = 0;
- JAWS_File_Handle *jfp = new JAWS_File_Handle (filename);
+ JAWS_File_Handle *handle = new JAWS_File_Handle (filename);
- int result = jfp->error ();
+ int result = handle->error ();
if (result == JAWS_File::OKIE_DOKIE)
{
ACE_Message_Block header_mb (header, header_size);
ACE_Message_Block trailer_mb (trailer, trailer_size);
+
header_and_trailer = new ACE_Asynch_Transmit_File::Header_And_Trailer
(&header_mb, header_size, &trailer_mb, trailer_size);
+
ACE_Asynch_Transmit_File tf;
- if (tf.open (*this, this->handle_) == -1 ||
- tf.transmit_file (jfp->handle (), // file handle
- header_and_trailer, // header and trailer data
- 0, // bytes_to_write
- 0, // offset
- 0, // offset_high
- 0, // bytes_per_send
- 0, // flags
- jfp // act
- ) == -1)
+
+ if (tf.open (*this, this->handle_) == -1
+ || tf.transmit_file (handle->handle (), // file handle
+ header_and_trailer, // header and trailer data
+ 0, // bytes_to_write
+ 0, // offset
+ 0, // offset_high
+ 0, // bytes_per_send
+ 0, // flags
+ handle // act
+ ) == -1)
result = -1;
}
@@ -281,7 +305,7 @@ JAWS_Asynch_IO::transmit_file (const char *filename,
{
this->handler_->transmit_file_error (result);
delete header_and_trailer;
- delete jfp;
+ delete handle;
}
}
@@ -318,12 +342,17 @@ JAWS_Asynch_IO::send_message (const char *buffer,
int length,
int act)
{
- ACE_Message_Block *mb = new ACE_Message_Block (buffer, length);
+ // James, make sure that you return -1 if new fails (and update callers?).
+
+ ACE_Message_Block *mb;
+ ACE_NEW (mb, ACE_Message_Block (buffer, length));
+
ACE_Asynch_Write_Stream aw;
- if (aw.open (*this, this->handle_) == -1 ||
- aw.write (*mb, length, (void *) act) == -1)
+ if (aw.open (*this, this->handle_) == -1
+ || aw.write (*mb, length, (void *) act) == -1)
{
mb->release ();
+
if (act == CONFORMATION)
this->handler_->confirmation_message_complete ();
else
@@ -335,6 +364,7 @@ void
JAWS_Asynch_IO::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result)
{
result.message_block ().release ();
+
if (result.act () == (void *) CONFORMATION)
this->handler_->confirmation_message_complete ();
else
diff --git a/apps/JAWS/server/IO.h b/apps/JAWS/server/IO.h
index 52eacf7b1dc..884783b96dd 100644
--- a/apps/JAWS/server/IO.h
+++ b/apps/JAWS/server/IO.h
@@ -2,7 +2,20 @@
// Hey, Emacs! This is a C++ file!
// $Id$
-#ifndef JAWS_IO_H
+// ============================================================================
+//
+// = LIBRARY
+// jaws
+//
+// = FILENAME
+// IO.h
+//
+// = AUTHOR
+// James Hu
+//
+// ============================================================================
+
+#if !defined (JAWS_IO_H)
#define JAWS_IO_H
class ACE_Message_Block;
@@ -12,7 +25,6 @@ class JAWS_IO_Handler;
#include "ace/Asynch_IO.h"
class JAWS_IO
- //
// = TITLE
//
// This class defines the abstract interface for an I/O class in
@@ -31,17 +43,23 @@ public:
void handle (ACE_HANDLE h);
ACE_HANDLE handle (void);
+ // James, please add documentation here.
+
virtual void read (ACE_Message_Block& mb, int size) = 0;
+
virtual void transmit_file (const char *filename,
const char *header,
int header_size,
const char *trailer,
int trailer_size) = 0;
+
virtual void receive_file (const char *filename,
void *initial_data,
int initial_data_length,
int entire_length) = 0;
+
virtual void send_confirmation_message (const char *buffer, int length) = 0;
+
virtual void send_error_message (const char *buffer, int length) = 0;
protected:
@@ -50,6 +68,7 @@ protected:
};
class JAWS_IO_Handler
+// James, please add documentation here.
{
public:
virtual void read_complete (ACE_Message_Block &data) = 0;
@@ -91,47 +110,66 @@ public:
};
class JAWS_Synch_IO : public JAWS_IO
+// James, please add documentation here.
{
public:
JAWS_Synch_IO (void);
+
~JAWS_Synch_IO (void);
+
void read (ACE_Message_Block& mb, int size);
+
void transmit_file (const char *filename,
const char *header,
int header_size,
const char *trailer,
int trailer_size);
+
void receive_file (const char *filename,
void *initial_data,
int initial_data_length,
int entire_length);
- void send_confirmation_message (const char *buffer, int length);
- void send_error_message (const char *buffer, int length);
+
+ void send_confirmation_message (const char *buffer,
+ int length);
+
+ void send_error_message (const char *buffer,
+ int length);
protected:
- virtual void send_message (const char *buffer, int length);
+ virtual void send_message (const char *buffer,
+ int length);
};
// This only works on Win32
#if defined (ACE_WIN32)
class JAWS_Asynch_IO : public JAWS_IO, public ACE_Handler
+// James, please add documentation here.
{
public:
JAWS_Asynch_IO (void);
+
~JAWS_Asynch_IO (void);
- void read (ACE_Message_Block& mb, int size);
+
+ void read (ACE_Message_Block& mb, int size);
+
void transmit_file (const char *filename,
const char *header,
int header_size,
const char *trailer,
int trailer_size);
+
void receive_file (const char *filename,
void *initial_data,
int initial_data_length,
int entire_length);
- void send_confirmation_message (const char *buffer, int length);
- void send_error_message (const char *buffer, int length);
+
+ void send_confirmation_message (const char *buffer,
+ int length);
+
+ void send_error_message (const char *buffer,
+ int length);
protected:
enum Message_Types
@@ -140,19 +178,23 @@ protected:
ERROR_MESSAGE
};
- virtual void send_message (const char *buffer, int length, int act);
+ virtual void send_message (const char *buffer,
+ int length,
+ int act);
virtual void handle_read_stream (const ACE_Asynch_Read_Stream::Result &result);
- // This method will be called when an asynchronous read completes on a stream.
+ // This method will be called when an asynchronous read completes on
+ // a stream.
virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result &result);
- // This method will be called when an asynchronous write completes on a stream.
+ // This method will be called when an asynchronous write completes
+ // on a stream.
virtual void handle_transmit_file (const ACE_Asynch_Transmit_File::Result &result);
- // This method will be called when an asynchronous transmit file completes.
-
+ // This method will be called when an asynchronous transmit file
+ // completes.
};
-#endif /* ACE_WIN32 */
+#endif /* ACE_WIN32 */
#endif /* JAWS_IO_H */
diff --git a/apps/JAWS/server/JAWS_File.cpp b/apps/JAWS/server/JAWS_File.cpp
index 99aca677a4f..77b9ec409fc 100644
--- a/apps/JAWS/server/JAWS_File.cpp
+++ b/apps/JAWS/server/JAWS_File.cpp
@@ -46,15 +46,20 @@ class JAWS_Virtual_Filesystem_Singleton
{
public:
JAWS_Virtual_Filesystem_Singleton (void)
- { this->singleton_ = JAWS_Virtual_Filesystem::instance (); }
+ {
+ this->singleton_ = JAWS_Virtual_Filesystem::instance ();
+ }
~JAWS_Virtual_Filesystem_Singleton (void)
- { delete this->singleton_; }
+ {
+ delete this->singleton_;
+ }
private:
JAWS_Virtual_Filesystem * singleton_;
};
+// James, please remove reliance on Singletons if possible.
static JAWS_Virtual_Filesystem_Singleton cvf_singleton;
void
@@ -143,27 +148,32 @@ JAWS_File_Handle::handle (void) const
int
JAWS_File_Handle::error (void) const
{
- return ((this->file_ == 0) ? -1 : this->file_->error ());
+ if (this->file_ == 0)
+ return -1;
+ else
+ return this->file_->error ();
}
size_t
JAWS_File_Handle::size (void) const
{
- return ((this->file_ == 0) ? -1 : this->file_->size ());
+ if (this->file_ == 0)
+ return -1;
+ else
+ return this->file_->size ();
}
JAWS_Virtual_Filesystem *
JAWS_Virtual_Filesystem::instance (void)
{
- // Double check locking pattern
+ // Double check locking pattern.
if (JAWS_Virtual_Filesystem::cvf_ == 0)
{
ACE_Guard<ACE_SYNCH_RW_MUTEX> m (JAWS_Virtual_Filesystem::lock_);
+
if (JAWS_Virtual_Filesystem::cvf_ == 0)
- {
- JAWS_Virtual_Filesystem::cvf_ = new JAWS_Virtual_Filesystem;
- }
+ JAWS_Virtual_Filesystem::cvf_ = new JAWS_Virtual_Filesystem;
}
return JAWS_Virtual_Filesystem::cvf_;
@@ -172,6 +182,7 @@ JAWS_Virtual_Filesystem::instance (void)
JAWS_Virtual_Filesystem::JAWS_Virtual_Filesystem (void)
{
this->size_ = DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE;
+
for (int i = 0; i < this->size_; i++)
this->table_[i] = 0;
}
@@ -179,56 +190,63 @@ JAWS_Virtual_Filesystem::JAWS_Virtual_Filesystem (void)
JAWS_Virtual_Filesystem::~JAWS_Virtual_Filesystem (void)
{
for (int i = 0; i < this->size_; i++)
- {
- if (this->table_[i] != 0) delete this->table_[i];
- }
+ if (this->table_[i] != 0)
+ delete this->table_[i];
}
JAWS_File *
JAWS_Virtual_Filesystem::fetch (const char * filename)
{
int i;
- JAWS_File * jf = 0;
+ JAWS_File *handle = 0;
{
ACE_Read_Guard<ACE_SYNCH_RW_MUTEX> m (JAWS_Virtual_Filesystem::lock_);
+
i = this->fetch_i (filename);
+
if (i != -1 && ! this->table_[i]->update ())
- jf = this->table_[i];
+ handle = this->table_[i];
}
// Considerably slower on misses, but should be faster on hits.
// This is actually the double check locking pattern.
- if (jf == 0)
+
+ if (handle == 0)
{
ACE_Write_Guard<ACE_SYNCH_RW_MUTEX> m (JAWS_Virtual_Filesystem::lock_);
+
i = this->fetch_i (filename);
+
if (i == -1)
- jf = this->insert_i (new JAWS_File (filename));
+ handle = this->insert_i (new JAWS_File (filename));
else if (this->table_[i]->update ())
{
this->remove_i (i);
- jf = this->table_[i] = new JAWS_File (filename);
+ handle = this->table_[i] = new JAWS_File (filename);
}
else
- jf = this->table_[i];
+ handle = this->table_[i];
}
- return jf;
+ return handle;
}
int
JAWS_Virtual_Filesystem::fetch_i (const char * filename)
{
- int i;
- int notfound = 1;
- for (i = 0; i < DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE; i++)
+ for (int i = 0;
+ i < DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE;
+ i++)
{
- if (this->table_[i] == 0) continue;
- notfound = ACE_OS::strcmp (filename, this->table_[i]->filename ());
- if (!notfound) break;
+ if (this->table_[i] == 0)
+ continue;
+
+ if (ACE_OS::strcmp (filename, this->table_[i]->filename ()) == 0)
+ return i;
}
- return (notfound ? -1 : i);
+
+ return -1;
}
JAWS_File *
@@ -237,27 +255,31 @@ JAWS_Virtual_Filesystem::remove (const char * filename)
ACE_Write_Guard<ACE_SYNCH_RW_MUTEX> m (JAWS_Virtual_Filesystem::lock_);
int i = this->fetch_i (filename);
- return ((i == -1) ? 0 : this->remove_i (i));
+
+ return i == -1 ? 0 : this->remove_i (i);
}
JAWS_File *
JAWS_Virtual_Filesystem::remove_i (int index)
{
- JAWS_File * jf = 0;
+ JAWS_File * handle = 0;
+
if (index != -1)
{
- jf = this->table_[index];
+ handle = this->table_[index];
this->table_[index] = 0;
- jf->release ();
- if (jf->action () == JAWS_File::IDLE)
+ handle->release ();
+
+ if (handle->action () == JAWS_File::IDLE)
{
- delete jf;
- jf = 0;
+ delete handle;
+ handle = 0;
}
else
- jf->action (JAWS_File::WAITING);
+ handle->action (JAWS_File::WAITING);
}
- return jf;
+
+ return handle;
}
JAWS_File *
@@ -274,6 +296,7 @@ JAWS_Virtual_Filesystem::insert_i (JAWS_File * new_file)
{
int i, max;
size_t maxsize = 0;
+
for (i = 0; i < DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE; i++)
{
if (this->table_[i] != 0)
@@ -285,24 +308,28 @@ JAWS_Virtual_Filesystem::insert_i (JAWS_File * new_file)
this->table_[i] = new_file;
break;
}
+
if (i == DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE)
{
- // Forced to exercise a replacement policy here.
- // Let's play nice, and remove the largest object from the cache.
+ // Forced to exercise a replacement policy here. Let's play
+ // nice, and remove the largest object from the cache.
this->remove_i (max);
this->table_[max] = new_file;
}
+
new_file->acquire ();
return new_file;
}
JAWS_File *
-JAWS_Virtual_Filesystem::replace (JAWS_File * new_file)
+JAWS_Virtual_Filesystem::replace (JAWS_File *new_file)
{
ACE_Write_Guard<ACE_SYNCH_RW_MUTEX> m (JAWS_Virtual_Filesystem::lock_);
int i = this->fetch_i (new_file->filename ());
- if (i == -1) this->insert_i (new_file);
+
+ if (i == -1)
+ this->insert_i (new_file);
else
{
this->remove_i (i);
@@ -312,8 +339,6 @@ JAWS_Virtual_Filesystem::replace (JAWS_File * new_file)
return new_file;
}
-
-
void
JAWS_File::init (void)
{
@@ -332,10 +357,13 @@ JAWS_File::JAWS_File (void)
this->init ();
}
-JAWS_File::JAWS_File (const char * filename)
+JAWS_File::JAWS_File (const char *filename)
{
this->init ();
+ // James, this code is important, yet it lacks documentation.
+ // Please rectify this.
+
ACE_OS::strcpy (this->filename_, filename);
this->action (JAWS_File::IDLE);
@@ -344,21 +372,25 @@ JAWS_File::JAWS_File (const char * filename)
this->error (JAWS_File::ACCESS_FAILED);
return;
}
+
if (ACE_OS::stat (this->filename_, &this->stat_) == -1)
{
this->error (JAWS_File::STAT_FAILED);
return;
}
+
this->size_ = this->stat_.st_size;
this->tempname_ = ACE_OS::tempnam (".", "zJAWS");
ACE_HANDLE original = ACE_OS::open (this->filename_, RCOPY_FLAGS, R_MASK);
+
if (original == ACE_INVALID_HANDLE)
{
this->error (JAWS_File::OPEN_FAILED);
return;
}
+
ACE_HANDLE copy = ACE_OS::open (this->tempname_, WCOPY_FLAGS, W_MASK);
if (copy == ACE_INVALID_HANDLE)
{
@@ -369,6 +401,7 @@ JAWS_File::JAWS_File (const char * filename)
ACE_Mem_Map original_map (original);
ACE_Mem_Map copy_map (copy, this->size_, PROT_WRITE, MAP_SHARED);
+
void *src = original_map.addr ();
void *dst = copy_map.addr ();
@@ -381,7 +414,8 @@ JAWS_File::JAWS_File (const char * filename)
{
ACE_OS::memcpy (dst, src, this->size_);
- if (original_map.unmap () == -1 || copy_map.unmap () == -1)
+ if (original_map.unmap () == -1
+ || copy_map.unmap () == -1)
this->error (JAWS_File::MEMMAP_FAILED);
}
@@ -423,6 +457,7 @@ int
JAWS_File::acquire (void)
{
ACE_Write_Guard<ACE_SYNCH_RW_MUTEX> m (this->lock_);
+
if (this->reference_count_++ == 0)
{
if (this->error_ == OKIE_DOKIE)
@@ -431,11 +466,10 @@ JAWS_File::acquire (void)
{
case JAWS_File::IDLE:
this->handle_ = ACE_OS::open (this->tempname_, READ_FLAGS, R_MASK);
+
if (this->handle_ == ACE_INVALID_HANDLE)
- {
- this->error (JAWS_File::OPEN_FAILED,
- "JAWS_File::acquire: open");
- }
+ this->error (JAWS_File::OPEN_FAILED,
+ "JAWS_File::acquire: open");
else if (this->mmap_.map (this->handle_, -1,
PROT_READ, MAP_PRIVATE) != 0)
{
@@ -444,18 +478,23 @@ JAWS_File::acquire (void)
ACE_OS::close (this->handle_);
this->handle_ = ACE_INVALID_HANDLE;
}
- else this->action (JAWS_File::READING);
+
+ else
+ this->action (JAWS_File::READING);
break;
case JAWS_File::WRITING:
- this->handle_ = ACE_OS::open (this->tempname_, WRITE_FLAGS, W_MASK);
+ this->handle_ = ACE_OS::open (this->tempname_,
+ WRITE_FLAGS,
+ W_MASK);
+
if (this->handle_ == ACE_INVALID_HANDLE)
- {
- this->error (JAWS_File::OPEN_FAILED,
- "JAWS_File::acquire: open");
- }
- else if (ACE_OS::lseek (this->handle_, this->size_ - 1, SEEK_SET)
- == -1)
+ this->error (JAWS_File::OPEN_FAILED,
+ "JAWS_File::acquire: open");
+
+ else if (ACE_OS::lseek (this->handle_,
+ this->size_ - 1,
+ SEEK_SET) == -1)
{
this->error (JAWS_File::OPEN_FAILED,
"JAWS_File::acquire: lseek");
@@ -492,10 +531,11 @@ int
JAWS_File::release (void)
{
ACE_Write_Guard<ACE_SYNCH_RW_MUTEX> m (this->lock_);
+
if (--this->reference_count_ == 0)
{
if (this->error_ == OKIE_DOKIE)
- // free file from memory if reference count is zero
+ // Free file from memory if reference count is zero.
switch (this->action ())
{
case JAWS_File::READING:
@@ -511,21 +551,17 @@ JAWS_File::release (void)
ACE_HANDLE original = ACE_OS::open (this->filename_,
WRITE_FLAGS, W_MASK);
if (original == ACE_INVALID_HANDLE)
- {
- this->error_ = JAWS_File::OPEN_FAILED;
- }
+ this->error_ = JAWS_File::OPEN_FAILED;
else if (ACE_OS::write (original, this->mmap_.addr (),
- this->size_)
- == -1)
+ this->size_) == -1)
{
this->error_ = JAWS_File::WRITE_FAILED;
ACE_OS::close (original);
ACE_OS::unlink (this->filename_);
}
else if (ACE_OS::stat (this->filename_, &this->stat_) == -1)
- {
- this->error_ = JAWS_File::STAT_FAILED;
- }
+ this->error_ = JAWS_File::STAT_FAILED;
+
this->mmap_.unmap ();
ACE_OS::close (this->handle_);
this->handle_ = ACE_INVALID_HANDLE;
@@ -569,7 +605,8 @@ JAWS_File::error (int error_value, const char * s)
{
ACE_Write_Guard<ACE_SYNCH_RW_MUTEX> m (this->lock_);
ACE_ERROR ((LM_ERROR, "%p.\n", s));
- return (this->error_ = error_value);
+ this->error_ = error_value;
+ return error_value;
}
const char *
@@ -608,14 +645,10 @@ JAWS_File::update (void) const
struct stat statbuf;
if (ACE_OS::stat (this->filename_, &statbuf) == -1)
- {
- result = 1;
- }
+ result = 1;
else
- {
- // non-portable code may follow
+ // non-portable code may follow
result = (ACE_OS::difftime (this->stat_.st_mtime, statbuf.st_mtime) < 0);
- }
return result;
}
diff --git a/apps/JAWS/server/JAWS_File.h b/apps/JAWS/server/JAWS_File.h
index 3bcca080715..ea01eebca5f 100644
--- a/apps/JAWS/server/JAWS_File.h
+++ b/apps/JAWS/server/JAWS_File.h
@@ -15,35 +15,36 @@
//
// ============================================================================
-#ifndef JAWS_FILE_H
+#if !defined (JAWS_FILE_H)
#define JAWS_FILE_H
#include "ace/Mem_Map.h"
#include "ace/Synch.h"
+// = Forward declarations.
class JAWS_File;
class JAWS_Virtual_Filesystem;
class JAWS_File_Handle
// = TITLE
- // Abstraction over a real file. This is meant to be the
- // entry point into the Cached Virtual Filesystem.
- // On creation, the cache is checked, and reference count is
- // incremented. On destruction, reference count is decremented.
- // If the reference count is 0, the file is removed from the cache.
-
+ // Abstraction over a real file. This is meant to be the entry
+ // point into the Cached Virtual Filesystem. On creation, the
+ // cache is checked, and reference count is incremented. On
+ // destruction, reference count is decremented. If the
+ // reference count is 0, the file is removed from the cache.
+ //
// E.g. 1,
// {
// JAWS_File_Handle foo("foo.html");
// this->peer ().send (foo.address (), foo.size ());
// }
-
+ //
// E.g. 2,
// {
// JAWS_File_Handle foo("foo.html");
// io->transmitfile (foo.handle (), this->peer ().handle ());
// }
-
+ //
// E.g. 3,
// {
// JAWS_File_Handle foo("foo.html", content_length);
@@ -52,28 +53,29 @@ class JAWS_File_Handle
{
public:
- JAWS_File_Handle (const char * filename);
- // query cache for file, and acquire it
- // assumes the file is being opened for reading
+ JAWS_File_Handle (const char *filename);
+ // Query cache for file, and acquire it assumes the file is being
+ // opened for reading.
- JAWS_File_Handle (const char * filename, int size);
- // create new entry, and acquire it
- // presence of SIZE assumes the file is being opened for writing
+ JAWS_File_Handle (const char *filename,
+ int size);
+ // Create new entry, and acquire it presence of SIZE assumes the
+ // file is being opened for writing.
~JAWS_File_Handle (void);
- // closes any open handles, release acquired file
+ // Closes any open handles, release acquired file.
- void * address (void) const;
- // base address of memory mapped file
+ void *address (void) const;
+ // Base address of memory mapped file.
ACE_HANDLE handle (void) const;
- // a handle (e.g., UNIX file descriptor, or NT file handle)
+ // A handle (e.g., UNIX file descriptor, or NT file handle).
int error (void) const;
- // any associated error in handle creation and acquisition
+ // Any associated error in handle creation and acquisition.
size_t size (void) const;
- // the size of the file
+ // The size of the file.
protected:
@@ -81,47 +83,53 @@ protected:
// Default do nothing constructor. Prevent it from being called.
void init (void);
+ // James, please document this function.
private:
- JAWS_File * file_;
+ // James, please document.
+ JAWS_File *file_;
+
ACE_HANDLE handle_;
};
+// James, can you please replace this with ACE_Hash_Map_Manager?
+
class JAWS_Virtual_Filesystem
// = TITLE
- // A hash table holding the information about
- // entry point into the Cached Virtual Filesystem.
- // On creation, the cache is checked, and reference count is
- // incremented. On destruction, reference count is decremented.
- // If the reference count is 0, the file is removed from the cache.
+ // A hash table holding the information about entry point into
+ // the Cached Virtual Filesystem. On creation, the cache is
+ // checked, and reference count is incremented. On destruction,
+ // reference count is decremented. If the reference count is 0,
+ // the file is removed from the cache.
{
public:
-
static JAWS_Virtual_Filesystem * instance (void);
~JAWS_Virtual_Filesystem (void);
- JAWS_File * fetch (const char * filename);
- JAWS_File * remove (const char * filename);
- JAWS_File * insert (JAWS_File * new_file);
- JAWS_File * replace (JAWS_File * new_file);
+ // James, please document these methods.
+ JAWS_File *fetch (const char * filename);
+ JAWS_File *remove (const char * filename);
+ JAWS_File *insert (JAWS_File * new_file);
+ JAWS_File *replace (JAWS_File * new_file);
protected:
-
JAWS_Virtual_Filesystem (void);
private:
+ // James, please document these methods.
+
int fetch_i (const char * filename);
JAWS_File * remove_i (int index);
- JAWS_File * insert_i (JAWS_File * new_file);
+ JAWS_File * insert_i (JAWS_File *new_file);
public:
enum
{
DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE = 512,
- // For this stupid implementation, use an array. Someday, use
- // a balanced search tree.
+ // For this stupid implementation, use an array. Someday, use a
+ // balanced search tree.
DEFAULT_VIRTUAL_FILESYSTEM_CACHE_SIZE = 10
// This determines the highwater mark in megabytes for the cache.
@@ -130,82 +138,99 @@ public:
private:
- JAWS_File * table_[DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE];
+ JAWS_File *table_[DEFAULT_VIRTUAL_FILESYSTEM_TABLE_SIZE];
int size_;
- static JAWS_Virtual_Filesystem * cvf_;
+ static JAWS_Virtual_Filesystem *cvf_;
static ACE_SYNCH_RW_MUTEX lock_;
};
class JAWS_File
// = TITLE
- // Abstraction over a real file. This is what the Virtual Filesystem
- // contains. This class is not intended for general consumption.
- // Please consult a physician before attempting to use this class.
+ // Abstraction over a real file. This is what the Virtual
+ // Filesystem contains. This class is not intended for general
+ // consumption. Please consult a physician before attempting to
+ // use this class.
{
public:
+ JAWS_File (const char *filename);
+ // Creates a file for reading.
- JAWS_File (const char * filename);
- // creates a file for reading
-
- JAWS_File (const char * filename, int size);
- // creates a file for writing
+ JAWS_File (const char *filename,
+ int size);
+ // Creates a file for writing.
~JAWS_File (void);
- // only if reference count is zero should this be called
+ // Only if reference count is zero should this be called.
int acquire (void);
- // increment the reference_count_
+ // Increment the reference_count_.
int release (void);
- // decrement the reference_count_
+ // Decrement the reference_count_.
+ // = action_ accessors
int action (void) const;
int action (int action_value);
- // action_ accessors
+ // = error_ accessors
int error (void) const;
- int error (int error_value, const char * s = "JAWS_File");
- // error_ accessors
+ int error (int error_value,
+ const char *s = "JAWS_File");
- const char * filename (void) const;
+ const char *filename (void) const;
// filename_ accessor
ACE_HANDLE handle (void) const;
- // handle_ accessor
+ // handle_ accessor.
- void * address (void) const;
- // base memory address for memory mapped file
+ void *address (void) const;
+ // Base memory address for memory mapped file.
size_t size (void) const;
- // size_ accessor
+ // size_ accessor.
int update (void) const;
- // true if file on disk is newer than cached file
+ // True if file on disk is newer than cached file.
protected:
-
JAWS_File (void);
+ // James, please document...
+
void init (void);
public:
- enum { IDLE = 0, READING = 1, WRITING = 2, WAITING = 4 };
- // action status indicators
+ enum
+ {
+ IDLE = 0,
+ READING = 1,
+ WRITING = 2,
+ WAITING = 4
+ };
+
+ // = action status indicators
+
// WAITING -- removed from Virtual Filesystem, but not deleted
- enum { OKIE_DOKIE = 0,
- ACCESS_FAILED,
- OPEN_FAILED,
- COPY_FAILED,
- STAT_FAILED,
- MEMMAP_FAILED,
- WRITE_FAILED };
+ enum
+ {
+ // James, please rename OKIE_DOKIE to SUCCESS or something boring.
+
+ OKIE_DOKIE = 0,
+ ACCESS_FAILED,
+ OPEN_FAILED,
+ COPY_FAILED,
+ STAT_FAILED,
+ MEMMAP_FAILED,
+ WRITE_FAILED
+ };
private:
- char * tempname_;
- char filename_[MAXPATHLEN+1];
+ // James, please document these fields.
+ char *tempname_;
+ char filename_[MAXPATHLEN + 1];
ACE_Mem_Map mmap_;
ACE_HANDLE handle_;
diff --git a/apps/JAWS/server/Parse_Headers.cpp b/apps/JAWS/server/Parse_Headers.cpp
index 2b28ce9426a..30d3abf45c3 100644
--- a/apps/JAWS/server/Parse_Headers.cpp
+++ b/apps/JAWS/server/Parse_Headers.cpp
@@ -27,33 +27,40 @@ Headers::parse_header_line (char * const header_line)
int offset = 1;
ptr = ACE_OS::strchr (header_line, '\n');
+
if (ptr > header_line && ptr[-1] == '\r')
- ptr--, offset++;
- if (ptr == header_line) {
- this->done_ = 1;
- return;
- }
+ {
+ ptr--;
+ offset++;
+ }
+
+ if (ptr == header_line)
+ {
+ this->done_ = 1;
+ return;
+ }
+
*ptr = '\0';
ptr += offset;
char *value;
char *header = ACE_OS::strtok_r (buf, ":", &value);
- if (header != NULL && this->map_.mapped (header)) {
- while (isspace (*value)) value++;
- this->map_[header] = value;
- }
+ if (header != NULL && this->map_.mapped (header))
+ {
+ while (isspace (*value))
+ value++;
- // write back the unused portion of the input
- ACE_OS::memmove(header_line, ptr, strlen(ptr)+1);
+ this->map_[header] = value;
+ }
+
+ // Write back the unused portion of the input.
+ ACE_OS::memmove (header_line, ptr, strlen(ptr) + 1);
}
int
-Headers::complete_header_line (char * const header_line)
+Headers::complete_header_line (char *const header_line)
{
- char *ptr;
- int offset;
-
// Algorithm --
// Scan for end of line marker.
// If the next character is linear white space, then unfold the header.
@@ -64,32 +71,41 @@ Headers::complete_header_line (char * const header_line)
// return 0 if no end of line marker
// return 1 if complete header line
- ptr = header_line;
- if (! this->end_of_line (ptr, offset)) return 0;
+ char *ptr = header_line;
+ int offset;
- if (ptr == header_line) {
- ACE_OS::memmove (ptr, ptr+offset, strlen(ptr+offset) + 1);
- this->done_ = 1;
- ACE_DEBUG ((LM_DEBUG, " (%t) no more headers\n"));
+ if (!this->end_of_line (ptr, offset))
return 0;
- }
-
- do {
- switch (ptr[offset]) {
- case ' ':
- case '\t':
- ACE_OS::memmove (ptr, ptr+offset, strlen(ptr+offset) + 1);
- break;
-
- case '\n':
- case '\r':
- return 1;
-
- default:
- if (isalpha (ptr[offset])) return 1;
- else return -1;
+
+ if (ptr == header_line)
+ {
+ ACE_OS::memmove (ptr, ptr+offset, ACE_OS::strlen (ptr + offset) + 1);
+ this->done_ = 1;
+ ACE_DEBUG ((LM_DEBUG, " (%t) no more headers\n"));
+ return 0;
}
- } while (this->end_of_line (ptr, offset));
+
+ do
+ {
+ switch (ptr[offset])
+ {
+ case ' ':
+ case '\t':
+ ACE_OS::memmove (ptr, ptr+offset, ACE_OS::strlen (ptr + offset) + 1);
+ break;
+
+ case '\n':
+ case '\r':
+ return 1;
+
+ default:
+ if (isalpha (ptr[offset]))
+ return 1;
+ else
+ return -1;
+ }
+ }
+ while (this->end_of_line (ptr, offset) != 0);
return 0;
}
@@ -116,19 +132,20 @@ int
Headers::end_of_line (char * &line, int &offset) const
{
const char *old_line = line;
- char *ptr;
+ char *ptr = ACE_OS::strchr (old_line, '\n');
- if ((ptr = ACE_OS::strchr (old_line, '\n')) == NULL) return 0;
+ if (pt == NULL)
+ return 0;
line = ptr;
offset = 1;
- if (line > old_line) {
- if (line[-1] == '\r') {
+ if (line > old_line
+ && line[-1] == '\r')
+ {
line--;
offset = 2;
}
- }
return 1;
}
@@ -136,7 +153,8 @@ Headers::end_of_line (char * &line, int &offset) const
// Implementation of class Headers_Map
-Headers_Map::Headers_Map (void) : num_headers_(0)
+Headers_Map::Headers_Map (void)
+ : num_headers_(0)
{
}
@@ -144,19 +162,22 @@ Headers_Map::~Headers_Map (void)
{
}
-Headers_Map::Map_Item::Map_Item () : header_(0), value_(0), no_value_("")
+Headers_Map::Map_Item::Map_Item (void)
+ : header_(0),
+ value_(0),
+ no_value_("")
{
}
-Headers_Map::Map_Item::~Map_Item ()
+Headers_Map::Map_Item::~Map_Item (void)
{
- ACE_OS::free ((void *)this->header_);
- ACE_OS::free ((void *)this->value_);
+ ACE_OS::free ((void *) this->header_);
+ ACE_OS::free ((void *) this->value_);
}
Headers_Map::Map_Item::operator const char * (void) const
{
- return (this->value_ == NULL) ? this->no_value_ : this->value_;
+ return this->value_ == NULL ? this->no_value_ : this->value_;
}
Headers_Map::Map_Item &
@@ -219,35 +240,41 @@ Headers_Map::mapped (const char * const header) const
Headers_Map::Map_Item *
Headers_Map::find (const char * const header) const
{
- Headers_Map * const mutable_this = (Headers_Map *)this;
+ Headers_Map *const mutable_this = (Headers_Map *) this;
mutable_this->garbage.header_ = header;
- Headers_Map::Map_Item *mi_ptr =
- (Headers_Map::Map_Item *)
- ::bsearch (&this->garbage, this->map_, this->num_headers_,
- sizeof(Headers_Map::Map_Item), Headers_Map::compare);
- mutable_this->garbage.header_ = 0;
+ Headers_Map::Map_Item *mi_ptr = (Headers_Map::Map_Item *)
+ ::bsearch (&this->garbage,
+ this->map_,
+ this->num_headers_,
+ sizeof (Headers_Map::Map_Item),
+ Headers_Map::compare);
+ mutable_this->garbage.header_ = 0;
return mi_ptr;
}
Headers_Map::Map_Item *
-Headers_Map::place (const char * const header)
+Headers_Map::place (const char *const header)
{
this->map_[this->num_headers_++].header_ = ACE_OS::strdup(header);
- ::qsort(this->map_, this->num_headers_, sizeof(Headers_Map::Map_Item),
- Headers_Map::compare);
+ ::qsort (this->map_,
+ this->num_headers_,
+ sizeof (Headers_Map::Map_Item),
+ Headers_Map::compare);
return this->find (header);
}
int
-Headers_Map::compare (const void *item1, const void *item2)
+Headers_Map::compare (const void *item1,
+ const void *item2)
{
Headers_Map::Map_Item *a, *b;
- a = (Headers_Map::Map_Item *)item1;
- b = (Headers_Map::Map_Item *)item2;
+ a = (Headers_Map::Map_Item *) item1;
+ b = (Headers_Map::Map_Item *) item2;
- return ACE_OS::strcasecmp(a->header_, b->header_);
+ return ACE_OS::strcasecmp (a->header_,
+ b->header_);
}
diff --git a/apps/JAWS/server/Parse_Headers.h b/apps/JAWS/server/Parse_Headers.h
index 0be498a7b77..7ef885c3d8f 100644
--- a/apps/JAWS/server/Parse_Headers.h
+++ b/apps/JAWS/server/Parse_Headers.h
@@ -5,10 +5,10 @@
// ============================================================================
//
// = LIBRARY
-// apps
+// jaws
//
// = FILENAME
-// Parse_Headers
+// Parse_Headers.h
//
// = AUTHOR
// James Hu
@@ -21,6 +21,7 @@
#include "ace/OS.h"
class Headers_Map
+// James, please add documentation here.
{
public:
Headers_Map (void);
@@ -29,13 +30,13 @@ public:
class Map_Item
{
public:
- Map_Item ();
- ~Map_Item ();
+ Map_Item (void);
+ ~Map_Item (void);
operator const char * (void) const;
- Map_Item & operator= (char *);
- Map_Item & operator= (const char *);
- Map_Item & operator= (const Map_Item &);
+ Map_Item &operator= (char *);
+ Map_Item &operator= (const char *);
+ Map_Item &operator= (const Map_Item &);
const char *header_;
const char *value_;
@@ -43,16 +44,19 @@ public:
const char *no_value_;
};
- Map_Item & operator[] (const char * const header);
- const Map_Item & operator[] (const char * const header) const;
+ Map_Item &operator[] (const char *const header);
+ const Map_Item &operator[] (const char *const header) const;
- enum { MAX_HEADERS = 100 };
+ enum
+ {
+ MAX_HEADERS = 100
+ };
- int mapped (const char * const header) const;
+ int mapped (const char *const header) const;
private:
- Map_Item * find (const char * const header) const;
- Map_Item * place (const char * const header);
+ 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:
@@ -75,24 +79,27 @@ public:
Headers (void);
~Headers (void);
- void recognize (const char * const header);
+ void recognize (const char *const header);
- void parse_header_line (char * const header_line);
+ void parse_header_line (char *const header_line);
- int complete_header_line (char * const header_line);
+ int complete_header_line (char *const header_line);
// -1 -> end of line but not complete header line
// 0 -> no end of line marker
// 1 -> complete header line
int end_of_headers (void) const;
- enum { MAX_HEADER_LINE_LENGTH = 8192 };
+ 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;
+ 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;
+ int end_of_line (char *&line, int &offset) const;
private:
Headers_Map map_;
diff --git a/apps/JAWS/server/main.cpp b/apps/JAWS/server/main.cpp
index 617088f2260..6929ecbe35a 100644
--- a/apps/JAWS/server/main.cpp
+++ b/apps/JAWS/server/main.cpp
@@ -8,12 +8,18 @@ ACE_STATIC_SVC_REQUIRE(HTTP_Server)
extern "C"
{
-/* call exit() so that static destructors get called */
+ // call exit() so that static destructors get called
static void
-handler (int) { exit (0); }
+handler (int)
+{
+ ACE_OS::exit (0);
+}
}
+// This is the driver entry point into JAWS. It is possible to use
+// JAWS as an ACE Service, as well.
+
int
main (int argc, char *argv[])
{
diff --git a/apps/JAWS/server/test_HTTP_Request.cpp b/apps/JAWS/server/test_HTTP_Request.cpp
index 1666142c84d..461a81eb9a1 100644
--- a/apps/JAWS/server/test_HTTP_Request.cpp
+++ b/apps/JAWS/server/test_HTTP_Request.cpp
@@ -17,7 +17,7 @@ static char* request_strings [] =
static int total = 2;
int
-main ()
+main (void)
{
int index = 0;
HTTP_Request request;
@@ -28,27 +28,27 @@ main ()
request.init (r, len);
request.dump ();
- if (request.type () == HTTP_Request::PUT)
- {
- ACE_Mem_Map outfile;
- ACE_HANDLE handle = ACE_OS::open (request.filename (),
- FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED | O_RDWR | O_CREAT);
- if (outfile.map (handle,
- request.content_length (),
- PROT_RDWR,
- MAP_SHARED) == -1)
- ACE_ERROR ((LM_ERROR, "%p: opening %s.\n",
- "main",
- request.filename ()));
- else
- {
- // Write the file.
- ACE_OS::memcpy (outfile.addr (),
- request.data (),
- request.content_length ());
- outfile.sync ();
- }
- }
+ if (request.type () == HTTP_Request::PUT)
+ {
+ ACE_Mem_Map outfile;
+ ACE_HANDLE handle = ACE_OS::open (request.filename (),
+ FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED | O_RDWR | O_CREAT);
+ if (outfile.map (handle,
+ request.content_length (),
+ PROT_RDWR,
+ MAP_SHARED) == -1)
+ ACE_ERROR ((LM_ERROR, "%p: opening %s.\n",
+ "main",
+ request.filename ()));
+ else
+ {
+ // Write the file.
+ ACE_OS::memcpy (outfile.addr (),
+ request.data (),
+ request.content_length ());
+ outfile.sync ();
+ }
+ }
}
return 0;