Skip to content

Commit

Permalink
Tweak layout.
Browse files Browse the repository at this point in the history
- Use enums instead of defines for config types.
- Cleanup mem_pool.h
- Refactor dir_db_log_insert() function.
  • Loading branch information
Marco van Wieringen committed Feb 17, 2015
1 parent 02714d5 commit 1a6883a
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 123 deletions.
32 changes: 11 additions & 21 deletions src/dird/dird.c
Expand Up @@ -87,42 +87,32 @@ static bool check_catalog(cat_op mode);
#define CONFIG_FILE "bareos-dir.conf" /* default configuration file */

/*
* This allows the message handler to operate on the database
* by using a pointer to this function. The pointer is
* needed because the other daemons do not have access
* to the database. If the pointer is not defined (other daemons),
* then writing the database is disabled.
* This allows the message handler to operate on the database by using a pointer
* to this function. The pointer is needed because the other daemons do not have
* access to the database. If the pointer is not defined (other daemons), then
* writing the database is disabled.
*/
static bool dir_db_log_insert(JCR *jcr, utime_t mtime, char *msg)
{
int length;
bool retval;
char ed1[50];
char dt[MAX_TIME_LENGTH];
POOLMEM *cmd, *esc_msg;
POOL_MEM query(PM_MESSAGE),
esc_msg(PM_MESSAGE);

if (!jcr || !jcr->db || !jcr->db->is_connected()) {
return false;
}

cmd = get_pool_memory(PM_MESSAGE);
esc_msg = get_pool_memory(PM_MESSAGE);

length = strlen(msg) + 1;

esc_msg = check_pool_memory_size(esc_msg, length * 2 + 1);
db_escape_string(jcr, jcr->db, esc_msg, msg, length);
esc_msg.check_size(length * 2 + 1);
db_escape_string(jcr, jcr->db, esc_msg.c_str(), msg, length);

bstrutime(dt, sizeof(dt), mtime);
Mmsg(cmd, "INSERT INTO Log (JobId, Time, LogText) VALUES (%s,'%s','%s')",
edit_int64(jcr->JobId, ed1), dt, esc_msg);

retval = db_sql_query(jcr->db, cmd);
Mmsg(query, "INSERT INTO Log (JobId, Time, LogText) VALUES (%s,'%s','%s')",
edit_int64(jcr->JobId, ed1), dt, esc_msg.c_str());

free_pool_memory(cmd);
free_pool_memory(esc_msg);

return retval;
return db_sql_query(jcr->db, query.c_str());
}

static void usage()
Expand Down
64 changes: 33 additions & 31 deletions src/dird/dird_conf.h
Expand Up @@ -31,37 +31,39 @@
/*
* Program specific config types (start at 50)
*/
#define CFG_TYPE_ACL 50 /* User Access Control List */
#define CFG_TYPE_AUTHPROTOCOLTYPE 51 /* Authentication Protocol */
#define CFG_TYPE_AUTHTYPE 52 /* Authentication Type */
#define CFG_TYPE_DEVICE 53 /* Device resource */
#define CFG_TYPE_JOBTYPE 54 /* Type of Job */
#define CFG_TYPE_PROTOCOLTYPE 55 /* Protocol */
#define CFG_TYPE_LEVEL 56 /* Backup Level */
#define CFG_TYPE_REPLACE 57 /* Replace option */
#define CFG_TYPE_SHRTRUNSCRIPT 58 /* Short Runscript definition */
#define CFG_TYPE_RUNSCRIPT 59 /* Runscript */
#define CFG_TYPE_RUNSCRIPT_CMD 60 /* Runscript Command */
#define CFG_TYPE_RUNSCRIPT_TARGET 61 /* Runscript Target (Host) */
#define CFG_TYPE_RUNSCRIPT_BOOL 62 /* Runscript Boolean */
#define CFG_TYPE_RUNSCRIPT_WHEN 63 /* Runscript When expression */
#define CFG_TYPE_MIGTYPE 64 /* Migration Type */
#define CFG_TYPE_INCEXC 65 /* Include/Exclude item */
#define CFG_TYPE_RUN 66 /* Schedule Run Command */
#define CFG_TYPE_ACTIONONPURGE 67 /* Action to perform on Purge */

