-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
115 lines (96 loc) · 2.03 KB
/
Copy pathutils.cpp
File metadata and controls
115 lines (96 loc) · 2.03 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
#include "utils.hpp"
map <string, int> userIDs;
vector<string> resources;
vector<string> approvals;
map<string, user_info> users;
int currentApprovals = -1;
string ttl;
/**
* @brief
*
* Function to read and store the userIds in the database from a given file
*
*
* @param filename - input file
*/
void read_userIDs(char *filename) {
fstream fin;
int n;
fin.open(filename, ios::in);
if (!fin.is_open()) {
fprintf(stderr, "Error opening file %s\n", filename);;
exit(1);
}
fin >> n;
for (int i = 0; i < n; i++) {
string name;
fin >> name;
userIDs[name] = 0;
}
fin.close();
}
/**
* @brief
*
* Function to read and store the resources in the database from a given file
*
*
* @param filename - input file
*/
void read_resources(char *filename) {
fstream fin;
int n;
fin.open(filename, ios::in);
if (!fin.is_open()) {
fprintf(stderr, "Error opening file %s\n", filename);;
exit(1);
}
fin >> n;
for (int i = 0; i < n; i++) {
string resource;
fin >> resource;
resources.push_back(resource);
}
fin.close();
}
/**
* @brief
*
* Function to read and store the approvals in the database from a given file
*
*
* @param filename - input file
*/
void read_approvals(char *filename) {
fstream fin;
fin.open(filename, ios::in);
if (!fin.is_open()) {
fprintf(stderr, "Error opening file %s\n", filename);;
exit(1);
}
while (!fin.eof()) {
string permissions;
fin >> permissions;
approvals.push_back(permissions);
}
fin.close();
}
/**
* @brief Function that stores the TTL value for the tokens. It reads them from
* a file or it uses the default value of 1.
*
*/
void read_ttl() {
fstream fin;
string input;
fin.open("readme", ios::in);
if (!fin.is_open()) {
ttl = "1";
} else {
while (!fin.eof()) {
fin >> input;
}
ttl = input;
fin.close();
}
}