<commit_before>/* maxminddb module
 *
 * Version 0.1
 *
 * This module sets an environment variable to the remote country
 * based on the requestor's IP address.  It uses the maxminddb library
 * to lookup the country by IP address.
 *
 * Copyright 2013, MaxMind Inc.
 *
 */

#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "http_log.h"
#include "ap_config.h"
#include "apr_strings.h"
#include "util_script.h"
#include <netdb.h>
#include <arpa/inet.h>
#include "MMDB.h"

typedef struct {
    MMDB_s *mmdb;
    char *filename;
    int enabled;
    int flags;
} maxminddb_server_config_rec;

typedef maxminddb_server_config_rec maxminddb_dir_config_rec;

module AP_MODULE_DECLARE_DATA maxminddb_module;

static void set_env_for_ip(request_rec * r, const char *filename,
                           const char *ipaddr);

/* create a disabled directory entry */

static void *create_dir_config(apr_pool_t * p, char *d)
{

    maxminddb_dir_config_rec *dcfg;

    dcfg =
        (maxminddb_dir_config_rec *) apr_pcalloc(p,
                                                 sizeof
                                                 (maxminddb_dir_config_rec));
    dcfg->enabled = 0;

    return dcfg;
}

/* create a standard disabled server entry */

static void *create_server_config(apr_pool_t * p, server_rec * d)
{
    maxminddb_server_config_rec *conf =
        apr_pcalloc(p, sizeof(maxminddb_server_config_rec));
    if (!conf) {
        return NULL;
    }

    conf->mmdb = NULL;
    conf->enabled = 0;
    conf->flags = 0;
    return (void *)conf;
}

static apr_status_t cleanup(void *cfgdata)
{
    int i;
    maxminddb_server_config_rec *cfg = (maxminddb_server_config_rec *) cfgdata;
    MMDB_close(cfg->mmdb);
    cfg->mmdb = NULL;
    return APR_SUCCESS;
}

/* initialize maxminddb once per server ( even virtal server! ) */
static void server_init(apr_pool_t * p, server_rec * s)
{
    maxminddb_server_config_rec *cfg;
    int i;
    cfg = (maxminddb_server_config_rec *)
        ap_get_module_config(s->module_config, &maxminddb_module);

    if (!cfg->mmdb && cfg->filename) {
        cfg->mmdb = MMDB_open(cfg->filename, cfg->flags & 7);

    }
    if (!cfg->mmdb) {
        ap_log_error(APLOG_MARK, APLOG_ERR, 0,
                     s,
                     "[mod_maxminddb]: Error while opening data file %s",
                     cfg->filename);
    }

    apr_pool_cleanup_register(p, (void *)cfg, cleanup, cleanup);

}

static void child_init(apr_pool_t * p, server_rec * s)
{
    maxminddb_server_config_rec *cfg;
    int i, flags;

    cfg = (maxminddb_server_config_rec *)
        ap_get_module_config(s->module_config, &maxminddb_module);

}
<commit_msg>No need to initalize or cleanup on server startup/shutdown<commit_after>/* maxminddb module
 *
 * Version 0.1
 *
 * This module sets an environment variable to the remote country
 * based on the requestor's IP address.  It uses the maxminddb library
 * to lookup the country by IP address.
 *
 * Copyright 2013, MaxMind Inc.
 *
 */

#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "http_log.h"
#include "ap_config.h"
#include "apr_strings.h"
#include "util_script.h"
#include <netdb.h>
#include <arpa/inet.h>
#include "MMDB.h"

typedef struct {
    MMDB_s *mmdb;
    char *filename;
    int enabled;
    int flags;
} maxminddb_server_config_rec;

typedef maxminddb_server_config_rec maxminddb_dir_config_rec;

module AP_MODULE_DECLARE_DATA maxminddb_module;

static void set_env_for_ip(request_rec * r, const char *filename,
                           const char *ipaddr);

/* create a disabled directory entry */

static void *create_dir_config(apr_pool_t * p, char *d)
{

    maxminddb_dir_config_rec *dcfg;

    dcfg =
        (maxminddb_dir_config_rec *) apr_pcalloc(p,
                                                 sizeof
                                                 (maxminddb_dir_config_rec));
    dcfg->enabled = 0;

    return dcfg;
}

/* create a standard disabled server entry */

static void *create_server_config(apr_pool_t * p, server_rec * d)
{
    maxminddb_server_config_rec *conf =
        apr_pcalloc(p, sizeof(maxminddb_server_config_rec));
    if (!conf) {
        return NULL;
    }

    conf->mmdb = NULL;
    conf->enabled = 0;
    conf->flags = 0;
    return (void *)conf;
}

static apr_status_t cleanup(void *cfgdata)
{
    int i;
    maxminddb_server_config_rec *cfg = (maxminddb_server_config_rec *) cfgdata;
    return APR_SUCCESS;
}

/* initialize maxminddb once per server ( even virtal server! ) */
static void server_init(apr_pool_t * p, server_rec * s)
{
    maxminddb_server_config_rec *cfg;
    cfg = (maxminddb_server_config_rec *)
        ap_get_module_config(s->module_config, &maxminddb_module);

    apr_pool_cleanup_register(p, (void *)cfg, cleanup, cleanup);

}

static void child_init(apr_pool_t * p, server_rec * s)
{
    maxminddb_server_config_rec *cfg;
    int i, flags;

    cfg = (maxminddb_server_config_rec *)
        ap_get_module_config(s->module_config, &maxminddb_module);

}

{'fraction_non_alphanumeric': 0.09948778565799843, 'fraction_numerical': 0.003940110323089046, 'mean_word_length': 2.95404984423676, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1495761', 'n_tokens_mistral': 1779, 'n_tokens_neox': 1729, 'n_words': 408}