📄 httpd.lst
字号:
154:net/httpd.c **** softuart_putc('.');
155:net/httpd.c **** for(f=0;f<3 && file_ext[f];f++)
156:net/httpd.c **** softuart_putc(file_ext[f]);
157:net/httpd.c **** softuart_puts_progmem(">.\r\n");
158:net/httpd.c **** #endif
159:net/httpd.c ****
160:net/httpd.c **** //set file id:
161:net/httpd.c **** if (file_name[0] == '/' || string_compare_progmem("index", file_name)){
162:net/httpd.c **** ///show index
163:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_INDEX;
164:net/httpd.c **** file_ext[0] = 'h'; //->html
165:net/httpd.c **** }else if ( string_compare_progmem("site/cam", file_name)){
166:net/httpd.c **** ///show webcam pic
167:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_SITE_CAM;
168:net/httpd.c **** }else if ( string_compare_progmem("site/temp", file_name)){
169:net/httpd.c **** ///show templog site
170:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_SITE_TEMP;
171:net/httpd.c **** }else if ( string_compare_progmem("site/io", file_name)){
172:net/httpd.c **** ///show io site
173:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_SITE_IO;
174:net/httpd.c **** }else if ( string_compare_progmem("site/ficon", file_name)){
175:net/httpd.c **** ///show file icon
176:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_SITE_FILE_ICON_PIC;
177:net/httpd.c **** }else if ( string_compare_progmem("graph_0", file_name)){
178:net/httpd.c **** ///show tempgraph (use eeprom data)
179:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_GRAPH0;
180:net/httpd.c **** }else if ( string_compare_progmem("fs/ls", file_name)){
181:net/httpd.c **** ///show dataflash file list
182:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_FS_LS;
183:net/httpd.c **** }else if ( string_compare_progmem("cam/pic", file_name)){
184:net/httpd.c **** ///show webcam image
185:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_CAM_PIC;
186:net/httpd.c **** }else if ( string_compare_progmem("cam/busy", file_name)){
187:net/httpd.c **** ///show webcam busy image
188:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_CAM_BUSY;
189:net/httpd.c **** }else if ( string_compare_progmem("site/servo", file_name)){
190:net/httpd.c **** ///show servo page
191:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_SERVO_OK;
192:net/httpd.c **** }else if ( string_compare_progmem_noeof("servo_", file_name)){
193:net/httpd.c **** ///show/set servo pos
194:net/httpd.c **** //parse number & set servopos (use uint16 parser)
195:net/httpd.c **** //if you want to show servopos without moving use servo_999.bmp for example
196:net/httpd.c **** if (string_buffer_to_uint16(&file_name[6])<256)
197:net/httpd.c **** servo_set_pos(string_buffer_to_uint16(&file_name[6])&0xFF);
198:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_SERVO_POS;
199:net/httpd.c **** }else if ( string_compare_progmem_noeof("set/", file_name)){
200:net/httpd.c **** ///show port image
201:net/httpd.c **** if(file_name[7] == '1'){
202:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_SET_IO_1_PIC;
203:net/httpd.c **** port_set_portbit(file_name[4], file_name[5], 1);
204:net/httpd.c **** }else{
205:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_SET_IO_0_PIC;
206:net/httpd.c **** port_set_portbit(file_name[4], file_name[5], 0);
207:net/httpd.c **** }
208:net/httpd.c **** //deprecated
209:net/httpd.c **** //}else if ( string_compare_progmem_noeof("fs/f", file_name)){
210:net/httpd.c **** // ///show dataflash file with id given (fs/f1234 -> file 1234 !):
211:net/httpd.c **** // httpd_conn[socketnum].file_id = 0xFF + string_buffer_to_uint16(&file_name[4]);
212:net/httpd.c **** }else if ( string_compare_progmem_noeof("fs/", file_name)){
213:net/httpd.c **** ///try to find dataflash file with the given name:
214:net/httpd.c **** httpd_conn[socketnum].file_id = 0xFF + filesystem_search_file(&file_name[3], &file_ext[0]);
215:net/httpd.c **** httpd_conn[socketnum].data_ptr = 0;
216:net/httpd.c **** if (httpd_conn[socketnum].file_id == 0xFF)
217:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_IDLE; ///no file found !
218:net/httpd.c **** }else if ( string_compare_progmem("adm/up", file_name)){
219:net/httpd.c **** ///show upload form
220:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_UP;
221:net/httpd.c **** }else if ( string_compare_progmem_noeof("adm/rm/", file_name)){
222:net/httpd.c **** ///try to find dataflash file with the given name:
223:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_REMOVED;
224:net/httpd.c **** }else if ( string_compare_progmem("adm/mkfs", file_name)){
225:net/httpd.c **** ///format filesystem question
226:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_MKFS;
227:net/httpd.c **** }else if ( string_compare_progmem("adm/mkfs2", file_name)){
228:net/httpd.c **** ///format filesystem exec!
229:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_MKFS2;
230:net/httpd.c **** }else{
231:net/httpd.c **** ///FILE not found -> 404 err
232:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_IDLE;
233:net/httpd.c **** }
234:net/httpd.c **** //initialise substate
235:net/httpd.c **** httpd_conn[socketnum].substate = HTTPD_SUBSTATE_NONE;
236:net/httpd.c **** }else if ((buffer[datapos + 0] == 'P') &&
237:net/httpd.c **** (buffer[datapos + 1] == 'O') &&
238:net/httpd.c **** (buffer[datapos + 2] == 'S') &&
239:net/httpd.c **** (buffer[datapos + 3] == 'T')){
240:net/httpd.c **** //QUICK HACK (TEST!)
241:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_POST;
242:net/httpd.c ****
243:net/httpd.c **** string_progmem_to_buffer(PSTR("adm/"), file_name,4);
244:net/httpd.c ****
245:net/httpd.c **** //initialise substate
246:net/httpd.c **** httpd_conn[socketnum].substate = HTTPD_SUBSTATE_NONE;
247:net/httpd.c **** }
248:net/httpd.c ****
249:net/httpd.c **** //find the content length!
250:net/httpd.c **** //use a quick & dirty method for this !!!
251:net/httpd.c **** //-> we search for *th: <number>
252:net/httpd.c **** // (instead of content-length:)
253:net/httpd.c **** //
254:net/httpd.c **** // we do this because to minimize the following problem:
255:net/httpd.c **** // clen detection DOES NOT work when the header is
256:net/httpd.c **** // split into multiple packets & the packetborder
257:net/httpd.c **** // is anywhere between th: <number> !! FIXME!
258:net/httpd.c **** if (httpd_conn[socketnum].file_id == 0xFE){
259:net/httpd.c **** pos = datapos;
260:net/httpd.c **** //pos+4 because len("th: ") is 4 (fixme: number might be outside packetlen!)
261:net/httpd.c **** while (pos+4<datapos+datalen){
262:net/httpd.c **** if (string_compare_progmem_noeof("th: ", &buffer[pos])){
263:net/httpd.c **** //next is the number !
264:net/httpd.c **** //parse it !
265:net/httpd.c **** httpd_conn[socketnum].data_position = string_buffer_to_uint32(&buffer[pos+4]);
266:net/httpd.c **** break;
267:net/httpd.c **** }
268:net/httpd.c **** pos++;
269:net/httpd.c **** }
270:net/httpd.c **** }
271:net/httpd.c ****
272:net/httpd.c **** ///search for authorization key
273:net/httpd.c **** authorized = 0;
274:net/httpd.c **** if (string_compare_progmem_noeof("adm/", file_name)){
275:net/httpd.c **** //accessing admin zone, search for auth!
276:net/httpd.c **** #if HTTPD_DEBUG_AUTH
277:net/httpd.c **** softuart_puts_progmem("HTTPD: auth required! [");
278:net/httpd.c **** #endif
279:net/httpd.c **** pos = datapos;
280:net/httpd.c ****
281:net/httpd.c **** while(pos<datapos+datalen){
282:net/httpd.c **** //speedup, check first letter
283:net/httpd.c **** if (buffer[pos] == 'A'){
284:net/httpd.c **** //if match, call whole function match
285:net/httpd.c **** if (string_compare_progmem_noeof("Authorization: Basic ", &buffer[pos])){
286:net/httpd.c **** //got it ! now buf[pos+21]-... has auth string!
287:net/httpd.c **** unsigned char len;
288:net/httpd.c **** unsigned char *pwbuff = &buffer[pos+21];
289:net/httpd.c ****
290:net/httpd.c **** //maximum pw len 100
291:net/httpd.c **** for(len=0; len < 100; len++){
292:net/httpd.c **** //check buf < '0' is ok because of base64... \r\n & space are smaller ;)
293:net/httpd.c **** if (pwbuff[len]<'0')
294:net/httpd.c **** break;
295:net/httpd.c **** #if HTTPD_DEBUG_AUTH
296:net/httpd.c **** softuart_putc(pwbuff[len]);
297:net/httpd.c **** #endif
298:net/httpd.c **** }
299:net/httpd.c **** //len--;
300:net/httpd.c ****
301:net/httpd.c **** //base64 decode, after this the decoded string is in buffer[pos+21]...
302:net/httpd.c **** base64_decode(&pwbuff[0], len);
303:net/httpd.c ****
304:net/httpd.c **** #if HTTPD_DEBUG_AUTH
305:net/httpd.c **** softuart_puts_progmem("], decoded [");
306:net/httpd.c **** for(len=0; len < 100; len++){
307:net/httpd.c **** if (pwbuff[len]==0)
308:net/httpd.c **** break;
309:net/httpd.c **** softuart_putc(pwbuff[len]);
310:net/httpd.c **** }
311:net/httpd.c **** softuart_puts_progmem("] auth? ");
312:net/httpd.c **** #endif
313:net/httpd.c ****
314:net/httpd.c **** if (string_compare_progmem(HTTPD_ADMIN_AUTH_LOGIN":"HTTPD_ADMIN_AUTH_PASS, &pwbuff[0])){
315:net/httpd.c **** //auth passed !!
316:net/httpd.c **** authorized = 1;
317:net/httpd.c **** }
318:net/httpd.c **** #if HTTPD_DEBUG_AUTH
319:net/httpd.c **** softuart_put_uint8(authorized);
320:net/httpd.c **** softuart_putnewline();
321:net/httpd.c **** #endif
322:net/httpd.c ****
323:net/httpd.c **** break;
324:net/httpd.c **** }
325:net/httpd.c **** }
326:net/httpd.c **** pos++;
327:net/httpd.c **** }
328:net/httpd.c **** //check if there was a file remove request
329:net/httpd.c **** if (authorized && (httpd_conn[socketnum].file_id == HTTPD_STATE_FILE_REMOVED)){
330:net/httpd.c **** httpd_conn[socketnum].file_id = 0xFF + string_buffer_to_uint16(&file_name[7]);
331:net/httpd.c **** if (httpd_conn[socketnum].file_id != 0xFF){
332:net/httpd.c **** //found ! -> remove file !
333:net/httpd.c **** filesystem_delete_file(httpd_conn[socketnum].file_id - 0xFF);
334:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_REMOVED;
335:net/httpd.c **** }
336:net/httpd.c **** }
337:net/httpd.c **** }
338:net/httpd.c ****
339:net/httpd.c **** //detect \r\n\r\n
340:net/httpd.c **** unsigned int inpos = datapos;
341:net/httpd.c **** unsigned int inpos_old =0;
342:net/httpd.c **** while( inpos<(datapos+datalen)){
343:net/httpd.c **** if (buffer[inpos] == '\r'){
344:net/httpd.c **** if ( ((httpd_conn[socketnum].substate & 0x07) == HTTPD_SUBSTATE_NONE) ||
345:net/httpd.c **** ((httpd_conn[socketnum].substate & 0x07) == HTTPD_SUBSTATE_RN) ){
346:net/httpd.c **** httpd_conn[socketnum].substate++;
347:net/httpd.c **** }else{
348:net/httpd.c **** httpd_conn[socketnum].substate = (httpd_conn[socketnum].substate & 0xF8) | HTTPD_SUBSTATE_NO
349:net/httpd.c **** }
350:net/httpd.c **** }else if (buffer[inpos] == '\n'){
351:net/httpd.c **** if ( ((httpd_conn[socketnum].substate & 0x07) == HTTPD_SUBSTATE_R) ||
352:net/httpd.c **** ((httpd_conn[socketnum].substate & 0x07) == HTTPD_SUBSTATE_RNR) ){
353:net/httpd.c **** httpd_conn[socketnum].substate++;
354:net/httpd.c **** }else{
355:net/httpd.c **** httpd_conn[socketnum].substate = (httpd_conn[socketnum].substate & 0xF8) | HTTPD_SUBSTATE_NO
356:net/httpd.c **** }
357:net/httpd.c **** }else{
358:net/httpd.c **** httpd_conn[socketnum].substate = (httpd_conn[socketnum].substate & 0xF8) | HTTPD_SUBSTATE_NONE
359:net/httpd.c **** }
360:net/httpd.c **** if ((httpd_conn[socketnum].substate & 0x07) == HTTPD_SUBSTATE_RNRN){
361:net/httpd.c **** if (httpd_conn[socketnum].file_id == HTTPD_STATE_FILE_POST){
362:net/httpd.c **** //file_name + 2nd rnrn found -> ready
363:net/httpd.c **** if (httpd_conn[socketnum].substate & HTTPD_SUBSTATE_POST_FN_OK)
364:net/httpd.c **** break;
365:net/httpd.c ****
366:net/httpd.c **** inpos_old = inpos;
367:net/httpd.c **** //we need to grab filename now & wait for another \r\n\r\n
368:net/httpd.c **** while(inpos<(datapos+datalen)){
369:net/httpd.c **** ///WARNING: this only works if the packet with filename is not
370:net/httpd.c **** ///splitted into two packets !!
371:net/httpd.c **** if (string_compare_progmem_noeof("filename=\"", &buffer[inpos])){
372:net/httpd.c **** //now the filename starts at inpos+strlen(filename=")
373:net/httpd.c ****
374:net/httpd.c **** //try to find the filename extension:
375:net/httpd.c **** unsigned int fextpos = inpos + 10;
376:net/httpd.c **** while((buffer[fextpos] != '.') &&(inpos<(datapos+datalen)))
377:net/httpd.c **** fextpos++;
378:net/httpd.c ****
379:net/httpd.c **** //terminate filename (replace .EXT by \0EXT)
380:net/httpd.c **** buffer[fextpos] = '\0';
381:net/httpd.c ****
382:net/httpd.c **** #if HTTPD_DEBUG
383:net/httpd.c **** softuart_puts_progmem("HTTP: POST ");
384:net/httpd.c **** softuart_putnewline();
385:net/httpd.c **** #endif
386:net/httpd.c **** //now open the file
387:net/httpd.c **** filesystem_open_file_wr(&buffer[inpos+10],&buffer[fextpos+1]);
388:net/httpd.c **** break;
389:net/httpd.c **** }
390:net/httpd.c **** inpos++;
391:net/httpd.c **** }
392:net/httpd.c **** //now find the next \r\n\r\n
393:net/httpd.c **** httpd_conn[socketnum].substate = HTTPD_SUBSTATE_POST_FN_OK | HTTPD_SUBSTATE_NONE;
394:net/httpd.c **** }else{
395:net/httpd.c **** //normal GET cmd, return data after \r\n\r\n
396:net/httpd.c **** break;
397:net/httpd.c **** }
398:net/httpd.c **** }
399:net/httpd.c **** inpos++;
400:net/httpd.c **** }
401:net/httpd.c ****
402:net/httpd.c ****
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -