X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Fprotocol.c;h=96d552d4db72e83544cc3b8e6fbbaefb6629ebb7;hb=691567b16c13087b31ee4c2b6d038e57872fae82;hp=4b3f54ffd02db456644cd82e37b25b141483f294;hpb=ac973066bc508cb82728e46eaf499e9424d4e0f1;p=debian%2Famanda diff --git a/common-src/protocol.c b/common-src/protocol.c index 4b3f54f..96d552d 100644 --- a/common-src/protocol.c +++ b/common-src/protocol.c @@ -1,6 +1,7 @@ /* * Amanda, The Advanced Maryland Automatic Network Disk Archiver * Copyright (c) 1991-1999 University of Maryland at College Park + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its @@ -35,10 +36,10 @@ #include "security.h" #include "protocol.h" -#define proto_debug(i,x) do { \ - if ((i) <= debug_protocol) { \ - dbprintf(x); \ - } \ +#define proto_debug(i, ...) do { \ + if ((i) <= debug_protocol) { \ + dbprintf(__VA_ARGS__); \ + } \ } while (0) /* @@ -159,7 +160,7 @@ protocol_sendreq( p->resettries = RESET_TRIES; p->reqtries = getconf_int(CNF_REQ_TRIES); p->conf_fn = conf_fn; - pkt_init(&p->req, P_REQ, req); + pkt_init(&p->req, P_REQ, "%s", req); /* * These are here for the caller @@ -170,8 +171,8 @@ protocol_sendreq( p->continuation = continuation; p->datap = datap; - proto_debug(1, ("%s: security_connect: host %s -> p %p\n", - debug_prefix_time(": protocol"), hostname, p)); + proto_debug(1, _("protocol: security_connect: host %s -> p %p\n"), + hostname, p); security_connect(p->security_driver, p->hostname, conf_fn, connect_callback, p, p->datap); @@ -196,8 +197,7 @@ connect_callback( assert(p != NULL); p->security_handle = security_handle; - proto_debug(1, ("%s: connect_callback: p %p\n", - debug_prefix_time(": protocol"), p)); + proto_debug(1, _("protocol: connect_callback: p %p\n"), p); switch (status) { case S_OK: @@ -205,7 +205,7 @@ connect_callback( break; case S_TIMEOUT: - security_seterror(p->security_handle, "timeout during connect"); + security_seterror(p->security_handle, _("timeout during connect")); /* FALLTHROUGH */ case S_ERROR: @@ -217,8 +217,8 @@ connect_callback( if (--p->connecttries == 0) { state_machine(p, PA_ABORT, NULL); } else { - proto_debug(1, ("%s: connect_callback: p %p: retrying %s\n", - debug_prefix_time(": protocol"), p, p->hostname)); + proto_debug(1, _("protocol: connect_callback: p %p: retrying %s\n"), + p, p->hostname); security_close(p->security_handle); /* XXX overload p->security handle to hold the event handle */ p->security_handle = @@ -301,24 +301,22 @@ state_machine( pstate_t curstate; p_action_t retaction; - proto_debug(1, ("protocol: state_machine: initial: p %p action %s pkt %p\n", - p, action2str(action), (void *)NULL)); + proto_debug(1, _("protocol: state_machine: initial: p %p action %s pkt %p\n"), + p, action2str(action), (void *)NULL); assert(p != NULL); assert(action == PA_RCVDATA || pkt == NULL); assert(p->state != NULL); for (;;) { - proto_debug(1, ("%s: state_machine: p %p state %s action %s\n", - debug_prefix_time(": protocol"), - p, pstate2str(p->state), action2str(action))); + proto_debug(1, _("protocol: state_machine: p %p state %s action %s\n"), + p, pstate2str(p->state), action2str(action)); if (pkt != NULL) { - proto_debug(1, ("%s: pkt: %s (t %d) orig REQ (t %d cur %d)\n", - debug_prefix_time(": protocol"), + proto_debug(1, _("protocol: pkt: %s (t %d) orig REQ (t %d cur %d)\n"), pkt_type2str(pkt->type), (int)CURTIME, - (int)p->origtime, (int)p->curtime)); - proto_debug(1, ("%s: pkt contents:\n-----\n%s-----\n", - debug_prefix_time(": protocol"), pkt->body)); + (int)p->origtime, (int)p->curtime); + proto_debug(1, _("protocol: pkt contents:\n-----\n%s-----\n"), + pkt->body); } /* @@ -344,9 +342,8 @@ state_machine( */ retaction = (*curstate)(p, action, pkt); - proto_debug(1, ("%s: state_machine: p %p state %s returned %s\n", - debug_prefix_time(": protocol"), - p, pstate2str(p->state), action2str(retaction))); + proto_debug(1, _("protocol: state_machine: p %p state %s returned %s\n"), + p, pstate2str(p->state), action2str(retaction)); /* * The state function is expected to return one of the following @@ -364,9 +361,8 @@ state_machine( /* FALLTHROUGH */ case PA_PENDING: - proto_debug(1, ("%s: state_machine: p %p state %s: timeout %d\n", - debug_prefix_time(": protocol"), - p, pstate2str(p->state), (int)p->timeout)); + proto_debug(1, _("protocol: state_machine: p %p state %s: timeout %d\n"), + p, pstate2str(p->state), (int)p->timeout); /* * Get the security layer to register a receive event for this * security handle on our behalf. Have it timeout in p->timeout @@ -382,10 +378,9 @@ state_machine( */ case PA_CONTINUE: assert(p->state != curstate); - proto_debug(1, ("%s: state_machine: p %p: moved from %s to %s\n", - debug_prefix_time(": protocol"), + proto_debug(1, _("protocol: state_machine: p %p: moved from %s to %s\n"), p, pstate2str(curstate), - pstate2str(p->state))); + pstate2str(p->state)); continue; /* @@ -442,7 +437,7 @@ s_sendreq( if (security_sendpkt(p->security_handle, &p->req) < 0) { /* XXX should retry */ - security_seterror(p->security_handle, "error sending REQ: %s", + security_seterror(p->security_handle, _("error sending REQ: %s"), security_geterror(p->security_handle)); return (PA_ABORT); } @@ -491,7 +486,7 @@ s_ackwait( assert(pkt == NULL); if (--p->reqtries == 0) { - security_seterror(p->security_handle, "timeout waiting for ACK"); + security_seterror(p->security_handle, _("timeout waiting for ACK")); return (PA_ABORT); } @@ -567,7 +562,7 @@ s_repwait( * return. */ if (p->resettries == 0 || DROP_DEAD_TIME(p->origtime)) { - security_seterror(p->security_handle, "timeout waiting for REP"); + security_seterror(p->security_handle, _("timeout waiting for REP")); return (PA_ABORT); } @@ -582,6 +577,10 @@ s_repwait( assert(action == PA_RCVDATA); + /* Finish if we get a NAK */ + if (pkt->type == P_NAK) + return (PA_FINISH); + /* * We've received some data. If we didn't get a reply, * requeue the packet and retry. Otherwise, acknowledge @@ -595,7 +594,7 @@ s_repwait( if (security_sendpkt(p->security_handle, &ack) < 0) { /* XXX should retry */ amfree(ack.body); - security_seterror(p->security_handle, "error sending ACK: %s", + security_seterror(p->security_handle, _("error sending ACK: %s"), security_geterror(p->security_handle)); return (PA_ABORT); } @@ -604,6 +603,8 @@ s_repwait( } else if(pkt->type == P_PREP) { p->timeout = p->repwait - CURTIME + p->curtime + 1; + if (p->timeout <= 0) + p->timeout = 1; return (PA_CONTPEND); } @@ -667,7 +668,7 @@ pstate2str( for (i = 0; i < ASIZE(pstates); i++) if (pstate == pstates[i].type) return (pstates[i].name); - return ("BOGUS PSTATE"); + return (_("BOGUS PSTATE")); } /* @@ -698,5 +699,5 @@ action2str( for (i = 0; i < ASIZE(actions); i++) if (action == actions[i].type) return (actions[i].name); - return ("BOGUS ACTION"); + return (_("BOGUS ACTION")); }