/* * 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 . */ #include "memory.h" #include "types.h" // IRC_* #include // assert() #include // llist_t remove_linked_list_elem() #include // malloc_string() #include // free() #include // 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 */ }