blob: 55b48ca076e1a038f2f765838a1093508529c53a [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include "zte_web_interface.h"
2
3
4
5
6data_safe_result_type_t zte_Safe_isMacValid(char *str)
7{
8 int i, len = strlen(str);
9 if (len != 17)
10 return 0;
11
12 for (i = 0; i < 5; i++) {
13 if ((!isxdigit(str[i * 3])) || (!isxdigit(str[i * 3 + 1])) || (str[i * 3 + 2] != ':'))
14 return 0;
15 }
16 return (isxdigit(str[15]) && isxdigit(str[16])) ? 1 : 0;
17}
18
19
20data_safe_result_type_t zte_Safe_isIpValid(char *str)
21{
22 struct in_addr addr; /*lint !e565 !e1080*/
23 if ((! strcmp(T("any"), str)) || (! strcmp(T("any/0"), str)))
24 return 1;
25
26 if (!(inet_aton(str, &addr))) {
27 slog(MISC_PRINT, SLOG_DEBUG, "isIpValid(): %s is not a valid IP address.\n", str); /*lint !e26*/
28 return 0;
29 }
30 return 1;
31}
32
33data_safe_result_type_t zte_Safe_isNumOnly(char *str)
34{
35 int i, len = strlen(str);
36 for (i = 0; i < len; i++) {
37 if ((str[i] >= '0' && str[i] <= '9'))
38 continue;
39 return 0;
40 }
41 return 1;
42}
43
44
45data_safe_result_type_t zte_Safe_noSpecialChar(char *str)
46{
47 int i = 0;
48 int len = 0;
49 if (NULL == str) {
50 return 0;
51 }
52 len = strlen(str);
53 for (i = 0; i < len; i++) {
54 if (zte_Safe_valid_SpecialChar(str[i]) != 0) {
55 continue;
56 } else {
57 return 0;
58 }
59 }
60 return 1;
61
62}
63
64data_safe_result_type_t zte_Safe_noSpecialChar_other(char *str)
65{
66 int i = 0;
67 int len = 0;
68 if (NULL == str) {
69 return 0;
70 }
71 len = strlen(str);
72 for (i = 0; i < len; i++) {
73 if (zte_Safe_valid_SpecialChar_other(str[i]) != 0) {
74 continue;
75 } else {
76 return 0;
77 }
78 }
79 return 1;
80
81}
82
83
84data_safe_result_type_t zte_Safe_isStringOnly(char *str)
85{
86 int i = 0;
87 int len = 0;
88 if (NULL == str) {
89 return 0;
90 }
91 len = strlen(str);
92 for (i = 0; i < len; i++) {
93 if ((str[i] <= 'Z' && str[i] >= 'A')
94 || (str[i] <= 'z' && str[i] >= 'a')
95 )
96 continue;
97 else {
98 return 0;
99 }
100
101 }
102 return 1;
103}
104
105data_safe_result_type_t zte_Safe_isNumorStringOnly(char *str)
106{
107 int i = 0;
108 int len = 0;
109 if (NULL == str) {
110 return 0;
111 }
112 len = strlen(str);
113 for (i = 0; i < len; i++) {
114 if ((str[i] <= 'Z' && str[i] >= 'A') || (str[i] <= 'z' && str[i] >= 'a') || (str[i] <= '9' && str[i] >= '0'))
115 continue;
116 else {
117 return 0;
118 }
119
120 }
121 return 1;
122}
123
124int zte_Safe_valid_SpecialChar(char single_data)
125{
126 if (single_data == '"') return 0;
127 else if (single_data == '\'') return 0;
128 else if (single_data == '<') return 0;
129 else if (single_data == '>') return 0;
130 else if (single_data == '\\') return 0;
131 else return 1;
132}
133
134int zte_Safe_valid_SpecialChar_other(char single_data)
135{
136 if (single_data == '&') return 0;
137 else if (single_data == '<') return 0;
138 else if (single_data == '>') return 0;
139 else if (single_data == '\\') return 0;
140 else if (single_data == '\'') return 0;
141 else if (single_data == '/') return 0;
142 else return 1;
143}
144
145
146
147int zte_valid_length_str(char *string_s, int min, int max)/*lint !e123*/
148{
149 int str_len = 0;
150 str_len = strlen(string_s);
151 if (str_len < min || str_len > max) { /*lint !e123*/
152 return -1;
153 } else {
154 return 1;
155 }
156}
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171