/* for commands with a simple integer response */
static void integer_response_opcallback(disorder_eclient *c,
struct operation *op) {
+ disorder_eclient_integer_response *completed
+ = (disorder_eclient_integer_response *)op->completed;
+
D(("string_response_callback"));
if(c->rc / 100 == 2) {
- if(op->completed)
- ((disorder_eclient_integer_response *)op->completed)
- (op->v, strtol(c->line + 4, 0, 10));
+ long n;
+ int e;
+
+ e = xstrtol(&n, c->line + 4, 0, 10);
+ if(e)
+ completed(op->v, strerror(e), 0);
+ else
+ completed(op->v, 0, n);
} else
- /* TODO don't use protocol_error here */
- protocol_error(c, op, c->rc, "%s: %s", c->ident, c->line);
+ completed(op->v, errorstring(c), 0);
}
/* for commands with no response */
static void no_response_opcallback(disorder_eclient *c,
struct operation *op) {
+ disorder_eclient_no_response *completed
+ = (disorder_eclient_no_response *)op->completed;
+
D(("no_response_callback"));
- if(c->rc / 100 == 2) {
- if(op->completed)
- ((disorder_eclient_no_response *)op->completed)(op->v);
- } else
- /* TODO don't use protocol_error here */
- protocol_error(c, op, c->rc, "%s: %s", c->ident, c->line);
+ if(c->rc / 100 == 2)
+ completed(op->v, NULL);
+ else
+ completed(op->v, errorstring(c));
}
/* error callback for queue_unmarshall */
/* for volume */
static void volume_response_opcallback(disorder_eclient *c,
struct operation *op) {
+ disorder_eclient_volume_response *completed
+ = (disorder_eclient_volume_response *)op->completed;
int l, r;
D(("volume_response_callback"));
if(c->rc / 100 == 2) {
if(op->completed) {
if(sscanf(c->line + 4, "%d %d", &l, &r) != 2 || l < 0 || r < 0)
- /* TODO don't use protocol_error here */
- protocol_error(c, op, -1, "%s: invalid volume response: %s",
- c->ident, c->line);
+ completed(op->v, "cannot parse volume response", 0, 0);
else
- ((disorder_eclient_volume_response *)op->completed)(op->v, l, r);
+ completed(op->v, 0, l, r);
}
} else
- /* TODO don't use protocol_error here */
- protocol_error(c, op, c->rc, "%s: %s", c->ident, c->line);
+ completed(op->v, errorstring(c), 0, 0);
}
static int simple(disorder_eclient *c,