Esempio n. 1
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();
  }
}
/* ****************************************************************************
*
* contextAttributeValue - 
*/
static int contextAttributeValue(xml_node<>* node, ParseData* parseDataP)
{
  LM_T(LmtParse, ("Got an attribute value: %s", node->value()));
  parseDataP->lastContextAttribute = parseDataP->acer.attributeP;
  parseDataP->lastContextAttribute->typeFromXmlAttribute = xmlTypeAttributeGet(node);
  parseDataP->acer.attributeP->stringValue = node->value();
  parseDataP->acer.attributeP->valueType = orion::ValueTypeString;
  return 0;
}
/* ****************************************************************************
*
* contextAttributeContextValue -
*/
static int contextAttributeContextValue(xml_node<>* node, ParseData* parseDataP)
{
  LM_T(LmtParse, ("Got an attribute value: '%s'", node->value()));
  parseDataP->lastContextAttribute = parseDataP->ncr.attributeP;
  parseDataP->lastContextAttribute->typeFromXmlAttribute = xmlTypeAttributeGet(node);

  parseDataP->ncr.attributeP->value = node->value();

  return 0;
}
Esempio n. 4
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();
  }
}