]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_tree.c
kes Make first step toward eliminating globals from config
[bacula/bacula] / bacula / src / dird / ua_tree.c
index 33a1766680fe268e09a0a93397c4d0882e201917..b6ae6b8ddaf0563b8c41370a8fed1aa389b96798 100644 (file)
@@ -1,14 +1,14 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2002-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2002-2008 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
    modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -106,18 +106,19 @@ bool user_select_files_from_tree(TREE_CTX *tree)
    ua->api = tree->ua->api;           /* keep API flag too */
    BSOCK *user = ua->UA_sock;
 
-   bsendmsg(tree->ua, _(
+   ua->send_msg(_(
       "\nYou are now entering file selection mode where you add (mark) and\n"
       "remove (unmark) files to be restored. No files are initially added, unless\n"
       "you used the \"all\" keyword on the command line.\n"
       "Enter \"done\" to leave this mode.\n\n"));
+   if (ua->api) user->signal(BNET_START_RTREE);
    /*
     * Enter interactive command handler allowing selection
     *  of individual files.
     */
    tree->node = (TREE_NODE *)tree->root;
    tree_getpath(tree->node, cwd, sizeof(cwd));
-   bsendmsg(tree->ua, _("cwd is: %s\n"), cwd);
+   ua->send_msg(_("cwd is: %s\n"), cwd);
    for ( ;; ) {
       int found, len, i;
       if (!get_cmd(ua, "$ ")) {
@@ -126,7 +127,7 @@ bool user_select_files_from_tree(TREE_CTX *tree)
       if (ua->api) user->signal(BNET_CMD_BEGIN);
       parse_args_only(ua->cmd, &ua->args, &ua->argc, ua->argk, ua->argv, MAX_CMD_ARGS);
       if (ua->argc == 0) {
-         bsendmsg(tree->ua, _("Invalid command. Enter \"done\" to exit.\n"));
+         ua->warning_msg(_("Invalid command. Enter \"done\" to exit.\n"));
          if (ua->api) user->signal(BNET_CMD_FAILED);
          continue;
       }
@@ -141,7 +142,7 @@ bool user_select_files_from_tree(TREE_CTX *tree)
             break;
          }
       if (!found) {
-         bsendmsg(tree->ua, _("Invalid command. Enter \"done\" to exit.\n"));
+         ua->warning_msg(_("Invalid command. Enter \"done\" to exit.\n"));
          if (ua->api) user->signal(BNET_CMD_FAILED);
          continue;
       }
@@ -150,6 +151,7 @@ bool user_select_files_from_tree(TREE_CTX *tree)
          break;
       }
    }
+   if (ua->api) user->signal(BNET_END_RTREE);
    ua->UA_sock = NULL;                /* don't release restore socket */
    stat = !ua->quit;
    ua->quit = false;
@@ -227,7 +229,7 @@ int insert_tree_handler(void *ctx, int num_fields, char **row)
    if (node->inserted) {
       tree->FileCount++;
       if (tree->DeltaCount > 0 && (tree->FileCount-tree->LastCount) > tree->DeltaCount) {
-         bsendmsg(tree->ua, "+");
+         tree->ua->send_msg("+");
          tree->LastCount = tree->FileCount;
       }
    }
@@ -490,17 +492,11 @@ static int lsmarkcmd(UAContext *ua, TREE_CTX *tree)
    return 1;
 }
 
-
-
-extern char *getuser(uid_t uid, char *name, int len);
-extern char *getgroup(gid_t gid, char *name, int len);
-
 /*
  * This is actually the long form used for "dir"
  */
-static void ls_output(char *buf, const char *fname, const char *tag, 
+static void ls_output(guid_list *guid, char *buf, const char *fname, const char *tag, 
                       struct stat *statp, bool dot_cmd) 
-                    
 {
    char *p;
    const char *f;
@@ -514,10 +510,11 @@ static void ls_output(char *buf, const char *fname, const char *tag,
       *p++ = ',';
       n = sprintf(p, "%d,", (uint32_t)statp->st_nlink);
       p += n;
-      n = sprintf(p, "%s,%s,", getuser(statp->st_uid, en1, sizeof(en1)),
-                  getgroup(statp->st_gid, en2, sizeof(en2)));
+      n = sprintf(p, "%s,%s,", 
+                  guid->uid_to_name(statp->st_uid, en1, sizeof(en1)),
+                  guid->gid_to_name(statp->st_gid, en2, sizeof(en2)));
       p += n;
-      n = sprintf(p, "%s,", edit_uint64(statp->st_size, ec1));
+      n = sprintf(p, "%s,", edit_int64(statp->st_size, ec1));
       p += n;
       p = encode_time(statp->st_mtime, p);
       *p++ = ',';
@@ -526,10 +523,11 @@ static void ls_output(char *buf, const char *fname, const char *tag,
    } else {
       n = sprintf(p, "  %2d ", (uint32_t)statp->st_nlink);
       p += n;
-      n = sprintf(p, "%-8.8s %-8.8s", getuser(statp->st_uid, en1, sizeof(en1)),
-                  getgroup(statp->st_gid, en2, sizeof(en2)));
+      n = sprintf(p, "%-8.8s %-8.8s", 
+                  guid->uid_to_name(statp->st_uid, en1, sizeof(en1)),
+                  guid->gid_to_name(statp->st_gid, en2, sizeof(en2)));
       p += n;
-      n = sprintf(p, "%10.10s  ", edit_uint64(statp->st_size, ec1));
+      n = sprintf(p, "%10.10s  ", edit_int64(statp->st_size, ec1));
       p += n;
       if (statp->st_ctime > statp->st_mtime) {
          time = statp->st_ctime;
@@ -557,12 +555,14 @@ static int do_dircmd(UAContext *ua, TREE_CTX *tree, bool dot_cmd)
    struct stat statp;
    char buf[1100];
    char cwd[1100], *pcwd;
+   guid_list *guid;
 
    if (!tree_node_has_child(tree->node)) {
       ua->send_msg(_("Node %s has no children.\n"), tree->node->fname);
       return 1;
    }
 
+   guid = new_guid_list();
    foreach_child(node, tree->node) {
       const char *tag;
       if (ua->argc == 1 || fnmatch(ua->argk[1], node->fname, 0) == 0) {
@@ -600,10 +600,11 @@ static int do_dircmd(UAContext *ua, TREE_CTX *tree, bool dot_cmd)
             /* Something went wrong getting attributes -- print name */
             memset(&statp, 0, sizeof(statp));
          }
-         ls_output(buf, cwd, tag, &statp, dot_cmd);
+         ls_output(guid, buf, cwd, tag, &statp, dot_cmd);
          ua->send_msg("%s\n", buf);
       }
    }
+   free_guid_list(guid);
    return 1;
 }