2
* ===========================================================================
5
* National Center for Biotechnology Information (NCBI)
7
* This software/database is a "United States Government Work" under the
8
* terms of the United States Copyright Act. It was written as part of
9
* the author's official duties as a United States Government employee and
10
* thus cannot be copyrighted. This software/database is freely available
11
* to the public for use. The National Library of Medicine and the U.S.
12
* Government do not place any restriction on its use or reproduction.
13
* We would, however, appreciate having the NCBI and the author cited in
14
* any work or product based on this material
16
* Although all reasonable efforts have been taken to ensure the accuracy
17
* and reliability of the software and data, the NLM and the U.S.
18
* Government do not and cannot warrant the performance or results that
19
* may be obtained by using this software or data. The NLM and the U.S.
20
* Government disclaim all warranties, express or implied, including
21
* warranties of performance, merchantability or fitness for any particular
24
* ===========================================================================
26
* File Name: urlquery.c
28
* Author: Jonathan Kans
30
* Version Creation Date: 4/16/98
37
* --------------------------------------------------------------------------
38
* $Log: urlquery.c,v $
39
* Revision 6.33 2005/12/01 18:47:49 lavr
42
* Revision 6.32 2004/09/16 19:16:45 lavr
43
* QUERY_OpenUrlQuery() to set port only if provided as non-zero
45
* Revision 6.31 2004/09/14 19:09:41 lavr
46
* Correct last change log entry
48
* Revision 6.30 2004/09/14 18:52:12 kans
49
* QUERY_OpenUrlQuery makes content type only if type < eMIME_T_Unknown
51
* Revision 6.29 2004/09/14 18:47:51 kans
52
* QUERY_OpenUrlQuery looks for eMIME_T_Unknown, does not compost content type
54
* Revision 6.28 2004/02/23 15:30:02 lavr
55
* New (last) parameter "how" added in CONN_Write() API call
57
* Revision 6.27 2003/10/21 18:27:43 lavr
58
* QUERY_OpenServiceQuery(): Timeout override changed
60
* Revision 6.26 2003/09/03 21:15:29 lavr
61
* Reuse "arguments" in QUERY_OpenServiceQuery() to be real service argument
62
* (formely it was to modify the dispatcher and was not really used anywhere)
64
* Revision 6.25 2003/05/29 21:54:20 kans
65
* QUERY_CheckQueue calls callback and dequeues connection if status is eIO_Closed as well as eIO_Success - callbacks already check status before trying to read
67
* Revision 6.24 2003/05/29 19:02:56 kans
68
* badstatus only used for future debugging purposes, does not block further checks, also increments count of remaining queued connections for return value
70
* Revision 6.23 2003/05/29 18:39:54 kans
71
* QUERY_CheckQueue sets new badstatus field, protects against further checks, if eIO_Timeout or eIO_Closed
73
* Revision 6.22 2002/11/21 20:35:41 kans
74
* forgot to call ConnNetInfo_Destroy if bailing due to NULL connector
76
* Revision 6.21 2002/11/21 19:46:32 kans
77
* if connector is NULL, do not call CONN_Create
79
* Revision 6.20 2002/08/07 18:45:17 lavr
80
* Change from deprecated to current EIO_ReadMethod enums
82
* Revision 6.19 2002/07/02 17:17:58 kans
85
* Revision 6.18 2001/09/25 13:20:56 lavr
86
* SERVICE_CreateConnectorEx() - number of args adjusted
88
* Revision 6.17 2001/08/16 18:07:04 kans
89
* protect against calling CONN_Read or CONN_Write with NULL conn parameter
91
* Revision 6.16 2001/06/07 20:17:34 kans
92
* in QUERY_OpenServiceQuery, pass service to ConnNetInfo_Create
94
* Revision 6.15 2001/06/07 20:07:41 kans
95
* added QUERY_OpenServiceQuery
97
* Revision 6.14 2001/04/25 15:14:27 lavr
98
* SConnNetInfo::timeout is now a pointer
100
* Revision 6.13 2001/02/25 21:42:27 kans
101
* changed several Uint4s to size_t due to new prototypes
103
* Revision 6.12 2001/02/21 22:02:04 lavr
104
* Changes for use new CONN interface
106
* Revision 6.11 2000/08/18 19:08:58 kans
107
* added QUERY_WaitForNextMacEvent, otherwise QuickDraw collides with mmdbapi
109
* Revision 6.10 2000/06/30 18:16:09 kans
110
* protect against reentrant calls if resultproc is GUI and processes timer - showed up on PC/Windows, not Mac or UNIX version of Sequin
112
* Revision 6.9 2000/06/30 12:46:10 kans
113
* added QUERY_CloseQueue
115
* Revision 6.8 2000/06/29 18:27:10 kans
116
* QUERY_OpenUrlQuery has new EMIME_Type type and EMIME_Encoding encoding parameters
118
* Revision 6.7 2000/06/13 12:58:14 kans
119
* added closeConn parameter to QUERY_AddToQueue
121
* Revision 6.6 1999/07/28 21:09:15 vakatov
122
* Multiple fixes in QUERY_OpenUrlQuery() to make it work with a generic
123
* URL server; also, pass arguments in the cmd.-line
125
* ==========================================================================
1
/* $Id: urlquery.c,v 6.39 2006/04/19 02:11:23 lavr Exp $
2
* ===========================================================================
5
* National Center for Biotechnology Information (NCBI)
7
* This software/database is a "United States Government Work" under the
8
* terms of the United States Copyright Act. It was written as part of
9
* the author's official duties as a United States Government employee and
10
* thus cannot be copyrighted. This software/database is freely available
11
* to the public for use. The National Library of Medicine and the U.S.
12
* Government do not place any restriction on its use or reproduction.
13
* We would, however, appreciate having the NCBI and the author cited in
14
* any work or product based on this material
16
* Although all reasonable efforts have been taken to ensure the accuracy
17
* and reliability of the software and data, the NLM and the U.S.
18
* Government do not and cannot warrant the performance or results that
19
* may be obtained by using this software or data. The NLM and the U.S.
20
* Government disclaim all warranties, express or implied, including
21
* warranties of performance, merchantability or fitness for any particular
24
* ===========================================================================
26
* File Name: urlquery.c
28
* Author: Jonathan Kans
30
* Version Creation Date: 4/16/98
37
* --------------------------------------------------------------------------
38
* $Log: urlquery.c,v $
39
* Revision 6.39 2006/04/19 02:11:23 lavr
40
* QUERY_OpenServiceQuery: Use PostOverrideArg instead of AppendArg
42
* Revision 6.38 2006/04/19 01:41:52 lavr
43
* QUERY_OpenServiceQuery(): Take advantage of ConnNetInfo_*Arg API
45
* Revision 6.37 2006/04/17 16:47:50 lavr
46
* QUERY_OpenServiceQueryEx not to override but append argument in net_info
48
* Revision 6.36 2006/04/15 01:59:01 lavr
49
* +QUERY_OpenServiceQueryEx
51
* Revision 6.35 2006/01/19 21:11:15 lavr
52
* QUERY_SendQuery() to return EIO_Status
54
* Revision 6.34 2006/01/17 21:11:51 lavr
55
* Formatting; a few minor code improvements; a few minor bugfixes
57
* Revision 6.33 2005/12/01 18:47:49 lavr
60
* Revision 6.32 2004/09/16 19:16:45 lavr
61
* QUERY_OpenUrlQuery() to set port only if provided as non-zero
63
* Revision 6.31 2004/09/14 19:09:41 lavr
64
* Correct last change log entry
66
* Revision 6.30 2004/09/14 18:52:12 kans
67
* QUERY_OpenUrlQuery makes content type only if type < eMIME_T_Unknown
69
* Revision 6.29 2004/09/14 18:47:51 kans
70
* QUERY_OpenUrlQuery looks for eMIME_T_Unknown, does not compost content type
72
* Revision 6.28 2004/02/23 15:30:02 lavr
73
* New (last) parameter "how" added in CONN_Write() API call
75
* Revision 6.27 2003/10/21 18:27:43 lavr
76
* QUERY_OpenServiceQuery(): Timeout override changed
78
* Revision 6.26 2003/09/03 21:15:29 lavr
79
* Reuse "arguments" in QUERY_OpenServiceQuery() to be real service argument
80
* (formely it was to modify the dispatcher and was not really used anywhere)
82
* Revision 6.25 2003/05/29 21:54:20 kans
83
* QUERY_CheckQueue calls callback and dequeues connection if status is
84
* eIO_Closed as well as eIO_Success - callbacks already check status
85
* before trying to read
87
* Revision 6.24 2003/05/29 19:02:56 kans
88
* badstatus only used for future debugging purposes, does not block further
89
* checks, also increments count of remaining queued connections for return
92
* Revision 6.23 2003/05/29 18:39:54 kans
93
* QUERY_CheckQueue sets new badstatus field, protects against further checks,
94
* if eIO_Timeout or eIO_Closed
96
* Revision 6.22 2002/11/21 20:35:41 kans
97
* forgot to call ConnNetInfo_Destroy if bailing due to NULL connector
99
* Revision 6.21 2002/11/21 19:46:32 kans
100
* if connector is NULL, do not call CONN_Create
102
* Revision 6.20 2002/08/07 18:45:17 lavr
103
* Change from deprecated to current EIO_ReadMethod enums
105
* Revision 6.19 2002/07/02 17:17:58 kans
106
* fixed error message
108
* Revision 6.18 2001/09/25 13:20:56 lavr
109
* SERVICE_CreateConnectorEx() - number of args adjusted
111
* Revision 6.17 2001/08/16 18:07:04 kans
112
* protect against calling CONN_Read or CONN_Write with NULL conn parameter
114
* Revision 6.16 2001/06/07 20:17:34 kans
115
* in QUERY_OpenServiceQuery, pass service to ConnNetInfo_Create
117
* Revision 6.15 2001/06/07 20:07:41 kans
118
* added QUERY_OpenServiceQuery
120
* Revision 6.14 2001/04/25 15:14:27 lavr
121
* SConnNetInfo::timeout is now a pointer
123
* Revision 6.13 2001/02/25 21:42:27 kans
124
* changed several Uint4s to size_t due to new prototypes
126
* Revision 6.12 2001/02/21 22:02:04 lavr
127
* Changes for use new CONN interface
129
* Revision 6.11 2000/08/18 19:08:58 kans
130
* added QUERY_WaitForNextMacEvent, otherwise QuickDraw collides with mmdbapi
132
* Revision 6.10 2000/06/30 18:16:09 kans
133
* protect against reentrant calls if resultproc is GUI and processes timer -
134
* showed up on PC/Windows, not Mac or UNIX version of Sequin
136
* Revision 6.9 2000/06/30 12:46:10 kans
137
* added QUERY_CloseQueue
139
* Revision 6.8 2000/06/29 18:27:10 kans
140
* QUERY_OpenUrlQuery has new EMIME_Type type and EMIME_Encoding
141
* encoding parameters
143
* Revision 6.7 2000/06/13 12:58:14 kans
144
* added closeConn parameter to QUERY_AddToQueue
146
* Revision 6.6 1999/07/28 21:09:15 vakatov
147
* Multiple fixes in QUERY_OpenUrlQuery() to make it work with a generic
148
* URL server; also, pass arguments in the cmd.-line
150
* ==========================================================================
128
153
#include "asnbuild.h"
129
154
#include <urlquery.h>
132
158
#include <Events.h>
134
160
NLM_EXTERN void QUERY_WaitForNextMacEvent (void)
137
162
EventRecord currEvent;
197
217
/* fill in connection info fields and create the connection */
198
218
info = ConnNetInfo_Create(0);
201
if ( host_machine ) {
202
StringNCpy_0(info->host, host_machine, sizeof(info->host));
221
if (! StringHasNoText (host_machine)) {
222
StringNCpy_0 (info->host, host_machine, sizeof(info->host));
204
224
if ( host_port ) {
205
225
info->port = host_port;
207
if ( !StringHasNoText(arguments) ) {
208
StringNCpy_0(info->args, arguments, sizeof(info->args));
227
if ( !StringHasNoText (arguments)) {
228
StringNCpy_0 (info->args, arguments, sizeof(info->args));
210
StringNCpy_0(info->path, host_path, sizeof(info->path));
230
StringNCpy_0 (info->path, host_path, sizeof(info->path));
212
232
if ( info->timeout ) {
213
233
info->timeout->sec = timeoutsec;
214
234
info->timeout->usec = 0;
217
connector = HTTP_CreateConnector(info, user_header, flags);
237
connector = HTTP_CreateConnector (info, user_header, flags);
238
ConnNetInfo_Destroy (info);
218
240
if (connector == NULL) {
219
241
ErrPostEx (SEV_ERROR, 0, 0, "QUERY_OpenUrlQuery failed in HTTP_CreateConnector");
220
ConnNetInfo_Destroy(info);
223
status = CONN_Create(connector, &conn);
224
if (status != eIO_Success) {
243
} else if ((status = CONN_Create(connector, &conn)) != eIO_Success) {
225
244
ErrPostEx(SEV_ERROR, 0, 0, "QUERY_OpenUrlQuery failed in CONN_Create");
245
ASSERT (conn == NULL);
228
/* cleanup & return */
229
ConnNetInfo_Destroy(info);
234
NLM_EXTERN CONN QUERY_OpenServiceQuery (
252
NLM_EXTERN CONN QUERY_OpenServiceQueryEx (
235
253
Nlm_CharPtr service,
236
Nlm_CharPtr arguments,
254
Nlm_CharPtr parameters,
255
Nlm_Uint4 timeoutsec,
256
Nlm_CharPtr arguments
262
SConnNetInfo* net_info;
248
265
/* fill in connection info fields and create the connection */
249
info = ConnNetInfo_Create (service);
266
net_info = ConnNetInfo_Create (service);
252
269
if (timeoutsec == (Nlm_Uint4)(-1)) {
270
net_info->timeout = 0;
254
271
} else if ( timeoutsec ) {
255
info->tmo.sec = timeoutsec;
257
info->timeout = &info->tmo;
272
net_info->tmo.sec = timeoutsec;
273
net_info->tmo.usec = 0;
274
net_info->timeout = &net_info->tmo;
260
connector = SERVICE_CreateConnectorEx (service, fSERV_Any, info, 0);
276
ConnNetInfo_PostOverrideArg(net_info, arguments, 0);
278
connector = SERVICE_CreateConnectorEx (service, fSERV_Any, net_info, 0);
280
ConnNetInfo_Destroy (net_info);
261
282
if (connector == NULL) {
262
283
ErrPostEx (SEV_ERROR, 0, 0, "QUERY_OpenServiceQuery failed in SERVICE_CreateConnectorEx");
263
ConnNetInfo_Destroy (info);
267
status = CONN_Create (connector, &conn);
268
if (status != eIO_Success) {
285
} else if ((status = CONN_Create (connector, &conn)) != eIO_Success) {
269
286
ErrPostEx (SEV_ERROR, 0, 0, "QUERY_OpenServiceQuery failed in CONN_Create");
271
} else if ( !StringHasNoText (arguments) ) {
272
args_len = StringLen (arguments);
273
status = CONN_Write (conn, arguments, args_len,
274
&n_written, eIO_WritePersist);
287
ASSERT (conn == NULL);
288
} else if (! StringHasNoText (parameters)) {
289
status = CONN_Write (conn, parameters, StringLen (parameters), &n_written, eIO_WritePersist);
275
290
if (status != eIO_Success) {
276
ErrPostEx (SEV_ERROR, 0, 0, "QUERY_OpenServiceQuery failed to write arguments in CONN_Write");
291
ErrPostEx (SEV_ERROR, 0, 0, "QUERY_OpenServiceQuery failed to write service parameters in CONN_Write");
277
292
CONN_Close (conn);
282
/* cleanup & return */
283
ConnNetInfo_Destroy (info);
288
NLM_EXTERN void QUERY_SendQuery (
301
NLM_EXTERN CONN QUERY_OpenServiceQuery (
303
Nlm_CharPtr parameters,
307
return QUERY_OpenServiceQueryEx (service, parameters, timeoutsec, 0);
311
NLM_EXTERN EIO_Status QUERY_SendQuery (
316
static const STimeout timeout = { 0 };
295
if (conn == 0) return;
319
if (conn == NULL) return eIO_Closed;
297
321
/* flush buffer, sending query, without waiting for response */
301
CONN_Wait (conn, eIO_Read, &timeout);
322
status = CONN_Wait (conn, eIO_Read, &timeout);
323
return status == eIO_Timeout ? eIO_Success : status;
304
327
#define URL_QUERY_BUFLEN 4096
306
329
NLM_EXTERN void QUERY_CopyFileToQuery (
312
334
Nlm_CharPtr buffer;