Пример #1
0
UsernameToken::UsernameToken(SOAPEnvelope& soap, const std::string& username, const std::string& password,const std::string& uid, PasswordType pwdtype) {
  header_=soap.Header();
  uid_ = uid;
  iteration_ = 0;
  
  //Get the username
  username_=username;
  if(username_.empty()) get_username(username_);

  //Get the password  
  password_=password;
  if(password_.empty()) get_password(password_,false);

  // Apply predefined namespace prefix
  NS ns;
  ns["wsse"]=WSSE_NAMESPACE;
  ns["wsse11"]=WSSE11_NAMESPACE;
  ns["wsu"]=WSU_NAMESPACE;
  header_.Namespaces(ns);

  //Check the arguments
  if(username_.empty() || password_.empty()) {
    std::cerr<<"Username and Password should not be empty"<<std::endl;
    header_=XMLNode();
    return;
  }

  // Insert the related elements
  XMLNode wsse = get_node(header_,"wsse:Security");
  XMLNode ut = get_node(wsse, "wsse:UsernameToken");
  if(!uid_.empty()) {
    ut.NewAttribute("wsu:Id") = uid_;
  }
  get_node(ut, "wsse:Username") = username_;
  XMLNode passwd_node = get_node(ut, "wsse:Password");

  if(pwdtype == PasswordText) {
    passwd_node.NewAttribute("Type") = passwdtype_ = PASSWORD_TEXT;
    passwd_node = password_;
  }
  else if(pwdtype == PasswordDigest) {
    passwd_node.NewAttribute("Type") = passwdtype_ = PASSWORD_DIGEST; 
    nonce_ = get_nonce();
    get_node(ut, "wsse:Nonce") = nonce_;
    created_ = Time().str(UTCTime);
    get_node(ut, "wsu:Created") = created_;

    //std::cout<<"nonce: "<<nonce_<<"createdtime: "<<created_<<"password: "******"Unsupported password type requested"<<std::endl;
    header_=XMLNode();
    return;
  }
}
Пример #2
0
 XMLNode XMLNode::GetRoot(void) {
   if (node_ == NULL)
     return XMLNode();
   xmlDocPtr doc = node_->doc;
   if (doc == NULL)
     return XMLNode();
   return XMLNode(doc->children);
 }
Пример #3
0
 XMLNode XMLNode::Parent(void) {
   if (node_ == NULL)
     return XMLNode();
   if (node_->type == XML_ELEMENT_NODE)
     return XMLNode(node_->parent);
   if (node_->type == XML_ATTRIBUTE_NODE)
     return XMLNode(((xmlAttrPtr)node_)->parent);
   return XMLNode();
 }
Пример #4
0
 XMLNode XMLNode::NewChild(const XMLNode& node, int n, bool global_order) {
   if (node_ == NULL)
     return XMLNode();
   if (node.node_ == NULL)
     return XMLNode();
   if (node_->type != XML_ELEMENT_NODE)
     return XMLNode();
   // TODO: Add new attribute if 'node' is attribute
   if (node.node_->type != XML_ELEMENT_NODE)
     return XMLNode();
   xmlNodePtr new_node = xmlDocCopyNode(node.node_, node_->doc, 1);
   if (new_node == NULL)
     return XMLNode();
   if (n < 0)
     return XMLNode(xmlAddChild(node_, new_node));
   std::string name;
   xmlNsPtr ns = GetNamespace(new_node);
   if (ns != NULL) {
     if (ns->prefix != NULL)
       name = (char*)ns->prefix;
     name += ":";
   }
   if (new_node->name)
     name += (char*)(new_node->name);
   XMLNode old_node = global_order ? Child(n) : operator[](name)[n];
   if (!old_node)
     // TODO: find last old_node
     return XMLNode(xmlAddChild(node_, new_node));
   if (old_node)
     return XMLNode(xmlAddPrevSibling(old_node.node_, new_node));
   return XMLNode(xmlAddChild(node_, new_node));
 }
