ms-runner/transport/utils.c

48 lines
1.4 KiB
C

#define _GNU_SOURCE
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gen/runner/v1/runner.pb-c.h"
#include <rabbitmq-c/amqp.h>
#include <rabbitmq-c/framing.h>
#include <rabbitmq-c/tcp_socket.h>
#include <stdint.h>
#include "transport/transport.h"
char* amqp_error(amqp_rpc_reply_t x) {
char* res=NULL;
switch (x.reply_type) {
case AMQP_RESPONSE_NORMAL:
break;
case AMQP_RESPONSE_NONE:
asprintf(&res,"missing RPC reply type");
break;
case AMQP_RESPONSE_LIBRARY_EXCEPTION:
asprintf(&res,amqp_error_string2(x.library_error));
break;
case AMQP_RESPONSE_SERVER_EXCEPTION:
switch (x.reply.id) {
case AMQP_CONNECTION_CLOSE_METHOD: {
amqp_connection_close_t *m = (amqp_connection_close_t *)x.reply.decoded;
asprintf(&res,"server connection error %uh, message: %.*s\n", m->reply_code, (int)m->reply_text.len, (char *)m->reply_text.bytes);
break;
}
case AMQP_CHANNEL_CLOSE_METHOD: {
amqp_channel_close_t *m = (amqp_channel_close_t *)x.reply.decoded;
asprintf(&res,"server channel error %uh, message: %.*s\n", m->reply_code, (int)m->reply_text.len, (char *)m->reply_text.bytes);
break;
}
default:
asprintf(&res,"unknown server error, method id 0x%08X\n", x.reply.id);
break;
}
}
return res;
}