mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-08 15:53:13 +02:00
Rename nvplist functions to match the rest, fix resource leak,
and move the functions to list.c where they belong. nvplist_add() -> add_nvplist() nvplist_add_fmt() -> add_fmt_nvplist() (new) -> free_nvplist
This commit is contained in:
+3
-2
@@ -999,6 +999,7 @@ extern void free_security_group(SecurityGroup *s);
|
||||
extern void set_security_group_defaults(void);
|
||||
extern int user_allowed_by_security_group(Client *client, SecurityGroup *s);
|
||||
extern int user_allowed_by_security_group_name(Client *client, char *secgroupname);
|
||||
extern void nvplist_add(NameValuePrioList **lst, int priority, char *name, char *value);
|
||||
extern void nvplist_add_fmt(NameValuePrioList **lst, int priority, char *name, FORMAT_STRING(const char *format), ...) __attribute__((format(printf,4,5)));
|
||||
extern void add_nvplist(NameValuePrioList **lst, int priority, char *name, char *value);
|
||||
extern void add_fmt_nvplist(NameValuePrioList **lst, int priority, char *name, FORMAT_STRING(const char *format), ...) __attribute__((format(printf,4,5)));
|
||||
extern void free_nvplist(NameValuePrioList *lst);
|
||||
extern char *get_connect_extinfo(Client *client);
|
||||
|
||||
+35
@@ -567,3 +567,38 @@ NameList *find_name_list_match(NameList *list, char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void add_nvplist(NameValuePrioList **lst, int priority, char *name, char *value)
|
||||
{
|
||||
va_list vl;
|
||||
NameValuePrioList *e = safe_alloc(sizeof(NameValuePrioList));
|
||||
safe_strdup(e->name, name);
|
||||
if (value && *value)
|
||||
safe_strdup(e->value, value);
|
||||
AddListItemPrio(e, *lst, priority);
|
||||
}
|
||||
|
||||
void add_fmt_nvplist(NameValuePrioList **lst, int priority, char *name, FORMAT_STRING(const char *format), ...)
|
||||
{
|
||||
char value[512];
|
||||
va_list vl;
|
||||
*value = '\0';
|
||||
if (format)
|
||||
{
|
||||
va_start(vl, format);
|
||||
vsnprintf(value, sizeof(value), format, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
add_nvplist(lst, priority, name, value);
|
||||
}
|
||||
|
||||
void free_nvplist(NameValuePrioList *lst)
|
||||
{
|
||||
NameValuePrioList *e, *e_next;
|
||||
for (e = lst; e; e = e_next)
|
||||
{
|
||||
e_next = e->next;
|
||||
safe_free(e->name);
|
||||
safe_free(e->value);
|
||||
safe_free(e);
|
||||
}
|
||||
}
|
||||
|
||||
-24
@@ -1964,27 +1964,3 @@ char *sendtype_to_cmd(SendType sendtype)
|
||||
return "TAGMSG";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void nvplist_add(NameValuePrioList **lst, int priority, char *name, char *value)
|
||||
{
|
||||
va_list vl;
|
||||
NameValuePrioList *e = safe_alloc(sizeof(NameValuePrioList));
|
||||
safe_strdup(e->name, name);
|
||||
if (value && *value)
|
||||
safe_strdup(e->value, value);
|
||||
AddListItemPrio(e, *lst, priority);
|
||||
}
|
||||
|
||||
void nvplist_add_fmt(NameValuePrioList **lst, int priority, char *name, FORMAT_STRING(const char *format), ...)
|
||||
{
|
||||
char value[512];
|
||||
va_list vl;
|
||||
*value = '\0';
|
||||
if (format)
|
||||
{
|
||||
va_start(vl, format);
|
||||
vsnprintf(value, sizeof(value), format, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
nvplist_add(lst, priority, name, value);
|
||||
}
|
||||
|
||||
@@ -673,7 +673,7 @@ CMD_FUNC(reputationunperm)
|
||||
|
||||
int reputation_connect_extinfo(Client *client, NameValuePrioList **list)
|
||||
{
|
||||
nvplist_add_fmt(list, 0, "reputation", "%d", GetReputation(client));
|
||||
add_fmt_nvplist(list, 0, "reputation", "%d", GetReputation(client));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+8
-4
@@ -889,17 +889,17 @@ char *get_connect_extinfo(Client *client)
|
||||
|
||||
/* "class": this should be first */
|
||||
if (MyUser(client) && client->local->class)
|
||||
nvplist_add(&list, -100000, "class", client->local->class->name);
|
||||
add_nvplist(&list, -100000, "class", client->local->class->name);
|
||||
|
||||
/* "secure": SSL/TLS */
|
||||
if (MyUser(client) && IsSecure(client))
|
||||
nvplist_add(&list, -1000, "secure", tls_get_cipher(client->local->ssl));
|
||||
add_nvplist(&list, -1000, "secure", tls_get_cipher(client->local->ssl));
|
||||
else if (!MyUser(client) && IsSecureConnect(client))
|
||||
nvplist_add(&list, -1000, "secure", NULL);
|
||||
add_nvplist(&list, -1000, "secure", NULL);
|
||||
|
||||
/* services account? */
|
||||
if (IsLoggedIn(client))
|
||||
nvplist_add(&list, -500, "account", client->user->svid);
|
||||
add_nvplist(&list, -500, "account", client->user->svid);
|
||||
|
||||
*retbuf = '\0';
|
||||
for (e = list; e; e = e->next)
|
||||
@@ -913,5 +913,9 @@ char *get_connect_extinfo(Client *client)
|
||||
/* Cut off last space (unless empty string) */
|
||||
if (*buf)
|
||||
buf[strlen(buf)-1] = '\0';
|
||||
|
||||
/* Free the list, as it was only used to build retbuf */
|
||||
free_nvplist(list);
|
||||
|
||||
return retbuf;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user