http_server.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* ympd
  2. (c) 2013-2014 Andrew Karpow <andy@ndyk.de>
  3. This project's homepage is: http://www.ympd.org
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with this program; if not, write to the Free Software Foundation, Inc.,
  13. Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  14. */
  15. #include <string.h>
  16. #include "http_server.h"
  17. int callback_http(struct mg_connection *c)
  18. {
  19. const struct embedded_file *req_file;
  20. if(!strcmp(c->uri, "/"))
  21. req_file = find_embedded_file("/index.html");
  22. else
  23. req_file = find_embedded_file(c->uri);
  24. if(req_file)
  25. {
  26. mg_send_header(c, "Content-Type", req_file->mimetype);
  27. mg_send_data(c, req_file->data, req_file->size);
  28. return MG_TRUE;
  29. }
  30. mg_send_status(c, 404);
  31. mg_printf_data(c, "Not Found");
  32. return MG_TRUE;
  33. }