]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/bsock.h
kes Expand new BSOCK class adding signal() and new BNET signals.
[bacula/bacula] / bacula / src / lib / bsock.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation plus additions
11    that are listed in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of John Walker.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  * Bacula Sock Structure definition
30  *
31  * Kern Sibbald, May MM
32  *
33  * Zero msglen from other end indicates soft eof (usually
34  *   end of some binary data stream, but not end of conversation).
35  *
36  * Negative msglen, is special "signal" (no data follows).
37  *   See below for SIGNAL codes.
38  *
39  *   Version $Id$
40  */
41
42
43 class BSOCK {
44 public:
45    uint64_t read_seqno;               /* read sequence number */
46    uint32_t in_msg_no;                /* input message number */
47    uint32_t out_msg_no;               /* output message number */
48    int fd;                            /* socket file descriptor */
49    TLS_CONNECTION *tls;               /* associated tls connection */
50    int32_t msglen;                    /* message length */
51    int b_errno;                       /* bsock errno */
52    int port;                          /* desired port */
53    int blocking;                      /* blocking state (0 = nonblocking, 1 = blocking) */
54    volatile int errors;               /* incremented for each error on socket */
55    volatile bool suppress_error_msgs: 1; /* set to suppress error messages */
56    volatile bool timed_out: 1;        /* timed out in read/write */
57    volatile bool terminated: 1;       /* set when BNET_TERMINATE arrives */
58    bool duped: 1;                     /* set if duped BSOCK */
59    bool spool: 1;                     /* set for spooling */
60    volatile time_t timer_start;       /* time started read/write */
61    volatile time_t timeout;           /* timeout BSOCK after this interval */
62    POOLMEM *msg;                      /* message pool buffer */
63    char *who;                         /* Name of daemon to which we are talking */
64    char *host;                        /* Host name/IP */
65    POOLMEM *errmsg;                   /* edited error message */
66    RES *res;                          /* Resource to which we are connected */
67    BSOCK *next;                       /* next BSOCK if duped */
68    FILE *spool_fd;                    /* spooling file */
69    JCR *jcr;                          /* jcr or NULL for error msgs */
70    struct sockaddr client_addr;    /* client's IP address */
71    struct sockaddr_in peer_addr;    /* peer's IP address */
72
73    /* methods -- in bsock.c */
74    bool send();
75    bool fsend(const char*, ...);
76    bool signal(int signal);
77
78 };
79
80 /* Signal definitions for use in bnet_sig() */
81 enum {
82    BNET_EOD            = -1,          /* End of data stream, new data may follow */
83    BNET_EOD_POLL       = -2,          /* End of data and poll all in one */
84    BNET_STATUS         = -3,          /* Send full status */
85    BNET_TERMINATE      = -4,          /* Conversation terminated, doing close() */
86    BNET_POLL           = -5,          /* Poll request, I'm hanging on a read */
87    BNET_HEARTBEAT      = -6,          /* Heartbeat Response requested */
88    BNET_HB_RESPONSE    = -7,          /* Only response permited to HB */
89    BNET_PROMPT         = -8,          /* Prompt for UA */
90    BNET_BTIME          = -9,          /* Send UTC btime */
91    BNET_BREAK          = -10,         /* Stop current command -- ctl-c */
92    BNET_START_SELECT   = -11,         /* Start of a selection list */
93    BNET_END_SELECT     = -12,         /* End of a select list */
94    BNET_INVALID_CMD    = -13,         /* Invalid command sent */
95    BNET_CMD_FAILED     = -14,         /* Command failed */
96    BNET_CMD_OK         = -15,         /* Command succeeded */
97    BNET_CMD_BEGIN      = -16          /* Start command execution */
98 };
99
100 #define BNET_SETBUF_READ  1           /* Arg for bnet_set_buffer_size */
101 #define BNET_SETBUF_WRITE 2           /* Arg for bnet_set_buffer_size */
102
103 /* Return status from bnet_recv() */
104 enum {
105    BNET_SIGNAL         = -1,
106    BNET_HARDEOF        = -2,
107    BNET_ERROR          = -3
108 };
109
110 /*
111  * TLS enabling values. Value is important for comparison, ie:
112  * if (tls_remote_need < BNET_TLS_REQUIRED) { ... }
113  */
114 enum {
115    BNET_TLS_NONE        = 0,          /* cannot do TLS */
116    BNET_TLS_OK          = 1,          /* can do, but not required on my end */
117    BNET_TLS_REQUIRED    = 2           /* TLS is required */
118 };
119
120 int32_t read_nbytes(BSOCK * bsock, char *ptr, int32_t nbytes);
121 int32_t write_nbytes(BSOCK * bsock, char *ptr, int32_t nbytes);