#define CFG_TYPE_FNAME 80 /* Filename */
#define CFG_TYPE_PLUGINNAME 81 /* Pluginname */
#define CFG_TYPE_EXCLUDEDIR 82 /* Exclude directory */
#define CFG_TYPE_OPTIONS 83 /* Options block */
#define CFG_TYPE_OPTION 84 /* Option of Options block */
#define CFG_TYPE_REGEX 85 /* Regular Expression */
#define CFG_TYPE_BASE 86 /* Basejob Expression */
#define CFG_TYPE_WILD 87 /* Wildcard Expression */
#define CFG_TYPE_PLUGIN 88 /* Plugin definition */
#define CFG_TYPE_FSTYPE 89 /* FileSytem match criterium (UNIX)*/
#define CFG_TYPE_DRIVETYPE 90 /* DriveType match criterium (Windows) */
#define CFG_TYPE_META 91 /* Meta tag */
enum {
CFG_TYPE_ACL = 50, /* User Access Control List */
CFG_TYPE_AUTHPROTOCOLTYPE = 51, /* Authentication Protocol */
CFG_TYPE_AUTHTYPE = 52, /* Authentication Type */
CFG_TYPE_DEVICE = 53, /* Device resource */
CFG_TYPE_JOBTYPE = 54, /* Type of Job */
CFG_TYPE_PROTOCOLTYPE = 55, /* Protocol */
CFG_TYPE_LEVEL = 56, /* Backup Level */
CFG_TYPE_REPLACE = 57, /* Replace option */
CFG_TYPE_SHRTRUNSCRIPT = 58, /* Short Runscript definition */
CFG_TYPE_RUNSCRIPT = 59, /* Runscript */
CFG_TYPE_RUNSCRIPT_CMD = 60, /* Runscript Command */
CFG_TYPE_RUNSCRIPT_TARGET = 61, /* Runscript Target (Host) */
CFG_TYPE_RUNSCRIPT_BOOL = 62, /* Runscript Boolean */
CFG_TYPE_RUNSCRIPT_WHEN = 63, /* Runscript When expression */
CFG_TYPE_MIGTYPE = 64, /* Migration Type */
CFG_TYPE_INCEXC = 65, /* Include/Exclude item */
CFG_TYPE_RUN = 66, /* Schedule Run Command */
CFG_TYPE_ACTIONONPURGE = 67, /* Action to perform on Purge */

CFG_TYPE_FNAME = 80, /* Filename */
CFG_TYPE_PLUGINNAME = 81, /* Pluginname */
CFG_TYPE_EXCLUDEDIR = 82, /* Exclude directory */
CFG_TYPE_OPTIONS = 83, /* Options block */
CFG_TYPE_OPTION = 84, /* Option of Options block */
CFG_TYPE_REGEX = 85, /* Regular Expression */
CFG_TYPE_BASE = 86, /* Basejob Expression */
CFG_TYPE_WILD = 87, /* Wildcard Expression */
CFG_TYPE_PLUGIN = 88, /* Plugin definition */
CFG_TYPE_FSTYPE = 89, /* FileSytem match criterium (UNIX)*/
CFG_TYPE_DRIVETYPE = 90, /* DriveType match criterium (Windows) */
CFG_TYPE_META = 91 /* Meta tag */
};

/*
* Resource codes -- they must be sequential for indexing
Expand Down
4 changes: 3 additions & 1 deletion src/filed/filed_conf.h
Expand Up @@ -29,7 +29,9 @@
/*
* Program specific config types (start at 50)
*/
#define CFG_TYPE_CIPHER 50 /* Encryption Cipher */
enum {
CFG_TYPE_CIPHER = 50 /* Encryption Cipher */
};

