Implemented validation #10

Merged
asdam9 merged 1 commits from 8-AddFilePost into master 2021-11-11 22:38:42 +00:00
1 changed files with 16 additions and 2 deletions
Showing only changes of commit 8ce9df1c01 - Show all commits

View File

@ -1,6 +1,7 @@
#define _GNU_SOURCE
#include <mysql/mysql.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <malloc.h>
@ -214,6 +215,19 @@ int AddFilePost(int authorID, char filePath[], MYSQL* con)
// Get first line
fgets(Buffer, BufferLength, FilePointer);
// Get the substrings Buffer[0:3] and Buffer[-6:-1]
// Buffer[BufferLength] is the same as "\0" but without warnings
int LineLength = strlen(Buffer);
char startTest[5] = {Buffer[0], Buffer[1], Buffer[2], Buffer[3], Buffer[BufferLength]};
char endTest[6] = {Buffer[LineLength - 6], Buffer[LineLength - 5], Buffer[LineLength - 4], Buffer[LineLength - 3], Buffer[LineLength - 2], Buffer[BufferLength]};
// Check that the firstline starts with "<h3>" and ends with "</h3>"
if (!(strcmp(startTest, "<h3>") == 0 && strcmp(endTest, "</h3>") == 0)) {
printf("%s What is this %s\n", startTest, endTest);
return -1;
}
// This is equivalent to Buffer = Buffer[3:-6]
// This is done to remove the <h3> tags
for (int i = 4; i < BufferLength; ++i) {
@ -957,7 +971,7 @@ int main(int argc, char *argv[])
//TogglePost(81, con);
//printf("%s\n", IsEnabled(81, con) ? "True" : "False");
//AddFilePost(1, "/home/adam/Documents/html/linuxenv.html", con);
BlogWrite(con);
//BlogWrite(con);
// =================================