-
Notifications
You must be signed in to change notification settings - Fork 257
/
Copy pathgnb_conf.c
176 lines (110 loc) · 3.21 KB
/
gnb_conf.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
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
/*
Copyright (C) gnbdev
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <limits.h>
#include <stddef.h>
#include <string.h>
#include "gnb_conf_type.h"
#include "gnb.h"
char * check_domain_name(char *host_string){
if ( NULL != strchr(host_string, ':') ) {
return NULL;
}
int i;
for( i=0; i<NAME_MAX; i++ ) {
if ( '\0' == host_string[i] ) {
return NULL;
}
if ( '.' == host_string[i] ) {
continue;
}
if ( host_string[i] >= 'a' && host_string[i] <= 'z' ) {
return host_string;
}
}
return NULL;
}
/*判断 配置行第二列是ip地址 还是node id*/
char * check_node_route(char *config_line_string){
if ( NULL != strchr(config_line_string, ':') || NULL != strchr(config_line_string, '.') ) {
return NULL;
}
return config_line_string;
}
int gnb_test_field_separator(char *config_string){
int i;
for ( i=0; i<strlen(config_string); i++ ) {
if ( '/' == config_string[i] ) {
return GNB_CONF_FIELD_SEPARATOR_TYPE_SLASH;
} else if ( '|' == config_string[i] ) {
return GNB_CONF_FIELD_SEPARATOR_TYPE_VERTICAL;
}
}
return GNB_CONF_FIELD_SEPARATOR_TYPE_ERROR;
}
/*
return value:
0 port
4 ipv4:port
6 [ipv6:port]
*/
int check_listen_string(char *listen_string){
if ( '[' == listen_string[0] ) {
return 6;
}
int i;
for ( i=0; i<strlen(listen_string); i++ ) {
if ( ':' == listen_string[i] ) {
return 4;
}
}
return 0;
}
void gnb_setup_listen_addr_port(char *listen_address_string, uint16_t *port_ptr, char *sockaddress_string, int addr_type){
int i;
char *host_string_end;
char *p;
int sockaddress_string_len;
sockaddress_string_len = strlen(sockaddress_string);
char *pb;
if ( AF_INET6 == addr_type ) {
if ( '[' != sockaddress_string[0] ) {
return;
}
host_string_end = sockaddress_string+1;
pb = sockaddress_string+1;
sockaddress_string_len -= 1;
} else {
host_string_end = sockaddress_string;
pb = sockaddress_string;
}
p = pb;
for ( i=0; i<sockaddress_string_len; i++ ) {
if ( ':' == *p ) {
host_string_end = p;
}
p++;
}
p = pb;
for ( i=0; i<sockaddress_string_len; i++ ) {
if( p == host_string_end ) {
break;
}
listen_address_string[i] = *p;
p++;
}
listen_address_string[i] = '\0';
p++;
*port_ptr = strtoul(p, NULL, 10);
return;
}