📄 xptitcp.c
字号:
/*************************************************************************//* module: SyncML Communication Protocol selection module *//* file: src/xpt/win/xptitcp.c *//* target system: win *//* target OS: win *//*************************************************************************//** * This module contains Windows specific code for the * TCP/IP protocol handler for SyncML */#include "syncml_tk_prefix_file.h" // %%% luz: needed for precompiled headers in eVC++#include "xptitcp.h"// %%% luz:2003-04-17: Note this is Synthesis SySync farmework specific#ifdef PROGRESS_EVENTS // we need SySync-specific include to allow progress monitoring #include "global_progress.h"#endif// # of active socketsint _iNumSockets = 0;// %%% 2002-09-28 luz addedBool_t weOpenedNetLib = false;#ifdef DEBUGHACKS#warning "%%% This is hacky debug only!!"int netlibopenerr;int netlibtcperr;// %%%#endif/********************************************************//* Function: implementation of the strrchr() c-function *//********************************************************/// %%% luz 2002-09-12: changed arguments from (char *,char)// to be compatible with PalmOS CW headers// %%% luz 2002-09-12: changed name from strrchr, as this// causes name clashes.char *StrRChr (const char *pszString, int ch){ const char *p; for (p = pszString + strlen (pszString) - 1; p >= pszString; p --) if (*p == ch) break; if (p < pszString) p = NULL; return (char *)p;} // StrRChr/***********************************************************//* Function: Initialize the TCP/IP stack *//* This must be done the first time the process is started *//***********************************************************/int _initTCPStack (void){ int rc = 0; Err err; #ifdef DEBUGHACKS #warning "%%% This is hacky debug only!!" netlibopenerr=0; netlibtcperr=0; // %%% #endif /**********************************************************************/ /* Load the Net.lib library to initialize the Berkeley IP stack */ /* The Library reference number must be stored in the global variable */ /* AppNetRefnum that is defined in NetSocket.lib */ /**********************************************************************/ err = SysLibFind ("Net.lib", &AppNetRefnum); if (err != 0) rc = INVALID_SOCKET; /***********************************************************/ /* Set the IP timeout. the global variable AppNetTimeout, */ /* defined in NetSocket.lib, is set accordingly. */ /***********************************************************/ AppNetTimeout = SysTicksPerSecond () * TIMEOUT_SECONDS; /* Open the TCP-IP interface */ if (rc == 0) { Word tcp_rc; err = NetLibOpen (AppNetRefnum, &tcp_rc); if (err != 0) { rc = INVALID_SOCKET; #ifdef DEBUGHACKS #warning "%%% This is hacky debug only!!" netlibopenerr=err; // %%% #endif } else if (tcp_rc != 0) { rc = SOCKET_ERROR; // %%% luz 2002-12-02: netlib is already open, even if there is an interface problem // we need to close netlib again or else next retry will cause a netErrAlreadyOpen // at the next attempt to connect! NetLibClose (AppNetRefnum, false); #ifdef DEBUGHACKS #warning "%%% This is hacky debug only!!" netlibtcperr=tcp_rc; // %%% #endif } // %%% 2002-09-28 luz added else { // all ok weOpenedNetLib=true; // remember for _termTCPStack } } return rc;} // _initTCPStack#ifdef PALM_SSL// clean up SSL entirelyvoid sslCleanUp(void);#endif/****************************************//* Function: Clean-up the TCP/IP stack. *//****************************************/void _termTCPStack (Bool_t aImmediate){ // #if EMULATION_LEVEL != EMULATION_NONE // %%% luz 2002-11-28 : test for weOpenedNetLib to prevent // NetLibClose is not called if not opened before if (weOpenedNetLib) { NetLibClose (AppNetRefnum, aImmediate); weOpenedNetLib=false; } // if (AppNetRefnum) // NetLibFinishCloseWait(AppNetRefnum); #ifdef PALM_SSL // release the SSL library if we used it sslCleanUp(); #endif } // _termTCPStack#ifdef PALM_SSL// librarystatic Bool_t gSSLLibLoaded = false;static Bool_t gSSLLibOpen = false;static UInt16 gSSLlibRef = 0;// connectionSslLib *gSSLContextTemplate = NULL;SslContext *gSSLContext = NULL;// clean up SSL stuff releated tostatic void sslCleanUpConn(void) { // clean up current SSL connection if (gSSLContext) { SslContextDestroy(gSSLlibRef,gSSLContext); gSSLContext=NULL; } if (gSSLContextTemplate) { SslLibDestroy(gSSLlibRef,gSSLContextTemplate); gSSLContextTemplate=NULL; }} // sslCleanUpConn// clean up SSL entirelyvoid sslCleanUp(void){ // clean up current context sslCleanUpConn(); // clean up library if (gSSLLibOpen) { // lib is open, close it SslLibClose(gSSLlibRef); gSSLLibOpen=false; } // unload if we loaded it if (gSSLLibLoaded) { // we have loaded it, unload now SysLibRemove(gSSLlibRef); gSSLLibLoaded=false; }} // sslCleanUp// verify callbackstatic Int32 verifyCallbackFunc( SslCallback *aCallbackStruct, Int32 aCommand, Int32 aFlavor, void *aInfo){ Int32 ret = errNone; // assume ok switch (aCommand) { case sslCmdVerify: // default to failing on verify problems ret = aFlavor; // verify switch (aFlavor) { case sslErrVerifyNoTrustedRoot: // certificate could not be verified #ifdef PROGRESS_EVENTS if (GlobalNotifyProgressEvent(pev_ssl_notrust,0,0)) ret=errNone; // user allows // %%%% evtl: sslErrOk ??? #endif break; case sslErrVerifyNotAfter: case sslErrVerifyNotBefore: // certificate has expired #ifdef PROGRESS_EVENTS if (GlobalNotifyProgressEvent(pev_ssl_expired,0,0)) ret=errNone; // user allows #endif break; } // switch break; case sslCmdNew: case sslCmdReset: case sslCmdFree: break; } // return status return ret;} // verifyCallbackFunc// enable SSL for specified socketTcpRc_t tcpEnableSSL(SocketPtr_t pSocket, Bool_t aConnected){ TcpRc_t rc = TCP_RC_OK; SOCKET lSocket = pSocket ? (SOCKET) *pSocket : -1L; // SSL vars SslCallback verifyCallback; Err err; // we need to do things only after the connection is open if (!aConnected) return TCP_RC_OK; // connected, now we can go on if (lSocket == -1L) return TCP_RC_ERROR; // Note: this SSL implementation is only good for a single SSL socket // at a time if (gSSLContext) return TCP_RC_ERROR; // SSL context already open, must close socket first // secure client connection requested /* Part 1: Find and open the SSL library. * Note that you only have to do this if you抮e * writing 68k code; ARM code can skip this step. */ // - Find the SSL library if (!gSSLLibOpen) { if (SysLibFind(kSslDBName,&gSSLlibRef) != errNone) { if (SysLibLoad(kSslLibType,kSslLibCreator,&gSSLlibRef) != errNone) { // No SSL available return TCP_RC_ENOPROTOOPT; } gSSLLibLoaded = true; } // - open the SSL library if (SslLibOpen(gSSLlibRef) != errNone) { sslCleanUp(); return TCP_RC_ENOPROTOOPT; } gSSLLibOpen = true; } /* Part 2: Create an SslLib object (which acts as an * 慡SL context template
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -