/
bget_msg.cc
102 lines (93 loc) · 3.18 KB
/
bget_msg.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2001-2011 Free Software Foundation Europe e.V.
Copyright (C) 2016-2016 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
/*
* Kern Sibbald, May MMI previously in src/stored/fdmsg.c
*/
/**
* @file
* Subroutines to receive network data and handle
* network signals for the FD and the SD.
*/
#include "include/bareos.h" /* pull in global headers */
#include "lib/bnet.h"
#include "lib/bget_msg.h"
static char OK_msg[] = "2000 OK\n";
static char TERM_msg[] = "2999 Terminate\n";
#define messagelevel 500
/**
* This routine does a BnetRecv(), then if a signal was
* sent, it handles it. The return codes are the same as
* bne_recv() except the BNET_SIGNAL messages that can
* be handled are done so without returning.
*
* Returns number of bytes read (may return zero)
* Returns -1 on signal (BNET_SIGNAL)
* Returns -2 on hard end of file (BNET_HARDEOF)
* Returns -3 on error (BNET_ERROR)
*/
int BgetMsg(BareosSocket *sock)
{
int n;
for ( ;; ) {
n = sock->recv();
if (n >= 0) { /* normal return */
return n;
}
if (IsBnetStop(sock)) { /* error return */
return n;
}
/* BNET_SIGNAL (-1) return from BnetRecv() => network signal */
switch (sock->message_length) {
case BNET_EOD: /* end of data */
Dmsg0(messagelevel, "Got BNET_EOD\n");
return n;
case BNET_EOD_POLL:
Dmsg0(messagelevel, "Got BNET_EOD_POLL\n");
if (sock->IsTerminated()) {
sock->fsend(TERM_msg);
} else {
sock->fsend(OK_msg); /* send response */
}
return n; /* end of data */
case BNET_TERMINATE:
Dmsg0(messagelevel, "Got BNET_TERMINATE\n");
sock->SetTerminated();
return n;
case BNET_POLL:
Dmsg0(messagelevel, "Got BNET_POLL\n");
if (sock->IsTerminated()) {
sock->fsend(TERM_msg);
} else {
sock->fsend(OK_msg); /* send response */
}
break;
case BNET_HEARTBEAT:
case BNET_HB_RESPONSE:
break;
case BNET_STATUS:
/* *****FIXME***** Implement BNET_STATUS */
Dmsg0(messagelevel, "Got BNET_STATUS\n");
sock->fsend(_("Status OK\n"));
sock->signal(BNET_EOD);
break;
default:
Emsg1(M_ERROR, 0, _("BgetMsg: unknown signal %d\n"), sock->message_length);
break;
}
}
}