/*
 *  Phusion Passenger - https://www.phusionpassenger.com/
 *  Copyright (c) 2010-2017 Phusion Holding B.V.
 *
 *  "Passenger", "Phusion Passenger" and "Union Station" are registered
 *  trademarks of Phusion Holding B.V.
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 */

/*
 * LocationConfig/AutoGeneratedMergeFunction.c is automatically generated from
 * LocationConfig/AutoGeneratedMergeFunction.c.cxxcodebuilder,
 * using definitions from src/ruby_supportlib/phusion_passenger/nginx/config_options.rb.
 * Edits to LocationConfig/AutoGeneratedMergeFunction.c will be lost.
 *
 * To update LocationConfig/AutoGeneratedMergeFunction.c:
 *   rake nginx
 *
 * To force regeneration of LocationConfig/AutoGeneratedMergeFunction.c:
 *   rm -f src/nginx_module/LocationConfig/AutoGeneratedMergeFunction.c
 *   rake src/nginx_module/LocationConfig/AutoGeneratedMergeFunction.c
 */

/*
 * 0: NGX_CONF_ERROR, 1: OK
 */
static int
passenger_merge_autogenerated_loc_conf(passenger_autogenerated_loc_conf_t *conf, passenger_autogenerated_loc_conf_t *prev, ngx_conf_t *cf) {
    ngx_conf_merge_str_value(conf->ruby,
        prev->ruby,
        "ruby");
    ngx_conf_merge_str_value(conf->python,
        prev->python,
        "python");
    ngx_conf_merge_str_value(conf->nodejs,
        prev->nodejs,
        "node");
    ngx_conf_merge_str_value(conf->meteor_app_settings,
        prev->meteor_app_settings,
        NULL);
    ngx_conf_merge_str_value(conf->environment,
        prev->environment,
        "production");
    ngx_conf_merge_value(conf->friendly_error_pages,
        prev->friendly_error_pages,
        NGX_CONF_UNSET);
    ngx_conf_merge_uint_value(conf->min_instances,
        prev->min_instances,
        1);
    ngx_conf_merge_uint_value(conf->start_timeout,
        prev->start_timeout,
        90);
    ngx_conf_merge_str_value(conf->user,
        prev->user,
        NULL);
    ngx_conf_merge_str_value(conf->group,
        prev->group,
        NULL);
    ngx_conf_merge_str_value(conf->app_group_name,
        prev->app_group_name,
        NULL);
    if (merge_string_array(cf, &prev->monitor_log_file, &conf->monitor_log_file) != NGX_OK) {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
            "cannot merge \"passenger_monitor_log_file\" configurations");
        return 0;
    }
    ngx_conf_merge_str_value(conf->app_root,
        prev->app_root,
        NULL);
    ngx_conf_merge_str_value(conf->app_rights,
        prev->app_rights,
        NULL);
    ngx_conf_merge_value(conf->debugger,
        prev->debugger,
        0);
    ngx_conf_merge_value(conf->max_preloader_idle_time,
        prev->max_preloader_idle_time,
        300);
    if (merge_string_keyval_table(cf, &prev->env_vars, &conf->env_vars) != NGX_OK) {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
            "cannot merge \"passenger_env_var\" configurations");
        return 0;
    }
    ngx_conf_merge_str_value(conf->spawn_method,
        prev->spawn_method,
        NULL);
    ngx_conf_merge_str_value(conf->direct_instance_request_address,
        prev->direct_instance_request_address,
        "127.0.0.1");
    ngx_conf_merge_value(conf->load_shell_envvars,
        prev->load_shell_envvars,
        1);
    ngx_conf_merge_value(conf->preload_bundler,
        prev->preload_bundler,
        0);
    ngx_conf_merge_uint_value(conf->max_request_queue_size,
        prev->max_request_queue_size,
        100);
    ngx_conf_merge_str_value(conf->app_type,
        prev->app_type,
        NULL);
    ngx_conf_merge_str_value(conf->startup_file,
        prev->startup_file,
        NULL);
    ngx_conf_merge_str_value(conf->app_start_command,
        prev->app_start_command,
        NULL);
    ngx_conf_merge_str_value(conf->restart_dir,
        prev->restart_dir,
        "tmp");
    ngx_conf_merge_value(conf->abort_websockets_on_process_shutdown,
        prev->abort_websockets_on_process_shutdown,
        1);
    ngx_conf_merge_value(conf->force_max_concurrent_requests_per_process,
        prev->force_max_concurrent_requests_per_process,
        -1);
    ngx_conf_merge_value(conf->enabled,
        prev->enabled,
        0);
    ngx_conf_merge_uint_value(conf->max_requests,
        prev->max_requests,
        0);
    if (merge_string_array(cf, &prev->base_uris, &conf->base_uris) != NGX_OK) {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
            "cannot merge \"passenger_base_uri\" configurations");
        return 0;
    }
    ngx_conf_merge_str_value(conf->document_root,
        prev->document_root,
        NULL);
    ngx_conf_merge_uint_value(conf->headers_hash_max_size,
        prev->headers_hash_max_size,
        512);
    ngx_conf_merge_uint_value(conf->headers_hash_bucket_size,
        prev->headers_hash_bucket_size,
        64);
    ngx_conf_merge_value(conf->request_queue_overflow_status_code,
        prev->request_queue_overflow_status_code,
        503);
    ngx_conf_merge_value(conf->spawn_exception_status_code,
        prev->spawn_exception_status_code,
        500);
    ngx_conf_merge_value(conf->buffer_upload,
        prev->buffer_upload,
        0);
    ngx_conf_merge_value(conf->sticky_sessions,
        prev->sticky_sessions,
        0);
    ngx_conf_merge_str_value(conf->sticky_sessions_cookie_name,
        prev->sticky_sessions_cookie_name,
        "_passenger_route");
    ngx_conf_merge_str_value(conf->sticky_sessions_cookie_attributes,
        prev->sticky_sessions_cookie_attributes,
        "SameSite=Lax; Secure;");
    ngx_conf_merge_str_value(conf->vary_turbocache_by_cookie,
        prev->vary_turbocache_by_cookie,
        NULL);
    ngx_conf_merge_str_value(conf->app_log_file,
        prev->app_log_file,
        NULL);

    return 1;
}

