| 1034 | } |
| 1035 | |
| 1036 | AP_DECLARE(const char *) ap_get_useragent_host(request_rec *r, |
| 1037 | int type, int *str_is_ip) |
| 1038 | { |
| 1039 | conn_rec *conn = r->connection; |
| 1040 | int hostname_lookups; |
| 1041 | int ignored_str_is_ip; |
| 1042 | |
| 1043 | /* Guard here when examining the host before the read_request hook |
| 1044 | * has populated an r->useragent_addr |
| 1045 | */ |
| 1046 | if (!r->useragent_addr || (r->useragent_addr == conn->client_addr)) { |
| 1047 | return ap_get_remote_host(conn, r->per_dir_config, type, str_is_ip); |
| 1048 | } |
| 1049 | |
| 1050 | if (!str_is_ip) { /* caller doesn't want to know */ |
| 1051 | str_is_ip = &ignored_str_is_ip; |
| 1052 | } |
| 1053 | *str_is_ip = 0; |
| 1054 | |
| 1055 | hostname_lookups = ((core_dir_config *) |
| 1056 | ap_get_core_module_config(r->per_dir_config)) |
| 1057 | ->hostname_lookups; |
| 1058 | if (hostname_lookups == HOSTNAME_LOOKUP_UNSET) { |
| 1059 | hostname_lookups = HOSTNAME_LOOKUP_OFF; |
| 1060 | } |
| 1061 | |
| 1062 | if (type != REMOTE_NOLOOKUP |
| 1063 | && r->useragent_host == NULL |
| 1064 | && (type == REMOTE_DOUBLE_REV |
| 1065 | || hostname_lookups != HOSTNAME_LOOKUP_OFF)) { |
| 1066 | |
| 1067 | if (apr_getnameinfo(&r->useragent_host, r->useragent_addr, 0) |
| 1068 | == APR_SUCCESS) { |
| 1069 | ap_str_tolower(r->useragent_host); |
| 1070 | |
| 1071 | if (hostname_lookups == HOSTNAME_LOOKUP_DOUBLE) { |
| 1072 | r->double_reverse = do_double_reverse(r->double_reverse, |
| 1073 | r->useragent_host, |
| 1074 | r->useragent_addr, |
| 1075 | r->pool); |
| 1076 | if (r->double_reverse != 1) { |
| 1077 | r->useragent_host = NULL; |
| 1078 | } |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | /* if failed, set it to the NULL string to indicate error */ |
| 1083 | if (r->useragent_host == NULL) { |
| 1084 | r->useragent_host = ""; |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | if (type == REMOTE_DOUBLE_REV) { |
| 1089 | r->double_reverse = do_double_reverse(r->double_reverse, |
| 1090 | r->useragent_host, |
| 1091 | r->useragent_addr, r->pool); |
| 1092 | if (r->double_reverse == -1) { |
| 1093 | return NULL; |
no test coverage detected