http.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: */
  2. /*
  3. * Copyright (c) 2016 Red Hat, Inc.
  4. * Author: Nathaniel McCallum <npmccallum@redhat.com>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #pragma once
  20. #include <http_parser.h>
  21. #include <sys/types.h>
  22. #include <regex.h>
  23. struct http_dispatch {
  24. int (*func)(enum http_method method, const char *path,
  25. const char *body, regmatch_t matches[], void *misc);
  26. uint64_t methods;
  27. size_t nmatches;
  28. const char *re;
  29. };
  30. struct http_request {
  31. int status;
  32. char path[1024 * 4];
  33. char body[1024 * 64];
  34. };
  35. struct http_state {
  36. const struct http_dispatch *dispatch;
  37. struct http_request req;
  38. void *misc;
  39. };
  40. extern const http_parser_settings http_settings;
  41. int __attribute__ ((format(printf, 4, 5)))
  42. http_reply(const char *file, int line,
  43. enum http_status code, const char *fmt, ...);
  44. #define http_reply(code, ...) \
  45. http_reply(__FILE__, __LINE__, code, __VA_ARGS__)