Implemented validation #10
16
BlogDB.c
16
BlogDB.c
|
|
@ -1,6 +1,7 @@
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <mysql/mysql.h>
|
#include <mysql/mysql.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|
@ -214,6 +215,19 @@ int AddFilePost(int authorID, char filePath[], MYSQL* con)
|
||||||
// Get first line
|
// Get first line
|
||||||
fgets(Buffer, BufferLength, FilePointer);
|
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 equivalent to Buffer = Buffer[3:-6]
|
||||||
// This is done to remove the <h3> tags
|
// This is done to remove the <h3> tags
|
||||||
for (int i = 4; i < BufferLength; ++i) {
|
for (int i = 4; i < BufferLength; ++i) {
|
||||||
|
|
@ -957,7 +971,7 @@ int main(int argc, char *argv[])
|
||||||
//TogglePost(81, con);
|
//TogglePost(81, con);
|
||||||
//printf("%s\n", IsEnabled(81, con) ? "True" : "False");
|
//printf("%s\n", IsEnabled(81, con) ? "True" : "False");
|
||||||
//AddFilePost(1, "/home/adam/Documents/html/linuxenv.html", con);
|
//AddFilePost(1, "/home/adam/Documents/html/linuxenv.html", con);
|
||||||
BlogWrite(con);
|
//BlogWrite(con);
|
||||||
|
|
||||||
// =================================
|
// =================================
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue