<commit_before>/*
*
* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U
*
* This file is part of Orion Context Broker.
*
* Orion Context Broker is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Orion Context Broker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by this license please contact with
* iot_support at tid dot es
*
* Author: <NAME>
*/
#include <stdio.h>
#include <string>

#include "logMsg/logMsg.h"
#include "logMsg/traceLevels.h"

#include "common/globals.h"
#include "common/wsStrip.h"
#include "common/string.h"
#include "ngsi/ParseData.h"
#include "ngsi/EntityId.h"
#include "parse/CompoundValueNode.h"
#include "parse/compoundValue.h"
#include "parse/forbiddenChars.h"
#include "rest/ConnectionInfo.h"
#include "xmlParse/XmlNode.h"
#include "xmlParse/xmlParse.h"

using namespace orion;

/* ****************************************************************************
*
* compoundValueRootV -
*
* The vector 'compoundValueRootV' contains a list of all the paths where we allow
* a compound value
*/
static const char* compoundValueRootV[] =
{
  "/updateContextRequest/contextElementList/contextElement/contextAttributeList/contextAttribute/contextValue",
  "/appendContextElementRequest/contextAttributeList/contextAttribute/contextValue",
  "/updateContextElementRequest/contextAttributeList/contextAttribute/contextValue",
  "/updateContextAttributeRequest/contextValue",
  "/notifyContextRequest/contextResponseList/contextElementResponse/contextElement/contextAttributeList/contextAttribute/contextValue"
};



/* ****************************************************************************
*
* isCompoundValuePath -
*
* This function examines a path to see whether we are inside a compound value or not.
*
* If the path doesn't belong to any compond, FALSE is returned, else TRUE.
*/
static bool isCompoundValuePath(const char* path)
{
  unsigned int len;

  for (unsigned int ix = 0; ix < sizeof(compoundValueRootV) / sizeof(compoundValueRootV[0]); ++ix)
  {
    len = strlen(compoundValueRootV[ix]);

    if (strlen(path) < len)
    {
      continue;
    }

    if (strncmp(compoundValueRootV[ix], path, len) == 0)
    {
      return true;
    }
  }

  return false;
}



/* ****************************************************************************
*
* treat -
*
* This is the function that actually treats a node, bu calling its treat function
* provided by src/lib/xmlRequest - the entry point of XML parsing.
*
* It simple compares the current path with the paths in the incoming vector 'parseVector'<commit_msg>reduce var scope, fix type<commit_after>/*
*
* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U
*
* This file is part of Orion Context Broker.
*
* Orion Context Broker is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Orion Context Broker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by this license please contact with
* iot_support at tid dot es
*
* Author: <NAME>
*/
#include <stdio.h>
#include <string>

#include "logMsg/logMsg.h"
#include "logMsg/traceLevels.h"

#include "common/globals.h"
#include "common/wsStrip.h"
#include "common/string.h"
#include "ngsi/ParseData.h"
#include "ngsi/EntityId.h"
#include "parse/CompoundValueNode.h"
#include "parse/compoundValue.h"
#include "parse/forbiddenChars.h"
#include "rest/ConnectionInfo.h"
#include "xmlParse/XmlNode.h"
#include "xmlParse/xmlParse.h"

using namespace orion;

/* ****************************************************************************
*
* compoundValueRootV -
*
* The vector 'compoundValueRootV' contains a list of all the paths where we allow
* a compound value
*/
static const char* compoundValueRootV[] =
{
  "/updateContextRequest/contextElementList/contextElement/contextAttributeList/contextAttribute/contextValue",
  "/appendContextElementRequest/contextAttributeList/contextAttribute/contextValue",
  "/updateContextElementRequest/contextAttributeList/contextAttribute/contextValue",
  "/updateContextAttributeRequest/contextValue",
  "/notifyContextRequest/contextResponseList/contextElementResponse/contextElement/contextAttributeList/contextAttribute/contextValue"
};



/* ****************************************************************************
*
* isCompoundValuePath -
*
* This function examines a path to see whether we are inside a compound value or not.
*
* If the path doesn't belong to any compond, FALSE is returned, else TRUE.
*/
static bool isCompoundValuePath(const char* path)
{

  for (unsigned int ix = 0; ix < sizeof(compoundValueRootV) / sizeof(compoundValueRootV[0]); ++ix)
  {
    size_t len = strlen(compoundValueRootV[ix]);

    if (strlen(path) < len)
    {
      continue;
    }

    if (strncmp(compoundValueRootV[ix], path, len) == 0)
    {
      return true;
    }
  }

  return false;
}



/* ****************************************************************************
*
* treat -
*
* This is the function that actually treats a node, bu calling its treat function
* provided by src/lib/xmlRequest - the entry point of XML parsing.
*
* It simple compares the current path with the paths in the incoming vector 'parseVector'
{'fraction_non_alphanumeric': 0.15956424223005447, 'fraction_numerical': 0.00256328099967959, 'mean_word_length': 4.962750716332378, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1337256', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1700, 'n_words': 597}