handler.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 __HANDLER_H__
  17. #define __HANDLER_H__
  18. #include <sys/queue.h>
  19. #include <stdbool.h>
  20. #include "helper.h"
  21. #include "htpasswd.h"
  22. #include "session.h"
  23. #include "template.h"
  24. extern char *cms_content_dir;
  25. extern char *cms_template_dir;
  26. extern char *cms_session_db;
  27. extern char *cms_session_htpasswd;
  28. struct page_info {
  29. char *path;
  30. struct md_mmap *content;
  31. struct md_mmap *descr;
  32. struct memmap *link;
  33. struct md_mmap *login;
  34. struct memmap *sort;
  35. struct memmap *style;
  36. struct memmap *script;
  37. struct memmap *title;
  38. bool ssl;
  39. bool sub;
  40. };
  41. struct lang_pref {
  42. TAILQ_ENTRY(lang_pref) entries;
  43. float priority;
  44. char lang[18];
  45. char short_lang[9];
  46. };
  47. struct header {
  48. TAILQ_ENTRY(header) entries;
  49. char *key;
  50. char *value;
  51. };
  52. struct param {
  53. TAILQ_ENTRY(param) entries;
  54. char *name;
  55. char *value;
  56. };
  57. struct cookie {
  58. TAILQ_ENTRY(cookie) entries;
  59. char *name;
  60. char *value;
  61. char *path;
  62. char *domain;
  63. time_t expires;
  64. };
  65. enum request_method {
  66. GET = 0, POST, INVALID
  67. };
  68. struct request {
  69. int content_dir;
  70. int lang_dir;
  71. int page_dir;
  72. int template_dir;
  73. char *path_info;
  74. char *page;
  75. char *lang;
  76. char *path;
  77. struct page_info *page_info;
  78. struct tmpl_data *data;
  79. struct md_mmap *content;
  80. struct memmap *tmpl_file;
  81. int status_code;
  82. int request_method;
  83. char *status;
  84. TAILQ_HEAD(, header) headers;
  85. TAILQ_HEAD(, lang_pref) accept_languages;
  86. TAILQ_HEAD(, cookie) cookies;
  87. TAILQ_HEAD(, param) params;
  88. struct dir_list *avail_languages;
  89. struct session *session;
  90. struct session_store *session_store;
  91. struct htpasswd *htpasswd;
  92. void *req_body;
  93. size_t req_body_size;
  94. };
  95. struct lang_pref *lang_pref_new(const char *_lang, const float _prio);
  96. void lang_pref_free(struct lang_pref *);
  97. struct request *request_new(char *_page_uri);
  98. void request_free(struct request *);
  99. struct page_info *page_info_new(char *_path);
  100. void page_info_free(struct page_info *);
  101. struct page_info *request_fetch_page(struct request *);
  102. struct tmpl_loop *fetch_language_links(struct request *);
  103. struct tmpl_loop *fetch_links(struct request *);
  104. char *set_language(struct request *);
  105. void request_add_lang_pref(struct request *,
  106. struct lang_pref *);
  107. void request_parse_lang_pref(struct request *);
  108. struct header *header_new(const char *, const char *);
  109. void header_free(struct header *);
  110. void request_add_header(struct request *, const char *,
  111. const char *);
  112. struct buffer_list * request_output_headers(struct request *);
  113. struct cookie *cookie_new(const char *, const char *);
  114. void cookie_free(struct cookie *);
  115. void request_cookie_mark_delete(struct request *,
  116. struct cookie *);
  117. bool request_cookie_remove(struct request *,
  118. struct cookie *);
  119. void request_cookie_set(struct request *, struct cookie *);
  120. struct cookie * request_cookie_get(struct request *, const char *);
  121. void request_parse_cookies(struct request *);
  122. struct tmpl_data *request_init_tmpl_data(struct request *);
  123. struct tmpl_loop *request_get_language_links(struct request *);
  124. struct tmpl_loop *request_get_links(struct request *);
  125. struct param *param_new(const char *, const char *);
  126. void param_free(struct param *);
  127. void param_decode(struct param *);
  128. void request_parse_params(struct request *, const char *);
  129. struct param *request_get_param(struct request *, const char *,
  130. struct param *);
  131. bool request_read_post_body(struct request *);
  132. bool request_handle_login(struct request *);
  133. struct buffer_list *request_render_page(struct request *, const char *);
  134. __dead void _error(const char *, const char *);
  135. #endif // __HANDLER_H__