X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fbitmapvalidator.cpp;h=12ba6de23475da02dfbf06740c3200818d53ad39;hb=HEAD;hp=68482c1a219fd1d3278a08349ade48df3cb8f51b;hpb=9b22dd53fe62e312c1647310b7ec43aa127090af;p=fms.git diff --git a/src/bitmapvalidator.cpp b/src/bitmapvalidator.cpp index 68482c1..12ba6de 100644 --- a/src/bitmapvalidator.cpp +++ b/src/bitmapvalidator.cpp @@ -1,27 +1,52 @@ #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(); + + if(data.size()==0) + { + return false; + } + + 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()); }