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
* ===========================================================================
4
4
* PUBLIC DOMAIN NOTICE
148
148
memcpy(s, attr->tag, attr->tag_len);
149
149
s += attr->tag_len;
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) {
154
154
memmove(s, str + reserve, n + 1);
182
SSERV_Info* SERV_ReadInfoEx(const char* info_str, size_t add)
182
SSERV_Info* SERV_ReadInfoEx(const char* info_str, const char* name)
184
184
/* detect server type */
186
const char* str = SERV_ReadType(info_str, &type);
187
int/*bool*/ coef, mime, locl, priv, quorum, rate, sful, time;
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 */
192
192
if (!str || (*str && !isspace((unsigned char)(*str))))
194
194
while (*str && isspace((unsigned char)(*str)))
196
if (!(str = StringToHostPort(str, &host, &port)))
196
if (!(str = SOCK_StringToHostPort(str, &host, &port)))
198
198
while (*str && isspace((unsigned char)(*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);
203
204
info->host = host;
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*/;
364
SSERV_Info* SERV_CopyInfoEx(const SSERV_Info* orig, const char* name)
366
size_t size = SERV_SizeOfInfo(orig);
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));
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*/;
384
SSERV_Info* SERV_CopyInfo(const SSERV_Info* orig)
386
return SERV_CopyInfoEx(orig, 0);
390
const char* SERV_NameOfInfo(const SSERV_Info* info)
394
return info->type != fSERV_Dns || info->u.dns.name
395
? (const char*) info + SERV_SizeOfInfo(info) : "";
357
399
size_t SERV_SizeOfInfo(const SSERV_Info *info)
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;
678
720
if (!(s = SERV_ReadType(*str, &type)))
679
type = (ESERV_Type) fSERV_Any;
721
type = (ESERV_Type) 0/*fSERV_Any*/;
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));
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
919
* Revision 6.60 2006/01/11 16:31:41 lavr
922
* Revision 6.59 2005/12/23 18:14:04 lavr
923
* Use fSERV_Any explicitly (instead of cast 0)
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
874
930
* Revision 6.57 2005/11/29 19:56:33 lavr
875
931
* Changed service type tag comparison to be case-insensitive