]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/bsock.h
Doc + compiler fixes
[bacula/bacula] / bacula / src / lib / bsock.h
1 /*
2  * Bacula Sock Structure definition
3  *
4  * Kern Sibbald, May MM
5  *
6  * Zero msglen from other end indicates soft eof (usually
7  *   end of some binary data stream, but not end of conversation).
8  *
9  * Negative msglen, is special "signal" (no data follows).
10  *   See below for SIGNAL codes.
11  *
12  *   Version $Id$
13  */
14 /*
15    Copyright (C) 2000-2004 Kern Sibbald and John Walker
16
17    This library is free software; you can redistribute it and/or
18    modify it under the terms of the GNU Lesser General Public
19    License as published by the Free Software Foundation; either
20    version 2.1 of the License, or (at your option) any later version.
21
22    This library is distributed in the hope that it will be useful,
23    but WITHOUT ANY WARRANTY; without even the implied warranty of
24    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25    Lesser General Public License for more details.
26
27    You should have received a copy of the GNU Lesser General Public
28    License along with this library; if not, write to the Free
29    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30    MA 02111-1307, USA.
31
32  */
33
34 struct BSOCK {
35    uint64_t read_seqno;               /* read sequence number */
36    uint32_t in_msg_no;                /* input message number */
37    uint32_t out_msg_no;               /* output message number */
38    int fd;                            /* socket file descriptor */
39    int32_t msglen;                    /* message length */
40    int b_errno;                       /* bsock errno */
41    int port;                          /* desired port */
42    volatile int errors;               /* incremented for each error on socket */
43    volatile bool suppress_error_msgs: 1; /* set to suppress error messages */
44    volatile bool timed_out: 1;        /* timed out in read/write */
45    volatile bool terminated: 1;       /* set when BNET_TERMINATE arrives */
46    bool duped: 1;                     /* set if duped BSOCK */
47    bool spool: 1;                     /* set for spooling */
48    volatile time_t timer_start;       /* time started read/write */
49    volatile time_t timeout;           /* timeout BSOCK after this interval */
50    POOLMEM *msg;                      /* message pool buffer */
51    char *who;                         /* Name of daemon to which we are talking */
52    char *host;                        /* Host name/IP */
53    POOLMEM *errmsg;                   /* edited error message (to be implemented) */
54    RES *res;                          /* Resource to which we are connected */
55    BSOCK *next;                       /* next BSOCK if duped */
56    FILE *spool_fd;                    /* spooling file */
57    JCR *jcr;                          /* jcr or NULL for error msgs */
58    struct sockaddr_in client_addr;    /* client's IP address */
59 };      
60
61 /* Signal definitions for use in bnet_sig() */
62 enum {
63    BNET_EOD            = -1,          /* End of data stream, new data may follow */
64    BNET_EOD_POLL       = -2,          /* End of data and poll all in one */
65    BNET_STATUS         = -3,          /* Send full status */
66    BNET_TERMINATE      = -4,          /* Conversation terminated, doing close() */
67    BNET_POLL           = -5,          /* Poll request, I'm hanging on a read */
68    BNET_HEARTBEAT      = -6,          /* Heartbeat Response requested */
69    BNET_HB_RESPONSE    = -7,          /* Only response permited to HB */
70    BNET_PROMPT         = -8,          /* Prompt for UA */
71    BNET_BTIME          = -9,          /* Send UTC btime */
72    BNET_BREAK          = -10          /* Stop current command -- ctl-c */
73 };
74
75 #define BNET_SETBUF_READ  1           /* Arg for bnet_set_buffer_size */
76 #define BNET_SETBUF_WRITE 2           /* Arg for bnet_set_buffer_size */
77
78 /* Return status from bnet_recv() */
79 #define BNET_SIGNAL  -1
80 #define BNET_HARDEOF -2
81 #define BNET_ERROR   -3
82
83 /* SSL enabling values */
84 #define BNET_SSL_NONE     0           /* cannot do SSL */
85 #define BNET_SSL_OK       1           /* can do, but not required on my end */
86 #define BNET_SSL_REQUIRED 2           /* SSL is required */
87
88 /*
89  * This is the structure of the in memory BPKT
90  */
91 typedef struct s_bpkt {
92    char *id;                          /* String identifier or name of field */
93    uint8_t type;                      /* field type */
94    uint32_t len;                      /* field length for string, name, bytes */
95    void *value;                       /* pointer to value */
96 } BPKT;
97
98 /*  
99  * These are the data types that can be sent.
100  * For all values other than string, the storage space
101  *  is assumed to be allocated in the receiving packet.
102  *  For BP_STRING if the *value is non-zero, it is a        
103  *  pointer to a POOLMEM buffer, and the Memory Pool
104  *  routines will be used to assure that the length is
105  *  adequate. NOTE!!! This pointer will be changed
106  *  if the memory is reallocated (sort of like Mmsg(&pool)
107  *  does). If the pointer is NULL, a POOLMEM
108  *  buffer will be allocated.
109  */
110 #define BP_EOF       0                /* end of file */
111 #define BP_CHAR      1                /* Character */
112 #define BP_INT32     1                /* 32 bit integer */
113 #define BP_UINT32    3                /* Unsigned 32 bit integer */
114 #define BP_INT64     4                /* 64 bit integer */
115 #define BP_STRING    5                /* string */
116 #define BP_NAME      6                /* Name string -- limited length */
117 #define BP_BYTES     7                /* Binary bytes */
118 #define BP_FLOAT32   8                /* 32 bit floating point */
119 #define BP_FLOAT64   9                /* 64 bit floating point */