00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #include <ConnInfo.h>
00013 #include "ace/OS.h"
00014 #include "ace/os_include/os_netdb.h"
00015 #include "ace/Log_Msg.h"
00016 #include "ace/INET_Addr.h"
00017 #include <ctype.h>
00018 #include <netinet/in.h>
00019
00020 using namespace std;
00021 using namespace channel;
00022
00023 void ConnInfo::parse(string conn_info) {
00024 valid_ = false;
00025 if (conn_info.length() == 0)
00026 return;
00027 size_t pos1 = conn_info.find(":");
00028 if(pos1 == string::npos) {
00029 bool found = false;
00030 for(size_t i=0; i<conn_info.length() && !found; i++)
00031 if (::isdigit(conn_info[i]) == 0) found = true;
00032 if (found)
00033 type_ = UNIX_SOCK;
00034 else
00035 type_ = INET_SOCK;
00036 } else {
00037 type_ = INET_SOCK;
00038 }
00039 if(type_ == INET_SOCK) {
00040 if(pos1 == string::npos) {
00041 ip_ = ACE_LOCALHOST;
00042 port_ = ACE_OS::atoi(conn_info.c_str());
00043 } else {
00044 ip_ = conn_info.substr(0,pos1);
00045 port_ = ACE_OS::atoi((conn_info.substr(pos1+1,string::npos)).c_str());
00046 }
00047 } else
00048 unix_addr_ = conn_info.substr(0,string::npos);
00049 if(type_ == INET_SOCK)
00050 ACE_DEBUG ((LM_DEBUG, "rmt_ip=%s, rmt_port=%d\n", ip_.c_str(), port_));
00051 else
00052 ACE_DEBUG ((LM_DEBUG, "unix_addr=%s\n", unix_addr_.c_str()));
00053 valid_ = true;
00054 }
00055
00056 void ConnInfo::dump(void) {
00057 switch(type_) {
00058 case INET_SOCK:
00059 ACE_DEBUG ((LM_DEBUG, "ip=%s ",ip_.c_str()));
00060 ACE_DEBUG ((LM_DEBUG, " port=%d\n", port_)) ;
00061 break;
00062 case UNIX_SOCK:
00063 ACE_DEBUG ((LM_DEBUG, "unix_addr=%s\n", unix_addr_.c_str())) ;
00064 break;
00065 default:
00066 ACE_DEBUG ((LM_DEBUG, "Invalid Conn type...\n"));
00067 break;
00068 }
00069 }
00070
00071 bool ConnInfo::operator== (const ConnInfo &ci) const {
00072 if(type_ != ci.type_) return false;
00073 switch(type_) {
00074 case UNIX_SOCK:
00075 return unix_addr_ == ci.unix_addr_;
00076 break;
00077 case INET_SOCK:
00078 {
00079 return ip_ != ci.ip_ ? false : port_ == ci.port_;
00080 }
00081 break;
00082 default:
00083 ACE_DEBUG ((LM_DEBUG, "invalid ConnInfo type...\n"));
00084 break;
00085 }
00086
00087 ACE_DEBUG ((LM_DEBUG, "Should not reach here in ConnInfo ....\n"));
00088 return true;
00089 }
00090
00091 bool ConnInfo::operator< (const ConnInfo &ci) const {
00092 if(type_ != ci.type_) return type_ < ci.type_;
00093 switch(type_) {
00094 case UNIX_SOCK:
00095 return unix_addr_ < ci.unix_addr_;
00096 break;
00097 case INET_SOCK:
00098 {
00099 return ip_ != ci.ip_ ? ip_ < ci.ip_ : port_ < ci.port_;
00100 }
00101 break;
00102 default:
00103 ACE_DEBUG ((LM_DEBUG, "invalid ConnInfo type...\n"));
00104 break;
00105 }
00106
00107 ACE_DEBUG ((LM_DEBUG, "Should not reach here in ConnInfo ....\n"));
00108 return true;
00109 }