This is neat. Honestly, in addition, I'd like to see something like Rack for C. The "gateway interfaces" for C are too implementation-specific (CGI, FastCGI, SCGI, web server extensions/modules, etc). It would be something more abstract that would run on-top of a web server interface. void application_main(web_request *request, web_response *response) { char body[1024]; snprintf(body, sizeof(body), "Hello, %s", reque…
As an illustration of why C kind of sucks for web apps, that code is obviously insecure† (it's reflected XSS). To get around that while preserving natural syntax, you want: char *hsafe(const char *input); But where does hsafe get the memory for the string from? It can't use input (the filtered result is larger than the input). Does it malloc? Now you have to free the result. Does it do the inet_ntoa() thing with the…
Which is to say it's only a problem if you are doing it by hand on a per field basis. Which leads to your next point:
> Maybe you can do an arena for each connection, so it's:
> char *hsafe(request_t *r, char *str)
> But that's still sort of painful.
This is only painful if you are doing it by hand every time you use the parameter. If the framework handles it for you, so that you always get the sanitized result, it strikes me as no different than any other language.r->param("input"); // presanitized, lazily created, pooled in r
r->param_raw("input"); // if you want to live dangerously
Why is this worse in straight C than in something like Python that is doing the same thing but with an interpreted layer between you and the C?