-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.cpp
More file actions
76 lines (55 loc) · 1.5 KB
/
command.cpp
File metadata and controls
76 lines (55 loc) · 1.5 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
#include "command.h"
using namespace BankOfEuler;
namespace BankOfEuler {
Command *read_command(FILE *fp) {
unsigned int magic = read_int32(fp);
Command *com = NULL;
#undef H
#define H(x) case x::magic: com = new x; break
switch (magic) {
H(MergeCommand);
H(CheckCommand);
H(SplitCommand);
}
#undef H
assert(com);
com->read(fp, 0);
return com;
}
}
bool MergeCommand::authorize(CTX *ctx, const AuthorizeCertificate *acert, unsigned int n) {
int got_abc = 0;
//fprintf(stderr, "adir = %s\n", adir.c_str());
//fprintf(stderr, "bdir = %s\n", bdir.c_str());
//fprintf(stderr, "cdir = %s\n", cdir.c_str());
//fprintf(stderr, "acert[0].gx = %s\n", acert[0].gx.c_str());
for (unsigned int i = 0; i < n && got_abc != 7; ++i) {
if (acert[i].gx == adir)
got_abc |= 1;
if (acert[i].gx == bdir)
got_abc |= 2;
if (acert[i].gx == cdir)
got_abc |= 4;
}
return (got_abc == 7);
}
bool SplitCommand::authorize(CTX *ctx, const AuthorizeCertificate *acert, unsigned int n) {
int got_abc = 0;
for (unsigned int i = 0; i < n && got_abc != 7; ++i) {
if (acert[i].gx == adir)
got_abc |= 1;
if (acert[i].gx == bdir)
got_abc |= 2;
if (acert[i].gx == cdir)
got_abc |= 4;
}
return (got_abc == 7);
}
bool CheckCommand::authorize(CTX *ctx, const AuthorizeCertificate *acert, unsigned int n) {
int got_abc = 0;
for (unsigned int i = 0; i < n && got_abc != 1; ++i) {
if (acert[i].gx == adir)
got_abc |= 1;
}
return (got_abc == 1);
}