-
Notifications
You must be signed in to change notification settings - Fork 0
/
roles.c
81 lines (71 loc) · 1.39 KB
/
roles.c
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
/*
*
* File: roles.c
*
* Description: a function to set the role of nodes and a function
* to know the default action within the DIR net.
*
* By <a href=ihttps://github.com/Eidonko>Eidon@tutanota.com</a>
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "dirnet.h"
#include "rcode.h"
/* returns the number of roles assigned within the DIR net */
int DIR_Roles(char *roles)
{
char *fname = RCODE_FILE;
FILE *f;
rcode_t r;
int n;
f = fopen(fname, "r+b");
/* added v1.1 */
if (f == NULL)
{
char fname2[80], *path;
path = getenv("EFTOS_HOME");
if (path == NULL)
return(0);
sprintf(fname2, "%s/%s", path, fname);
f = fopen(fname2, "r+b");
if (f == NULL)
return(0);
}
/* end v1.1 */
n = 0;
while ( fread(&r, sizeof(r), 1, f) > 0 )
{
if (r[0] == R_SET_ROLE)
{
roles [ r[1] ] = (r[2]==R_AGENT)? DIR_AGENT :
DIR_BACKUP;
n++;
}
else
if (r[0] == R_FALSE) /* stop at the first FALSE statement */
break;
}
fclose(f);
return (n);
}
/* returns R_DA_IS_KILL or R_DA_IS_RESTART on success, and 0 in case of failure */
int DIR_Default_Action()
{
char *fname = RCODE_FILE;
FILE *f;
rcode_t r;
int n;
f = fopen(fname, "r+b");
n = 0;
while ( fread(&r, sizeof(r), 1, f) > 0 )
{
if (r[0] == R_SET_DEF_ACT)
{
return (r[1]);
}
}
fclose(f);
return (0);
}
/* eof roles.c */