Пример #5
0
MIR_APP_DLL(int) xmlGetElement(HXML _n, XML_ELEMENT_POS pos, XML_ELEMENT_TYPE *type, HXML *child, LPCTSTR *value, LPCTSTR *name, LPCTSTR *openTag, LPCTSTR *closeTag)
{
	// reset all values
	if (child)
		*child = NULL;
	if (value)
		*value = NULL;
	if (name)
		*name = NULL;
	if (openTag)
		*openTag = NULL;
	if (closeTag)
		*closeTag = NULL;

	if (!type || pos >= XMLNode(_n).nElement())
		return false;

	XMLNodeContents c(XMLNode(_n).enumContents((XMLElementPosition)pos));
	switch (c.etype) {
	case eNodeChild:
		*type = XML_ELEM_TYPE_CHILD;
		if (child)
			*child = c.child;
		break;
	
	case eNodeAttribute:
		*type = XML_ELEM_TYPE_ATTRIBUTE;
		if (name)
			*name = c.attrib.lpszName;
		if (value)
			*value = c.attrib.lpszValue;
		break;
	
	case eNodeText:
		*type = XML_ELEM_TYPE_TEXT;
		if (value)
			*value = c.text;
		break;

	case eNodeClear:
		*type = XML_ELEM_TYPE_CLEAR;
		if (value)
			*value = c.clear.lpszValue;
		if (openTag)
			*openTag = c.clear.lpszOpenTag;
		if (closeTag)
			*closeTag = c.clear.lpszCloseTag;
		break;

	case eNodeNULL:
		return false;
	}
	return true;
}
Пример #6
0
int
main ()
{
    char * xml;

    xml = XMLNode ("a", ATTRS({"href", "#"}, {"class", "plop"}), "%s",
                   XMLNode ("span", ATTRS({"class", "plip"}), "%s%d", "coucou", 42));

    printf("%s\n", xml);
    free(xml);
    return (0);
}
Пример #7
0
 XMLNode XMLNode::Child(int n) {
   if (!node_)
     return XMLNode();
   if (node_->type != XML_ELEMENT_NODE)
     return XMLNode();
   xmlNodePtr p = n < 0 ? NULL : node_->children;
   for (; p; p = p->next) {
     if (p->type != XML_ELEMENT_NODE)
       continue;
     if ((--n) < 0)
       break;
   }
   return XMLNode(p);
 }
Пример #8
0
MIR_APP_DLL(HXML) xmlAddChild(HXML _n, LPCTSTR name, LPCTSTR text)
{
	XMLNode result = XMLNode(_n).addChild(name);
	if (text != NULL)
		result.updateText(text);
	return result;
}
Пример #9
0
UsernameToken::UsernameToken(SOAPEnvelope& soap, const std::string& username, const std::string& uid, bool mac, int iteration) {
  header_=soap.Header();
  uid_ = uid;
  iteration_ = iteration;

  //Get the username
  username_=username;
  if(username_.empty()) get_username(username_);

  salt_ = get_salt(mac);

  // Apply predefined namespace prefix
  NS ns;
  ns["wsse"]=WSSE_NAMESPACE;
  ns["wsse11"]=WSSE11_NAMESPACE;
  ns["wsu"]=WSU_NAMESPACE;
  header_.Namespaces(ns);

  //Check the arguments
  if(username_.empty() || salt_.empty()) {
    std::cerr<<"Username and Salt should not be empty"<<std::endl;
    header_=XMLNode();
    return;
  }

  // Insert the related elements
  XMLNode wsse = get_node(header_,"wsse:Security");
  XMLNode ut = get_node(wsse, "wsse:UsernameToken");
  if(!uid_.empty()) {
    ut.NewAttribute("wsse:Id") = uid_;
  }
  get_node(ut, "wsse:Username") = username_;
  get_node(ut, "wsse11:Salt") = salt_;
  get_node(ut, "wsse11:Iteration") = tostring(iteration);
}
Пример #10
0
  XMLNodeList XMLNode::XPathLookup(const std::string& xpathExpr, const NS& nsList) {
    std::list<XMLNode> retlist;
    if (node_ == NULL)
      return retlist;
    if (node_->type != XML_ELEMENT_NODE)
      return retlist;
    xmlDocPtr doc = node_->doc;
    if (doc == NULL)
      return retlist;
    xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
    for (NS::const_iterator ns = nsList.begin(); ns != nsList.end(); ++ns)
      xmlXPathRegisterNs(xpathCtx, (xmlChar*)ns->first.c_str(), (xmlChar*)ns->second.c_str());
    xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression((const xmlChar*)(xpathExpr.c_str()), xpathCtx);
    if (xpathObj && xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) {
      xmlNodeSetPtr nodes = xpathObj->nodesetval;
      int size = nodes->nodeNr;
      for (int i = 0; i < size; ++i)
        if (nodes->nodeTab[i]->type == XML_ELEMENT_NODE) {
          xmlNodePtr cur = nodes->nodeTab[i];
          xmlNodePtr parent = cur;
          for (; parent; parent = parent->parent)
            if (parent == node_)
              break;
          if (parent)
            retlist.push_back(XMLNode(cur));
        }
    }

    xmlXPathFreeObject(xpathObj);
    xmlXPathFreeContext(xpathCtx);

    return retlist;
  }
