00001 /* jabberoo.cc 00002 * Jabber client library 00003 * 00004 * Original Code Copyright (C) 1999-2001 Dave Smith (dave@jabber.org) 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 * Contributor(s): Julian Missig 00021 * 00022 * This Original Code has been modified by IBM Corporation. Modifications 00023 * made by IBM described herein are Copyright (c) International Business 00024 * Machines Corporation, 2002. 00025 * 00026 * Date Modified by Description of modification 00027 * 01/20/2002 IBM Corp. Updated to libjudo 1.1.1 00028 */ 00029 00030 00031 #include <jabberoo.hh> 00032 00033 using namespace jabberoo; 00034 00035 /* 00036 string JID::getResource(const string& jid) 00037 { // Search for resource divider 00038 string::size_type i = jid.find("/"); 00039 // If it was found, extract the resource and return it.. 00040 if (i != string::npos) 00041 return jid.substr(i+1, jid.length()-i); 00042 else 00043 return ""; 00044 } 00045 00046 string JID::getUserHost(const string& jid) 00047 { 00048 // Search for resource divider.. 00049 string::size_type i = jid.find("/"); 00050 // If it was found, extract he userhost and return.. 00051 if (i != string::npos) 00052 return jid.substr(0,i); 00053 else 00054 return jid; 00055 } 00056 00057 string JID::getHost(const string& jid) 00058 { 00059 string::size_type d1 = jid.find("@"); // Search for @ divider 00060 string::size_type d2 = jid.find("/"); // Search for / divider 00061 if ((d1 != string::npos) && (d2 != string::npos)) 00062 return jid.substr(d1+1,d2-d1-1); 00063 else if ((d1 != string::npos) && (d2 == string::npos)) 00064 return jid.substr(d1+1, jid.length()); 00065 else if ((d1 == string::npos) && (d2 != string::npos)) 00066 return jid.substr(0,d2); 00067 // else if ((d1 == string::npos) && (d2 == string::npos)) 00068 else 00069 return jid; 00070 } 00071 00072 string JID::getUser(const string& jid) 00073 { 00074 string::size_type d1 = jid.find("@"); 00075 if (d1 != string::npos) 00076 return jid.substr(0, d1); 00077 else 00078 return jid; 00079 } 00080 00081 bool JID::isValidUser(const string& user) 00082 { 00083 if ( (user.empty()) || 00084 (user.find(' ') != string::npos) || 00085 (user.find('@') != string::npos) || 00086 (user.find('/') != string::npos) || 00087 (user.find('\'') != string::npos) || 00088 (user.find('\"') != string::npos) || 00089 (user.find(':') != string::npos) 00090 // Insert other invalid chars here 00091 ) 00092 { 00093 return false; 00094 } 00095 return true; 00096 } 00097 00098 bool JID::isValidHost(const string& host) 00099 { 00100 if ( (host.empty()) || 00101 (host.find(' ') != string::npos) || 00102 (host.find('@') != string::npos) || 00103 (host.find('/') != string::npos) || 00104 (host.find('\'') != string::npos) || 00105 (host.find('\"') != string::npos) 00106 // Insert other invalid chars here 00107 ) 00108 { 00109 return false; 00110 } 00111 return true; 00112 } 00113 00114 int JID::compare(const string& ljid, const string& rjid) 00115 { 00116 // User and Host are case insensitive, Resource is case sensitive 00117 int userhost = strcasecmp(JID::getUserHost(ljid).c_str(), JID::getUserHost(rjid).c_str()); 00118 int resource = JID::getResource(ljid).compare(JID::getResource(rjid)); 00119 00120 // If the user and host of both are equal, return whether the resource is 00121 if (userhost == 0) 00122 return resource; 00123 return userhost; 00124 } 00125 00126 bool JID::Compare::operator()(const string& lhs, const string& rhs) const 00127 { 00128 return (JID::compare(lhs, rhs) < 0); 00129 } 00130 */