2013-07-07 16:55:22 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "webarchive.h"
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
const char *query_string = getenv("QUERY_STRING");
|
|
|
|
if (query_string == NULL) {
|
2013-07-07 18:06:52 +02:00
|
|
|
generatepage("Internal error: invalid request");
|
2013-07-13 10:23:10 +02:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2013-07-07 16:55:22 +02:00
|
|
|
|
2013-07-13 10:23:10 +02:00
|
|
|
if (NULL != validate_name_version(query_string)) {
|
|
|
|
generatepage(validate_name_version(query_string));
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2013-07-07 16:55:22 +02:00
|
|
|
|
2013-07-13 10:23:10 +02:00
|
|
|
char *data[MAX_RECORDS] = {0};
|
|
|
|
if (!readdata(data, MAX_RECORDS)) {
|
|
|
|
generatepage("Failed to delete file, try again");
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
sortdata(data, MAX_RECORDS);
|
|
|
|
|
2013-07-21 11:27:50 +02:00
|
|
|
char name[MAX_NAME_LEN] = {0};
|
2013-07-13 10:23:10 +02:00
|
|
|
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;
|
2013-07-07 16:55:22 +02:00
|
|
|
}
|
2013-07-13 10:23:10 +02:00
|
|
|
}
|
2013-07-07 16:55:22 +02:00
|
|
|
|
2013-07-13 10:23:10 +02:00
|
|
|
if (index == -1) {
|
|
|
|
generatepage("File not found");
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2013-07-07 16:55:22 +02:00
|
|
|
|
2013-07-13 10:23:10 +02:00
|
|
|
FILE *f = fopen("data.txt", "wt");
|
|
|
|
if (f == NULL) {
|
|
|
|
generatepage("Failed to delete file (access denied)");
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2013-07-07 18:06:52 +02:00
|
|
|
|
2013-07-13 10:23:10 +02:00
|
|
|
int deleted = 0;
|
|
|
|
for (int i = 0; i < MAX_RECORDS && data[i]; i++) {
|
|
|
|
if (i != index)
|
|
|
|
fprintf(f, "%s\n", data[i]);
|
|
|
|
else
|
|
|
|
deleted = 1;
|
2013-07-07 16:55:22 +02:00
|
|
|
}
|
2013-07-13 10:23:10 +02:00
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
generatepage(deleted ? "File deleted" : "Failed to delete file");
|
2013-07-07 16:55:22 +02:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|