Пример #11
0
XMLNode &
XMLNode::AddChild(const TCHAR *lpszName, bool isDeclaration)
{
  assert(lpszName != NULL);

  d->pChild.push_back(XMLNode(lpszName, isDeclaration));
  return d->pChild.back();
}
Пример #12
0
XMLNode& XMLNode::operator[](const string &name) {
    XMLNode::ListType &list = children[name];
    if ( list.size() == 0 ) {
        list.push_front(XMLNode());
        list.front().name = name;
    }
    return list.front();
}
Пример #13
0
XMLNode &
XMLNode::AddChild(const TCHAR *name, size_t name_length, bool is_declaration)
{
  assert(name != NULL);

  d->children.push_back(XMLNode(name, name_length, is_declaration));
  return d->children.back();
}
Пример #14
0
XMLNode &
XMLNode::AddChild(const TCHAR *name, bool is_declaration)
{
  assert(name != nullptr);

  d->children.push_back(XMLNode(name, is_declaration));
  return d->children.back();
}
Пример #15
0
 XMLNode XMLNode::NewChild(const char *name, int n, bool global_order) {
   if (node_ == NULL)
     return XMLNode();
   if (node_->type != XML_ELEMENT_NODE)
     return XMLNode();
   const char *name_ = strchr(name, ':');
   xmlNsPtr ns = NULL;
   if (name_ != NULL) {
     std::string ns_(name, name_ - name);
     ns = xmlSearchNs(node_->doc, node_, (const xmlChar*)(ns_.c_str()));
     ++name_;
   }
   else
     name_ = name;
   xmlNodePtr new_node = xmlNewNode(ns, (const xmlChar*)name_);
   if (new_node == NULL)
     return XMLNode();
   if (n < 0)
     return XMLNode(xmlAddChild(node_, new_node));
   XMLNode old_node = global_order ? Child(n) : operator[](name)[n];
   if (!old_node)
     // TODO: find last old_node
     return XMLNode(xmlAddChild(node_, new_node));
   if (old_node)
     return XMLNode(xmlAddPrevSibling(old_node.node_, new_node));
   return XMLNode(xmlAddChild(node_, new_node));
 }
Пример #16
0
MIR_APP_DLL(LPCTSTR) xmlGetClear(HXML _n, int i, LPCTSTR *openTag, LPCTSTR *closeTag)
{
	XMLClear c = XMLNode(_n).getClear(i);
	if (openTag)
		*openTag = c.lpszOpenTag;
	if (closeTag)
		*closeTag = c.lpszCloseTag;
	return c.lpszValue;
}
Пример #17
0
 XMLNode creamJobInfo::ToXML() const {
   return XMLNode("<jobId>"
                   "<id>"+id+"</id>"
                   "<creamURL>"+creamURL+"</creamURL>"+
                   (!ISB.empty() ? "<property><name>CREAMInputSandboxURI</name><value>" + ISB +"</value></property>" : std::string()) +
                   (!OSB.empty() ? "<property><name>CREAMOutputSandboxURI</name><value>" + OSB +"</value></property>" : std::string()) +
                   "<delegationID>"+delegationID+"</delegationID>"
                  "</jobId>");
 }
