This commit is contained in:
commit
a6d87f95ef
42
GNUmakefile
42
GNUmakefile
@ -227,14 +227,14 @@ plugin_auth_sqlite_SOURCES := src/plugins/mod_auth_sqlite.c
|
|||||||
plugin_auth_sqlite_TARGET := mod_auth_sqlite.so
|
plugin_auth_sqlite_TARGET := mod_auth_sqlite.so
|
||||||
plugin_auth_sqlite_LIBS := -lsqlite3
|
plugin_auth_sqlite_LIBS := -lsqlite3
|
||||||
|
|
||||||
plugin_chat_history_SOURCE := src/plugins/mod_chat_history.c
|
plugin_chat_history_SOURCES := src/plugins/mod_chat_history.c
|
||||||
plugin_chat_history_TARGET := mod_chat_history.so
|
plugin_chat_history_TARGET := mod_chat_history.so
|
||||||
|
|
||||||
plugin_chat_only_SOURCE := src/plugins/mod_chat_only.c
|
plugin_chat_only_SOURCES := src/plugins/mod_chat_only.c
|
||||||
plugin_chat_only_TARGET := mod_chat_only.so
|
plugin_chat_only_TARGET := mod_chat_only.so
|
||||||
|
|
||||||
plugin_topic_SOURCES := src/plugins/mod_topic.c
|
plugin_topic_SOURCES := src/plugins/mod_topic.c
|
||||||
plugin_topic_TARGET := mod_topic.so
|
plugin_topic_TARGET := mod_topic.so
|
||||||
|
|
||||||
# Source to objects
|
# Source to objects
|
||||||
libuhub_OBJECTS := $(libuhub_SOURCES:.c=.o)
|
libuhub_OBJECTS := $(libuhub_SOURCES:.c=.o)
|
||||||
@ -247,9 +247,27 @@ uhub-passwd_OBJECTS := $(uhub-passwd_SOURCES:.c=.o)
|
|||||||
adcrush_OBJECTS := $(adcrush_SOURCES:.c=.o)
|
adcrush_OBJECTS := $(adcrush_SOURCES:.c=.o)
|
||||||
admin_OBJECTS := $(admin_SOURCES:.c=.o)
|
admin_OBJECTS := $(admin_SOURCES:.c=.o)
|
||||||
|
|
||||||
all_plugins := $(plugin_example_TARGET) $(plugin_logging_TARGET) $(plugin_auth_TARGET) $(plugin_auth_sqlite_TARGET) $(plugin_welcome_TARGET) $(plugin_chat_history_TARGET) $(plugin_chat_only_TARGET) $(plugin_topic_TARGET)
|
all_plugins := \
|
||||||
all_OBJECTS := $(libuhub_OBJECTS) $(uhub_OBJECTS) $(libutils_OBJECTS) $(adcrush_OBJECTS) $(autotest_OBJECTS) $(admin_OBJECTS) $(libadc_common_OBJECTS) $(libadc_client_OBJECTS)
|
$(plugin_example_TARGET) \
|
||||||
all_OBJECTS += $(all_plugins)
|
$(plugin_logging_TARGET) \
|
||||||
|
$(plugin_auth_TARGET) \
|
||||||
|
$(plugin_auth_sqlite_TARGET) \
|
||||||
|
$(plugin_welcome_TARGET) \
|
||||||
|
$(plugin_chat_history_TARGET) \
|
||||||
|
$(plugin_chat_only_TARGET) \
|
||||||
|
$(plugin_topic_TARGET)
|
||||||
|
|
||||||
|
all_OBJECTS := \
|
||||||
|
$(libuhub_OBJECTS) \
|
||||||
|
$(uhub_OBJECTS) \
|
||||||
|
$(libutils_OBJECTS) \
|
||||||
|
$(adcrush_OBJECTS) \
|
||||||
|
$(autotest_OBJECTS) \
|
||||||
|
$(admin_OBJECTS) \
|
||||||
|
$(libadc_common_OBJECTS) \
|
||||||
|
$(libadc_client_OBJECTS)
|
||||||
|
|
||||||
|
all_OBJECTS += $(all_plugins)
|
||||||
|
|
||||||
uhub_BINARY=uhub$(BIN_EXT)
|
uhub_BINARY=uhub$(BIN_EXT)
|
||||||
uhub-passwd_BINARY=uhub-passwd$(BIN_EXT)
|
uhub-passwd_BINARY=uhub-passwd$(BIN_EXT)
|
||||||
@ -284,10 +302,10 @@ $(plugin_example_TARGET): $(plugin_example_SOURCES) $(libutils_OBJECTS)
|
|||||||
$(plugin_logging_TARGET): $(plugin_logging_SOURCES) $(libutils_OBJECTS) $(libadc_common_OBJECTS) src/network/network.o
|
$(plugin_logging_TARGET): $(plugin_logging_SOURCES) $(libutils_OBJECTS) $(libadc_common_OBJECTS) src/network/network.o
|
||||||
$(MSG_CC) $(CC) -shared -fPIC -o $@ $^ $(CFLAGS)
|
$(MSG_CC) $(CC) -shared -fPIC -o $@ $^ $(CFLAGS)
|
||||||
|
|
||||||
$(plugin_chat_history_TARGET): $(plugin_chat_history_SOURCE) $(libutils_OBJECTS)
|
$(plugin_chat_history_TARGET): $(plugin_chat_history_SOURCES) $(libutils_OBJECTS)
|
||||||
$(MSG_CC) $(CC) -shared -fPIC -o $@ $^ $(CFLAGS)
|
$(MSG_CC) $(CC) -shared -fPIC -o $@ $^ $(CFLAGS)
|
||||||
|
|
||||||
$(plugin_chat_only_TARGET): $(plugin_chat_only_SOURCE) $(libutils_OBJECTS)
|
$(plugin_chat_only_TARGET): $(plugin_chat_only_SOURCES) $(libutils_OBJECTS)
|
||||||
$(MSG_CC) $(CC) -shared -fPIC -o $@ $^ $(CFLAGS)
|
$(MSG_CC) $(CC) -shared -fPIC -o $@ $^ $(CFLAGS)
|
||||||
|
|
||||||
$(plugin_welcome_TARGET): $(plugin_welcome_SOURCES) $(libutils_OBJECTS)
|
$(plugin_welcome_TARGET): $(plugin_welcome_SOURCES) $(libutils_OBJECTS)
|
||||||
@ -344,8 +362,8 @@ install: all
|
|||||||
@cp $(uhub-passwd_BINARY) $(UHUB_PREFIX)/bin/
|
@cp $(uhub-passwd_BINARY) $(UHUB_PREFIX)/bin/
|
||||||
@if [ ! -d $(UHUB_CONF_DIR) ]; then echo Creating $(UHUB_CONF_DIR); mkdir -p $(UHUB_CONF_DIR); fi
|
@if [ ! -d $(UHUB_CONF_DIR) ]; then echo Creating $(UHUB_CONF_DIR); mkdir -p $(UHUB_CONF_DIR); fi
|
||||||
@if [ ! -f $(UHUB_CONF_DIR)/uhub.conf ]; then cp doc/uhub.conf $(UHUB_CONF_DIR); fi
|
@if [ ! -f $(UHUB_CONF_DIR)/uhub.conf ]; then cp doc/uhub.conf $(UHUB_CONF_DIR); fi
|
||||||
@if [ ! -f $(UHUB_CONF_DIR)/rules.txt ]; then cp doc/rules.txt $(UHUB_CONF_DIR); fi
|
@if [ ! -f $(UHUB_CONF_DIR)/rules.txt ]; then cp doc/rules.txt $(UHUB_CONF_DIR); fi
|
||||||
@if [ ! -f $(UHUB_CONF_DIR)/plugins.conf ]; then cp doc/plugins.conf $(UHUB_CONF_DIR); fi
|
@if [ ! -f $(UHUB_CONF_DIR)/plugins.conf ]; then cp doc/plugins.conf $(UHUB_CONF_DIR); fi
|
||||||
@if [ ! -d $(UHUB_MOD_DIR) ]; then echo Creating $(UHUB_MOD_DIR); mkdir -p $(UHUB_MOD_DIR); fi
|
@if [ ! -d $(UHUB_MOD_DIR) ]; then echo Creating $(UHUB_MOD_DIR); mkdir -p $(UHUB_MOD_DIR); fi
|
||||||
@cp -f mod_*.so $(UHUB_MOD_DIR)
|
@cp -f mod_*.so $(UHUB_MOD_DIR)
|
||||||
@touch $(UHUB_CONF_DIR)/motd.txt
|
@touch $(UHUB_CONF_DIR)/motd.txt
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# uhub.conf - A example configuration file.
|
# uhub.conf - A example configuration file.
|
||||||
# You should normally place this file in /etc/uhub/uhub.conf
|
# You should normally place this file in /etc/uhub/uhub.conf
|
||||||
# And change the file_acl and file_motd below.
|
# and customize some of the settings below.
|
||||||
#
|
#
|
||||||
# This file is read only to the uhub deamon, and if you
|
# This file is read only to the uhub deamon, and if you
|
||||||
# make changes to it while uhub is running you can send a
|
# make changes to it while uhub is running you can send a
|
||||||
@ -38,17 +38,6 @@ hub_enabled=1
|
|||||||
# Access control list (user database)
|
# Access control list (user database)
|
||||||
file_acl=/etc/uhub/users.conf
|
file_acl=/etc/uhub/users.conf
|
||||||
|
|
||||||
# This file can contain a message of the day. A welcome
|
|
||||||
# message send to any client when connecting.
|
|
||||||
# If the file does not exist, is empty, or cannot be opened
|
|
||||||
# the motd will not be sent to the clients.
|
|
||||||
# Normally this message is sent to clients when connecting.
|
|
||||||
file_motd=/etc/uhub/motd.txt
|
|
||||||
|
|
||||||
# This file can contain a rules of the hub.
|
|
||||||
# Normally this message is sent to clients when write in chat !rules
|
|
||||||
file_rules=/etc/uhub/rules.txt
|
|
||||||
|
|
||||||
# This file can contain a conf for plugin subsystem
|
# This file can contain a conf for plugin subsystem
|
||||||
file_plugins = /etc/uhub/plugins.conf
|
file_plugins = /etc/uhub/plugins.conf
|
||||||
|
|
||||||
|
@ -82,12 +82,13 @@ static struct plugin_user* convert_user_type(struct hub_user* user)
|
|||||||
|
|
||||||
plugin_st plugin_check_ip_early(struct hub_info* hub, struct ip_addr_encap* addr)
|
plugin_st plugin_check_ip_early(struct hub_info* hub, struct ip_addr_encap* addr)
|
||||||
{
|
{
|
||||||
PLUGIN_INVOKE_STATUS_1(hub, login_check_ip_early, addr);
|
PLUGIN_INVOKE_STATUS_1(hub, on_check_ip_early, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin_st plugin_check_ip_late(struct hub_info* hub, struct ip_addr_encap* addr)
|
plugin_st plugin_check_ip_late(struct hub_info* hub, struct hub_user* who, struct ip_addr_encap* addr)
|
||||||
{
|
{
|
||||||
PLUGIN_INVOKE_STATUS_1(hub, login_check_ip_late, addr);
|
struct plugin_user* user = convert_user_type(who);
|
||||||
|
PLUGIN_INVOKE_STATUS_2(hub, on_check_ip_late, user, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void plugin_log_connection_accepted(struct hub_info* hub, struct ip_addr_encap* ipaddr)
|
void plugin_log_connection_accepted(struct hub_info* hub, struct ip_addr_encap* ipaddr)
|
||||||
|
@ -38,7 +38,7 @@ void plugin_log_chat_message(struct hub_info* hub, struct hub_user* from, const
|
|||||||
|
|
||||||
/* IP ban related */
|
/* IP ban related */
|
||||||
plugin_st plugin_check_ip_early(struct hub_info* hub, struct ip_addr_encap* addr);
|
plugin_st plugin_check_ip_early(struct hub_info* hub, struct ip_addr_encap* addr);
|
||||||
plugin_st plugin_check_ip_late(struct hub_info* hub, struct ip_addr_encap* addr);
|
plugin_st plugin_check_ip_late(struct hub_info* hub, struct hub_user* user, struct ip_addr_encap* addr);
|
||||||
|
|
||||||
/* Nickname allow/deny handling */
|
/* Nickname allow/deny handling */
|
||||||
plugin_st plugin_check_nickname_valid(struct hub_info* hub, const char* nick);
|
plugin_st plugin_check_nickname_valid(struct hub_info* hub, const char* nick);
|
||||||
|
@ -109,7 +109,7 @@ struct hub_user
|
|||||||
struct hub_user_info id; /** Contains nick name and CID */
|
struct hub_user_info id; /** Contains nick name and CID */
|
||||||
enum auth_credentials credentials; /** see enum user_credentials */
|
enum auth_credentials credentials; /** see enum user_credentials */
|
||||||
enum user_state state; /** see enum user_state */
|
enum user_state state; /** see enum user_state */
|
||||||
uint32_t flags; /** see enum user_features */
|
uint32_t flags; /** see enum user_flags */
|
||||||
struct linked_list* feature_cast; /** Features supported by feature cast */
|
struct linked_list* feature_cast; /** Features supported by feature cast */
|
||||||
struct adc_message* info; /** ADC 'INF' message (broadcasted to everyone joining the hub) */
|
struct adc_message* info; /** ADC 'INF' message (broadcasted to everyone joining the hub) */
|
||||||
struct hub_info* hub; /** The hub instance this user belong to */
|
struct hub_info* hub; /** The hub instance this user belong to */
|
||||||
|
@ -29,13 +29,6 @@
|
|||||||
#include "util/ipcalc.h"
|
#include "util/ipcalc.h"
|
||||||
#include "plugin_api/types.h"
|
#include "plugin_api/types.h"
|
||||||
|
|
||||||
typedef plugin_st (*on_chat_msg_t)(struct plugin_handle*, struct plugin_user* from, const char* message);
|
|
||||||
typedef plugin_st (*on_private_msg_t)(struct plugin_handle*, struct plugin_user* from, struct plugin_user* to, const char* message);
|
|
||||||
typedef plugin_st (*on_search_t)(struct plugin_handle*, struct plugin_user* from, const char* data);
|
|
||||||
typedef plugin_st (*on_search_result_t)(struct plugin_handle*, struct plugin_user* from, struct plugin_user* to, const char* data);
|
|
||||||
typedef plugin_st (*on_p2p_connect_t)(struct plugin_handle*, struct plugin_user* from, struct plugin_user* to);
|
|
||||||
typedef plugin_st (*on_p2p_revconnect_t)(struct plugin_handle*, struct plugin_user* from, struct plugin_user* to);
|
|
||||||
|
|
||||||
typedef void (*on_connection_accepted_t)(struct plugin_handle*, struct ip_addr_encap*);
|
typedef void (*on_connection_accepted_t)(struct plugin_handle*, struct ip_addr_encap*);
|
||||||
typedef void (*on_connection_refused_t)(struct plugin_handle*, struct ip_addr_encap*);
|
typedef void (*on_connection_refused_t)(struct plugin_handle*, struct ip_addr_encap*);
|
||||||
|
|
||||||
@ -51,12 +44,18 @@ typedef void (*on_hub_reloaded_t)(struct plugin_handle*, struct plugin_hub_info*
|
|||||||
typedef void (*on_hub_shutdown_t)(struct plugin_handle*, struct plugin_hub_info*);
|
typedef void (*on_hub_shutdown_t)(struct plugin_handle*, struct plugin_hub_info*);
|
||||||
typedef void (*on_hub_error_t)(struct plugin_handle*, struct plugin_hub_info*, const char* message);
|
typedef void (*on_hub_error_t)(struct plugin_handle*, struct plugin_hub_info*, const char* message);
|
||||||
|
|
||||||
typedef plugin_st (*on_change_nick_t)(struct plugin_handle*, struct plugin_user*, const char* new_nick);
|
|
||||||
|
|
||||||
typedef plugin_st (*on_check_ip_early_t)(struct plugin_handle*, struct ip_addr_encap*);
|
typedef plugin_st (*on_check_ip_early_t)(struct plugin_handle*, struct ip_addr_encap*);
|
||||||
typedef plugin_st (*on_check_ip_late_t)(struct plugin_handle*, struct ip_addr_encap*);
|
typedef plugin_st (*on_check_ip_late_t)(struct plugin_handle*, struct plugin_user*, struct ip_addr_encap*);
|
||||||
typedef plugin_st (*on_validate_nick_t)(struct plugin_handle*, const char* nick);
|
typedef plugin_st (*on_validate_nick_t)(struct plugin_handle*, const char* nick);
|
||||||
typedef plugin_st (*on_validate_cid_t)(struct plugin_handle*, const char* cid);
|
typedef plugin_st (*on_validate_cid_t)(struct plugin_handle*, const char* cid);
|
||||||
|
typedef plugin_st (*on_change_nick_t)(struct plugin_handle*, struct plugin_user*, const char* new_nick);
|
||||||
|
|
||||||
|
typedef plugin_st (*on_chat_msg_t)(struct plugin_handle*, struct plugin_user* from, const char* message);
|
||||||
|
typedef plugin_st (*on_private_msg_t)(struct plugin_handle*, struct plugin_user* from, struct plugin_user* to, const char* message);
|
||||||
|
typedef plugin_st (*on_search_t)(struct plugin_handle*, struct plugin_user* from, const char* data);
|
||||||
|
typedef plugin_st (*on_search_result_t)(struct plugin_handle*, struct plugin_user* from, struct plugin_user* to, const char* data);
|
||||||
|
typedef plugin_st (*on_p2p_connect_t)(struct plugin_handle*, struct plugin_user* from, struct plugin_user* to);
|
||||||
|
typedef plugin_st (*on_p2p_revconnect_t)(struct plugin_handle*, struct plugin_user* from, struct plugin_user* to);
|
||||||
|
|
||||||
typedef plugin_st (*auth_get_user_t)(struct plugin_handle*, const char* nickname, struct auth_info* info);
|
typedef plugin_st (*auth_get_user_t)(struct plugin_handle*, const char* nickname, struct auth_info* info);
|
||||||
typedef plugin_st (*auth_register_user_t)(struct plugin_handle*, struct auth_info* user);
|
typedef plugin_st (*auth_register_user_t)(struct plugin_handle*, struct auth_info* user);
|
||||||
@ -65,28 +64,32 @@ typedef plugin_st (*auth_delete_user_t)(struct plugin_handle*, struct auth_info*
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* These are callbacks used for the hub to invoke functions in plugins.
|
* These are callbacks used for the hub to invoke functions in plugins.
|
||||||
|
* The marked ones are not being called yet.
|
||||||
*/
|
*/
|
||||||
struct plugin_funcs
|
struct plugin_funcs
|
||||||
{
|
{
|
||||||
// Log events for connections
|
// Log events for connections
|
||||||
on_connection_accepted_t on_connection_accepted; /* Someone successfully connected to the hub */
|
on_connection_accepted_t on_connection_accepted; /* Someone successfully connected to the hub */
|
||||||
on_connection_refused_t on_connection_refused; /* Someone was refused connection to the hub */
|
on_connection_refused_t on_connection_refused; /* Someone was refused connection to the hub */
|
||||||
|
|
||||||
// Log events for users
|
// Log events for users
|
||||||
on_user_login_t on_user_login; /* A user has successfully logged in to the hub */
|
on_user_login_t on_user_login; /* A user has successfully logged in to the hub */
|
||||||
on_user_login_error_t on_user_login_error; /* A user has failed to log in to the hub */
|
on_user_login_error_t on_user_login_error; /* A user has failed to log in to the hub */
|
||||||
on_user_logout_t on_user_logout; /* A user has logged out of the hub (was previously logged in) */
|
on_user_logout_t on_user_logout; /* A user has logged out of the hub (was previously logged in) */
|
||||||
on_user_nick_change_t on_user_nick_change; /* A user has changed nickname */
|
/* ! */ on_user_nick_change_t on_user_nick_change; /* A user has changed nickname */
|
||||||
on_user_update_error_t on_user_update_error;/* A user has failed to update - nickname, etc. */
|
on_user_update_error_t on_user_update_error;/* A user has failed to update - nickname, etc. */
|
||||||
on_user_chat_msg_t on_user_chat_message;/* A user has sent a public chat message */
|
on_user_chat_msg_t on_user_chat_message;/* A user has sent a public chat message */
|
||||||
|
|
||||||
// Log hub events
|
// Log hub events
|
||||||
on_hub_started_t on_hub_started; /* Triggered just after plugins are loaded and the hub is started. */
|
/* ! */ on_hub_started_t on_hub_started; /* Triggered just after plugins are loaded and the hub is started. */
|
||||||
on_hub_reloaded_t on_hub_reloaded; /* Triggered immediately after hub configuration is reloaded. */
|
/* ! */ on_hub_reloaded_t on_hub_reloaded; /* Triggered immediately after hub configuration is reloaded. */
|
||||||
on_hub_shutdown_t on_hub_shutdown; /* Triggered just before the hub is being shut down and before plugins are unloaded. */
|
/* ! */ on_hub_shutdown_t on_hub_shutdown; /* Triggered just before the hub is being shut down and before plugins are unloaded. */
|
||||||
on_hub_error_t on_hub_error; /* Triggered for log-worthy error messages */
|
/* ! */ on_hub_error_t on_hub_error; /* Triggered for log-worthy error messages */
|
||||||
|
|
||||||
// Activity events (can be intercepted and refused/accepted by a plugin)
|
// Activity events (can be intercepted and refused/accepted by a plugin)
|
||||||
|
on_check_ip_early_t on_check_ip_early; /* A user has just connected (can be intercepted) */
|
||||||
|
/* ! */ on_check_ip_late_t on_check_ip_late; /* A user has logged in (can be intercepted) */
|
||||||
|
/* ! */ on_change_nick_t on_change_nick; /* A user wants to change his nick (can be intercepted) */
|
||||||
on_chat_msg_t on_chat_msg; /* A public chat message is about to be sent (can be intercepted) */
|
on_chat_msg_t on_chat_msg; /* A public chat message is about to be sent (can be intercepted) */
|
||||||
on_private_msg_t on_private_msg; /* A public chat message is about to be sent (can be intercepted) */
|
on_private_msg_t on_private_msg; /* A public chat message is about to be sent (can be intercepted) */
|
||||||
on_search_t on_search; /* A search is about to be sent (can be intercepted) */
|
on_search_t on_search; /* A search is about to be sent (can be intercepted) */
|
||||||
@ -100,9 +103,6 @@ struct plugin_funcs
|
|||||||
auth_update_user_t auth_update_user; /* Update a registered user */
|
auth_update_user_t auth_update_user; /* Update a registered user */
|
||||||
auth_delete_user_t auth_delete_user; /* Delete a registered user */
|
auth_delete_user_t auth_delete_user; /* Delete a registered user */
|
||||||
|
|
||||||
// Login check functions
|
|
||||||
on_check_ip_early_t login_check_ip_early;
|
|
||||||
on_check_ip_late_t login_check_ip_late;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct plugin_command_handle;
|
struct plugin_command_handle;
|
||||||
@ -119,9 +119,9 @@ typedef size_t (*hfunc_command_arg_reset)(struct plugin_handle*, struct plugin_c
|
|||||||
typedef struct plugin_command_arg_data* (*hfunc_command_arg_next)(struct plugin_handle*, struct plugin_command*, enum plugin_command_arg_type);
|
typedef struct plugin_command_arg_data* (*hfunc_command_arg_next)(struct plugin_handle*, struct plugin_command*, enum plugin_command_arg_type);
|
||||||
|
|
||||||
typedef char* (*hfunc_get_hub_name)(struct plugin_handle*);
|
typedef char* (*hfunc_get_hub_name)(struct plugin_handle*);
|
||||||
|
typedef void (*hfunc_set_hub_name)(struct plugin_handle*, const char*);
|
||||||
typedef char* (*hfunc_get_hub_description)(struct plugin_handle*);
|
typedef char* (*hfunc_get_hub_description)(struct plugin_handle*);
|
||||||
typedef void (*hfunc_set_hub_name)(struct plugin_handle*, const char*);
|
typedef void (*hfunc_set_hub_description)(struct plugin_handle*, const char*);
|
||||||
typedef void (*hfunc_set_hub_description)(struct plugin_handle*, const char*);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These are functions created and initialized by the hub and which can be used
|
* These are functions created and initialized by the hub and which can be used
|
||||||
@ -137,8 +137,8 @@ struct plugin_hub_funcs
|
|||||||
hfunc_command_arg_reset command_arg_reset;
|
hfunc_command_arg_reset command_arg_reset;
|
||||||
hfunc_command_arg_next command_arg_next;
|
hfunc_command_arg_next command_arg_next;
|
||||||
hfunc_get_hub_name get_name;
|
hfunc_get_hub_name get_name;
|
||||||
hfunc_get_hub_description get_description;
|
|
||||||
hfunc_set_hub_name set_name;
|
hfunc_set_hub_name set_name;
|
||||||
|
hfunc_get_hub_description get_description;
|
||||||
hfunc_set_hub_description set_description;
|
hfunc_set_hub_description set_description;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#if !defined(WIN32)
|
#if !defined(WIN32)
|
||||||
|
#include <inttypes.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
@ -88,12 +89,13 @@
|
|||||||
#define HAVE_GETRLIMIT
|
#define HAVE_GETRLIMIT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* printf and size_t support */
|
/* printf support for size_t and uint64_t */
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
/* Windows uses %Iu for size_t */
|
|
||||||
#define PRINTF_SIZE_T "%Iu"
|
#define PRINTF_SIZE_T "%Iu"
|
||||||
|
#define PRINTF_UINT64_T "%I64u"
|
||||||
#else
|
#else
|
||||||
#define PRINTF_SIZE_T "%zu"
|
#define PRINTF_SIZE_T "%zu"
|
||||||
|
#define PRINTF_UINT64_T ("%" PRIu64)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SSL_SUPPORT
|
#ifdef SSL_SUPPORT
|
||||||
|
@ -73,10 +73,10 @@ struct cfg_tokens* cfg_tokenize(const char* line)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\"':
|
case '"':
|
||||||
if (backslash)
|
if (backslash)
|
||||||
{
|
{
|
||||||
ADD_CHAR('\"');
|
ADD_CHAR('"');
|
||||||
backslash = 0;
|
backslash = 0;
|
||||||
}
|
}
|
||||||
else if (quote)
|
else if (quote)
|
||||||
|
@ -258,7 +258,7 @@ int file_read_lines(const char* file, void* data, file_line_handler_t handler)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse configuaration */
|
/* Parse configuration */
|
||||||
split_data.handler = handler;
|
split_data.handler = handler;
|
||||||
split_data.data = data;
|
split_data.data = data;
|
||||||
|
|
||||||
@ -303,47 +303,19 @@ int is_number(const char* value, int* num)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* FIXME: -INTMIN is wrong!
|
|
||||||
*/
|
|
||||||
const char* uhub_itoa(int val)
|
const char* uhub_itoa(int val)
|
||||||
{
|
{
|
||||||
size_t i;
|
|
||||||
int value;
|
|
||||||
static char buf[22];
|
static char buf[22];
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
if (!val)
|
|
||||||
{
|
|
||||||
buf[0] = '0';
|
|
||||||
buf[1] = '\0';
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
i = sizeof(buf) - 1;
|
|
||||||
for (value = abs(val); value && i > 0; value /= 10)
|
|
||||||
buf[--i] = "0123456789"[value % 10];
|
|
||||||
|
|
||||||
if (val < 0 && i > 0)
|
return snprintf(buf, sizeof(buf), "%d", val) < 0 ? NULL : buf;
|
||||||
buf[--i] = '-';
|
|
||||||
return buf+i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* uhub_ulltoa(uint64_t val)
|
const char* uhub_ulltoa(uint64_t val)
|
||||||
{
|
{
|
||||||
size_t i;
|
static char buf[22];
|
||||||
static char buf[22] = { 0, };
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
|
|
||||||
if (!val)
|
return snprintf(buf, sizeof(buf), PRINTF_UINT64_T, val) < 0 ? NULL : buf;
|
||||||
{
|
|
||||||
buf[0] = '0';
|
|
||||||
buf[1] = '\0';
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
i = sizeof(buf) - 1;
|
|
||||||
for (; val && i > 0; val /= 10)
|
|
||||||
buf[--i] = "0123456789"[val % 10];
|
|
||||||
return buf+i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +53,11 @@ extern int file_read_lines(const char* file, void* data, file_line_handler_t han
|
|||||||
*/
|
*/
|
||||||
extern int string_to_boolean(const char* str, int* boolean);
|
extern int string_to_boolean(const char* str, int* boolean);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert number to string.
|
||||||
|
* Note: these functions are neither thread-safe nor reentrant.
|
||||||
|
* @return pointer to the resulting string, NULL on error
|
||||||
|
*/
|
||||||
extern const char* uhub_itoa(int val);
|
extern const char* uhub_itoa(int val);
|
||||||
extern const char* uhub_ulltoa(uint64_t val);
|
extern const char* uhub_ulltoa(uint64_t val);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user