]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/bget_msg.c
kes Add dynamic dll entry point for SHGetFolderPath to Win32 code.
[bacula/bacula] / bacula / src / lib / bget_msg.c
1 /*
2  *  Subroutines to receive network data and handle
3  *   network signals for the FD and the SD.
4  *
5  *   Kern Sibbald, May MMI previously in src/stored/fdmsg.c
6  *
7  *   Version $Id$
8  *
9  */
10 /*
11    Bacula® - The Network Backup Solution
12
13    Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
14
15    The main author of Bacula is Kern Sibbald, with contributions from
16    many others, a complete list can be found in the file AUTHORS.
17    This program is Free Software; you can redistribute it and/or
18    modify it under the terms of version two of the GNU General Public
19    License as published by the Free Software Foundation plus additions
20    that are listed in the file LICENSE.
21
22    This program is distributed in the hope that it will be useful, but
23    WITHOUT ANY WARRANTY; without even the implied warranty of
24    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25    General Public License for more details.
26
27    You should have received a copy of the GNU General Public License
28    along with this program; if not, write to the Free Software
29    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30    02110-1301, USA.
31
32    Bacula® is a registered trademark of John Walker.
33    The licensor of Bacula is the Free Software Foundation Europe
34    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
35    Switzerland, email:ftf@fsfeurope.org.
36 */
37
38 #include "bacula.h"                   /* pull in global headers */
39
40 static char OK_msg[]   = "2000 OK\n";
41 static char TERM_msg[] = "2999 Terminate\n";
42
43 #define msglvl 500
44
45 /*
46  * This routine does a bnet_recv(), then if a signal was
47  *   sent, it handles it.  The return codes are the same as
48  *   bne_recv() except the BNET_SIGNAL messages that can
49  *   be handled are done so without returning.
50  *
51  * Returns number of bytes read (may return zero)
52  * Returns -1 on signal (BNET_SIGNAL)
53  * Returns -2 on hard end of file (BNET_HARDEOF)
54  * Returns -3 on error  (BNET_ERROR)
55  */
56 int bget_msg(BSOCK *sock)
57 {
58    int n;
59    for ( ;; ) {
60       n = bnet_recv(sock);
61       if (n >= 0) {                  /* normal return */
62          return n;
63       }
64       if (is_bnet_stop(sock)) {      /* error return */
65          return n;
66       }
67
68       /* BNET_SIGNAL (-1) return from bnet_recv() => network signal */
69       switch (sock->msglen) {
70       case BNET_EOD:               /* end of data */
71          Dmsg0(msglvl, "Got BNET_EOD\n");
72          return n;
73       case BNET_EOD_POLL:
74          Dmsg0(msglvl, "Got BNET_EOD_POLL\n");
75          if (sock->terminated) {
76             bnet_fsend(sock, TERM_msg);
77          } else {
78             bnet_fsend(sock, OK_msg); /* send response */
79          }
80          return n;                 /* end of data */
81       case BNET_TERMINATE:
82          Dmsg0(msglvl, "Got BNET_TERMINATE\n");
83          sock->terminated = 1;
84          return n;
85       case BNET_POLL:
86          Dmsg0(msglvl, "Got BNET_POLL\n");
87          if (sock->terminated) {
88             bnet_fsend(sock, TERM_msg);
89          } else {
90             bnet_fsend(sock, OK_msg); /* send response */
91          }
92          break;
93       case BNET_HEARTBEAT:
94       case BNET_HB_RESPONSE:
95          break;
96       case BNET_STATUS:
97          /* *****FIXME***** Implement BNET_STATUS */
98          Dmsg0(msglvl, "Got BNET_STATUS\n");
99          bnet_fsend(sock, _("Status OK\n"));
100          bnet_sig(sock, BNET_EOD);
101          break;
102       default:
103          Emsg1(M_ERROR, 0, _("bget_msg: unknown signal %d\n"), sock->msglen);
104          break;
105       }
106    }
107 }