Synchronize notmuch mail across machines
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

misc.h 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // -*- C++ -*-
  2. #ifndef _MUCHSYNC_MISC_H_
  3. #define _MUCHSYNC_MISC_H_ 1
  4. #include <cstddef>
  5. #include <string>
  6. #include <time.h>
  7. #include <sys/time.h>
  8. #include <openssl/sha.h>
  9. #ifndef ST_MTIM
  10. #define ST_MTIM 1
  11. #endif //!ST_MTIM
  12. using std::string;
  13. extern int opt_verbose;
  14. template<typename C> inline typename C::mapped_type
  15. find_default (typename C::mapped_type def, const C &c, typename C::key_type k)
  16. {
  17. auto i = c.find(k);
  18. return i == c.end() ? def : i->second;
  19. }
  20. std::istream &input_match (std::istream &in, char want);
  21. string percent_encode (const string &raw);
  22. string percent_decode (const string &escaped);
  23. class hash_ctx {
  24. SHA_CTX ctx_;
  25. public:
  26. static constexpr size_t output_bytes = SHA_DIGEST_LENGTH;
  27. hash_ctx() { init(); }
  28. void init() { SHA1_Init(&ctx_); }
  29. void update(const void *buf, size_t n) { SHA1_Update (&ctx_, buf, n); }
  30. string final();
  31. };
  32. bool hash_ok (const string &hash);
  33. constexpr double
  34. ts_to_double (const timespec &ts)
  35. {
  36. return ts.tv_sec + ts.tv_nsec / 1000000000.0;
  37. }
  38. void print_time (string msg);
  39. #endif /* !_MUCHSYNC_MISC_H_ 1 */