Fix various problems with adding and removing module DCC bindings

Change remove_all_dcc_binds() so that it only removes DCC binds for the module supplied, as it's supposed to.

get_dcc_type() should ignore the first entry in dcc_types[] ("<none>") otherwise the client will try to
respond to DCC requests with that name.

Explicitly track the number of entries in the dcc_types[] array rather than using a NULL terminator.  This
allows us to change dcc_types[] to use NULL entries to mark unused slots in the array, rather than pointers
to entries with a NULL .name element.  Together, this means that the dcc_types[] array is only resized when it
actually needs to be grown and removal works correctly (without eg. prematurely marking the end of the array).

Make add_dcc_bind() fail if the requested DCC type has already been bound by a module (this still allows one
module at a time to rebind a built-in DCC type).  Previously the behaviour was ill-defined in this case.
This commit is contained in:
Kevin Easton
2018-02-20 23:27:32 +11:00
parent 5ae42802ec
commit 9e7fc85ae1
4 changed files with 84 additions and 42 deletions

View File

@@ -156,7 +156,7 @@ struct dcc_offer {
int check_dcc_socket(int);
char *get_dcc_info(SocketList *, DCC_int *, int);
void init_dcc_table(void);
int BX_remove_all_dcc_binds(char *);
int BX_remove_all_dcc_binds(const char *);
int BX_remove_dcc_bind(char *, int);
/* Function pointers for the operations implementing a DCC type.

View File

@@ -606,7 +606,7 @@ extern Function_ptr *global;
#define erase_dcc_info (*(void (*)(int, int, char *, ...))global[ERASE_DCC_INFO])
#define add_dcc_bind (*(int (*)(char *, char *, const struct dcc_ops *))global[ADD_DCC_BIND])
#define remove_dcc_bind (*(int (*)(char *, int ))global[REMOVE_DCC_BIND])
#define remove_all_dcc_binds (*(int (*)(char *))global[REMOVE_ALL_DCC_BINDS])
#define remove_all_dcc_binds (*(int (*)(const char *))global[REMOVE_ALL_DCC_BINDS])
#define get_active_count (*(int (*)(void ))global[GET_ACTIVE_COUNT])
#define get_num_queue (*(int (*)(void ))global[GET_NUM_QUEUE])
#define add_to_queue (*(int (*)(char *, char *, pack *))global[ADD_TO_QUEUE])