summaryrefslogtreecommitdiff
path: root/librabbitmq/amqp_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'librabbitmq/amqp_api.c')
-rw-r--r--librabbitmq/amqp_api.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/librabbitmq/amqp_api.c b/librabbitmq/amqp_api.c
index a748f90..3724a37 100644
--- a/librabbitmq/amqp_api.c
+++ b/librabbitmq/amqp_api.c
@@ -52,7 +52,6 @@
#include <stdio.h>
#include <string.h>
#include <stdint.h>
-#include <errno.h>
#include "amqp.h"
#include "amqp_framing.h"
@@ -60,6 +59,40 @@
#include <assert.h>
+static const char *client_error_strings[ERROR_MAX] = {
+ "could not allocate memory", /* ERROR_NO_MEMORY */
+ "received bad AMQP data", /* ERROR_BAD_AQMP_DATA */
+ "unknown AMQP class id", /* ERROR_UNKOWN_CLASS */
+ "unknown AMQP method id", /* ERROR_UNKOWN_METHOD */
+ "unknown host", /* ERROR_HOST_NOT_FOUND */
+ "incompatible AMQP version", /* ERROR_INCOMPATIBLE_AMQP_VERSION */
+ "connection closed unexpectedly", /* ERROR_CONNECTION_CLOSED */
+};
+
+const char *amqp_error_string(int err)
+{
+ const char *str;
+ int category = (err & ERROR_CATEGORY_MASK);
+ err = (err & ~ERROR_CATEGORY_MASK);
+
+ switch (category) {
+ case ERROR_CATEGORY_CLIENT:
+ if (err < 1 || err > ERROR_MAX)
+ str = "(undefined librabbitmq error)";
+ else
+ str = client_error_strings[err - 1];
+ break;
+
+ case ERROR_CATEGORY_OS:
+ return amqp_os_error_string(err);
+
+ default:
+ str = "(undefined error category)";
+ }
+
+ return strdup(str);
+}
+
#define RPC_REPLY(replytype) \
(state->most_recent_api_result.reply_type == AMQP_RESPONSE_NORMAL \
? (replytype *) state->most_recent_api_result.reply.decoded \