version 0.2.23
[fms.git] / src / bitmapvalidator.cpp
1 #include "../include/bitmapvalidator.h"\r
2 #include "../include/freenet/captcha/easybmp/EasyBMP.h"\r
3 \r
4 #include <sstream>\r
5 \r
6 const bool BitmapValidator::Validate(const std::vector<unsigned char> &data)\r
7 {\r
8         bool validated=false;\r
9         std::ostringstream tempname;\r
10         \r
11         tempname << "validatebmp-" << rand() << ".tmp";\r
12         FILE *outfile=fopen(tempname.str().c_str(),"w+b");\r
13         if(outfile)\r
14         {\r
15                 fwrite(&data[0],1,data.size(),outfile);\r
16                 fclose(outfile);\r
17                 \r
18                 BMP temp;\r
19                 if(temp.ReadFromFile(tempname.str().c_str()))\r
20                 {\r
21                         validated=true; \r
22                 }\r
23 \r
24                 unlink(tempname.str().c_str());\r
25                 \r
26         }\r
27         \r
28         return validated;\r
29 }\r