Skip to content

Commit 2a47389

Browse files
committed
CF message with an empty or no value will delete the configuration entry for the specified key.
1 parent f2206b6 commit 2a47389

3 files changed

Lines changed: 53 additions & 20 deletions

File tree

include/ircd_netconf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct StatDesc;
3333
#define CONFIG_CREATED 0 /**< New entry created */
3434
#define CONFIG_TIMESTAMP 1 /**< Timestamp updated, same value */
3535
#define CONFIG_CHANGED 2 /**< Value actually changed */
36+
#define CONFIG_DELETED 3 /**< Entry deleted */
3637

3738
/** Configuration entry structure */
3839
struct ConfigEntry {

ircd/ircd_netconf.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,27 @@ int config_set(const char *key, const char *value, time_t timestamp)
125125

126126
entry = config_find(key);
127127

128+
if (value[0] == '\0') {
129+
/* Delete the entry if it exists and timestamp is newer */
130+
if (entry && timestamp > entry->timestamp) {
131+
DupString(old_value, entry->value);
132+
/* Remove from list */
133+
struct ConfigEntry **p = &config_list;
134+
while (*p && *p != entry) p = &(*p)->next;
135+
if (*p == entry) {
136+
*p = entry->next;
137+
MyFree(entry->key);
138+
MyFree(entry->value);
139+
MyFree(entry);
140+
}
141+
config_call_callbacks(key, old_value, NULL);
142+
if (old_value) MyFree(old_value);
143+
return CONFIG_DELETED;
144+
} else {
145+
return CONFIG_REJECTED;
146+
}
147+
}
148+
128149
if (entry) {
129150
/* Only update if timestamp is newer */
130151
if (timestamp <= entry->timestamp)

ircd/m_config.c

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,34 @@ int ms_config(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
4949
const char *key, *value;
5050
const char *old_value;
5151
int result;
52-
53-
if (parc < 4)
54-
return need_more_params(sptr, "CF");
5552

56-
timestamp = atol(parv[1]);
57-
key = parv[2];
58-
value = parv[3];
53+
if (parc < 3)
54+
return need_more_params(sptr, "CF");
55+
56+
timestamp = atol(parv[1]);
57+
key = parv[2];
58+
value = (parc >= 4) ? parv[3] : "";
5959

60-
/* Get the old value for comparison */
61-
old_value = config_get(key);
62-
char *old_value_copy = NULL;
63-
if (old_value)
64-
DupString(old_value_copy, old_value);
60+
/* Get the old value for comparison */
61+
old_value = config_get(key);
62+
char *old_value_copy = NULL;
63+
if (old_value)
64+
DupString(old_value_copy, old_value);
6565

6666
/* Try to set the configuration */
6767
result = config_set(key, value, timestamp);
68-
68+
6969
if (result != CONFIG_REJECTED) {
70-
/* Configuration was set or updated, propagate to other servers */
71-
sendcmdto_serv_butone(sptr, CMD_CONFIG, cptr, "%Tu %s :%s",
72-
timestamp, key, value);
73-
74-
/* Send notification to operators based on what actually happened */
70+
/* Propagate to other servers */
71+
if (value[0] != '\0') {
72+
sendcmdto_serv_butone(sptr, CMD_CONFIG, cptr, "%Tu %s :%s",
73+
timestamp, key, value);
74+
} else {
75+
sendcmdto_serv_butone(sptr, CMD_CONFIG, cptr, "%Tu %s",
76+
timestamp, key);
77+
}
78+
79+
/* Notify operators */
7580
if (result == CONFIG_CREATED) {
7681
sendto_opmask_butone(0, SNO_NETWORK,
7782
"Network configuration set: %s = %s",
@@ -80,10 +85,16 @@ int ms_config(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
8085
sendto_opmask_butone(0, SNO_NETWORK,
8186
"Network configuration updated: %s = %s (was: %s)",
8287
key, value, old_value_copy ? old_value_copy : "(unset)");
88+
} else if (result == CONFIG_DELETED) {
89+
sendto_opmask_butone(0, SNO_NETWORK,
90+
"Network configuration deleted: %s (was: %s)",
91+
key, old_value_copy ? old_value_copy : "(unset)");
92+
Debug((DEBUG_DEBUG, "NETCONF: %s deleted %s (timestamp: %Tu)",
93+
cli_name(sptr), key, timestamp));
94+
} else {
95+
Debug((DEBUG_DEBUG, "NETCONF: %s set %s = %s (timestamp: %Tu)",
96+
cli_name(sptr), key, value, timestamp));
8397
}
84-
85-
Debug((DEBUG_DEBUG, "NETCONF: %s set %s = %s (timestamp: %Tu)",
86-
cli_name(sptr), key, value, timestamp));
8798
}
8899

89100
/* Clean up the copied old value */

0 commit comments

Comments
 (0)