-
Notifications
You must be signed in to change notification settings - Fork 165
/
mp_recaptcha.h
executable file
·118 lines (105 loc) · 4.12 KB
/
mp_recaptcha.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* Copyright (C) 2012-2015 Doubango Telecom <http://www.doubango.org>
*
* This file is part of Open Source 'webrtc2sip' project
* <http://code.google.com/p/webrtc2sip/>
*
* 'webrtc2sip' is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 'webrtc2sip' is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 'webrtc2sip'.
*/
#if !defined(_MEDIAPROXY_RECAPTCHA_H_)
#define _MEDIAPROXY_RECAPTCHA_H_
#include "mp_config.h"
#include "mp_common.h"
#include "mp_net_transport.h"
#include <map>
struct thttp_url_s;
namespace webrtc2sip {
class MPRecaptchaTransport;
//
// MPRecaptcha
//
class MPRecaptcha : public MPObject
{
public:
MPRecaptcha(MPNetFd nFd, const char* pcAccountName, const char* pcAccountEmail, const char* pcResponse, const char* pcRemoteIP = NULL);
virtual ~MPRecaptcha();
virtual MP_INLINE const char* getObjectId() { return "MPRecaptcha"; }
virtual MP_INLINE const char* getResponse() { return m_pResponse; }
virtual MP_INLINE const char* getRemoteIP() { return m_pRemoteIP; }
virtual MP_INLINE const char* getAccountName() { return m_pAccountName; }
virtual MP_INLINE const char* getAccountEmail() { return m_pAccountEmail; }
virtual MP_INLINE MPNetFd getFd() { return m_nFd; }
virtual MP_INLINE bool isConnected() { return m_bConnected; }
virtual MP_INLINE void setConnected(bool bConnected) { m_bConnected = bConnected; }
virtual void setRemoteIP(const char* pcRemoteIP);
private:
char* m_pResponse;
char* m_pRemoteIP;
char* m_pAccountName;
char* m_pAccountEmail;
MPNetFd m_nFd;
bool m_bConnected;
};
//
// MPRecaptchaTransportCallback
//
class MPRecaptchaTransportCallback : public MPNetTransportCallback
{
public:
MPRecaptchaTransportCallback(const MPRecaptchaTransport* pcTransport);
virtual ~MPRecaptchaTransportCallback();
virtual MP_INLINE const char* getObjectId() { return "MPRecaptchaTransportCallback"; }
virtual bool onData(MPObjectWrapper<MPNetPeer*> oPeer, size_t &nConsumedBytes);
virtual bool onConnectionStateChanged(MPObjectWrapper<MPNetPeer*> oPeer);
private:
const MPRecaptchaTransport* m_pcTransport;
};
//
// MPRecaptchaValidationCallback
//
class MPRecaptchaValidationCallback: public MPObject
{
public:
MPRecaptchaValidationCallback() {}
virtual ~MPRecaptchaValidationCallback() {}
virtual MP_INLINE const char* getObjectId() { return "MPRecaptchaValidationCallback"; }
virtual bool onValidationEvent(bool bSucess, MPObjectWrapper<MPRecaptcha*> oRecaptcha) = 0;
};
//
// MPRecaptchaTransport
//
class MPRecaptchaTransport : public MPNetTransport
{
friend class MPRecaptchaTransportCallback;
public:
MPRecaptchaTransport(const char* pcVerifySiteUrl, const char* pcSecret);
virtual ~MPRecaptchaTransport();
virtual MP_INLINE const char* getObjectId() { return "MPRecaptchaTransport"; }
virtual MP_INLINE void setValidationCallback(MPObjectWrapper<MPRecaptchaValidationCallback*> oCallback) { m_oValidationCallback = oCallback; };
virtual bool validate(MPNetFd nLocalFd, const char* pcAccountName, const char* pcAccountEmail, const char* pcResponse);
private:
void insertRecaptcha(MPObjectWrapper<MPRecaptcha*> oRecaptcha);
void removeRecaptcha(MPNetFd nFd);
MPObjectWrapper<MPRecaptcha*> getRecaptchaFd(MPNetFd nFd);
bool sendRecaptcha(MPObjectWrapper<MPRecaptcha*> oRecaptcha);
private:
MPObjectWrapper<MPRecaptchaTransportCallback*> m_oCallback;
MPObjectWrapper<MPRecaptchaValidationCallback*> m_oValidationCallback;
std::map<MPNetFd, MPObjectWrapper<MPRecaptcha*> > m_Recaptchas;
char* m_pVerifySiteUrl;
char* m_pSecret;
struct thttp_url_s* m_pWrappedHttpUrl;
tsk_mutex_handle_t *m_pWrappedRecaptchasMutex;
};
}// namespace
#endif /* _MEDIAPROXY_RECAPTCHA_H_ */