Example #1
0
/* ****************************************************************************
*
* xmlParse - 
*
* This function is called once (actually it is not that simple) for each node in
* the tree that the XML parser has built for us.
* 
*
* In the node '<contextValue>', isCompoundValuePath returns TRUE.
* Under "<contextValue>", we have either a simple string or a Compound Value Tree.
* In the case of a "simple string" the value of the current node is NON EMPTY,
* and as the node is treated already in the previous call to 'treat()', no further action is needed.
*
* If a node is NOT TREATED and it is NOT a compound, a parse error is issued
*/
void xmlParse
(
   ConnectionInfo*     ciP,
   xml_node<>*         father,
   xml_node<>*         node,
   const std::string&  indentation,
   const std::string&  fatherPath,
   XmlNode*            parseVector,
   ParseData*          parseDataP
)
{
  std::string  value            = wsStrip(node->value());
  std::string  name             = wsStrip(node->name());
  std::string  path             = fatherPath + "/" + name;
  bool         treated          = treat(node, path, parseVector, parseDataP);

  if (isCompoundValuePath(path.c_str()) && (value == "") && (node->first_node() != NULL))
  {
    //
    // Count children (to avoid false compounds because of just en empty sttribute value)
    // 
    xml_node<>* child    = node->first_node();
    int         children = 0;
    while (child != NULL)
    {
      if (child->name()[0] != 0)
        ++children;
      child = child->next_sibling();
    }
    
    if (children == 0) // NOT a compound value
      return;

    eatCompound(ciP, NULL, node, "");
    compoundValueEnd(ciP, parseDataP);
    return;
  }
  else  if (treated == false)
  {
    ciP->httpStatusCode = SccBadRequest;
    if (ciP->answer == "")
      ciP->answer = std::string("Unknown XML field: '") + name.c_str() + "'";
    LM_W(("ERROR: '%s', PATH: '%s'   ", ciP->answer.c_str(), fatherPath.c_str()));
    return;
  }

  // Recursive calls for all children of this node
  xml_node<>* child = node->first_node();
  while (child != NULL)
  {
    if ((child != NULL) && (child->name() != NULL) && (onlyWs(child->name()) == false))
      xmlParse(ciP, node, child, indentation + "  ", path, parseVector, parseDataP);

    child = child->next_sibling();
  }
}
Example #2
0
/* ****************************************************************************
*
* eatCompound - consume the compound tree
*
* Three types of tree nodes here (4 actually);
*   - toplevel node
*   - leaf
*   - object node
*   - vector node
*/
void eatCompound(ConnectionInfo* ciP, orion::CompoundValueNode* containerP, xml_node<>* node, std::string indent)
{
  if (containerP == NULL) // toplevel)
  {
    std::string xmlAttribute = xmlTypeAttributeGet(node);
    
    if (xmlAttribute == "vector")
      containerP = new CompoundValueNode(orion::CompoundValueNode::Vector);
    else if (xmlAttribute =="")
      containerP = new CompoundValueNode(orion::CompoundValueNode::Struct);
    else
    {
      ciP->httpStatusCode = SccBadRequest;
      ciP->answer = std::string("Bad value for XML attribute 'type' for '") + node->name() + "': '" + xmlAttribute + "'";
      LM_W(("ERROR: '%s'", ciP->answer.c_str()));
      return;
    }
    ciP->compoundValueRoot = containerP;
  }
  else
  {
    std::string value = wsStrip(node->value());
    std::string name  = wsStrip(node->name());

    if (value == "")  // Object OR Vector
    {
      std::string xmlAttribute = xmlTypeAttributeGet(node);
    
      if (xmlAttribute == "vector")
        containerP = containerP->add(orion::CompoundValueNode::Vector, name);
      else if (xmlAttribute == "")
        containerP = containerP->add(orion::CompoundValueNode::Struct, name);
      else
      {
        ciP->httpStatusCode = SccBadRequest;
        ciP->answer = std::string("Bad value for XML attribute 'type' for '") + name + "': '" + xmlAttribute + "'";
        LM_W(("ERROR: '%s'", ciP->answer.c_str()));
        return;
      }
    }
    else // String
      containerP->add(orion::CompoundValueNode::Leaf, name, value);
  }

  xml_node<>* child = node->first_node();
  while (child != NULL)
  {
    if (child->name()[0] != 0)
      eatCompound(ciP, containerP, child, indent + "  ");
    child = child->next_sibling();
  }
}
Example #3
0
/* ****************************************************************************
*
* eatCompound - consume the compound tree
*
* Three types of tree nodes here (4 actually);
*   - toplevel node
*   - string
*   - object node
*   - vector node
*/
void eatCompound(ConnectionInfo* ciP, orion::CompoundValueNode* containerP, xml_node<>* node, const std::string& indent)
{
  if (containerP == NULL)  // toplevel
  {
    std::string xmlAttribute = xmlTypeAttributeGet(node);

    if (xmlAttribute == "vector")
    {
      containerP = new CompoundValueNode(orion::CompoundValueNode::Vector);
    }
    else if (xmlAttribute =="")
    {
      containerP = new CompoundValueNode(orion::CompoundValueNode::Object);
    }
    else
    {
      ciP->httpStatusCode = SccBadRequest;

      ciP->answer = std::string("Bad value for XML attribute /type/ for /") +
        node->name() + "/: " + xmlAttribute;

      LM_W(("Bad Input (%s)", ciP->answer.c_str()));

      return;
    }

    ciP->compoundValueRoot = containerP;
  }
  else
  {
    std::string value = wsStrip(node->value());
    std::string name  = wsStrip(node->name());

    if (value == "")   // Object OR Vector
    {
      std::string xmlAttribute = xmlTypeAttributeGet(node);

      if (xmlAttribute == "vector")
      {
        containerP = containerP->add(orion::CompoundValueNode::Vector, name);
      }
      else if (xmlAttribute == "")
      {
        containerP = containerP->add(orion::CompoundValueNode::Object, name);
      }
      else
      {
        ciP->httpStatusCode = SccBadRequest;
        ciP->answer = std::string("Bad value for XML attribute /type/ for /") + name + "/: " + xmlAttribute;
        LM_W(("Bad Input (%s)", ciP->answer.c_str()));

        return;
      }
    }
    else  // String
    {
      if (forbiddenChars(value.c_str()) == true)
      {
        LM_E(("Found a forbidden value in '%s'", value.c_str()));
        ciP->httpStatusCode = SccBadRequest;
        ciP->answer = std::string("Illegal value for XML attribute");
        return;
      }

      containerP->add(orion::CompoundValueNode::String, name, value);
    }
  }

  xml_node<>* child = node->first_node();
  while (child != NULL)
  {
    if (child->name()[0] != 0)
    {
      eatCompound(ciP, containerP, child, indent + "  ");
    }

    child = child->next_sibling();
  }
}