From 0a3fe10f16b04c70f15a80f76733fb20a32117b7 Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Tue, 6 Apr 2010 23:09:46 +0200 Subject: [PATCH] Added XML file for configurations. The XML file will be used to auto generate the configuratioin code and the corresponding documentation in the future. The perl script parses this XML format and outputs gen_config.{h,c} files accordingly. --- src/core/config.c | 418 +------------------------- src/core/config.h | 91 +----- src/core/config.pl | 164 +++++++++++ src/core/config.xml | 663 ++++++++++++++++++++++++++++++++++++++++++ src/core/gen_config.c | 306 +++++++++++++++++++ src/core/gen_config.h | 86 ++++++ 6 files changed, 1222 insertions(+), 506 deletions(-) create mode 100755 src/core/config.pl create mode 100644 src/core/config.xml create mode 100644 src/core/gen_config.c create mode 100644 src/core/gen_config.h diff --git a/src/core/config.c b/src/core/config.c index 151ebc7..48d48d0 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -105,330 +105,7 @@ { \ LOG_WARN("Configuration option %s deprecated and ingnored.", key); \ return 0; \ - } \ - -/* default configuration values */ -#define DEF_SERVER_BIND_ADDR "any" -#define DEF_SERVER_PORT 1511 -#define DEF_SERVER_BACKLOG 50 -#define DEF_SERVER_ALT_PORTS "" -#define DEF_HUB_NAME "uhub" -#define DEF_HUB_DESCRIPTION "" -#define DEF_HUB_ENABLED 1 -#define DEF_FILE_ACL "" -#define DEF_FILE_MOTD "" -#define DEF_FILE_RULES "" -#define DEF_MAX_USERS 500 -#define DEF_MAX_CHAT_HISTORY 20 -#define DEF_MAX_LOGOUT_LOG 100 -#define DEF_MAX_RECV_BUFFER 4096 -#define DEF_MAX_SEND_BUFFER 131072 -#define DEF_MAX_SEND_BUFFER_SOFT 98304 -#define DEF_SHOW_BANNER 1 -#define DEF_SHOW_BANNER_SYS_INFO 1 -#define DEF_REGISTERED_USERS_ONLY 0 -#define DEF_OBSOLETE_CLIENTS 0 -#define DEF_CHAT_ONLY 0 -#define DEF_CHAT_IS_PRIVILEGED 0 -#define DEF_LOW_BANDWIDTH_MODE 0 -#define DEF_LIMIT_MAX_HUBS_USER 0 -#define DEF_LIMIT_MAX_HUBS_REG 0 -#define DEF_LIMIT_MAX_HUBS_OP 0 -#define DEF_LIMIT_MAX_HUBS 0 -#define DEF_LIMIT_MIN_HUBS_USER 0 -#define DEF_LIMIT_MIN_HUBS_REG 0 -#define DEF_LIMIT_MIN_HUBS_OP 0 -#define DEF_LIMIT_MIN_SHARE 0 -#define DEF_LIMIT_MAX_SHARE 0 -#define DEF_LIMIT_MIN_SLOTS 0 -#define DEF_LIMIT_MAX_SLOTS 0 -#define DEF_FLOOD_INTERVAL 0 -#define DEF_FLOOD_CHAT 0 -#define DEF_FLOOD_CONNECT 0 -#define DEF_FLOOD_SEARCH 0 -#define DEF_FLOOD_UPDATE 0 -#define DEF_FLOOD_EXTRAS 0 -#define DEF_TLS_ENABLE 0 -#define DEF_TLS_REQUIRE 1 -#define DEF_TLS_PRIVATE_KEY "" -#define DEF_TLS_CERTIFICATE "" -#define DEF_MSG_HUB_FULL "Hub is full" -#define DEF_MSG_HUB_DISABLED "Hub is disabled" -#define DEF_MSG_HUB_REGISTERED_USERS_ONLY "Hub is for registered users only" -#define DEF_MSG_INF_ERROR_NICK_MISSING "No nickname given" -#define DEF_MSG_INF_ERROR_NICK_MULTIPLE "Multiple nicknames given" -#define DEF_MSG_INF_ERROR_NICK_INVALID "Nickname is invalid" -#define DEF_MSG_INF_ERROR_NICK_LONG "Nickname too long" -#define DEF_MSG_INF_ERROR_NICK_SHORT "Nickname too short" -#define DEF_MSG_INF_ERROR_NICK_SPACES "Nickname cannot start with spaces" -#define DEF_MSG_INF_ERROR_NICK_BAD_CHARS "Nickname contains invalid characters" -#define DEF_MSG_INF_ERROR_NICK_NOT_UTF8 "Nickname is not valid utf8" -#define DEF_MSG_INF_ERROR_NICK_TAKEN "Nickname is already in use" -#define DEF_MSG_INF_ERROR_NICK_RESTRICTED "Nickname cannot be used on this hub" -#define DEF_MSG_INF_ERROR_CID_INVALID "CID is not valid" -#define DEF_MSG_INF_ERROR_CID_MISSING "CID is not specified" -#define DEF_MSG_INF_ERROR_CID_TAKEN "CID is taken" -#define DEF_MSG_INF_ERROR_PID_MISSING "PID is not specified" -#define DEF_MSG_INF_ERROR_PID_INVALID "PID is invalid" -#define DEF_MSG_BAN_PERMANENTLY "Banned permanently" -#define DEF_MSG_BAN_TEMPORARILY "Banned temporarily" -#define DEF_MSG_AUTH_INVALID_PASSWORD "Password is wrong" -#define DEF_MSG_AUTH_USER_NOT_FOUND "User not found in password database" -#define DEF_MSG_ERROR_NO_MEMORY "No memory" -#define DEF_MSG_USER_SHARE_SIZE_LOW "User is not sharing enough" -#define DEF_MSG_USER_SHARE_SIZE_HIGH "User is sharing too much" -#define DEF_MSG_USER_SLOTS_LOW "User have too few upload slots." -#define DEF_MSG_USER_SLOTS_HIGH "User have too many upload slots." -#define DEF_MSG_USER_HUB_LIMIT_LOW "User is on too few hubs." -#define DEF_MSG_USER_HUB_LIMIT_HIGH "User is on too many hubs." -#define DEF_MSG_FLOOD_CHAT "Chat flood detected, messages are dropped." -#define DEF_MSG_FLOOD_CONNECT "Connect flood detected, connection refused." -#define DEF_MSG_FLOOD_SEARCH "Search flood detected, search is stopped." -#define DEF_MSG_FLOOD_UPDATE "Update flood detected." -#define DEF_MSG_FLOOD_EXTRAS "Flood detected." -#define DEF_MSG_PROTO_NO_COMMON_HASH "No common hash algorithm." -#define DEF_MSG_PROTO_OBSOLETE_ADC0 "Your client does not support ADC/1.0." - -void config_defaults(struct hub_config* config) -{ - DEFAULT_STRING (server_bind_addr, DEF_SERVER_BIND_ADDR); - DEFAULT_STRING (hub_name, DEF_HUB_NAME); - DEFAULT_STRING (hub_description, DEF_HUB_DESCRIPTION); - DEFAULT_BOOLEAN(hub_enabled, DEF_HUB_ENABLED); - DEFAULT_STRING (file_acl, DEF_FILE_ACL); - DEFAULT_STRING (file_motd, DEF_FILE_MOTD); - DEFAULT_STRING (file_rules, DEF_FILE_RULES); - DEFAULT_INTEGER(server_port, DEF_SERVER_PORT); - DEFAULT_INTEGER(server_listen_backlog, DEF_SERVER_BACKLOG); - DEFAULT_STRING (server_alt_ports, DEF_SERVER_ALT_PORTS); - DEFAULT_INTEGER(max_users, DEF_MAX_USERS); - DEFAULT_INTEGER(max_chat_history, DEF_MAX_CHAT_HISTORY); - DEFAULT_INTEGER(max_logout_log, DEF_MAX_LOGOUT_LOG); - DEFAULT_INTEGER(max_recv_buffer, DEF_MAX_RECV_BUFFER); - DEFAULT_INTEGER(max_send_buffer, DEF_MAX_SEND_BUFFER); - DEFAULT_INTEGER(max_send_buffer_soft, DEF_MAX_SEND_BUFFER_SOFT); - DEFAULT_BOOLEAN(show_banner, DEF_SHOW_BANNER); - DEFAULT_BOOLEAN(show_banner_sys_info, DEF_SHOW_BANNER_SYS_INFO); - DEFAULT_BOOLEAN(obsolete_clients, DEF_OBSOLETE_CLIENTS); - DEFAULT_BOOLEAN(chat_only, DEF_CHAT_ONLY); - DEFAULT_BOOLEAN(chat_is_privileged, DEF_CHAT_IS_PRIVILEGED); - DEFAULT_BOOLEAN(low_bandwidth_mode, DEF_LOW_BANDWIDTH_MODE); - DEFAULT_BOOLEAN(registered_users_only, DEF_REGISTERED_USERS_ONLY); - - /* Limits enforced on users */ - DEFAULT_INTEGER(limit_max_hubs_user, DEF_LIMIT_MAX_HUBS_USER); - DEFAULT_INTEGER(limit_max_hubs_reg, DEF_LIMIT_MAX_HUBS_REG); - DEFAULT_INTEGER(limit_max_hubs_op, DEF_LIMIT_MAX_HUBS_OP); - DEFAULT_INTEGER(limit_min_hubs_user, DEF_LIMIT_MIN_HUBS_USER); - DEFAULT_INTEGER(limit_min_hubs_reg, DEF_LIMIT_MIN_HUBS_REG); - DEFAULT_INTEGER(limit_min_hubs_op, DEF_LIMIT_MIN_HUBS_OP); - DEFAULT_INTEGER(limit_max_hubs, DEF_LIMIT_MAX_HUBS); - DEFAULT_INTEGER(limit_min_share, DEF_LIMIT_MIN_SHARE); - DEFAULT_INTEGER(limit_max_share, DEF_LIMIT_MAX_SHARE); - DEFAULT_INTEGER(limit_min_slots, DEF_LIMIT_MIN_SLOTS); - DEFAULT_INTEGER(limit_max_slots, DEF_LIMIT_MAX_SLOTS); - - /* Flood control */ - DEFAULT_INTEGER(flood_ctl_interval, DEF_FLOOD_INTERVAL); - DEFAULT_INTEGER(flood_ctl_chat, DEF_FLOOD_CHAT); - DEFAULT_INTEGER(flood_ctl_connect, DEF_FLOOD_CONNECT); - DEFAULT_INTEGER(flood_ctl_search, DEF_FLOOD_SEARCH); - DEFAULT_INTEGER(flood_ctl_update, DEF_FLOOD_UPDATE); - DEFAULT_INTEGER(flood_ctl_extras, DEF_FLOOD_EXTRAS); - - /* Status/error strings */ - DEFAULT_STRING (msg_hub_full, DEF_MSG_HUB_FULL); - DEFAULT_STRING (msg_hub_disabled, DEF_MSG_HUB_DISABLED) - DEFAULT_STRING (msg_hub_registered_users_only, DEF_MSG_HUB_REGISTERED_USERS_ONLY); - DEFAULT_STRING (msg_inf_error_nick_missing, DEF_MSG_INF_ERROR_NICK_MISSING); - DEFAULT_STRING (msg_inf_error_nick_multiple, DEF_MSG_INF_ERROR_NICK_MULTIPLE); - DEFAULT_STRING (msg_inf_error_nick_invalid, DEF_MSG_INF_ERROR_NICK_INVALID); - DEFAULT_STRING (msg_inf_error_nick_long, DEF_MSG_INF_ERROR_NICK_LONG); - DEFAULT_STRING (msg_inf_error_nick_short, DEF_MSG_INF_ERROR_NICK_SHORT); - DEFAULT_STRING (msg_inf_error_nick_spaces, DEF_MSG_INF_ERROR_NICK_SPACES); - DEFAULT_STRING (msg_inf_error_nick_bad_chars, DEF_MSG_INF_ERROR_NICK_BAD_CHARS); - DEFAULT_STRING (msg_inf_error_nick_not_utf8, DEF_MSG_INF_ERROR_NICK_NOT_UTF8); - DEFAULT_STRING (msg_inf_error_nick_taken, DEF_MSG_INF_ERROR_NICK_TAKEN); - DEFAULT_STRING (msg_inf_error_nick_restricted, DEF_MSG_INF_ERROR_NICK_RESTRICTED); - DEFAULT_STRING (msg_inf_error_cid_invalid, DEF_MSG_INF_ERROR_CID_INVALID); - DEFAULT_STRING (msg_inf_error_cid_missing, DEF_MSG_INF_ERROR_CID_MISSING); - DEFAULT_STRING (msg_inf_error_cid_taken, DEF_MSG_INF_ERROR_CID_TAKEN); - DEFAULT_STRING (msg_inf_error_pid_missing, DEF_MSG_INF_ERROR_PID_MISSING); - DEFAULT_STRING (msg_inf_error_pid_invalid, DEF_MSG_INF_ERROR_PID_INVALID); - DEFAULT_STRING (msg_ban_permanently, DEF_MSG_BAN_PERMANENTLY); - DEFAULT_STRING (msg_ban_temporarily, DEF_MSG_BAN_TEMPORARILY); - DEFAULT_STRING (msg_auth_invalid_password, DEF_MSG_AUTH_INVALID_PASSWORD); - DEFAULT_STRING (msg_auth_user_not_found, DEF_MSG_AUTH_USER_NOT_FOUND); - DEFAULT_STRING (msg_error_no_memory, DEF_MSG_ERROR_NO_MEMORY); - DEFAULT_STRING (msg_user_share_size_low, DEF_MSG_USER_SHARE_SIZE_LOW); - DEFAULT_STRING (msg_user_share_size_high, DEF_MSG_USER_SHARE_SIZE_HIGH); - DEFAULT_STRING (msg_user_slots_low, DEF_MSG_USER_SLOTS_LOW); - DEFAULT_STRING (msg_user_slots_high, DEF_MSG_USER_SLOTS_HIGH); - DEFAULT_STRING (msg_user_hub_limit_low, DEF_MSG_USER_HUB_LIMIT_LOW); - DEFAULT_STRING (msg_user_hub_limit_high, DEF_MSG_USER_HUB_LIMIT_HIGH); - DEFAULT_STRING (msg_user_flood_chat, DEF_MSG_FLOOD_CHAT); - DEFAULT_STRING (msg_user_flood_connect, DEF_MSG_FLOOD_CONNECT); - DEFAULT_STRING (msg_user_flood_search, DEF_MSG_FLOOD_SEARCH); - DEFAULT_STRING (msg_user_flood_update, DEF_MSG_FLOOD_UPDATE); - DEFAULT_STRING (msg_user_flood_extras, DEF_MSG_FLOOD_EXTRAS); - DEFAULT_STRING (msg_proto_no_common_hash, DEF_MSG_PROTO_NO_COMMON_HASH); - DEFAULT_STRING (msg_proto_obsolete_adc0, DEF_MSG_PROTO_OBSOLETE_ADC0); - - DEFAULT_INTEGER(tls_enable, DEF_TLS_ENABLE); - DEFAULT_INTEGER(tls_require, DEF_TLS_REQUIRE); - DEFAULT_STRING (tls_certificate, DEF_TLS_CERTIFICATE); - DEFAULT_STRING (tls_private_key, DEF_TLS_PRIVATE_KEY); -} - - -static int apply_config(struct hub_config* config, char* key, char* data, int line_count) -{ - GET_STR (file_acl); - GET_STR (file_motd); - GET_STR (file_rules); - GET_STR (server_bind_addr); - GET_INT (server_port); - GET_INT (server_listen_backlog); - GET_STR (server_alt_ports); - GET_STR (hub_name); - GET_STR (hub_description); - GET_BOOL(hub_enabled); - GET_INT (max_users); - GET_INT (max_chat_history); - GET_INT (max_logout_log); - GET_INT (max_recv_buffer); - GET_INT (max_send_buffer); - GET_INT (max_send_buffer_soft); - GET_BOOL(show_banner); - GET_BOOL(show_banner_sys_info); - GET_BOOL(obsolete_clients); - GET_BOOL(chat_only); - GET_BOOL(chat_is_privileged); - GET_BOOL(low_bandwidth_mode); - GET_BOOL(registered_users_only); - - /* Limits enforced on users */ - GET_INT(limit_max_hubs_user); - GET_INT(limit_max_hubs_reg); - GET_INT(limit_max_hubs_op); - GET_INT(limit_min_hubs_user); - GET_INT(limit_min_hubs_reg); - GET_INT(limit_min_hubs_op); - GET_INT(limit_max_hubs); - GET_INT(limit_min_share); - GET_INT(limit_max_share); - GET_INT(limit_min_slots); - GET_INT(limit_max_slots); - - GET_INT(flood_ctl_interval); - GET_INT(flood_ctl_chat); - GET_INT(flood_ctl_connect); - GET_INT(flood_ctl_search); - GET_INT(flood_ctl_update); - GET_INT(flood_ctl_extras); - - /* Status/error strings */ - GET_STR (msg_hub_full); - GET_STR (msg_hub_disabled); - GET_STR (msg_hub_registered_users_only); - GET_STR (msg_inf_error_nick_missing); - GET_STR (msg_inf_error_nick_multiple); - GET_STR (msg_inf_error_nick_invalid); - GET_STR (msg_inf_error_nick_long); - GET_STR (msg_inf_error_nick_short); - GET_STR (msg_inf_error_nick_spaces); - GET_STR (msg_inf_error_nick_bad_chars); - GET_STR (msg_inf_error_nick_not_utf8); - GET_STR (msg_inf_error_nick_taken); - GET_STR (msg_inf_error_nick_restricted); - GET_STR (msg_inf_error_cid_invalid); - GET_STR (msg_inf_error_cid_missing); - GET_STR (msg_inf_error_cid_taken); - GET_STR (msg_inf_error_pid_missing); - GET_STR (msg_inf_error_pid_invalid); - GET_STR (msg_ban_permanently); - GET_STR (msg_ban_temporarily); - GET_STR (msg_auth_invalid_password); - GET_STR (msg_auth_user_not_found); - GET_STR (msg_error_no_memory); - GET_STR (msg_user_share_size_low); - GET_STR (msg_user_share_size_high); - GET_STR (msg_user_slots_low); - GET_STR (msg_user_slots_high); - GET_STR (msg_user_hub_limit_low); - GET_STR (msg_user_hub_limit_high); - GET_STR (msg_user_flood_chat); - GET_STR (msg_user_flood_connect); - GET_STR (msg_user_flood_search); - GET_STR (msg_user_flood_update); - GET_STR (msg_user_flood_extras); - GET_STR (msg_proto_no_common_hash); - GET_STR (msg_proto_obsolete_adc0); - - /* TLS/SSL related */ - GET_BOOL(tls_enable); - GET_BOOL(tls_require); - GET_STR (tls_certificate); - GET_STR (tls_private_key); - - /* Still here -- unknown directive */ - LOG_ERROR("Unknown configuration directive: '%s'", key); - return -1; -} - - -void free_config(struct hub_config* config) -{ - hub_free(config->server_bind_addr); - hub_free(config->server_alt_ports); - hub_free(config->file_motd); - hub_free(config->file_acl); - hub_free(config->file_rules); - hub_free(config->hub_name); - hub_free(config->hub_description); - - hub_free(config->msg_hub_full); - hub_free(config->msg_hub_disabled); - hub_free(config->msg_hub_registered_users_only); - hub_free(config->msg_inf_error_nick_missing); - hub_free(config->msg_inf_error_nick_multiple); - hub_free(config->msg_inf_error_nick_invalid); - hub_free(config->msg_inf_error_nick_long); - hub_free(config->msg_inf_error_nick_short); - hub_free(config->msg_inf_error_nick_spaces); - hub_free(config->msg_inf_error_nick_bad_chars); - hub_free(config->msg_inf_error_nick_not_utf8); - hub_free(config->msg_inf_error_nick_taken); - hub_free(config->msg_inf_error_nick_restricted); - hub_free(config->msg_inf_error_cid_invalid); - hub_free(config->msg_inf_error_cid_missing); - hub_free(config->msg_inf_error_cid_taken); - hub_free(config->msg_inf_error_pid_missing); - hub_free(config->msg_inf_error_pid_invalid); - hub_free(config->msg_ban_permanently); - hub_free(config->msg_ban_temporarily); - hub_free(config->msg_auth_invalid_password); - hub_free(config->msg_auth_user_not_found); - hub_free(config->msg_error_no_memory); - hub_free(config->msg_user_share_size_low); - hub_free(config->msg_user_share_size_high); - hub_free(config->msg_user_slots_low); - hub_free(config->msg_user_slots_high); - hub_free(config->msg_user_hub_limit_low); - hub_free(config->msg_user_hub_limit_high); - hub_free(config->msg_user_flood_chat); - hub_free(config->msg_user_flood_connect); - hub_free(config->msg_user_flood_search); - hub_free(config->msg_user_flood_update); - hub_free(config->msg_user_flood_extras); - hub_free(config->msg_proto_no_common_hash); - hub_free(config->msg_proto_obsolete_adc0); - - hub_free(config->tls_certificate); - hub_free(config->tls_private_key); - - memset(config, 0, sizeof(struct hub_config)); -} + } #define DUMP_STR(NAME, DEFAULT) \ if (ignore_defaults) \ @@ -448,7 +125,6 @@ void free_config(struct hub_config* config) else \ fprintf(stdout, "%s = %d\n", #NAME , config->NAME); \ - #define DUMP_BOOL(NAME, DEFAULT) \ if (ignore_defaults) \ { \ @@ -458,98 +134,8 @@ void free_config(struct hub_config* config) else \ fprintf(stdout, "%s = %s\n", #NAME , (config->NAME ? "yes" : "no")); -void dump_config(struct hub_config* config, int ignore_defaults) -{ - DUMP_STR (file_acl, DEF_FILE_ACL); - DUMP_STR (file_motd, DEF_FILE_MOTD); - DUMP_STR (file_rules, DEF_FILE_RULES); - DUMP_STR (server_bind_addr, DEF_SERVER_BIND_ADDR); - DUMP_INT (server_port, DEF_SERVER_PORT); - DUMP_INT (server_listen_backlog, DEF_SERVER_BACKLOG); - DUMP_STR (server_alt_ports, DEF_SERVER_ALT_PORTS); - DUMP_STR (hub_name, DEF_HUB_NAME); - DUMP_STR (hub_description, DEF_HUB_DESCRIPTION); - DUMP_BOOL(hub_enabled, DEF_HUB_ENABLED); - DUMP_INT (max_users, DEF_MAX_USERS); - DUMP_INT (max_chat_history, DEF_MAX_CHAT_HISTORY); - DUMP_INT (max_logout_log, DEF_MAX_LOGOUT_LOG); - DUMP_INT (max_recv_buffer, DEF_MAX_RECV_BUFFER); - DUMP_INT (max_send_buffer, DEF_MAX_SEND_BUFFER); - DUMP_INT (max_send_buffer_soft, DEF_MAX_SEND_BUFFER_SOFT); - DUMP_BOOL(show_banner, DEF_SHOW_BANNER); - DUMP_BOOL(show_banner_sys_info, DEF_SHOW_BANNER_SYS_INFO); - DUMP_BOOL(obsolete_clients, DEF_OBSOLETE_CLIENTS); - DUMP_BOOL(chat_only, DEF_CHAT_ONLY); - DUMP_BOOL(chat_is_privileged, DEF_CHAT_IS_PRIVILEGED); - DUMP_BOOL(low_bandwidth_mode, DEF_LOW_BANDWIDTH_MODE); - DUMP_BOOL(registered_users_only, DEF_REGISTERED_USERS_ONLY); - -#ifdef SSL_SUPPORT - DUMP_BOOL(tls_enable, DEF_TLS_ENABLE); - DUMP_BOOL(tls_require, DEF_TLS_REQUIRE); - DUMP_STR (tls_certificate, DEF_TLS_CERTIFICATE); - DUMP_STR (tls_private_key, DEF_TLS_PRIVATE_KEY); -#endif - - /* Limits enforced on users */ - DUMP_INT(limit_max_hubs_user, DEF_LIMIT_MAX_HUBS_USER); - DUMP_INT(limit_max_hubs_reg, DEF_LIMIT_MAX_HUBS_REG); - DUMP_INT(limit_max_hubs_op, DEF_LIMIT_MAX_HUBS_OP); - DUMP_INT(limit_min_hubs_user, DEF_LIMIT_MIN_HUBS_USER); - DUMP_INT(limit_min_hubs_reg, DEF_LIMIT_MIN_HUBS_REG); - DUMP_INT(limit_min_hubs_op, DEF_LIMIT_MIN_HUBS_OP); - DUMP_INT(limit_max_hubs, DEF_LIMIT_MAX_HUBS); - DUMP_INT(limit_min_share, DEF_LIMIT_MIN_SHARE); - DUMP_INT(limit_max_share, DEF_LIMIT_MAX_SHARE); - DUMP_INT(limit_min_slots, DEF_LIMIT_MIN_SLOTS); - DUMP_INT(limit_max_slots, DEF_LIMIT_MAX_SLOTS); - - DUMP_INT(flood_ctl_interval, DEF_FLOOD_INTERVAL); - DUMP_INT(flood_ctl_chat, DEF_FLOOD_CHAT); - DUMP_INT(flood_ctl_connect, DEF_FLOOD_CONNECT); - DUMP_INT(flood_ctl_search, DEF_FLOOD_SEARCH); - DUMP_INT(flood_ctl_update, DEF_FLOOD_UPDATE); - DUMP_INT(flood_ctl_extras, DEF_FLOOD_EXTRAS); - - /* Status/error strings */ - DUMP_STR (msg_hub_full, DEF_MSG_HUB_FULL); - DUMP_STR (msg_hub_disabled, DEF_MSG_HUB_DISABLED); - DUMP_STR (msg_hub_registered_users_only, DEF_MSG_HUB_REGISTERED_USERS_ONLY); - DUMP_STR (msg_inf_error_nick_missing, DEF_MSG_INF_ERROR_NICK_MISSING); - DUMP_STR (msg_inf_error_nick_multiple, DEF_MSG_INF_ERROR_NICK_MULTIPLE); - DUMP_STR (msg_inf_error_nick_invalid, DEF_MSG_INF_ERROR_NICK_INVALID); - DUMP_STR (msg_inf_error_nick_long, DEF_MSG_INF_ERROR_NICK_LONG); - DUMP_STR (msg_inf_error_nick_short, DEF_MSG_INF_ERROR_NICK_SHORT); - DUMP_STR (msg_inf_error_nick_spaces, DEF_MSG_INF_ERROR_NICK_SPACES); - DUMP_STR (msg_inf_error_nick_bad_chars, DEF_MSG_INF_ERROR_NICK_BAD_CHARS); - DUMP_STR (msg_inf_error_nick_not_utf8, DEF_MSG_INF_ERROR_NICK_NOT_UTF8); - DUMP_STR (msg_inf_error_nick_taken, DEF_MSG_INF_ERROR_NICK_TAKEN); - DUMP_STR (msg_inf_error_nick_restricted, DEF_MSG_INF_ERROR_NICK_RESTRICTED); - DUMP_STR (msg_inf_error_cid_invalid, DEF_MSG_INF_ERROR_CID_INVALID); - DUMP_STR (msg_inf_error_cid_missing, DEF_MSG_INF_ERROR_CID_MISSING); - DUMP_STR (msg_inf_error_cid_taken, DEF_MSG_INF_ERROR_CID_TAKEN); - DUMP_STR (msg_inf_error_pid_missing, DEF_MSG_INF_ERROR_PID_MISSING); - DUMP_STR (msg_inf_error_pid_invalid, DEF_MSG_INF_ERROR_PID_INVALID); - DUMP_STR (msg_ban_permanently, DEF_MSG_BAN_PERMANENTLY); - DUMP_STR (msg_ban_temporarily, DEF_MSG_BAN_TEMPORARILY); - DUMP_STR (msg_auth_invalid_password, DEF_MSG_AUTH_INVALID_PASSWORD); - DUMP_STR (msg_auth_user_not_found, DEF_MSG_AUTH_USER_NOT_FOUND); - DUMP_STR (msg_error_no_memory, DEF_MSG_ERROR_NO_MEMORY); - DUMP_STR (msg_user_share_size_low, DEF_MSG_USER_SHARE_SIZE_LOW); - DUMP_STR (msg_user_share_size_high, DEF_MSG_USER_SHARE_SIZE_HIGH); - DUMP_STR (msg_user_slots_low, DEF_MSG_USER_SLOTS_LOW); - DUMP_STR (msg_user_slots_high, DEF_MSG_USER_SLOTS_HIGH); - DUMP_STR (msg_user_hub_limit_low, DEF_MSG_USER_HUB_LIMIT_LOW); - DUMP_STR (msg_user_hub_limit_high, DEF_MSG_USER_HUB_LIMIT_HIGH); - DUMP_STR (msg_user_flood_chat, DEF_MSG_FLOOD_CHAT); - DUMP_STR (msg_user_flood_connect, DEF_MSG_FLOOD_CONNECT); - DUMP_STR (msg_user_flood_search, DEF_MSG_FLOOD_SEARCH); - DUMP_STR (msg_user_flood_update, DEF_MSG_FLOOD_UPDATE); - DUMP_STR (msg_user_flood_extras, DEF_MSG_FLOOD_EXTRAS); - DUMP_STR (msg_proto_no_common_hash, DEF_MSG_PROTO_NO_COMMON_HASH); - DUMP_STR (msg_proto_obsolete_adc0, DEF_MSG_PROTO_OBSOLETE_ADC0); -} +#include "gen_config.c" static int config_parse_line(char* line, int line_count, void* ptr_data) { diff --git a/src/core/config.h b/src/core/config.h index 2e3e48c..889941b 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -20,96 +20,7 @@ #ifndef HAVE_UHUB_CONFIG_H #define HAVE_UHUB_CONFIG_H -struct hub_config -{ - int server_port; /**<<< "Server port to bind to (default: 1511)" */ - char* server_bind_addr; /**<<< "Server bind address (default: '0.0.0.0' or '::')" */ - int server_listen_backlog; /**<<< "Server listen backlog (default: 50)" */ - char* server_alt_ports; /**<<< "Comma separated list of alternative ports to listen to (default: '')" */ - int hub_enabled; /**<<< "Is server enabled (default: 1)" */ - int show_banner; /**<<< "Show banner on connect (default: 1)" */ - int show_banner_sys_info; /**<<< "Show banner system information (default: 1). Has no effect unless show_banner is enabled." */ - int max_users; /**<<< "Maximum number of users allowed on the hub (default: 500)" */ - int registered_users_only; /**<<< "Allow registered users only (default: 0)" */ - int obsolete_clients; /**<<< "Support obsolete clients using a ADC protocol prior to 1.0 (default: off)" */ - int chat_only; /**<<< "Allow chat only operation on hub (default: 0)" */ - int chat_is_privileged; /**<<< "Allow chat for operators and above only (default: 0) */ - char* file_motd; /**<<< "File containing the 'message of the day' (default: '' - no motd)" */ - char* file_acl; /**<<< "File containing user database (default: '' - no known users)" */ - char* file_rules; /**<<< "File containing the rules (default: '' - no rules)" */ - char* hub_name; /**<<< "Name of hub (default: 'My uhub hub')" */ - char* hub_description; /**<<< "Name of hub (default: 'no description')" */ - int max_recv_buffer; /**<<< "Max read buffer before parse, per user (default: 4096)" */ - int max_send_buffer; /**<<< "Max send buffer before disconnect, per user (default: 128K)" */ - int max_send_buffer_soft; /**<<< "Max send buffer before message drops, per user (default: 96K)" */ - int low_bandwidth_mode; /**<<< "If this is enabled, the hub will strip off elements from each user's info message to reduce bandwidth usage" */ - - int max_chat_history; /**<<< "Number of chat messages kept in history (default: 20)" */ - int max_logout_log; /**<<< "Number of log entries for people leaving the hub. (default: 100) */ - - /* Limits enforced on users */ - int limit_max_hubs_user; /**<<< "Max concurrent hubs as a user. (0=off, default: 10)" */ - int limit_max_hubs_reg; /**<<< "Max concurrent hubs as registered user. (0=off, default: 10)" */ - int limit_max_hubs_op; /**<<< "Max concurrent hubs as operator. (0=off, default: 10)" */ - int limit_min_hubs_user; /**<<< "Min concurrent hubs as a user. (0=off, default: 0)" */ - int limit_min_hubs_reg; /**<<< "Min concurrent hubs as registered user. (0=off, default: 0)" */ - int limit_min_hubs_op; /**<<< "Min concurrent hubs as operator. (0=off, default: 0)" */ - int limit_max_hubs; /**<<< "Max total hub connections allowed, user/reg/op combined. (0=off, default: 25)" */ - int limit_min_share; /**<<< "Limit minimum share size in megabytes (MiB) (0=off, default: 0)" */ - int limit_max_share; /**<<< "Limit maximum share size in megabytes (MiB) (0=off, default: 0)" */ - int limit_min_slots; /**<<< "Limit minimum number of slots open per user (0=off, default: 0)" */ - int limit_max_slots; /**<<< "Limit maximum number of slots open per user (0=off, default: 0)" */ - - int flood_ctl_interval; /**<<< "Time interval in seconds for flood control check. If 0 then all flood control is disabled. (0=off, default: 0)" */ - int flood_ctl_chat; /**<<< "Max chat messages allowed inside the time interval (0=off, default: 0)" */ - int flood_ctl_connect; /**<<< "Max connect requests allowed inside the time interval (0=off, default: 0)" */ - int flood_ctl_search; /**<<< "Max search requests allowed inside the time interval (0=off, default: 0)" */ - int flood_ctl_update; /**<<< "Max updates allowed inside the time interval (0=off, default: 0)" */ - int flood_ctl_extras; /**<<< "Max extra protocol messages allowed inside the time interval (0=off, default: 0)" */ - - /* Messages that can be sent to a user */ - char* msg_hub_full; /**<<< "hub is full" */ - char* msg_hub_disabled; /**<<< "hub is disabled" */ - char* msg_hub_registered_users_only; /**<<< "hub is for registered users only" */ - char* msg_inf_error_nick_missing; /**<<< "no nickname given" */ - char* msg_inf_error_nick_multiple; /**<<< "multiple nicknames given" */ - char* msg_inf_error_nick_invalid; /**<<< "generic/unkown" */ - char* msg_inf_error_nick_long; /**<<< "nickname too long" */ - char* msg_inf_error_nick_short; /**<<< "nickname too short" */ - char* msg_inf_error_nick_spaces; /**<<< "nickname cannot start with spaces" */ - char* msg_inf_error_nick_bad_chars; /**<<< "nickname contains chars below ascii 32" */ - char* msg_inf_error_nick_not_utf8; /**<<< "nickname is not valid utf8" */ - char* msg_inf_error_nick_taken; /**<<< "nickname is in use" */ - char* msg_inf_error_nick_restricted; /**<<< "nickname cannot be used on this hub" */ - char* msg_inf_error_cid_invalid; /**<<< "CID is not valid" */ - char* msg_inf_error_cid_missing; /**<<< "CID is not specified" */ - char* msg_inf_error_cid_taken; /**<<< "CID is taken" */ - char* msg_inf_error_pid_missing; /**<<< "PID is not specified" */ - char* msg_inf_error_pid_invalid; /**<<< "PID is invalid" */ - char* msg_ban_permanently; /**<<< "Banned permanently" */ - char* msg_ban_temporarily; /**<<< "Banned temporarily" */ - char* msg_auth_invalid_password; /**<<< "Password is wrong" */ - char* msg_auth_user_not_found; /**<<< "User not found in password database" */ - char* msg_error_no_memory; /**<<< "No memory" */ - char* msg_user_share_size_low; /**<<< "User is not sharing enough" */ - char* msg_user_share_size_high; /**<<< "User is sharing too much" */ - char* msg_user_slots_low; /**<<< "User have too few upload slots." */ - char* msg_user_slots_high; /**<<< "User have too many upload slots." */ - char* msg_user_hub_limit_low; /**<<< "User is on too few hubs." */ - char* msg_user_hub_limit_high; /**<<< "User is on too many hubs." */ - char* msg_user_flood_chat; /**<<< "Chat flood detected, messages are dropped." */ - char* msg_user_flood_connect; /**<<< "Connect flood detected, connection refused." */ - char* msg_user_flood_search; /**<<< "Search flood detected, search is stopped." */ - char* msg_user_flood_update; /**<<< "Update flood detected." */ - char* msg_user_flood_extras; /**<<< "Flood detected." */ - char* msg_proto_no_common_hash; /**<<< "No common hash algorithm." */ - char* msg_proto_obsolete_adc0; /**<<< "Client is using an obsolete ADC protocol version." */ - - int tls_enable; /**<<< "Enable SSL/TLS support (default: 0)" */ - int tls_require; /**<<< "If SSL/TLS enabled, should it be required (default: 0) */ - char* tls_certificate; /**<<< "Certificate file (PEM)" */ - char* tls_private_key; /**<<< "Private key" */ -}; +#include "gen_config.h" /** * This initializes the configuration variables, and sets the default diff --git a/src/core/config.pl b/src/core/config.pl new file mode 100755 index 0000000..2f5ec16 --- /dev/null +++ b/src/core/config.pl @@ -0,0 +1,164 @@ +#!/usr/bin/perl -w + +use strict; +use XML::Twig; + +sub write_c_header(@); +sub write_c_impl_defaults(@); +sub write_c_impl_apply(@); +sub write_c_impl_free(@); +sub write_c_impl_dump(@); +sub get_data($); + +# initialize parser and read the file +my $input = "./config.xml"; +my $parser = XML::Twig->new(); +my $tree = $parser->parsefile($input) || die "Unable to parse XML file."; + +# Write header file +open GENHEAD, ">gen_config.h" || die "Unable to write header file"; +print GENHEAD "/* THIS FILE IS AUTOGENERATED - DO NOT CHANGE IT! */\n\nstruct hub_config\n{\n"; +foreach my $p ($tree->root->children("option")) +{ + my @data = ($p->att("type"), $p->att("name"), $p->att("default"), $p->att("advanced"), $p->children_text("short"), $p->children_text("description"), $p->children_text("since"), $p->children_text("example")); + write_c_header(@data); +} +print GENHEAD "};\n\n"; + +# Write c source file +open GENIMPL, ">gen_config.c" || die "Unable to write source file"; +print GENIMPL "/* THIS FILE IS AUTOGENERATED - DO NOT CHANGE IT! */\n\n"; + +# The defaults function +print GENIMPL "void config_defaults(struct hub_config* config)\n{\n"; +foreach my $p ($tree->root->children("option")) +{ + write_c_impl_defaults(get_data($p)); +} +print GENIMPL "}\n\n"; + +# apply function +print GENIMPL "static int apply_config(struct hub_config* config, char* key, char* data, int line_count)\n{\n"; +foreach my $p ($tree->root->children("option")) +{ + write_c_impl_apply(get_data($p)); +} +print GENIMPL "\t/* Still here -- unknown directive */\n"; +print GENIMPL "\tLOG_ERROR(\"Unknown configuration directive: '%s'\", key);\n"; +print GENIMPL "\t\treturn -1;\n"; +print GENIMPL "}\n\n"; + +# free function (for strings) +print GENIMPL "void free_config(struct hub_config* config)\n{\n"; +foreach my $p ($tree->root->children("option")) +{ + write_c_impl_free(get_data($p)); +} +print GENIMPL "}\n\n"; + +# dump function +print GENIMPL "void dump_config(struct hub_config* config, int ignore_defaults)\n{\n"; +foreach my $p ($tree->root->children("option")) +{ + write_c_impl_dump(get_data($p)); +} +print GENIMPL "}\n\n"; + + + +sub write_c_header(@) +{ + my @output = @_; + my ($type, $name, $default, $advanced, $short, $desc, $since, $example) = @output; + + print GENHEAD "\t"; + print GENHEAD "int " if ($type eq "int"); + print GENHEAD "int " if ($type eq "boolean"); + print GENHEAD "char*" if ($type =~ /(string|file|message)/); + print GENHEAD " " . $name . ";"; + + my $comment = ""; + if ($type eq "message") + { + $comment = "\"" . $default . "\""; + } + elsif (defined $short && length $short > 0) + { + $comment = $short; + $comment .= " (default: " . $default . ")" if (defined $default); + } + + if (length $comment > 0) + { + my $pad = ""; + for (my $i = length $name; $i < 32; $i++) + { + $pad .= " "; + } + $comment = $pad . "/*<<< " . $comment . " */"; + } + + print GENHEAD $comment . "\n"; +} + +sub write_c_impl_defaults(@) +{ + my @output = @_; + my ($type, $name, $default, $advanced, $short, $desc, $since, $example) = @output; + + print GENIMPL "\t"; + print GENIMPL "DEFAULT_INTEGER" if ($type eq "int"); + print GENIMPL "DEFAULT_BOOLEAN" if ($type eq "boolean"); + + if ($type =~ /(string|file|message)/) + { + print GENIMPL "DEFAULT_STRING "; + $default = "\"" . $default . "\""; + } + print GENIMPL "(" . $name . ", " . $default . ");\n"; +} + +sub write_c_impl_apply(@) +{ + my @output = @_; + my ($type, $name, $default, $advanced, $short, $desc, $since, $example) = @output; + + print GENIMPL "\t"; + print GENIMPL "GET_INT " if ($type eq "int"); + print GENIMPL "GET_BOOL" if ($type eq "boolean"); + print GENIMPL "GET_STR " if ($type =~ /(string|file|message)/); + print GENIMPL "(" . $name . ");\n"; +} + +sub write_c_impl_free(@) +{ + my @output = @_; + my ($type, $name, $default, $advanced, $short, $desc, $since, $example) = @output; + + print GENIMPL "\thub_free(config->" . $name . ");\n" if ($type =~ /(string|file|message)/) +} + +sub write_c_impl_dump(@) +{ + my @output = @_; + my ($type, $name, $default, $advanced, $short, $desc, $since, $example) = @output; + + print GENIMPL "\t"; + print GENIMPL "DUMP_INT " if ($type eq "int"); + print GENIMPL "DUMP_BOOL" if ($type eq "boolean"); + + if ($type =~ /(string|file|message)/) + { + print GENIMPL "DUMP_STR"; + $default = "\"" . $default . "\""; + } + print GENIMPL "(" . $name . ", " . $default . ");\n" +} + +sub get_data($) +{ + my $p = shift; + my @data = ($p->att("type"), $p->att("name"), $p->att("default"), $p->att("advanced"), $p->children_text("short"), $p->children_text("description"), $p->children_text("since"), $p->children_text("example")); + return @data; +} + diff --git a/src/core/config.xml b/src/core/config.xml new file mode 100644 index 0000000..9a837e5 --- /dev/null +++ b/src/core/config.xml @@ -0,0 +1,663 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/core/gen_config.c b/src/core/gen_config.c new file mode 100644 index 0000000..edb91f7 --- /dev/null +++ b/src/core/gen_config.c @@ -0,0 +1,306 @@ +/* THIS FILE IS AUTOGENERATED - DO NOT CHANGE IT! */ + +void config_defaults(struct hub_config* config) +{ + DEFAULT_INTEGER(server_port, 1511); + DEFAULT_STRING (server_bind_addr, "any"); + DEFAULT_INTEGER(server_listen_backlog, 50); + DEFAULT_STRING (server_alt_ports, ""); + DEFAULT_BOOLEAN(hub_enabled, 1); + DEFAULT_BOOLEAN(show_banner, 1); + DEFAULT_BOOLEAN(show_banner_sys_info, 1); + DEFAULT_INTEGER(max_users, 500); + DEFAULT_BOOLEAN(registered_users_only, 0); + DEFAULT_BOOLEAN(obsolete_clients, 0); + DEFAULT_BOOLEAN(chat_only, 0); + DEFAULT_BOOLEAN(chat_is_privileged, 0); + DEFAULT_STRING (hub_name, "uhub"); + DEFAULT_STRING (hub_description, "no description"); + DEFAULT_INTEGER(max_recv_buffer, 4096); + DEFAULT_INTEGER(max_send_buffer, 131072); + DEFAULT_INTEGER(max_send_buffer_soft, 98304); + DEFAULT_BOOLEAN(low_bandwidth_mode, 0); + DEFAULT_INTEGER(max_chat_history, 20); + DEFAULT_INTEGER(max_logout_log, 20); + DEFAULT_INTEGER(limit_max_hubs_user, 10); + DEFAULT_INTEGER(limit_max_hubs_reg, 10); + DEFAULT_INTEGER(limit_max_hubs_op, 10); + DEFAULT_INTEGER(limit_max_hubs, 25); + DEFAULT_INTEGER(limit_min_hubs_user, 10); + DEFAULT_INTEGER(limit_min_hubs_reg, 10); + DEFAULT_INTEGER(limit_min_hubs_op, 10); + DEFAULT_INTEGER(limit_min_share, 0); + DEFAULT_INTEGER(limit_max_share, 0); + DEFAULT_INTEGER(limit_min_slots, 0); + DEFAULT_INTEGER(limit_max_slots, 0); + DEFAULT_INTEGER(flood_ctl_interval, 0); + DEFAULT_INTEGER(flood_ctl_chat, 0); + DEFAULT_INTEGER(flood_ctl_connect, 0); + DEFAULT_INTEGER(flood_ctl_search, 0); + DEFAULT_INTEGER(flood_ctl_update, 0); + DEFAULT_INTEGER(flood_ctl_extras, 0); + DEFAULT_BOOLEAN(tls_enable, 0); + DEFAULT_BOOLEAN(tls_require, 0); + DEFAULT_STRING (tls_certificate, ""); + DEFAULT_STRING (tls_private_key, ""); + DEFAULT_STRING (file_motd, ""); + DEFAULT_STRING (file_acl, ""); + DEFAULT_STRING (file_rules, ""); + DEFAULT_STRING (msg_hub_full, "Hub is full"); + DEFAULT_STRING (msg_hub_disabled, "Hub is disabled"); + DEFAULT_STRING (msg_hub_registered_users_only, "Hub is for registered users only"); + DEFAULT_STRING (msg_inf_error_nick_missing, "No nickname given"); + DEFAULT_STRING (msg_inf_error_nick_multiple, "Multiple nicknames given"); + DEFAULT_STRING (msg_inf_error_nick_invalid, "Nickname is invalid"); + DEFAULT_STRING (msg_inf_error_nick_long, "Nickname too long"); + DEFAULT_STRING (msg_inf_error_nick_short, "Nickname too short"); + DEFAULT_STRING (msg_inf_error_nick_spaces, "Nickname cannot start with spaces"); + DEFAULT_STRING (msg_inf_error_nick_bad_chars, "Nickname contains invalid characters"); + DEFAULT_STRING (msg_inf_error_nick_not_utf8, "Nickname is not valid UTF-8"); + DEFAULT_STRING (msg_inf_error_nick_taken, "Nickname is already in use"); + DEFAULT_STRING (msg_inf_error_nick_restricted, "Nickname cannot be used on this hub"); + DEFAULT_STRING (msg_inf_error_cid_invalid, "CID is not valid"); + DEFAULT_STRING (msg_inf_error_cid_missing, "CID is not specified"); + DEFAULT_STRING (msg_inf_error_cid_taken, "CID is taken"); + DEFAULT_STRING (msg_inf_error_pid_missing, "PID is not specified"); + DEFAULT_STRING (msg_inf_error_pid_invalid, "PID is invalid"); + DEFAULT_STRING (msg_ban_permanently, "Banned permanently"); + DEFAULT_STRING (msg_ban_temporarily, "Banned temporarily"); + DEFAULT_STRING (msg_auth_invalid_password, "Password is wrong"); + DEFAULT_STRING (msg_auth_user_not_found, "User not found in password database"); + DEFAULT_STRING (msg_error_no_memory, "No memory"); + DEFAULT_STRING (msg_user_share_size_low, "User is not sharing enough"); + DEFAULT_STRING (msg_user_share_size_high, "User is sharing too much"); + DEFAULT_STRING (msg_user_slots_low, "User have too few upload slots."); + DEFAULT_STRING (msg_user_slots_high, "User have too many upload slots."); + DEFAULT_STRING (msg_user_hub_limit_low, "User is on too few hubs."); + DEFAULT_STRING (msg_user_hub_limit_high, "User is on too many hubs."); + DEFAULT_STRING (msg_user_flood_chat, "Chat flood detected, messages are dropped."); + DEFAULT_STRING (msg_user_flood_connect, "Connect flood detected, connection refused."); + DEFAULT_STRING (msg_user_flood_search, "Search flood detected, search is stopped."); + DEFAULT_STRING (msg_user_flood_update, "Update flood detected."); + DEFAULT_STRING (msg_user_flood_extras, "Flood detected."); + DEFAULT_STRING (msg_proto_no_common_hash, "No common hash algorithm."); + DEFAULT_STRING (msg_proto_obsolete_adc0, "Client is using an obsolete ADC protocol version."); +} + +static int apply_config(struct hub_config* config, char* key, char* data, int line_count) +{ + GET_INT (server_port); + GET_STR (server_bind_addr); + GET_INT (server_listen_backlog); + GET_STR (server_alt_ports); + GET_BOOL(hub_enabled); + GET_BOOL(show_banner); + GET_BOOL(show_banner_sys_info); + GET_INT (max_users); + GET_BOOL(registered_users_only); + GET_BOOL(obsolete_clients); + GET_BOOL(chat_only); + GET_BOOL(chat_is_privileged); + GET_STR (hub_name); + GET_STR (hub_description); + GET_INT (max_recv_buffer); + GET_INT (max_send_buffer); + GET_INT (max_send_buffer_soft); + GET_BOOL(low_bandwidth_mode); + GET_INT (max_chat_history); + GET_INT (max_logout_log); + GET_INT (limit_max_hubs_user); + GET_INT (limit_max_hubs_reg); + GET_INT (limit_max_hubs_op); + GET_INT (limit_max_hubs); + GET_INT (limit_min_hubs_user); + GET_INT (limit_min_hubs_reg); + GET_INT (limit_min_hubs_op); + GET_INT (limit_min_share); + GET_INT (limit_max_share); + GET_INT (limit_min_slots); + GET_INT (limit_max_slots); + GET_INT (flood_ctl_interval); + GET_INT (flood_ctl_chat); + GET_INT (flood_ctl_connect); + GET_INT (flood_ctl_search); + GET_INT (flood_ctl_update); + GET_INT (flood_ctl_extras); + GET_BOOL(tls_enable); + GET_BOOL(tls_require); + GET_STR (tls_certificate); + GET_STR (tls_private_key); + GET_STR (file_motd); + GET_STR (file_acl); + GET_STR (file_rules); + GET_STR (msg_hub_full); + GET_STR (msg_hub_disabled); + GET_STR (msg_hub_registered_users_only); + GET_STR (msg_inf_error_nick_missing); + GET_STR (msg_inf_error_nick_multiple); + GET_STR (msg_inf_error_nick_invalid); + GET_STR (msg_inf_error_nick_long); + GET_STR (msg_inf_error_nick_short); + GET_STR (msg_inf_error_nick_spaces); + GET_STR (msg_inf_error_nick_bad_chars); + GET_STR (msg_inf_error_nick_not_utf8); + GET_STR (msg_inf_error_nick_taken); + GET_STR (msg_inf_error_nick_restricted); + GET_STR (msg_inf_error_cid_invalid); + GET_STR (msg_inf_error_cid_missing); + GET_STR (msg_inf_error_cid_taken); + GET_STR (msg_inf_error_pid_missing); + GET_STR (msg_inf_error_pid_invalid); + GET_STR (msg_ban_permanently); + GET_STR (msg_ban_temporarily); + GET_STR (msg_auth_invalid_password); + GET_STR (msg_auth_user_not_found); + GET_STR (msg_error_no_memory); + GET_STR (msg_user_share_size_low); + GET_STR (msg_user_share_size_high); + GET_STR (msg_user_slots_low); + GET_STR (msg_user_slots_high); + GET_STR (msg_user_hub_limit_low); + GET_STR (msg_user_hub_limit_high); + GET_STR (msg_user_flood_chat); + GET_STR (msg_user_flood_connect); + GET_STR (msg_user_flood_search); + GET_STR (msg_user_flood_update); + GET_STR (msg_user_flood_extras); + GET_STR (msg_proto_no_common_hash); + GET_STR (msg_proto_obsolete_adc0); + /* Still here -- unknown directive */ + LOG_ERROR("Unknown configuration directive: '%s'", key); + return -1; +} + +void free_config(struct hub_config* config) +{ + hub_free(config->server_bind_addr); + hub_free(config->server_alt_ports); + hub_free(config->hub_name); + hub_free(config->hub_description); + hub_free(config->tls_certificate); + hub_free(config->tls_private_key); + hub_free(config->file_motd); + hub_free(config->file_acl); + hub_free(config->file_rules); + hub_free(config->msg_hub_full); + hub_free(config->msg_hub_disabled); + hub_free(config->msg_hub_registered_users_only); + hub_free(config->msg_inf_error_nick_missing); + hub_free(config->msg_inf_error_nick_multiple); + hub_free(config->msg_inf_error_nick_invalid); + hub_free(config->msg_inf_error_nick_long); + hub_free(config->msg_inf_error_nick_short); + hub_free(config->msg_inf_error_nick_spaces); + hub_free(config->msg_inf_error_nick_bad_chars); + hub_free(config->msg_inf_error_nick_not_utf8); + hub_free(config->msg_inf_error_nick_taken); + hub_free(config->msg_inf_error_nick_restricted); + hub_free(config->msg_inf_error_cid_invalid); + hub_free(config->msg_inf_error_cid_missing); + hub_free(config->msg_inf_error_cid_taken); + hub_free(config->msg_inf_error_pid_missing); + hub_free(config->msg_inf_error_pid_invalid); + hub_free(config->msg_ban_permanently); + hub_free(config->msg_ban_temporarily); + hub_free(config->msg_auth_invalid_password); + hub_free(config->msg_auth_user_not_found); + hub_free(config->msg_error_no_memory); + hub_free(config->msg_user_share_size_low); + hub_free(config->msg_user_share_size_high); + hub_free(config->msg_user_slots_low); + hub_free(config->msg_user_slots_high); + hub_free(config->msg_user_hub_limit_low); + hub_free(config->msg_user_hub_limit_high); + hub_free(config->msg_user_flood_chat); + hub_free(config->msg_user_flood_connect); + hub_free(config->msg_user_flood_search); + hub_free(config->msg_user_flood_update); + hub_free(config->msg_user_flood_extras); + hub_free(config->msg_proto_no_common_hash); + hub_free(config->msg_proto_obsolete_adc0); +} + +void dump_config(struct hub_config* config, int ignore_defaults) +{ + DUMP_INT (server_port, 1511); + DUMP_STR(server_bind_addr, "any"); + DUMP_INT (server_listen_backlog, 50); + DUMP_STR(server_alt_ports, ""); + DUMP_BOOL(hub_enabled, 1); + DUMP_BOOL(show_banner, 1); + DUMP_BOOL(show_banner_sys_info, 1); + DUMP_INT (max_users, 500); + DUMP_BOOL(registered_users_only, 0); + DUMP_BOOL(obsolete_clients, 0); + DUMP_BOOL(chat_only, 0); + DUMP_BOOL(chat_is_privileged, 0); + DUMP_STR(hub_name, "uhub"); + DUMP_STR(hub_description, "no description"); + DUMP_INT (max_recv_buffer, 4096); + DUMP_INT (max_send_buffer, 131072); + DUMP_INT (max_send_buffer_soft, 98304); + DUMP_BOOL(low_bandwidth_mode, 0); + DUMP_INT (max_chat_history, 20); + DUMP_INT (max_logout_log, 20); + DUMP_INT (limit_max_hubs_user, 10); + DUMP_INT (limit_max_hubs_reg, 10); + DUMP_INT (limit_max_hubs_op, 10); + DUMP_INT (limit_max_hubs, 25); + DUMP_INT (limit_min_hubs_user, 10); + DUMP_INT (limit_min_hubs_reg, 10); + DUMP_INT (limit_min_hubs_op, 10); + DUMP_INT (limit_min_share, 0); + DUMP_INT (limit_max_share, 0); + DUMP_INT (limit_min_slots, 0); + DUMP_INT (limit_max_slots, 0); + DUMP_INT (flood_ctl_interval, 0); + DUMP_INT (flood_ctl_chat, 0); + DUMP_INT (flood_ctl_connect, 0); + DUMP_INT (flood_ctl_search, 0); + DUMP_INT (flood_ctl_update, 0); + DUMP_INT (flood_ctl_extras, 0); + DUMP_BOOL(tls_enable, 0); + DUMP_BOOL(tls_require, 0); + DUMP_STR(tls_certificate, ""); + DUMP_STR(tls_private_key, ""); + DUMP_STR(file_motd, ""); + DUMP_STR(file_acl, ""); + DUMP_STR(file_rules, ""); + DUMP_STR(msg_hub_full, "Hub is full"); + DUMP_STR(msg_hub_disabled, "Hub is disabled"); + DUMP_STR(msg_hub_registered_users_only, "Hub is for registered users only"); + DUMP_STR(msg_inf_error_nick_missing, "No nickname given"); + DUMP_STR(msg_inf_error_nick_multiple, "Multiple nicknames given"); + DUMP_STR(msg_inf_error_nick_invalid, "Nickname is invalid"); + DUMP_STR(msg_inf_error_nick_long, "Nickname too long"); + DUMP_STR(msg_inf_error_nick_short, "Nickname too short"); + DUMP_STR(msg_inf_error_nick_spaces, "Nickname cannot start with spaces"); + DUMP_STR(msg_inf_error_nick_bad_chars, "Nickname contains invalid characters"); + DUMP_STR(msg_inf_error_nick_not_utf8, "Nickname is not valid UTF-8"); + DUMP_STR(msg_inf_error_nick_taken, "Nickname is already in use"); + DUMP_STR(msg_inf_error_nick_restricted, "Nickname cannot be used on this hub"); + DUMP_STR(msg_inf_error_cid_invalid, "CID is not valid"); + DUMP_STR(msg_inf_error_cid_missing, "CID is not specified"); + DUMP_STR(msg_inf_error_cid_taken, "CID is taken"); + DUMP_STR(msg_inf_error_pid_missing, "PID is not specified"); + DUMP_STR(msg_inf_error_pid_invalid, "PID is invalid"); + DUMP_STR(msg_ban_permanently, "Banned permanently"); + DUMP_STR(msg_ban_temporarily, "Banned temporarily"); + DUMP_STR(msg_auth_invalid_password, "Password is wrong"); + DUMP_STR(msg_auth_user_not_found, "User not found in password database"); + DUMP_STR(msg_error_no_memory, "No memory"); + DUMP_STR(msg_user_share_size_low, "User is not sharing enough"); + DUMP_STR(msg_user_share_size_high, "User is sharing too much"); + DUMP_STR(msg_user_slots_low, "User have too few upload slots."); + DUMP_STR(msg_user_slots_high, "User have too many upload slots."); + DUMP_STR(msg_user_hub_limit_low, "User is on too few hubs."); + DUMP_STR(msg_user_hub_limit_high, "User is on too many hubs."); + DUMP_STR(msg_user_flood_chat, "Chat flood detected, messages are dropped."); + DUMP_STR(msg_user_flood_connect, "Connect flood detected, connection refused."); + DUMP_STR(msg_user_flood_search, "Search flood detected, search is stopped."); + DUMP_STR(msg_user_flood_update, "Update flood detected."); + DUMP_STR(msg_user_flood_extras, "Flood detected."); + DUMP_STR(msg_proto_no_common_hash, "No common hash algorithm."); + DUMP_STR(msg_proto_obsolete_adc0, "Client is using an obsolete ADC protocol version."); +} + diff --git a/src/core/gen_config.h b/src/core/gen_config.h new file mode 100644 index 0000000..cdd8154 --- /dev/null +++ b/src/core/gen_config.h @@ -0,0 +1,86 @@ +/* THIS FILE IS AUTOGENERATED - DO NOT CHANGE IT! */ + +struct hub_config +{ + int server_port; /*<<< Server port to bind to (default: 1511) */ + char* server_bind_addr; /*<<< Server bind address (default: any) */ + int server_listen_backlog; /*<<< Server listen backlog (default: 50) */ + char* server_alt_ports; /*<<< Comma separated list of alternative ports to listen to (default: ) */ + int hub_enabled; /*<<< Is server enabled (default: 1) */ + int show_banner; /*<<< Show banner on connect (default: 1) */ + int show_banner_sys_info; /*<<< Show banner on connect (default: 1) */ + int max_users; /*<<< Maximum number of users allowed on the hub (default: 500) */ + int registered_users_only; /*<<< Allow registered users only (default: 0) */ + int obsolete_clients; /*<<< Support obsolete clients using a ADC protocol prior to 1.0 (default: 0) */ + int chat_only; /*<<< Allow chat only operation on hub (default: 0) */ + int chat_is_privileged; /*<<< Allow chat for operators and above only (default: 0) */ + char* hub_name; /*<<< Name of hub (default: uhub) */ + char* hub_description; /*<<< Short hub description, topic or subject. (default: no description) */ + int max_recv_buffer; /*<<< Max read buffer before parse, per user (default: 4096) */ + int max_send_buffer; /*<<< Max send buffer before disconnect, per user (default: 131072) */ + int max_send_buffer_soft; /*<<< Max send buffer before message drops, per user (default: 98304) */ + int low_bandwidth_mode; /*<<< Enable bandwidth saving measures (default: 0) */ + int max_chat_history; /*<<< Number of chat messages kept in history (default: 20) */ + int max_logout_log; /*<<< Number of log entries for people leaving the hub (default: 20) */ + int limit_max_hubs_user; /*<<< Max concurrent hubs as a guest user (default: 10) */ + int limit_max_hubs_reg; /*<<< Max concurrent hubs as a registered user (default: 10) */ + int limit_max_hubs_op; /*<<< Max concurrent hubs as a operator (or admin) (default: 10) */ + int limit_max_hubs; /*<<< Max total hub connections allowed, user/reg/op combined. (default: 25) */ + int limit_min_hubs_user; /*<<< Minimum concurrent hubs as a guest user (default: 10) */ + int limit_min_hubs_reg; /*<<< Minimum concurrent hubs as a registered user (default: 10) */ + int limit_min_hubs_op; /*<<< Minimum concurrent hubs as a operator (or admin) (default: 10) */ + int limit_min_share; /*<<< Limit minimum share size in megabytes (default: 0) */ + int limit_max_share; /*<<< Limit maximum share size in megabytes (default: 0) */ + int limit_min_slots; /*<<< Limit minimum number of upload slots open per user (default: 0) */ + int limit_max_slots; /*<<< Limit minimum number of upload slots open per user (default: 0) */ + int flood_ctl_interval; /*<<< Time interval in seconds for flood control check. (default: 0) */ + int flood_ctl_chat; /*<<< Max chat messages allowed in time interval (default: 0) */ + int flood_ctl_connect; /*<<< Max connections requests allowed in time interval (default: 0) */ + int flood_ctl_search; /*<<< Max search requests allowed in time interval (default: 0) */ + int flood_ctl_update; /*<<< Max updates allowed in time interval (default: 0) */ + int flood_ctl_extras; /*<<< Max extra messages allowed in time interval (default: 0) */ + int tls_enable; /*<<< Enable SSL/TLS support (default: 0) */ + int tls_require; /*<<< If SSL/TLS enabled, should it be required (default: 0) (default: 0) */ + char* tls_certificate; /*<<< Certificate file (default: ) */ + char* tls_private_key; /*<<< Private key file (default: ) */ + char* file_motd; /*<<< File containing the 'message of the day (default: ) */ + char* file_acl; /*<<< File containing access control lists (default: ) */ + char* file_rules; /*<<< File containing hub rules (default: ) */ + char* msg_hub_full; /*<<< "Hub is full" */ + char* msg_hub_disabled; /*<<< "Hub is disabled" */ + char* msg_hub_registered_users_only; /*<<< "Hub is for registered users only" */ + char* msg_inf_error_nick_missing; /*<<< "No nickname given" */ + char* msg_inf_error_nick_multiple; /*<<< "Multiple nicknames given" */ + char* msg_inf_error_nick_invalid; /*<<< "Nickname is invalid" */ + char* msg_inf_error_nick_long; /*<<< "Nickname too long" */ + char* msg_inf_error_nick_short; /*<<< "Nickname too short" */ + char* msg_inf_error_nick_spaces; /*<<< "Nickname cannot start with spaces" */ + char* msg_inf_error_nick_bad_chars; /*<<< "Nickname contains invalid characters" */ + char* msg_inf_error_nick_not_utf8; /*<<< "Nickname is not valid UTF-8" */ + char* msg_inf_error_nick_taken; /*<<< "Nickname is already in use" */ + char* msg_inf_error_nick_restricted; /*<<< "Nickname cannot be used on this hub" */ + char* msg_inf_error_cid_invalid; /*<<< "CID is not valid" */ + char* msg_inf_error_cid_missing; /*<<< "CID is not specified" */ + char* msg_inf_error_cid_taken; /*<<< "CID is taken" */ + char* msg_inf_error_pid_missing; /*<<< "PID is not specified" */ + char* msg_inf_error_pid_invalid; /*<<< "PID is invalid" */ + char* msg_ban_permanently; /*<<< "Banned permanently" */ + char* msg_ban_temporarily; /*<<< "Banned temporarily" */ + char* msg_auth_invalid_password; /*<<< "Password is wrong" */ + char* msg_auth_user_not_found; /*<<< "User not found in password database" */ + char* msg_error_no_memory; /*<<< "No memory" */ + char* msg_user_share_size_low; /*<<< "User is not sharing enough" */ + char* msg_user_share_size_high; /*<<< "User is sharing too much" */ + char* msg_user_slots_low; /*<<< "User have too few upload slots." */ + char* msg_user_slots_high; /*<<< "User have too many upload slots." */ + char* msg_user_hub_limit_low; /*<<< "User is on too few hubs." */ + char* msg_user_hub_limit_high; /*<<< "User is on too many hubs." */ + char* msg_user_flood_chat; /*<<< "Chat flood detected, messages are dropped." */ + char* msg_user_flood_connect; /*<<< "Connect flood detected, connection refused." */ + char* msg_user_flood_search; /*<<< "Search flood detected, search is stopped." */ + char* msg_user_flood_update; /*<<< "Update flood detected." */ + char* msg_user_flood_extras; /*<<< "Flood detected." */ + char* msg_proto_no_common_hash; /*<<< "No common hash algorithm." */ + char* msg_proto_obsolete_adc0; /*<<< "Client is using an obsolete ADC protocol version." */ +}; +