I am writing puzzle bot, http server which upon hitting , renders a default page with text area to write code similar to http://codepad.org/. When I type in following program.
#include <stdio.h>
int main( int argc, char **argv) {
return 0;
}
I get following response from HTTP POST.
code : %23include+%3Cstdio.h%3E%0D%0Aint+main%28+int+argc%2C+char+**argv%29+%7B%0D%0A++++return+0%3B%0D%0A%7D
lang : C
How Do I parse the information from the key code
. I need to write this program in a temporary file and then compile/run.
You need to decode the data, first. You could use this reference .
All spaces are replaces with the sign +
, and all numbers after %
are special - 2 digit hex encoded numbers - URL encoded special symbols (like +
, ,
, }
, etc.).
For example, you code
will be translated to :
#include <stdio.h>\r\nint main( int argc, char **argv) {\r\n return 0;\r\n}
Where \r\n
are CRLF, So, from this, you'll finally get:
#include <stdio.h>
int main( int argc, char **argv) {
return 0;
}
which is exactly your code. Then you could write it to your temp file and try to compile it.
Some things, that come to my mind for better application like this:
Of course, these are just some advice, that come to my mind. That would be great exercise for any developer - IPC + multithreading + network programming + http! Great :)
Good luck
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With