<commit_before>#include "avatars_gen.h"


/* Directives handlers declarations */
static char *ngx_http_avatars_gen_found_cb(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_http_avatars_gen_bg_color_found_cb(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_http_avatars_gen_contour_color_found_cb(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_http_avatars_gen_font_color_found_cb(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);

/* Configuration structure */
typedef struct {
    avatars_gen_rgb bg_color;
    avatars_gen_rgb contour_color;
    avatars_gen_rgb font_color;
    ngx_str_t font_face;
} ngx_http_avatars_gen_loc_conf_t;

/* Allocate memory for configuration */
static void *ngx_http_avatars_gen_create_loc_conf(ngx_conf_t *cf) {
    unsigned char *default_font_face;
    ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "create loc conf");
    ngx_http_avatars_gen_loc_conf_t  *conf;
    conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_avatars_gen_loc_conf_t));
    if (conf == NULL) {
        return NULL;
    }
    /* Set default directives values */
    conf->bg_color.red = 0.22;
    conf->bg_color.green = 0.8;
    conf->bg_color.blue = 0.8;
    conf->contour_color.red = 0;
    conf->contour_color.green = 0.12;
    conf->contour_color.blue = 0.25;
    conf->font_color.red = 1.0;
    conf->font_color.green = 1.0;
    conf->font_color.blue = 1.0;
    default_font_face = ngx_palloc(cf->pool, 5);
    if (default_font_face == NULL) {
        return NULL;
    }
    ngx_memcpy(default_font_face, "sans", 4);
    conf->font_face.len = 4;
    conf->font_face.data = default_font_face;
    return conf;
}

/* Module directives */
static ngx_command_t ngx_http_avatars_gen_commands[] = {
    { ngx_string("avatars_gen"),
      NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
      ngx_http_avatars_gen_found_cb,
      0,
      0,
      NULL},
    { ngx_string("avatars_gen_bg_color"),
      NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
      ngx_http_avatars_gen_bg_color_found_cb,
      NGX_HTTP_LOC_CONF_OFFSET,
      0,
      NULL},
    { ngx_string("avatars_gen_contour_color"),
      NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
      ngx_http_avatars_gen_contour_color_found_cb,
      NGX_HTTP_LOC_CONF_OFFSET,
      offsetof(ngx_http_avatars_gen_loc_conf_t, contour_color),
      NULL},
    { ngx_string("avatars_gen_font_color"),
      NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
      ngx_http_avatars_gen_font_color_found_cb,
      NGX_HTTP_LOC_CONF_OFFSET,
      offsetof(ngx_http_avatars_gen_loc_conf_t, font_color),
      NULL},
    { ngx_string("avatars_gen_font_face"),
      NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
      ngx_conf_set_str_slot,
      NGX_HTTP_LOC_CONF_OFFSET,
      offsetof(ngx_http_avatars_gen_loc_conf_t, font_face),
      NULL},

    ngx_null_command
};


static ngx_http_module_t ngx_http_avatars_gen_module_ctx = {
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    ngx_http_avatars_gen_create_loc_conf,
    NULL
};


/*
 * The module which binds the context and commands
 */
ngx_module_t ngx_http_avatars_gen_module = {
    NGX_MODULE_V1,
    &ngx_http_avatars_gen_module_ctx,
    ngx_http_avatars_gen_commands,
    NGX_HTTP_MODULE,
    NULL,
    NULL,
    NULL,<commit_msg>:wrench: fix duplicate directive error<commit_after>#include "avatars_gen.h"


/* Directives handlers declarations */
static char *ngx_http_avatars_gen_found_cb(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_http_avatars_gen_bg_color_found_cb(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_http_avatars_gen_contour_color_found_cb(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_http_avatars_gen_font_color_found_cb(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);

/* Configuration structure */
typedef struct {
    avatars_gen_rgb bg_color;
    avatars_gen_rgb contour_color;
    avatars_gen_rgb font_color;
    ngx_str_t font_face;
} ngx_http_avatars_gen_loc_conf_t;

/* Allocate memory for configuration */
static void *ngx_http_avatars_gen_create_loc_conf(ngx_conf_t *cf) {
    ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "create loc conf");
    ngx_http_avatars_gen_loc_conf_t *conf;
    conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_avatars_gen_loc_conf_t));
    if (conf == NULL) {
        return NULL;
    }
    /* Set default directives values */
    conf->bg_color.red = 0.22;
    conf->bg_color.green = 0.8;
    conf->bg_color.blue = 0.8;
    conf->contour_color.red = 0;
    conf->contour_color.green = 0.12;
    conf->contour_color.blue = 0.25;
    conf->font_color.red = 1.0;
    conf->font_color.green = 1.0;
    conf->font_color.blue = 1.0;
    return conf;
}

/* Merge location configuration */
static char *ngx_http_avatars_gen_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) {
    ngx_http_avatars_gen_loc_conf_t *conf = child;
    unsigned char *default_font_face;
    if (!conf->font_face.len) {
        default_font_face = ngx_palloc(cf->pool, 5);
        if (default_font_face == NULL) {
            return NGX_CONF_ERROR;
        }
        ngx_memcpy(default_font_face, "sans", 4);
        conf->font_face.len = 4;
        conf->font_face.data = default_font_face;
    }
    return NGX_CONF_OK;
}


/* Module directives */
static ngx_command_t ngx_http_avatars_gen_commands[] = {
    { ngx_string("avatars_gen"),
      NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
      ngx_http_avatars_gen_found_cb,
      0,
      0,
      NULL},
    { ngx_string("avatars_gen_bg_color"),
      NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
      ngx_http_avatars_gen_bg_color_found_cb,
      NGX_HTTP_LOC_CONF_OFFSET,
      0,
      NULL},
    { ngx_string("avatars_gen_contour_color"),
      NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
      ngx_http_avatars_gen_contour_color_found_cb,
      NGX_HTTP_LOC_CONF_OFFSET,
      offsetof(ngx_http_avatars_gen_loc_conf_t, contour_color),
      NULL},
    { ngx_string("avatars_gen_font_color"),
      NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
      ngx_http_avatars_gen_font_color_found_cb,
      NGX_HTTP_LOC_CONF_OFFSET,
      offsetof(ngx_http_avatars_gen_loc_conf_t, font_color),
      NULL},
    { ngx_string("avatars_gen_font_face"),
      NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
      ngx_conf_set_str_slot,
      NGX_HTTP_LOC_CONF_OFFSET,
      offsetof(ngx_http_avatars_gen_loc_conf_t, font_face),
      NULL},

    ngx_null_command
};


static ngx_http_module_t ngx_http_avatars_gen_module_ctx = {
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    ngx_http_avatars_gen_create_loc_conf,
    ngx_http_avatars_gen_merge_loc_conf
};


/*
 * The module which binds the context and commands
 */
ngx_module_t ngx_http_avatars_gen_module = {
    NGX_MODULE_V1,
    &ngx_http_avatars_gen_module_ctx,
    ngx_http_avatars_gen_commands,
    NGX_HTTP_MODULE,
    NULL,
    NULL,
    NULL,
{'fraction_non_alphanumeric': 0.09084227546670587, 'fraction_numerical': 0.0094076142878142, 'mean_word_length': 3.9555717407137654, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, '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': '4020451', 'n_tokens_mistral': 2850, 'n_tokens_neox': 2702, 'n_words': 387}