Changeset 155 for uKadecot/trunk/uip
- Timestamp:
- Feb 4, 2016, 11:11:09 PM (8 years ago)
- Location:
- uKadecot/trunk/uip/apps/webserver
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uKadecot/trunk/uip/apps/webserver/http-strings
r101 r155 8 8 http_content_type "content-type: " 9 9 http_texthtml "text/html" 10 http_location " location: "10 http_location "Location: " 11 11 http_host "host: " 12 12 http_crnl "\r\n" … … 21 21 http_header_101 "HTTP/1.1 101 Switching Protocols\r\n" 22 22 http_header_200 "HTTP/1.1 200 OK\r\nServer: uIP/1.0 http://www.toppers.jp/\r\nConnection: close\r\n" 23 http_header_301 "HTTP/1.1 301 Moved Permanently\r\nServer: uIP/1.0 http://www.toppers.jp/\r\nConnection: close\r\n" 23 24 http_header_404 "HTTP/1.1 404 Not found\r\nServer: uIP/1.0 http://www.toppers.jp/\r\nConnection: close\r\n" 24 25 http_content_encoding_gzip "Content-Encoding: gzip\r\n" -
uKadecot/trunk/uip/apps/webserver/http-strings.c
r108 r155 27 27 {0x74, 0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, }; 28 28 const char http_location[11] = 29 /* " location: " */30 {0x 6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, };29 /* "Location: " */ 30 {0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, }; 31 31 const char http_host[7] = 32 32 /* "host: " */ … … 65 65 /* "HTTP/1.1 200 OK\r\nServer: uIP/1.0 http://www.toppers.jp/\r\nConnection: close\r\n" */ 66 66 {0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x20, 0x32, 0x30, 0x30, 0x20, 0x4f, 0x4b, 0xd, 0xa, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a, 0x20, 0x75, 0x49, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x74, 0x6f, 0x70, 0x70, 0x65, 0x72, 0x73, 0x2e, 0x6a, 0x70, 0x2f, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0xd, 0xa, }; 67 const char http_header_301[92] = 68 /* "HTTP/1.1 301 Moved Permanently\r\nServer: uIP/1.0 http://www.toppers.jp/\r\nConnection: close\r\n" */ 69 {0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x20, 0x33, 0x30, 0x31, 0x20, 0x4d, 0x6f, 0x76, 0x65, 0x64, 0x20, 0x50, 0x65, 0x72, 0x6d, 0x61, 0x6e, 0x65, 0x6e, 0x74, 0x6c, 0x79, 0xd, 0xa, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3a, 0x20, 0x75, 0x49, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x74, 0x6f, 0x70, 0x70, 0x65, 0x72, 0x73, 0x2e, 0x6a, 0x70, 0x2f, 0xd, 0xa, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0xd, 0xa, }; 67 70 const char http_header_404[84] = 68 71 /* "HTTP/1.1 404 Not found\r\nServer: uIP/1.0 http://www.toppers.jp/\r\nConnection: close\r\n" */ -
uKadecot/trunk/uip/apps/webserver/http-strings.h
r108 r155 21 21 extern const char http_header_101[35]; 22 22 extern const char http_header_200[77]; 23 extern const char http_header_301[92]; 23 24 extern const char http_header_404[84]; 24 25 extern const char http_content_encoding_gzip[25]; -
uKadecot/trunk/uip/apps/webserver/httpd-fs.c
r154 r155 40 40 #include "mmc_rspi.h" 41 41 #include <string.h> 42 #include "http-strings.h" 43 44 #ifndef _MSC_VER 45 #ifndef strcat_s 46 #define strcat_s(dst, dsz, src) strcat(dst, src) 47 #endif 48 #endif 42 49 43 50 //#define FILE_DUMP … … 114 121 /*-----------------------------------------------------------------------------------*/ 115 122 int 116 httpd_fs_open(int drv, c onst char *name, struct httpd_fs_file *file)123 httpd_fs_open(int drv, char *name, int len, struct httpd_fs_file *file) 117 124 { 118 125 FRESULT res; 119 FATFS *fs = (FATFS *)file->fs; 126 FATFS *fs = (FATFS *)&file->fs; 127 FILINFO fno; 128 DIR dir; 120 129 121 130 file->pos = 0; … … 123 132 file->drv = drv; 124 133 file->name = name; 134 file->redirect = 0; 125 135 memset(fs, 0, sizeof(FATFS)); 126 136 … … 143 153 } 144 154 145 if((res = pf_open(fs, name)) != FR_OK){ 146 printf("pf_open(%d:%s) => %d\n", drv, name, res); 147 return 0; 155 if ((res = pf_open(fs, name)) != FR_OK) { 156 dir.fs = fs; 157 if ((res = pf_opendir(&dir, name)) != FR_OK) { 158 printf("pf_opendir(%d:%s) => %d\n", drv, name, res); 159 return 0; 160 } 161 162 if ((res = pf_readdir(&dir, &fno)) != FR_OK) { 163 printf("pf_readdir(%d:%s) => %d\n", drv, name, res); 164 return 0; 165 } 166 167 if (len != 0/*fno.fattrib & AM_DIR*/) { 168 strcat_s(name, len, http_index_html); 169 res = pf_open(fs, name); 170 file->redirect = res == FR_OK; 171 } 172 else 173 res = FR_NO_FILE; 174 175 if (res != FR_OK) { 176 printf("pf_open(%d:%s) => %d %x\n", drv, name, res, fno.fattrib); 177 return 0; 178 } 148 179 } 149 180 … … 160 191 FRESULT ret; 161 192 UINT rlen; 162 FATFS *fs = (FATFS *) file->fs;193 FATFS *fs = (FATFS *)&file->fs; 163 194 164 195 if((ret = pf_lseek(fs, file->pos)) != FR_OK){ -
uKadecot/trunk/uip/apps/webserver/httpd-fs.h
r154 r155 43 43 int drv; 44 44 const char *name; 45 void *fs; 45 int redirect; 46 char fs[64 + 512/*sizeof(FATFS)*/]; 46 47 }; 47 48 48 49 /* file must be allocated by caller and will be filled in 49 50 by the function. */ 50 int httpd_fs_open(int drv, c onst char *name, struct httpd_fs_file *file);51 int httpd_fs_open(int drv, char *name, int len, struct httpd_fs_file *file); 51 52 int httpd_fs_read(struct httpd_fs_file *file, void *dst, int len); 52 53 -
uKadecot/trunk/uip/apps/webserver/httpd.c
r154 r155 203 203 } 204 204 205 if (s->file.redirect) { 206 len = strlen(http_location); 207 memcpy(pos, http_location, len); pos += len; 208 if (s->drv == 1) { 209 len = 2; 210 memcpy(pos, "/~", len); pos += len; 211 } 212 len = strlen(s->filename); 213 memcpy(pos, s->filename, len); pos += len; 214 len = 2; 215 memcpy(pos, "\r\n", len); pos += len; 216 } 217 205 218 ptr = strrchr(s->message.request_url, ISO_period); 206 219 if (ptr == NULL) { … … 248 261 PT_BEGIN(&s->outputpt); 249 262 250 s->file.fs = ((char *)&s[1]) - 64 - 512; 251 252 if (!httpd_fs_open(s->drv, s->filename, &s->file)) { 263 if (!httpd_fs_open(s->drv, s->filename, sizeof(s->filename), &s->file)) { 253 264 s->drv = 0; 254 httpd_fs_open(s->drv, http_404_html, &s->file);255 strcpy_s(s->message.request_url, sizeof(s->message.request_url), http_404_html);265 strcpy_s(s->filename, sizeof(s->filename), http_404_html); 266 httpd_fs_open(s->drv, s->filename, sizeof(s->filename), &s->file); 256 267 PT_WAIT_THREAD(&s->outputpt, 257 268 send_headers(s, … … 261 272 PT_WAIT_THREAD(&s->outputpt, 262 273 send_headers(s, 263 http_header_200));274 s->file.redirect ? http_header_301 : http_header_200)); 264 275 PT_WAIT_THREAD(&s->outputpt, send_file(s)); 265 276 } … … 381 392 size_t done; 382 393 const char *data; 394 char *ptr; 395 383 396 PSOCK_BEGIN(&s->sin); 384 397 … … 407 420 /* ""か"/"なら"index.html"に変更 */ 408 421 if ((s->message.request_url[0] == '\0') || ((s->message.request_url[0] == '/') && (s->message.request_url[1] == '\0'))) { 409 s trncpy_s(s->message.request_url, sizeof(s->message.request_url), http_index_html, sizeof(s->message.request_url));410 s ->filename = s->message.request_url;422 s->drv = 0; 423 strcpy_s(s->filename, sizeof(s->filename), http_index_html); 411 424 } 412 425 /* "/~/"ならSDカードから読み込み */ 413 426 else if ((s->message.request_url[0] == '/') && (s->message.request_url[1] == '~') && (s->message.request_url[2] == '/')) { 414 427 s->drv = 1; 415 s ->filename = &s->message.request_url[2];428 strcpy_s(s->filename, sizeof(s->filename), &s->message.request_url[2]); 416 429 } 417 430 else { 418 431 s->drv = 0; 419 s->filename = s->message.request_url; 420 } 432 strcpy_s(s->filename, sizeof(s->filename), s->message.request_url); 433 } 434 435 ptr = strrchr(s->filename, '?'); 436 if (ptr != NULL) 437 ptr[0] = '\0'; 421 438 422 439 /* httpd_log_file(uip_conn->ripaddr, s->message.request_url);*/ … … 426 443 s->state = STATE_WS_OUTPUT; 427 444 445 s->close_req = 0; 428 446 websocket_init(&s->websocket, uip_getid((struct uip_conn *)((intptr_t)s - offsetof(struct uip_conn, appstate)))); 429 447 for (;;) { -
uKadecot/trunk/uip/apps/webserver/httpd.h
r154 r155 47 47 char inputbuf[50]; 48 48 char state; 49 int drv; 50 char *filename; 51 int len; 52 struct httpd_fs_file file; 53 int parse_pos; 54 int parse_len; 55 struct http_parser parser; 56 struct http_parser_url handle; 57 struct message message; 58 struct websocket websocket; 59 int close_req; 49 union{ 50 struct{ 51 int parse_pos; 52 int parse_len; 53 struct http_parser parser; 54 struct http_parser_url handle; 55 struct message message; 56 }; 57 struct{ 58 char _dummy1[340]; 59 int drv; 60 char filename[256]; 61 int len; 62 struct httpd_fs_file file; 63 }; 64 struct{ 65 char _dummy2[340]; 66 struct websocket websocket; 67 int close_req; 68 }; 69 }; 60 70 }; 61 71 #define get_context(p) (struct httpd_state *)((intptr_t)p - (intptr_t)&((struct httpd_state *)0)->parser)
Note:
See TracChangeset
for help on using the changeset viewer.