version 0.2.23
[fms.git] / src / bitmapvalidator.cpp
diff --git a/src/bitmapvalidator.cpp b/src/bitmapvalidator.cpp
new file mode 100644 (file)
index 0000000..68482c1
--- /dev/null
@@ -0,0 +1,29 @@
+#include "../include/bitmapvalidator.h"\r
+#include "../include/freenet/captcha/easybmp/EasyBMP.h"\r
+\r
+#include <sstream>\r
+\r
+const bool BitmapValidator::Validate(const std::vector<unsigned char> &data)\r
+{\r
+       bool validated=false;\r
+       std::ostringstream tempname;\r
+       \r
+       tempname << "validatebmp-" << rand() << ".tmp";\r
+       FILE *outfile=fopen(tempname.str().c_str(),"w+b");\r
+       if(outfile)\r
+       {\r
+               fwrite(&data[0],1,data.size(),outfile);\r
+               fclose(outfile);\r
+               \r
+               BMP temp;\r
+               if(temp.ReadFromFile(tempname.str().c_str()))\r
+               {\r
+                       validated=true; \r
+               }\r
+\r
+               unlink(tempname.str().c_str());\r
+               \r
+       }\r
+       \r
+       return validated;\r
+}\r