9 questions_t::iterator i
;
11 for (i
= questions
.begin() ; i
!= questions
.end() ; i
++ ) {
16 bool captcha::docaptcha(imcontact c
)
18 if (captchas
.find(c
) == captchas
.end()) {
21 captchas_t::iterator i
;
31 void captcha::donecaptcha(imcontact c
)
36 bool captcha::checkcaptcha(imcontact c
, string answer
)
38 captchas_t::iterator i
;
43 if (i
!= captchas
.end()) {
45 if (ca
->expiry
< time(NULL
)) {
49 return (ca
->answers
->find(lo(answer
)) != ca
->answers
->end());
55 string
captcha::getcaptchaquestion(imcontact c
) {
59 t
= questions
[(int)(questions
.size() * (rand() / (RAND_MAX
+ 1.0)))];
60 ca
.answers
= &t
->answers
;
61 ca
.expiry
= conf
.getcaptchatimeout() * 60 + time(NULL
);
67 void captcha::addquestion(string data
) {
69 string::size_type pos
;
72 pos
= data
.find("//");
73 if (pos
== string::npos
) {
77 q
->question
= data
.substr(0, pos
);
78 data
.erase(0, pos
+ 2);
80 while (data
.length()) {
81 pos
= data
.find("::");
82 if (pos
== string::npos
) {
83 q
->answers
.insert(lo(data
));
85 } else if (pos
== 0) {
88 q
->answers
.insert(lo(data
.substr(0, pos
)));
89 data
.erase(0, pos
+ 2);
93 if (q
->answers
.empty()) {
96 questions
.push_back(q
);
101 bool captcha::empty()
103 return questions
.empty();
106 unsigned int captcha::size()
108 return questions
.size();