-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
executable file
·112 lines (99 loc) · 2.28 KB
/
Copy pathutils.cpp
File metadata and controls
executable file
·112 lines (99 loc) · 2.28 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
#include "utils.hpp"
#include <sstream>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
char *generate_access_token(char *clientIdToken)
{
char *token = (char *)malloc(TOKEN_LEN * sizeof(char *));
int i, key, used[TOKEN_LEN];
int rotationIndex = TOKEN_LEN;
memset(used, 0, TOKEN_LEN * sizeof(int));
for (i = 0; i < TOKEN_LEN; i++)
{
do
{
key = rand() % rotationIndex;
} while (used[key] == 1);
token[i] = clientIdToken[key];
used[key] = 1;
}
token[TOKEN_LEN] = '\0';
return token;
}
vector<string> split(const string &s, char delim)
{
vector<string> tokens;
stringstream ss(s);
string token;
while (getline(ss, token, delim))
{
tokens.push_back(token);
}
return tokens;
}
void load_ids(char *path, vector<string> &userIDs)
{
ifstream fin(path);
if (!fin.is_open())
{
cerr << "Error opening file" << endl;
exit(1);
}
int n;
fin >> n;
string token;
for (int i = 0; i < n; i++)
{
fin >> token;
userIDs.push_back(token);
}
fin.close();
}
void load_resource(char *path, vector<string> &resources)
{
ifstream fin(path);
if (!fin.is_open())
{
cerr << "Error opening file" << endl;
exit(1);
}
int n;
fin >> n;
string token;
for (int i = 0; i < n; i++)
{
fin >> token;
resources.push_back(token);
}
fin.close();
}
void load_approvals(char *path, vector<vector<pair<string, string>>> &approvals)
{
ifstream fin(path);
if (!fin.is_open())
{
cerr << "Error opening file" << endl;
exit(1);
}
string line;
while (getline(fin, line))
{
stringstream ss(line);
string token1, token2;
vector<pair<string, string>> line_approval;
while (getline(ss, token1, ','))
{
getline(ss, token2, ',');
line_approval.push_back({token1, token2});
}
if (line_approval.size() > 0)
{
approvals.push_back(line_approval);
}
}
fin.close();
}