From ff1dad7ec8717a3cf4a798daff9f025964c660f5 Mon Sep 17 00:00:00 2001 From: defanor Date: Thu, 26 Nov 2020 15:09:42 +0300 Subject: Introduce rexmpp_strerror --- examples/basic.c | 2 +- examples/weechat.c | 2 +- src/rexmpp.c | 31 +++++++++++++++++++++++++++++++ src/rexmpp.h | 9 ++++++++- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/examples/basic.c b/examples/basic.c index 1d19c90..cd3d6e3 100644 --- a/examples/basic.c +++ b/examples/basic.c @@ -160,7 +160,7 @@ main (int argc, char **argv) { break; } if (err != REXMPP_E_AGAIN) { - puts("error"); + printf("error: %s\n", rexmpp_strerror(err)); break; } /* Could inspect the state here. */ diff --git a/examples/weechat.c b/examples/weechat.c index 29a592a..1fa4e57 100644 --- a/examples/weechat.c +++ b/examples/weechat.c @@ -432,7 +432,7 @@ void iter (struct weechat_rexmpp *wr, fd_set *rfds, fd_set *wfds) { return; } if (err != REXMPP_E_AGAIN) { - weechat_printf(wr->server_buffer, "rexmpp error"); + weechat_printf(wr->server_buffer, "rexmpp error: %s", rexmpp_strerror(err)); return; } fd_set read_fds, write_fds; diff --git a/src/rexmpp.c b/src/rexmpp.c index a004fbe..13b8c00 100644 --- a/src/rexmpp.c +++ b/src/rexmpp.c @@ -34,6 +34,37 @@ #include "rexmpp_openpgp.h" #include "rexmpp_console.h" +const char *rexmpp_strerror (rexmpp_err_t error) { + switch (error) { + case REXMPP_SUCCESS: return "No error"; + case REXMPP_E_AGAIN: return "An operation is in progress"; + case REXMPP_E_SEND_QUEUE_FULL: return + "A message can't be queued for sending, because the queue is full"; + case REXMPP_E_STANZA_QUEUE_FULL: return + "The library can't take responsibility for message delivery because " + "XEP-0198 stanza queue is full"; + case REXMPP_E_CANCELLED: return "Cancelled by a user"; + case REXMPP_E_SEND_BUFFER_EMPTY: return + "Attempted to send while send buffer is empty"; + case REXMPP_E_SEND_BUFFER_NOT_EMPTY: return + "Attempted to start sending while send buffer is not empty"; + case REXMPP_E_SASL: return "SASL-related error"; + case REXMPP_E_PGP: return "OpenPGP-related error"; + case REXMPP_E_TLS: return "TLS-related error"; + case REXMPP_E_TCP: return "TCP-related error"; + case REXMPP_E_DNS: return "DNS-related error"; + case REXMPP_E_XML: return "XML-related error"; + case REXMPP_E_JID: return "JID-related error"; + case REXMPP_E_MALLOC: return "Memory allocation failure"; + case REXMPP_E_ROSTER: return "Roster-related error"; + case REXMPP_E_ROSTER_ITEM_NOT_FOUND: return "Roster item is not found"; + case REXMPP_E_PARAM: return "An erroneous parameter is supplied"; + case REXMPP_E_STREAM: return "A stream error"; + case REXMPP_E_OTHER: return "An unspecified error"; + default: return "Unknown error"; + } +} + void rexmpp_sax_start_elem_ns (rexmpp_t *s, const char *localname, const char *prefix, diff --git a/src/rexmpp.h b/src/rexmpp.h index 781a1df..570cab1 100644 --- a/src/rexmpp.h +++ b/src/rexmpp.h @@ -178,7 +178,7 @@ enum rexmpp_err { REXMPP_E_SEND_BUFFER_NOT_EMPTY, /** SASL-related error. */ REXMPP_E_SASL, - /** OpenGPG-related error. */ + /** OpenPGP-related error. */ REXMPP_E_PGP, /** TLS-related error. */ REXMPP_E_TLS, @@ -519,4 +519,11 @@ xmlNodePtr rexmpp_find_event (rexmpp_t *s, void rexmpp_console_feed (rexmpp_t *s, char *str, ssize_t str_len); +/** + @brief A strerror function for ::rexmpp_err + @param[in] error Error code, as returned by rexmpp functions. + @returns A string explaining the error. +*/ +const char *rexmpp_strerror (rexmpp_err_t error); + #endif -- cgit v1.2.3