////////////////////////////////////////////////////////////////////////// //check whether user that request to log in from client side is in the repository //if so return Login type message //else return warning. Message MessageHandler::LoginMessage() { strVal path = _repositoryPath+"Users.xml"; XmlDoc doc; if (!doc.LoadXmlFile(path)) return WarningMessage("Users file broken, please contact administrator."); strVal name = GetMessageName(); strVal tag = "User"; strVal content; xmlRep rep; vector<XmlDoc> users = doc.Children(tag); for (size_t i=0; i<users.size(); ++i) { strVal userName = users[i].Children("Name")[0].InnerText(); if (userName == name) { _loginUsers[_curIP] = name; return _msg; } } return WarningMessage("User is not in the repository."); }
////////////////////////////////////////////////////////////////////////// //Extract InnerText of Name tag in message strVal MessageHandler::GetMessageName() { strVal tag = "Name"; XmlDoc doc = _msg.Doc(); vector<XmlDoc> names = doc.Children(tag); if (names.size() <=0)return ""; strVal name = names[0].InnerText(); return names[0].InnerText(); }
////////////////////////////////////////////////////////////////////////// //generate a package type message Message MessageHandler::PackageMessage() { const strVal name = GetMessageName(); strVal path = _repositoryPath+_metaFolder+name+".xml"; XmlDoc doc; strVal prefix = "\n "; if (!doc.LoadXmlFile(path)) return WarningMessage(name+": the package is not in the repository."); vector<XmlDoc> refs ; strVal packInfo; if((refs=doc.Children("head")).size()>0) packInfo+=prefix+refs[0].InnerText(); if((refs=doc.Children("implement")).size()>0) packInfo+=prefix+refs[0].InnerText(); if (packInfo.size()>0) packInfo = "Package files: " + packInfo; else return WarningMessage("Package metadata file broken, please administrator."); strVal dependency="\n \nDependencies: "; if ((refs=doc.Children("references")).size()>0) if ((refs=refs[0].Children("reference")).size()>0) for(size_t i=0; i<refs.size(); ++i) dependency+=prefix+refs[i].InnerText(); strVal owner="\n \nPackage Owner: "; if ((refs=doc.Children("owner")).size()>0) owner+=prefix+refs[0].InnerText(); xmlRep rep(xmlElem("Name",packInfo+dependency+owner)); rep.makeParent(MsgType::EnumToString(MsgType::Package)); return Message(rep.xmlStr()); }
////////////////////////////////////////////////////////////////////////// //check whether uploaded file is not in repository //or user own the file bool MessageHandler::OKtoCheckin(strVal fileName) { fileName = GetKeyName(fileName)+".xml"; XmlDoc doc; //package not in the repository, ok to check in if (!doc.LoadXmlFile(_repositoryPath+_metaFolder+fileName)) if (!doc.LoadXmlFile(_repositoryPath+_checkinFoler+fileName)) return true; vector<XmlDoc> elems = doc.Children("owner"); if (elems.size()<=0)return false; //check in depend on whether user is package owner strVal owner = elems[0].InnerText(); return owner == _curUser; }
////////////////////////////////////////////////////////////////////////// //generate a Dependency type message Message MessageHandler::DependencyMessage() { const strVal name = GetMessageName(); if (name == "*.*")return AllPackageMessage(); strVal path = _repositoryPath+_metaFolder+name+".xml"; strVal tag = "references"; strVal content; XmlDoc doc; xmlRep rep; if (!doc.LoadXmlFile(path)) return WarningMessage(name+": the package is not in the repository."); vector<XmlDoc> refs = doc.Children(tag); if (refs.size()<=0) return WarningMessage(name+": the package does not depend on other package."); //find all dependency children under dependency tag refs = refs[0].Children(); if (refs.size()<=0) return WarningMessage(name+": the package does not depend on other package."); tag = "Name"; for (size_t i=0; i<refs.size(); ++i) { content = refs[i].InnerText(); content = GetKeyName(content); xmlElem elem(tag,content); rep.addSibling(elem); } tag = MsgType::EnumToString(MsgType::Dependency); rep.makeParent(tag); return Message(rep.xmlStr()); }