📄 ncbi_service_connector.c
字号:
memset(&uuu->meta, 0, sizeof(uuu->meta)); METACONN_Add(&uuu->meta, conn); /* ...then link the new connector in using current connection's meta */ conn->meta = meta; conn->next = meta->list; meta->list = conn; CONN_SET_METHOD(meta, descr, uuu->meta.descr, uuu->meta.c_descr); CONN_SET_METHOD(meta, wait, uuu->meta.wait, uuu->meta.c_wait); CONN_SET_METHOD(meta, write, uuu->meta.write, uuu->meta.c_write); CONN_SET_METHOD(meta, flush, uuu->meta.flush, uuu->meta.c_flush); CONN_SET_METHOD(meta, read, uuu->meta.read, uuu->meta.c_read); CONN_SET_METHOD(meta, status, uuu->meta.status, uuu->meta.c_status);#ifdef IMPLEMENTED__CONN_WaitAsync CONN_SET_METHOD(meta, wait_async, uuu->meta.wait_async, uuu->meta.c_wait_async);#endif if (uuu->meta.get_type) { const char* type; if ((type = uuu->meta.get_type(uuu->meta.c_get_type)) != 0) { static const char prefix[] = "SERVICE/"; char* name = (char*) malloc(sizeof(prefix) + strlen(type)); if (name) { strcpy(&name[0], prefix); strcpy(&name[sizeof(prefix)-1], type); uuu->name = name; } } } status = uuu->meta.open ? uuu->meta.open(uuu->meta.c_open, timeout) : eIO_Success; if (status == eIO_Success) break; s_Close(connector, timeout, 0/*don't close dispatcher!*/); } uuu->status = status; return status;}/*ARGSUSED*/static EIO_Status s_VT_Status(CONNECTOR connector, EIO_Event dir){ return ((SServiceConnector*) connector->handle)->status;}static EIO_Status s_VT_Close(CONNECTOR connector, const STimeout* timeout){ return s_Close(connector, timeout, 1/*close_dispatcher*/);}static void s_Setup(SMetaConnector *meta, CONNECTOR connector){ SServiceConnector* uuu = (SServiceConnector*) connector->handle; /* initialize virtual table */ CONN_SET_METHOD(meta, get_type, s_VT_GetType, connector); CONN_SET_METHOD(meta, open, s_VT_Open, connector); CONN_SET_METHOD(meta, close, s_VT_Close, connector); CONN_SET_DEFAULT_TIMEOUT(meta, uuu->net_info->timeout); /* all the rest is reset to NULL */ s_Reset(meta);}static void s_Destroy(CONNECTOR connector){ SServiceConnector* uuu = (SServiceConnector*) connector->handle; s_CloseDispatcher(uuu); if (uuu->params.cleanup) uuu->params.cleanup(uuu->params.data); ConnNetInfo_Destroy(uuu->net_info); if (uuu->name) free((void*) uuu->name); free((void*) uuu->service); free(uuu); connector->handle = 0; free(connector);}/*********************************************************************** * EXTERNAL -- the connector's "constructor" ***********************************************************************/extern CONNECTOR SERVICE_CreateConnectorEx(const char* service, TSERV_Type types, const SConnNetInfo* net_info, const SSERVICE_Extra* params){ CONNECTOR ccc; SServiceConnector* xxx; char* x_args; SConnNetInfo* x_net_info; if (!service || !*service) return 0; x_net_info = net_info ? ConnNetInfo_Clone(net_info) : ConnNetInfo_Create(service); x_args = s_GetArgs(x_net_info->client_host); ccc = (SConnector*) malloc(sizeof(SConnector)); xxx = (SServiceConnector*) malloc(sizeof(SServiceConnector) + (x_args ? strlen(x_args) : 0)); xxx->name = 0; xxx->service = SERV_ServiceName(service); xxx->net_info = x_net_info; if (types & fSERV_StatelessOnly) xxx->net_info->stateless = 1/*true*/; if (types & fSERV_Firewall) xxx->net_info->firewall = 1/*true*/; xxx->status = eIO_Success; xxx->types = types; xxx->iter = 0; memset(&xxx->params, 0, sizeof(xxx->params)); memset(&xxx->meta, 0, sizeof(xxx->meta)); if (x_args) { strcpy(xxx->args, x_args); free(x_args); } else xxx->args[0] = '\0'; /* initialize connector structure */ ccc->handle = xxx; ccc->next = 0; ccc->meta = 0; ccc->setup = s_Setup; ccc->destroy = s_Destroy; /* now make the first probe dispatching */ if (!s_OpenDispatcher(xxx)) { s_CloseDispatcher(xxx); s_Destroy(ccc); return 0; } assert(xxx->iter != 0); /* finally, store all callback parameters */ if (params) memcpy(&xxx->params, params, sizeof(xxx->params)); /* done */ return ccc;}/* * -------------------------------------------------------------------------- * $Log: ncbi_service_connector.c,v $ * Revision 1000.0 2003/10/29 16:39:51 gouriano * PRODUCTION: IMPORTED [ORIGINAL] Dev-tree R6.60 * * Revision 6.60 2003/08/25 14:41:53 lavr * Employ new k..Timeout constants -- log modification only * * Revision 6.59 2003/05/31 05:16:45 lavr * Add ARGSUSED where args are meant to be unused * * Revision 6.58 2003/05/29 20:13:48 lavr * -#include <connect/ncbi_connection.h> * * Revision 6.57 2003/05/22 20:31:28 lavr * Callbacks in the constructor had to be set after successful init only * * Revision 6.56 2003/05/14 15:43:45 lavr * Modify format of host address in dispatcher's CGI query * * Revision 6.55 2003/05/14 13:55:06 lavr * BUGFIX: Buffer overrun in s_GetArgs() * * Revision 6.54 2003/05/14 04:19:48 lavr * BUGFIX: Actually add IP address in "address=" CGI argument * * Revision 6.53 2003/05/14 03:55:28 lavr * Arguments to include host address (for statistics purposes on backends) * * Revision 6.52 2002/12/19 17:34:58 lavr * Do not initiate STATEFUL_CAPABLE challenge with HTTP servers in relay mode * * Revision 6.51 2002/12/10 22:11:50 lavr * Stamp HTTP packets with "User-Agent:" header tag and DISP_PROTOCOL_VERSION * * Revision 6.50 2002/11/19 19:23:25 lavr * Set MIME type whenever possible; introduce status of last op * * Revision 6.49 2002/11/12 05:52:00 lavr * Use client_host from conn.info as value for "address=" * * Revision 6.48 2002/11/01 20:16:05 lavr * Expand hostname buffers to hold up to 256 chars * * Revision 6.47 2002/10/29 22:19:37 lavr * Fix proper use of non-transparent proxy if one is specified * * Revision 6.46 2002/10/28 15:44:00 lavr * Use "ncbi_ansi_ext.h" privately and use strncpy0() * * Revision 6.45 2002/10/22 15:11:24 lavr * Zero connector's handle to crash if revisited * * Revision 6.44 2002/10/21 18:32:28 lavr * Append service arguments "address" and "platform" in dispatcher requests * * Revision 6.43 2002/10/11 19:56:42 lavr * Add "myargs" into connector structure (for later use in requests to * show address and platform of the dispatcher's requestors) * * Revision 6.42 2002/09/06 17:45:33 lavr * Include <connect/ncbi_priv.h> unconditionally (reported by J.Kans) * * Revision 6.41 2002/09/06 15:44:02 lavr * Use fHCC_SureFlush and CONN_Flush() instead of dummy read * * Revision 6.40 2002/08/07 16:33:33 lavr * Changed EIO_ReadMethod enums accordingly; log moved to end * * Revision 6.39 2002/06/10 19:51:43 lavr * Wrong assertion removed from FIREWALL open case * * Revision 6.38 2002/05/07 15:31:47 lavr * +#include <stdio.h>: noticed by J.Kans * * Revision 6.37 2002/05/06 19:17:33 lavr * Take advantage of SERV_ServiceName() * * Revision 6.36 2002/04/26 16:28:51 lavr * SSERVICE_Params: reset added for use in open/close pairs * No checks for kDefaultTimeout: now real timeouts always go from CONN * * Revision 6.35 2002/03/30 03:34:32 lavr * BUGFIX: Memory leak from SERV_ITER in usused connector * * Revision 6.34 2002/03/22 22:18:28 lavr * Remove uuu->conn (contained in uuu->meta.list); honor timeout on open * * Revision 6.33 2002/03/22 19:52:18 lavr * Do not include <stdio.h>: included from ncbi_util.h or ncbi_priv.h * * Revision 6.32 2002/03/19 22:14:53 lavr * Proper indentation of nested preprocessor directives * * Revision 6.31 2002/03/11 22:00:22 lavr * Support encoding in MIME content type for server data * * Revision 6.30 2001/12/04 15:56:47 lavr * Use strdup() instead of explicit strcpy(malloc(...), ...) * * Revision 6.29 2001/10/26 21:17:59 lavr * 'service=name' now always precedes other params in connects to DISPD/NCBID * * Revision 6.28 2001/09/28 20:51:31 lavr * Comments revised; parameter (and SHttpConnector's) names adjusted * Retry logic moved entirely into s_Adjust() * * Revision 6.27 2001/09/24 20:29:36 lavr * +SSERVICE_Extra* parameter in constructor; store and use of this parameter * * Revision 6.26 2001/09/10 21:21:20 lavr * Support for temporary switching into firewall mode as per dispatcher request * * Revision 6.25 2001/07/26 15:12:17 lavr * while(1) -> for(;;) * * Revision 6.24 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.23 2001/06/04 17:02:17 lavr * Insert MIME type/subtype in Content-Type for servers, * which have this feature configured * * Revision 6.22 2001/05/30 18:46:38 lavr * Always call dispatcher in header-parsing callback (to see err.msg. if any) * * Revision 6.21 2001/05/23 21:53:19 lavr * Do not close dispatcher in Open; leave it as it is * * Revision 6.20 2001/05/17 15:03:07 lavr * Typos corrected * * Revision 6.19 2001/05/11 15:32:05 lavr * Minor patch in code of 'fallback to STATELESS' * * Revision 6.18 2001/05/08 20:27:05 lavr * Patches in re-try code * * Revision 6.17 2001/05/03 16:37:09 lavr * Flow control fixed in s_Open for firewall connection * * Revision 6.16 2001/04/26 20:20:57 lavr * Default tags are explicitly used to differ from a Web browser * * Revision 6.15 2001/04/25 15:49:54 lavr * Memory leaks in Open (when unsuccessful) fixed * * Revision 6.14 2001/04/24 21:36:50 lavr * More structured code to re-try abrupted connection/mapping attempts * * Revision 6.13 2001/03/07 23:01:07 lavr * fSERV_Any used instead of 0 in SERVICE_CreateConnector * * Revision 6.12 2001/03/06 23:55:37 lavr * SOCK_gethostaddr -> SOCK_gethostbyname * * Revision 6.11 2001/03/02 20:10:07 lavr * Typo fixed * * Revision 6.10 2001/03/01 00:32:15 lavr * FIX: Empty update does not generate parse error * * Revision 6.9 2001/02/09 17:35:45 lavr * Modified: fSERV_StatelessOnly overrides info->stateless * Bug fixed: free(type) -> free(name) * * Revision 6.8 2001/01/25 17:04:43 lavr * Reversed:: DESTROY method calls free() to delete connector structure * * Revision 6.7 2001/01/23 23:09:19 lavr * Flags added to 'Ex' constructor * * Revision 6.6 2001/01/11 16:38:18 lavr * free(connector) removed from s_Destroy function * (now always called from outside, in METACONN_Remove) * * Revision 6.5 2001/01/08 22:39:40 lavr * Further development of service-mapping protocol: stateless/stateful * is now separated from firewall/direct mode (see also in few more files) * * Revision 6.4 2001/01/03 22:35:53 lavr * Next working revision (bugfixes and protocol changes) * * Revision 6.3 2000/12/29 18:05:12 lavr * First working revision. * * Revision 6.2 2000/10/20 17:34:39 lavr * Partially working service connector (service mapping works) * Checkin for backup purposes * * Revision 6.1 2000/10/07 22:14:07 lavr * Initial revision, placeholder mostly * * ========================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -