From 747589f03a1ba61273d21ed6446ad47841a1f46a Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 2 Aug 2007 23:28:17 +0000 Subject: Convert most printf() and fprintf() calls to use logging framework instead. (refs #3) --- bin/bbackupquery/BackupQueries.cpp | 280 ++++++++++++++++++++----------------- bin/bbackupquery/bbackupquery.cpp | 34 +++-- 2 files changed, 168 insertions(+), 146 deletions(-) (limited to 'bin/bbackupquery') diff --git a/bin/bbackupquery/BackupQueries.cpp b/bin/bbackupquery/BackupQueries.cpp index 0c5f9c15..09003d4d 100644 --- a/bin/bbackupquery/BackupQueries.cpp +++ b/bin/bbackupquery/BackupQueries.cpp @@ -181,7 +181,7 @@ void BackupQueries::DoCommand(const char *Command, bool isFromCommandLine) if (!ConvertEncoding(*i, CP_ACP, converted, GetConsoleCP())) { - printf("Failed to convert encoding"); + BOX_ERROR("Failed to convert encoding"); return; } *i = converted; @@ -255,7 +255,7 @@ void BackupQueries::DoCommand(const char *Command, bool isFromCommandLine) // No such command if(alias[a] == 0) { - printf("Unrecognised command: %s\n", Command); + BOX_ERROR("Unrecognised command: " << Command); return; } } @@ -275,8 +275,8 @@ void BackupQueries::DoCommand(const char *Command, bool isFromCommandLine) // Valid option? if(::strchr(commands[cmd].opts, *c) == NULL) { - printf("Invalid option '%c' for command %s\n", - *c, commands[cmd].name); + BOX_ERROR("Invalid option '" << *c << "' for " + "command " << commands[cmd].name); return; } opts[(int)*c] = true; @@ -305,9 +305,8 @@ void BackupQueries::DoCommand(const char *Command, bool isFromCommandLine) case COMMAND_pwd: { // Simple implementation, so do it here - printf("%s (%08llx)\n", - GetCurrentDirectoryName().c_str(), - (long long)GetCurrentDirectoryID()); + BOX_INFO(GetCurrentDirectoryName() << " (" << + BOX_FORMAT_OBJECTID(GetCurrentDirectoryID())); } break; @@ -320,7 +319,7 @@ void BackupQueries::DoCommand(const char *Command, bool isFromCommandLine) break; case COMMAND_sh: - printf("The command to run must be specified as an argument.\n"); + BOX_ERROR("The command to run must be specified as an argument."); break; case COMMAND_GetObject: @@ -401,8 +400,8 @@ void BackupQueries::CommandList(const std::vector &args, const bool if(rootDir == 0) { - printf("Directory '%s' not found on store\n", - args[0].c_str()); + BOX_ERROR("Directory '" << args[0] << "' not found " + "on store."); return; } } @@ -747,7 +746,7 @@ void BackupQueries::CommandChangeDir(const std::vector &args, const { if(args.size() != 1 || args[0].size() == 0) { - printf("Incorrect usage.\ncd [-o] [-d] \n"); + BOX_ERROR("Incorrect usage. cd [-o] [-d] "); return; } @@ -764,7 +763,7 @@ void BackupQueries::CommandChangeDir(const std::vector &args, const if(id == 0) { - printf("Directory '%s' not found\n", args[0].c_str()); + BOX_ERROR("Directory '" << args[0] << "' not found."); return; } @@ -785,7 +784,7 @@ void BackupQueries::CommandChangeLocalDir(const std::vector &args) { if(args.size() != 1 || args[0].size() == 0) { - printf("Incorrect usage.\nlcd \n"); + BOX_ERROR("Incorrect usage. lcd "); SetReturnCode(COMMAND_RETURN_ERROR); return; } @@ -795,7 +794,7 @@ void BackupQueries::CommandChangeLocalDir(const std::vector &args) std::string dirName; if(!ConvertConsoleToUtf8(args[0].c_str(), dirName)) { - printf("Failed to convert path from console encoding.\n"); + BOX_ERROR("Failed to convert path from console encoding."); SetReturnCode(COMMAND_RETURN_ERROR); return; } @@ -805,8 +804,16 @@ void BackupQueries::CommandChangeLocalDir(const std::vector &args) #endif if(result != 0) { - printf((errno == ENOENT || errno == ENOTDIR)?"Directory '%s' does not exist\n":"Error changing dir to '%s'\n", - args[0].c_str()); + if(errno == ENOENT || errno == ENOTDIR) + { + BOX_ERROR("Directory '" << args[0] << "' does not exist."); + } + else + { + BOX_ERROR("Error changing to directory '" << + args[0] << ": " << strerror(errno)); + } + SetReturnCode(COMMAND_RETURN_ERROR); return; } @@ -815,7 +822,8 @@ void BackupQueries::CommandChangeLocalDir(const std::vector &args) char wd[PATH_MAX]; if(::getcwd(wd, PATH_MAX) == 0) { - printf("Error getting current directory\n"); + BOX_ERROR("Error getting current directory: " << + strerror(errno)); SetReturnCode(COMMAND_RETURN_ERROR); return; } @@ -823,13 +831,13 @@ void BackupQueries::CommandChangeLocalDir(const std::vector &args) #ifdef WIN32 if(!ConvertUtf8ToConsole(wd, dirName)) { - printf("Failed to convert new path from console encoding.\n"); + BOX_ERROR("Failed to convert new path from console encoding."); SetReturnCode(COMMAND_RETURN_ERROR); return; } - printf("Local current directory is now '%s'\n", dirName.c_str()); + BOX_INFO("Local current directory is now '" << dirName << "'."); #else - printf("Local current directory is now '%s'\n", wd); + BOX_INFO("Local current directory is now '" << wd << "'."); #endif } @@ -847,14 +855,15 @@ void BackupQueries::CommandGetObject(const std::vector &args, const // Check args if(args.size() != 2) { - printf("Incorrect usage.\ngetobject \n"); + BOX_ERROR("Incorrect usage. getobject " + ""); return; } int64_t id = ::strtoll(args[0].c_str(), 0, 16); if(id == std::numeric_limits::min() || id == std::numeric_limits::max() || id == 0) { - printf("Not a valid object ID (specified in hex)\n"); + BOX_ERROR("Not a valid object ID (specified in hex)."); return; } @@ -862,7 +871,7 @@ void BackupQueries::CommandGetObject(const std::vector &args, const struct stat st; if(::stat(args[1].c_str(), &st) == 0 || errno != ENOENT) { - printf("The local file %s already exists\n", args[1].c_str()); + BOX_ERROR("The local file '" << args[1] << " already exists."); return; } @@ -880,18 +889,20 @@ void BackupQueries::CommandGetObject(const std::vector &args, const std::auto_ptr objectStream(mrConnection.ReceiveStream()); objectStream->CopyStreamTo(out); - printf("Object ID %08llx fetched successfully.\n", id); + BOX_INFO("Object ID " << BOX_FORMAT_OBJECTID(id) << + " fetched successfully."); } else { - printf("Object does not exist on store.\n"); + BOX_ERROR("Object ID " << BOX_FORMAT_OBJECTID(id) << + " does not exist on store."); ::unlink(args[1].c_str()); } } catch(...) { ::unlink(args[1].c_str()); - printf("Error occured fetching object.\n"); + BOX_ERROR("Error occured fetching object."); } } @@ -911,9 +922,9 @@ void BackupQueries::CommandGet(std::vector args, const bool *opts) // Check args if(args.size() < 1 || (opts['i'] && args.size() != 2) || args.size() > 2) { - printf("Incorrect usage.\n" + BOX_ERROR("Incorrect usage.\n" "get [] or\n" - "get -i \n"); + "get -i "); return; } @@ -931,7 +942,7 @@ void BackupQueries::CommandGet(std::vector args, const bool *opts) std::string out; if(!ConvertConsoleToUtf8(i->c_str(), out)) { - fprintf(stderr, "failed to convert encoding\n"); + BOX_ERROR("Failed to convert encoding."); return; } *i = out; @@ -952,8 +963,8 @@ void BackupQueries::CommandGet(std::vector args, const bool *opts) dirId = FindDirectoryObjectID(dirName); if(dirId == 0) { - printf("Directory '%s' not found\n", - dirName.c_str()); + BOX_ERROR("Directory '" << dirName << + "' not found."); return; } } @@ -981,18 +992,19 @@ void BackupQueries::CommandGet(std::vector args, const bool *opts) fileId == std::numeric_limits::max() || fileId == 0) { - printf("Not a valid object ID (specified in hex)\n"); + BOX_ERROR("Not a valid object ID (specified in hex)."); return; } // Check that the item is actually in the directory if(dir.FindEntryByID(fileId) == 0) { - printf("ID '%08llx' not found in current " + BOX_ERROR("File ID " << + BOX_FORMAT_OBJECTID(fileId) << + " not found in current " "directory on store.\n" - "(You can only download objects by ID " - "from the current directory.)\n", - fileId); + "(You can only download files by ID " + "from the current directory.)"); return; } @@ -1007,10 +1019,11 @@ void BackupQueries::CommandGet(std::vector args, const bool *opts) if(en == 0) { - printf("Filename '%s' not found in current " + BOX_ERROR("Filename '" << args[0] << "' " + "not found in current " "directory on store.\n" "(Subdirectories in path not " - "searched.)\n", args[0].c_str()); + "searched.)"); return; } @@ -1027,8 +1040,8 @@ void BackupQueries::CommandGet(std::vector args, const bool *opts) struct stat st; if(::stat(localName.c_str(), &st) == 0 || errno != ENOENT) { - printf("The local file %s already exists, will not " - "overwrite it.\n", localName.c_str()); + BOX_ERROR("The local file " << localName << " already exists, " + "will not overwrite it."); SetReturnCode(COMMAND_RETURN_ERROR); return; } @@ -1046,7 +1059,8 @@ void BackupQueries::CommandGet(std::vector args, const bool *opts) BackupStoreFile::DecodeFile(*objectStream, localName.c_str(), mrConnection.GetTimeout()); // Done. - printf("Object ID %08llx fetched sucessfully.\n", fileId); + BOX_INFO("Object ID " << BOX_FORMAT_OBJECTID(fileId) << + " fetched successfully."); } catch (BoxException &e) { @@ -1160,14 +1174,16 @@ void BackupQueries::CommandCompare(const std::vector &args, const b } else { - printf("Warning: couldn't determine the time of the last synchronisation -- checks not performed.\n"); + BOX_WARNING("Failed to determine the time of the last " + "synchronisation -- checks not performed."); } } // Quick compare? if(params.mQuickCompare) { - printf("WARNING: Quick compare used -- file attributes are not checked.\n"); + BOX_WARNING("Quick compare used -- file attributes are not " + "checked."); } if(!opts['l'] && opts['a'] && args.size() == 0) @@ -1192,7 +1208,7 @@ void BackupQueries::CommandCompare(const std::vector &args, const b // Can't be bothered to do all the hard work to work out which location it's on, and hence which exclude list if(!params.mIgnoreExcludes) { - printf("Cannot use excludes on directory to directory comparison -- use -E flag to specify ignored excludes\n"); + BOX_ERROR("Cannot use excludes on directory to directory comparison -- use -E flag to specify ignored excludes."); return; } else @@ -1203,22 +1219,22 @@ void BackupQueries::CommandCompare(const std::vector &args, const b } else { - printf("Incorrect usage.\ncompare -a\n or compare -l \n or compare \n"); + BOX_ERROR("Incorrect usage.\ncompare -a\n or compare -l \n or compare "); return; } if (!params.mQuietCompare) { - printf("\n[ %d (of %d) differences probably due to file " - "modifications after the last upload ]\n", - params.mDifferencesExplainedByModTime, - params.mDifferences); + BOX_INFO("[ " << + params.mDifferencesExplainedByModTime << " (of " << + params.mDifferences << ") differences probably " + "due to file modifications after the last upload ]"); } - printf("Differences: %d (%d dirs excluded, %d files excluded, " - "%d files not checked)\n", - params.mDifferences, params.mExcludedDirs, - params.mExcludedFiles, params.mUncheckedFiles); + BOX_INFO("Differences: " << params.mDifferences << " (" << + params.mExcludedDirs << " dirs excluded, " << + params.mExcludedFiles << " files excluded, " << + params.mUncheckedFiles << " files not checked)"); // Set return code? if(opts['c']) @@ -1253,7 +1269,7 @@ void BackupQueries::CompareLocation(const std::string &rLocation, BackupQueries: const Configuration &locations(mrConfiguration.GetSubConfiguration("BackupLocations")); if(!locations.SubConfigurationExists(rLocation.c_str())) { - printf("Location %s does not exist.\n", rLocation.c_str()); + BOX_ERROR("Location " << rLocation << " does not exist."); return; } const Configuration &loc(locations.GetSubConfiguration(rLocation.c_str())); @@ -1264,9 +1280,9 @@ void BackupQueries::CompareLocation(const std::string &rLocation, BackupQueries: if (path.size() > 0 && path[path.size()-1] == DIRECTORY_SEPARATOR_ASCHAR) { - fprintf(stderr, "Warning: location '%s' path ends " - "with '%s', compare may fail!", - rLocation.c_str(), DIRECTORY_SEPARATOR); + BOX_WARNING("Location '" << rLocation << "' path ends " + "with '" DIRECTORY_SEPARATOR "', " + "compare may fail!"); } } #endif @@ -1319,9 +1335,9 @@ void BackupQueries::Compare(const std::string &rStoreDir, const std::string &rLo // Found? if(dirID == 0) { - printf("Local directory '%s' exists, but " - "server directory '%s' does not exist\n", - rLocalDir.c_str(), rStoreDir.c_str()); + BOX_WARNING("Local directory '" << rLocalDir << "' exists, " + "but server directory '" << rStoreDir << "' does not " + "exist."); rParams.mDifferences ++; return; } @@ -1369,24 +1385,23 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s // What kind of error? if(errno == ENOTDIR) { - printf("Local object '%s' is a file, " - "server object '%s' is a directory\n", - localDirDisplay.c_str(), - storeDirDisplay.c_str()); + BOX_WARNING("Local object '" << localDirDisplay << "' " + "is a file, server object '" << + storeDirDisplay << "' is a directory."); rParams.mDifferences ++; } else if(errno == ENOENT) { - printf("Local directory '%s' does not exist " - "(compared to server directory '%s')\n", - localDirDisplay.c_str(), - storeDirDisplay.c_str()); + BOX_WARNING("Local directory '" << localDirDisplay << + "' does not exist (compared to server " + "directory '" << storeDirDisplay << "')."); rParams.mDifferences ++; } else { - printf("ERROR: stat on local dir '%s'\n", - localDirDisplay.c_str()); + BOX_WARNING("Failed to access local directory '" << + localDirDisplay << ": " << strerror(errno) << + "'."); rParams.mUncheckedFiles ++; } return; @@ -1407,8 +1422,8 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s // Test out the attributes if(!dir.HasAttributes()) { - printf("Store directory '%s' doesn't have attributes.\n", - storeDirDisplay.c_str()); + BOX_WARNING("Store directory '" << storeDirDisplay << "' " + "doesn't have attributes."); } else { @@ -1423,10 +1438,9 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s if(!(attr.Compare(localAttr, true, true /* ignore modification times */))) { - printf("Local directory '%s' has different attributes " - "to store directory '%s'.\n", - localDirDisplay.c_str(), - storeDirDisplay.c_str()); + BOX_WARNING("Local directory '" << localDirDisplay << + "' has different attributes to store " + "directory '" << storeDirDisplay << "'."); rParams.mDifferences ++; } } @@ -1435,8 +1449,8 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s DIR *dirhandle = ::opendir(rLocalDir.c_str()); if(dirhandle == 0) { - printf("ERROR: opendir on local dir '%s'\n", - localDirDisplay.c_str()); + BOX_WARNING("Failed to open local directory '" << + localDirDisplay << "': " << strerror(errno)); rParams.mUncheckedFiles ++; return; } @@ -1457,9 +1471,9 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s #ifdef HAVE_VALID_DIRENT_D_TYPE if (localDirEn->d_type != DT_DIR) { - fprintf(stderr, "ERROR: d_type does " - "not really work on your " - "platform. Reconfigure Box!\n"); + BOX_ERROR("d_type does not really " + "work on your platform. " + "Reconfigure Box!"); return; } #endif @@ -1504,8 +1518,8 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s // Close directory if(::closedir(dirhandle) != 0) { - printf("ERROR: closedir on local dir '%s'\n", - localDirDisplay.c_str()); + BOX_ERROR("Failed to close local directory '" << + localDirDisplay << "': " << strerror(errno)); } dirhandle = 0; @@ -1565,10 +1579,10 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s if(local == localFiles.end()) { // Not found -- report - printf("Local file '%s' does not exist, " - "but store file '%s' does.\n", - localPathDisplay.c_str(), - storePathDisplay.c_str()); + BOX_WARNING("Local file '" << + localDirDisplay << "' does not exist, " + "but store file '" << + storePathDisplay << "' does."); rParams.mDifferences ++; } else @@ -1643,20 +1657,21 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s ignoreAttrModTime, fileOnServerStream->IsSymLink() /* ignore modification time if it's a symlink */)) { - printf("Local file '%s' " - "has different attributes " - "to store file '%s'.\n", - localPathDisplay.c_str(), - storePathDisplay.c_str()); + BOX_WARNING("Local file '" << + localPathDisplay << + "' has different attributes " + "to store file '" << + storePathDisplay << + "'."); rParams.mDifferences ++; if(modifiedAfterLastSync) { rParams.mDifferencesExplainedByModTime ++; - printf("(the file above was modified after the last sync time -- might be reason for difference)\n"); + BOX_INFO("(the file above was modified after the last sync time -- might be reason for difference)"); } else if(i->second->HasAttributes()) { - printf("(the file above has had new attributes applied)\n"); + BOX_INFO("(the file above has had new attributes applied)\n"); } } @@ -1722,20 +1737,21 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s // Report if not equal. if(!equal) { - printf("Local file '%s' " + BOX_WARNING("Local file '" << + localPathDisplay << "' " "has different contents " - "to store file '%s'.\n", - localPathDisplay.c_str(), - storePathDisplay.c_str()); + "to store file '" << + storePathDisplay << + "'."); rParams.mDifferences ++; if(modifiedAfterLastSync) { rParams.mDifferencesExplainedByModTime ++; - printf("(the file above was modified after the last sync time -- might be reason for difference)\n"); + BOX_INFO("(the file above was modified after the last sync time -- might be reason for difference)"); } else if(i->second->HasAttributes()) { - printf("(the file above has had new attributes applied)\n"); + BOX_INFO("(the file above has had new attributes applied)\n"); } } } @@ -1794,11 +1810,11 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s if(rParams.mpExcludeFiles == 0 || !(rParams.mpExcludeFiles->IsExcluded(localPath))) { - printf("Local file '%s' exists, " - "but store file '%s' " - "does not exist.\n", - localPathDisplay.c_str(), - storePathDisplay.c_str()); + BOX_WARNING("Local file '" << + localPathDisplay << + "' exists, but store file '" << + storePathDisplay << + "' does not."); rParams.mDifferences ++; // Check the file modification time @@ -1809,7 +1825,7 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s if(FileModificationTime(st) > rParams.mLatestFileUploadTime) { rParams.mDifferencesExplainedByModTime ++; - printf("(the file above was modified after the last sync time -- might be reason for difference)\n"); + BOX_INFO("(the file above was modified after the last sync time -- might be reason for difference)"); } } } @@ -1852,19 +1868,19 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s rParams.mpExcludeDirs->IsExcluded(localPath)) { // Not found -- report - printf("Local directory '%s' is excluded, but " - "store directory '%s' still exists.\n", - localPathDisplay.c_str(), - storePathDisplay.c_str()); + BOX_WARNING("Local directory '" << + localPathDisplay << "' is excluded, " + "but store directory '" << + storePathDisplay << "' still exists."); rParams.mDifferences ++; } else if(local == localDirs.end()) { // Not found -- report - printf("Local directory '%s' does not exist, " - "but store directory '%s' does.\n", - localPathDisplay.c_str(), - storePathDisplay.c_str()); + BOX_WARNING("Local directory '" << + localPathDisplay << "' does not exist, " + "but store directory '" << + storePathDisplay << "' does."); rParams.mDifferences ++; } else if(rParams.mpExcludeDirs != NULL && @@ -1908,10 +1924,10 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s // Should this be ignored (ie is excluded)? if(rParams.mpExcludeDirs == 0 || !(rParams.mpExcludeDirs->IsExcluded(localPath))) { - printf("Local directory '%s' exists, but " - "store directory '%s' does not exist.\n", - localPathDisplay.c_str(), - storePathDisplay.c_str()); + BOX_WARNING("Local directory '" << + localPathDisplay << "' exists, but " + "store directory '" << + storePathDisplay << "' does not."); rParams.mDifferences ++; } else @@ -1944,7 +1960,7 @@ void BackupQueries::CommandRestore(const std::vector &args, const b // Check arguments if(args.size() != 2) { - printf("Incorrect usage.\nrestore [-d] [-r] [-i] \n"); + BOX_ERROR("Incorrect usage. restore [-d] [-r] [-i] "); return; } @@ -1959,7 +1975,7 @@ void BackupQueries::CommandRestore(const std::vector &args, const b dirID = ::strtoll(args[0].c_str(), 0, 16); if(dirID == std::numeric_limits::min() || dirID == std::numeric_limits::max() || dirID == 0) { - printf("Not a valid object ID (specified in hex)\n"); + BOX_ERROR("Not a valid object ID (specified in hex)"); return; } } @@ -1982,12 +1998,12 @@ void BackupQueries::CommandRestore(const std::vector &args, const b // Allowable? if(dirID == 0) { - printf("Directory '%s' not found on server\n", args[0].c_str()); + BOX_ERROR("Directory '" << args[0] << "' not found on server"); return; } if(dirID == BackupProtocolClientListDirectory::RootDirectory) { - printf("Cannot restore the root directory -- restore locations individually.\n"); + BOX_ERROR("Cannot restore the root directory -- restore locations individually."); return; } @@ -2023,31 +2039,31 @@ void BackupQueries::CommandRestore(const std::vector &args, const b switch(result) { case Restore_Complete: - printf("Restore complete\n"); + BOX_INFO("Restore complete."); break; case Restore_ResumePossible: - printf("Resume possible -- repeat command with -r flag to resume\n"); + BOX_ERROR("Resume possible -- repeat command with -r flag to resume"); break; case Restore_TargetExists: - printf("The target directory exists. You cannot restore over an existing directory.\n"); + BOX_ERROR("The target directory exists. You cannot restore over an existing directory."); break; #ifdef WIN32 case Restore_TargetPathNotFound: - printf("The target directory path does not exist.\n" + BOX_ERROR("The target directory path does not exist.\n" "To restore to a directory whose parent " - "does not exist, create the parent first.\n"); + "does not exist, create the parent first."); break; #endif case Restore_UnknownError: - printf("Unknown error during restore.\n"); + BOX_ERROR("Unknown error during restore."); break; default: - printf("ERROR: Unknown restore result %d.\n", result); + BOX_ERROR("Unknown restore result " << result << "."); break; } } @@ -2167,7 +2183,7 @@ void BackupQueries::CommandUndelete(const std::vector &args, const // Check arguments if(args.size() != 1) { - printf("Incorrect usage.\nundelete \n"); + BOX_ERROR("Incorrect usage. undelete "); return; } @@ -2185,12 +2201,12 @@ void BackupQueries::CommandUndelete(const std::vector &args, const // Allowable? if(dirID == 0) { - printf("Directory '%s' not found on server\n", args[0].c_str()); + BOX_ERROR("Directory '" << args[0] << "' not found on server."); return; } if(dirID == BackupProtocolClientListDirectory::RootDirectory) { - printf("Cannot undelete the root directory.\n"); + BOX_ERROR("Cannot undelete the root directory."); return; } diff --git a/bin/bbackupquery/bbackupquery.cpp b/bin/bbackupquery/bbackupquery.cpp index 9cc3eb1a..98726843 100644 --- a/bin/bbackupquery/bbackupquery.cpp +++ b/bin/bbackupquery/bbackupquery.cpp @@ -12,8 +12,14 @@ #ifdef HAVE_UNISTD_H #include #endif + +#include #include -#include + +#ifdef HAVE_SYS_TYPES_H + #include +#endif + #ifdef HAVE_LIBREADLINE #ifdef HAVE_READLINE_READLINE_H #include @@ -168,7 +174,8 @@ int main(int argc, const char *argv[]) logFile = ::fopen(optarg, "w"); if(logFile == 0) { - printf("Can't open log file '%s'\n", optarg); + BOX_ERROR("Failed to open log file '" << + optarg << "': " << strerror(errno)); } break; @@ -201,14 +208,14 @@ int main(int argc, const char *argv[]) { if (!SetConsoleCP(CP_UTF8)) { - fprintf(stderr, "Failed to set input codepage: " - "error %d\n", GetLastError()); + BOX_ERROR("Failed to set input codepage: " << + GetErrorMessage(GetLastError())); } if (!SetConsoleOutputCP(CP_UTF8)) { - fprintf(stderr, "Failed to set output codepage: " - "error %d\n", GetLastError()); + BOX_ERROR("Failed to set output codepage: " << + GetErrorMessage(GetLastError())); } // enable input of Unicode characters @@ -222,8 +229,7 @@ int main(int argc, const char *argv[]) #endif // WIN32 // Read in the configuration file - if(!quiet) printf("Using configuration file %s\n", - configFilename.c_str()); + if(!quiet) BOX_INFO("Using configuration file " << configFilename); std::string errs; std::auto_ptr config( @@ -232,7 +238,7 @@ int main(int argc, const char *argv[]) if(config.get() == 0 || !errs.empty()) { - printf("Invalid configuration file:\n%s", errs.c_str()); + BOX_FATAL("Invalid configuration file: " << errs); return 1; } // Easier coding @@ -252,12 +258,12 @@ int main(int argc, const char *argv[]) BackupClientCryptoKeys_Setup(conf.GetKeyValue("KeysFile").c_str()); // 2. Connect to server - if(!quiet) printf("Connecting to store...\n"); + if(!quiet) BOX_INFO("Connecting to store..."); SocketStreamTLS socket; socket.Open(tlsContext, Socket::TypeINET, conf.GetKeyValue("StoreHostname").c_str(), BOX_PORT_BBSTORED); // 3. Make a protocol, and handshake - if(!quiet) printf("Handshake with store...\n"); + if(!quiet) BOX_INFO("Handshake with store..."); BackupProtocolClient connection(socket); connection.Handshake(); @@ -268,7 +274,7 @@ int main(int argc, const char *argv[]) } // 4. Log in to server - if(!quiet) printf("Login to store...\n"); + if(!quiet) BOX_INFO("Login to store..."); // Check the version of the server { std::auto_ptr serverVersion(connection.QueryVersion(BACKUP_STORE_SERVER_VERSION)); @@ -345,9 +351,9 @@ int main(int argc, const char *argv[]) #endif // Done... stop nicely - if(!quiet) printf("Logging off...\n"); + if(!quiet) BOX_INFO("Logging off..."); connection.QueryFinished(); - if(!quiet) printf("Session finished.\n"); + if(!quiet) BOX_INFO("Session finished."); // Return code returnCode = context.GetReturnCode(); -- cgit v1.2.3