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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
#include "HTUtils.h"
#include "tcp.h"
#include "LYGlobalDefs.h"
#include "LYUtils.h"
#include "LYSignal.h"
#include "LYTraversal.h"
#include "LYexit.h"
#include "LYLeaks.h"
/* routines to handle special traversal feature */
PUBLIC BOOLEAN lookup ARGS1(char *,target)
{
FILE *ifp;
char buffer[200], line[200];
if ((ifp = fopen(TRAVERSE_FILE,"r")) == NULL) {
if ((ifp = fopen(TRAVERSE_FILE,"w")) == NULL) {
perror("unable to open or create a traversal file");
#ifndef NOSIGHUP
(void) signal(SIGHUP, SIG_DFL);
#endif /* NOSIGHUP */
(void) signal(SIGTERM, SIG_DFL);
#ifndef VMS
(void) signal(SIGINT, SIG_DFL);
#endif /* !VMS */
#ifdef SIGTSTP
if (no_suspend)
(void) signal(SIGTSTP,SIG_DFL);
#endif /* SIGTSTP */
exit(-1);
} else {
fclose(ifp);
return(FALSE);
}
}
sprintf(line,"%s\n",target);
while(fgets(buffer, 200, ifp) != NULL) {
if (STREQ(line,buffer)) {
fclose(ifp);
return(TRUE);
}
} /* end while */
fclose(ifp);
return(FALSE);
}
PUBLIC void add_to_table ARGS1(char *,target)
{
FILE *ifp;
if ((ifp = fopen(TRAVERSE_FILE,"a+")) == NULL) {
perror("unable to open traversal file");
#ifndef NOSIGHUP
(void) signal(SIGHUP, SIG_DFL);
#endif /* NOSIGHUP */
(void) signal(SIGTERM, SIG_DFL);
#ifndef VMS
(void) signal(SIGINT, SIG_DFL);
#endif /* !VMS */
#ifdef SIGTSTP
if (no_suspend)
(void) signal(SIGTSTP,SIG_DFL);
#endif /* SIGTSTP */
exit(-1);
}
fprintf(ifp,"%s\n",target);
fclose(ifp);
}
PUBLIC void add_to_traverse_list ARGS2(char *,fname, char *,prev_link_name)
{
FILE *ifp;
if ((ifp = fopen(TRAVERSE_FOUND_FILE,"a+")) == NULL) {
perror("unable to open traversal found file");
#ifndef NOSIGHUP
(void) signal(SIGHUP, SIG_DFL);
#endif /* NOSIGHUP */
(void) signal(SIGTERM, SIG_DFL);
#ifndef VMS
(void) signal(SIGINT, SIG_DFL);
#endif /* !VMS */
#ifdef SIGTSTP
if (no_suspend)
(void) signal(SIGTSTP,SIG_DFL);
#endif /* SIGTSTP */
exit(-1);
}
fprintf(ifp,"%s %s\n",fname, prev_link_name);
fclose(ifp);
}
PUBLIC void dump_traversal_history NOARGS
{
int x;
FILE *ifp;
if (nhist <= 0)
return;
if ((ifp = fopen(TRAVERSE_FILE,"a+")) == NULL) {
perror("unable to open traversal file");
return;
}
fprintf(ifp, "\n\nTRAVERSAL WAS INTERUPTED\n\n\
here is a list of the history stack so that you may rebuild\n\n");
for (x = nhist-1; x >= 0; x--) {
fprintf(ifp,"%s %s\n", history[x].title, history[x].address);
}
fclose(ifp);
}
PUBLIC void add_to_reject_list ARGS1(char *,target)
{
FILE *ifp;
if ((ifp = fopen(TRAVERSE_REJECT_FILE,"a+")) == NULL) {
perror("unable to open reject file");
#ifndef NOSIGHUP
(void) signal(SIGHUP, SIG_DFL);
#endif /* NOSIGHUP */
(void) signal(SIGTERM, SIG_DFL);
#ifndef VMS
(void) signal(SIGINT, SIG_DFL);
#endif /* !VMS */
#ifdef SIGTSTP
if (no_suspend)
(void) signal(SIGTSTP,SIG_DFL);
#endif /* SIGTSTP */
exit(-1);
}
fprintf(ifp,"%s\n",target);
fclose(ifp);
}
/* there need not be a reject file, so if it doesn't open, just return
FALSE, meaning "target not in reject file" If the last character in
a line in a reject file is "*", then also reject if target matches up to
that point in the string
Blank lines are ignored
Lines that contain just a * are allowed, but since they mean "reject
everything" it shouldn't come up much!
*/
PUBLIC BOOLEAN lookup_reject ARGS1(char *,target)
{
FILE *ifp;
char buffer[200], line[200], ch;
int frag;
if ((ifp = fopen(TRAVERSE_REJECT_FILE,"r")) == NULL){
return(FALSE);
}
sprintf(line,"%s\n",target);
while (fgets(buffer, 200, ifp) != NULL) {
frag = strlen(buffer) - 1; /* real length, minus trailing null */
ch = buffer[frag - 1]; /* last character in buffer */
if (frag > 0) { /* if not an empty line */
if (ch == '*') {
if (frag == 1 || ((strncmp(line,buffer,frag - 1)) == 0)) {
fclose(ifp);
return(TRUE);
}
} else { /* last character = "*" test */
if (STREQ(line,buffer)) {
fclose(ifp);
return(TRUE);
}
} /* last character = "*" test */
} /* frag >= 0 */
} /* end while */
fclose(ifp);
return(FALSE);
}
|