28
28
* File Description:
29
29
* NCBI server meta-address info
31
* --------------------------------------------------------------------------
32
* $Log: ncbi_server_info.c,v $
33
* Revision 6.34 2001/12/06 16:07:44 lavr
34
* More accurate string length estimation in SERV_WriteInfo()
36
* Revision 6.33 2001/11/25 22:12:00 lavr
37
* Replaced g_SERV_LocalServerDefault -> SERV_SetLocalServerDefault()
39
* Revision 6.32 2001/11/16 20:25:53 lavr
40
* +g_SERV_LocalServerDefault as a private global parameter
42
* Revision 6.31 2001/09/24 20:43:58 lavr
43
* TSERV_Flags reverted to 'int'; expilict cast added in comparison
45
* Revision 6.30 2001/09/10 21:17:10 lavr
46
* Support written for FIREWALL server type
48
* Revision 6.29 2001/06/19 19:12:01 lavr
49
* Type change: size_t -> TNCBI_Size; time_t -> TNCBI_Time
51
* Revision 6.28 2001/06/05 14:11:29 lavr
52
* SERV_MIME_UNDEFINED split into 2 (typed) constants:
53
* SERV_MIME_TYPE_UNDEFINED and SERV_MIME_SUBTYPE_UNDEFINED
55
* Revision 6.27 2001/06/04 17:01:06 lavr
56
* MIME type/subtype added to server descriptor
58
* Revision 6.26 2001/05/03 16:35:46 lavr
59
* Local bonus coefficient modified: meaning of negative value changed
61
* Revision 6.25 2001/04/24 21:38:21 lavr
62
* Additions to code to support new locality and bonus attributes of servers.
64
* Revision 6.24 2001/03/26 18:39:38 lavr
65
* Casting to (unsigned char) instead of (int) for ctype char.class macros
67
* Revision 6.23 2001/03/06 23:53:07 lavr
68
* SERV_ReadInfo can now consume either hostname or IP address
70
* Revision 6.22 2001/03/05 23:10:11 lavr
71
* SERV_WriteInfo & SERV_ReadInfo both take only one argument now
73
* Revision 6.21 2001/03/02 20:09:14 lavr
76
* Revision 6.20 2001/03/01 18:48:19 lavr
77
* NCBID allowed to have '' (special case) as an empty argument
79
* Revision 6.19 2001/01/03 22:34:44 lavr
80
* MAX_IP_ADDRESS_LEN -> MAX_IP_ADDR_LEN (as everywhere else)
82
* Revision 6.18 2000/12/29 17:59:38 lavr
83
* Reading and writing of SERV_Info now use SOCK_* utility functions
84
* SOCK_gethostaddr and SOCK_ntoa. More clean code for reading.
86
* Revision 6.17 2000/12/06 22:19:02 lavr
87
* Binary host addresses are now explicitly stated to be in network byte
88
* order, whereas binary port addresses now use native (host) representation
90
* Revision 6.16 2000/12/04 17:34:19 beloslyu
91
* the order of include files is important, especially on other Unixes!
92
* Look the man on inet_ntoa
94
* Revision 6.15 2000/10/20 17:13:30 lavr
95
* Service descriptor parse bug fixed
96
* Unknown type now returns empty text string (instead of abort) in 'SERV_TypeStr'
98
* Revision 6.14 2000/10/05 21:31:23 lavr
99
* Standalone connection marked "stateful" by default
101
* Revision 6.13 2000/06/05 20:21:20 lavr
102
* Eliminated gcc warning: "subscript has type `char'" in calls to
103
* classification macros (<ctype.h>) by explicit casting to unsigned chars
105
* Revision 6.12 2000/05/31 23:12:22 lavr
106
* First try to assemble things together to get working service mapper
108
* Revision 6.11 2000/05/24 16:45:15 lavr
109
* Introduced replacement for inet_ntoa: my_ntoa
111
* Revision 6.10 2000/05/23 21:05:33 lavr
112
* Memory leaks fixed (appeared after server-info structure rearrangement)
114
* Revision 6.9 2000/05/23 19:02:49 lavr
115
* Server-info now includes rate; verbal representation changed
117
* Revision 6.8 2000/05/22 16:53:11 lavr
118
* Rename service_info -> server_info everywhere (including
119
* file names) as the latter name is more relevant
121
* Revision 6.7 2000/05/18 14:12:43 lavr
124
* Revision 6.6 2000/05/17 16:15:13 lavr
125
* NCBI_* (for ANSI ext) undone - now "ncbi_ansi_ext.h" does good prototyping
127
* Revision 6.5 2000/05/17 14:22:32 lavr
128
* Small cosmetic changes
130
* Revision 6.4 2000/05/16 15:09:02 lavr
131
* Added explicit type casting to get "very smart" compilers happy
133
* Revision 6.3 2000/05/15 19:06:09 lavr
134
* Use home-made ANSI extensions (NCBI_***)
136
* Revision 6.2 2000/05/12 21:42:59 lavr
137
* Cleaned up for the C++ compilation, etc.
139
* Revision 6.1 2000/05/12 18:36:26 lavr
140
* First working revision
142
* ==========================================================================
33
#include "ncbi_ansi_ext.h"
145
34
#include "ncbi_server_infop.h"
146
#include <connect/ncbi_ansi_ext.h>
147
#include <connect/ncbi_server_info.h>
148
#include <connect/ncbi_socket.h>
150
35
#include <ctype.h>
152
37
#include <stdio.h>
153
38
#include <stdlib.h>
157
40
#define MAX_IP_ADDR_LEN 16 /* sizeof("255.255.255.255") */
268
150
s += HostPortToString(info->host, info->port, s, reserve);
269
151
if ((n = strlen(str + reserve)) != 0) {
271
memmove(s, str + reserve, n+1);
153
memmove(s, str + reserve, n + 1);
272
154
s = str + strlen(str);
275
s += sprintf(s, " C=%s", c_t);
276
157
assert(info->flag < (int)(sizeof(k_FlagTag)/sizeof(k_FlagTag[0])));
277
158
if (k_FlagTag[info->flag] && *k_FlagTag[info->flag])
278
159
s += sprintf(s, " %s", k_FlagTag[info->flag]);
279
s += sprintf(s, " T=%lu R=%.2f B=%.2f L=%s", (unsigned long)info->time,
280
info->rate, info->coef, info->locl ? "yes" : "no");
281
if (!(info->type & fSERV_Http))
160
s += sprintf(s, " B=%.2f", info->coef);
162
s += sprintf(s, " C=%s", c_t);
163
s += sprintf(s, " L=%s", info->locl & 0x0F ? "yes" : "no");
164
if (info->type != fSERV_Dns && (info->locl & 0xF0))
165
s += sprintf(s, " P=yes");
166
if (info->host && info->quorum) {
167
if (info->quorum == (unsigned short)(-1))
168
s += sprintf(s, " Q=yes");
170
s += sprintf(s, " Q=%hu", info->quorum);
172
s += sprintf(s," R=%.*f", fabs(info->rate) < 0.01 ? 3 : 2, info->rate);
173
if (!(info->type & fSERV_Http) && info->type != fSERV_Dns)
282
174
s += sprintf(s, " S=%s", info->sful ? "yes" : "no");
175
s += sprintf(s, " T=%lu", (unsigned long)info->time);
363
229
else if (d > 1000.0)
237
if (type == fSERV_Dns)
239
if (!mime && MIME_ParseContentTypeEx(str + 1, &mime_t,
241
info->mime_t = mime_t;
242
info->mime_s = mime_s;
243
info->mime_e = mime_e;
245
while (*str && !isspace((unsigned char)(*str)))
370
250
if (!locl && sscanf(str, "=%3s%n", s, &n) >= 1) {
371
251
if (strcasecmp(s, "YES") == 0) {
372
info->locl = 1/*true*/;
375
} else if (strcasecmp(s, "NO") == 0) {
376
info->locl = 0/*false*/;
252
info->locl |= 0x01/*true in low nibble*/;
255
} else if (strcasecmp(s, "NO") == 0) {
256
info->locl &= ~0x0F/*false in low nibble*/;
263
if (type == fSERV_Dns)
265
if (!priv && sscanf(str, "=%3s%n", s, &n) >= 1) {
266
if (strcasecmp(s, "YES") == 0) {
267
info->locl |= 0x10;/*true in high nibble*/
270
} else if (strcasecmp(s, "NO") == 0) {
271
info->locl &= ~0xF0;/*false in high nibble*/
278
if (type == fSERV_Firewall || !info->host || quorum)
280
if (sscanf(str,"=%3s%n",s,&n) >= 1 && strcasecmp(s, "YES")==0){
281
info->quorum = (unsigned short)(-1);
284
} else if (sscanf(str, "=%hu%n", &h, &n) >= 1) {
291
if (!rate && sscanf(str, "=%lf%n", &d, &n) >= 1) {
294
else if (fabs(d) > 100000.0)
295
d = (d < 0.0 ? -1.0 : 1.0)*100000.0;
750
696
/*****************************************************************************
697
* DNS:: constructor and virtual functions
701
static char* s_Dns_Write(size_t reserve, const USERV_Info* u_info)
703
char* str = (char*) malloc(reserve + 1);
712
static SSERV_Info* s_Dns_Read(const char** str)
714
return SERV_CreateDnsInfo(0);
718
static size_t s_Dns_SizeOf(const USERV_Info* u)
720
return sizeof(u->dns);
725
static int/*bool*/ s_Dns_Equal(const USERV_Info* u1, const USERV_Info* u2)
731
SSERV_Info* SERV_CreateDnsInfo(unsigned int host)
733
SSERV_Info* info = (SSERV_Info*) malloc(sizeof(SSERV_Info));
736
info->type = fSERV_Dns;
740
info->locl = s_LocalServerDefault & 0x0F;
744
info->mime_t = SERV_MIME_TYPE_UNDEFINED;
745
info->mime_s = SERV_MIME_SUBTYPE_UNDEFINED;
746
info->mime_e = eENCOD_None;
747
info->flag = SERV_DEFAULT_FLAG;
748
memset(&info->reserved, 0, sizeof(info->reserved));
750
memset(&info->u.dns.pad, 0, sizeof(info->u.dns.pad));
756
/*****************************************************************************
751
757
* Attributes for the different server types:: Implementation
839
* --------------------------------------------------------------------------
840
* $Log: ncbi_server_info.c,v $
841
* Revision 6.53 2003/09/02 21:21:42 lavr
842
* Cleanup included headers
844
* Revision 6.52 2003/06/26 15:21:43 lavr
845
* Use server's default locality for fSERV_Dns infos
847
* Revision 6.51 2003/06/16 15:58:50 lavr
848
* Minor code format changes
850
* Revision 6.50 2003/05/31 05:16:28 lavr
851
* Add ARGSUSED where args are meant to be unused
853
* Revision 6.49 2003/04/25 15:21:05 lavr
854
* Explicit cast to avoid int->enum warning
856
* Revision 6.48 2003/03/13 19:08:26 lavr
857
* Allow missing type in Firewall server info specification
859
* Revision 6.47 2003/03/07 22:21:31 lavr
860
* Heed 'uninitted use' (false) warning by moving lines around
862
* Revision 6.46 2003/02/28 14:48:38 lavr
863
* String type match for size_t and int in few expressions
865
* Revision 6.45 2002/11/01 20:15:36 lavr
866
* Do not allow FIREWALL server specs to have Q flag
868
* Revision 6.44 2002/10/28 20:15:06 lavr
869
* -<connect/ncbi_server_info.h> ("ncbi_server_infop.h" should suffice)
871
* Revision 6.43 2002/10/28 15:46:21 lavr
872
* Use "ncbi_ansi_ext.h" privately
874
* Revision 6.42 2002/10/21 19:19:23 lavr
875
* 2(was:3)-digit precision if R is exactly 0.01
877
* Revision 6.41 2002/09/24 15:05:23 lavr
878
* Increase precision in SERV_Write() when R is small
880
* Revision 6.40 2002/09/17 15:39:33 lavr
881
* SSERV_Info::quorum moved past the reserved area
883
* Revision 6.39 2002/09/04 15:09:47 lavr
884
* Handle quorum field in SSERV_Info::, log moved to end
886
* Revision 6.38 2002/05/06 19:16:16 lavr
887
* +#include <stdio.h>
889
* Revision 6.37 2002/03/22 19:52:18 lavr
890
* Do not include <stdio.h>: included from ncbi_util.h or ncbi_priv.h
892
* Revision 6.36 2002/03/19 22:13:58 lavr
893
* Do not use home-made ANSI-extensions if the platform provides
895
* Revision 6.35 2002/03/11 21:59:00 lavr
896
* Support for changes in ncbi_server_info.h: DNS server type added as
897
* well as support for MIME encoding in server specifications
899
* Revision 6.34 2001/12/06 16:07:44 lavr
900
* More accurate string length estimation in SERV_WriteInfo()
902
* Revision 6.33 2001/11/25 22:12:00 lavr
903
* Replaced g_SERV_LocalServerDefault -> SERV_SetLocalServerDefault()
905
* Revision 6.32 2001/11/16 20:25:53 lavr
906
* +g_SERV_LocalServerDefault as a private global parameter
908
* Revision 6.31 2001/09/24 20:43:58 lavr
909
* TSERV_Flags reverted to 'int'; expilict cast added in comparison
911
* Revision 6.30 2001/09/10 21:17:10 lavr
912
* Support written for FIREWALL server type
914
* Revision 6.29 2001/06/19 19:12:01 lavr
915
* Type change: size_t -> TNCBI_Size; time_t -> TNCBI_Time
917
* Revision 6.28 2001/06/05 14:11:29 lavr
918
* SERV_MIME_UNDEFINED split into 2 (typed) constants:
919
* SERV_MIME_TYPE_UNDEFINED and SERV_MIME_SUBTYPE_UNDEFINED
921
* Revision 6.27 2001/06/04 17:01:06 lavr
922
* MIME type/subtype added to server descriptor
924
* Revision 6.26 2001/05/03 16:35:46 lavr
925
* Local bonus coefficient modified: meaning of negative value changed
927
* Revision 6.25 2001/04/24 21:38:21 lavr
928
* Additions to code to support new locality and bonus attributes of servers.
930
* Revision 6.24 2001/03/26 18:39:38 lavr
931
* Casting to (unsigned char) instead of (int) for ctype char.class macros
933
* Revision 6.23 2001/03/06 23:53:07 lavr
934
* SERV_ReadInfo can now consume either hostname or IP address
936
* Revision 6.22 2001/03/05 23:10:11 lavr
937
* SERV_WriteInfo & SERV_ReadInfo both take only one argument now
939
* Revision 6.21 2001/03/02 20:09:14 lavr
942
* Revision 6.20 2001/03/01 18:48:19 lavr
943
* NCBID allowed to have '' (special case) as an empty argument
945
* Revision 6.19 2001/01/03 22:34:44 lavr
946
* MAX_IP_ADDRESS_LEN -> MAX_IP_ADDR_LEN (as everywhere else)
948
* Revision 6.18 2000/12/29 17:59:38 lavr
949
* Reading and writing of SERV_Info now use SOCK_* utility functions
950
* SOCK_gethostaddr and SOCK_ntoa. More clean code for reading.
952
* Revision 6.17 2000/12/06 22:19:02 lavr
953
* Binary host addresses are now explicitly stated to be in network byte
954
* order, whereas binary port addresses now use native (host) representation
956
* Revision 6.16 2000/12/04 17:34:19 beloslyu
957
* the order of include files is important, especially on other Unixes!
958
* Look the man on inet_ntoa
960
* Revision 6.15 2000/10/20 17:13:30 lavr
961
* Service descriptor parse bug fixed
962
* Return empty string on unknown type (instead of abort) in 'SERV_TypeStr'
964
* Revision 6.14 2000/10/05 21:31:23 lavr
965
* Standalone connection marked "stateful" by default
967
* Revision 6.13 2000/06/05 20:21:20 lavr
968
* Eliminated gcc warning: "subscript has type `char'" in calls to
969
* classification macros (<ctype.h>) by explicit casting to unsigned chars
971
* Revision 6.12 2000/05/31 23:12:22 lavr
972
* First try to assemble things together to get working service mapper
974
* Revision 6.11 2000/05/24 16:45:15 lavr
975
* Introduced replacement for inet_ntoa: my_ntoa
977
* Revision 6.10 2000/05/23 21:05:33 lavr
978
* Memory leaks fixed (appeared after server-info structure rearrangement)
980
* Revision 6.9 2000/05/23 19:02:49 lavr
981
* Server-info now includes rate; verbal representation changed
983
* Revision 6.8 2000/05/22 16:53:11 lavr
984
* Rename service_info -> server_info everywhere (including
985
* file names) as the latter name is more relevant
987
* Revision 6.7 2000/05/18 14:12:43 lavr
990
* Revision 6.6 2000/05/17 16:15:13 lavr
991
* NCBI_* (for ANSI ext) undone - now "ncbi_ansi_ext.h" does good prototyping
993
* Revision 6.5 2000/05/17 14:22:32 lavr
994
* Small cosmetic changes
996
* Revision 6.4 2000/05/16 15:09:02 lavr
997
* Added explicit type casting to get "very smart" compilers happy
999
* Revision 6.3 2000/05/15 19:06:09 lavr
1000
* Use home-made ANSI extensions (NCBI_***)
1002
* Revision 6.2 2000/05/12 21:42:59 lavr
1003
* Cleaned up for the C++ compilation, etc.
1005
* Revision 6.1 2000/05/12 18:36:26 lavr
1006
* First working revision
1008
* ==========================================================================