<commit_before>/* resource.c -- generic resource handling
 *
 * Copyright (C) 2010--2014 <NAME> <<EMAIL>>
 *
 * This file is part of the CoAP library libcoap. Please see
 * README for terms of use.
 */

#include "include/coap/config.h"
#include "include/coap/net.h"
#include "include/coap/debug.h"
#include "include/coap/resource.h"
#include "include/coap/subscribe.h"

#ifdef WITH_LWIP
#include "include/coap/utlist.h"
/* mem.h is only needed for the string free calls for
 * COAP_ATTR_FLAGS_RELEASE_NAME / COAP_ATTR_FLAGS_RELEASE_VALUE /
 * COAP_RESOURCE_FLAGS_RELEASE_URI. not sure what those lines should actually
 * do on lwip. */
#include "include/coap/mem.h"

#include <lwip/memp.h>

#define COAP_MALLOC_TYPE(Type) \
  ((coap_##Type##_t *)memp_malloc(MEMP_COAP_##Type))
#define COAP_FREE_TYPE(Type, Object) memp_free(MEMP_COAP_##Type, Object)

#endif
#if defined(WITH_POSIX) || defined(WITH_ARDUINO) || defined(_WIN32)
#include "include/coap/utlist.h"
#include "include/coap/mem.h"

#define COAP_MALLOC_TYPE(Type) \
  ((coap_##Type##_t *)coap_malloc(sizeof(coap_##Type##_t)))
#define COAP_FREE_TYPE(Type, Object) coap_free(Object)

#endif /* WITH_POSIX */
#ifdef WITH_CONTIKI
#include "memb.h"

MEMB(resource_storage, coap_resource_t, COAP_MAX_RESOURCES);
MEMB(attribute_storage, coap_attr_t, COAP_MAX_ATTRIBUTES);
MEMB(subscription_storage, coap_subscription_t, COAP_MAX_SUBSCRIBERS);

void
coap_resources_init()
{
    memb_init(&resource_storage);
    memb_init(&attribute_storage);
    memb_init(&subscription_storage);
}

static inline coap_subscription_t *
coap_malloc_subscription()
{
    return memb_alloc(&subscription_storage);
}

static inline void
coap_free_subscription(coap_subscription_t *subscription)
{
    memb_free(&subscription_storage, subscription);
}
#endif /* WITH_CONTIKI */

#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#endif

/* Helper functions for conditional output of character sequences into
 * a given buffer. The first Offset characters are skipped.
 */

/**
 * Adds Char to Buf if Offset is zero. Otherwise, Char is not written
 * and Offset is decremented.
 */
#define PRINT_WITH_OFFSET(Buf,Offset,Char)      \
  if ((Offset) == 0) {                  \
    (*(Buf)++) = (Char);                \
  } else {                      \
    (Offset)--;                     \
  }                         \

/**
 * Adds Char to Buf if Offset is zero and Buf is less than Bufend.
 */
#define PRINT_COND_WITH_OFFSET(Buf,Bufend,Offset,Char,Result) {     \
    if ((Buf) < (Bufend)) {                     \
      PRINT_WITH_OFFSET(Buf,Offset,Char);               \
    }                                   \
    (Result)++;                             \
  }

/**
 * Copies at most Length characters of Str to Buf. The first Offset
 * characters are skipped. Output may be truncated to Bufend - Buf
 * characters.
 */
#define COPY_COND_WITH_OFFSET(Buf,Bufend,Offset,Str,Length,Result) {    \
    size_t i;                               \
    for (i = 0; i < (Length); i++) {                    \
      PRINT_COND_WITH_OFFSET((Buf), (Bufend), (Offset), (Str)[i], (Result)); \
    }                                   \
  }

int match(const str *text, const str *pattern, int match_prefix, int match_substring)
{
    assert(text);
    assert(pattern);

    if (text->length < pattern->length)
        return 0;

    if (match_substring)
    {
        unsigned char *next_token = text->s;<commit_msg>iotivity: change match() to static function in libcoap-4.1.1<commit_after>/* resource.c -- generic resource handling
 *
 * Copyright (C) 2010--2014 <NAME> <<EMAIL>>
 *
 * This file is part of the CoAP library libcoap. Please see
 * README for terms of use.
 */

#include "include/coap/config.h"
#include "include/coap/net.h"
#include "include/coap/debug.h"
#include "include/coap/resource.h"
#include "include/coap/subscribe.h"

#ifdef WITH_LWIP
#include "include/coap/utlist.h"
/* mem.h is only needed for the string free calls for
 * COAP_ATTR_FLAGS_RELEASE_NAME / COAP_ATTR_FLAGS_RELEASE_VALUE /
 * COAP_RESOURCE_FLAGS_RELEASE_URI. not sure what those lines should actually
 * do on lwip. */
#include "include/coap/mem.h"

#include <lwip/memp.h>

#define COAP_MALLOC_TYPE(Type) \
  ((coap_##Type##_t *)memp_malloc(MEMP_COAP_##Type))
#define COAP_FREE_TYPE(Type, Object) memp_free(MEMP_COAP_##Type, Object)

#endif
#if defined(WITH_POSIX) || defined(WITH_ARDUINO) || defined(_WIN32)
#include "include/coap/utlist.h"
#include "include/coap/mem.h"

#define COAP_MALLOC_TYPE(Type) \
  ((coap_##Type##_t *)coap_malloc(sizeof(coap_##Type##_t)))
#define COAP_FREE_TYPE(Type, Object) coap_free(Object)

#endif /* WITH_POSIX */
#ifdef WITH_CONTIKI
#include "memb.h"

MEMB(resource_storage, coap_resource_t, COAP_MAX_RESOURCES);
MEMB(attribute_storage, coap_attr_t, COAP_MAX_ATTRIBUTES);
MEMB(subscription_storage, coap_subscription_t, COAP_MAX_SUBSCRIBERS);

void
coap_resources_init()
{
    memb_init(&resource_storage);
    memb_init(&attribute_storage);
    memb_init(&subscription_storage);
}

static inline coap_subscription_t *
coap_malloc_subscription()
{
    return memb_alloc(&subscription_storage);
}

static inline void
coap_free_subscription(coap_subscription_t *subscription)
{
    memb_free(&subscription_storage, subscription);
}
#endif /* WITH_CONTIKI */

#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#endif

/* Helper functions for conditional output of character sequences into
 * a given buffer. The first Offset characters are skipped.
 */

/**
 * Adds Char to Buf if Offset is zero. Otherwise, Char is not written
 * and Offset is decremented.
 */
#define PRINT_WITH_OFFSET(Buf,Offset,Char)      \
  if ((Offset) == 0) {                  \
    (*(Buf)++) = (Char);                \
  } else {                      \
    (Offset)--;                     \
  }                         \

/**
 * Adds Char to Buf if Offset is zero and Buf is less than Bufend.
 */
#define PRINT_COND_WITH_OFFSET(Buf,Bufend,Offset,Char,Result) {     \
    if ((Buf) < (Bufend)) {                     \
      PRINT_WITH_OFFSET(Buf,Offset,Char);               \
    }                                   \
    (Result)++;                             \
  }

/**
 * Copies at most Length characters of Str to Buf. The first Offset
 * characters are skipped. Output may be truncated to Bufend - Buf
 * characters.
 */
#define COPY_COND_WITH_OFFSET(Buf,Bufend,Offset,Str,Length,Result) {    \
    size_t i;                               \
    for (i = 0; i < (Length); i++) {                    \
      PRINT_COND_WITH_OFFSET((Buf), (Bufend), (Offset), (Str)[i], (Result)); \
    }                                   \
  }

#ifdef __TIZENRT__
static
#endif
int match(const str *text, const str *pattern, int match_prefix, int match_substring)
{
    assert(text);
    assert(pattern);

    if (text->length < pattern->length)
        return 0;

    if (match_substring)
    {
        unsigned char *next_token = text->s;
{'fraction_non_alphanumeric': 0.12532411408815902, 'fraction_numerical': 0.004177470469605301, 'mean_word_length': 2.915961646926114, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5632990', 'n_tokens_mistral': 2409, 'n_tokens_neox': 2327, 'n_words': 538}