-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlist.c
More file actions
149 lines (122 loc) · 3.5 KB
/
Copy pathlist.c
File metadata and controls
149 lines (122 loc) · 3.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "list.h"
peernode *peershead = NULL;
rfcdetailnode *rfcdetailhead = NULL;
int insertFrontPeerList(peernode* newnode){
if(peershead != NULL){
peernode* temp = peershead;
newnode->next = temp;
peershead = newnode;
}else{
peershead = newnode;
peershead->next = NULL;
}
}
int insertFrontrfcList(rfcdetailnode* newnode){
if(rfcdetailhead != NULL){
rfcdetailnode* temp = rfcdetailhead;
newnode->next = temp;
rfcdetailhead = newnode;
}else{
rfcdetailhead = newnode;
rfcdetailhead->next = NULL;
}
}
void printAll(){
peernode* temp = peershead;
printf("Peers : ");
while(temp != NULL){
printf("%s:%d\t",temp->hostname,temp->uploadportno);
temp = temp->next;
}
printf("\n");
rfcdetailnode* temp1 = rfcdetailhead;
printf("rfc's : \n");
while(temp1 != NULL){
printf("%d : %s : %s \n",temp1->rfcno,temp1->rfctitle,temp1->hostname);
temp1 = temp1->next;
}
printf("\n");
}
bool isHostAvailable(char *hostname){
peernode* temp = peershead;
while(temp != NULL){
if(strcmp(temp->hostname,hostname) == 0)
return true;
temp = temp->next;
}
return false;
}
rfcdetailnode* getList(){
return rfcdetailhead;
}
//Get hosts with rfcid
rfcdetailnode* getHostwithRFC(int rfcid){
rfcdetailnode* temp = rfcdetailhead;
rfcdetailnode* nodes = NULL;
rfcdetailnode* nodescont= NULL;
while(temp != NULL){
if(temp->rfcno == rfcid){
if(nodes == NULL){
nodes = (struct rfcdetailnode *)malloc(sizeof(rfcdetailnode));
nodes->rfcno = rfcid;
nodes->hostname=temp->hostname;
nodes->rfctitle=temp->rfctitle;
nodes->next = NULL;
}else{
nodescont = (struct rfcdetailnode *)malloc(sizeof(rfcdetailnode));
nodescont->rfcno = rfcid;
nodescont->hostname=temp->hostname;
nodescont->rfctitle=temp->rfctitle;
nodescont->next = nodes;
nodes = nodescont;
}
}
temp = temp->next;
}
if(nodescont == NULL)
return nodes;
else if(nodes == NULL)
return NULL;
else
return nodescont;
}
/*int main(){
printf("List test\n");
peernode *temp = malloc(sizeof(peernode));
temp->hostname="sys1";
insertFrontPeerList(temp);
peernode *temp2= malloc(sizeof(peernode));
temp2->hostname="sys2";
insertFrontPeerList(temp2);
printf("ishostavailable :%s\n",(isHostAvailable("sys1"))?"true":"false");
printf("ishostavailable :%s\n",(isHostAvailable("sys2"))?"true":"false");
printf("ishostavailable :%s\n",(isHostAvailable("sys3"))?"true":"false");
rfcdetailnode *temp1 = malloc(sizeof(rfcdetailnode));
temp1->rfcno =1;
temp1->rfctitle = "Test";
temp1->hostname = "sys1";
insertFrontrfcList(temp1);
rfcdetailnode *temp3 = malloc(sizeof(rfcdetailnode));
temp3->rfcno =2;
temp3->rfctitle = "choke";
temp3->hostname = "sys2";
insertFrontrfcList(temp3);
temp3 = malloc(sizeof(rfcdetailnode));
temp3->rfcno =2;
temp3->rfctitle = "choke";
temp3->hostname = "sys1";
insertFrontrfcList(temp3);
temp3 = malloc(sizeof(rfcdetailnode));
temp3->rfcno =3;
temp3->rfctitle = "Test";
temp3->hostname = "sys1";
insertFrontrfcList(temp3);
printAll();
rfcdetailnode* tempx = getList();
printf("Nodes : \n");
while(tempx != NULL){
printf("%d : %s : %s \n",tempx->rfcno,tempx->rfctitle,tempx->hostname);
tempx = tempx->next;
}
return 0;
}*/