SPIPE_Addr.cpp

Go to the documentation of this file.
00001 // SPIPE_Addr.cpp,v 4.23 2005/10/28 16:14:55 ossama Exp
00002 
00003 #include "ace/SPIPE_Addr.h"
00004 #include "ace/OS_NS_string.h"
00005 #include "ace/OS_NS_unistd.h"
00006 #include "ace/os_include/sys/os_socket.h"
00007 
00008 #if !defined (__ACE_INLINE__)
00009 #include "ace/SPIPE_Addr.inl"
00010 #endif /* __ACE_INLINE__ */
00011 
00012 ACE_RCSID(ace, SPIPE_Addr, "SPIPE_Addr.cpp,v 4.23 2005/10/28 16:14:55 ossama Exp")
00013 
00014 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00015 
00016 ACE_ALLOC_HOOK_DEFINE(ACE_SPIPE_Addr)
00017 
00018 void
00019 ACE_SPIPE_Addr::dump (void) const
00020 {
00021 #if defined (ACE_HAS_DUMP)
00022 #endif /* ACE_HAS_DUMP */
00023 }
00024 
00025 // Set a pointer to the address.
00026 void
00027 ACE_SPIPE_Addr::set_addr (void *addr, int len)
00028 {
00029   ACE_TRACE ("ACE_SPIPE_Addr::set_addr");
00030 
00031   this->ACE_Addr::base_set (AF_SPIPE, len);
00032   ACE_OS::memcpy ((void *) &this->SPIPE_addr_,
00033                   (void *) addr,
00034                   len);
00035 }
00036 
00037 // Return the address.
00038 
00039 void *
00040 ACE_SPIPE_Addr::get_addr (void) const
00041 {
00042   return (void *) &this->SPIPE_addr_;
00043 }
00044 
00045 
00046 // Do nothing constructor.
00047 
00048 ACE_SPIPE_Addr::ACE_SPIPE_Addr (void)
00049   : ACE_Addr (AF_SPIPE, sizeof this->SPIPE_addr_)
00050 {
00051   (void) ACE_OS::memset ((void *) &this->SPIPE_addr_,
00052                          0,
00053                          sizeof this->SPIPE_addr_);
00054 }
00055 
00056 int
00057 ACE_SPIPE_Addr::addr_to_string (ACE_TCHAR *s, size_t len) const
00058 {
00059   ACE_OS::strsncpy (s,
00060                     this->SPIPE_addr_.rendezvous_,
00061                     len);
00062   return 0;
00063 }
00064 
00065 // Transform the string into the current addressing format.
00066 
00067 int
00068 ACE_SPIPE_Addr::string_to_addr (const ACE_TCHAR *addr)
00069 {
00070   return this->set (addr);
00071 }
00072 
00073 int
00074 ACE_SPIPE_Addr::set (const ACE_SPIPE_Addr &sa)
00075 {
00076   this->base_set (sa.get_type (), sa.get_size ());
00077 
00078   if (sa.get_type () == AF_ANY)
00079     (void) ACE_OS::memset ((void *) &this->SPIPE_addr_,
00080                            0,
00081                            sizeof this->SPIPE_addr_);
00082   else
00083     (void) ACE_OS::memcpy ((void *) &this->SPIPE_addr_, (void *)
00084                            &sa.SPIPE_addr_,
00085                            sa.get_size ());
00086   return 0;
00087 }
00088 
00089 // Copy constructor.
00090 
00091 ACE_SPIPE_Addr::ACE_SPIPE_Addr (const ACE_SPIPE_Addr &sa)
00092   : ACE_Addr (AF_SPIPE, sizeof this->SPIPE_addr_)
00093 {
00094   this->set (sa);
00095 }
00096 
00097 int
00098 ACE_SPIPE_Addr::set (const ACE_TCHAR *addr,
00099                      gid_t gid,
00100                      uid_t uid)
00101 {
00102   int len = sizeof (this->SPIPE_addr_.uid_);
00103   len += sizeof (this->SPIPE_addr_.gid_);
00104 
00105 #if defined (ACE_WIN32)
00106   const ACE_TCHAR *colonp = ACE_OS::strchr (addr, ':');
00107   ACE_TCHAR temp[BUFSIZ];
00108 
00109   if (colonp == 0) // Assume it's a local name.
00110     {
00111       ACE_OS::strcpy (temp, ACE_LIB_TEXT ( "\\\\.\\pipe\\"));
00112       ACE_OS::strcat (temp, addr);
00113     }
00114   else
00115     {
00116 
00117       if (ACE_OS::strncmp (addr,
00118                            ACE_LIB_TEXT ("localhost"),
00119                            ACE_OS::strlen ("localhost")) == 0)
00120         // change "localhost" to "."
00121         ACE_OS::strcpy (temp, ACE_LIB_TEXT ("\\\\."));
00122       else
00123         {
00124           ACE_OS::strcpy (temp, ACE_LIB_TEXT ("\\\\"));
00125 
00126           ACE_TCHAR *t;
00127 
00128           // We need to allocate a duplicate so that we can write a
00129           // NUL character into it.
00130           ACE_ALLOCATOR_RETURN (t, ACE_OS::strdup (addr), -1);
00131 
00132           t[colonp - addr] = ACE_LIB_TEXT ('\0');
00133           ACE_OS::strcat (temp, t);
00134 
00135           ACE_OS::free (t);
00136         }
00137 
00138       ACE_OS::strcat (temp, ACE_LIB_TEXT ("\\pipe\\"));
00139       ACE_OS::strcat (temp, colonp + 1);
00140     }
00141   len += static_cast<int> (ACE_OS::strlen (temp));
00142   this->ACE_Addr::base_set (AF_SPIPE, len);
00143 
00144   ACE_OS::strcpy (this->SPIPE_addr_.rendezvous_, temp);
00145 #else
00146   this->ACE_Addr::base_set (AF_SPIPE,
00147                             ACE_OS::strlen (addr) + 1 + len);
00148   ACE_OS::strsncpy (this->SPIPE_addr_.rendezvous_,
00149                     addr,
00150                     sizeof this->SPIPE_addr_.rendezvous_);
00151 #endif /* ACE_WIN32 */
00152   this->SPIPE_addr_.gid_ = gid == 0 ? ACE_OS::getgid () : gid;
00153   this->SPIPE_addr_.uid_ = uid == 0 ? ACE_OS::getuid () : uid;
00154   return 0;
00155 }
00156 
00157 // Create a ACE_Addr from a ACE_SPIPE pathname.
00158 
00159 ACE_SPIPE_Addr::ACE_SPIPE_Addr (const ACE_TCHAR *addr,
00160                                 gid_t gid,
00161                                 uid_t uid)
00162   : ACE_Addr (AF_SPIPE, sizeof this->SPIPE_addr_)
00163 {
00164   this->set (addr, gid, uid);
00165 }
00166 
00167 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:42:04 2006 for ACE by doxygen 1.3.6