Fixed 3191 (GUI: Does not compile against Qt 5)

This commit is contained in:
Kimmo Varis 2013-07-13 09:16:15 +02:00 committed by Daniel Marjamäki
parent 8285510996
commit d1ec81771c
6 changed files with 194 additions and 216 deletions

View File

@ -5,6 +5,12 @@ DEPENDPATH += . \
../lib
INCLUDEPATH += . \
../lib
# In Qt 5 widgets are in separate module
greaterThan(QT_MAJOR_VERSION, 4) {
QT += widgets
}
contains(LINKCORE, [yY][eE][sS]) {
LIBS += -l../bin/cppcheck-core
DEFINES += CPPCHECKLIB_IMPORT

View File

@ -43,9 +43,13 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
#if QT_VERSION < 0x050000
// Set codecs so that UTF-8 strings in sources are handled correctly.
// This is ONLY needed for Qt versions 4.x.
// Qt 5.x assumes UTF-8 by default.
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
QCoreApplication::setOrganizationName("Cppcheck");
QCoreApplication::setApplicationName("Cppcheck-GUI");

View File

@ -5,73 +5,65 @@
#include "webarchive.h"
const char *validate(const char *data)
{
int i;
if (strncmp(data,"name=",5) != 0)
return "invalid query string: must start with 'name='";
i = 5;
while (isalnum(data[i]))
i++;
if (i == 5)
return "invalid query string: no name";
if (i > 35)
return "invalid query string: max name size is 32";
if (data[i] != '\0')
return "invalid edit command";
return NULL;
}
int main()
{
const char *query_string = getenv("QUERY_STRING");
if (query_string == NULL) {
generatepage("Internal error: invalid request");
} else if (NULL != validate(query_string)) {
generatepage(validate(query_string));
} else {
char *data[MAX_RECORDS] = {0};
if (!readdata(data, MAX_RECORDS)) {
generatepage("Failed to read file data");
return EXIT_SUCCESS;
}
char name[32] = {0};
strcpy(name, getname(query_string));
int index = -1;
for (int i = 0; i < MAX_RECORDS && data[i]; i++) {
if (strcmp(name, getname(data[i])) == 0) {
index = i;
break;
}
}
if (index == -1) {
generatepage("File not found");
return EXIT_SUCCESS;
}
const char *olddata = strstr(data[index], "&data=");
if (olddata) {
char *temp = malloc(strlen(olddata+6));
unencode(olddata+6, temp);
olddata = temp;
} else
olddata = "";
puts("Content-type: text/html\r\n\r\n");
puts("<html>");
puts("<body>");
puts(" <form action=\"http://cppcheck.sf.net/cgi-bin/setfiledata.cgi\" method=\"get\">");
printf(" <textarea name=\"name\" cols=\"30\" rows=\"1\" readonly>abcd</textarea><br>\n",name);
printf(" <textarea name=\"data\" cols=\"60\" rows=\"20\" maxsize=\"512\">123</textarea><br>\n",olddata);
puts(" <input type=\"submit\" value=\"Save\">");
puts(" </form>");
puts("</body>");
puts("</html>");
return EXIT_SUCCESS;
}
if (NULL != validate_name_version(query_string)) {
generatepage(validate_name_version(query_string));
return EXIT_SUCCESS;
}
char *data[MAX_RECORDS] = {0};
if (!readdata(data, MAX_RECORDS)) {
generatepage("Failed to read file data");
return EXIT_SUCCESS;
}
char name[32] = {0};
strcpy(name, getname(query_string));
int index = -1;
for (int i = 0; i < MAX_RECORDS && data[i]; i++) {
if (strcmp(name, getname(data[i])) == 0) {
index = i;
break;
}
}
if (index == -1) {
generatepage("File not found");
return EXIT_SUCCESS;
}
int version = getversion(data[index]);
if (version < 1)
version = 1;
const char *olddata = strstr(data[index], "&data=");
if (olddata) {
char *temp = malloc(strlen(olddata+6));
unencode(olddata+6, temp);
olddata = temp;
} else
olddata = "";
puts("Content-type: text/html\r\n\r\n");
puts("<html>");
puts("<body>");
puts(" <form action=\"http://cppcheck.sf.net/cgi-bin/setfiledata.cgi\" method=\"get\">");
printf(" <textarea name=\"name\" cols=\"30\" rows=\"1\" readonly>%s</textarea>\n",name);
printf(" <textarea name=\"name\" cols=\"30\" rows=\"1\" readonly>%i</textarea>\n",version);
printf(" <textarea name=\"data\" cols=\"60\" rows=\"20\" maxsize=\"512\">123</textarea><br>\n",olddata);
puts(" <input type=\"submit\" value=\"Save\">");
puts(" </form>");
puts("</body>");
puts("</html>");
return EXIT_SUCCESS;
}

View File

@ -1,89 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "webarchive.h"
#define MAX_RECORDS 1000
void listAll(char **data)
{
puts("Content-type: text/html\r\n\r\n");
puts("<html>");
puts("<head>");
puts("<meta http-equiv=\"Pragma\" content=\"no-cache\">");
puts("<script>");
puts("function addfile() {");
puts(" var name = prompt(\"Name of library/platform/etc\", \"\");");
puts(" if (name != null)");
puts(" window.location = \"http://cppcheck.sf.net/cgi-bin/addfile.cgi?name=\" + name;");
puts("}");
puts("function editfile(name) {\n");
puts(" window.location = \"http://cppcheck.sf.net/cgi-bin/edit.cgi?name=\" + name;\n");
puts("}");
puts("function renamefile(name1) {\n");
puts(" var name2 = prompt(\"Name\", name1);\n");
puts(" if (name2 != null)\n");
puts(" window.location = \"http://cppcheck.sf.net/cgi-bin/renamefile.cgi?name1=\" + name1 + \"&name2=\" + name2;\n");
puts("}\n");
puts("function deletefile(name) {\n");
puts(" window.location = \"http://cppcheck.sf.net/cgi-bin/deletefile.cgi?name=\" + name;\n");
puts("}");
puts("</script>");
puts("</head><body>");
puts("<input type=\"button\" onclick=\"addfile()\" value=\"Add file\">");
puts("<table border=\"1\"><tr><td><table>");
for (int i = 0; i < MAX_RECORDS && data[i]; i++) {
const char *name = getname(data[i]);
printf("<tr><td>%s</td>", name);
printf("<td><input type=\"button\" onclick=\"editfile(\'%s\')\" value=\"Edit\"></td>", name);
printf("<td><input type=\"button\" onclick=\"renamefile(\'%s\')\" value=\"Rename\"></td>", name);
printf("<td><input type=\"button\" onclick=\"deletefile(\'%s\')\" value=\"Delete\"></td>", name);
printf("</tr>\n");
}
puts("</table></td></tr></table>");
puts("</body></html>");
}
void listOne(char **data, const char name[])
{
int index = -1;
for (int i = 0; i < MAX_RECORDS && data[i]; i++) {
if (strcmp(getname(data[i]), name)==0) {
index = i;
break;
}
}
puts("Content-type: text/plain\r\n\r\n");
puts((index == -1) ? "Not found" : data[index]);
}
int main()
{
char *data[MAX_RECORDS] = {0};
// read
if (!readdata(data, MAX_RECORDS)) {
puts("Content-type: text/html\r\n\r\n");
puts("Internal error: failed to load data");
return 0;
}
// sort
sortdata(data,MAX_RECORDS);
const char *query_string = getenv("QUERY_STRING");
if (query_string == NULL || *query_string == '\0') {
listAll(data);
} else if (strncmp(query_string, "name=", 5) == 0 && getname(query_string) != NULL) {
char name[32] = {0};
strcpy(name, getname(query_string));
listOne(data,name);
} else {
puts("Content-type: text/plain\r\n\r\n");
puts("Invalid query");
}
return 0;
}

View File

@ -5,81 +5,63 @@
#include "webarchive.h"
const char *validate(const char *data)
{
int i;
// name
if (strncmp(data,"name=",5) != 0)
return "invalid query string: must start with 'name='";
i = 5;
while (isalnum(data[i]))
i++;
if (i == 5)
return "invalid query string: no name";
if (i > 35)
return "invalid query string: max name size is 32";
// filedata
if (strncmp(data+i, "&data=", 6) != 0)
return "invalid query string: invalid name / no data";
return NULL;
}
int main()
{
const char *query_string = getenv("QUERY_STRING");
if (query_string == NULL) {
generatepage("Internal error: invalid request");
} else if (NULL != validate(query_string)) {
generatepage(validate(query_string));
} else {
char *data[MAX_RECORDS] = {0};
if (!readdata(data, MAX_RECORDS)) {
generatepage("Failed to read file data");
return EXIT_SUCCESS;
}
char name[32] = {0};
strcpy(name, getname(query_string));
int index = -1;
for (int i = 0; i < MAX_RECORDS && data[i]; i++) {
if (strcmp(name, getname(data[i])) == 0) {
index = i;
break;
}
}
if (index == -1) {
generatepage("File not found");
return EXIT_SUCCESS;
}
// cleanup data...
char str[1000] = {0};
char *dst = str;
for (const char *src = query_string; *src; src++) {
*dst = *src;
dst++;
if (strncmp(src, "%25", 3) == 0 && isxdigit(src[3]) && isxdigit(src[4]))
src += 2;
}
data[index] = str;
sortdata(data, MAX_RECORDS);
FILE *f = fopen("data.txt", "wt");
if (f == NULL) {
generatepage("Failed to add file (access denied). Try again.");
return EXIT_SUCCESS;
}
for (int i = 0; i < MAX_RECORDS && data[i]; i++)
fprintf(f, "%s\n", data[i]);
fclose(f);
generatepage("saved.");
return EXIT_SUCCESS;
}
if (NULL != validate_name_version_data(query_string)) {
generatepage(validate_name_version_data(query_string));
return EXIT_SUCCESS;
}
char *data[MAX_RECORDS] = {0};
if (!readdata(data, MAX_RECORDS)) {
generatepage("Failed to read file data");
return EXIT_SUCCESS;
}
char name[32] = {0};
strcpy(name, getname(query_string));
int index = -1;
for (int i = 0; i < MAX_RECORDS && data[i]; i++) {
if (strcmp(name, getname(data[i])) == 0) {
index = i;
break;
}
}
if (index == -1) {
generatepage("File not found");
return EXIT_SUCCESS;
}
// cleanup data...
char str[1000] = {0};
char *dst = str;
for (const char *src = query_string; *src; src++) {
*dst = *src;
dst++;
if (strncmp(src, "%25", 3) == 0 && isxdigit(src[3]) && isxdigit(src[4]))
src += 2;
}
data[index] = str;
sortdata(data, MAX_RECORDS);
FILE *f = fopen("data.txt", "wt");
if (f == NULL) {
generatepage("Failed to add file (access denied). Try again.");
return EXIT_SUCCESS;
}
for (int i = 0; i < MAX_RECORDS && data[i]; i++)
fprintf(f, "%s\n", data[i]);
fclose(f);
generatepage("saved.");
return EXIT_SUCCESS;
}

View File

@ -60,6 +60,25 @@ const char * getname(const char *data)
return name;
}
int getversion(const char *data)
{
const char *name = getname(data);
if (name == NULL)
return 0; // invalid string => 0
data = data + strlen("name=") + strlen(name);
if (strncmp(data,"&version=",9) != 0)
return 1; // no version => 1
data = data + 9;
int ret = 0;
while (isdigit(*data)) {
ret = ret * 10 + *data - '0';
data++;
}
if (*data != '\0' && *data != '&')
return -1; // invalid version => -1
return ret;
}
void sortdata(char * * const data, int sz)
{
for (int i = 1; i < sz && data[i]; i++) {
@ -85,3 +104,67 @@ void generatepage(const char msg[])
puts("<br><input type=\"button\" value=\"OK\" onclick=\"ok()\"></body></html>");
}
const char *validate_name_version(const char *data)
{
int i = 0;
// name
if (strncmp(data,"name=",5) != 0)
return "invalid query string: must start with 'name='";
i += 5;
if (!isalnum(data[i]))
return "invalid query string: no name / invalid character in name";
while (isalnum(data[i]))
i++;
if (i > 35)
return "invalid query string: max name size is 32";
// version
if (strncmp(&data[i], "&version=", 9) != 0)
return "invalid query string: 'version=' not seen at the expected location";
i += strlen("&version=");
if (!isdigit(data[i]))
return "invalid query string: version must consist of digits 0-9";
while (isdigit(data[i]))
i++;
// end
if (data[i] != '\0')
return "invalid query";
return NULL;
}
const char *validate_name_version_data(const char *data)
{
int i = 0;
// name
if (strncmp(data,"name=",5) != 0)
return "invalid query string: must start with 'name='";
i += 5;
if (!isalnum(data[i]))
return "invalid query string: no name / invalid character in name";
while (isalnum(data[i]))
i++;
if (i > 35)
return "invalid query string: max name size is 32";
// version
if (strncmp(&data[i], "&version=", 9) != 0)
return "invalid query string: 'version=' not seen at the expected location";
i += strlen("&version=");
if (!isdigit(data[i]))
return "invalid query string: version must consist of digits 0-9";
while (isdigit(data[i]))
i++;
// filedata
if (strncmp(data+i, "&data=", 6) != 0)
return "invalid query string: 'data=' not seen at the expected location";
return NULL;
}