http_server.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* ympd
  2. (c) 2013-2014 Andrew Karpow <andy@ympd.org>
  3. This project's homepage is: http://www.ympd.org
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. - Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  15. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  16. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #include <string.h>
  25. #include "http_server.h"
  26. #include "http_files.h"
  27. int callback_http(struct mg_connection *c)
  28. {
  29. const struct embedded_file *req_file;
  30. if(!strcmp(c->uri, "/"))
  31. req_file = find_embedded_file("/index.html");
  32. else
  33. req_file = find_embedded_file(c->uri);
  34. if(req_file)
  35. {
  36. mg_send_header(c, "Content-Type", req_file->mimetype);
  37. mg_send_data(c, req_file->data, req_file->size);
  38. return MG_REQUEST_PROCESSED;
  39. }
  40. mg_send_status(c, 404);
  41. mg_printf_data(c, "Not Found");
  42. return MG_REQUEST_PROCESSED;
  43. }