diff options
author | nw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-08-26 20:40:55 +0000 |
---|---|---|
committer | nw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-08-26 20:40:55 +0000 |
commit | 2ceffa537ed9692d29de28d4bc049064eb66b690 (patch) | |
tree | b32687ef66de34a3a0492fe33b4fa7cf092c3738 | |
parent | 56e6d632b026e0ee1f816e3f988eb808467350e3 (diff) | |
download | ATCD-2ceffa537ed9692d29de28d4bc049064eb66b690.tar.gz |
*** empty log message ***
-rw-r--r-- | apps/JAWS/clients/Caching/Local_Locator.cpp | 1 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/Local_Locator.h | 1 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/Locator_Request_Reply.cpp | 273 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/Locator_Request_Reply.h | 62 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/Locator_Request_Reply.i | 76 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/URL_Array_Helper.cpp | 41 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/URL_Array_Helper.h | 40 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/URL_Locator.h | 3 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/URL_Properties.cpp | 30 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/URL_Properties.h | 2 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/URL_Properties.i | 2 |
11 files changed, 476 insertions, 55 deletions
diff --git a/apps/JAWS/clients/Caching/Local_Locator.cpp b/apps/JAWS/clients/Caching/Local_Locator.cpp index aae81ffde1e..784229471f1 100644 --- a/apps/JAWS/clients/Caching/Local_Locator.cpp +++ b/apps/JAWS/clients/Caching/Local_Locator.cpp @@ -5,7 +5,6 @@ #define ACE_BUILD_DLL #include "Local_Locator.h" -#include "ID_Generator.h" #if !defined (__ACE_INLINE__) #include "Local_Locator.i" diff --git a/apps/JAWS/clients/Caching/Local_Locator.h b/apps/JAWS/clients/Caching/Local_Locator.h index 6bd5f8a882b..a0e303866bb 100644 --- a/apps/JAWS/clients/Caching/Local_Locator.h +++ b/apps/JAWS/clients/Caching/Local_Locator.h @@ -20,6 +20,7 @@ #include "URL_Locator.h" #include "ace/Containers.h" +#include "ID_Generator.h" class ACE_URL_Record // = TITLE diff --git a/apps/JAWS/clients/Caching/Locator_Request_Reply.cpp b/apps/JAWS/clients/Caching/Locator_Request_Reply.cpp new file mode 100644 index 00000000000..dc762835ac2 --- /dev/null +++ b/apps/JAWS/clients/Caching/Locator_Request_Reply.cpp @@ -0,0 +1,273 @@ +/* -*- C++ -*- */ + +// $Id$ + +#if !defined (ACE_LOCATOR_REQUEST_REPLY_C) +#define ACE_LOCATOR_REQUEST_REPLY_C + +#define ACE_BUILD_DLL +#include "Locator_Request_Reply.h" + +#if !defined (__ACE_INLINE__) +#include "Locator_Request_Reply.i" +#endif + +#include "URL_Properties.h" +#include "URL_Array_Helper.h" +#include "URL_Locator.h" + +int +ACE_URL_Locator_Request::url_query (const int how, + const ACE_URL_Property_Seq &pseq, + const int how_many) +{ + ACE_TRACE ("ACE_URL_Locator_Request::url_query"); + + if (how >= ACE_URL_Locator::INVALID_SELECTION) + return -1; + ACE_NEW_RETURN (this->seq1_, ACE_URL_Property_Seq (pseq), -1); + this->how_ = how; + this->how_many_ = how_many; + this->code_ = ACE_URL_Locator_Request::QUERY; + return 0; +} + +int +ACE_URL_Locator_Request::export_offer (const ACE_URL_Offer &offer) +{ + ACE_TRACE ("ACE_URL_Locator_Request::export_offer"); + + ACE_NEW_RETURN (this->offer_, ACE_URL_Offer (offer), -1); + this->code_ = ACE_URL_Locator_Request::EXPORT; + return 0; +} + +int +ACE_URL_Locator_Request::withdraw_offer (const ACE_WString &offer_id) +{ + ACE_TRACE ("ACE_URL_Locator_Request::withdraw_offer"); + + this->id_ = offer_id; + this->code_ = ACE_URL_Locator_Request::WITHDRAW; + return 0; +} + +int +ACE_URL_Locator_Request::describe_offer (const ACE_WString &offer_id) +{ + ACE_TRACE ("ACE_URL_Locator_Request::describe_offer"); + + this->id_ = offer_id; + this->code_ = ACE_URL_Locator_Request::DESCRIBE; + return 0; +} + +int +ACE_URL_Locator_Request::modify_offer (const ACE_WString &offer_id, + const ACE_WString *url, + const ACE_URL_Property_Seq &del, + const ACE_URL_Property_Seq &modify) +{ + ACE_TRACE ("ACE_URL_Locator_Request::modify_offer"); + + ACE_NEW_RETURN (this->seq1_, ACE_URL_Property_Seq (del), -1); + ACE_NEW_RETURN (this->seq2_, ACE_URL_Property_Seq (modify), -1); + + if (url != 0) + this->url_ = *url; + + this->id_ = offer_id; + this->code_ = ACE_URL_Locator_Request::MODIFY; + return 0; +} + +#define ENCODE_UINT32(ADDR,LEN,V) \ + * (ACE_UINT32 *) (ADDR+LEN) = htonl (V); \ + total_length += sizeof (ACE_UINT32); + +#define DECODE_UINT32(ADDR,LEN,V) \ + V = ntohl (* (ACE_UINT32 *) (ADDR+LEN)); \ + total_length += sizeof (ACE_UINT32); + +size_t +ACE_URL_Locator_Request::encode (void) +{ + ACE_TRACE ("ACE_URL_Locator_Request::encode"); + + size_t buf_size = this->bsize (); + + ACE_NEW_RETURN (this->buffer_, char [buf_size], 0); + ((ACE_UINT32 *) this->buffer_)[0] = htonl (buf_size); + ((ACE_UINT32 *) this->buffer_)[1] = htonl (this->code_); + size_t total_length = 2 * sizeof (ACE_UINT32); + + switch (this->code_) + { + case ACE_URL_Locator_Request::QUERY: + ENCODE_UINT32 (this->buffer_, total_length, this->how_); + ENCODE_UINT32 (this->buffer_, total_length, this->how_many_); + total_length += ace_array_encode (this->buffer_ + total_length, *this->seq1_); + break; + case ACE_URL_Locator_Request::EXPORT: + total_length += this->offer_->encode (this->buffer_ + total_length); + break; + case ACE_URL_Locator_Request::WITHDRAW: + case ACE_URL_Locator_Request::DESCRIBE: + total_length += ACE_WString_Helper::encode (this->buffer_ + total_length, + &this->id_); + break; + case ACE_URL_Locator_Request::MODIFY: + total_length += ACE_WString_Helper::encode (this->buffer_ + total_length, + &this->id_); + total_length += ACE_WString_Helper::encode (this->buffer_ + total_length, + &this->url_); + total_length += ace_array_encode (this->buffer_ + total_length, *this->seq1_); + total_length += ace_array_encode (this->buffer_ + total_length, *this->seq2_); + break; + default: + // Invalid data encountered. Stop encoding now. + return 0; + break; + } + ACE_ASSERT (total_length == buf_size); + return total_length; +} + +size_t +ACE_URL_Locator_Request::decode (void *buffer) +{ + ACE_TRACE ("ACE_URL_Locator_Request::decode"); + + if (buffer == 0) + return 0; + // Check if we have a buffer available. + delete [] this->buffer_; + this->buffer_ = (char*) buffer; + + size_t buf_size = ntohl (((ACE_UINT32 *) this->buffer_)[0]); + this->code_ = ntohl (((ACE_UINT32 *) this->buffer_)[1]); + // Get the operation code. + + size_t total_length = 2 * sizeof (ACE_UINT32); + + switch (this->code_) + { + case ACE_URL_Locator_Request::QUERY: + DECODE_UINT32 (this->buffer_, total_length, this->how_); + DECODE_UINT32 (this->buffer_, total_length, this->how_many_); + delete this->seq1_; + ACE_NEW_RETURN (this->seq1_, ACE_URL_Property_Seq (1), 0); + total_length += ace_array_decode (this->buffer_ + total_length, *this->seq1_); + break; + case ACE_URL_Locator_Request::EXPORT: + delete this->offer_; + ACE_NEW_RETURN (this->offer_, ACE_URL_Offer, 0); + total_length += this->offer_->decode (this->buffer_); + break; + case ACE_URL_Locator_Request::WITHDRAW: + case ACE_URL_Locator_Request::DESCRIBE: + total_length = ACE_WString_Helper::decode (this->buffer_ + total_length); + this->id_ = ACE_WString ((ACE_USHORT16 *) (this->buffer_ + total_length)); + break; + case ACE_URL_Locator_Request::MODIFY: + total_length += ACE_WString_Helper::decode (this->buffer_ + total_length); + this->id_ = ACE_WString ((ACE_USHORT16 *) (this->buffer_ + total_length)); + total_length += ACE_WString_Helper::decode (this->buffer_ + total_length); + this->url_ = ACE_WString ((ACE_USHORT16 *) (this->buffer_ + total_length)); + ACE_NEW_RETURN (this->seq1_, ACE_URL_Property_Seq (1), 0); + ACE_NEW_RETURN (this->seq2_, ACE_URL_Property_Seq (1), 0); + total_length += ace_array_decode (this->buffer_ + total_length, *this->seq1_); + total_length += ace_array_decode (this->buffer_ + total_length, *this->seq2_); + break; + default: + // Invalid data encountered. Stop encoding now. + return 0; + break; + } +} + + +size_t +ACE_URL_Locator_Request::bsize (void) const +{ + ACE_TRACE ("ACE_URL_Locator_Request::bsize"); + + size_t total_length = 2 * sizeof (ACE_UINT32); + + switch (this->code_) + { + case ACE_URL_Locator_Request::QUERY: + total_length += 2 * sizeof (ACE_UINT32); + total_length += ace_array_bsize (*this->seq1_); + break; + case ACE_URL_Locator_Request::EXPORT: + total_length += this->offer_->bsize (); + break; + case ACE_URL_Locator_Request::WITHDRAW: + case ACE_URL_Locator_Request::DESCRIBE: + total_length += ACE_WString_Helper::bsize (&this->id_); + break; + case ACE_URL_Locator_Request::MODIFY: + total_length += ACE_WString_Helper::bsize (&this->id_); + total_length += ACE_WString_Helper::bsize (&this->url_); + total_length += ace_array_bsize (*this->seq1_); + total_length += ace_array_bsize (*this->seq2_); + break; + default: + // Invalid data encountered. Stop encoding now. + return 0; + break; + } + return total_length; +} + +void +ACE_URL_Locator_Request::dump (void) const +{ + ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); + + + switch (this->code_) + { + case ACE_URL_Locator_Request::QUERY: + ACE_DEBUG ((LM_DEBUG, "Query Request:\nSelection: ")); + switch (this->how_) + { + case ACE_URL_Locator::NONE: + ACE_DEBUG ((LM_DEBUG, "NONE.\n")); + break; + case ACE_URL_Locator::SOME: + ACE_DEBUG ((LM_DEBUG, "SOME.\n")); + break; + case ACE_URL_Locator::ALL: + ACE_DEBUG ((LM_DEBUG, "ALL.\n")); + break; + default: + ACE_DEBUG ((LM_DEBUG, "Invalid Selection??\n")); + break; + } + ACE_DEBUG ((LM_DEBUG, "At most %d reply.\n", this->how_many_)); + this->seq1_->dump (); + break; + case ACE_URL_Locator_Request::EXPORT: + ACE_DEBUG ((LM_DEBUG, "Export Request:\n")); + break; + case ACE_URL_Locator_Request::WITHDRAW: + ACE_DEBUG ((LM_DEBUG, "Withdraw Request:\n")); + break; + case ACE_URL_Locator_Request::DESCRIBE: + ACE_DEBUG ((LM_DEBUG, "Describe Request:\n")); + break; + case ACE_URL_Locator_Request::MODIFY: + ACE_DEBUG ((LM_DEBUG, "Modify Request:\n")); + break; + default: + // Invalid data encountered. Stop encoding now. + ACE_DEBUG ((LM_DEBUG, "Invalid Request.\n")); + break; + } + + ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); +} + +#endif /* ACE_LOCATOR_REQUEST_REPLY_C */ diff --git a/apps/JAWS/clients/Caching/Locator_Request_Reply.h b/apps/JAWS/clients/Caching/Locator_Request_Reply.h index 66b694738c7..a6036fc7586 100644 --- a/apps/JAWS/clients/Caching/Locator_Request_Reply.h +++ b/apps/JAWS/clients/Caching/Locator_Request_Reply.h @@ -22,7 +22,7 @@ class ACE_Export ACE_URL_Locator_Request // = TITLE - // A URL request wrappers. + // A URL request message formater/wrapper. // // = DESCRIPTION // This class defines a URL request data. @@ -39,15 +39,21 @@ public: }; // Request type + ACE_URL_Locator_Request (void); + // Default ctor. + + ~ACE_URL_Locator_Request (void); + // Default dtor. + int url_query (const int how, - const ACE_URL_Property_Seq *pseq, + const ACE_URL_Property_Seq &pseq, const int how_many); // Query the locator for HTTP with designate properties (none, some, // or all). The locator being queried will return a sequence of // offers with <how_many> offers in it. This interface allocates // <offer> so users must deallocate it after use. - int export_offer (ACE_URL_Offer *offer); + int export_offer (const ACE_URL_Offer &offer); // Export an offer to the locator. int withdraw_offer (const ACE_WString &offer_id); @@ -58,32 +64,42 @@ public: int modify_offer (const ACE_WString &offer_id, const char *url = 0, - const ACE_URL_Property_Seq *del = 0, - const ACE_URL_Property_Seq *modify = 0); + const ACE_URL_Property_Seq &del = 0, + const ACE_URL_Property_Seq &modify = 0); // Modify a previously registered offer. int modify_offer (const ACE_WString &offer_id, const ACE_WString *url = 0, - const ACE_URL_Property_Seq *del = 0, - const ACE_URL_Property_Seq *modify = 0); + const ACE_URL_Property_Seq &del = 0, + const ACE_URL_Property_Seq &modify = 0); // Modify a previously registered offer. - int encode (void); - // Encode request for network communication. - - int decode (void); - // Restore from network data. - - int how (void); - int how_many (void); - ACE_URL_Property_Seq &seq (void); - ACE_URL_Property_Seq &del (void); - ACE_URL_Property_Seq &modify (void); - ACE_WString &id (void); - ACE_WString &url (void); - void *buffer (void); + size_t encode (void); + // Encode request for network communication. If succeed, + // returns the size of the buffer, otherwise, return 0. + + size_t decode (void *buffer); + // Restore from network data. Returns size of the buffer + // if succeed, 0 otherwise. + + const int how (void) const; + const int how_many (void) const; + const ACE_URL_Property_Seq *seq (void) const; + const ACE_URL_Property_Seq *del (void) const; + const ACE_URL_Property_Seq *modify (void) const; + const ACE_URL_Offer *offer (void) const; + const ACE_WString &id (void) const; + const ACE_WString &url (void) const; + const char *buffer (void) const; // A bunch of methods to access internal data. + + void dump (void); + // Print out this object. protected: + size_t bsize (void) const; + // Return the size of buffer required to encode + // this request. + unsigned int code_; // Request type code. @@ -95,11 +111,13 @@ protected: ACE_URL_Property_Seq *seq2_; // For modify seq. in modify_offer. + ACE_URL_Offer *offer_; + ACE_WString id_; ACE_WString url_; - void *buffer_; + char *buffer_; }; #if defined (__ACE_INLINE__) diff --git a/apps/JAWS/clients/Caching/Locator_Request_Reply.i b/apps/JAWS/clients/Caching/Locator_Request_Reply.i new file mode 100644 index 00000000000..5181649ca2c --- /dev/null +++ b/apps/JAWS/clients/Caching/Locator_Request_Reply.i @@ -0,0 +1,76 @@ +/* -*- C++ -*- */ + +// $Id$ + +ACE_INLINE +ACE_URL_Locator_Request::ACE_URL_Locator_Request (void) + : how_(INVALID_REQUEST), + seq1_ (0), + seq2_ (0), + offer_ (0), + buffer_ (0) +{ +} + +ACE_INLINE +ACE_URL_Locator_Request::~ACE_URL_Locator_Request (void) +{ + delete this->seq1_; + delete this->seq2_; + delete this->offer_; + delete [] this->buffer_; +} + +ACE_INLINE const int +ACE_URL_Locator_Request::how (void) const +{ + return this-> how_; +} + +ACE_INLINE const int +ACE_URL_Locator_Request::how_many (void) const +{ + return this->how_many_; +} + +ACE_INLINE const ACE_URL_Property_Seq * +ACE_URL_Locator_Request::seq (void) const +{ + return this->seq1_; +} + +ACE_INLINE const ACE_URL_Property_Seq * +ACE_URL_Locator_Request::del (void) const +{ + return this->seq1_; +} + +ACE_INLINE const ACE_URL_Property_Seq * +ACE_URL_Locator_Request::modify (void) const +{ + return this->seq2_; +} + +ACE_INLINE const ACE_URL_Offer * +ACE_URL_Locator_Request::offer (void) const +{ + return this->offer_; +} + +ACE_INLINE const ACE_WString & +ACE_URL_Locator_Request::id (void) const +{ + return this->id_; +} + +ACE_INLINE const ACE_WString & +ACE_URL_Locator_Request::url (void) const +{ + return this->url_; +} + +ACE_INLINE const char * +ACE_URL_Locator_Request::buffer (void) const +{ + return this->buffer_; +} diff --git a/apps/JAWS/clients/Caching/URL_Array_Helper.cpp b/apps/JAWS/clients/Caching/URL_Array_Helper.cpp new file mode 100644 index 00000000000..a2027d2b09b --- /dev/null +++ b/apps/JAWS/clients/Caching/URL_Array_Helper.cpp @@ -0,0 +1,41 @@ +// URL_Array_Helper.cpp +// $Id$ + +#if !defined (ACE_URL_ARRAY_HELPER_C) +#define ACE_URL_ARRAY_HELPER_C + +#define ACE_BUILD_DLL +#include "URL_Array_Helper.h" + +// Some helper functions for encoding/decoding + +template <class T> +size_t ace_array_bsize (const T &x) +{ + size_t sum = sizeof (ACE_UINT32); + for (size_t i = 0; i < x.size (); i++) + sum += x[i].bsize (); + return sum; +} + +template <class T> +size_t ace_array_encode (void *buf, const T &x) +{ + size_t len = 0; + for (size_t i = 0; i < x.size (); i++) + len+= x[i].encode ((void *) ((char *) buf + len)); + return len ; +} + +template <class T> +size_t ace_array_decode (void *buf, T &x) +{ + size_t len = 0; + for (size_t i = 0; i < x.size (); i++) + len += x[i].decode ((void *) ((char *) buf + len)); + return len; +} + + + +#endif /* ACE_URL_ARRAY_HELPER_C */ diff --git a/apps/JAWS/clients/Caching/URL_Array_Helper.h b/apps/JAWS/clients/Caching/URL_Array_Helper.h new file mode 100644 index 00000000000..c59627c5721 --- /dev/null +++ b/apps/JAWS/clients/Caching/URL_Array_Helper.h @@ -0,0 +1,40 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// none +// +// = FILENAME +// URL_Array_Helper.h +// +// = AUTHOR +// Nanbor Wang +// +// ============================================================================ + +#if !defined (ACE_URL_ARRAY_HELPER_H) +#define ACE_URL_ARRAY_HELPER_H + +// ### These template functions are probably named improperly. +// You should find some way to avoid name space polution. + +template <class T> +size_t ace_array_bsize (const T &x); + +template <class T> +size_t ace_array_encode (void *buf, const T &x); + +template <class T> +size_t ace_array_decode (void *buf, T &x); + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "URL_Array_Helper.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("URL_Array_Helper.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#endif /* ACE_URL_ARRAY_HELPER_H */ diff --git a/apps/JAWS/clients/Caching/URL_Locator.h b/apps/JAWS/clients/Caching/URL_Locator.h index bb1054fefe4..ffa9aa5e406 100644 --- a/apps/JAWS/clients/Caching/URL_Locator.h +++ b/apps/JAWS/clients/Caching/URL_Locator.h @@ -33,7 +33,8 @@ public: { NONE, SOME, - ALL + ALL, + INVALID_SELECTION }; // Specify how to select offers. diff --git a/apps/JAWS/clients/Caching/URL_Properties.cpp b/apps/JAWS/clients/Caching/URL_Properties.cpp index f8cbf2a7ec4..24bf9932b4a 100644 --- a/apps/JAWS/clients/Caching/URL_Properties.cpp +++ b/apps/JAWS/clients/Caching/URL_Properties.cpp @@ -13,35 +13,7 @@ #include "ace/OS.h" #include "ace/Auto_Ptr.h" - -// Some helper functions for encoding/decoding - -template <class T> -size_t ace_array_bsize (const T &x) -{ - size_t sum = sizeof (ACE_UINT32); - for (size_t i = 0; i < x.size (); i++) - sum += x[i].bsize (); - return sum; -} - -template <class T> -size_t ace_array_encode (void *buf, const T &x) -{ - size_t len = 0; - for (size_t i = 0; i < x.size (); i++) - len+= x[i].encode ((void *) ((char *) buf + len)); - return len ; -} - -template <class T> -size_t ace_array_decode (void *buf, T &x) -{ - size_t len = 0; - for (size_t i = 0; i < x.size (); i++) - len += x[i].decode ((void *) ((char *) buf + len)); - return len; -} +#include "URL_Array_Helper.h" size_t ACE_WString_Helper::encode (void *buf, ACE_WString *wstr) diff --git a/apps/JAWS/clients/Caching/URL_Properties.h b/apps/JAWS/clients/Caching/URL_Properties.h index 90ee5a835b1..94b1129e53c 100644 --- a/apps/JAWS/clients/Caching/URL_Properties.h +++ b/apps/JAWS/clients/Caching/URL_Properties.h @@ -30,7 +30,7 @@ class ACE_Export ACE_WString_Helper // ACE_WString objects for network communication. { public: - static size_t bsize (ACE_WString *wstr); + static size_t bsize (const ACE_WString *wstr); // Returns the actual size required to contain the ACE_WString. static size_t encode (void *buf, ACE_WString *wstr); diff --git a/apps/JAWS/clients/Caching/URL_Properties.i b/apps/JAWS/clients/Caching/URL_Properties.i index 37b8c190257..63722c4e6f8 100644 --- a/apps/JAWS/clients/Caching/URL_Properties.i +++ b/apps/JAWS/clients/Caching/URL_Properties.i @@ -3,7 +3,7 @@ // $Id$ ACE_INLINE size_t -ACE_WString_Helper::bsize (ACE_WString *wstr) +ACE_WString_Helper::bsize (const ACE_WString *wstr) { return (wstr->length () + 1) * sizeof (ACE_USHORT16); } |