~ubuntu-branches/ubuntu/edgy/ncbi-tools6/edgy

« back to all changes in this revision

Viewing changes to connect/ncbi_server_info.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-07-19 23:28:07 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060719232807-et3cdmcjgmnyleyx
Tags: 6.1.20060507-3ubuntu1
Re-merge with Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  $Id: ncbi_server_info.c,v 6.57 2005/11/29 19:56:33 lavr Exp $
 
1
/*  $Id: ncbi_server_info.c,v 6.61 2006/01/27 17:09:32 lavr Exp $
2
2
 * ===========================================================================
3
3
 *
4
4
 *                            PUBLIC DOMAIN NOTICE
148
148
        memcpy(s, attr->tag, attr->tag_len);
149
149
        s += attr->tag_len;
150
150
        *s++ = ' ';
151
 
        s += HostPortToString(info->host, info->port, s, reserve);
 
151
        s += SOCK_HostPortToString(info->host, info->port, s, reserve);
152
152
        if ((n = strlen(str + reserve)) != 0) {
153
153
            *s++ = ' ';
154
154
            memmove(s, str + reserve, n + 1);
179
179
}
180
180
 
181
181
 
182
 
SSERV_Info* SERV_ReadInfoEx(const char* info_str, size_t add)
 
182
SSERV_Info* SERV_ReadInfoEx(const char* info_str, const char* name)
183
183
{
184
184
    /* detect server type */
185
 
    ESERV_Type  type;
186
 
    const char* str = SERV_ReadType(info_str, &type);
187
 
    int/*bool*/ coef, mime, locl, priv, quorum, rate, sful, time;
 
185
    ESERV_Type     type;
 
186
    const char*    str = SERV_ReadType(info_str, &type);
 
187
    int/*bool*/    coef, mime, locl, priv, quorum, rate, sful, time;
 
188
    unsigned int   host;                /* network byte order       */
188
189
    unsigned short port;                /* host (native) byte order */
189
 
    unsigned int host;                  /* network byte order       */
190
 
    SSERV_Info *info;
 
190
    SSERV_Info*    info;
191
191
 
192
192
    if (!str || (*str && !isspace((unsigned char)(*str))))
193
193
        return 0;
194
194
    while (*str && isspace((unsigned char)(*str)))
195
195
        str++;
196
 
    if (!(str = StringToHostPort(str, &host, &port)))
 
196
    if (!(str = SOCK_StringToHostPort(str, &host, &port)))
197
197
        return 0;
198
198
    while (*str && isspace((unsigned char)(*str)))
199
199
        str++;
200
200
    /* read server-specific info according to the detected type */
201
 
    if (!(info = s_GetAttrByType(type)->vtable.Read(&str, add)))
 
201
    info = s_GetAttrByType(type)->vtable.Read(&str, name ? strlen(name)+1 : 0);
 
202
    if (!info)
202
203
        return 0;
203
204
    info->host = host;
204
205
    if (port)
343
344
    if (*str) {
344
345
        free(info);
345
346
        info = 0;
 
347
    } else if (name) {
 
348
        strcpy((char*) info + SERV_SizeOfInfo(info), name);
 
349
        if (info->type == fSERV_Dns)
 
350
            info->u.dns.name = 1/*true*/;
 
351
    } else if (info->type == fSERV_Dns) {
 
352
        info->u.dns.name = 0/*false*/;
346
353
    }
347
354
    return info;
348
355
}
354
361
}
355
362
 
356
363
 
 
364
SSERV_Info* SERV_CopyInfoEx(const SSERV_Info* orig, const char* name)
 
365
{
 
366
    size_t      size = SERV_SizeOfInfo(orig);
 
367
    SSERV_Info* info;
 
368
    if (!size)
 
369
        return 0;
 
370
    if ((info = (SSERV_Info*)malloc(size + (name ? strlen(name)+1 : 0))) != 0){
 
371
        memcpy(info, orig, size);
 
372
        memset(&info->reserved, 0, sizeof(info->reserved));
 
373
        if (name) {
 
374
            strcpy((char*) info + size, name);
 
375
            if (orig->type == fSERV_Dns)
 
376
                info->u.dns.name = 1/*true*/;
 
377
        } else if (orig->type == fSERV_Dns)
 
378
            info->u.dns.name = 0/*false*/;
 
379
    }
 
380
    return info;
 
381
}
 
382
 
 
383
 
 
384
SSERV_Info* SERV_CopyInfo(const SSERV_Info* orig)
 
385
{
 
386
    return SERV_CopyInfoEx(orig, 0);
 
387
}
 
388
 
 
389
 
 
390
const char* SERV_NameOfInfo(const SSERV_Info* info)
 
391
{
 
392
    if (!info)
 
393
        return 0;
 
394
    return info->type != fSERV_Dns  ||  info->u.dns.name
 
395
        ? (const char*) info + SERV_SizeOfInfo(info) : "";
 
396
}
 
397
 
 
398
 
357
399
size_t SERV_SizeOfInfo(const SSERV_Info *info)
358
400
{
359
 
    return sizeof(*info) - sizeof(info->u) +
360
 
        s_GetAttrByType(info->type)->vtable.SizeOf(&info->u);
 
401
    return info ? sizeof(*info) - sizeof(info->u) +
 
402
        s_GetAttrByType(info->type)->vtable.SizeOf(&info->u) : 0;
361
403
}
362
404
 
363
405
 
676
718
    ESERV_Type type;
677
719
    const char* s;
678
720
    if (!(s = SERV_ReadType(*str, &type)))
679
 
        type = (ESERV_Type) fSERV_Any;
 
721
        type = (ESERV_Type) 0/*fSERV_Any*/;
680
722
    else
681
723
        *str = s;
682
724
    return SERV_CreateFirewallInfoEx(0, 0, type, add);
775
817
        info->flag   = SERV_DEFAULT_FLAG;
776
818
        memset(&info->reserved, 0, sizeof(info->reserved));
777
819
        info->quorum = 0;
778
 
        memset(&info->u.dns.pad, 0, sizeof(info->u.dns.pad));
 
820
        memset(&info->u.dns, 0, sizeof(info->u.dns));
779
821
    }
780
822
    return info;
781
823
}
871
913
/*
872
914
 * --------------------------------------------------------------------------
873
915
 * $Log: ncbi_server_info.c,v $
 
916
 * Revision 6.61  2006/01/27 17:09:32  lavr
 
917
 * Replace obsolete call names with current ones
 
918
 *
 
919
 * Revision 6.60  2006/01/11 16:31:41  lavr
 
920
 * Cosmetics
 
921
 *
 
922
 * Revision 6.59  2005/12/23 18:14:04  lavr
 
923
 * Use fSERV_Any explicitly (instead of cast 0)
 
924
 *
 
925
 * Revision 6.58  2005/12/14 21:25:24  lavr
 
926
 * Name parameter for SERV_ReadInfoEx() (instead of "add")
 
927
 * +SERV_CopyInfoEx(), +SERV_NameOfInfo() [+u.dns.name use]
 
928
 * SERV_SizeOfInfo() to return 0 on NULL
 
929
 *
874
930
 * Revision 6.57  2005/11/29 19:56:33  lavr
875
931
 * Changed service type tag comparison to be case-insensitive
876
932
 *