hirc

IRC client
Log | Files | Refs

commit 12dcc76b59802cda402719ccb59e14bbc2f56dc6
parent cc6efa84fd36016d0b5e84b33448c331eb0f8177
Author: hhvn <dev@hhvn.uk>
Date:   Tue,  9 Nov 2021 16:55:51 +0000

main.c serv.c hirc.h: clean disconnects

Diffstat:
Mhirc.h | 3++-
Mmain.c | 13+++++++++++++
Mserv.c | 3++-
3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/hirc.h b/hirc.h @@ -12,6 +12,7 @@ /* main.c */ void * emalloc(size_t size); char * estrdup(const char *str); +void cleanup(char *quitmsg); void param_free(char **params); int param_len(char **params); char ** param_create(char *msg); @@ -73,7 +74,7 @@ int serv_len(struct Server **head); int serv_poll(struct Server **head, int timeout); int serv_remove(struct Server **head, char *name); int serv_selected(struct Server *server); -void serv_disconnect(struct Server *server, int reconnect); +void serv_disconnect(struct Server *server, int reconnect, char *msg); char * support_get(struct Server *server, char *key); void support_set(struct Server *server, char *key, char *value); diff --git a/main.c b/main.c @@ -37,6 +37,19 @@ estrdup(const char *str) { } void +cleanup(char *quitmsg) { + struct Server *sp; + + for (sp = servers; sp; sp = sp->next) { + if (sp->prev) + serv_free(sp->prev); + serv_disconnect(sp, 0, quitmsg); + } + + ui_deinit(); +} + +void param_free(char **params) { char **p; diff --git a/serv.c b/serv.c @@ -269,7 +269,8 @@ serv_poll(struct Server **head, int timeout) { } void -serv_disconnect(struct Server *server, int reconnect) { +serv_disconnect(struct Server *server, int reconnect, char *msg) { + ircprintf(server, "QUIT %s\r\n", msg); shutdown(server->rfd, SHUT_RDWR); shutdown(server->wfd, SHUT_RDWR); close(server->rfd);