00001 #include "ace_pch.h"
00002
00003
00004
00005 #include "ace/SPIPE_Addr.h"
00006
00007 #if !defined (__ACE_INLINE__)
00008 #include "ace/SPIPE_Addr.i"
00009 #endif
00010
00011 ACE_RCSID(ace, SPIPE_Addr, "$Id: SPIPE_Addr.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:22 chad Exp $")
00012
00013 ACE_ALLOC_HOOK_DEFINE(ACE_SPIPE_Addr)
00014
00015 void
00016 ACE_SPIPE_Addr::dump (void) const
00017 {
00018 }
00019
00020
00021 void
00022 ACE_SPIPE_Addr::set_addr (void *addr, int len)
00023 {
00024 ACE_TRACE ("ACE_SPIPE_Addr::set_addr");
00025
00026 this->ACE_Addr::base_set (AF_SPIPE, len);
00027 ACE_OS::memcpy ((void *) &this->SPIPE_addr_,
00028 (void *) addr,
00029 len);
00030 }
00031
00032
00033
00034 ACE_SPIPE_Addr::ACE_SPIPE_Addr (void)
00035 : ACE_Addr (AF_SPIPE, sizeof this->SPIPE_addr_)
00036 {
00037 (void) ACE_OS::memset ((void *) &this->SPIPE_addr_,
00038 0,
00039 sizeof this->SPIPE_addr_);
00040 }
00041
00042
00043
00044 int
00045 ACE_SPIPE_Addr::string_to_addr (const ACE_TCHAR *addr)
00046 {
00047 return this->set (addr);
00048 }
00049
00050 int
00051 ACE_SPIPE_Addr::set (const ACE_SPIPE_Addr &sa)
00052 {
00053 this->base_set (sa.get_type (), sa.get_size ());
00054
00055 if (sa.get_type () == AF_ANY)
00056 (void) ACE_OS::memset ((void *) &this->SPIPE_addr_,
00057 0,
00058 sizeof this->SPIPE_addr_);
00059 else
00060 (void) ACE_OS::memcpy ((void *) &this->SPIPE_addr_, (void *)
00061 &sa.SPIPE_addr_,
00062 sa.get_size ());
00063 return 0;
00064 }
00065
00066
00067
00068 ACE_SPIPE_Addr::ACE_SPIPE_Addr (const ACE_SPIPE_Addr &sa)
00069 : ACE_Addr (AF_SPIPE, sizeof this->SPIPE_addr_)
00070 {
00071 this->set (sa);
00072 }
00073
00074 int
00075 ACE_SPIPE_Addr::set (const ACE_TCHAR *addr,
00076 gid_t gid,
00077 uid_t uid)
00078 {
00079 int len = sizeof (this->SPIPE_addr_.uid_);
00080 len += sizeof (this->SPIPE_addr_.gid_);
00081
00082 #if defined (ACE_WIN32)
00083 const ACE_TCHAR *colonp = ACE_OS::strchr (addr, ':');
00084 ACE_TCHAR temp[BUFSIZ];
00085
00086 if (colonp == 0)
00087 {
00088 ACE_OS::strcpy (temp, ACE_LIB_TEXT ( "\\\\.\\pipe\\"));
00089 ACE_OS::strcat (temp, addr);
00090 }
00091 else
00092 {
00093
00094 if (ACE_OS::strncmp (addr,
00095 ACE_LIB_TEXT ("localhost"),
00096 ACE_OS::strlen ("localhost")) == 0)
00097
00098 ACE_OS::strcpy (temp, ACE_LIB_TEXT ("\\\\."));
00099 else
00100 {
00101 ACE_OS::strcpy (temp, ACE_LIB_TEXT ("\\\\"));
00102
00103 ACE_TCHAR *t;
00104
00105
00106
00107 ACE_ALLOCATOR_RETURN (t, ACE_OS::strdup (addr), -1);
00108
00109 t[colonp - addr] = ACE_LIB_TEXT ('\0');
00110 ACE_OS::strcat (temp, t);
00111
00112 ACE_OS::free (t);
00113 }
00114
00115 ACE_OS::strcat (temp, ACE_LIB_TEXT ("\\pipe\\"));
00116 ACE_OS::strcat (temp, colonp + 1);
00117 }
00118 len += ACE_static_cast (int, ACE_OS_String::strlen (temp));
00119 this->ACE_Addr::base_set (AF_SPIPE, len);
00120
00121 ACE_OS_String::strcpy (this->SPIPE_addr_.rendezvous_, temp);
00122 #else
00123 this->ACE_Addr::base_set (AF_SPIPE,
00124 ACE_OS::strlen (addr) + 1 + len);
00125 ACE_OS::strsncpy (this->SPIPE_addr_.rendezvous_,
00126 addr,
00127 sizeof this->SPIPE_addr_.rendezvous_);
00128 #endif
00129 this->SPIPE_addr_.gid_ = gid == 0 ? ACE_OS::getgid () : gid;
00130 this->SPIPE_addr_.uid_ = uid == 0 ? ACE_OS::getuid () : uid;
00131 return 0;
00132 }
00133
00134
00135
00136 ACE_SPIPE_Addr::ACE_SPIPE_Addr (const ACE_TCHAR *addr,
00137 gid_t gid,
00138 uid_t uid)
00139 : ACE_Addr (AF_SPIPE, sizeof this->SPIPE_addr_)
00140 {
00141 this->set (addr, gid, uid);
00142 }
00143