@@ -39,16 +39,12 @@ class CppcheckExecutor : public ErrorLogger {
3939 }
4040
4141 void run (const char code[]) {
42- printf (" %s\n " , ErrorLogger::ErrorMessage::getXMLHeader (2 ).c_str ());
4342 cppcheck.check (" test.c" , code);
44- printf (" %s\n " , ErrorLogger::ErrorMessage::getXMLFooter (2 ).c_str ());
45- printf (" \n\n " );
4643 }
4744
4845 void reportOut (const std::string &outmsg) { }
4946 void reportErr (const ErrorLogger::ErrorMessage &msg) {
50- const std::string str (msg.toXML (true ,2U ));
51- printf (" %s\n " , str.c_str ());
47+ printf (" %s\n " , msg.toString (true ).c_str ());
5248 }
5349
5450 void reportProgress (const
@@ -70,28 +66,38 @@ int main()
7066{
7167 char data[4096 ] = {0 };
7268
69+ const char *query_string = getenv (" QUERY_STRING" );
70+ if (query_string)
71+ std::strncpy (data, query_string, sizeof (data)-2 );
72+
7373 const char *lenstr = getenv (" CONTENT_LENGTH" );
7474 if (lenstr) {
7575 int len = std::min (1 + atoi (lenstr), (int )(sizeof (data) - 2 ));
7676 fgets (data, len, stdin);
77- } else {
78- const char *s = getenv (" QUERY_STRING" );
79- std::strncpy (data, s?s:" " , sizeof (data)-2 );
8077 }
8178
8279 char code[4096 ] = {0 };
8380 unencode (data, code);
8481
82+ if (strlen (code) > 1000 ) {
83+ puts (" Content-type: text/html\r\n\r\n " );
84+ puts (" <html><body>For performance reasons the code must be shorter than 1000 chars.</body></html>" );
85+ return EXIT_SUCCESS ;
86+ }
87+
8588 FILE *logfile = fopen (" democlient.log" , " at" );
8689 if (logfile != NULL ) {
8790 fprintf (logfile, " ===========================================================\n %s\n " , code);
8891 fclose (logfile);
8992 }
9093
91- printf (" Content-type: text/plain\n\n " );
94+ puts (" Content-type: text/html\r\n\r\n " );
95+ puts (" <html><body><pre>" );
9296
9397 CppcheckExecutor cppcheckExecutor;
9498 cppcheckExecutor.run (code);
9599
100+ puts (" </pre>Done!</body></html>" );
101+
96102 return EXIT_SUCCESS ;
97103}
0 commit comments