/*
* Resource codes -- they must be sequential for indexing
Expand Down
18 changes: 10 additions & 8 deletions src/lib/ini.h
Expand Up @@ -24,14 +24,16 @@
/*
* Standard global types with handlers defined in ini.c
*/
#define INI_CFG_TYPE_INT32 1 /* 32 bits Integer */
#define INI_CFG_TYPE_PINT32 2 /* Positive 32 bits Integer (unsigned) */
#define INI_CFG_TYPE_INT64 3 /* 64 bits Integer */
#define INI_CFG_TYPE_PINT64 4 /* Positive 64 bits Integer (unsigned) */
#define INI_CFG_TYPE_NAME 5 /* Name */
#define INI_CFG_TYPE_STR 6 /* String */
#define INI_CFG_TYPE_BOOL 7 /* Boolean */
#define INI_CFG_TYPE_ALIST_STR 8 /* List of strings */
enum {
INI_CFG_TYPE_INT32 = 1, /* 32 bits Integer */
INI_CFG_TYPE_PINT32 = 2, /* Positive 32 bits Integer (unsigned) */
INI_CFG_TYPE_INT64 = 3, /* 64 bits Integer */
INI_CFG_TYPE_PINT64 = 4, /* Positive 64 bits Integer (unsigned) */
INI_CFG_TYPE_NAME = 5, /* Name */
INI_CFG_TYPE_STR = 6, /* String */
INI_CFG_TYPE_BOOL = 7, /* Boolean */
INI_CFG_TYPE_ALIST_STR = 8 /* List of strings */
};

/*
* Plugin has a internal C structure that describes the configuration:
Expand Down
63 changes: 33 additions & 30 deletions src/lib/mem_pool.h
Expand Up @@ -30,54 +30,58 @@
#ifdef SMARTALLOC

#define get_pool_memory(pool) sm_get_pool_memory(__FILE__, __LINE__, pool)
extern POOLMEM *sm_get_pool_memory(const char *file, int line, int pool);
POOLMEM *sm_get_pool_memory(const char *file, int line, int pool);

#define get_memory(size) sm_get_memory(__FILE__, __LINE__, size)
extern POOLMEM *sm_get_memory(const char *fname, int line, int32_t size);
POOLMEM *sm_get_memory(const char *fname, int line, int32_t size);

#define sizeof_pool_memory(buf) sm_sizeof_pool_memory(__FILE__, __LINE__, buf)
extern int32_t sm_sizeof_pool_memory(const char *fname, int line, POOLMEM *buf);
int32_t sm_sizeof_pool_memory(const char *fname, int line, POOLMEM *buf);

#define realloc_pool_memory(buf,size) sm_realloc_pool_memory(__FILE__, __LINE__, buf, size)
extern POOLMEM *sm_realloc_pool_memory(const char *fname, int line, POOLMEM *buf, int32_t size);
POOLMEM *sm_realloc_pool_memory(const char *fname, int line, POOLMEM *buf, int32_t size);

#define check_pool_memory_size(buf,size) sm_check_pool_memory_size(__FILE__, __LINE__, buf, size)
extern POOLMEM *sm_check_pool_memory_size(const char *fname, int line, POOLMEM *buf, int32_t size);
POOLMEM *sm_check_pool_memory_size(const char *fname, int line, POOLMEM *buf, int32_t size);

#define free_pool_memory(x) sm_free_pool_memory(__FILE__, __LINE__, x)
#define free_memory(x) sm_free_pool_memory(__FILE__, __LINE__, x)
extern void sm_free_pool_memory(const char *fname, int line, POOLMEM *buf);
void sm_free_pool_memory(const char *fname, int line, POOLMEM *buf);

#else

extern POOLMEM *get_pool_memory(int pool);
extern POOLMEM *get_memory(int32_t size);
extern int32_t sizeof_pool_memory(POOLMEM *buf);
extern POOLMEM *realloc_pool_memory(POOLMEM *buf, int32_t size);
extern POOLMEM *check_pool_memory_size(POOLMEM *buf, int32_t size);
POOLMEM *get_pool_memory(int pool);
POOLMEM *get_memory(int32_t size);
int32_t sizeof_pool_memory(POOLMEM *buf);
POOLMEM *realloc_pool_memory(POOLMEM *buf, int32_t size);
POOLMEM *check_pool_memory_size(POOLMEM *buf, int32_t size);
#define free_memory(x) free_pool_memory(x)
extern void free_pool_memory(POOLMEM *buf);
void free_pool_memory(POOLMEM *buf);

#endif

/* Macro to simplify free/reset pointers */
#define free_and_null_pool_memory(a) do{if(a){free_pool_memory(a); (a)=NULL;}} while(0)

