nss: import at 3.0.1 beta 1
[mozilla-nss.git] / security / nss / lib / libpkix / pkix_pl_nss / module / pkix_pl_socket.h
blob133c620c3f4f173fda7a425be20d1d49fc40d9dd
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the PKIX-C library.
16 * The Initial Developer of the Original Code is
17 * Sun Microsystems, Inc.
18 * Portions created by the Initial Developer are
19 * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
21 * Contributor(s):
22 * Sun Microsystems, Inc.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 * pkix_pl_socket.h
40 * Socket Object Type Definition
44 #ifndef _PKIX_PL_SOCKET_H
45 #define _PKIX_PL_SOCKET_H
47 #include <errno.h>
48 #include "pkix_pl_common.h"
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
54 typedef enum {
55 SOCKET_BOUND,
56 SOCKET_LISTENING,
57 SOCKET_ACCEPTPENDING,
58 SOCKET_UNCONNECTED,
59 SOCKET_CONNECTPENDING,
60 SOCKET_CONNECTED,
61 SOCKET_SENDPENDING,
62 SOCKET_RCVPENDING,
63 SOCKET_SENDRCVPENDING,
64 SOCKET_SHUTDOWN
65 } SockStatus;
67 /* This is the default port number, if none is supplied to CreateByName. */
68 #define LDAP_PORT 389
71 * These callbacks allow a user to substitute a counterfeit socket in places
72 * where a PKIX_PL_Socket is expected. A conforming usage will use the
73 * ListenCallback function instead of Listen, AcceptCallback instead of Accept,
74 * etc. The counterfeit socket may have special capabilites such as the
75 * ability to do proxy authentication, etc.
78 typedef PKIX_Error *
79 (*pkix_pl_Socket_ListenCallback)(
80 PKIX_PL_Socket *socket,
81 PKIX_UInt32 backlog,
82 void *plContext);
84 typedef PKIX_Error *
85 (*pkix_pl_Socket_AcceptCallback)(
86 PKIX_PL_Socket *socket,
87 PKIX_PL_Socket **pRendezvousSock,
88 void *plContext);
90 typedef PKIX_Error *
91 (*pkix_pl_Socket_ConnectContinueCallback)(
92 PKIX_PL_Socket *socket,
93 PRErrorCode *pStatus,
94 void *plContext);
96 typedef PKIX_Error *
97 (*pkix_pl_Socket_SendCallback)(
98 PKIX_PL_Socket *sendSock,
99 void *buf,
100 PKIX_UInt32 bytesToWrite,
101 PKIX_Int32 *pBytesWritten,
102 void *plContext);
104 typedef PKIX_Error *
105 (*pkix_pl_Socket_RecvCallback)(
106 PKIX_PL_Socket *rcvSock,
107 void *buf,
108 PKIX_UInt32 capacity,
109 PKIX_Int32 *pBytesRead,
110 void *plContext);
112 typedef PKIX_Error *
113 (*pkix_pl_Socket_PollCallback)(
114 PKIX_PL_Socket *sock,
115 PKIX_Int32 *pBytesWritten,
116 PKIX_Int32 *pBytesRead,
117 void *plContext);
119 typedef PKIX_Error *
120 (*pkix_pl_Socket_ShutdownCallback)(
121 PKIX_PL_Socket *socket, void *plContext);
123 typedef struct PKIX_PL_Socket_CallbackStruct {
124 pkix_pl_Socket_ListenCallback listenCallback;
125 pkix_pl_Socket_AcceptCallback acceptCallback;
126 pkix_pl_Socket_ConnectContinueCallback connectcontinueCallback;
127 pkix_pl_Socket_SendCallback sendCallback;
128 pkix_pl_Socket_RecvCallback recvCallback;
129 pkix_pl_Socket_PollCallback pollCallback;
130 pkix_pl_Socket_ShutdownCallback shutdownCallback;
131 } PKIX_PL_Socket_Callback;
133 struct PKIX_PL_SocketStruct {
134 PKIX_Boolean isServer;
135 PRIntervalTime timeout; /* zero for non-blocking I/O */
136 SockStatus status;
137 PRFileDesc *clientSock;
138 PRFileDesc *serverSock;
139 void *readBuf;
140 void *writeBuf;
141 PKIX_UInt32 readBufSize;
142 PKIX_UInt32 writeBufSize;
143 PRNetAddr *netAddr;
144 PKIX_PL_Socket_Callback callbackList;
147 /* see source file for function documentation */
149 PKIX_Error *pkix_pl_Socket_RegisterSelf(void *plContext);
151 PKIX_Error *
152 pkix_pl_Socket_Create(
153 PKIX_Boolean isServer,
154 PRIntervalTime timeout, /* zero for non-blocking I/O */
155 PRNetAddr *netAddr,
156 PRErrorCode *status,
157 PKIX_PL_Socket **pSocket,
158 void *plContext);
160 PKIX_Error *
161 pkix_pl_Socket_CreateByName(
162 PKIX_Boolean isServer,
163 PRIntervalTime timeout,
164 char *serverName,
165 PRErrorCode *pStatus,
166 PKIX_PL_Socket **pSocket,
167 void *plContext);
169 PKIX_Error *
170 pkix_pl_Socket_CreateByHostAndPort(
171 PKIX_Boolean isServer,
172 PRIntervalTime timeout,
173 char *hostname,
174 PRUint16 portnum,
175 PRErrorCode *pStatus,
176 PKIX_PL_Socket **pSocket,
177 void *plContext);
179 /* Do not use these functions directly; use their callback variants instead
180 * static PKIX_Error *
181 * pkix_pl_Socket_Listen(
182 * PKIX_PL_Socket *socket,
183 * PKIX_UInt32 backlog,
184 * void *plContext);
186 * static PKIX_Error *
187 * pkix_pl_Socket_Accept(
188 * PKIX_PL_Socket *socket,
189 * PKIX_PL_Socket **pRendezvousSock,
190 * void *plContext);
192 * static PKIX_Error *
193 * pkix_pl_Socket_ConnectContinue(
194 * PKIX_PL_Socket *socket,
195 * PRErrorCode *pStatus,
196 * void *plContext);
198 * static PKIX_Error *
199 * pkix_pl_Socket_Send(
200 * PKIX_PL_Socket *sendSock,
201 * void *buf,
202 * PKIX_UInt32 bytesToWrite,
203 * PKIX_Int32 *pBytesWritten,
204 * void *plContext);
206 * static PKIX_Error *
207 * pkix_pl_Socket_Recv(
208 * PKIX_PL_Socket *rcvSock,
209 * void *buf,
210 * PKIX_UInt32 capacity,
211 * PKIX_Int32 *pBytesRead,
212 * void *plContext);
214 * static PKIX_Error *
215 * pkix_pl_Socket_Poll(
216 * PKIX_PL_Socket *sock,
217 * PKIX_Int32 *pBytesWritten,
218 * PKIX_Int32 *pBytesRead,
219 * void *plContext);
221 * static PKIX_Error *
222 * pkix_pl_Socket_Shutdown(
223 * PKIX_PL_Socket *socket, void *plContext);
226 PKIX_Error *
227 pkix_pl_Socket_GetCallbackList(
228 PKIX_PL_Socket *socket,
229 PKIX_PL_Socket_Callback **pCallbackList,
230 void *plContext);
232 PKIX_Error *
233 pkix_pl_Socket_GetPRFileDesc(
234 PKIX_PL_Socket *socket,
235 PRFileDesc **pDesc,
236 void *plContext);
238 #ifdef __cplusplus
240 #endif
242 #endif /* _PKIX_PL_SOCKET_H */