00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <JID.hh>
00032
00033 namespace jabberoo {
00034
00035 std::string JID::getResource(const std::string& jid)
00036 {
00037 std::string::size_type i = jid.find("/");
00038
00039 if (i != std::string::npos)
00040 return jid.substr(i+1, jid.length()-i);
00041 else
00042 return "";
00043 }
00044
00045 std::string JID::getUserHost(const std::string& jid)
00046 {
00047
00048 std::string::size_type i = jid.find("/");
00049
00050 if (i != std::string::npos)
00051 return jid.substr(0,i);
00052 else
00053 return jid;
00054 }
00055
00056 std::string JID::getHost(const std::string& jid)
00057 {
00058 std::string::size_type d1 = jid.find("@");
00059 std::string::size_type d2 = jid.find("/");
00060 if ((d1 != std::string::npos) && (d2 != std::string::npos))
00061 return jid.substr(d1+1,d2-d1-1);
00062 else if ((d1 != std::string::npos) && (d2 == std::string::npos))
00063 return jid.substr(d1+1, jid.length());
00064 else if ((d1 == std::string::npos) && (d2 != std::string::npos))
00065 return jid.substr(0,d2);
00066
00067 else
00068 return jid;
00069 }
00070
00071 std::string JID::getUser(const std::string& jid)
00072 {
00073 std::string::size_type d1 = jid.find("@");
00074 if (d1 != std::string::npos)
00075 return jid.substr(0, d1);
00076 else
00077 return jid;
00078 }
00079
00080 bool JID::isValidUser(const std::string& user)
00081 {
00082 if ( (user.empty()) ||
00083 (user.find(' ') != std::string::npos) ||
00084 (user.find('@') != std::string::npos) ||
00085 (user.find('/') != std::string::npos) ||
00086 (user.find('\'') != std::string::npos) ||
00087 (user.find('\"') != std::string::npos) ||
00088 (user.find(':') != std::string::npos)
00089
00090 )
00091 {
00092 return false;
00093 }
00094 return true;
00095 }
00096
00097 bool JID::isValidHost(const std::string& host)
00098 {
00099 if ( (host.empty()) ||
00100 (host.find(' ') != std::string::npos) ||
00101 (host.find('@') != std::string::npos) ||
00102 (host.find('/') != std::string::npos) ||
00103 (host.find('\'') != std::string::npos) ||
00104 (host.find('\"') != std::string::npos)
00105
00106 )
00107 {
00108 return false;
00109 }
00110 return true;
00111 }
00112
00113 int JID::compare(const std::string& ljid, const std::string& rjid)
00114 {
00115
00116 int userhost = _stricmp(JID::getUserHost(ljid).c_str(), JID::getUserHost(rjid).c_str());
00117 int resource = JID::getResource(ljid).compare(JID::getResource(rjid));
00118
00119
00120 if (userhost == 0)
00121 return resource;
00122 return userhost;
00123 }
00124
00125 bool JID::Compare::operator()(const std::string& lhs, const std::string& rhs) const
00126 {
00127 return (JID::compare(lhs, rhs) < 0);
00128 }
00129
00130 }