<commit_before>/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */

#include <GeoIP.h>
#include <GeoIPCity.h>
#include <glib.h>
#include <json-glib/json-glib.h>
#include <libsoup/soup.h>


static const gchar *attribution_text = "This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com\n";

enum ERROR_CODES {
        PARSE_ERR = 0,
        INVALID_DATA_ERR,
        INVALID_IP_ADDRESS_ERR,
        INVALID_ENTRY_ERR,
        DATABASE_ERR
};
static char *error_message_array [] = {
        "Can not parse the input",
        "Invalid data",
        "Invalid IP address format",
        "Can not find the IP address in the database",
        "Can not open the database. Set GEOIP_DATABASE_PATH env variable"
};

static void
add_json_object_for_address (JsonBuilder *builder,
                             const char *name,
                             const char *code,
                             const char *type)
{
        if (!name && !code)
                return;
        json_builder_begin_object (builder);
        if (name) {
                json_builder_set_member_name (builder, "name");
                json_builder_add_string_value (builder, name);<commit_msg>server: Better error message for missing database<commit_after>/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */

#include <GeoIP.h>
#include <GeoIPCity.h>
#include <glib.h>
#include <json-glib/json-glib.h>
#include <libsoup/soup.h>


static const gchar *attribution_text = "This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com\n";

enum ERROR_CODES {
        PARSE_ERR = 0,
        INVALID_DATA_ERR,
        INVALID_IP_ADDRESS_ERR,
        INVALID_ENTRY_ERR,
        DATABASE_ERR
};
static char *error_message_array [] = {
        "Can not parse the input",
        "Invalid data",
        "Invalid IP address format",
        "Can not find the IP address in the database",
        "Can not open the GeoLiteCity Binary database. Set GEOIP_DATABASE_PATH env variable."
};

static void
add_json_object_for_address (JsonBuilder *builder,
                             const char *name,
                             const char *code,
                             const char *type)
{
        if (!name && !code)
                return;
        json_builder_begin_object (builder);
        if (name) {
                json_builder_set_member_name (builder, "name");
                json_builder_add_string_value (builder, name);
{'fraction_non_alphanumeric': 0.09904912836767037, 'fraction_numerical': 0.002377179080824089, 'mean_word_length': 2.2371794871794872, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '124670', 'n_tokens_mistral': 780, 'n_tokens_neox': 752, 'n_words': 211}