<commit_before>/*
*
* Copyright 2015 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: Orion dev team
*/

#include "alarmMgr/alarmMgr.h"
#include "mongoBackend/mongoSubscribeContext.h"
#include "ngsi/ParseData.h"
#include "ngsi10/SubscribeContextResponse.h"
#include "common/statistics.h"
#include "rest/uriParamNames.h"
#include "rest/OrionError.h"
#include "serviceRoutinesV2/postSubscriptions.h"



/* ****************************************************************************
*
* postSubscriptions -
*/
extern std::string postSubscriptions
(
  ConnectionInfo*            ciP,
  int                        components,
  std::vector<std::string>&  compV,
  ParseData*                 parseDataP
)
{
  SubscribeContextResponse  scr;
  std::string               answer;

  if (ciP->servicePathV.size() > 1)
  {
    const size_t  MSG_SIZE        = 96;  // strlen(msg) + enough room for digits
    char          errMsg[MSG_SIZE];

    snprintf(errMsg, MSG_SIZE, "max *one* service-path allowed for subscriptions (%zd given)", ciP->servicePathV.size());
    alarmMgr.badInput(clientIp, errMsg);
    scr.subscribeError.errorCode.fill(SccBadRequest, "max one service-path allowed for subscriptions");

    TIMED_RENDER(answer = scr.render(SubscribeContext, ""));
    return answer;
  }

  if (parseDataP->scr.res.attrsFormat == NGSI_NO_NOTIFICATION_FORMAT)
  {
    parseDataP->scr.res.attrsFormat = NGSI_V2_NORMALIZED; // FIXME PR: default notification format ?
  }
  TIMED_MONGO(ciP->httpStatusCode = mongoSubscribeContext(&parseDataP->scr.res, &scr, ciP->tenant, ciP->uriParam, ciP->httpHeaders.xauthToken, ciP->servicePathV, ciP->httpHeaders.correlator));

  parseDataP->scr.res.release();

  if (scr.subscribeError.errorCode.code != SccNone )
  {
    TIMED_RENDER(answer = scr.render(SubscribeContext, ""));
    return answer;
  }
  std::string location = "/v2/subscriptions/" + scr.subscribeResponse.subscriptionId.string;
  ciP->httpHeader.push_back("Location");
  ciP->httpHeaderValue.push_back(location);

  ciP->httpStatusCode = SccCreated;

  return "";
}<commit_msg>Unwanted FIXME removed in postSubscriptions.cpp<commit_after>/*
*
* Copyright 2015 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 "alarmMgr/alarmMgr.h"
#include "mongoBackend/mongoSubscribeContext.h"
#include "ngsi/ParseData.h"
#include "ngsi10/SubscribeContextResponse.h"
#include "common/statistics.h"
#include "rest/uriParamNames.h"
#include "rest/OrionError.h"
#include "serviceRoutinesV2/postSubscriptions.h"



/* ****************************************************************************
*
* postSubscriptions -
*/
extern std::string postSubscriptions
(
  ConnectionInfo*            ciP,
  int                        components,
  std::vector<std::string>&  compV,
  ParseData*                 parseDataP
)
{
  SubscribeContextResponse  scr;
  std::string               answer;

  if (ciP->servicePathV.size() > 1)
  {
    const size_t  MSG_SIZE        = 96;  // strlen(msg) + enough room for digits
    char          errMsg[MSG_SIZE];

    snprintf(errMsg, MSG_SIZE, "max *one* service-path allowed for subscriptions (%zd given)", ciP->servicePathV.size());
    alarmMgr.badInput(clientIp, errMsg);
    scr.subscribeError.errorCode.fill(SccBadRequest, "max one service-path allowed for subscriptions");

    TIMED_RENDER(answer = scr.render(SubscribeContext, ""));
    return answer;
  }

  if (parseDataP->scr.res.attrsFormat == NGSI_NO_NOTIFICATION_FORMAT)
  {
    parseDataP->scr.res.attrsFormat = NGSI_V2_NORMALIZED;
  }
  TIMED_MONGO(ciP->httpStatusCode = mongoSubscribeContext(&parseDataP->scr.res, &scr, ciP->tenant, ciP->uriParam, ciP->httpHeaders.xauthToken, ciP->servicePathV, ciP->httpHeaders.correlator));

  parseDataP->scr.res.release();

  if (scr.subscribeError.errorCode.code != SccNone )
  {
    TIMED_RENDER(answer = scr.render(SubscribeContext, ""));
    return answer;
  }
  std::string location = "/v2/subscriptions/" + scr.subscribeResponse.subscriptionId.string;
  ciP->httpHeader.push_back("Location");
  ciP->httpHeaderValue.push_back(location);

  ciP->httpStatusCode = SccCreated;

  return "";
}
{'fraction_non_alphanumeric': 0.13011923276308968, 'fraction_numerical': 0.0044928287541040265, 'mean_word_length': 4.117595048629531, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '7652113', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1747, 'n_words': 489}