forked from Novators/libsqrl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqrlAction.cpp
More file actions
127 lines (109 loc) · 2.96 KB
/
SqrlAction.cpp
File metadata and controls
127 lines (109 loc) · 2.96 KB
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
119
120
121
122
123
124
125
126
127
/** \file SqrlAction.cpp
*
* \author Adam Comley
*
* This file is part of libsqrl. It is released under the MIT license.
* For more details, see the LICENSE file included with this package.
**/
#include "sqrl_internal.h"
#include "sqrl.h"
#include "SqrlAction.h"
#include "SqrlUri.h"
#include "SqrlUser.h"
#include "SqrlClient.h"
namespace libsqrl
{
struct Sqrl_action_List
{
SqrlAction *action;
struct Sqrl_action_List *next;
};
struct Sqrl_action_List *SQRL_action_LIST = NULL;
SqrlAction::SqrlAction()
: user( NULL ),
uri( NULL ),
tag( NULL ),
state( 0 ),
status( SQRL_ACTION_RUNNING ),
shouldCancel( false ) {
SqrlClient *client = SqrlClient::getClient();
if( !client ) {
exit( 1 );
}
SQRL_MUTEX_LOCK( &client->actionMutex )
client->actions.push_back( this );
SQRL_MUTEX_UNLOCK( &client->actionMutex )
}
SqrlAction::~SqrlAction() {
SqrlClient *client = SqrlClient::getClient();
if( client ) {
client->actions.erase( this );
}
this->onRelease();
if( this->uri ) {
delete this->uri;
}
}
int SqrlAction::retActionComplete( int status ) {
this->status = status;
SqrlClient::getClient()->callActionComplete( this );
return SQRL_ACTION_STATE_DELETE;
}
bool SqrlAction::exec() {
if( this->state == SQRL_ACTION_STATE_DELETE ) {
delete this;
return false;
} else {
this->state = this->run( this->state );
SqrlClient *client = SqrlClient::getClient();
if( client ) {
client->actions.push_back( this );
}
return true;
}
}
void SqrlAction::onRelease() {
}
void SqrlAction::onProgress( int progress ) {
SqrlClient *client = SqrlClient::getClient();
client->callProgress( this, progress );
}
void SqrlAction::setUser( SqrlUser *u ) {
this->user = u;
}
SqrlUser *SqrlAction::getUser() {
return this->user;
}
SqrlUri *SqrlAction::getUri() {
return this->uri;
}
void SqrlAction::setUri( SqrlUri *uri ) {
if( this->uri ) {
delete this->uri;
}
this->uri = new SqrlUri( uri );
}
void * SqrlAction::getTag() {
return this->tag;
}
void SqrlAction::setTag( void * tag ) {
this->tag = tag;
}
void SqrlAction::authenticate( Sqrl_Credential_Type credentialType, const char *credential, size_t length ) {
if( !this->user ) return;
switch( credentialType ) {
case SQRL_CREDENTIAL_HINT:
break;
case SQRL_CREDENTIAL_PASSWORD:
break;
case SQRL_CREDENTIAL_NEW_PASSWORD:
this->user->setPassword( credential, length );
break;
case SQRL_CREDENTIAL_RESCUE_CODE:
break;
}
}
void SqrlAction::cancel() {
this->shouldCancel = true;
}
}