📄 ncbi_server_info.c
字号:
if (info) { info->type = fSERV_Firewall; info->host = host; info->port = port; info->sful = 0; info->locl = s_LocalServerDefault & 0x0F; info->time = 0; info->coef = 0.0; info->rate = 0.0; info->mime_t = SERV_MIME_TYPE_UNDEFINED; info->mime_s = SERV_MIME_SUBTYPE_UNDEFINED; info->mime_e = eENCOD_None; info->flag = SERV_DEFAULT_FLAG; memset(&info->reserved, 0, sizeof(info->reserved)); info->quorum = 0; info->u.firewall.type = type; } return info;}/***************************************************************************** * DNS:: constructor and virtual functions *//*ARGSUSED*/static char* s_Dns_Write(size_t reserve, const USERV_Info* u_info){ char* str = (char*) malloc(reserve + 1); if (str) str[reserve] = '\0'; return str;}/*ARGSUSED*/static SSERV_Info* s_Dns_Read(const char** str){ return SERV_CreateDnsInfo(0);}static size_t s_Dns_SizeOf(const USERV_Info* u){ return sizeof(u->dns);}/*ARGSUSED*/static int/*bool*/ s_Dns_Equal(const USERV_Info* u1, const USERV_Info* u2){ return 1;}SSERV_Info* SERV_CreateDnsInfo(unsigned int host){ SSERV_Info* info = (SSERV_Info*) malloc(sizeof(SSERV_Info)); if (info) { info->type = fSERV_Dns; info->host = host; info->port = 0; info->sful = 0; info->locl = s_LocalServerDefault & 0x0F; info->time = 0; info->coef = 0.0; info->rate = 0.0; info->mime_t = SERV_MIME_TYPE_UNDEFINED; info->mime_s = SERV_MIME_SUBTYPE_UNDEFINED; info->mime_e = eENCOD_None; info->flag = SERV_DEFAULT_FLAG; memset(&info->reserved, 0, sizeof(info->reserved)); info->quorum = 0; memset(&info->u.dns.pad, 0, sizeof(info->u.dns.pad)); } return info;}/***************************************************************************** * Attributes for the different server types:: Implementation */static const char kNCBID [] = "NCBID";static const char kSTANDALONE[] = "STANDALONE";static const char kHTTP_GET [] = "HTTP_GET";static const char kHTTP_POST [] = "HTTP_POST";static const char kHTTP [] = "HTTP";static const char kFIREWALL [] = "FIREWALL";static const char kDNS [] = "DNS";/* Note: be aware of "prefixness" of tag constants and order of * their appearance in the table below, as comparison is done via * "strncmp", which can result 'true' on a smaller fit fragment. */static const SSERV_Attr s_SERV_Attr[] = { { fSERV_Ncbid, kNCBID, sizeof(kNCBID) - 1, {s_Ncbid_Write, s_Ncbid_Read, s_Ncbid_SizeOf, s_Ncbid_Equal} }, { fSERV_Standalone, kSTANDALONE, sizeof(kSTANDALONE) - 1, {s_Standalone_Write, s_Standalone_Read, s_Standalone_SizeOf, s_Standalone_Equal} }, { fSERV_HttpGet, kHTTP_GET, sizeof(kHTTP_GET) - 1, {s_Http_Write, s_HttpGet_Read, s_Http_SizeOf, s_Http_Equal} }, { fSERV_HttpPost, kHTTP_POST, sizeof(kHTTP_POST) - 1, {s_Http_Write, s_HttpPost_Read, s_Http_SizeOf, s_Http_Equal} }, { fSERV_Http, kHTTP, sizeof(kHTTP) - 1, {s_Http_Write, s_Http_Read, s_Http_SizeOf, s_Http_Equal} }, { fSERV_Firewall, kFIREWALL, sizeof(kFIREWALL) - 1, {s_Firewall_Write, s_Firewall_Read, s_Firewall_SizeOf, s_Firewall_Equal} }, { fSERV_Dns, kDNS, sizeof(kDNS) - 1, {s_Dns_Write, s_Dns_Read, s_Dns_SizeOf, s_Dns_Equal} }};static const SSERV_Attr* s_GetAttrByType(ESERV_Type type){ size_t i; for (i = 0; i < sizeof(s_SERV_Attr)/sizeof(s_SERV_Attr[0]); i++) { if (s_SERV_Attr[i].type == type) return &s_SERV_Attr[i]; } return 0;}static const SSERV_Attr* s_GetAttrByTag(const char* tag){ if (tag) { size_t i; for (i = 0; i < sizeof(s_SERV_Attr)/sizeof(s_SERV_Attr[0]); i++) { size_t len = s_SERV_Attr[i].tag_len; if (strncmp(s_SERV_Attr[i].tag, tag, len) == 0) if (!tag[len] || /* avoid prefix-only match */ !(isalnum((unsigned char) tag[len]) || tag[len] == '_')) return &s_SERV_Attr[i]; } } return 0;}/* * -------------------------------------------------------------------------- * $Log: ncbi_server_info.c,v $ * Revision 1000.0 2003/10/29 16:39:27 gouriano * PRODUCTION: IMPORTED [ORIGINAL] Dev-tree R6.53 * * Revision 6.53 2003/09/02 21:21:42 lavr * Cleanup included headers * * Revision 6.52 2003/06/26 15:21:43 lavr * Use server's default locality for fSERV_Dns infos * * Revision 6.51 2003/06/16 15:58:50 lavr * Minor code format changes * * Revision 6.50 2003/05/31 05:16:28 lavr * Add ARGSUSED where args are meant to be unused * * Revision 6.49 2003/04/25 15:21:05 lavr * Explicit cast to avoid int->enum warning * * Revision 6.48 2003/03/13 19:08:26 lavr * Allow missing type in Firewall server info specification * * Revision 6.47 2003/03/07 22:21:31 lavr * Heed 'uninitted use' (false) warning by moving lines around * * Revision 6.46 2003/02/28 14:48:38 lavr * String type match for size_t and int in few expressions * * Revision 6.45 2002/11/01 20:15:36 lavr * Do not allow FIREWALL server specs to have Q flag * * Revision 6.44 2002/10/28 20:15:06 lavr * -<connect/ncbi_server_info.h> ("ncbi_server_infop.h" should suffice) * * Revision 6.43 2002/10/28 15:46:21 lavr * Use "ncbi_ansi_ext.h" privately * * Revision 6.42 2002/10/21 19:19:23 lavr * 2(was:3)-digit precision if R is exactly 0.01 * * Revision 6.41 2002/09/24 15:05:23 lavr * Increase precision in SERV_Write() when R is small * * Revision 6.40 2002/09/17 15:39:33 lavr * SSERV_Info::quorum moved past the reserved area * * Revision 6.39 2002/09/04 15:09:47 lavr * Handle quorum field in SSERV_Info::, log moved to end * * Revision 6.38 2002/05/06 19:16:16 lavr * +#include <stdio.h> * * Revision 6.37 2002/03/22 19:52:18 lavr * Do not include <stdio.h>: included from ncbi_util.h or ncbi_priv.h * * Revision 6.36 2002/03/19 22:13:58 lavr * Do not use home-made ANSI-extensions if the platform provides * * Revision 6.35 2002/03/11 21:59:00 lavr * Support for changes in ncbi_server_info.h: DNS server type added as * well as support for MIME encoding in server specifications * * Revision 6.34 2001/12/06 16:07:44 lavr * More accurate string length estimation in SERV_WriteInfo() * * Revision 6.33 2001/11/25 22:12:00 lavr * Replaced g_SERV_LocalServerDefault -> SERV_SetLocalServerDefault() * * Revision 6.32 2001/11/16 20:25:53 lavr * +g_SERV_LocalServerDefault as a private global parameter * * Revision 6.31 2001/09/24 20:43:58 lavr * TSERV_Flags reverted to 'int'; expilict cast added in comparison * * Revision 6.30 2001/09/10 21:17:10 lavr * Support written for FIREWALL server type * * Revision 6.29 2001/06/19 19:12:01 lavr * Type change: size_t -> TNCBI_Size; time_t -> TNCBI_Time * * Revision 6.28 2001/06/05 14:11:29 lavr * SERV_MIME_UNDEFINED split into 2 (typed) constants: * SERV_MIME_TYPE_UNDEFINED and SERV_MIME_SUBTYPE_UNDEFINED * * Revision 6.27 2001/06/04 17:01:06 lavr * MIME type/subtype added to server descriptor * * Revision 6.26 2001/05/03 16:35:46 lavr * Local bonus coefficient modified: meaning of negative value changed * * Revision 6.25 2001/04/24 21:38:21 lavr * Additions to code to support new locality and bonus attributes of servers. * * Revision 6.24 2001/03/26 18:39:38 lavr * Casting to (unsigned char) instead of (int) for ctype char.class macros * * Revision 6.23 2001/03/06 23:53:07 lavr * SERV_ReadInfo can now consume either hostname or IP address * * Revision 6.22 2001/03/05 23:10:11 lavr * SERV_WriteInfo & SERV_ReadInfo both take only one argument now * * Revision 6.21 2001/03/02 20:09:14 lavr * Typo fixed * * Revision 6.20 2001/03/01 18:48:19 lavr * NCBID allowed to have '' (special case) as an empty argument * * Revision 6.19 2001/01/03 22:34:44 lavr * MAX_IP_ADDRESS_LEN -> MAX_IP_ADDR_LEN (as everywhere else) * * Revision 6.18 2000/12/29 17:59:38 lavr * Reading and writing of SERV_Info now use SOCK_* utility functions * SOCK_gethostaddr and SOCK_ntoa. More clean code for reading. * * Revision 6.17 2000/12/06 22:19:02 lavr * Binary host addresses are now explicitly stated to be in network byte * order, whereas binary port addresses now use native (host) representation * * Revision 6.16 2000/12/04 17:34:19 beloslyu * the order of include files is important, especially on other Unixes! * Look the man on inet_ntoa * * Revision 6.15 2000/10/20 17:13:30 lavr * Service descriptor parse bug fixed * Return empty string on unknown type (instead of abort) in 'SERV_TypeStr' * * Revision 6.14 2000/10/05 21:31:23 lavr * Standalone connection marked "stateful" by default * * Revision 6.13 2000/06/05 20:21:20 lavr * Eliminated gcc warning: "subscript has type `char'" in calls to * classification macros (<ctype.h>) by explicit casting to unsigned chars * * Revision 6.12 2000/05/31 23:12:22 lavr * First try to assemble things together to get working service mapper * * Revision 6.11 2000/05/24 16:45:15 lavr * Introduced replacement for inet_ntoa: my_ntoa * * Revision 6.10 2000/05/23 21:05:33 lavr * Memory leaks fixed (appeared after server-info structure rearrangement) * * Revision 6.9 2000/05/23 19:02:49 lavr * Server-info now includes rate; verbal representation changed * * Revision 6.8 2000/05/22 16:53:11 lavr * Rename service_info -> server_info everywhere (including * file names) as the latter name is more relevant * * Revision 6.7 2000/05/18 14:12:43 lavr * Cosmetic change * * Revision 6.6 2000/05/17 16:15:13 lavr * NCBI_* (for ANSI ext) undone - now "ncbi_ansi_ext.h" does good prototyping * * Revision 6.5 2000/05/17 14:22:32 lavr * Small cosmetic changes * * Revision 6.4 2000/05/16 15:09:02 lavr * Added explicit type casting to get "very smart" compilers happy * * Revision 6.3 2000/05/15 19:06:09 lavr * Use home-made ANSI extensions (NCBI_***) * * Revision 6.2 2000/05/12 21:42:59 lavr * Cleaned up for the C++ compilation, etc. * * Revision 6.1 2000/05/12 18:36:26 lavr * First working revision * * ========================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -