Browse code

core: keep references to proto and port parts by parse_protohostport()

Daniel-Constantin Mierla authored on 30/03/2022 06:26:32
Showing 2 changed files
... ...
@@ -2271,11 +2271,14 @@ int parse_protohostport(str* ins, sr_phostp_t *r)
2271 2271
 	if (second) { /* 2 ':' found => check if valid */
2272 2272
 		if (parse_proto((unsigned char*)ins->s, first-ins->s, &r->proto)<0)
2273 2273
 			goto error_proto;
2274
+		r->sproto.s = ins->s;
2275
+		r->sproto.len = first-ins->s;
2274 2276
 
2275 2277
 		tmp.s=second+1;
2276 2278
 		tmp.len=(ins->s + ins->len) - tmp.s;
2277 2279
 
2278 2280
 		if (str2int(&tmp, (unsigned int *)&(r->port))<0) goto error_port;
2281
+		r->sport = tmp;
2279 2282
 
2280 2283
 		r->host.s=first+1;
2281 2284
 		r->host.len=(int)(second-r->host.s);
... ...
@@ -2288,10 +2291,13 @@ int parse_protohostport(str* ins, sr_phostp_t *r)
2288 2291
 		/* invalid port => it's proto:host */
2289 2292
 		if (parse_proto((unsigned char*)ins->s, first-ins->s, &r->proto)<0)
2290 2293
 			goto error_proto;
2294
+		r->sproto.s = ins->s;
2295
+		r->sproto.len = first-ins->s;
2291 2296
 		r->host.s=first+1;
2292 2297
 		r->host.len=(int)(p-r->host.s);
2293 2298
 	}else{
2294 2299
 		/* valid port => its host:port */
2300
+		r->sport = tmp;
2295 2301
 		r->host.s=ins->s;
2296 2302
 		r->host.len=(int)(first-r->host.s);
2297 2303
 	}
... ...
@@ -151,8 +151,10 @@ inline static struct socket_info* get_first_socket(void)
151 151
 
152 152
 /* structure to break down 'proto:host:port' */
153 153
 typedef struct _sr_phostp {
154
+	str sproto;
154 155
 	int proto;
155 156
 	str host;
157
+	str sport;
156 158
 	int port;
157 159
 } sr_phostp_t;
158 160