src/server/daemon/httprequest.c

changeset 397
f202a655f4c2
parent 396
77d81f2bb9f7
child 407
78af44222463
equal deleted inserted replaced
396:77d81f2bb9f7 397:f202a655f4c2
162 162
163 // the session needs the current server configuration 163 // the session needs the current server configuration
164 sn->config = request->connection->listener->cfg; 164 sn->config = request->connection->listener->cfg;
165 165
166 // add ip to sn->client pblock 166 // add ip to sn->client pblock
167 char ip_str[INET_ADDRSTRLEN];
168 // TODO: ipv6
169 if(request->connection->addr_type == CONN_ADDR_IPV4) { 167 if(request->connection->addr_type == CONN_ADDR_IPV4) {
168 char ip_str[INET_ADDRSTRLEN];
170 if(inet_ntop( 169 if(inet_ntop(
171 AF_INET, 170 AF_INET,
172 &request->connection->address.address_v4.sin_addr, 171 &request->connection->address.address_v4.sin_addr,
173 ip_str, 172 ip_str,
174 INET_ADDRSTRLEN) != NULL) 173 INET_ADDRSTRLEN) != NULL)
175 { 174 {
176 pblock_kvinsert(pb_key_ip, ip_str, INET_ADDRSTRLEN, sn->sn.client); 175 pblock_kvinsert(pb_key_ip, ip_str, INET_ADDRSTRLEN, sn->sn.client);
176 }
177 } else if(request->connection->addr_type == CONN_ADDR_IPV6) {
178 char ip_str[INET6_ADDRSTRLEN];
179 if(inet_ntop(
180 AF_INET6,
181 &request->connection->address.address_v6.sin6_addr,
182 ip_str,
183 INET6_ADDRSTRLEN) != NULL)
184 {
185 pblock_kvinsert(pb_key_ip, ip_str, INET6_ADDRSTRLEN, sn->sn.client);
177 } 186 }
178 } 187 }
179 188
180 // init NSAPI request structure 189 // init NSAPI request structure
181 if(request_initialize(pool, request, rq) != 0) { 190 if(request_initialize(pool, request, rq) != 0) {
340 349
341 // get host and port 350 // get host and port
342 char *hosthdr = pblock_findkeyval(pb_key_host, rq->rq.headers); 351 char *hosthdr = pblock_findkeyval(pb_key_host, rq->rq.headers);
343 if(hosthdr) { 352 if(hosthdr) {
344 char *host = pool_strdup(pool, hosthdr); 353 char *host = pool_strdup(pool, hosthdr);
345 char *portstr = strchr(host, ':'); 354 char *portstr = NULL;
355 if(host[0] != '[') {
356 portstr = strchr(host, ':');
357 } else {
358 char *v6end = strchr(host, ']');
359 if(v6end) {
360 portstr = strchr(v6end, ':');
361 }
362 }
363
346 if(portstr) { 364 if(portstr) {
347 *portstr = '\0'; 365 *portstr = '\0';
348 } 366 }
349 rq->host = host; 367 rq->host = host;
350 } else { 368 } else {

mercurial