extern void garbage_collect_memory_pool();
extern void close_memory_pool();
extern void print_memory_pool_stats();

extern void garbage_collect_memory();

/*
* Macro to simplify free/reset pointers
*/
#define free_and_null_pool_memory(a) do { if (a) { free_pool_memory(a); (a) = NULL;} } while (0)

void garbage_collect_memory_pool();
void close_memory_pool();
void print_memory_pool_stats();

void garbage_collect_memory();

enum {
PM_NOPOOL = 0, /* Nonpooled memory */
PM_NAME = 1, /* BAREOS name */
PM_FNAME = 2, /* File name buffer */
PM_MESSAGE = 3, /* Daemon message */
PM_EMSG = 4, /* Error message */
PM_BSOCK = 5, /* BSOCK buffer */
PM_RECORD = 6 /* DEV_RECORD buffer */
};

#define PM_NOPOOL 0 /* Nonpooled memory */
#define PM_NAME 1 /* BAREOS name */
#define PM_FNAME 2 /* File name buffer */
#define PM_MESSAGE 3 /* Daemon message */
#define PM_EMSG 4 /* Error message */
#define PM_BSOCK 5 /* BSOCK buffer */
#define PM_RECORD 6 /* DEV_RECORD buffer */
#define PM_MAX PM_RECORD /* Number of types */
#define PM_MAX PM_RECORD /* Number of types */

