session.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2018 Markus Hennecke <markus-hennecke@markus-hennecke.de>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef __SESSION_H__
  17. #define __SESSION_H__
  18. #include <sys/types.h>
  19. #include <db.h>
  20. #include <stdbool.h>
  21. struct session_data {
  22. time_t timeout;
  23. int loggedin;
  24. char username[32];
  25. };
  26. struct session {
  27. struct session_data data;
  28. char *sid;
  29. };
  30. struct session_store {
  31. DB *db;
  32. char *filename;
  33. };
  34. struct session_data *session_data_new(void);
  35. bool session_data_timeout(struct session_data *);
  36. struct session *session_new(void);
  37. void session_free(struct session *);
  38. bool session_save(struct session *, struct session_store *,
  39. bool);
  40. struct session *session_load(char *, struct session_store *);
  41. struct session_store *session_store_new(const char *);
  42. void session_store_free(struct session_store *);
  43. void session_store_cleanup(struct session_store *);
  44. #endif // __SESSION_H__