-
Notifications
You must be signed in to change notification settings - Fork 0
/
strip.c
151 lines (132 loc) · 3.23 KB
/
strip.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
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
/* (c) Yves Lafon <[email protected]> */
/* */
/* $Id: strip.c,v 1.2 2007/07/03 14:02:58 ylafon Exp $ */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "defs.h"
#include "strip.h"
#include "match.h"
int IsValidName(addr)
char *addr;
{
int is_ok;
char *tmp;
is_ok = TRUE;
for (tmp=addr;is_ok && *tmp; tmp++)
is_ok = (*tmp>='0' && *tmp<= '9') || (*tmp>='a' && *tmp<= 'z') ||
(*tmp>='A' && *tmp<= 'Z') || (*tmp == '.') || (*tmp == '-');
return is_ok;
}
int IsIp(addr)
char *addr;
{
int is_ok, nb_dot;
char *tmp;
is_ok = TRUE;
nb_dot = 0;
for (tmp=addr;is_ok && *tmp; tmp++) {
is_ok = ((*tmp>='0') && (*tmp<= '9')) || (*tmp == '.');
nb_dot += (*tmp == '.');
}
is_ok *= (nb_dot == 3);
return is_ok;
}
int IsNumeric(raw_addr)
char *raw_addr;
{
int num_ok;
int is_really_num;
char *tmp;
num_ok = TRUE;
is_really_num = FALSE;
tmp = raw_addr;
while (*tmp && (*tmp!='@')) /* skip login */
tmp++;
for (tmp++;num_ok && *tmp; tmp++) {
num_ok=((*tmp>47)&&(*tmp<58))||*tmp=='*'||*tmp=='.';
is_really_num +=((*tmp>47)&&(*tmp<58));
}
return(num_ok&&is_really_num);
}
void Strip(raw_addr, stripped_addr)
char *raw_addr,*stripped_addr;
{
char *tmp_raw,*tmp_strip;
int i;
tmp_strip = stripped_addr;
*tmp_strip++='*';
tmp_raw = raw_addr;
for (i=0; i<USER_PREFIX_NUM; i++)
if (*raw_addr == USER_PREFIXES[i])
tmp_raw = raw_addr + 1;
i = 0;
while (*tmp_raw && *tmp_raw!='@' && (i < MAX_LOGIN_LENGTH)) {
*tmp_strip++=*tmp_raw++;
i++;
}
if (*tmp_raw!='@' && (i == MAX_LOGIN_LENGTH)) {
*tmp_strip++='*';
while (*tmp_raw && *tmp_raw!='@')
tmp_raw++;
}
*tmp_strip++=*tmp_raw++;
*tmp_strip++='*';
while (*tmp_raw && *tmp_raw!='.')
tmp_raw++;
while (*tmp_raw)
*tmp_strip++=*tmp_raw++;
*tmp_strip=0;
}
void StripNumeric(raw, stripped)
char *raw, *stripped;
{
char *tmp_raw,*tmp_strip, *tmp_select;
int net_class;
char ip_select[64];
int i;
tmp_strip = stripped;
*tmp_strip++='*';
tmp_raw = raw;
for (i=0; i<USER_PREFIX_NUM; i++)
if (*raw == USER_PREFIXES[i])
tmp_raw = raw + 1;
i = 0;
while (*tmp_raw && *tmp_raw!='@' && (i < MAX_LOGIN_LENGTH)) {
*tmp_strip++=*tmp_raw++;
i++;
}
if (*tmp_raw!='@' && (i == MAX_LOGIN_LENGTH)) {
*tmp_strip++='*';
while (*tmp_raw && *tmp_raw!='@')
tmp_raw++;
}
if (*tmp_raw=='@')
*tmp_strip++=*tmp_raw++;
tmp_select = ip_select;
while (*tmp_raw && (*tmp_raw!='.'))
*tmp_select++ = *tmp_strip++ = *tmp_raw++;
*tmp_select = 0;
net_class = atoi(ip_select);
if (net_class<ENDCLASS_A)
strcpy(tmp_strip,".*.*.*");
else
if (net_class<ENDCLASS_B) {
*tmp_strip++ = *tmp_raw++;
while (*tmp_raw && (*tmp_raw!='.'))
*tmp_strip++ = *tmp_raw++;
strcpy(tmp_strip,".*.*");
} else
if (net_class<ENDCLASS_C) {
*tmp_strip++ = *tmp_raw++;
while (*tmp_raw && (*tmp_raw!='.'))
*tmp_strip++ = *tmp_raw++;
*tmp_strip++ = *tmp_raw++;
while (*tmp_raw && (*tmp_raw!='.'))
*tmp_strip++ = *tmp_raw++;
strcpy(tmp_strip,".*");
}
else
while (*tmp_raw)
*tmp_strip++ = *tmp_raw++;
}