class POOL_MEM {
char *mem;
Expand Down Expand Up @@ -111,5 +115,4 @@ int pm_memcpy(POOLMEM **pm, const char *data, int32_t n);
int pm_memcpy(POOLMEM *&pm, const char *data, int32_t n);
int pm_memcpy(POOL_MEM &pm, const char *data, int32_t n);
int pm_memcpy(POOLMEM *&pm, POOL_MEM &data, int32_t n);

#endif
57 changes: 30 additions & 27 deletions src/lib/parse_conf.h
Expand Up @@ -134,9 +134,10 @@ struct RES_TABLE {

/* Common Resource definitions */

#define MAX_RES_NAME_LENGTH MAX_NAME_LENGTH-1 /* maximum resource name length */
#define MAX_RES_NAME_LENGTH MAX_NAME_LENGTH - 1 /* maximum resource name length */

/*
* Config item flags.
*/
#define CFG_ITEM_REQUIRED 0x1 /* Item required */
#define CFG_ITEM_DEFAULT 0x2 /* Default supplied */
Expand All @@ -147,32 +148,34 @@ struct RES_TABLE {
/*
* Standard global types with handlers defined in res.c
*/
#define CFG_TYPE_STR 1 /* String */
#define CFG_TYPE_DIR 2 /* Directory */
#define CFG_TYPE_MD5PASSWORD 3 /* MD5 hashed Password */
#define CFG_TYPE_CLEARPASSWORD 4 /* Clear text Password */
#define CFG_TYPE_AUTOPASSWORD 5 /* Password stored in clear when needed otherwise hashed */
#define CFG_TYPE_NAME 6 /* Name */
#define CFG_TYPE_STRNAME 7 /* String Name */
#define CFG_TYPE_RES 8 /* Resource */
#define CFG_TYPE_ALIST_RES 9 /* List of resources */
#define CFG_TYPE_ALIST_STR 10 /* List of strings */
#define CFG_TYPE_ALIST_DIR 11 /* List of dirs */
#define CFG_TYPE_INT32 12 /* 32 bits Integer */
#define CFG_TYPE_PINT32 13 /* Positive 32 bits Integer (unsigned) */
#define CFG_TYPE_MSGS 14 /* Message resource */
#define CFG_TYPE_INT64 15 /* 64 bits Integer */
#define CFG_TYPE_BIT 16 /* Bitfield */
#define CFG_TYPE_BOOL 17 /* Boolean */
#define CFG_TYPE_TIME 18 /* Time value */
#define CFG_TYPE_SIZE64 19 /* 64 bits file size */
#define CFG_TYPE_SIZE32 20 /* 32 bits file size */
#define CFG_TYPE_SPEED 21 /* Speed limit */
#define CFG_TYPE_DEFS 22 /* Definition */
#define CFG_TYPE_LABEL 23 /* Label */
#define CFG_TYPE_ADDRESSES 24 /* List of ip addresses */
#define CFG_TYPE_ADDRESSES_ADDRESS 25 /* Ip address */
#define CFG_TYPE_ADDRESSES_PORT 26 /* Ip port */
enum {
CFG_TYPE_STR = 1, /* String */
CFG_TYPE_DIR = 2, /* Directory */
CFG_TYPE_MD5PASSWORD = 3, /* MD5 hashed Password */
CFG_TYPE_CLEARPASSWORD = 4, /* Clear text Password */
CFG_TYPE_AUTOPASSWORD = 5, /* Password stored in clear when needed otherwise hashed */
CFG_TYPE_NAME = 6, /* Name */
CFG_TYPE_STRNAME = 7, /* String Name */
CFG_TYPE_RES = 8, /* Resource */
CFG_TYPE_ALIST_RES = 9, /* List of resources */
CFG_TYPE_ALIST_STR = 10, /* List of strings */
CFG_TYPE_ALIST_DIR = 11, /* List of dirs */
CFG_TYPE_INT32 = 12, /* 32 bits Integer */
CFG_TYPE_PINT32 = 13, /* Positive 32 bits Integer (unsigned) */
CFG_TYPE_MSGS = 14, /* Message resource */
CFG_TYPE_INT64 = 15, /* 64 bits Integer */
CFG_TYPE_BIT = 16, /* Bitfield */
CFG_TYPE_BOOL = 17, /* Boolean */
CFG_TYPE_TIME = 18, /* Time value */
CFG_TYPE_SIZE64 = 19, /* 64 bits file size */
CFG_TYPE_SIZE32 = 20, /* 32 bits file size */
CFG_TYPE_SPEED = 21, /* Speed limit */
CFG_TYPE_DEFS = 22, /* Definition */
CFG_TYPE_LABEL = 23, /* Label */
CFG_TYPE_ADDRESSES = 24, /* List of ip addresses */
CFG_TYPE_ADDRESSES_ADDRESS = 25, /* Ip address */
CFG_TYPE_ADDRESSES_PORT = 26 /* Ip port */
};

/*
* Base Class for all Resource Classes
Expand Down
12 changes: 7 additions & 5 deletions src/stored/stored_conf.h
Expand Up @@ -27,11 +27,13 @@
/*
* Program specific config types (start at 50)
*/
#define CFG_TYPE_AUTHTYPE 50 /* Authentication Type */
#define CFG_TYPE_DEVTYPE 51 /* Device Type */
#define CFG_TYPE_MAXBLOCKSIZE 52 /* Maximum Blocksize */
#define CFG_TYPE_IODIRECTION 53 /* IO Direction */
#define CFG_TYPE_CMPRSALGO 54 /* Compression Algorithm */
enum {
CFG_TYPE_AUTHTYPE = 50, /* Authentication Type */
CFG_TYPE_DEVTYPE = 51, /* Device Type */
CFG_TYPE_MAXBLOCKSIZE = 52, /* Maximum Blocksize */
CFG_TYPE_IODIRECTION = 53, /* IO Direction */
CFG_TYPE_CMPRSALGO = 54 /* Compression Algorithm */
};

enum {
R_DIRECTOR = 3001,
Expand Down

0 comments on commit 1a6883a

Please sign in to comment.