X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=util.h;h=0d1b45d45e83983bf62194a5d631d3f41eeacb20;hb=5d386960f207f991833f1204748bc4323934f761;hp=bb36333efff10b862fb2d6a98addc88a1a917c43;hpb=6bb973b965a30832c3e2d9f6a24e80d3309ef89e;p=cumulus.git diff --git a/util.h b/util.h index bb36333..0d1b45d 100644 --- a/util.h +++ b/util.h @@ -1,10 +1,25 @@ -/* LBS: An LFS-inspired filesystem backup system - * Copyright (C) 2006 Michael Vrable +/* Cumulus: Efficient Filesystem Backup to the Cloud + * Copyright (C) 2007 The Cumulus Developers + * See the AUTHORS file for a list of contributors. * - * Utility functions for converting various datatypes to text format (and - * later, for parsing them back, perhaps). + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +/* Utility functions for converting various datatypes to text format (and + * later, for parsing them back, perhaps). */ + #ifndef _LBS_FORMAT_H #define _LBS_FORMAT_H @@ -15,10 +30,31 @@ std::string uri_encode(const std::string &in); std::string uri_decode(const std::string &in); std::string encode_int(long long n, int base=10); -std::string encode_dict(const std::map& dict); -void dict_output(std::ostream &o, - const std::map& dict); long long parse_int(const std::string &s); +void cloexec(int fd); + +void fatal(std::string msg) __attribute__((noreturn)); + +/* Date/time string formatting and parsing utility functions. All data and + * methods are static, so this class should not be instantiated. */ +class TimeFormat { +public: + // Abbreviated time format encoded in snapshot file names. + static const char FORMAT_FILENAME[]; + // A timestamp, in UTC, written out in an ISO 8601 format (compatible with + // the SQLite datetime function). + static const char FORMAT_ISO8601[]; + // Similar to the above, but including a timezone offset. + static const char FORMAT_LOCALTIME[]; + + static std::string format(time_t timestamp, const char *format, bool utc); + + static std::string isoformat(time_t timestamp) + { return format(timestamp, FORMAT_ISO8601, true); } + +private: + TimeFormat() { } +}; #endif // _LBS_TARSTORE_H