diff options
Diffstat (limited to 'src/captcha.cpp')
-rw-r--r-- | src/captcha.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/captcha.cpp b/src/captcha.cpp new file mode 100644 index 0000000..2d44ebc --- /dev/null +++ b/src/captcha.cpp @@ -0,0 +1,44 @@ +#include "captcha.hpp" + +#include <b64/encode.h> +#include <sstream> + +#define GIFSIZE 17646 +extern "C" { + const int gifsize = GIFSIZE; + void captcha( unsigned char im[70*200], unsigned char l[6]); + void makegif(unsigned char im[70*200], unsigned char gif[gifsize]); +} + +struct captcha generateCaptcha( ) +{ + struct captcha c; + unsigned char l[6]; + unsigned char *im = new unsigned char[70*200]; + unsigned char *gif = new unsigned char[gifsize]; + + captcha( im, l ); + + c.text = std::string( (char *)l ); + + std::ostringstream raws( std::stringstream::out | std::stringstream::binary ); + makegif( im, gif ); + raws.write( (char *)gif, gifsize ); + std::string raw = raws.str( ); + + std::istringstream in( std::ios_base::in | std::ios_base::binary ); + in.str( raw ); + + base64::encoder E; + std::string base_s; + base_s.reserve( 3 * gifsize ); + std::ostringstream base( base_s, std::stringstream::out | std::stringstream::binary ); + E.encode( in, base ); + c.base64 = base.str( ); + + delete gif; + delete im; + + return c; +} + |