Пример #1
0
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*/;
}
Пример #2
0
int/*bool*/ SERV_Update(SERV_ITER iter, const char* text, int code)
{
    static const char used_server_info[] = "Used-Server-Info-";
    int retval = 0/*not updated yet*/;

    if (iter  &&  iter->op  &&  text) {
        const char *c, *b;
        iter->time = (TNCBI_Time) time(0);
        for (b = text;  (c = strchr(b, '\n')) != 0;  b = c + 1) {
            size_t len = (size_t)(c - b);
            SSERV_Info* info;
            unsigned int d1;
            char* p, *t;
            int d2;

            if (!(t = (char*) malloc(len + 1)))
                continue;
            memcpy(t, b, len);
            if (t[len - 1] == '\r')
                t[len - 1] =  '\0';
            else
                t[len] = '\0';
            p = t;
            if (iter->op->Update  &&  iter->op->Update(iter, p, code))
                retval = 1/*updated*/;
            if (!strncasecmp(p, used_server_info, sizeof(used_server_info) - 1)
                &&  isdigit((unsigned char) p[sizeof(used_server_info) - 1])) {
                p += sizeof(used_server_info) - 1;
                if (sscanf(p, "%u: %n", &d1, &d2) >= 1
                    &&  (info = SERV_ReadInfoEx(p + d2, "")) != 0) {
                    if (!s_AddSkipInfo(iter, "", info))
                        free(info);
                    else
                        retval = 1/*updated*/;
                }
            }
            free(t);
        }
    }
    return retval;
}
Пример #3
0
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*/;
}
Пример #4
0
SSERV_Info* SERV_ReadInfo(const char* info_str)
{
    return SERV_ReadInfoEx(info_str, 0);
}
Пример #5
0
static int/*bool*/ s_Update(SERV_ITER iter, const char* text, int code)
{
    static const char server_info[] = "Server-Info-";
    struct SDISPD_Data* data = (struct SDISPD_Data*) iter->data;
    int/*bool*/ failure;

    if (strncasecmp(text, server_info, sizeof(server_info) - 1) == 0
        &&  isdigit((unsigned char) text[sizeof(server_info) - 1])) {
        const char* name;
        SSERV_Info* info;
        unsigned int d1;
        char* s;
        int d2;

        text += sizeof(server_info) - 1;
        if (sscanf(text, "%u: %n", &d1, &d2) < 1  ||  d1 < 1)
            return 0/*not updated*/;
        if (iter->ismask  ||  iter->reverse_dns) {
            char* c;
            if (!(s = strdup(text + d2)))
                return 0/*not updated*/;
            name = s;
            while (*name  &&  isspace((unsigned char)(*name)))
                name++;
            if (!*name) {
                free(s);
                return 0/*not updated*/;
            }
            for (c = s + (name - s);  *c;  c++) {
                if (isspace((unsigned char)(*c)))
                    break;
            }
            *c++ = '\0';
            d2 += (int)(c - s);
        } else {
            s = 0;
            name = "";
        }
        info = SERV_ReadInfoEx(text + d2, name);
        if (s)
            free(s);
        if (info) {
            if (info->time != NCBI_TIME_INFINITE)
                info->time += iter->time; /* expiration time now */
            if (s_AddServerInfo(data, info))
                return 1/*updated*/;
            free(info);
        }
    } else if (((failure = strncasecmp(text, HTTP_DISP_FAILURES,
                                       sizeof(HTTP_DISP_FAILURES) - 1) == 0)
                ||  strncasecmp(text, HTTP_DISP_MESSAGES,
                                sizeof(HTTP_DISP_MESSAGES) - 1) == 0)  &&
               isspace((unsigned char) text[sizeof(HTTP_DISP_FAILURES) - 1])) {
        assert(sizeof(HTTP_DISP_FAILURES) == sizeof(HTTP_DISP_MESSAGES));
#if defined(_DEBUG) && !defined(NDEBUG)
        if (data->net_info->debug_printout) {
            text += sizeof(HTTP_DISP_FAILURES) - 1;
            while (*text  &&  isspace((unsigned char)(*text)))
                text++;
            CORE_LOGF_X(2, failure ? eLOG_Warning : eLOG_Note,
                        ("[%s]  %s", data->net_info->svc, text));
        }
#endif /*_DEBUG && !NDEBUG*/
        if (failure) {
            if (code)
                data->fail = 1;
            return 1/*updated*/;
        }
        /* NB: a mere message does not constitute an update */
    }

    return 0/*not updated*/;
}
Пример #6
0
extern SSERV_Info* SERV_ReadInfo(const char* str)
{
    return SERV_ReadInfoEx(str, 0);
}