static int/*bool*/ s_LoadSingleService(const char* name, SERV_ITER iter) { struct SLOCAL_Data* data = (struct SLOCAL_Data*) iter->data; const TSERV_Type types = iter->types & ~fSERV_Firewall; char key[sizeof(REG_CONN_LOCAL_SERVER) + 10]; int/*bool*/ ok = 0/*failed*/; SSERV_Info* info; int n; info = 0; strcpy(key, REG_CONN_LOCAL_SERVER "_"); for (n = 0; n <= 100; n++) { const char* svc; char buf[1024]; if (info) { free((void*) info); info = 0; } sprintf(key + sizeof(REG_CONN_LOCAL_SERVER), "%d", n); if (!(svc = ConnNetInfo_GetValue(name, key, buf, sizeof(buf), 0))) continue; if (!(info = SERV_ReadInfoEx (svc, iter->ismask || iter->reverse_dns ? name : "", 0))) { continue; } if (iter->external && (info->site & (fSERV_Local | fSERV_Private))) continue; /* external mapping for local server not allowed */ if (!info->host || (info->site & fSERV_Private)) { unsigned int localhost = SOCK_GetLocalHostAddress(eDefault); if (!info->host) info->host = localhost; if ((info->site & fSERV_Private) && info->host != localhost) continue; /* private server */ } if (!iter->reverse_dns && info->type != fSERV_Dns) { if (types != fSERV_Any && !(types & info->type)) continue; /* type doesn't match */ if (types == fSERV_Any && info->type == fSERV_Dns) continue; /* DNS entries have to be req'd explicitly */ if (iter->stateless && (info->mode & fSERV_Stateful)) continue; /* skip stateful only servers */ } if (!info->rate) info->rate = LBSM_DEFAULT_RATE; if (!info->time) info->time = LBSM_DEFAULT_TIME; if (!s_AddService(info, data)) break; info = 0; ok = 1/*succeeded*/; } if (info) free((void*) info); return ok/*whatever*/; }
static int/*bool*/ s_LoadSingleService(const char* name, SERV_ITER iter) { struct SLOCAL_Data* data = (struct SLOCAL_Data*) iter->data; const TSERV_Type type = iter->type & ~fSERV_Firewall; int/*bool*/ ok = 0/*failed*/; SSERV_Info* info; char* buf; int n; if (!(buf = (char*) malloc(strlen(name) + sizeof(REG_CONN_LOCAL_SERVER) + 80))) { return 0/*failed*/; } info = 0; for (n = 0; n <= 100; n++) { char service[1024]; const char* c; if (info) { free((void*) info); info = 0; } sprintf(buf, "%s_" REG_CONN_LOCAL_SERVER "_%d", name, n); if (!(c = getenv(buf)) && !(c = getenv(strupr(buf)))) { char* b = buf + strlen(name); size_t len; *b++ = '\0'; CORE_REG_GET(buf, b, service, sizeof(service) - 1, 0); len = strlen(service); if (len > 1 && (service[0] == '"' || service[0] == '\'') && service[len - 1] == service[0] && (len -= 2) > 0) { memmove(service, service + 1, len); service[len] = '\0'; } if (!len) continue; c = service; } if (!(info = SERV_ReadInfoEx (c, iter->ismask || iter->reverse_dns ? name : ""))) { continue; } if (iter->external && info->locl) continue; /* external mapping for local server not allowed */ if (!info->host || (info->locl & 0xF0)) { unsigned int localhost = SOCK_GetLocalHostAddress(eDefault); if (!info->host) info->host = localhost; if ((info->locl & 0xF0) && info->host != localhost) continue; /* private server */ } if (!iter->reverse_dns && info->type != fSERV_Dns) { if (type != fSERV_Any && !(type & info->type)) continue; /* type doesn't match */ if (type == fSERV_Any && info->type == fSERV_Dns) continue; /* DNS entries have to be req'd explicitly */ if (iter->stateless && info->sful && !(info->type & fSERV_Http)) continue; /* skip stateful only servers */ } if (!info->rate) info->rate = LBSM_DEFAULT_RATE; if (!info->time) info->time = LBSM_DEFAULT_TIME; if (!s_AddService(info, data)) break; info = 0; ok = 1/*succeeded*/; } if (info) free((void*) info); free(buf); return ok/*whatever*/; }