bool WsDirNode::isAllowed(const set<string>& gids) { WsGlobalProperties* props = WsGlobalProperties::instance(); if (props->get("global", "public_site", "false") == "true") { /* Public site access granted */ return true; } //lock the parent because we are using it to avoid free NodePtr parent = m_parent.lock(); if ((m_properties.get() == 0 || m_properties.get()->getGroups().size() == 0) && parent.get() != 0) { /* Check if inherit from parent is set to true in Global configuration */ if (props->get("global", "inherit_rights_from_parent", "false") == "true") { /* Set to true, so Get right from parent */ return parent.get()->isAllowed(gids); /* Check if inherit from parent set to true in Node conf */ } else if (m_properties.get()->get("global", "inherit_rights_from_parent", "false") == "true") { if (!parent.get() == 0) { /* get right from parent if not null */ return parent.get()->isAllowed(gids); } else return false; } else return false; } else { /* We need the rights from the current node */ return m_properties.get()->isAllowed(gids); } }
vector<WsResultItem> WsMnoGoSearch::getResults(const set<string>& groups) { string path; vector<WsResultItem> filteredResults; list<WsResultItem>::iterator it; NodePtr n; LOG(DEBUG) << "WsMnoGoSearch::getResults() : Total found results before filter " << m_results.size(); for (it = m_results.begin(); it != m_results.end(); ++it) { /* remove file://tmp/directories from path*/ path = (*it).getPath().string(); /* Get the node associated with the result */ n = m_fst->eatPath(path); if (n.get() != 0) { /* If it's a directory, skip it */ if ( n.get()->isDirectory() ) continue; /* Check if user if allowed to access this node */ if (n.get()->isAllowed(groups)) { string newPath = (*it).getFullPath().string(); std::time_t t = boost::filesystem::last_write_time(newPath); (*it).setModifyDate(t); (*it).setSize(boost::filesystem::file_size(newPath)); filteredResults.push_back(*it); } } else LOG(ERROR) << "WsMnoGoSearch::getResults() : Error finding node " << path << endl; } LOG(DEBUG) << "WsMnoGoSearch :: Total found results after filter " << m_results.size(); return filteredResults; }
void WsMenu::loadMenu(NodePtr pNodeParent, WMenu* menuParent) { std::vector<NodePtr> dirNode = pNodeParent.get()->getAll(); for (std::vector<NodePtr>::iterator it = dirNode.begin(); it != dirNode.end(); ++it) { NodePtr curNode = *it; if (curNode.get()->getDisplayInMenu()) createMenu(curNode, menuParent); } }
void LazyGraph::removeNode(NodeId id) { NodePtr n = getNode(id); nodeCache->changedResources.erase(n.get()); map<NodeId, long int>::iterator k = nodeOffsets.find(id); if (k != nodeOffsets.end()) { nodeOffsets.erase(k); } //n->owner = NULL; nodeCache->changedResources.erase(n.get()); }
NodeVector Parser::parse() { std::vector<Token> tokens = tokenize(); std::deque<NodePtr> stack; stack.push_back(std::make_shared<Node>(CMD, "ROOT")); NodePtr lastCompleted = nullptr; while (tokens.size() && stack.size()) { NodePtr node; Token tok = tokens.front(); tokens.erase(tokens.begin()); if (tok.type == TokType::RAW) { node = std::make_shared<Node>(TEXT, tok.str); stack.back()->addChild(node); } else if (tok.type == TokType::CMD_BEG) { node = std::make_shared<Node>(CMD, tok.str); stack.push_back(node); } else if (tok.type == TokType::CMD_CNT) { node = std::make_shared<TmpNode>(TMP, ""); ((TmpNode*)node.get())->setParent(lastCompleted); stack.push_back(node); } else if (tok.type == TokType::CMD_END) { node = stack.back(); stack.pop_back(); if (!stack.size()) throw std::runtime_error("Too many CMD_ENDs"); if (node->getType() == TMP) { if (!lastCompleted) throw std::runtime_error("Noone to absorb children"); NodePtr parent = ((TmpNode*)node.get())->getParent(); parent->absorb(node->getChildren(), 1); } else { if (node->getType() == CMD) lastCompleted = node; stack.back()->addChild(node); } } } if (tokens.size()) throw std::runtime_error("Unconsomed tokens"); if (stack.size() != 1) throw std::runtime_error("Invalid format - !1 stack elems"); NodeVector vec = stack.front()->getChildren(0); return vec; }
void LinkedNode::Attache(LinkedNode* father_node,u32 transformcode) { if (father_) { //ret == this //use ret to keep this pointer not to be deleted NodePtr ret = father_->RemoveChild(name_); Assert(ret.get()==this); father_node->InsertChild(ret.get()); } else father_node->InsertChild(this); transform_code_ = transformcode; }
bool LocalNode::_connect( NodePtr node, ConnectionPtr connection ) { EQASSERT( connection.isValid( )); EQASSERT( node->getNodeID() != getNodeID( )); if( !node.isValid() || _state != STATE_LISTENING || !connection->isConnected() || node->_state != STATE_CLOSED ) { return false; } _addConnection( connection ); // send connect packet to peer NodeConnectPacket packet; packet.requestID = registerRequest( node.get( )); packet.nodeID = _id; packet.nodeType = getType(); connection->send( packet, serialize( )); bool connected = false; if( !waitRequest( packet.requestID, connected, 10000 /*ms*/ )) { EQWARN << "Node connection handshake timeout - peer not a Collage node?" << std::endl; return false; } if( !connected ) return false; EQASSERT( node->_id != NodeID::ZERO ); EQASSERTINFO( node->_id != _id, _id ); EQINFO << node << " connected to " << *(Node*)this << std::endl; return true; }
void dumpBT(std::ostream& out, NodePtr<BacktraceFrame> frame) { if (frame == nullptr) return; auto value = frame->get(); out << " " << std::get<1>(value) << "(" << std::get<0>(value) << ")"; dumpBT(out, popNode(frame)); }
void WsContent::doEditPage(std::string path) { std::string newPath = path; boost::algorithm::replace_first(newPath, "/Edit", ""); boost::algorithm::replace_first(newPath, "/SiteMap", ""); std::string sPathWithoutPrefix = WsApp->WsModules().pathWithoutPrefix(newPath); // ex. /SiteMap std::string sysPath(m_sDocumentRoot + sPathWithoutPrefix); WsUser* pUser = WsApp->wsUser(); NodePtr pNode = pUser->getAccessRoot()->eatPath(sPathWithoutPrefix); if (!pNode.get() ) { addWidget(new WsErrorPage(WsErrorPage::Error, path, pUser, "Returned node is null")); return; } clear(); setOverflow(WContainerWidget::OverflowAuto); WVBoxLayout* vbox = new WVBoxLayout(); setLayout(vbox); WsFormConfig* m_formConfig = new WsFormConfig(pNode, WsApp->WsModules()); vbox->addWidget(m_formConfig, 0); vbox->addWidget(WsApp->WsModules().module("WsModEditorUploader")->createContents()); std::string strExt(boost::filesystem::extension(sPathWithoutPrefix)); if ( strExt == ".fhtml" ) { if ( !gdcore_isPathFile(sysPath) ) return; gdFHtmlEditor* pEditor = new gdFHtmlEditor("", false); pEditor->setCurrentPath(sysPath); pEditor->readFile(); m_formConfig->setEditorFhtml(pEditor); pEditor->resize(WLength(100, WLength::Percentage), WLength(400)); vbox->addWidget(pEditor, 1); } }
NodeImpl *TreeWalkerImpl::previousNode( void*& filterException ) { NodePtr n = getPreviousNode(filterException); if( n ) m_currentNode = n; return n.get(); }
NodeImpl *TreeWalkerImpl::nextSibling( void*& filterException ) { NodePtr n = getNextSibling( m_currentNode, filterException ); if( n ) m_currentNode = n; return n.get(); }
NodeImpl *TreeWalkerImpl::lastChild( void*& filterException ) { NodePtr n = getLastChild(m_currentNode, filterException); if( n ) m_currentNode = n; return n.get(); }
NodeImpl *TreeWalkerImpl::parentNode( void*& filterException ) { NodePtr n = getParentNode( m_currentNode, filterException ); if ( n ) m_currentNode = n; return n.get(); }
NodePtr LazyGraph::newNode(const vec2d &p) { NodeId id = nextNodeId; nextNodeId.id++; NodePtr n = new LazyNode(this, id, p.x, p.y); if (mapping != NULL) { mapping->insert(make_pair(p, n.get())); } nodes.insert(make_pair(id, n.get())); if (nodeOffsets.find(id) == nodeOffsets.end()) { nodeOffsets.insert(make_pair(id, (long int) - 1)); } nodeCache->add(n.get(), true); return n; }
int WsTreeDeserializer::addSub(const Value& v, NodePtr n) { /* Iterate on nodes of current level in Json file and add it as children of node n */ for (ValueIterator itr = v.begin() ; itr != v.end() ; ++itr) { Value v1 = *itr; path p(itr.key().asString()); if (v1["type"].asString() == "DIRECTORY") { /* Create node */ NodePtr temp = NodePtr(new WsDirNode(p, m_rootPath)); n.get()->addChildDirectory(temp); /* Set its properties */ temp.get()->setProperties(NodePropertiesPtr(new WsNodeProperties(v1["properties"].toStyledString()))); temp.get()->setModifyDate(v1["modifdate"].asDouble()); temp.get()->setCreateDate(v1["creatdate"].asDouble()); /* No children */ if (v1["children"] == Value::null) { continue; } /* Add children because current node is directory*/ addSub(v1["children"], temp); } else { /* current node is file, add only children to parent (n) */ NodePtr temp = NodePtr(new WsFileNode(p, m_rootPath)); n.get()->addChildFile(temp); temp.get()->setProperties(NodePropertiesPtr(new WsNodeProperties(v1["properties"].toStyledString()))); temp.get()->setModifyDate(v1["modifdate"].asDouble()); temp.get()->setCreateDate(v1["creatdate"].asDouble()); temp.get()->setSize(v1["size"].asDouble()); } } return ErrorCode::Success; }
void WsMenu::doLoadCurPath() { std::string rootPath = asString(option("rootPath")).toUTF8(); boost::algorithm::replace_all(rootPath, "&", "&"); // Si pas de root path on prend l'internal Path if ( rootPath.size() < 1 ){ m_sCurPath = WsApp->internalPath(); }else m_sCurPath = rootPath; std::string sWithoutPrefix = WsApp->WsModules().pathWithoutPrefix(m_sCurPath); WsUser* pUser = WsApp->wsUser(); NodePtr tmpNode = pUser->getAccessRoot().get()->eatPath(sWithoutPrefix); if ( !tmpNode.get() ) { wApp->log("notice") << "WsMenu::doLoadCurPath - eatPath return NULL "; return; } if ( tmpNode.get()->isRegularFile() ) { tmpNode = pUser->getAccessRoot().get()->eatPath(boost::filesystem::path(sWithoutPrefix).parent_path().string()); if ( !tmpNode.get() ) { wApp->log("notice") << "WsMenu::doLoadCurPath - eatPath on parent return NULL "; return; } } NodePtr startNode = pUser->getAccessRoot(); if ( !startNode.get() ) { wApp->log("notice") << "WsMenu::doLoadCurPath - startNode = " << startNode; return; } NodePtr pNode = startNode.get()->eatPath(tmpNode.get()->getPath().string()); if ( !pNode.get() ) return; if ( asString(option("useTitle")) == "true" ) { std::string sTitle(pNode.get()->getDisplayName()); boost::algorithm::replace_all(sTitle, "&", "&"); WText* title = new WText(sTitle); title->addStyleClass("WsMenuTitle"); addWidget(title); } WMenu* menuParent = 0; if ( asString(option("useButtons")) != "true" ) menuParent = new WMenu(this); if ( asString(option("showRoot")) == "true" ) if ( pNode.get()->getPath() == "/" ) { createMenu(pNode, menuParent); } loadMenu(pNode, menuParent); if ( asString(option("useImages")) == "true" ) loadImage(pNode); }
void importExportDeclVisitor(const NodePtr& parent, const NodePtr& node, PackagePtr& pkg) { //we care only about toplevel decl if (parent) return; switch (node->type()) { // EXPORT case NodeType_InterfaceDecl: { InterfaceDeclNode* tnode = static_cast<InterfaceDeclNode*>(node.get()); pkg->addMember(tnode->name, node); return; } case NodeType_StructDecl: { StructDeclNode* tnode = static_cast<StructDeclNode*>(node.get()); pkg->addMember(tnode->name, node); return; } case NodeType_FnDecl: { FnDeclNode* tnode = static_cast<FnDeclNode*>(node.get()); pkg->addMember(tnode->name, node); return; } case NodeType_ConstDecl: { ConstDeclNode* tnode = static_cast<ConstDeclNode*>(node.get()); pkg->addMember(tnode->name, node); return; } case NodeType_ObjectDef: { ObjectDefNode* tnode = static_cast<ObjectDefNode*>(node.get()); pkg->addMember(tnode->name, node); return; } case NodeType_TypeDefDecl: { TypeDefDeclNode* tnode = static_cast<TypeDefDeclNode*>(node.get()); pkg->addMember(tnode->name, node); return; } case NodeType_EnumDecl: { EnumDeclNode* tnode = static_cast<EnumDeclNode*>(node.get()); pkg->addMember(tnode->name, node); return; } // IMPORT case NodeType_Import: { ImportNode* tnode = static_cast<ImportNode*>(node.get()); pkg->addImport(tnode->name, node); return; } default: { return; } } }
void LazyGraph::movePoint(CurvePtr c, int i, const vec2d &p) { if (i == 0 || i == c->getSize() - 1) { NodePtr n = i == 0 ? c->getStart() : c->getEnd(); nodeCache->add(n.get(), true); } else { curveCache->add(c.get(), true); } Graph::movePoint(c, i, p); }
std::string extractPackageName(const NodePtr& node) { switch(node->type()) { case NodeType_Package: { PackageNode* tnode = static_cast<PackageNode*>(node.get()); return tnode->name; } default: throw std::runtime_error("node is not a package"); }; }
bool LocalNode::_cmdGetNodeDataReply( Command& command ) { EQASSERT( _inReceiverThread( )); const NodeGetNodeDataReplyPacket* packet = command.get< NodeGetNodeDataReplyPacket >(); EQVERB << "cmd get node data reply: " << packet << std::endl; const uint32_t requestID = packet->requestID; const NodeID& nodeID = packet->nodeID; // No locking needed, only recv thread writes NodeHash::const_iterator i = _nodes->find( nodeID ); if( i != _nodes->end( )) { // Requested node connected to us in the meantime NodePtr node = i->second; node->ref( CO_REFERENCED_PARAM ); serveRequest( requestID, node.get( )); return true; } if( packet->nodeType == NODETYPE_CO_INVALID ) { serveRequest( requestID, (void*)0 ); return true; } // new node: create and add unconnected node NodePtr node = createNode( packet->nodeType ); EQASSERT( node.isValid( )); std::string data = packet->nodeData; if( !node->deserialize( data )) EQWARN << "Failed to initialize node data" << std::endl; EQASSERT( data.empty( )); node->ref( CO_REFERENCED_PARAM ); serveRequest( requestID, node.get( )); return true; }
StatCache::NodePtr StatCache::getNode(const std::string& path, bool follow) { #ifdef __linux__ int wd = inotify_add_watch(m_ifd, path.c_str(), 0 | IN_MODIFY | IN_ATTRIB | IN_MOVED_FROM | IN_MOVED_TO | IN_CREATE | IN_DELETE | (follow ? 0 : IN_DONT_FOLLOW) | IN_ONLYDIR); if (wd == -1 && errno != ENOTDIR) { TRACE(2, "StatCache: getNode('%s', follow=%s) failed\n", path.c_str(), follow ? "true" : "false"); return NodePtr(nullptr); } NodePtr node; if (wd != -1) { node = folly::get_default(m_watch2Node, wd); if (!node.get()) { node = new Node(*this, wd); if (!m_watch2Node.insert(std::make_pair(wd, node)).second) { assertx(0); // should not already exist in the map } TRACE(2, "StatCache: getNode('%s', follow=%s) --> %p (wd=%d)\n", path.c_str(), follow ? "true" : "false", node.get(), wd); } else { TRACE(3, "StatCache: getNode('%s', follow=%s) --> alias %p (wd=%d)\n", path.c_str(), follow ? "true" : "false", node.get(), wd); } } else { node = new Node(*this); TRACE(3, "StatCache: getNode('%s', follow=%s) --> %p\n", path.c_str(), follow ? "true" : "false", node.get()); } node->setPath(path); return node; #else return NodePtr(nullptr); #endif }
Vehicle *VehicleManager::CreateVehicleFromNode(osg::Node *node, const RGBf &cColor) { // Deep copy NodePtr pNewModel = (osg::Node *) node->clone(osg::CopyOp::DEEP_COPY_NODES); if (!pNewModel.valid()) return NULL; osg::Group *group = dynamic_cast<osg::Group*>(pNewModel.get()); //VTLOG1("-----------------\n"); //vtLogGraph(node); //VTLOG1("-----------------\n"); //vtLogGraph(pNewModel); osg::Node *pFrontLeft = FindDescendent(group, "front_left"); osg::Node *pFrontRight = FindDescendent(group, "front_right"); osg::Node *pRearLeft = FindDescendent(group, "rear_left"); osg::Node *pRearRight = FindDescendent(group, "rear_right"); if (!pFrontLeft || !pFrontRight || !pRearLeft || !pRearRight) { // Didn't find them. return NULL; } Vehicle *pNewVehicle = new Vehicle; pNewVehicle->addChild(pNewModel); // Stick transform above them pNewVehicle->m_pFrontLeft = new vtTransform; pNewVehicle->m_pFrontLeft->setName("front_left_xform"); InsertNodeBelow(pFrontLeft->asGroup(), pNewVehicle->m_pFrontLeft); pNewVehicle->m_pFrontRight = new vtTransform; pNewVehicle->m_pFrontRight->setName("front_right_xform"); InsertNodeBelow(pFrontRight->asGroup(), pNewVehicle->m_pFrontRight); pNewVehicle->m_pRearLeft = new vtTransform; pNewVehicle->m_pRearLeft->setName("rear_left_xform"); InsertNodeBelow(pRearLeft->asGroup(), pNewVehicle->m_pRearLeft); pNewVehicle->m_pRearRight = new vtTransform; pNewVehicle->m_pRearRight->setName("rear_right_xform"); InsertNodeBelow(pRearRight->asGroup(), pNewVehicle->m_pRearRight); //VTLOG1("-----------------\n"); //vtLogGraph(pNewModel); // Replace the special 'purple' materials in the model with our color of choice ConvertPurpleToColor(pNewVehicle, cColor); return pNewVehicle; }
shared_ptr<GraphicsNode> GraphicsNodeScene::add(NodePtr node) { auto gNode = make_shared<GraphicsNode>(node); // connecting the node controller with the node view, so that // updates to the node controller are reflected in the widget. connect(node.get(), &Node::dirty, gNode.get(), &GraphicsNode::refreshNode); _nodes.insert(gNode); addItem(gNode.get()); return gNode; }
const std::wstring& Text::wholeText() const { NodePtr sibling = nextSibling(); if (!(sibling && sibling->nodeType()==TEXT_NODE)) return nodeValue(); Text* sibling_ptr = reinterpret_cast<Text*>(sibling.get()); m_oTempString = nodeValue()+sibling_ptr->wholeText(); sibling_ptr->m_oTempString.clear(); return m_oTempString; }
void XmlWriter::write(const NodePtr nodeArg) { NodePtr node = nodeArg; indent+=2; NamedNodeMap attributes = node->getAttributes(); int nrAttrs = attributes.getLength(); //### Start open tag spaces(); po("<"); pos(node->getNodeName()); if (nrAttrs>0) po("\n"); //### Attributes for (int i=0 ; i<nrAttrs ; i++) { NodePtr attr = attributes.item(i); spaces(); pos(attr->getNodeName()); po("=\""); pos(attr->getNodeValue()); po("\"\n"); } //### Finish open tag if (nrAttrs>0) spaces(); po(">\n"); //### Contents spaces(); pos(node->getNodeValue()); //### Children for (NodePtr child = node->getFirstChild() ; child.get() ; child=child->getNextSibling()) { write(child); } //### Close tag spaces(); po("</"); pos(node->getNodeName()); po(">\n"); indent-=2; }
void Builder::reparent(NodePtr parent, std::initializer_list<NodePtr> nodes) noexcept { auto parentPos = iteratorFor(impl_->nodes_, *parent); for (auto&& node: nodes) { auto it = iteratorFor(impl_->nodes_, *node); impl_->nodes_.reparent(parentPos, it, impl_->nodes_.next_sibling(it)); // Sanity check assert((*tree_t::parent(it)).get() == parent.get()); } }
NodePtr LazyGraph::getNode(NodeId id) { if (id.id == NULL_ID) { return NULL; } map<NodeId, Node *>::iterator i = nodes.find(id); if (i != nodes.end()) { // if the requested resource has already been loaded NodePtr r = i->second; nodeCache->remove(r);// we remove it from the unusedResources Cache //r->owner = this; // and we return the resource return r; } if (Logger::DEBUG_LOGGER != NULL) { ostringstream os; os << "Loading node '" << id.id << "'"; Logger::DEBUG_LOGGER->log("GRAPH", os.str()); } // otherwise the resource is not already loaded; we first load its descriptor NodePtr r = NULL; long int offset; map<NodeId, long int>::iterator j = nodeOffsets.find(id); if (j != nodeOffsets.end()) { offset = j->second; r = loadNode(offset, id); nodes[id] = r.get(); mapping->insert(make_pair(r->getPos(), r.get())); return r; } if (Logger::ERROR_LOGGER != NULL) { ostringstream os; os << "Loading : Missing or invalid node '" << id.id << "'"; Logger::ERROR_LOGGER->log("GRAPH", os.str()); } throw exception(); // return NULL; }
void LazyGraph::removeCurve(CurveId id) { CurvePtr c = getCurve(id); if (c != NULL) { NodePtr start = c->getStart(); NodePtr end = c->getEnd(); NodeId nId; nId.id = NULL_ID; c->addVertex(nId, 0); c->addVertex(nId, 1); if (start != end && start != NULL) { start->removeCurve(id); if (start->getCurveCount() == 0) { NodeId sid = start->getId(); start = NULL; removeNode(sid); } else { nodeCache->add(start.get(), true); } } if (end != NULL) { end->removeCurve(id); if (end->getCurveCount() == 0) { NodeId eid = end->getId(); end = NULL; removeNode(eid); } else { nodeCache->add(end.get(), true); } } } curveCache->changedResources.erase(c.get()); map<CurveId, long int>::iterator k = curveOffsets.find(id); if (k != curveOffsets.end()) { curveOffsets.erase(k); } }
NodePtr BaseTest::createNode(const QString & pluginID, int majorVersion, int minorVersion) { CreateNodeArgs args(pluginID, eCreateNodeReasonInternal, _app->getProject()); args.majorV = majorVersion; args.minorV = minorVersion; NodePtr ret = _app->createNode(args); EXPECT_NE(ret.get(),(Node*)NULL); return ret; }
bool StatCache::mergePath(const std::string& path, bool follow) { String canonicalPath = FileUtil::canonicalize(path); std::vector<std::string> pvec; folly::split('/', canonicalPath.slice(), pvec); assertx((pvec[0].size() == 0)); // path should be absolute. // Lazily initialize so that if StatCache never gets used, no kernel // resources are consumed. if (m_ifd == -1 && init()) { return true; } NodePtr curNode = m_root; std::string curPath = "/"; for (unsigned i = 1; i < pvec.size(); ++i) { // Follow links unless 'follow' is false and this is the last path // component. bool curFollow = (follow || i + 1 < pvec.size()); curPath += pvec[i]; NodePtr child = curNode->getChild(pvec[i], curFollow); if (child.get() == nullptr) { child = getNode(curPath, curFollow); if (child.get() == nullptr) { return true; } curNode->insertChild(pvec[i], child, curFollow); } curNode = child; curPath += "/"; } NameNodeMap::accessor acc; NameNodeMap& p2n = follow ? m_path2Node : m_lpath2Node; if (p2n.insert(acc, path)) { acc->second = curNode; TRACE(1, "StatCache: merge '%s' --> %p (follow=%s)\n", path.c_str(), curNode.get(), follow ? "true" : "false"); } return false; }