X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fbitmapvalidator.cpp;h=c2a4a3c7cca47d8e71981f03e270c2c63fc064be;hb=f8c0410b12183ecb40aafbb44086fa146b25b528;hp=68482c1a219fd1d3278a08349ade48df3cb8f51b;hpb=9b22dd53fe62e312c1647310b7ec43aa127090af;p=fms.git diff --git a/src/bitmapvalidator.cpp b/src/bitmapvalidator.cpp index 68482c1..c2a4a3c 100644 --- a/src/bitmapvalidator.cpp +++ b/src/bitmapvalidator.cpp @@ -1,27 +1,47 @@ #include "../include/bitmapvalidator.h" #include "../include/freenet/captcha/easybmp/EasyBMP.h" +#include + #include +#include + +BitmapValidator::BitmapValidator():m_maxwidth(-1),m_maxheight(-1) +{ + +} + +BitmapValidator::~BitmapValidator() +{ + +} const bool BitmapValidator::Validate(const std::vector &data) { bool validated=false; - std::ostringstream tempname; - - tempname << "validatebmp-" << rand() << ".tmp"; - FILE *outfile=fopen(tempname.str().c_str(),"w+b"); + std::string tempname=Poco::TemporaryFile::tempName(); + + FILE *outfile=fopen(tempname.c_str(),"w+b"); if(outfile) { fwrite(&data[0],1,data.size(),outfile); fclose(outfile); BMP temp; - if(temp.ReadFromFile(tempname.str().c_str())) + if(temp.ReadFromFile(tempname.c_str())) { - validated=true; + validated=true; + if(m_maxwidth!=-1 && temp.TellWidth()>m_maxwidth) + { + validated=false; + } + if(m_maxheight!=-1 && temp.TellHeight()>m_maxheight) + { + validated=false; + } } - unlink(tempname.str().c_str()); + unlink(tempname.c_str()); }