Пример #18
0
QList<XMLNode> XMLNode::childNodes() const
{
	if(!isNull())
	{
		QList<XMLNode> nodes;
		foreach(NodeData *data, m_data->children)
			nodes.append(XMLNode(data));
		return nodes;
	}
	return QList<XMLNode>();
}
Пример #19
0
 static XMLNode find_xml_node(XMLNode node,
                              const std::string& el_name,
                              const std::string& attr_name,
                              const std::string& attr_value) {
   if (MatchXMLName(node, el_name) &&
       (((std::string)node.Attribute(attr_name)) == attr_value))
     return node;
   XMLNode cn = node[el_name];
   while (cn) {
     XMLNode fn = find_xml_node(cn, el_name, attr_name, attr_value);
     if (fn)
       return fn;
     cn = cn[1];
   }
   return XMLNode();
 }
Пример #20
0
LIBSBML_EXTERN XMLNode getXmlNodeForSBase(const SBase* object)
{
  char* rawsbml = const_cast<SBase*>(object)->toSBML();  
  SBMLNamespaces *sbmlns = object->getSBMLNamespaces();
  XMLNamespaces* xmlns = sbmlns->getNamespaces()->clone();
  // in rare cases the above returns a package element with default namespace, however the 
  // XMLNamespaces would then assign the actual default namespace, which is in most cases
  // the SBML namespace. In that case we adjust the default namespace here
  ISBMLExtensionNamespaces *extns = dynamic_cast<ISBMLExtensionNamespaces*>(sbmlns);
  if (extns != NULL)
  {
    xmlns->remove("");
    xmlns->add(xmlns->getURI(extns->getPackageName()), "");    
  }

  XMLNode* tmp = XMLNode::convertStringToXMLNode(rawsbml, xmlns);
  if (tmp == NULL) return XMLNode();
  XMLNode result(*tmp);
  delete tmp;
  delete xmlns;
  free(rawsbml);
  return result;
}
Пример #21
0
	void XMLDocument::LoadData(TByteArray data, int options)
	{
		if (data.size()) {
			data.push_back('\0');
			rapidxml::xml_document<> doc;
			doc.parse<0>((char *) &data[0]);

			rapidxml::xml_node<> *root = doc.first_node(0);
			if (!root) {
				throw "Could not find root node";
			}

			mRootNode = XMLNode(root->name(), root->value());
			rapidxml::xml_attribute<> *attr = root->first_attribute(0);
			while (attr) {
				mRootNode.SetAttribute(std::string(attr->name()), std::string(attr->value()));

				attr = attr->next_attribute();
			}

			this->ParseNodeTree(mRootNode, root->first_node(0));
		}
	}
Пример #22
0
 static inline XMLNode Null() {
   return XMLNode(_T(""), false);
 }
Пример #23
0
XMLNode
XMLNode::mustNextElement(const char* elementName) const 
{
	return XMLNode(m_impl->nextElement(elementName, true));
}
Пример #24
0
XMLNode
XMLNode::mustFindElement(const char* elementName) const  
{
	return XMLNode(m_impl->findElement(elementName, true));
}
Пример #25
0
XMLNode
XMLNode::CreateRoot(const TCHAR *name)
{
  return XMLNode(name, false);
}
Пример #26
0
XMLNode
XMLNode::getChild() const
{
	return XMLNode(m_impl->getChild());
}
Пример #27
0
XMLNode
XMLNode::mustGetChild() const
{
	return XMLNode(m_impl->mustGetChild());
}
Пример #28
0
XMLNode
XMLNode::getNext() const
{
	return XMLNode(m_impl->getNext());
}
Пример #29
0
XMLNode
XMLNode::mustChildFindElementChild(const char* elementName) const 
{
	return XMLNode(m_impl->mustChildFindElementChild(elementName));
}
Пример #30
0
XMLNode
XMLNode::nextElement(const char* elementName)
{
	return XMLNode(m_impl->nextElement(elementName));
}