From: Michal Rakowski Date: Thu, 31 Dec 2020 13:53:20 +0000 (+0100) Subject: Add 'db_name_handler' for getting resource name from the catalog X-Git-Tag: Release-11.3.2~777 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2bb350ee3f178ded63b95e47afce400648d3496d;p=thirdparty%2Fbacula.git Add 'db_name_handler' for getting resource name from the catalog --- diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index 915d599fe..505fc30c5 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -84,6 +84,7 @@ BDB *db_init_database(JCR *jcr, const char *db_driver, const char *db_name, int db_int64_handler(void *ctx, int num_fields, char **row); int db_strtime_handler(void *ctx, int num_fields, char **row); int db_list_handler(void *ctx, int num_fields, char **row); +int db_name_handler(void *ctx, int num_fields, char **row); int db_string_list_handler(void *ctx, int num_fields, char **row); int db_int_handler(void *ctx, int num_fields, char **row); void bdb_debug_print(JCR *jcr, FILE *fp); diff --git a/bacula/src/cats/sql.c b/bacula/src/cats/sql.c index 0d7b5532e..57e35ce5d 100644 --- a/bacula/src/cats/sql.c +++ b/bacula/src/cats/sql.c @@ -57,6 +57,23 @@ dbid_list::~dbid_list() free(DBId); } +/* + * Called here to retrieve an resource name (e.g. Storage name) from the database + */ +int db_name_handler(void *ctx, int num_fields, char **row) +{ + char *name = (char *)ctx; + + // Retrieved name is longer than it should be + if (strlen(row[0]) > (MAX_NAME_LENGTH - 1)) { + return 1; + } + + bstrncpy(name, row[0], MAX_NAME_LENGTH); + + return 0; +} + /* * Called here to retrieve an string list from the database */