forked from bareos/contrib-pgsql-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pluglib.h
142 lines (114 loc) · 3.59 KB
/
pluglib.h
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Copyright (c) 2013 by Inteos sp. z o.o.
* All rights reserved. See LICENSE.Inteos for details.
*
* Common definitions and utility functions for Inteos plugins.
* Functions defines a common framework used in our utilities and plugins
*/
#ifndef _PLUGLIB_H_
#define _PLUGLIB_H_
#include <sys/stat.h>
#include <sys/types.h>
#include <ctype.h>
#include "bareos.h"
#include "utils.h"
/* definitions */
/* size of different string or sql buffers */
#define CONNSTRLEN 256
#define BUFLEN 1024
#define BIGBUFLEN 65536
#define LOGMSGLEN (6 + 32 + 7 + 24 + 1)
/* Assertions definitions */
#define ASSERT_bfuncs_RET_BRCERROR \
if ( ! bfuncs ) \
{ \
return bRC_Error; \
}
#define ASSERT_ctx_RET_BRCERROR \
if ( ! ctx ) \
{ \
return bRC_Error; \
}
#define ASSERT_ctxp_RET \
if ( ! ctx || ! ctx->pContext ) \
{ \
return; \
}
#define ASSERT_ctxp_RET_BRCERROR \
if ( ! ctx || ! ctx->pContext ) \
{ \
return bRC_Error; \
}
#define ASSERT_ctxp_RET_NULL \
if ( ! ctx || ! ctx->pContext ) \
{ \
return NULL; \
}
/* check valid pointer with bRC return */
#define ASSERT_NVAL_RET_BRCERROR(value) ASSERT_bp(value)
#define ASSERT_NVAL_RET_BRCERR(value) ASSERT_bp(value)
#define ASSERT_bp(value) \
if ( ! value ) \
{ \
return bRC_Error; \
}
/* check a valid pointer with bRC return */
#define ASSERT_NVAL_RET_BRCOK(value) \
if ( ! value ) \
{ \
return bRC_OK; \
}
/* check valid pointer if not exit with error */
#define ASSERT_NVAL_EXIT_BRCERR(value) ASSERT_bpex(value)
#define ASSERT_bpex(value) \
if ( ! value ){ \
exit ( bRC_Error ); \
}
/* checks error value then bRC return */
#define ASSERT_VAL_RET_BRCERR(value) ASSERT_bn(value)
#define ASSERT_bn(value) \
if ( value ) \
{ \
return bRC_Error; \
}
/* memory allocation/deallocation */
/* use bacula->malloc function */
#define MALLOC(size) \
(char *) malloc ( size );
#define MALLOCT(size,type) \
(typeof(type)*) malloc ( size );
/* use bacula->free function */
#define FREE(ptr) \
if ( ptr != NULL ){ \
free ( ptr ); \
ptr = NULL; \
}
/* debug and messages functions */
#define JMSG0(ctx,type,msg) \
bfuncs->JobMessage ( ctx, __FILE__, __LINE__, type, 0, PLUGIN_INFO msg );
#define JMSG(ctx,type,msg,var) \
bfuncs->JobMessage ( ctx, __FILE__, __LINE__, type, 0, PLUGIN_INFO msg, var );
#define JMSG2(ctx,type,msg,var1,var2) \
bfuncs->JobMessage ( ctx, __FILE__, __LINE__, type, 0, PLUGIN_INFO msg, var1, var2 );
#define DMSG0(ctx,level,msg) \
bfuncs->DebugMessage ( ctx, __FILE__, __LINE__, level, PLUGIN_INFO msg );
#define DMSG1(ctx,level,msg,var) \
bfuncs->DebugMessage ( ctx, __FILE__, __LINE__, level, PLUGIN_INFO msg, var );
#define DMSG2(ctx,level,msg,var1,var2) \
bfuncs->DebugMessage ( ctx, __FILE__, __LINE__, level, PLUGIN_INFO msg, var1, var2 );
#define DMSG3(ctx,level,msg,var1,var2,var3) \
bfuncs->DebugMessage ( ctx, __FILE__, __LINE__, level, PLUGIN_INFO msg, var1, var2, var3 );
#define DMSG4(ctx,level,msg,var1,var2,var3,var4) \
bfuncs->DebugMessage ( ctx, __FILE__, __LINE__, level, PLUGIN_INFO msg, var1, var2, var3, var4 );
/* fixed debug level definitions */
#define D1 1 /* debug for every error */
#define DERROR D1
#define D2 10 /* debug only important stuff */
#define DINFO D2
#define D3 100 /* debug for information only */
#define DDEBUG D3
/* functions */
//char * check_ofname ( struct restore_pkt *rp );
//int strisprintable ( char * str, int len );
//char * bstrndup ( char * str, unsigned int n );
#endif /* _INTEOSLIB_H_ */