]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/bsock.h
kes Begin implementing new comm signals for API.
[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 private:
45    BSOCK *m_next;                     /* next BSOCK if duped */
46    JCR *m_jcr;                        /* jcr or NULL for error msgs */
47    char *m_who;                       /* Name of daemon to which we are talking */
48    char *m_host;                      /* Host name/IP */
49    int m_port;                        /* desired port */
50    
51 public:
52    uint64_t read_seqno;               /* read sequence number */
53    uint32_t in_msg_no;                /* input message number */
54    uint32_t out_msg_no;               /* output message number */
55    int fd;                            /* socket file descriptor */
56    TLS_CONNECTION *tls;               /* associated tls connection */
57    int32_t msglen;                    /* message length */
58    int b_errno;                       /* bsock errno */
59    int blocking;                      /* blocking state (0 = nonblocking, 1 = blocking) */
60    volatile int errors;               /* incremented for each error on socket */
61    volatile bool suppress_error_msgs: 1; /* set to suppress error messages */
62    volatile bool timed_out: 1;        /* timed out in read/write */
63    volatile bool terminated: 1;       /* set when BNET_TERMINATE arrives */
64    bool duped: 1;                     /* set if duped BSOCK */
65    bool spool: 1;                     /* set for spooling */
66    volatile time_t timer_start;       /* time started read/write */
67    volatile time_t timeout;           /* timeout BSOCK after this interval */
68    POOLMEM *msg;                      /* message pool buffer */
69    POOLMEM *errmsg;                   /* edited error message */
70    RES *res;                          /* Resource to which we are connected */
71    FILE *spool_fd;                    /* spooling file */
72    struct sockaddr client_addr;       /* client's IP address */
73    struct sockaddr_in peer_addr;      /* peer's IP address */
74
75    /* methods -- in bsock.c */
76    int32_t recv();
77    bool send();
78    bool fsend(const char*, ...);
79    bool signal(int signal);
80    void close();                      /* close connection and destroy packet */
81    void destroy();                    /* destroy socket packet */
82    void set_jcr(JCR *jcr) { m_jcr = jcr; };
83    void set_who(char *who) { m_who = who; };
84    void set_host(char *host) { m_host = host; };
85    void set_port(int port) { m_port = port; };
86    char *who() { return m_who; };
87    char *host() { return m_host; };
88    int port() { return m_port; };
89    JCR *jcr() { return m_jcr; };
90
91 };
92
93 /* Signal definitions for use in bnet_sig() */
94 enum {
95    BNET_EOD            = -1,          /* End of data stream, new data may follow */
96    BNET_EOD_POLL       = -2,          /* End of data and poll all in one */
97    BNET_STATUS         = -3,          /* Send full status */
98    BNET_TERMINATE      = -4,          /* Conversation terminated, doing close() */
99    BNET_POLL           = -5,          /* Poll request, I'm hanging on a read */
100    BNET_HEARTBEAT      = -6,          /* Heartbeat Response requested */
101    BNET_HB_RESPONSE    = -7,          /* Only response permited to HB */
102    BNET_PROMPT         = -8,          /* Prompt for UA */
103    BNET_BTIME          = -9,          /* Send UTC btime */
104    BNET_BREAK          = -10,         /* Stop current command -- ctl-c */
105    BNET_START_SELECT   = -11,         /* Start of a selection list */
106    BNET_END_SELECT     = -12,         /* End of a select list */
107    BNET_INVALID_CMD    = -13,         /* Invalid command sent */
108    BNET_CMD_FAILED     = -14,         /* Command failed */
109    BNET_CMD_OK         = -15,         /* Command succeeded */
110    BNET_CMD_BEGIN      = -16          /* Start command execution */
111 };
112
113 #define BNET_SETBUF_READ  1           /* Arg for bnet_set_buffer_size */
114 #define BNET_SETBUF_WRITE 2           /* Arg for bnet_set_buffer_size */
115
116 /* Return status from bnet_recv() */
117 enum {
118    BNET_SIGNAL         = -1,
119    BNET_HARDEOF        = -2,
120    BNET_ERROR          = -3
121 };
122
123 /*
124  * TLS enabling values. Value is important for comparison, ie:
125  * if (tls_remote_need < BNET_TLS_REQUIRED) { ... }
126  */
127 enum {
128    BNET_TLS_NONE        = 0,          /* cannot do TLS */
129    BNET_TLS_OK          = 1,          /* can do, but not required on my end */
130    BNET_TLS_REQUIRED    = 2           /* TLS is required */
131 };
132
133 int32_t read_nbytes(BSOCK * bsock, char *ptr, int32_t nbytes);
134 int32_t write_nbytes(BSOCK * bsock, char *ptr, int32_t nbytes);