Merge pull request 'Implemented validation' (#10) from 8-AddFilePost into master
Reviewed-on: #10
This commit is contained in:
commit
e9ebc640e7
18
BlogDB.c
18
BlogDB.c
|
|
@ -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,8 +971,8 @@ 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);
|
||||
|
||||
// =================================
|
||||
|
||||
exit(0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue