Working on regex and validator

This commit is contained in:
2017-09-04 14:59:13 -05:00
parent ba44a85419
commit 07957aff00
2 changed files with 29 additions and 3 deletions

View File

@@ -1,11 +1,11 @@
/*
Compiler: g++
Flags: -static-libgcc -static-libstdc++ -lws2_32
Flags: -std=c++11 -static-libgcc -static-libstdc++ -lws2_32
TODO:
Do not send auto reply
Fix regex validation, should be 16 character hexadecimal starting with e004
Fix validation for file checker file
Change card0.txt file based on information given by client
*/
#include <iostream>
@@ -13,6 +13,7 @@ Change card0.txt file based on information given by client
#include "argh.h"
#include <winsock2.h>
#include <stdio.h>
#include <regex>
#pragma comment(lib,"ws2_32.lib") //Winsock Library
@@ -229,6 +230,31 @@ int main (int argc, char* argv[])
//add null character, if you want to use with printf/puts or other string handling functions
buffer[valread] = '\0';
printf("%s:%d - %s \n" , inet_ntoa(address.sin_addr) , ntohs(address.sin_port), buffer);
// the 'buffer' is the string to use to edit our card0.txt file
// check if the check file exists
//if(std::ifstream(check))
//{
// check file exists, rewrite
// regex to validate buffer is a e004 hex number
std::regex cardRegex("[eE]004[0-9a-fA-F]{12}");
if(std::regex_match(buffer, cardRegex))
{
std::cout << "Data recieved is a valid game card" << std::endl;
}
else
{
std::cout << "Data recieved is not a valid game card" << std::endl;
}
//}
//else
//{
// no check file
// std::cout << "No check file! Will not re-write: " << file << std::endl;
//}
send( s , buffer , valread , 0 );
}
}

Binary file not shown.