Prof. A Olowofoyeku (The African Chief) wrote:
The problem is the size of the compiled program (320kb when statically linked with libgpc.a, and 250kb when linked to libgpc.so, which itself is 320kb). This is a significant amount of space for a single program to take on a router.
Are you planning to have multiple programs? In this case, dynamic linking of libgpc.so (and possibly the CGI unit and the units it uses in turn) should be worthwile. Otherwise, of course, for a single program, dynamic linking doesn't gain anything filesize-wise.
This was just an experiment to see if I could add somefunctionality to the router firmware that other routers didn't have, but which I have seen in Smoothwall. In the end all that was required was two small procedures. I would have probably wanted to add more programs - but the router has only limited free space in the flash memory, and so it is not feasible if all programs would be 100kb or more in size.
With full dynamic linking (i.e., if you move the .o files of all non-RTS units into a .so library as well), the individual programs should be smaller, but of course, the one-time space requirement for this .so and libgpc.so would still be a few 100 KB. How much free space does it have, BTW?
I have just had a look through cgi.pas and found "query_string". A search through the web indicates that this might be all I need for my shell script :)
Basically yes, at least for GET requests, though you might have to do some parsing which isn't always nice to do in shell scripts -- especially if you need multiple variables or quoted characters (though most printable ASCII characters are usually not quoted).
Though a bit OT, I have some ugly (almost write-only ;-) bash code to do some parsing for simple cases. It allows only GET requests (POST without multipart could be added using dd ...), and allows only a limited set of characters (others can be added, but one has to be careful of special characters, as always in shell scripts; in particular quote characters would be problematic here), and only a few quoted characters (2F (/) and E4 (À), can be taken as examples to add what one needs). It does everything with bash-internals (no sed or such, for performance), but therefore it really requires bash. It puts the content of the CGI variable foo in the shell variable CGIVAR_foo. It tried to make it secure against malicious input, but of course, I can't guarantee anything.
#!/bin/bash
error () { echo "Content-type: text/plain" echo "" echo "Error: $1" exit }
tmp="&${QUERY_STRING##*?}" tmp="${tmp//[%]2[Ff]//}" tmp="${tmp//[%][Ee]4/À}" tmp="${tmp// /#}" tmp="${tmp//[+]/ }" if [ x"$REQUEST_METHOD" != x"GET" ] || [ x"${tmp//[=A-Za-z0-9_.&/ -]/}" != x ]; then error "invalid input" fi tmp="${tmp//[&=]/" "}" tmp="${tmp#"}"" eval tmp="($tmp)" a="" for b in "${tmp[@]}"; do if [ x"$a" = x ]; then a="${b:-dummy}" else [ x"${a//[A-Za-z0-9_]/}" = x ] && eval "CGIVAR_$a="$b"" a="" fi done
Frank