Adding initial http daemon implementation

This commit is contained in:
logicog
2025-07-13 12:03:40 +02:00
parent e2716da6c8
commit d66931acdf
11 changed files with 154 additions and 154 deletions
+23
View File
@@ -0,0 +1,23 @@
CC = sdcc
CC_FLAGS = -mmcs51 -I. -I../uip
ASM = sdas8051
AFLAGS= -plosgff
SRCS = httpd.c
OBJS = ${SRCS:.c=.rel}
all: $(OBJS)
%.asm: %.c
$(CC) $(CC_FLAGS) -c -S $<
%.rel: %.asm
./treatasm.py $^ >$^.new
mv $^.new $^
${ASM} ${AFLAGS} $^
clean:
rm .asm *.lst *.rel *.rst *.sym
.PHONY: all clean
+77
View File
@@ -0,0 +1,77 @@
#include "httpd.h"
#include "../rtl837x_common.h"
#include "uip.h"
#pragma codeseg BANK1
static __code uint8_t page_main[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n"
"\r\n<!DOCTYPE html>"
"<html>"
" <head>"
" <title>FreeSwitchOS Main Page</title>"
" </head>"
" <body>"
" <h1>Port configuration:</h1>"
" <p>TBD</p>"
" </body>"
"</html>\r\n";
__xdata uint8_t outbuf[2048];
inline uint8_t is_space(uint8_t c)
{
return c == ' ' || c == '\t';
}
void httpd_init(void) __banked
{
// Start listening to port 80
uip_listen(HTONS(80));
}
void httpd_appcall(void)
{
__xdata struct httpd_state *s = &(uip_conn->appstate);
write_char('P');
if(uip_connected()) {
print_string("Connected...\n");
s->transmitted = 0;
} else if (uip_closed()) {
print_string("Connection closed\n");
} else if (uip_poll()) {
uip_len = 0;
if (s->transmitted)
uip_close();
// write_char('p');
} else if (uip_newdata()) {
write_char('<'); print_short(uip_len); write_char('\n');
__xdata uint8_t *p = uip_appdata;
while (*p)
write_char(*p++);
write_char('\n');
p = uip_appdata;
if (p[0] == 'G' && p[1] == 'E' && p[2] == 'T' && p[3] == ' ')
print_string("GET request ");
p += 4;
__xdata uint8_t *q = p;
while (!is_space(*p))
p++;
*p = '\0';
print_string_x(q);
write_char('\n');
// For now, we do not have anything to send...
uip_len = strlen(page_main);
strtox(outbuf, page_main);
s->transmitted = 1;
uip_send(outbuf, uip_len);
} else if (uip_rexmit()) { // Connection established, need to rexmit?
write_char('r');
uip_len = 0;
} else {
uip_len = 0;
}
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef __HELLO_WORLD_H__
#define __HELLO_WORLD_H__
/* Since this file will be included by uip.h, we cannot include uip.h
here. But we might need to include uipopt.h if we need the u8_t and
u16_t datatypes. */
#include "uipopt.h"
/* Next, we define the uip_tcp_appstate_t datatype. This is the state
of our application, and the memory required for this state is
allocated together with each TCP connection. One application state
for each TCP connection. */
typedef struct httpd_state {
char transmitted;
} uip_tcp_appstate_t;
/* Finally we define the application function to be called by uIP. */
void httpd_appcall(void);
#ifndef UIP_APPCALL
#define UIP_APPCALL httpd_appcall
#endif /* UIP_APPCALL */
void httpd_init(void) __banked;
#endif
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/python
import re
import sys
isBanked = False
regex_bank = re.compile(r'^\s*\.area\s+BANK\d+\s*\(CODE\)')
regex_const = re.compile(r'^\s*\.area\s+CONST\s*\(CODE\)')
regex_area = re.compile(r'^\s*\.area\s+\(CODE\)')
with open(sys.argv[1], "r") as file:
for line in file:
line = line.rstrip()
bmatch = re.search(regex_bank, line)
if bmatch:
isBanked = True
print(line)
else:
cmatch = re.search(regex_const, line)
if not isBanked or not cmatch:
print(line)
amatch = re.search(regex_area, line)
if amatch:
isBanked = False
print(line)