/* http7_main.c — SLeeLa HTTP 7.0 server entry point */ #include "http7_server.h" #include #include #include #include #include static int echo_frame(const http7_frame_view_t *f, uint8_t *rp, size_t rc, size_t *rl, void *ud) { (void)ud; if (f->header.payload_length > rc) return -1; size_t n = f->header.payload_length; if (n > 0) memcpy(rp, f->payload, n); *rl = n; return 0; } static int demo_http(const h7s_request *req, h7s_response *resp, void *ud) { (void)req; (void)ud; static const char body[] = "{\"server\":\"SLeeLa\",\"http_generation\":\"7.0\",\"reality_assertion\":true}\n"; resp->status_code = 200; resp->content_type = "application/json"; resp->body = body; resp->body_length = sizeof(body) - 1; return 0; } static int parse_port(const char *s,uint16_t *out){ if(!s||!*s||!out)return -1; unsigned long v=0; for(const unsigned char*p=(const unsigned char*)s;*p;++p){ if(*p<'0'||*p>'9')return -1; unsigned d=(unsigned)(*p-'0'); if(v>(65535UL-d)/10UL)return -1; v=v*10UL+d; } if(v==0||v>65535UL)return -1; *out=(uint16_t)v;return 0; } int main(int argc, char **argv) { h7s_server_config cfg; h7s_server_config_init(&cfg); cfg.handler = demo_http; cfg.frame_handler = echo_frame; for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "--self-test") == 0) return h7s_self_test(); else if (strcmp(argv[i], "--port") == 0 && i+1 < argc) { if(parse_port(argv[++i],&cfg.port)!=0){fprintf(stderr,"invalid port\n");return 2;} } else if(strcmp(argv[i],"--bind")==0&&i+1