andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: /* andre@0: * pkix_pl_socket.h andre@0: * andre@0: * Socket Object Type Definition andre@0: * andre@0: */ andre@0: andre@0: #ifndef _PKIX_PL_SOCKET_H andre@0: #define _PKIX_PL_SOCKET_H andre@0: andre@0: #include andre@0: #include "pkix_pl_common.h" andre@0: andre@0: #ifdef __cplusplus andre@0: extern "C" { andre@0: #endif andre@0: andre@0: typedef enum { andre@0: SOCKET_BOUND, andre@0: SOCKET_LISTENING, andre@0: SOCKET_ACCEPTPENDING, andre@0: SOCKET_UNCONNECTED, andre@0: SOCKET_CONNECTPENDING, andre@0: SOCKET_CONNECTED, andre@0: SOCKET_SENDPENDING, andre@0: SOCKET_RCVPENDING, andre@0: SOCKET_SENDRCVPENDING, andre@0: SOCKET_SHUTDOWN andre@0: } SockStatus; andre@0: andre@0: /* This is the default port number, if none is supplied to CreateByName. */ andre@0: #define LDAP_PORT 389 andre@0: andre@0: /* andre@0: * These callbacks allow a user to substitute a counterfeit socket in places andre@0: * where a PKIX_PL_Socket is expected. A conforming usage will use the andre@0: * ListenCallback function instead of Listen, AcceptCallback instead of Accept, andre@0: * etc. The counterfeit socket may have special capabilites such as the andre@0: * ability to do proxy authentication, etc. andre@0: */ andre@0: andre@0: typedef PKIX_Error * andre@0: (*pkix_pl_Socket_ListenCallback)( andre@0: PKIX_PL_Socket *socket, andre@0: PKIX_UInt32 backlog, andre@0: void *plContext); andre@0: andre@0: typedef PKIX_Error * andre@0: (*pkix_pl_Socket_AcceptCallback)( andre@0: PKIX_PL_Socket *socket, andre@0: PKIX_PL_Socket **pRendezvousSock, andre@0: void *plContext); andre@0: andre@0: typedef PKIX_Error * andre@0: (*pkix_pl_Socket_ConnectContinueCallback)( andre@0: PKIX_PL_Socket *socket, andre@0: PRErrorCode *pStatus, andre@0: void *plContext); andre@0: andre@0: typedef PKIX_Error * andre@0: (*pkix_pl_Socket_SendCallback)( andre@0: PKIX_PL_Socket *sendSock, andre@0: void *buf, andre@0: PKIX_UInt32 bytesToWrite, andre@0: PKIX_Int32 *pBytesWritten, andre@0: void *plContext); andre@0: andre@0: typedef PKIX_Error * andre@0: (*pkix_pl_Socket_RecvCallback)( andre@0: PKIX_PL_Socket *rcvSock, andre@0: void *buf, andre@0: PKIX_UInt32 capacity, andre@0: PKIX_Int32 *pBytesRead, andre@0: void *plContext); andre@0: andre@0: typedef PKIX_Error * andre@0: (*pkix_pl_Socket_PollCallback)( andre@0: PKIX_PL_Socket *sock, andre@0: PKIX_Int32 *pBytesWritten, andre@0: PKIX_Int32 *pBytesRead, andre@0: void *plContext); andre@0: andre@0: typedef PKIX_Error * andre@0: (*pkix_pl_Socket_ShutdownCallback)( andre@0: PKIX_PL_Socket *socket, void *plContext); andre@0: andre@0: typedef struct PKIX_PL_Socket_CallbackStruct { andre@0: pkix_pl_Socket_ListenCallback listenCallback; andre@0: pkix_pl_Socket_AcceptCallback acceptCallback; andre@0: pkix_pl_Socket_ConnectContinueCallback connectcontinueCallback; andre@0: pkix_pl_Socket_SendCallback sendCallback; andre@0: pkix_pl_Socket_RecvCallback recvCallback; andre@0: pkix_pl_Socket_PollCallback pollCallback; andre@0: pkix_pl_Socket_ShutdownCallback shutdownCallback; andre@0: } PKIX_PL_Socket_Callback; andre@0: andre@0: struct PKIX_PL_SocketStruct { andre@0: PKIX_Boolean isServer; andre@0: PRIntervalTime timeout; /* zero for non-blocking I/O */ andre@0: SockStatus status; andre@0: PRFileDesc *clientSock; andre@0: PRFileDesc *serverSock; andre@0: void *readBuf; andre@0: void *writeBuf; andre@0: PKIX_UInt32 readBufSize; andre@0: PKIX_UInt32 writeBufSize; andre@0: PRNetAddr *netAddr; andre@0: PKIX_PL_Socket_Callback callbackList; andre@0: }; andre@0: andre@0: /* see source file for function documentation */ andre@0: andre@0: PKIX_Error *pkix_pl_Socket_RegisterSelf(void *plContext); andre@0: andre@0: PKIX_Error * andre@0: pkix_pl_Socket_Create( andre@0: PKIX_Boolean isServer, andre@0: PRIntervalTime timeout, /* zero for non-blocking I/O */ andre@0: PRNetAddr *netAddr, andre@0: PRErrorCode *status, andre@0: PKIX_PL_Socket **pSocket, andre@0: void *plContext); andre@0: andre@0: PKIX_Error * andre@0: pkix_pl_Socket_CreateByName( andre@0: PKIX_Boolean isServer, andre@0: PRIntervalTime timeout, andre@0: char *serverName, andre@0: PRErrorCode *pStatus, andre@0: PKIX_PL_Socket **pSocket, andre@0: void *plContext); andre@0: andre@0: PKIX_Error * andre@0: pkix_pl_Socket_CreateByHostAndPort( andre@0: PKIX_Boolean isServer, andre@0: PRIntervalTime timeout, andre@0: char *hostname, andre@0: PRUint16 portnum, andre@0: PRErrorCode *pStatus, andre@0: PKIX_PL_Socket **pSocket, andre@0: void *plContext); andre@0: andre@0: /* Do not use these functions directly; use their callback variants instead andre@0: * static PKIX_Error * andre@0: * pkix_pl_Socket_Listen( andre@0: * PKIX_PL_Socket *socket, andre@0: * PKIX_UInt32 backlog, andre@0: * void *plContext); andre@0: * andre@0: * static PKIX_Error * andre@0: * pkix_pl_Socket_Accept( andre@0: * PKIX_PL_Socket *socket, andre@0: * PKIX_PL_Socket **pRendezvousSock, andre@0: * void *plContext); andre@0: * andre@0: * static PKIX_Error * andre@0: * pkix_pl_Socket_ConnectContinue( andre@0: * PKIX_PL_Socket *socket, andre@0: * PRErrorCode *pStatus, andre@0: * void *plContext); andre@0: * andre@0: * static PKIX_Error * andre@0: * pkix_pl_Socket_Send( andre@0: * PKIX_PL_Socket *sendSock, andre@0: * void *buf, andre@0: * PKIX_UInt32 bytesToWrite, andre@0: * PKIX_Int32 *pBytesWritten, andre@0: * void *plContext); andre@0: * andre@0: * static PKIX_Error * andre@0: * pkix_pl_Socket_Recv( andre@0: * PKIX_PL_Socket *rcvSock, andre@0: * void *buf, andre@0: * PKIX_UInt32 capacity, andre@0: * PKIX_Int32 *pBytesRead, andre@0: * void *plContext); andre@0: * andre@0: * static PKIX_Error * andre@0: * pkix_pl_Socket_Poll( andre@0: * PKIX_PL_Socket *sock, andre@0: * PKIX_Int32 *pBytesWritten, andre@0: * PKIX_Int32 *pBytesRead, andre@0: * void *plContext); andre@0: * andre@0: * static PKIX_Error * andre@0: * pkix_pl_Socket_Shutdown( andre@0: * PKIX_PL_Socket *socket, void *plContext); andre@0: */ andre@0: andre@0: PKIX_Error * andre@0: pkix_pl_Socket_GetCallbackList( andre@0: PKIX_PL_Socket *socket, andre@0: PKIX_PL_Socket_Callback **pCallbackList, andre@0: void *plContext); andre@0: andre@0: PKIX_Error * andre@0: pkix_pl_Socket_GetPRFileDesc( andre@0: PKIX_PL_Socket *socket, andre@0: PRFileDesc **pDesc, andre@0: void *plContext); andre@0: andre@0: #ifdef __cplusplus andre@0: } andre@0: #endif andre@0: andre@0: #endif /* _PKIX_PL_SOCKET_H */