<commit_before>/*
 * Edison 'C' Library to load plugins on-demand
 * Copyright (c) 2014, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
 * more details.
 */

/**
 * @file edisonapi.c
 * @brief Implementation of Edison Library
 *
 * Provides features to create client,service, to load communication interfaces as well as to load the Plugins.
 */

#include "edisonapi.h"

#include "cJSON.h"
#include "util.h"

#ifndef DEBUG
    #define DEBUG 0
#endif


/** Reports dynamic link library errors. Checks for any recent error happened while loading an shared library
 * @return boolean specifies whether an error was present or not
 */
static inline bool checkDLError() {
    char *error = dlerror();
    if (error != NULL) {
        fprintf(stderr, "DL error %s\n", error);
        return false;
    }
    return true;
}

/*
 * Helper snippet to print JSON parse errors.
 */
#define handleParseConfigError() \
{\
    fprintf(stderr,"invalid JSON format for %s file\n", config_file);\
    goto endParseConfig;\
}

/** Considers user defined configuration. Loads and parses user defined configuration
* '.edison-config.json' present in user's home directory for 'plugin interface' and
* 'plugins' configuration properties and concats with edison configuration properties
 */
void concatUserDefinedConfigurations(){
    char *home, config_file[1024];

    home = getenv("HOME");
    if(home == NULL || strlen(home) == 0){
        struct passwd *pw = getpwuid(getuid());
        home = pw->pw_dir;
    }

    strcpy(config_file, home);
    if(*(home + (strlen(home) - 1)) != '/')
        strcat(config_file, "/");

    strcat(config_file, USER_CONFIG_FILENAME);

       char *out;
           cJSON *json, *jitem;
           FILE *fp = fopen(config_file, "rb");

           if (fp == NULL)
           {
       	    fprintf(stderr,"Error can't open file %s\n", config_file);
           }
           else
           {
       	fseek(fp, 0, SEEK_END);
       	long size = ftell(fp);
       	rewind(fp);
<commit_msg>middleware: fix log message for iecf-c<commit_after>/*
 * Edison 'C' Library to load plugins on-demand
 * Copyright (c) 2014, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
 * more details.
 */

/**
 * @file edisonapi.c
 * @brief Implementation of Edison Library
 *
 * Provides features to create client,service, to load communication interfaces as well as to load the Plugins.
 */

#include "edisonapi.h"

#include "cJSON.h"
#include "util.h"

#ifndef DEBUG
    #define DEBUG 0
#endif


/** Reports dynamic link library errors. Checks for any recent error happened while loading an shared library
 * @return boolean specifies whether an error was present or not
 */
static inline bool checkDLError() {
    char *error = dlerror();
    if (error != NULL) {
        fprintf(stderr, "DL error %s\n", error);
        return false;
    }
    return true;
}

/*
 * Helper snippet to print JSON parse errors.
 */
#define handleParseConfigError() \
{\
    fprintf(stderr,"invalid JSON format for %s file\n", config_file);\
    goto endParseConfig;\
}

/** Considers user defined configuration. Loads and parses user defined configuration
* '.edison-config.json' present in user's home directory for 'plugin interface' and
* 'plugins' configuration properties and concats with edison configuration properties
 */
void concatUserDefinedConfigurations(){
    char *home, config_file[1024];

    home = getenv("HOME");
    if(home == NULL || strlen(home) == 0){
        struct passwd *pw = getpwuid(getuid());
        home = pw->pw_dir;
    }

    strcpy(config_file, home);
    if(*(home + (strlen(home) - 1)) != '/')
        strcat(config_file, "/");

    strcat(config_file, USER_CONFIG_FILENAME);

       char *out;
           cJSON *json, *jitem;
           FILE *fp = fopen(config_file, "rb");

           if (fp == NULL)
           {
       	    fprintf(stderr,"Warning: Optional user config file not found. Continuing...\n");
           }
           else
           {
       	fseek(fp, 0, SEEK_END);
       	long size = ftell(fp);
       	rewind(fp);

{'fraction_non_alphanumeric': 0.10423053341508277, 'fraction_numerical': 0.005722460658082976, 'mean_word_length': 2.982099267697315, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3854594', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1372, 'n_words': 531}