GNUMessenger::XMLManager Class Reference

The XMLManager class controls all of the disk-based XML configuration loading and unloading. More...

#include <xml_manager.h>

Collaboration diagram for GNUMessenger::XMLManager:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 XMLManager (const string &directory="")
 ~XMLManager ()
 Destructor.
bool createNew (const string &username, const VBuffer &password)
 Creates new XML config file on disk for specified user and logs that user into the system.
bool login (const string &username, const VBuffer &password)
 Tries to log the specified user in.
bool logout ()
 Saves and closes the configuration for a user.
string getFileName (const string &username) const
 Return the encoded file name for given user name.
bool commit ()
 Writes configuration to disk.
bool setPassword (const VBuffer &password)
 Sets active password for loged-in user.
string getLogin () const
 Returns loged-in username.
bool isOK ()
 Returns wether someone is logged in or not.
string encode (const string &inbound)
 Replace HTML formated unfriendly sequences with original sequence.
string decode (const string &inbound)
 Replace HTML/XML unfriendlies with HTML codes.
XMLNodereturnXML ()
ContactManagercontacts ()
SettingsManagersettings ()

Static Public Member Functions

bool setDirectory (const string &dir)
 Sets the directory that configs are stored in.
const string & getDirectory ()
 Returns the current directory used to store configurations.
bool search (const string &dataToFind, const string &tagName, XMLNode &parentNode, XMLNode &returnNode)
 Static XML searching algo, assigns a node by reference as return.
bool baseSearch (const string &dataToFind, const string &tagName, XMLNode &parentNode, XMLNode &realParent, unsigned int &num)
 Same as regular search but the parent of the search term is returned.
unsigned int tagCount (const string &findType, const XMLNode &parentNode)
 Counts all tags of certain type in a XML node, recursive underbelly.
void getAllTags (const string &findType, XMLNode &parentNode, vector< XMLNode > &result_vector)
 Returns a vector of all tags.
string printTree (const XMLNode &base)
 Returns a string of the XML tree in text form.
bool exists (const string &username)
 Checks to see if a given user has a configuration.
bool isDirectory (const string &dirname)

Detailed Description

The XMLManager class controls all of the disk-based XML configuration loading and unloading.

The XML Manager also controls authentication of users and encryption/decryption of disk-based settings.

Author:
Jesse Lovelace

Definition at line 41 of file xml_manager.h.


Member Function Documentation

bool GNUMessenger::XMLManager::commit  ) 
 

Writes configuration to disk.

Returns:
False if no-one is online
Exceptions:
DiskError if a file IO error occured
Definition at line 261 of file xml_manager.cpp.

Referenced by createNew(), logout(), and setPassword().

