This repository has been archived on 2021-04-17. You can view files and clone it, but cannot push or open issues or pull requests.
uIRC/src/memory/free.c

124 lines
2.6 KiB
C

/*
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
* Copyright (c) 2019, 2020 Alex-David Denes
*
* uIRC is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* uIRC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with uIRC. If not, see <https://www.gnu.org/licenses/>.
*/
#include "memory.h"
#include "types.h" // IRC_*
#include <assert.h> // assert()
#include <corelibs/llist.h> // llist_t remove_linked_list_elem()
#include <corelibs/stringext.h> // malloc_string()
#include <stdlib.h> // free()
#include <string.h> // strcpy()
#ifdef UIRC_FEATURE_IRCV3
void
uirc_free_tag(IRC_Tag* t)
{
assert(t != NULL);
free(t->key);
free(t->value);
}
void
uirc_free_capability(IRC_Capability* c)
{
assert(c != NULL);
free(c->name);
}
#endif /* UIRC_FEATURE_IRCV3 */
void
uirc_free_user(IRC_User* u)
{
assert(u != NULL);
free(u->user);
free(u->nick);
free(u->host);
free(u->real);
}
void
uirc_free_message(IRC_Message* m)
{
assert(m != NULL);
if (m->source != NULL) {
uirc_free_user(m->source);
free(m->source);
}
free(m->command);
for (unsigned short i = 0; m->args[i] != NULL; i++) free(m->args[i]);
#ifdef UIRC_FEATURE_IRCV3
for (llist_t* t = m->tag_list; t != NULL; t = t->next) {
uirc_free_tag(t->content);
remove_linked_list_elem(t);
}
#endif /* UIRC_FEATURE_IRCV3 */
}
void
uirc_free_buffer(IRC_Buffer* b)
{
assert(b != NULL);
free(b->name);
free(b->topic);
free(b->key);
for (llist_t* t = b->user_list; t != NULL; t = t->next) {
uirc_free_user(t->content);
remove_linked_list_elem(t);
}
for (llist_t* t = b->message_list; t != NULL; t = t->next) {
uirc_free_message(t->content);
remove_linked_list_elem(t);
}
}
void
uirc_free_network(IRC_Network* n)
{
assert(n != NULL);
free(n->addr);
free(n->svc);
free(n->pass);
free(n->quitmsg);
if (n->user != NULL) {
uirc_free_user(n->user);
free(n->user);
}
for (llist_t* t = n->buf_list; t != NULL; t = t->next) {
uirc_free_buffer(t->content);
remove_linked_list_elem(t);
}
#ifdef UIRC_FEATURE_IRCV3
for (llist_t* t = n->cap_list; t != NULL; t = t->next) {
uirc_free_capability(t->content);
remove_linked_list_elem(t);
}
#endif /* UIRC_FEATURE_IRCV3 */
}