Changeset 279 for EcnlProtoTool/trunk/ntshell
- Timestamp:
- Apr 29, 2017, 4:33:37 PM (7 years ago)
- Location:
- EcnlProtoTool/trunk/ntshell
- Files:
-
- 57 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/ntshell/fatfs/ccsbcs.c
r278 r279 266 266 267 267 268 #if !_TBLDEF || !_USE_LFN268 #if _CODE_PAGE != 65001 && (!_TBLDEF || !_USE_LFN) 269 269 #error This file is not needed at current configuration. Remove from the project. 270 270 #endif … … 272 272 273 273 274 274 #if _CODE_PAGE != 65001 275 275 WCHAR ff_convert ( /* Converted character, Returns zero on error */ 276 276 WCHAR chr, /* Character code to be converted */ … … 298 298 return c; 299 299 } 300 300 #endif 301 301 302 302 -
EcnlProtoTool/trunk/ntshell/fatfs/diskio.c
r278 r279 15 15 #define MAX_DRIVES 1 /* Max number of physical drives to be used */ 16 16 17 unsigned char RamDisk[SZ_RAMDISK * 1024]; 17 #define RamDisk _binary____webserver_httpd_fs_bin_start 18 extern unsigned char RamDisk[]; 18 19 19 20 typedef struct { -
EcnlProtoTool/trunk/ntshell/fatfs/ff.c
r278 r279 314 314 #endif 315 315 #define _DF1S 0 316 317 #elif _CODE_PAGE == 65001 /* UTF-8 */ 318 #if _LFN_UNICODE 319 #error Cannot use LFN_UNICODE feature without valid code page. 320 #endif 321 #define _DF1S 0 322 323 void Utf16_to_Utf8(unsigned char *ret_code, int *ret_size, UINT chr) 324 { 325 ret_code[0] = ret_code[1] = ret_code[2] = ret_code[3] = 0; 326 327 if (chr <= 0x7f) { // ASCIIäºæ 328 ret_code[0] = chr; 329 *ret_size = 1; 330 return; 331 } 332 333 if (chr <= 0x7ff) { 334 ret_code[1] = (0x80 | (chr & 0x3f)); 335 ret_code[0] = (0xc0 | (chr >> 6)); 336 *ret_size = 2; 337 return; 338 } 339 340 if (chr <= 0xffff) { 341 ret_code[2] = (0x80 | (chr & 0x3f)); 342 ret_code[1] = (0x80 | ((chr >> 6) & 0x3f)); 343 ret_code[0] = (0xe0 | ((chr >> 12) & 0x0f)); 344 *ret_size = 3; 345 return; 346 } 347 348 if (chr <= 0x1fffff) { 349 ret_code[3] = (0x80 | (chr & 0x3f)); 350 ret_code[2] = (0x80 | ((chr >> 6) & 0x3f)); 351 ret_code[1] = (0x80 | ((chr >> 12) & 0x3f)); 352 ret_code[0] = (0xf0 | ((chr >> 18) & 0x07)); 353 *ret_size = 4; 354 return; 355 } 356 357 if (chr <= 0x3ffffff) { 358 ret_code[4] = (0x80 | (chr & 0x3f)); 359 ret_code[3] = (0x80 | ((chr >> 6) & 0x3f)); 360 ret_code[2] = (0x80 | ((chr >> 12) & 0x3f)); 361 ret_code[1] = (0x80 | ((chr >> 18) & 0x3f)); 362 ret_code[0] = (0xf8 | ((chr >> 24) & 0x03)); 363 *ret_size = 5; 364 return; 365 } 366 367 ret_code[5] = (0x80 | (chr & 0x3f)); 368 ret_code[4] = (0x80 | ((chr >> 6) & 0x3f)); 369 ret_code[3] = (0x80 | ((chr >> 12) & 0x3f)); 370 ret_code[2] = (0x80 | ((chr >> 18) & 0x3f)); 371 ret_code[1] = (0x80 | ((chr >> 24) & 0x3f)); 372 ret_code[0] = (0xfc | ((chr >> 30) & 0x01)); 373 *ret_size = 6; 374 return; 375 } 376 377 //2ãã¤ãã®UTF-16ã³ã¼ããå¾ããã 378 WCHAR Utf8_to_Utf16(const char *src, int *code_size) 379 { 380 int i; 381 unsigned int uc = 0; 382 unsigned char len = 0; 383 384 len = 0; 385 if ((src[0] & 0x80) == 0) { uc = src[0] & 0x7F; len = 0; } 386 else if ((src[0] & 0xE0) == 0xC0) { uc = src[0] & 0x1F; len = 1; } 387 else if ((src[0] & 0xF0) == 0xE0) { uc = src[0] & 0x0F; len = 2; } 388 else if ((src[0] & 0xF8) == 0xF0) { uc = src[0] & 0x07; len = 3; } 389 else if ((src[0] & 0xFC) == 0xF8) { uc = src[0] & 0x03; len = 4; } 390 else if ((src[0] & 0xFE) == 0xFC) { uc = src[0] & 0x01; len = 5; } 391 392 i = 1; 393 while ((i <= len) && ((src[i] & 0xC0) == 0x80)) { 394 uc = (uc << 6) | (src[i] & 0x3F); 395 i++; 396 } 397 398 //æ¶è²»æåæ°è¨å® 399 *code_size = i; 400 401 //ç¾ç¶ã2ãã¤ãéå® 402 return uc; 403 } 316 404 317 405 #else … … 1712 1800 WCHAR w, *lfn; 1713 1801 #endif 1802 #if _CODE_PAGE == 65001 1803 unsigned char utf8_code[6]; 1804 int code_size; 1805 #endif 1714 1806 1715 1807 p = fno->fname; … … 1748 1840 while ((w = *lfn++) != 0) { /* Get an LFN character */ 1749 1841 #if !_LFN_UNICODE 1842 #if _CODE_PAGE == 65001 1843 Utf16_to_Utf8(utf8_code, &code_size, w); 1844 for (int j = 0; j < code_size - 1; j++) { 1845 p[i++] = utf8_code[j]; 1846 } 1847 w = utf8_code[code_size - 1]; 1848 #else 1750 1849 w = ff_convert(w, 0); /* Unicode -> OEM */ 1751 1850 if (!w) { i = 0; break; } /* No LFN if it could not be converted */ … … 1753 1852 p[i++] = (TCHAR)(w >> 8); 1754 1853 #endif 1854 #endif 1755 1855 if (i >= fno->lfsize - 1) { i = 0; break; } /* No LFN if buffer overflow */ 1756 1856 p[i++] = (TCHAR)w; … … 1778 1878 1779 1879 #if !_LFN_UNICODE 1880 #if _CODE_PAGE == 65001 1881 int code_size; 1882 chr = Utf8_to_Utf16(*ptr, &code_size); 1883 (*ptr) += code_size; 1884 #else 1780 1885 chr = (BYTE)*(*ptr)++; /* Get a byte */ 1781 1886 if (IsLower(chr)) chr -= 0x20; /* To upper ASCII char */ 1782 1887 if (IsDBCS1(chr) && IsDBCS2(**ptr)) /* Get DBC 2nd byte if needed */ 1783 1888 chr = chr << 8 | (BYTE)*(*ptr)++; 1889 #endif 1784 1890 #ifdef _EXCVT 1785 1891 if (chr >= 0x80) chr = ExCvt[chr - 0x80]; /* To upper SBCS extended char */ … … 1851 1957 UINT i, ni, si, di; 1852 1958 const TCHAR *p; 1853 1959 #if _CODE_PAGE == 65001 1960 char utf8_code[6]; 1961 int code_size; 1962 #endif 1854 1963 /* Create LFN in Unicode */ 1855 1964 for (p = *path; *p == '/' || *p == '\\'; p++) ; /* Strip duplicated separator */ … … 1862 1971 return FR_INVALID_NAME; 1863 1972 #if !_LFN_UNICODE 1973 #if _CODE_PAGE == 65001 1974 w = Utf8_to_Utf16(&p[si - 1], &code_size); 1975 si += code_size - 1; 1976 #else 1864 1977 w &= 0xFF; 1865 1978 if (IsDBCS1(w)) { /* Check if it is a DBC 1st byte (always false on SBCS cfg) */ … … 1871 1984 w = ff_convert(w, 1); /* Convert ANSI/OEM to Unicode */ 1872 1985 if (!w) return FR_INVALID_NAME; /* Reject invalid code */ 1986 #endif 1873 1987 #endif 1874 1988 if (w < 0x80 && chk_chr("\"*:<>\?|\x7F", w)) /* Reject illegal characters for LFN */ … … 1925 2039 if (w) w = ExCvt[w - 0x80]; /* Convert extended character to upper (SBCS) */ 1926 2040 #else 2041 #if _CODE_PAGE == 65001 2042 Utf16_to_Utf8(utf8_code, &code_size, ff_wtoupper(w)); 2043 #else 1927 2044 w = ff_convert(ff_wtoupper(w), 0); /* Upper converted Unicode -> OEM code */ 1928 2045 #endif 2046 #endif 1929 2047 cf |= NS_LFN; /* Force create LFN entry */ 1930 2048 } 1931 2049 #if _CODE_PAGE == 65001 2050 else 2051 code_size = 1; 2052 #endif 2053 2054 #if _CODE_PAGE == 65001 2055 if (code_size > 1) { /* Is this DBC? (always false at SBCS cfg) */ 2056 if (i >= ni - 1) { 2057 cf |= NS_LOSS | NS_LFN; i = ni; continue; 2058 } 2059 for (int j = 0; j < code_size; j++) { 2060 dp->fn[i++] = (BYTE)utf8_code[j]; 2061 } 2062 } 2063 else { /* SBC */ 2064 if (!w || chk_chr("+,;=[]", w)) { /* Replace illegal characters for SFN */ 2065 w = '_'; cf |= NS_LOSS | NS_LFN;/* Lossy conversion */ 2066 } 2067 else { 2068 if (IsUpper(w)) { /* ASCII large capital */ 2069 b |= 2; 2070 } 2071 else { 2072 if (IsLower(w)) { /* ASCII small capital */ 2073 b |= 1; w -= 0x20; 2074 } 2075 } 2076 } 2077 dp->fn[i++] = (BYTE)w; 2078 } 2079 #else 1932 2080 if (_DF1S && w >= 0x100) { /* Is this DBC? (always false at SBCS cfg) */ 1933 2081 if (i >= ni - 1) { … … 1949 2097 } 1950 2098 dp->fn[i++] = (BYTE)w; 2099 #endif 1951 2100 } 1952 2101 … … 3178 3327 } 3179 3328 3180 3329 FRESULT f_seek(FIL* fp, DWORD ofs, BYTE mode) 3330 { 3331 switch (mode) { 3332 case F_SEEK_SET: 3333 return f_lseek((fp), ofs); 3334 case F_SEEK_CUR: 3335 return f_lseek((fp), (fp)->fptr + ofs); 3336 case F_SEEK_END: 3337 return f_lseek((fp), (fp)->fsize - ofs); 3338 default: 3339 return FR_INVALID_PARAMETER; 3340 } 3341 } 3181 3342 3182 3343 #if _FS_MINIMIZE <= 1 … … 3719 3880 DWORD dw; 3720 3881 DEFINE_NAMEBUF; 3882 TCHAR *temp_new_path = 0; 3721 3883 3722 3884 … … 3742 3904 else 3743 3905 res = FR_INVALID_DRIVE; 3744 if (res == FR_OK) res = FR_EXIST; /* The new object name is already existing */ 3906 if (res == FR_OK) { 3907 res = FR_EXIST; /* The new object name is already existing */ 3908 dir = djn.dir; 3909 if (dir[DIR_Attr] & AM_DIR) { /* The new object is a directory */ 3910 temp_new_path = (TCHAR *)ff_memalloc((_MAX_LFN + 1) * sizeof(WCHAR)); 3911 snprintf(temp_new_path, _MAX_LFN, "%s/%s", path_new, basename((char *)path_old)); 3912 res = follow_path(&djn, temp_new_path); 3913 } 3914 } 3745 3915 if (res == FR_NO_FILE) { /* It is a valid path and no name collision */ 3746 3916 res = dir_register(&djn); /* Register the new entry */ … … 3777 3947 } 3778 3948 3949 if (temp_new_path != 0) ff_memfree(temp_new_path); 3950 3779 3951 LEAVE_FF(djo.fs, res); 3780 3952 } … … 3912 4084 WCHAR w; 3913 4085 DWORD tm; 3914 4086 #if _CODE_PAGE == 65001 4087 int code_size; 4088 char utf8_code[6]; 4089 #endif 3915 4090 3916 4091 /* Get logical drive number */ … … 3925 4100 i = j = 0; 3926 4101 do { 4102 #if _CODE_PAGE == 65001 4103 w = ff_wtoupper(Utf8_to_Utf16(&label[i], &code_size)); 4104 i += code_size; 4105 Utf16_to_Utf8(utf8_code, &code_size, w); 4106 if (!w || chk_chr("\"*+,.:;<=>\?[]|\x7F", w) || j >= sizeof(vn) - code_size) /* Reject invalid characters for volume label */ 4107 LEAVE_FF(dj.fs, FR_INVALID_NAME); 4108 for (int k = 0; k < code_size; k++) 4109 vn[j++] = utf8_code[k]; 4110 #else 3927 4111 #if _USE_LFN && _LFN_UNICODE 3928 4112 w = ff_convert(ff_wtoupper(label[i++]), 0); … … 3946 4130 if (w >= 0x100) vn[j++] = (BYTE)(w >> 8); 3947 4131 vn[j++] = (BYTE)w; 4132 #endif 3948 4133 } while (i < sl); 3949 4134 while (j < 11) vn[j++] = ' '; /* Fill remaining name field */ -
EcnlProtoTool/trunk/ntshell/fatfs/ff.h
r278 r279 143 143 /* Directory object structure (DIR) */ 144 144 145 typedef struct {145 typedef struct __dirstream { 146 146 FATFS* fs; /* Pointer to the owner file system object (**do not change order**) */ 147 147 WORD id; /* Owner file system mount ID (**do not change order**) */ … … 162 162 const TCHAR* pat; /* Pointer to the name matching pattern */ 163 163 #endif 164 struct dirent *dirent; 164 165 } DIR; 165 166 … … 252 253 #define f_rewind(fp) f_lseek((fp), 0) 253 254 #define f_rewinddir(dp) f_readdir((dp), 0) 254 #define f_flush(fp) 255 #define f_flush(fp) (FR_OK) 255 256 256 257 #define F_SEEK_SET 1 257 258 #define F_SEEK_CUR 2 258 259 #define F_SEEK_END 3 259 static FRESULT f_seek(FIL* fp, DWORD ofs, BYTE mode) 260 { 261 switch (mode) { 262 case F_SEEK_SET: 263 return f_lseek((fp), ofs); 264 case F_SEEK_CUR: 265 return f_lseek((fp), (fp)->fptr + ofs); 266 case F_SEEK_END: 267 return f_lseek((fp), (fp)->fsize - ofs); 268 default: 269 return FR_INVALID_PARAMETER; 270 } 271 } 260 FRESULT f_seek(FIL* fp, DWORD ofs, BYTE mode); 272 261 273 262 #ifndef EOF -
EcnlProtoTool/trunk/ntshell/fatfs/ffarch.c
r278 r279 56 56 #include <kernel.h> 57 57 #include <stdlib.h> 58 #include <errno.h>59 #include <sys/types.h>60 58 #include <string.h> 61 59 #include "t_stdlib.h" 60 #include "syssvc/serial.h" 62 61 #include "syssvc/syslog.h" 63 62 #include "kernel_cfg.h" … … 65 64 #include "sdfs.h" 66 65 #include "ff.h" 66 #include "tlsf.h" 67 #include "ntstdio.h" 68 69 #define SIO_PORTID 1 70 extern ntstdio_t ntstdio; 71 72 static tlsf_t sys_tlsf; 73 static pool_t sys_pool; 74 75 uint32_t __HeapBase; 76 uint32_t __HeapLimit; 77 FATFS RomDisk; 67 78 68 79 gpio_t ins; … … 70 81 #define WP() false 71 82 72 extern FATFS RomDisk; 73 extern unsigned char RamDisk[SZ_RAMDISK * 1024]; 74 83 typedef struct SD { 84 DSTATUS dst; 85 BYTE type; 86 FATFS FatFs; 87 } SD; 88 SD Sd; 89 90 void sys_init(void); 75 91 bool_t romdisk_init(); 92 bool_t SD_begin(); 76 93 77 94 int mruby_arduino_init() 78 95 { 79 96 int result = -1; 97 98 sys_init(); 80 99 81 100 /* SD_CD */ … … 85 104 sdfs_init(&sdfs, P8_5, P8_6, P8_3, P8_4, "sd"); 86 105 87 SD_begin(); 88 89 FIL fd; 90 UINT rlen = 0; 91 memset(&fd, 0, sizeof(fd)); 92 if (f_open(&fd, "1:/httpd-fs.bin", FA_OPEN_EXISTING | FA_READ) == FR_OK) { 93 f_read(&fd, RamDisk, SZ_RAMDISK * 1024, &rlen); 94 f_close(&fd); 95 if (romdisk_init()) 96 result = 0; 97 } 98 106 result = SD_begin() ? 0 : -1; 99 107 if (result == 0) { 100 syslog(LOG_NOTICE, "ramdisk ok!");108 ntstdio_printf(&ntstdio, "SD card (1:) OK!\n"); 101 109 } 102 110 else { 103 syslog(LOG_NOTICE, "ramdisk ng!"); 104 } 105 106 arduino_init(); 111 ntstdio_printf(&ntstdio, "SD card (1:) NG!\n"); 112 } 113 sta_cyc(SDFS_CYC); 114 115 if (romdisk_init()) 116 result = 0; 117 118 if (result == 0) { 119 ntstdio_printf(&ntstdio, "ROM disk (0:) OK!\n"); 120 } 121 else { 122 ntstdio_printf(&ntstdio, "ROM disk (0:) NG!\n"); 123 } 124 125 /* uploadãã£ã¬ã¯ããªãä½æãã¦ãã */ 126 f_mkdir("1:/upload"); 127 128 serial_ctl_por(SIO_PORTID, IOCTL_FCSND | IOCTL_FCRCV); 107 129 108 130 return result; 131 } 132 133 void sys_init(void) 134 { 135 sys_tlsf = tlsf_create(&__HeapBase); 136 if (sys_tlsf == NULL) 137 return; 138 139 sys_pool = tlsf_add_pool(sys_tlsf, ((uint8_t *)&__HeapBase) + tlsf_size(), ((size_t)&__HeapLimit - (size_t)&__HeapBase) - tlsf_size()); 140 } 141 142 void sys_fini(void) 143 { 144 tlsf_destroy(sys_tlsf); 145 } 146 147 void *sys_malloc(size_t size) 148 { 149 return tlsf_malloc(sys_tlsf, size); 150 } 151 152 void *sys_calloc(size_t size, size_t count) 153 { 154 void *result = tlsf_malloc(sys_tlsf, count * size); 155 memset(result, 0, count * size); 156 return result; 157 } 158 159 void *sys_realloc(void *ptr, size_t size) 160 { 161 return tlsf_realloc(sys_tlsf, ptr, size); 162 } 163 164 void sys_free(void *ptr) 165 { 166 tlsf_free(sys_tlsf, ptr); 109 167 } 110 168 … … 122 180 123 181 if ((res = f_mount(&RomDisk, "0:", 1)) != FR_OK) { 182 return false; 183 } 184 185 return true; 186 } 187 188 bool_t SD_begin() 189 { 190 DSTATUS dst; 191 FRESULT res; 192 BYTE pdrv = 1, type; 193 194 if (Sd.FatFs.fs_type != 0) 195 return true; 196 197 if ((dst = disk_initialize(pdrv)) != RES_OK) { 198 return false; 199 } 200 201 if ((dst = disk_ioctl(pdrv, MMC_GET_TYPE, &type)) != RES_OK) { 202 Sd.dst = dst; 203 Sd.type = 0; 204 } 205 else { 206 Sd.dst = RES_OK; 207 Sd.type = type; 208 } 209 210 if ((res = f_mount(&Sd.FatFs, "1:", 1)) != FR_OK) { 124 211 return false; 125 212 } … … 207 294 } 208 295 209 static int lock[TNUM_TSKID]; 210 static int stack_pos[TNUM_TSKID]; 211 212 void __malloc_lock(struct _reent *a) 213 { 214 ID tskid; 296 int ff_cre_syncobj(BYTE vol, _SYNC_t* sobj) 297 { 298 return 1; 299 } 300 301 int ff_req_grant(_SYNC_t sobj) 302 { 215 303 ER ret; 216 int count, sp; 217 218 ret = get_tid(&tskid); 219 if (ret != E_OK) { 220 /*syslog(LOG_DEBUG, "get_tid %s", itron_strerror(ret));*/ 221 Asm("bkpt #0"); 222 } 223 224 Asm("mov %0, sp" : "=r"(sp) :); 225 if ((stack_pos[tskid - 1] == 0) || (stack_pos[tskid - 1] < sp)) 226 stack_pos[tskid - 1] = sp; 227 228 count = ++lock[tskid - 1]; 229 if (count != 1) 230 return; 231 232 ret = wai_sem(SEM_MALLOC); 233 if (ret != E_OK) { 234 /*syslog(LOG_DEBUG, "wai_sem %s", itron_strerror(ret));*/ 235 Asm("bkpt #0"); 236 } 237 } 238 239 void __malloc_unlock(struct _reent *a) 240 { 241 ID tskid; 242 ER ret; 243 int count; 244 245 ret = get_tid(&tskid); 246 if (ret != E_OK) { 247 /*syslog(LOG_DEBUG, "get_tid %s", itron_strerror(ret));*/ 248 Asm("bkpt #0"); 249 } 250 251 count = --lock[tskid - 1]; 252 if(count != 0) 253 return; 254 255 ret = sig_sem(SEM_MALLOC); 256 if (ret != E_OK) { 257 /*syslog(LOG_DEBUG, "sig_sem %s", itron_strerror(ret));*/ 258 Asm("bkpt #0"); 259 } 260 } 261 262 // Provide implementation of _sbrk (low-level dynamic memory allocation 263 // routine) for GCC_ARM which compares new heap pointer with MSP instead of 264 // SP. This make it compatible with RTX RTOS thread stacks. 265 266 // Linker defined symbol used by _sbrk to indicate where heap should start. 267 int __end__; 268 uint32_t __HeapLimit; 269 270 // Turn off the errno macro and use actual global variable instead. 271 #undef errno 272 int errno; 273 274 static unsigned char* heap = (unsigned char*)&__end__; 275 276 // Dynamic memory allocation related syscall. 277 caddr_t _sbrk(int incr) { 278 unsigned char* prev_heap = heap; 279 unsigned char* new_heap = heap + incr; 280 281 if (new_heap >= (unsigned char*)&__HeapLimit) { /* __HeapLimit is end of heap section */ 282 errno = ENOMEM; 283 return (caddr_t)-1; 284 } 285 286 heap = new_heap; 287 return (caddr_t) prev_heap; 288 } 289 290 void reset_heap() 291 { 292 // .data 293 extern uint8_t __malloc_av_[0x408]; 294 extern uint8_t __malloc_sbrk_base[0x4]; 295 extern uint8_t __malloc_trim_threshold[0x4]; 296 // .bss 297 extern uint8_t __malloc_top_pad[0x4]; 298 extern uint8_t __malloc_current_mallinfo[0x28]; 299 extern uint8_t __malloc_max_sbrked_mem[0x4]; 300 extern uint8_t __malloc_max_total_mem[0x4]; 301 // 302 extern void *__etext; 303 extern void *__data_start__; 304 305 int offset = (int)&__etext - (int)&__data_start__; 306 307 __malloc_lock(_REENT); 308 309 memcpy(__malloc_av_, &__malloc_av_[offset], sizeof(__malloc_av_)); 310 memcpy(__malloc_sbrk_base, &__malloc_sbrk_base[offset], sizeof(__malloc_sbrk_base)); 311 memcpy(__malloc_trim_threshold, &__malloc_trim_threshold[offset], sizeof(__malloc_trim_threshold)); 312 313 memset(__malloc_top_pad, 0, sizeof(__malloc_top_pad)); 314 memset(__malloc_current_mallinfo, 0, sizeof(__malloc_current_mallinfo)); 315 memset(__malloc_max_sbrked_mem, 0, sizeof(__malloc_max_sbrked_mem)); 316 memset(__malloc_max_total_mem, 0, sizeof(__malloc_max_total_mem)); 317 318 heap = (unsigned char*)&__end__; 319 320 __malloc_unlock(_REENT); 321 } 322 323 void exit(int return_code) { 324 Asm("bkpt #0"); 325 reset_heap(); 326 ext_tsk(); 327 for(;;); 328 } 304 ret = wai_sem(SEM_FILESYSTEM); 305 return ret == E_OK; 306 } 307 308 void ff_rel_grant(_SYNC_t sobj) 309 { 310 sig_sem(SEM_FILESYSTEM); 311 } 312 313 int ff_del_syncobj(_SYNC_t sobj) 314 { 315 return 1; 316 } 317 318 void* ff_memalloc (UINT msize) 319 { 320 return sys_malloc(msize); 321 } 322 323 void ff_memfree (void* mblock) 324 { 325 sys_free(mblock); 326 } -
EcnlProtoTool/trunk/ntshell/fatfs/ffarch.cfg
r278 r279 51 51 */ 52 52 53 #include " mruby_arduino.h"53 #include "ffarch.h" 54 54 55 CRE_CYC(SDFS_CYC, { TA_NULL, { TNFY_HANDLER, 0, sdfs_cychdr }, 1000 , 0 });55 CRE_CYC(SDFS_CYC, { TA_NULL, { TNFY_HANDLER, 0, sdfs_cychdr }, 1000000, 0 }); 56 56 57 57 CRE_SEM(SEM_MALLOC, { TA_TPRI, 1, 1 }); -
EcnlProtoTool/trunk/ntshell/fatfs/ffarch.h
r278 r279 54 54 55 55 int mruby_arduino_init(); 56 void reset_heap();57 56 void sdfs_cychdr(intptr_t exinf); 58 57 -
EcnlProtoTool/trunk/ntshell/fatfs/ffconf.h
r278 r279 62 62 /---------------------------------------------------------------------------*/ 63 63 64 #define _CODE_PAGE 43764 #define _CODE_PAGE 65001 65 65 /* This option specifies the OEM code page to be used on the target system. 66 66 / Incorrect setting of the code page can cause a file open failure. … … 91 91 92 92 93 #define _USE_LFN 193 #define _USE_LFN 3 94 94 #define _MAX_LFN 255 95 95 /* The _USE_LFN option switches the LFN feature. … … 227 227 228 228 229 #define _FS_REENTRANT 0229 #define _FS_REENTRANT 1 230 230 #define _FS_TIMEOUT 1000 231 #define _SYNC_t HANDLE231 #define _SYNC_t unsigned int 232 232 /* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs 233 233 / module itself. Note that regardless of this option, file access to different -
EcnlProtoTool/trunk/ntshell/webserver/httpd-fs.c
r270 r279 60 60 #include "kernel_cfg.h" 61 61 #include "syssvc/syslog.h" 62 #include " arduino.h"62 #include "ntstdio.h" 63 63 64 64 #ifndef _MSC_VER … … 96 96 fn = fno.fname; 97 97 if (fno.fattrib & AM_DIR) { 98 sprintf(&path[i], "0:/%s", fn);98 ntstdio_sprintf(&path[i], "0:/%s", fn); 99 99 res = scan_files(path, size); 100 100 if (res != FR_OK) break; … … 112 112 /*-----------------------------------------------------------------------------------*/ 113 113 int 114 httpd_fs_open _ul(char *name, int len, struct httpd_fs_file *file)114 httpd_fs_open(char *name, int len, struct httpd_fs_file *file) 115 115 { 116 116 FRESULT res; … … 157 157 } 158 158 159 int 160 httpd_fs_open(char *name, int len, struct httpd_fs_file *file) 161 { 162 int result; 163 164 wai_sem(SEM_FILESYSTEM); 165 166 result = httpd_fs_open_ul(name, len, file); 167 168 sig_sem(SEM_FILESYSTEM); 169 170 return result; 171 } 172 /*-----------------------------------------------------------------------------------*/ 173 int 174 httpd_fs_create_ul(char *name, struct httpd_fs_file *file) 159 /*-----------------------------------------------------------------------------------*/ 160 int 161 httpd_fs_create(char *name, struct httpd_fs_file *file) 175 162 { 176 163 FRESULT res; … … 196 183 } 197 184 198 int 199 httpd_fs_create(char *name, struct httpd_fs_file *file) 200 { 201 int result; 202 203 wai_sem(SEM_FILESYSTEM); 204 205 result = httpd_fs_create_ul(name, file); 206 207 sig_sem(SEM_FILESYSTEM); 208 209 return result; 210 } 211 /*-----------------------------------------------------------------------------------*/ 212 int 213 httpd_fs_read_ul(struct httpd_fs_file *file, void *dst, int len) 185 /*-----------------------------------------------------------------------------------*/ 186 int 187 httpd_fs_read(struct httpd_fs_file *file, void *dst, int len) 214 188 { 215 189 FRESULT ret; … … 236 210 } 237 211 238 int 239 httpd_fs_read(struct httpd_fs_file *file, void *dst, int len) 240 { 241 int result; 242 243 wai_sem(SEM_FILESYSTEM); 244 245 result = httpd_fs_read_ul(file, dst, len); 246 247 sig_sem(SEM_FILESYSTEM); 248 249 return result; 250 } 251 /*-----------------------------------------------------------------------------------*/ 252 int 253 httpd_fs_write_ul(struct httpd_fs_file *file, const void *src, int len) 212 /*-----------------------------------------------------------------------------------*/ 213 int 214 httpd_fs_write(struct httpd_fs_file *file, const void *src, int len) 254 215 { 255 216 FRESULT ret; … … 279 240 } 280 241 281 int 282 httpd_fs_write(struct httpd_fs_file *file, const void *src, int len) 283 { 284 int result; 285 286 wai_sem(SEM_FILESYSTEM); 287 288 result = httpd_fs_write_ul(file, src, len); 289 290 sig_sem(SEM_FILESYSTEM); 291 292 return result; 293 } 294 /*-----------------------------------------------------------------------------------*/ 295 int httpd_fs_close_ul(struct httpd_fs_file *file) 242 /*-----------------------------------------------------------------------------------*/ 243 int httpd_fs_close(struct httpd_fs_file *file) 296 244 { 297 245 FRESULT ret; … … 307 255 return 1; 308 256 } 309 310 int httpd_fs_close(struct httpd_fs_file *file)311 {312 int result;313 314 wai_sem(SEM_FILESYSTEM);315 316 result = httpd_fs_close_ul(file);317 318 sig_sem(SEM_FILESYSTEM);319 320 return result;321 } -
EcnlProtoTool/trunk/ntshell/webserver/httpd-fs.h
r270 r279 4 4 * Copyright (C) 2017 Cores Co., Ltd. Japan 5 5 * 6 * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF 7 * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü 8 * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD 9 * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì 10 * \¦C±Ìpð¨æѺL̳ÛØKèªC»ÌÜÜÌ`Å\[ 11 * XR[hÉÜÜêÄ¢é±ÆD 12 * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg 13 * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL 14 gip 15 * Ò}j 16 AÈÇjÉCãLÌì \¦C±Ìpð¨æѺL 17 * ̳ÛØKèðfÚ·é±ÆD 18 * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg 19 * pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·± 20 * ÆD 21 * (a) Äzzɺ¤hL 22 gipÒ}j 23 AÈÇjÉCãLÌ 24 * ì \¦C±Ìpð¨æѺL̳ÛØKèðfÚ·é±ÆD 25 * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ 26 * ñ·é±ÆD 27 * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹ 28 * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD 29 * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé 30 * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð 31 * ÆÓ·é±ÆD 6 * ä¸è¨èä½æ¨©è 7 ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ 8 * ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹ 9 * å¤ã»åé 10 å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼ 11 * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½ 12 * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼ 13 * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼ 14 * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿ 15 * ç¨ã§ããå½¢ã§åé 16 å¸ããå ´åã«ã¯ï¼åé 17 å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨ 18 * è 19 ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ 20 * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼ 21 * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿ 22 * ç¨ã§ããªãå½¢ã§åé 23 å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã 24 * ã¨ï¼ 25 * (a) åé 26 å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è 27 ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è 28 * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼ 29 * (b) åé 30 å¸ã®å½¢æ 31 ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã« 32 * å ±åãããã¨ï¼ 33 * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ 34 * 害ãããï¼ä¸è¨èä½æ¨©è 35 ããã³TOPPERSããã¸ã§ã¯ããå 36 責ãããã¨ï¼ 37 * ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç 38 * ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è 39 ããã³TOPPERSããã¸ã§ã¯ãã 40 * å 41 責ãããã¨ï¼ 32 42 * 33 * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨ 34 * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI 35 * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF 36 * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC» 37 * ÌÓCðíÈ¢D 43 * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è 44 ã 45 * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç 46 * ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ 47 * ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã 48 * ã®è²¬ä»»ãè² ããªãï¼ 38 49 * 39 50 * @(#) $Id$ -
EcnlProtoTool/trunk/ntshell/webserver/httpd.c
r270 r279 54 54 #include <string.h> 55 55 #include <stdlib.h> 56 #include "kernel_cfg.h" 57 #include "tinet_cfg.h" 56 58 #include "syssvc/syslog.h" 57 59 #include "http-strings.h" 58 60 #include "netinet/in.h" 59 #include "arduino.h" 61 #include "netinet/in_var.h" 62 #include "httpd.h" 63 #include "httpd-fs.h" 64 #include "http-strings.h" 65 #include "base64.h" 66 #include "sha1.h" 67 #include "ntstdio.h" 60 68 61 69 #define TRUE 1 62 70 #define FALSE 0 71 72 extern ntstdio_t ntstdio; 73 SYSTIM httpd_time; 74 struct httpd_state *uploding; 75 extern char command[256]; 76 77 extern int execute_command(int wait); 78 79 /* TCP éåä¿¡ã¦ã£ã³ããããã¡ */ 80 uint8_t tcp_swbuf1[TCP_SWBUF_SIZE]; 81 uint8_t tcp_rwbuf1[TCP_RWBUF_SIZE]; 82 uint8_t tcp_swbuf2[TCP_SWBUF_SIZE]; 83 uint8_t tcp_rwbuf2[TCP_RWBUF_SIZE]; 84 85 #define ISO_nl 0x0a 86 #define ISO_space 0x20 87 #define ISO_bang 0x21 88 #define ISO_percent 0x25 89 #define ISO_period 0x2e 90 #define ISO_slash 0x2f 91 #define ISO_colon 0x3a 92 93 struct httpd_state httpd_state[2] = { 94 { HTTPD1_TASK, TCP_CEPID1 }, 95 { HTTPD2_TASK, TCP_CEPID2 }, 96 }; 63 97 64 98 #ifndef _MSC_VER … … 147 181 return ncpy; 148 182 } 149 150 extern struct httpd_state *uploding;151 183 152 184 int websvr_message_begin(http_parser *p) … … 306 338 ã¯SDã«ã¼ã 307 339 s->filename[0] = '1'; 308 syslog(LOG_NOTICE, "create: %s.%d %s", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);340 ntstdio_printf(&ntstdio, "create: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 309 341 if (!httpd_fs_create(s->filename, &s->file)) { 310 342 goto error; … … 314 346 } 315 347 else if (strcmp(s->filename, uploding->filename) == 0) { 316 syslog(LOG_NOTICE, "collision: %s.%d %s", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);348 ntstdio_printf(&ntstdio, "collision: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 317 349 goto error; 318 350 } … … 359 391 360 392 if (s->message.body_is_final) { 361 syslog(LOG_NOTICE, "close: %s.%d %s", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);393 ntstdio_printf(&ntstdio, "close: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 362 394 httpd_fs_close(&s->file); 363 395 memset(&s->file, 0, sizeof(s->file)); 364 396 365 strcpy_s(RubyFilename, sizeof(RubyFilename), s->filename); 397 strcpy_s(command, sizeof(command), "mruby -b "); 398 strcat_s(command, sizeof(command), s->filename); 366 399 s->reset = 1; 367 400 … … 413 446 websvr_message_complete, 414 447 }; 448 449 /* 450 * ãããã¯ã¼ã¯å±¤ã®é¸æ 451 */ 452 453 #ifdef SUPPORT_INET6 454 455 #define TCP_ACP_CEP(c,r,d,t) tcp6_acp_cep(c,r,d,t) 456 #define IP2STR(s,a) ipv62str(s,a) 457 458 #else /* of #ifdef SUPPORT_INET6 */ 459 460 #ifdef SUPPORT_INET4 461 462 #define TCP_ACP_CEP(c,r,d,t) tcp_acp_cep(c,r,d,t) 463 #define IP2STR(s,a) ip2str(s,a) 464 465 #endif /* of #ifdef SUPPORT_INET4 */ 466 467 #endif /* of #ifdef SUPPORT_INET6 */ 468 469 struct httpd_state *get_httpd(ID cepid) 470 { 471 for (int i = 0; i < 2; i++) { 472 if (httpd_state[i].cepid != cepid) 473 continue; 474 475 return &httpd_state[i]; 476 } 477 return NULL; 478 } 479 480 struct websocket *websocket_getws(ID wbsid) 481 { 482 for (int i = 0; i < 2; i++) { 483 if (httpd_state[i].websocket.wbsid != wbsid) 484 continue; 485 486 return &httpd_state[i].websocket; 487 } 488 return NULL; 489 } 490 491 void send_file(struct httpd_state *s) 492 { 493 char *buf; 494 int len, slen; 495 496 while (s->file.len > 0) { 497 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 498 if (slen < 0) { 499 syslog(LOG_ERROR, "send_file#tcp_get_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 500 s->state = STATE_CLOSING; 501 break; 502 } 503 if (slen == 0) 504 return; 505 506 len = s->file.len; 507 if (len > slen) 508 len = slen; 509 510 len = httpd_fs_read(&s->file, buf, len); 511 if (len <= 0) { 512 syslog(LOG_ERROR, "send_file#httpd_fs_read(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, len); 513 break; 514 } 515 516 s->file.len -= len; 517 s->file.pos += len; 518 519 if ((slen = tcp_snd_buf(s->cepid, len)) != E_OK) { 520 syslog(LOG_ERROR, "send_file#tcp_snd_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 521 s->state = STATE_CLOSING; 522 break; 523 } 524 } 525 526 ntstdio_printf(&ntstdio, "close: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 527 httpd_fs_close(&s->file); 528 s->file.len = 0; 529 s->file.pos = 0; 530 531 s->out.state = OUT_STATE_SEND_END; 532 } 533 534 void send_data(struct httpd_state *s) 535 { 536 char *buf; 537 int len, slen; 538 539 while (s->response_len > 0) { 540 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 541 if (slen < 0) { 542 syslog(LOG_ERROR, "send_data#tcp_get_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 543 s->state = STATE_CLOSING; 544 break; 545 } 546 if (slen == 0) 547 return; 548 549 len = s->response_len; 550 if (len > slen) 551 len = slen; 552 553 memcpy(buf, &s->response_body[s->response_pos], len); 554 555 s->response_len -= len; 556 s->response_pos += len; 557 558 if ((slen = tcp_snd_buf(s->cepid, len)) != E_OK) { 559 syslog(LOG_ERROR, "send_data#tcp_snd_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 560 s->state = STATE_CLOSING; 561 break; 562 } 563 } 564 565 s->response_body = NULL; 566 s->response_len = 0; 567 s->response_pos = 0; 568 569 s->out.state = OUT_STATE_SEND_END; 570 } 571 572 void send_headers(struct httpd_state *s, const char *statushdr) 573 { 574 int len; 575 char *ptr; 576 577 len = strlen(statushdr); 578 tcp_snd_dat(s->cepid, (void *)statushdr, len, TMO_FEVR); 579 580 if ((s->filename[0] == '0') && (s->file.len > 0)) { 581 len = sizeof(http_content_encoding_gzip) - 1; 582 tcp_snd_dat(s->cepid, (void *)http_content_encoding_gzip, len, TMO_FEVR); 583 } 584 585 if (s->file.redirect) { 586 len = sizeof(http_location) - 1; 587 tcp_snd_dat(s->cepid, (void *)http_location, len, TMO_FEVR); 588 if (s->filename[0] == '1') { 589 len = 2; 590 tcp_snd_dat(s->cepid, "/~", len, TMO_FEVR); 591 } 592 len = strlen(s->filename); 593 tcp_snd_dat(s->cepid, s->filename, len, TMO_FEVR); 594 if (s->query != NULL) { 595 tcp_snd_dat(s->cepid, "?", 1, TMO_FEVR); 596 len = strlen(s->query); 597 tcp_snd_dat(s->cepid, s->query, len, TMO_FEVR); 598 } 599 len = 2; 600 tcp_snd_dat(s->cepid, "\r", len, TMO_FEVR); 601 } 602 603 ptr = strrchr(s->filename, ISO_period); 604 if (ptr == NULL) { 605 len = sizeof(http_content_type_binary) - 1; 606 tcp_snd_dat(s->cepid, (void *)http_content_type_binary, len, TMO_FEVR); 607 } 608 else if (strncmp(http_html, ptr, sizeof(http_html) - 1) == 0 || 609 strncmp(http_htm, ptr, sizeof(http_htm) - 1) == 0) { 610 len = sizeof(http_content_type_html) - 1; 611 tcp_snd_dat(s->cepid, (void *)http_content_type_html, len, TMO_FEVR); 612 } 613 else if (strncmp(http_css, ptr, sizeof(http_css) - 1) == 0) { 614 len = sizeof(http_content_type_css) - 1; 615 tcp_snd_dat(s->cepid, (void *)http_content_type_css, len, TMO_FEVR); 616 } 617 else if (strncmp(http_js, ptr, sizeof(http_js) - 1) == 0) { 618 len = sizeof(http_content_type_js) - 1; 619 tcp_snd_dat(s->cepid, (void *)http_content_type_js, len, TMO_FEVR); 620 } 621 else if (strncmp(http_json, ptr, sizeof(http_json) - 1) == 0) { 622 len = sizeof(http_content_type_json) - 1; 623 tcp_snd_dat(s->cepid, (void *)http_content_type_json, len, TMO_FEVR); 624 } 625 else if (strncmp(http_png, ptr, sizeof(http_png) - 1) == 0) { 626 len = sizeof(http_content_type_png) - 1; 627 tcp_snd_dat(s->cepid, (void *)http_content_type_png, len, TMO_FEVR); 628 } 629 else if (strncmp(http_gif, ptr, sizeof(http_gif) - 1) == 0) { 630 len = sizeof(http_content_type_gif) - 1; 631 tcp_snd_dat(s->cepid, (void *)http_content_type_gif, len, TMO_FEVR); 632 } 633 else if (strncmp(http_jpg, ptr, sizeof(http_jpg) - 1) == 0) { 634 len = sizeof(http_content_type_jpg) - 1; 635 tcp_snd_dat(s->cepid, (void *)http_content_type_jpg, len, TMO_FEVR); 636 } 637 else if (strncmp(http_svg, ptr, sizeof(http_svg) - 1) == 0) { 638 len = sizeof(http_content_type_svg) - 1; 639 tcp_snd_dat(s->cepid, (void *)http_content_type_svg, len, TMO_FEVR); 640 } 641 else if (strncmp(http_text, ptr, sizeof(http_text) - 1) == 0) { 642 len = sizeof(http_content_type_text) - 1; 643 tcp_snd_dat(s->cepid, (void *)http_content_type_text, len, TMO_FEVR); 644 } 645 else if (strncmp(http_eot, ptr, sizeof(http_eot) - 1) == 0) { 646 len = sizeof(http_content_type_eot) - 1; 647 tcp_snd_dat(s->cepid, (void *)http_content_type_eot, len, TMO_FEVR); 648 } 649 else if (strncmp(http_ttf, ptr, sizeof(http_ttf) - 1) == 0) { 650 len = sizeof(http_content_type_ttf) - 1; 651 tcp_snd_dat(s->cepid, (void *)http_content_type_ttf, len, TMO_FEVR); 652 } 653 else if (strncmp(http_woff, ptr, sizeof(http_woff) - 1) == 0) { 654 len = sizeof(http_content_type_woff) - 1; 655 tcp_snd_dat(s->cepid, (void *)http_content_type_woff, len, TMO_FEVR); 656 } 657 else if (strncmp(http_woff2, ptr, sizeof(http_woff2) - 1) == 0) { 658 len = sizeof(http_content_type_woff2) - 1; 659 tcp_snd_dat(s->cepid, (void *)http_content_type_woff2, len, TMO_FEVR); 660 } 661 else if (strncmp(http_ico, ptr, sizeof(http_ico) - 1) == 0) { 662 len = sizeof(http_content_type_ico) - 1; 663 tcp_snd_dat(s->cepid, (void *)http_content_type_ico, len, TMO_FEVR); 664 } 665 else { 666 len = sizeof(http_content_type_plain) - 1; 667 tcp_snd_dat(s->cepid, (void *)http_content_type_plain, len, TMO_FEVR); 668 } 669 670 if (s->file.len > 0) { 671 len = sizeof(http_content_length) - 1; 672 tcp_snd_dat(s->cepid, (void *)http_content_length, len, TMO_FEVR); 673 ntstdio_snprintf(s->temp, sizeof(s->temp), "%d\r\n", s->file.len); 674 tcp_snd_dat(s->cepid, (void *)s->temp, strlen(s->temp), TMO_FEVR); 675 } 676 677 if (s->message.should_keep_alive && s->reset == 0) { 678 len = sizeof(http_connection_keep_alive) - 1; 679 tcp_snd_dat(s->cepid, (void *)http_connection_keep_alive, len, TMO_FEVR); 680 } 681 else { 682 len = sizeof(http_connection_close) - 1; 683 tcp_snd_dat(s->cepid, (void *)http_connection_close, len, TMO_FEVR); 684 } 685 686 tcp_snd_dat(s->cepid, (void *)http_crnl, 2, TMO_FEVR); 687 688 if (s->filename != NULL) { 689 s->out.state = OUT_STATE_SEND_FILE; 690 } 691 else { 692 s->out.state = OUT_STATE_SEND_DATA; 693 } 694 } 695 696 void handle_output(struct httpd_state *s) 697 { 698 s->out.wait = false; 699 700 switch (s->out.state) { 701 case OUT_STATE_WAIT_REQUEST: 702 s->out.wait = true; 703 break; 704 case OUT_STATE_OPEN_GET_FILE: 705 ntstdio_printf(&ntstdio, "open: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 706 if (!httpd_fs_open(s->filename, sizeof(s->message.request_url), &s->file)) { 707 s->filename = NULL; 708 s->response_body = http_content_404; 709 s->response_pos = 0; 710 s->response_len = sizeof(http_content_403) - 1; 711 s->out.statushdr = http_header_404; 712 } 713 else { 714 s->out.statushdr = s->file.redirect ? http_header_301 : http_header_200; 715 } 716 s->out.state = OUT_STATE_SEND_HEADER; 717 break; 718 case OUT_STATE_WAIT_POST_BODY: 719 s->out.wait = true; 720 break; 721 case OUT_STATE_BODY_RECEIVED: 722 s->out.statushdr = http_header_200; 723 s->out.state = OUT_STATE_SEND_HEADER; 724 break; 725 case OUT_STATE_SEND_HEADER: 726 send_headers(s, s->out.statushdr); 727 break; 728 case OUT_STATE_SEND_FILE: 729 send_file(s); 730 break; 731 case OUT_STATE_SEND_DATA: 732 send_data(s); 733 break; 734 case OUT_STATE_SEND_END: 735 s->out.wait = true; 736 if (s->message.should_keep_alive && s->reset == 0) { 737 s->out.state = OUT_STATE_WAIT_REQUEST; 738 } 739 else { 740 s->state = STATE_CLOSING; 741 } 742 break; 743 } 744 } 745 746 void send_ws_headers(struct httpd_state *s, const char *statushdr) 747 { 748 int len; 749 750 len = strlen(statushdr); 751 tcp_snd_dat(s->cepid, (void *)statushdr, len, TMO_FEVR); 752 753 len = sizeof(http_upgrade) - 1; 754 tcp_snd_dat(s->cepid, (void *)http_upgrade, len, TMO_FEVR); 755 len = strlen(s->message.upgrade); 756 tcp_snd_dat(s->cepid, s->message.upgrade, len, TMO_FEVR); 757 len = sizeof(http_crnl) - 1; 758 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 759 760 len = sizeof(http_connection) - 1; 761 tcp_snd_dat(s->cepid, (void *)http_connection, len, TMO_FEVR); 762 len = strlen(s->message.connection); 763 tcp_snd_dat(s->cepid, s->message.connection, len, TMO_FEVR); 764 len = sizeof(http_crnl) - 1; 765 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 766 767 len = sizeof(http_sec_websocket_accept) - 1; 768 tcp_snd_dat(s->cepid, (void *)http_sec_websocket_accept, len, TMO_FEVR); 769 len = strlen(s->message.response_key); 770 tcp_snd_dat(s->cepid, s->message.response_key, len, TMO_FEVR); 771 len = sizeof(http_crnl) - 1; 772 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 773 774 len = sizeof(http_sec_websocket_protocol) - 1; 775 tcp_snd_dat(s->cepid, (void *)http_sec_websocket_protocol, len, TMO_FEVR); 776 len = strlen(s->message.sec_websocket_protocol); 777 tcp_snd_dat(s->cepid, s->message.sec_websocket_protocol, len, TMO_FEVR); 778 len = sizeof(http_crnl) - 1; 779 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 780 781 len = sizeof(http_crnl) - 1; 782 tcp_snd_dat(s->cepid, (void *)http_crnl, len, TMO_FEVR); 783 } 784 785 void send_ws_data(struct httpd_state *s) 786 { 787 char *buf; 788 int slen; 789 790 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 791 if (slen < 0) { 792 syslog(LOG_ERROR, "send_ws_data#tcp_get_buf(%s.%d) => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 793 return; 794 } 795 796 websocket_output(&s->websocket, buf, slen); 797 } 798 799 void handle_ws_output(struct httpd_state *s) 800 { 801 char shaHash[20]; 802 SHA_CTX sha1; 803 int len; 804 805 strlncat(s->message.response_key, sizeof(s->message.response_key), 806 s->message.sec_websocket_key, sizeof(s->message.sec_websocket_key)); 807 len = strlncat(s->message.response_key, sizeof(s->message.response_key), 808 http_websocket_guid, sizeof(http_websocket_guid)); 809 memset(shaHash, 0, sizeof(shaHash)); 810 SHA1_Init(&sha1); 811 SHA1_Update(&sha1, (sha1_byte *)s->message.response_key, len); 812 SHA1_Final((sha1_byte *)shaHash, &sha1); 813 base64_encode((unsigned char *)s->message.response_key, 814 sizeof(s->message.response_key), (unsigned char *)shaHash, sizeof(shaHash)); 815 816 send_ws_headers(s, http_header_101); 817 818 s->message.response_key[0] = '\0'; 819 820 do { 821 while (!websocket_newdata(&s->websocket)) 822 slp_tsk(); 823 824 send_ws_data(s); 825 } while ((s->state == STATE_CONNECTED) && (!s->close_req)); 826 s->state = STATE_DISCONNECTED; 827 websocket_destroy(&s->websocket); 828 s->close_req = 0; 829 830 s->state = STATE_CLOSING; 831 } 832 833 void handle_input(struct httpd_state *s) 834 { 835 size_t done; 836 int len; 837 838 s->in.wait = false; 839 840 switch (s->in.state) { 841 case IN_STATE_START: 842 http_parser_init(&s->parser, HTTP_REQUEST); 843 s->in.state = IN_STATE_REQUEST; 844 break; 845 case IN_STATE_REQUEST: 846 case IN_STATE_RESPONSE: 847 case IN_STATE_UPLOAD: 848 if ((len = tcp_rcv_buf(s->cepid, (void **)&s->in.data, TMO_POL)) <= 0) { 849 if ((len == E_TMOUT) || (len == 0)) { 850 // 3ç§ã¯å¾ 851 㤠852 //if (httpd_time - s->in.timer < 30000000) { 853 s->in.wait = true; 854 break; 855 //} 856 } 857 syslog(LOG_ERROR, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len); 858 uploding = NULL; 859 s->state = STATE_CLOSING; 860 return; 861 } 862 done = http_parser_execute(&s->parser, &websvr_settings, s->in.data, len); 863 tcp_rel_buf(s->cepid, done); 864 if (s->parser.http_errno != HPE_OK) { 865 syslog(LOG_ERROR, "http_parser error %s.%d => %d", s->addr, ((T_IPV4EP *)s->dst)->portno, s->parser.http_errno); 866 uploding = NULL; 867 s->state = STATE_CLOSING; 868 return; 869 } 870 871 s->parse_pos = done; 872 s->parse_len = len - done; 873 break; 874 case IN_STATE_UPLOAD_WAIT: 875 if (uploding != NULL) { 876 s->in.wait = true; 877 } 878 else { 879 uploding = s; 880 s->in.state = IN_STATE_UPLOAD; 881 } 882 break; 883 case IN_STATE_WEBSOCKET: 884 if (s->parse_len <= 0) { 885 if ((len = tcp_rcv_buf(s->cepid, (void **)&s->in.data, TMO_POL)) <= 0) { 886 if ((len == E_TMOUT) || (len == 0)) { 887 s->in.wait = true; 888 break; 889 } 890 syslog(LOG_ERROR, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len); 891 s->state = STATE_CLOSING; 892 break; 893 } 894 895 s->parse_pos = 0; 896 s->parse_len = len; 897 } 898 else 899 len = s->parse_len; 900 done = websocket_input(&s->websocket, (void *)s->in.data, s->parse_len); 901 tcp_rel_buf(s->cepid, done); 902 if ((done != 0) || (s->websocket.rstate.opecode == connection_close)) { 903 s->close_req = 1; 904 s->state = STATE_CLOSING; 905 break; 906 } 907 s->parse_pos = done; 908 s->parse_len -= done; 909 break; 910 case IN_STATE_END: 911 s->in.wait = true; 912 break; 913 default: 914 s->state = STATE_CLOSING; 915 break; 916 } 917 } 918 919 /* 920 * ãã³ããããã³ã°ã³ã¼ã«ã®ã³ã¼ã«ããã¯é¢æ° 921 */ 922 ER 923 callback_nblk_tcp(ID cepid, FN fncd, void *p_parblk) 924 { 925 struct httpd_state *s = get_httpd(cepid); 926 927 if (s == NULL) 928 ntstdio_printf(&ntstdio, "callback_nblk_tcp(%d, %d)\n", fncd, cepid); 929 else 930 ntstdio_printf(&ntstdio, "callback_nblk_tcp(%d, %s.%d)\n", fncd, s->addr, ((T_IPV4EP *)s->dst)->portno); 931 932 return E_PAR; 933 } 934 935 /* 936 * HTTPãµã¼ãã¼ã¿ã¹ã¯ 937 */ 938 void httpd_task(intptr_t exinf) 939 { 940 ER ret, ret2; 941 struct httpd_state *s = &httpd_state[exinf]; 942 943 for (;;) { 944 ret2 = get_tim(&httpd_time); 945 if (ret2 != E_OK) { 946 syslog(LOG_ERROR, "get_tim"); 947 return; 948 } 949 950 switch (s->state) { 951 case STATE_DISCONNECTED: 952 memset(&s->dst, 0, sizeof(s->dst)); 953 if ((ret = TCP_ACP_CEP(s->cepid, TCP_REPID, (T_IPV4EP *)s->dst, TMO_FEVR)) != E_OK) { 954 syslog(LOG_ERROR, "tcp_acp_cep(%d) => %d", s->cepid, ret); 955 tslp_tsk(100); // TODO 956 s->state = STATE_CLOSING; 957 break; 958 } 959 IP2STR(s->addr, &((T_IPV4EP *)s->dst)->ipaddr); 960 ntstdio_printf(&ntstdio, "connected: %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno); 961 memset(&s->in, 0, sizeof(s->in)); 962 memset(&s->out, 0, sizeof(s->out)); 963 s->in.timer = httpd_time; 964 s->state = STATE_CONNECTED; 965 break; 966 case STATE_CONNECTED: 967 handle_input(s); 968 handle_output(s); 969 break; 970 case STATE_WEBSOCKET: 971 handle_input(s); 972 handle_ws_output(s); 973 break; 974 case STATE_CLOSING: 975 ntstdio_printf(&ntstdio, "close: %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno); 976 tcp_sht_cep(s->cepid); 977 tcp_cls_cep(s->cepid, TMO_FEVR); 978 979 if (s->reset) { 980 s->reset = 0; 981 s->state = STATE_RESET; 982 } 983 else { 984 s->state = STATE_DISCONNECTED; 985 } 986 break; 987 case STATE_RESET: 988 execute_command(0); 989 s->state = STATE_DISCONNECTED; 990 break; 991 } 992 993 if (s->in.wait && s->out.wait) { 994 tslp_tsk(100); 995 } 996 } 997 } -
EcnlProtoTool/trunk/ntshell/webserver/httpd.h
r270 r279 4 4 * Copyright (C) 2017 Cores Co., Ltd. Japan 5 5 * 6 * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF 7 * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü 8 * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD 9 * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì 10 * \¦C±Ìpð¨æѺL̳ÛØKèªC»ÌÜÜÌ`Å\[ 11 * XR[hÉÜÜêÄ¢é±ÆD 12 * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg 13 * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL 14 gip 15 * Ò}j 16 AÈÇjÉCãLÌì \¦C±Ìpð¨æѺL 17 * ̳ÛØKèðfÚ·é±ÆD 18 * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg 19 * pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·± 20 * ÆD 21 * (a) Äzzɺ¤hL 22 gipÒ}j 23 AÈÇjÉCãLÌ 24 * ì \¦C±Ìpð¨æѺL̳ÛØKèðfÚ·é±ÆD 25 * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ 26 * ñ·é±ÆD 27 * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹ 28 * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD 29 * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé 30 * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð 31 * ÆÓ·é±ÆD 32 * 33 * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨ 34 * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI 35 * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF 36 * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC» 37 * ÌÓCðíÈ¢D 6 * ä¸è¨èä½æ¨©è 7 ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ 8 * ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹ 9 * å¤ã»åé 10 å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼ 11 * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½ 12 * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼ 13 * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼ 14 * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿ 15 * ç¨ã§ããå½¢ã§åé 16 å¸ããå ´åã«ã¯ï¼åé 17 å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨ 18 * è 19 ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ 20 * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼ 21 * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿ 22 * ç¨ã§ããªãå½¢ã§åé 23 å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã 24 * ã¨ï¼ 25 * (a) åé 26 å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è 27 ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è 28 * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼ 29 * (b) åé 30 å¸ã®å½¢æ 31 ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã« 32 * å ±åãããã¨ï¼ 33 * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ 34 * 害ãããï¼ä¸è¨èä½æ¨©è 35 ããã³TOPPERSããã¸ã§ã¯ããå 36 責ãããã¨ï¼ 37 * ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç 38 * ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è 39 ããã³TOPPERSããã¸ã§ã¯ãã 40 * å 41 責ãããã¨ï¼ 42 * 43 * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è 44 ã 45 * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç 46 * ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ 47 * ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã 48 * ã®è²¬ä»»ãè² ããªãï¼ 38 49 * 39 50 * @(#) $Id$ … … 43 54 #define __HTTPD_H__ 44 55 56 /* 57 * ã¿ã¼ã²ããä¾åã®å®ç¾© 58 */ 59 #include <kernel.h> 45 60 #include "httpd-fs.h" 46 61 #include "http_parser.h" 47 62 #include "websocket.h" 63 64 /* 65 * åã¿ã¹ã¯ã®åªå 66 度ã®å®ç¾© 67 */ 68 69 #define HTTPD_PRIORITY 5 /* HTTPãµã¼ãã¼ã¿ã¹ã¯ã®åªå 70 度 */ 71 72 #define HTTPD_STACK_SIZE 1024 /* HTTPãµã¼ãã¼ã¿ã¹ã¯ã®ã¹ã¿ãã¯é åã®ãµã¤ãº */ 73 74 /* TCP éåä¿¡ã¦ã£ã³ããããã¡ãµã¤ãº */ 75 76 #define TCP_SWBUF_SIZE 512 77 #define TCP_RWBUF_SIZE 512 78 79 /* 80 * é¢æ°ã®ãããã¿ã¤ãå®£è¨ 81 */ 82 #ifndef TOPPERS_MACRO_ONLY 83 84 /* TCP éåä¿¡ã¦ã£ã³ããããã¡ */ 85 86 extern uint8_t tcp_swbuf1[]; 87 extern uint8_t tcp_rwbuf1[]; 88 extern uint8_t tcp_swbuf2[]; 89 extern uint8_t tcp_rwbuf2[]; 90 91 /* HTTPãµã¼ãã¼ã¿ã¹ã¯ */ 92 extern void httpd_task(intptr_t exinf); 48 93 49 94 #define MAX_ELEMENT_SIZE 256 … … 81 126 82 127 typedef enum httpd_state_t { 83 STATE_DISCONNECTED, /* Øf*/84 STATE_CONNECTED, /* Ú±*/85 STATE_WEBSOCKET, /* WebSocket ÊM*/86 STATE_CLOSING, /* Øf*/87 STATE_RESET, /* mruby N®Ì½ßÌZbg*/128 STATE_DISCONNECTED, /* åæä¸ */ 129 STATE_CONNECTED, /* æ¥ç¶ä¸ */ 130 STATE_WEBSOCKET, /* WebSocketéä¿¡ä¸ */ 131 STATE_CLOSING, /* åæå¦çä¸ */ 132 STATE_RESET, /* mrubyèµ·åã®ããã®ãªã»ãã */ 88 133 } httpd_state_t; 89 134 … … 155 200 #define get_context(p) (struct httpd_state *)((intptr_t)p - (intptr_t)&((struct httpd_state *)0)->parser) 156 201 202 /* 203 * ãã³ããããã³ã°ã³ã¼ã«ã®ã³ã¼ã«ããã¯é¢æ° 204 */ 205 extern ER callback_nblk_tcp(ID cepid, FN fncd, void *p_parblk); 206 207 #endif /* TOPPERS_MACRO_ONLY */ 208 157 209 #endif /* __HTTPD_H__ */ -
EcnlProtoTool/trunk/ntshell/webserver/websocket.c
r270 r279 57 57 #include "syssvc/syslog.h" 58 58 59 static ECN_FBS_ID cur_out_msg;59 static WS_FBS_ID cur_out_msg; 60 60 61 61 void websocket_init(struct websocket *ws, ID wbsid) … … 69 69 if ((cur_out_msg.ptr != NULL) && (((ID *)cur_out_msg.ptr->_gap)[0] == ws->wbsid)) 70 70 { 71 _ ecn_fbs_del(cur_out_msg);71 _ws_fbs_del(cur_out_msg); 72 72 memset(&cur_out_msg, 0, sizeof(cur_out_msg)); 73 73 } 74 74 75 75 if (ws->cur_in_msg.ptr != NULL) { 76 _ ecn_fbs_del(ws->cur_in_msg);76 _ws_fbs_del(ws->cur_in_msg); 77 77 memset(&ws->cur_in_msg, 0, sizeof(ws->cur_in_msg)); 78 78 } … … 136 136 } 137 137 else { 138 _ ecn_fbs_cre(1, &ws->cur_in_msg);138 _ws_fbs_cre(1, &ws->cur_in_msg); 139 139 s->state++; 140 140 } … … 143 143 default: 144 144 if(ws->cur_in_msg.ptr != NULL) 145 _ ecn_fbs_poke(ws->cur_in_msg, s->data_pos, *pos ^ s->masking_key[s->data_pos % 4]);145 _ws_fbs_poke(ws->cur_in_msg, s->data_pos, *pos ^ s->masking_key[s->data_pos % 4]); 146 146 147 147 s->data_pos++; … … 152 152 if (ws->cur_in_msg.ptr != NULL) { 153 153 ((ID *)ws->cur_in_msg.ptr->_gap)[0] = ws->wbsid; 154 ret = psnd_dtq( ecn_api_mailboxid, (intptr_t)ws->cur_in_msg.ptr);154 ret = psnd_dtq(ws_api_mailboxid, (intptr_t)ws->cur_in_msg.ptr); 155 155 if (ret != E_OK) { 156 syslog(LOG_WARNING, "websocket_input() : psnd_dtq(%d) result = %d", ecn_api_mailboxid, ret);157 _ ecn_fbs_del(ws->cur_in_msg);156 syslog(LOG_WARNING, "websocket_input() : psnd_dtq(%d) result = %d", ws_api_mailboxid, ret); 157 _ws_fbs_del(ws->cur_in_msg); 158 158 } 159 159 } … … 172 172 struct websocket *mws; 173 173 ER ret; 174 ECN_FBS_ID data;174 WS_FBS_ID data; 175 175 ID wbsid; 176 176 … … 196 196 break; 197 197 198 _ ecn_fbs_del(cur_out_msg);198 _ws_fbs_del(cur_out_msg); 199 199 } 200 200 … … 217 217 return (intptr_t)pos - (intptr_t)data; 218 218 219 s->payload_len = _ ecn_fbs_get_datalen(cur_out_msg);219 s->payload_len = _ws_fbs_get_datalen(cur_out_msg); 220 220 if(s->payload_len == 0){ 221 221 goto next; … … 281 281 // Payload buffer 282 282 default: 283 *pos = _ ecn_fbs_peek(cur_out_msg, s->data_pos) ^ s->masking_key[s->data_pos % 4];283 *pos = _ws_fbs_peek(cur_out_msg, s->data_pos) ^ s->masking_key[s->data_pos % 4]; 284 284 285 285 s->data_pos++; … … 289 289 break; 290 290 next: 291 _ ecn_fbs_del(cur_out_msg);291 _ws_fbs_del(cur_out_msg); 292 292 memset(&cur_out_msg, 0, sizeof(cur_out_msg)); 293 293 s->state = 0; -
EcnlProtoTool/trunk/ntshell/webserver/websocket.h
r270 r279 58 58 #include "t_stddef.h" 59 59 60 #define NUM_ECHONET_MEMPOOL_BLOCK (60) /* é»æç¨ã¡ã¢ãªãããã¯ã®æ° */ 61 #define ECHONET_MEMPOOL_BLOCK_SIZE (256) /* é»æç¨ã¡ã¢ãªãããã¯ã®ãµã¤ãº */ 60 #define NUM_WEBSOCKET_MBXID 2 62 61 63 /* T_EDATA管çé åãµã¤ãº */ 64 # define DEF_ECN_EDT_HDR_LEN (sizeof(intptr_t))62 #ifndef TOPPERS_MACRO_ONLY 63 #include "websocket_fbs.h" 65 64 66 /* 管çé åãµã¤ãº(64byte - sizeof(T_MSG)) */ 67 /* #define DEF_ECN_FBS_LIB_HDR_LEN ((ECHONET_MEMPOOL_BLOCK_SIZE + sizeof(int) - 1)>> 2) // */ 68 #define DEF_ECN_FBS_LIB_HDR_LEN (64 - DEF_ECN_EDT_HDR_LEN) 69 70 /* 管çé åãå«ããããã¯ã«ä¿æãããã¼ã¿ãµã¤ãº */ 71 #define DEF_ECN_FBS_FST_DAT_LEN (64) 72 73 /* ãªã³ã¯ãã¤ã³ã¿é 74 åã®ãµã¤ãº(byte) */ 75 #define DEF_ECN_FBS_LNK_LEN (ECHONET_MEMPOOL_BLOCK_SIZE - DEF_ECN_EDT_HDR_LEN - DEF_ECN_FBS_LIB_HDR_LEN - DEF_ECN_FBS_FST_DAT_LEN) 76 77 /* åºå®é·ãããã¡æ大ãµã¤ãº */ 78 #define DEF_ECN_FBS_BUF_MAXLEN ((DEF_ECN_FBS_LNK_LEN / sizeof(void *)) * ECHONET_MEMPOOL_BLOCK_SIZE + DEF_ECN_FBS_FST_DAT_LEN) 79 80 /* åè¦ç´ ãããã¡ã®ãµã¤ãº */ 81 #define DEF_ECN_FBS_SUB_BUF_LEN ECHONET_MEMPOOL_BLOCK_SIZE 82 83 /* ãªã³ã¯ãã¤ã³ã¿é 84 åã«åæããããåè¦ç´ ãããã¡ */ 85 typedef struct { 86 uint8_t payload[ECHONET_MEMPOOL_BLOCK_SIZE]; 87 } T_ECN_SUB_BLK; 88 89 /* ãªã³ã¯ãã¤ã³ã¿é 90 å */ 91 typedef union { 92 T_ECN_SUB_BLK *p_sub[DEF_ECN_FBS_LNK_LEN / sizeof(T_ECN_SUB_BLK *)]; 93 uint8_t bin[DEF_ECN_FBS_LNK_LEN]; 94 } T_ECN_FBS_LNK; 95 96 /* 管çé å(64byte - sizeof(T_MSG)) */ 97 typedef struct { 98 uint16_t length; /* ã¡ãã»ã¼ã¸é· */ 99 uint16_t type; /* ã¡ãã»ã¼ã¸ã¿ã¤ã */ 100 union { 101 ID mbxid; /* éä¿¡å 102 ã¡ã¼ã«ããã¯ã¹IDï¼å 103 é¨ã¡ãã»ã¼ã¸ï¼ */ 104 }sender; 105 union { 106 ID mbxid; /* éä¿¡å 107 ã¡ã¼ã«ããã¯ã¹IDï¼å 108 é¨ã¡ãã»ã¼ã¸ï¼ */ 109 }target; 110 union { 111 ID mbxid; /* è¿ä¿¡å 112 ã¡ã¼ã«ããã¯ã¹IDï¼å 113 é¨ã¡ãã»ã¼ã¸ï¼ */ 114 }reply; 115 116 int rd; /* èªã¿åããããæ 117 å ± */ 118 int wr; /* æ¸ãè¾¼ã¿ãããæ 119 å ± */ 120 } T_ECN_FBS_HDR; 121 122 /* 管çé åãå«ããããã¯ã®æ§é */ 123 typedef struct { 124 uint8_t _msg[DEF_ECN_EDT_HDR_LEN]; /* T_MSG */ 125 T_ECN_FBS_HDR hdr; /* 管çé å 64byte - sizeof(T_MSG) */ 126 uint8_t _gap[DEF_ECN_FBS_LIB_HDR_LEN - sizeof(T_ECN_FBS_HDR)]; 127 T_ECN_FBS_LNK lnk; /* ãªã³ã¯ãã¤ã³ã¿é 128 å 128byte */ 129 uint8_t payload[DEF_ECN_FBS_FST_DAT_LEN]; 130 } T_ECN_FST_BLK; 131 132 /* FBS-ID */ 133 typedef struct ecn_fbs_id_strc { 134 T_ECN_FST_BLK *ptr; 135 } ECN_FBS_ID; 136 137 ER _ecn_fbs_cre(size_t fa_req_size, ECN_FBS_ID *fp_id); 138 ER _ecn_fbs_del(ECN_FBS_ID fa_id); 139 size_t _ecn_fbs_get_datalen(ECN_FBS_ID fa_id); 140 int _ecn_fbs_peek(ECN_FBS_ID fa_id, size_t fa_seek); 141 ER _ecn_fbs_poke(ECN_FBS_ID fa_id, size_t fa_seek, int fa_val); 142 143 extern ID ecn_api_mailboxid; 144 extern ID WEBSOCKET_MBXID; 65 extern ID ws_api_mailboxid; 145 66 146 67 typedef struct ws_state … … 168 89 ws_state_t wstate; 169 90 ws_state_t rstate; 170 ECN_FBS_ID cur_in_msg;91 WS_FBS_ID cur_in_msg; 171 92 }; 172 93 … … 179 100 int websocket_output(struct websocket *ws, void *data, int len); 180 101 102 #endif /* TOPPERS_MACRO_ONLY */ 103 181 104 #endif /* WEBSOCKET_H */
Note:
See TracChangeset
for help on using the changeset viewer.