00262 { 00263 // if user is not logged in, then cannot commit to disk 00264 if (!m_isOnline) 00265 { 00266 LOG_ERROR("Cannot Commit to file while not logged in."); 00267 return false; 00268 } 00269 00270 // add xml encoding information for expat 00271 string data("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 00272 00273 // convert xmlnode to a string 00274 data += string(m_xml); 00275 00276 // try to encrypt to disk 00277 try 00278 { 00279 CryptoManager::encryptFile(m_directory + m_filename, m_diskPass, data.c_str()); 00280 } 00281 catch (CryptoManager::IOError &e) 00282 { 00283 LOG_THROW(e.what(), DiskError); 00284 return false; 00285 } 00286 00287 //#ifdef _DEBUG 00288 // write out debug xml 00289 ofstream out; 00290 string dir = m_directory + string("test.xml"); 00291 out.open(dir.c_str()); 00292 out << data; 00293 //#endif 00294 00295 return true; 00296 }

bool GNUMessenger::XMLManager::createNew const string &  username,
const VBuffer password
 

Creates new XML config file on disk for specified user and logs that user into the system.

Note:
The configuration is saved initially
Definition at line 98 of file xml_manager.cpp.

References commit(), exists(), getFileName(), logout(), GNUMessenger::XMLNode::setName(), and GNUMessenger::XMLNode::setProperty().

00099 { 00100 // if username exists, return false 00101 if (exists(username)) 00102 return false; 00103 00104 if (m_isOnline) 00105 logout(); 00106 00107 // create a new file to hold user data 00108 m_filename = getFileName(username); 00109 00110 // hash the user's password to use as file key 00111 m_diskPass = CryptoManager::hash(password, CryptDefines::SHA_384); 00112 00113 // set up initial values in the xml node 00114 m_xml.setName("config").setProperty("username", username); 00115 00116 m_settingsManager.reset(new SettingsManager(m_xml)); 00117 m_contactManager.reset(new ContactManager(m_xml)); 00118 00119 // set status to online - user logged in 00120 m_isOnline = true; 00121 00122 // do initial save to disk 00123 commit(); 00124 00125 return true; 00126 00127 }

Here is the call graph for this function:

bool GNUMessenger::XMLManager::exists const string &  username  )  [static]
 

Checks to see if a given user has a configuration.

Returns:
True if the user has an account file
Note:
This is directory specific
Definition at line 371 of file xml_manager.cpp.

Referenced by createNew(), and login().

00372 { 00373 string toOpen; 00374 toOpen += m_directory; 00375 toOpen += CryptoManager::encode(username, CryptDefines::Base32); // file name 00376 toOpen += ".gm"; 00377 00378 struct stat my_stat; 00379 return (stat(toOpen.c_str(), &my_stat) == 0); 00380 00381 #if 0 00382 ifstream in; 00383 in.open(toOpen.c_str()); 00384 00385 if (in.fail() || in.bad()) 00386 { 00387 return false; 00388 } 00389 return true; 00390 #endif 00391 }

bool GNUMessenger::XMLManager::login const string &  username,
const VBuffer password
 

Tries to log the specified user in.

Note:
This function logs the current user out if any
Returns:
False if user does not exist
Exceptions:
InvalidPassword if specified password was invalid
AuthFailed if data integrity could not be verified
DiskError if a file IO error occured
Definition at line 129 of file xml_manager.cpp.

References exists(), getFileName(), and logout().

00130 { 00131 // returns false if user does not exist 00132 if (!exists(username)) 00133 return false; 00134 00135 if (m_isOnline) 00136 logout(); 00137 00138 m_filename = getFileName(username); 00139 00140 m_diskPass = CryptoManager::hash(password, CryptDefines::SHA_384); 00141 00142 #if 0 00143 // plain text read in of config for testing 00144 ifstream in; 00145 string tmp, inbound; 00146 in.open("test.xml"); 00147 while (getline(in, tmp)) 00148 inbound += tmp; 00149 00150 *m_config << inbound; 00151 #endif 00152 00153 try { 00154 00155 m_xml << CryptoManager::decryptFile(m_directory + m_filename, m_diskPass); 00156 } catch(CryptoManager::InvalidPassword &e) 00157 { 00158 LOG_THROW(e.what(), PasswordError); 00159 } catch(CryptoManager::AuthFailed &e) 00160 { 00161 LOG_THROW(e.what(), AuthError); 00162 } catch(CryptoManager::IOError &e) 00163 { 00164 LOG_THROW(e.what(), DiskError); 00165 } 00166 00167 m_settingsManager.reset(new SettingsManager(m_xml)); 00168 m_contactManager.reset(new ContactManager(m_xml)); 00169 00170 m_isOnline = true; 00171 00172 return true; 00173 00174 }

Here is the call graph for this function:

bool GNUMessenger::XMLManager::logout  ) 
 

Saves and closes the configuration for a user.

Returns:
False if no-one is currently logged in
Definition at line 50 of file xml_manager.cpp.

References commit(), and GNUMessenger::VBuffer::wipe().

Referenced by createNew(), and login().

00051 { 00052 if (!m_isOnline) 00053 return false; 00054 00055 // save data 00056 commit(); 00057 00058 // set status to offline 00059 m_isOnline = false; 00060 00061 // set the config to a empty xml 00062 XMLNode empty; 00063 m_xml = empty; 00064 00065 // resize the disk password to zero length 00066 m_diskPass.wipe(); 00067 00068 // erase old file name 00069 m_filename.clear(); 00070 00071 return true; 00072 00073 }

Here is the call graph for this function:

bool GNUMessenger::XMLManager::setDirectory const string &  dir  )  [static]
 

Sets the directory that configs are stored in.

Returns:
False if the directory does not exist, the value before the call is not altered.
Definition at line 75 of file xml_manager.cpp.
00076 { 00077 if (dir.empty()) { 00078 LOG_DEBUG("Dir is empty."); 00079 m_directory.clear(); 00080 return true; 00081 } 00082 00083 if (!isDirectory(dir)) { 00084 LOG_DEBUG("Dir is not a directory."); 00085 return false; 00086 } 00087 00088 m_directory = dir; 00089 00090 if ( (dir[dir.length() - 1] != '\\') && 00091 (dir[dir.length() -1] != '/')) { 00092 m_directory += '/'; 00093 } 00094 00095 return true; 00096 }


The documentation for this class was generated from the following files:
Generated on Tue Oct 5 14:41:59 2004 for GNU Messenger by doxygen 1.3.8