]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport bacula/src/lib/output.c
authorEric Bollengier <eric@baculasystems.com>
Thu, 23 Apr 2020 14:13:22 +0000 (16:13 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 29 Apr 2021 08:44:16 +0000 (10:44 +0200)
This commit is the result of the squash of the following main commits:

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Mon Mar 30 14:58:01 2020 +0200

    Add OutputWriter boolean type

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Mar 19 18:09:32 2020 +0100

    more work on QT5 for windows

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Mon Feb 3 19:01:21 2020 +0100

    Allow to use empty options in OutputWriter

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Tue Jan 28 09:15:23 2014 +0100

    Implement .api v2 and use computer friendly output to status commands.

    For example, we can use the following code:

    static void api_list_dir_status_header(UAContext *ua)
    {
       OutputWriter wt;
       ua->send_msg("%s",
        wt.get_output(
         OT_STRING, "name",        my_name,
         OT_STRING, "version",     VERSION " (" BDATE ")",
         OT_STRING, "uname",       HOST_OS " " DISTNAME " " DISTVER,
         OT_UTIME,  "started",     daemon_start_time,
         OT_UTIME,  "reloaded",    last_reload_time,
         OT_INT,    "jobs_run",    num_jobs_run,
         OT_INT,    "jobs_running",job_count(),
         OT_END
           ));
    }

    It will display

    name=bacula-dir
    version=6.6.3 (12Dec13)
    uname=....

    The OutputWriter class can be configured to use a custom
    separator (\t or \n for example), custom date format, and
    will handle basic formating such as time, string, integer,
    list of strings, etc...

bacula/src/lib/output.c

index 1c4ec7ff59d21778c57f11100998c5a917b08b1d..4011741d86ad9c453c86b58632841bf41952c5d5 100644 (file)
@@ -31,6 +31,9 @@ void OutputWriter::parse_options(const char *options)
 {
    int nb=0;
    const char *p = options;
+   if (!p) {
+      return;
+   }
    while (*p) {
       nb=0;
 
@@ -205,7 +208,8 @@ char *OutputWriter::get_output(va_list ap, POOLMEM **out, OutputType first)
    POOLMEM   *tmp2 = get_pool_memory(PM_FNAME);
    POOLMEM   *tmp = get_pool_memory(PM_FNAME);
    OutputType val = first;
-         
+   *tmp2 = *tmp = 0;
+
    while (val != OT_END) {
 
       *tmp = 0;
@@ -271,7 +275,10 @@ char *OutputWriter::get_output(va_list ap, POOLMEM **out, OutputType first)
          d = va_arg(ap, double);
          Mmsg(tmp, "%s=%.2f%c", k, d, separator);
          break;
-
+      case OT_BOOL:
+         i = va_arg(ap, int);
+         Mmsg(tmp, "%s=%s%c", k, i?"true":"false", separator);
+         break;
       case OT_STRING:
          s = va_arg(ap, char *);
          Mmsg(tmp, "%s=%s%c", k, NPRTB(s), separator) ;