httpd-fs.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) 2001, Swedish Institute of Computer Science.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the Institute nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. *
  29. * This file is part of the lwIP TCP/IP stack.
  30. *
  31. * Author: Adam Dunkels <adam@sics.se>
  32. *
  33. * $Id: httpd-fs.c,v 1.1 2006/06/07 09:13:08 adam Exp $
  34. */
  35. #include "httpd.h"
  36. #include "httpd-fs.h"
  37. #include "httpd-fsdata.h"
  38. #ifndef NULL
  39. #define NULL 0
  40. #endif /* NULL */
  41. #include "httpd-fsdata.c"
  42. #if HTTPD_FS_STATISTICS
  43. static u16_t count[HTTPD_FS_NUMFILES];
  44. #endif /* HTTPD_FS_STATISTICS */
  45. /*-----------------------------------------------------------------------------------*/
  46. static u8_t
  47. httpd_fs_strcmp(const char *str1, const char *str2)
  48. {
  49. u8_t i;
  50. i = 0;
  51. loop:
  52. if(str2[i] == 0 ||
  53. str1[i] == '\r' ||
  54. str1[i] == '\n') {
  55. return 0;
  56. }
  57. if(str1[i] != str2[i]) {
  58. return 1;
  59. }
  60. ++i;
  61. goto loop;
  62. }
  63. /*-----------------------------------------------------------------------------------*/
  64. int
  65. httpd_fs_open(const char *name, struct httpd_fs_file *file)
  66. {
  67. #if HTTPD_FS_STATISTICS
  68. u16_t i = 0;
  69. #endif /* HTTPD_FS_STATISTICS */
  70. struct httpd_fsdata_file_noconst *f;
  71. for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;
  72. f != NULL;
  73. f = (struct httpd_fsdata_file_noconst *)f->next) {
  74. if(httpd_fs_strcmp(name, f->name) == 0) {
  75. file->data = f->data;
  76. file->len = f->len;
  77. #if HTTPD_FS_STATISTICS
  78. ++count[i];
  79. #endif /* HTTPD_FS_STATISTICS */
  80. return 1;
  81. }
  82. #if HTTPD_FS_STATISTICS
  83. ++i;
  84. #endif /* HTTPD_FS_STATISTICS */
  85. }
  86. return 0;
  87. }
  88. /*-----------------------------------------------------------------------------------*/
  89. void
  90. httpd_fs_init(void)
  91. {
  92. #if HTTPD_FS_STATISTICS
  93. u16_t i;
  94. for(i = 0; i < HTTPD_FS_NUMFILES; i++) {
  95. count[i] = 0;
  96. }
  97. #endif /* HTTPD_FS_STATISTICS */
  98. }
  99. /*-----------------------------------------------------------------------------------*/
  100. #if HTTPD_FS_STATISTICS
  101. u16_t httpd_fs_count
  102. (char *name)
  103. {
  104. struct httpd_fsdata_file_noconst *f;
  105. u16_t i;
  106. i = 0;
  107. for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;
  108. f != NULL;
  109. f = (struct httpd_fsdata_file_noconst *)f->next) {
  110. if(httpd_fs_strcmp(name, f->name) == 0) {
  111. return count[i];
  112. }
  113. ++i;
  114. }
  115. return 0;
  116. }
  117. #endif /* HTTPD_FS_STATISTICS */
  118. /*-----------------------------------------------------------------------------------*/