2 * "$Id: http.c,v 1.120 2003/05/27 14:03:37 mike Exp $"
4 * HTTP routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2003 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * httpInitialize() - Initialize the HTTP interface library and set the
29 * default HTTP proxy (if any).
30 * httpCheck() - Check to see if there is a pending response from
32 * httpClearCookie() - Clear the cookie value(s).
33 * httpClose() - Close an HTTP connection...
34 * httpConnect() - Connect to a HTTP server.
35 * httpConnectEncrypt() - Connect to a HTTP server using encryption.
36 * httpEncryption() - Set the required encryption on the link.
37 * httpReconnect() - Reconnect to a HTTP server...
38 * httpGetSubField() - Get a sub-field value.
39 * httpSetField() - Set the value of an HTTP header.
40 * httpDelete() - Send a DELETE request to the server.
41 * httpGet() - Send a GET request to the server.
42 * httpHead() - Send a HEAD request to the server.
43 * httpOptions() - Send an OPTIONS request to the server.
44 * httpPost() - Send a POST request to the server.
45 * httpPut() - Send a PUT request to the server.
46 * httpTrace() - Send an TRACE request to the server.
47 * httpFlush() - Flush data from a HTTP connection.
48 * httpRead() - Read data from a HTTP connection.
49 * httpSetCookie() - Set the cookie value(s)...
50 * httpWait() - Wait for data available on a connection.
51 * httpWrite() - Write data to a HTTP connection.
52 * httpGets() - Get a line of text from a HTTP connection.
53 * httpPrintf() - Print a formatted string to a HTTP connection.
54 * httpGetDateString() - Get a formatted date/time string from a time value.
55 * httpGetDateTime() - Get a time value from a formatted date/time string.
56 * httpUpdate() - Update the current HTTP state for incoming data.
57 * httpDecode64() - Base64-decode a string.
58 * httpEncode64() - Base64-encode a string.
59 * httpGetLength() - Get the amount of data remaining from the
60 * content-length or transfer-encoding fields.
61 * http_field() - Return the field index for a field name.
62 * http_send() - Send a request with all fields and the trailing
64 * http_upgrade() - Force upgrade to TLS encryption.
65 * http_setup_ssl() - Set up SSL/TLS on a connection.
66 * http_shutdown_ssl() - Shut down SSL/TLS on a connection.
67 * http_read_ssl() - Read from a SSL/TLS connection.
68 * http_write_ssl() - Write to a SSL/TLS connection.
69 * CDSAReadFunc() - Read function for CDSA decryption code.
70 * CDSAWriteFunc() - Write function for CDSA encryption code.
74 * Include necessary headers...
86 #include "http-private.h"
91 # include <sys/time.h>
92 # include <sys/resource.h>
97 * Some operating systems have done away with the Fxxxx constants for
98 * the fcntl() call; this works around that "feature"...
102 # define FNONBLK O_NONBLOCK
103 #endif /* !FNONBLK */
110 static http_field_t
http_field(const char *name
);
111 static int http_send(http_t
*http
, http_state_t request
,
114 static int http_upgrade(http_t
*http
);
115 static int http_setup_ssl(http_t
*http
);
116 static void http_shutdown_ssl(http_t
*http
);
117 static int http_read_ssl(http_t
*http
, char *buf
, int len
);
118 static int http_write_ssl(http_t
*http
, const char *buf
, int len
);
120 static OSStatus
CDSAReadFunc(SSLConnectionRef connection
, void *data
, size_t *dataLength
);
121 static OSStatus
CDSAWriteFunc(SSLConnectionRef connection
, const void *data
, size_t *dataLength
);
122 # endif /* HAVE_CDSASSL */
123 #endif /* HAVE_SSL */
130 static const char * const http_fields
[] =
147 "If-Unmodified-since",
160 static const char * const days
[7] =
170 static const char * const months
[12] =
188 * 'httpInitialize()' - Initialize the HTTP interface library and set the
189 * default HTTP proxy (if any).
197 struct timeval curtime
; /* Current time in microseconds */
199 int i
; /* Looping var */
200 unsigned char data
[1024]; /* Seed data */
201 #endif /* HAVE_LIBSSL */
204 WSADATA winsockdata
; /* WinSock data */
205 static int initialized
= 0;/* Has WinSock been initialized? */
209 WSAStartup(MAKEWORD(1,1), &winsockdata
);
210 #elif defined(HAVE_SIGSET)
211 sigset(SIGPIPE
, SIG_IGN
);
212 #elif defined(HAVE_SIGACTION)
213 struct sigaction action
; /* POSIX sigaction data */
217 * Ignore SIGPIPE signals...
220 memset(&action
, 0, sizeof(action
));
221 action
.sa_handler
= SIG_IGN
;
222 sigaction(SIGPIPE
, &action
, NULL
);
224 signal(SIGPIPE
, SIG_IGN
);
228 gnutls_global_init();
229 #endif /* HAVE_GNUTLS */
232 SSL_load_error_strings();
236 * Using the current time is a dubious random seed, but on some systems
237 * it is the best we can do (on others, this seed isn't even used...)
242 gettimeofday(&curtime
, NULL
);
243 srand(curtime
.tv_sec
+ curtime
.tv_usec
);
246 for (i
= 0; i
< sizeof(data
); i
++)
247 data
[i
] = rand(); /* Yes, this is a poor source of random data... */
249 RAND_seed(&data
, sizeof(data
));
250 #endif /* HAVE_LIBSSL */
255 * 'httpCheck()' - Check to see if there is a pending response from the server.
258 int /* O - 0 = no data, 1 = data available */
259 httpCheck(http_t
*http
) /* I - HTTP connection */
261 return (httpWait(http
, 0));
266 * 'httpClearCookie()' - Clear the cookie value(s).
270 httpClearCookie(http_t
*http
) /* I - Connection */
284 * 'httpClose()' - Close an HTTP connection...
288 httpClose(http_t
*http
) /* I - Connection to close */
294 free(http
->input_set
);
301 http_shutdown_ssl(http
);
302 #endif /* HAVE_SSL */
305 closesocket(http
->fd
);
315 * 'httpConnect()' - Connect to a HTTP server.
318 http_t
* /* O - New HTTP connection */
319 httpConnect(const char *host
, /* I - Host to connect to */
320 int port
) /* I - Port number */
322 http_encryption_t encrypt
;/* Type of encryption to use */
326 * Set the default encryption status...
330 encrypt
= HTTP_ENCRYPT_ALWAYS
;
332 encrypt
= HTTP_ENCRYPT_IF_REQUESTED
;
334 return (httpConnectEncrypt(host
, port
, encrypt
));
339 * 'httpConnectEncrypt()' - Connect to a HTTP server using encryption.
342 http_t
* /* O - New HTTP connection */
343 httpConnectEncrypt(const char *host
, /* I - Host to connect to */
344 int port
, /* I - Port number */
345 http_encryption_t encrypt
)
346 /* I - Type of encryption to use */
348 int i
; /* Looping var */
349 http_t
*http
; /* New HTTP connection */
350 struct hostent
*hostaddr
; /* Host address data */
362 if ((hostaddr
= httpGetHostByName(host
)) == NULL
)
365 * This hack to make users that don't have a localhost entry in
366 * their hosts file or DNS happy...
369 if (strcasecmp(host
, "localhost") != 0)
371 else if ((hostaddr
= httpGetHostByName("127.0.0.1")) == NULL
)
376 * Verify that it is an IPv4 address (IPv6 support will come in CUPS 1.2...)
379 if (hostaddr
->h_addrtype
!= AF_INET
|| hostaddr
->h_length
!= 4)
383 * Allocate memory for the structure...
386 http
= calloc(sizeof(http_t
), 1);
390 http
->version
= HTTP_1_1
;
392 http
->activity
= time(NULL
);
396 * Copy the hostname and port and then "reconnect"...
399 strlcpy(http
->hostname
, host
, sizeof(http
->hostname
));
400 http
->hostaddr
.sin_family
= hostaddr
->h_addrtype
;
402 http
->hostaddr
.sin_port
= htons((u_short
)port
);
404 http
->hostaddr
.sin_port
= htons(port
);
408 * Set the encryption status...
411 if (port
== 443) /* Always use encryption for https */
412 http
->encryption
= HTTP_ENCRYPT_ALWAYS
;
414 http
->encryption
= encrypt
;
417 * Loop through the addresses we have until one of them connects...
420 strlcpy(http
->hostname
, host
, sizeof(http
->hostname
));
422 for (i
= 0; hostaddr
->h_addr_list
[i
]; i
++)
425 * Load the address...
428 memcpy((char *)&(http
->hostaddr
.sin_addr
), hostaddr
->h_addr_list
[i
],
432 * Connect to the remote system...
435 if (!httpReconnect(http
))
440 * Could not connect to any known address - bail out!
449 * 'httpEncryption()' - Set the required encryption on the link.
452 int /* O - -1 on error, 0 on success */
453 httpEncryption(http_t
*http
, /* I - HTTP data */
454 http_encryption_t e
) /* I - New encryption preference */
460 http
->encryption
= e
;
462 if ((http
->encryption
== HTTP_ENCRYPT_ALWAYS
&& !http
->tls
) ||
463 (http
->encryption
== HTTP_ENCRYPT_NEVER
&& http
->tls
))
464 return (httpReconnect(http
));
465 else if (http
->encryption
== HTTP_ENCRYPT_REQUIRED
&& !http
->tls
)
466 return (http_upgrade(http
));
470 if (e
== HTTP_ENCRYPT_ALWAYS
|| e
== HTTP_ENCRYPT_REQUIRED
)
474 #endif /* HAVE_SSL */
479 * 'httpReconnect()' - Reconnect to a HTTP server...
482 int /* O - 0 on success, non-zero on failure */
483 httpReconnect(http_t
*http
) /* I - HTTP data */
485 int val
; /* Socket option value */
489 http_shutdown_ssl(http
);
490 #endif /* HAVE_SSL */
493 * Close any previously open socket...
498 closesocket(http
->fd
);
504 * Create the socket and set options to allow reuse.
507 if ((http
->fd
= socket(AF_INET
, SOCK_STREAM
, 0)) < 0)
510 http
->error
= WSAGetLastError();
514 http
->status
= HTTP_ERROR
;
519 fcntl(http
->fd
, F_SETFD
, FD_CLOEXEC
); /* Close this socket when starting *
520 * other processes... */
521 #endif /* FD_CLOEXEC */
524 setsockopt(http
->fd
, SOL_SOCKET
, SO_REUSEADDR
, (char *)&val
, sizeof(val
));
528 setsockopt(http
->fd
, SOL_SOCKET
, SO_REUSEPORT
, &val
, sizeof(val
));
529 #endif /* SO_REUSEPORT */
532 * Using TCP_NODELAY improves responsiveness, especially on systems
533 * with a slow loopback interface... Since we write large buffers
534 * when sending print files and requests, there shouldn't be any
535 * performance penalty for this...
539 setsockopt(http
->fd
, IPPROTO_TCP
, TCP_NODELAY
, &val
, sizeof(val
));
542 * Connect to the server...
545 if (connect(http
->fd
, (struct sockaddr
*)&(http
->hostaddr
),
546 sizeof(http
->hostaddr
)) < 0)
549 http
->error
= WSAGetLastError();
553 http
->status
= HTTP_ERROR
;
556 closesocket(http
->fd
);
567 http
->status
= HTTP_CONTINUE
;
570 if (http
->encryption
== HTTP_ENCRYPT_ALWAYS
)
573 * Always do encryption via SSL.
576 if (http_setup_ssl(http
) != 0)
579 closesocket(http
->fd
);
587 else if (http
->encryption
== HTTP_ENCRYPT_REQUIRED
)
588 return (http_upgrade(http
));
589 #endif /* HAVE_SSL */
596 * 'httpGetSubField()' - Get a sub-field value.
599 char * /* O - Value or NULL */
600 httpGetSubField(http_t
*http
, /* I - HTTP data */
601 http_field_t field
, /* I - Field index */
602 const char *name
, /* I - Name of sub-field */
603 char *value
) /* O - Value string */
605 const char *fptr
; /* Pointer into field */
606 char temp
[HTTP_MAX_VALUE
], /* Temporary buffer for name */
607 *ptr
; /* Pointer into string buffer */
611 field
< HTTP_FIELD_ACCEPT_LANGUAGE
||
612 field
> HTTP_FIELD_WWW_AUTHENTICATE
||
613 name
== NULL
|| value
== NULL
)
616 DEBUG_printf(("httpGetSubField(%p, %d, \"%s\", %p)\n",
617 http
, field
, name
, value
));
619 for (fptr
= http
->fields
[field
]; *fptr
;)
622 * Skip leading whitespace...
625 while (isspace(*fptr
))
635 * Get the sub-field name...
639 *fptr
&& *fptr
!= '=' && !isspace(*fptr
) && ptr
< (temp
+ sizeof(temp
) - 1);
644 DEBUG_printf(("name = \"%s\"\n", temp
));
647 * Skip trailing chars up to the '='...
650 while (isspace(*fptr
))
660 * Skip = and leading whitespace...
665 while (isspace(*fptr
))
671 * Read quoted string...
674 for (ptr
= value
, fptr
++;
675 *fptr
&& *fptr
!= '\"' && ptr
< (value
+ HTTP_MAX_VALUE
- 1);
680 while (*fptr
&& *fptr
!= '\"')
689 * Read unquoted string...
693 *fptr
&& !isspace(*fptr
) && *fptr
!= ',' && ptr
< (value
+ HTTP_MAX_VALUE
- 1);
698 while (*fptr
&& !isspace(*fptr
) && *fptr
!= ',')
702 DEBUG_printf(("value = \"%s\"\n", value
));
705 * See if this is the one...
708 if (strcmp(name
, temp
) == 0)
719 * 'httpSetField()' - Set the value of an HTTP header.
723 httpSetField(http_t
*http
, /* I - HTTP data */
724 http_field_t field
, /* I - Field index */
725 const char *value
) /* I - Value */
728 field
< HTTP_FIELD_ACCEPT_LANGUAGE
||
729 field
> HTTP_FIELD_WWW_AUTHENTICATE
||
733 strlcpy(http
->fields
[field
], value
, HTTP_MAX_VALUE
);
738 * 'httpDelete()' - Send a DELETE request to the server.
741 int /* O - Status of call (0 = success) */
742 httpDelete(http_t
*http
, /* I - HTTP data */
743 const char *uri
) /* I - URI to delete */
745 return (http_send(http
, HTTP_DELETE
, uri
));
750 * 'httpGet()' - Send a GET request to the server.
753 int /* O - Status of call (0 = success) */
754 httpGet(http_t
*http
, /* I - HTTP data */
755 const char *uri
) /* I - URI to get */
757 return (http_send(http
, HTTP_GET
, uri
));
762 * 'httpHead()' - Send a HEAD request to the server.
765 int /* O - Status of call (0 = success) */
766 httpHead(http_t
*http
, /* I - HTTP data */
767 const char *uri
) /* I - URI for head */
769 return (http_send(http
, HTTP_HEAD
, uri
));
774 * 'httpOptions()' - Send an OPTIONS request to the server.
777 int /* O - Status of call (0 = success) */
778 httpOptions(http_t
*http
, /* I - HTTP data */
779 const char *uri
) /* I - URI for options */
781 return (http_send(http
, HTTP_OPTIONS
, uri
));
786 * 'httpPost()' - Send a POST request to the server.
789 int /* O - Status of call (0 = success) */
790 httpPost(http_t
*http
, /* I - HTTP data */
791 const char *uri
) /* I - URI for post */
795 return (http_send(http
, HTTP_POST
, uri
));
800 * 'httpPut()' - Send a PUT request to the server.
803 int /* O - Status of call (0 = success) */
804 httpPut(http_t
*http
, /* I - HTTP data */
805 const char *uri
) /* I - URI to put */
809 return (http_send(http
, HTTP_PUT
, uri
));
814 * 'httpTrace()' - Send an TRACE request to the server.
817 int /* O - Status of call (0 = success) */
818 httpTrace(http_t
*http
, /* I - HTTP data */
819 const char *uri
) /* I - URI for trace */
821 return (http_send(http
, HTTP_TRACE
, uri
));
826 * 'httpFlush()' - Flush data from a HTTP connection.
830 httpFlush(http_t
*http
) /* I - HTTP data */
832 char buffer
[8192]; /* Junk buffer */
835 if (http
->state
!= HTTP_WAITING
)
837 while (httpRead(http
, buffer
, sizeof(buffer
)) > 0);
843 * 'httpRead()' - Read data from a HTTP connection.
846 int /* O - Number of bytes read */
847 httpRead(http_t
*http
, /* I - HTTP data */
848 char *buffer
, /* I - Buffer for data */
849 int length
) /* I - Maximum number of bytes */
851 int bytes
; /* Bytes read */
852 char len
[32]; /* Length string */
855 DEBUG_printf(("httpRead(%p, %p, %d)\n", http
, buffer
, length
));
857 if (http
== NULL
|| buffer
== NULL
)
860 http
->activity
= time(NULL
);
865 if (http
->data_encoding
== HTTP_ENCODE_CHUNKED
&&
866 http
->data_remaining
<= 0)
868 DEBUG_puts("httpRead: Getting chunk length...");
870 if (httpGets(len
, sizeof(len
), http
) == NULL
)
872 DEBUG_puts("httpRead: Could not get length!");
876 http
->data_remaining
= strtol(len
, NULL
, 16);
877 if (http
->data_remaining
< 0)
879 DEBUG_puts("httpRead: Negative chunk length!");
884 DEBUG_printf(("httpRead: data_remaining = %d\n", http
->data_remaining
));
886 if (http
->data_remaining
<= 0)
889 * A zero-length chunk ends a transfer; unless we are reading POST
893 if (http
->data_encoding
== HTTP_ENCODE_CHUNKED
)
894 httpGets(len
, sizeof(len
), http
);
896 if (http
->state
== HTTP_POST_RECV
)
899 http
->state
= HTTP_WAITING
;
903 else if (length
> http
->data_remaining
)
904 length
= http
->data_remaining
;
906 if (http
->used
== 0 && length
<= 256)
909 * Buffer small reads for better performance...
912 if (!http
->blocking
&& !httpWait(http
, 1000))
915 if (http
->data_remaining
> sizeof(http
->buffer
))
916 bytes
= sizeof(http
->buffer
);
918 bytes
= http
->data_remaining
;
922 bytes
= http_read_ssl(http
, http
->buffer
, bytes
);
924 #endif /* HAVE_SSL */
926 DEBUG_printf(("httpRead: reading %d bytes from socket into buffer...\n",
929 bytes
= recv(http
->fd
, http
->buffer
, bytes
, 0);
931 DEBUG_printf(("httpRead: read %d bytes from socket into buffer...\n",
940 http
->error
= WSAGetLastError();
959 if (length
> http
->used
)
964 DEBUG_printf(("httpRead: grabbing %d bytes from input buffer...\n", bytes
));
966 memcpy(buffer
, http
->buffer
, length
);
967 http
->used
-= length
;
970 memmove(http
->buffer
, http
->buffer
+ length
, http
->used
);
975 if (!http
->blocking
&& !httpWait(http
, 1000))
978 bytes
= http_read_ssl(http
, buffer
, length
);
980 #endif /* HAVE_SSL */
983 if (!http
->blocking
&& !httpWait(http
, 1000))
986 DEBUG_printf(("httpRead: reading %d bytes from socket...\n", length
));
987 bytes
= recv(http
->fd
, buffer
, length
, 0);
988 DEBUG_printf(("httpRead: read %d bytes from socket...\n", bytes
));
992 http
->data_remaining
-= bytes
;
996 http
->error
= WSAGetLastError();
1001 http
->error
= errno
;
1006 http
->error
= EPIPE
;
1010 if (http
->data_remaining
== 0)
1012 if (http
->data_encoding
== HTTP_ENCODE_CHUNKED
)
1013 httpGets(len
, sizeof(len
), http
);
1015 if (http
->data_encoding
!= HTTP_ENCODE_CHUNKED
)
1017 if (http
->state
== HTTP_POST_RECV
)
1020 http
->state
= HTTP_WAITING
;
1027 printf("httpRead: Read %d bytes:\n", bytes
);
1028 for (i
= 0; i
< bytes
; i
+= 16)
1032 for (j
= 0; j
< 16 && (i
+ j
) < bytes
; j
++)
1033 printf(" %02X", buffer
[i
+ j
] & 255);
1042 for (j
= 0; j
< 16 && (i
+ j
) < bytes
; j
++)
1044 ch
= buffer
[i
+ j
] & 255;
1046 if (ch
< ' ' || ch
== 127)
1061 * 'httpSetCookie()' - Set the cookie value(s)...
1065 httpSetCookie(http_t
*http
, /* I - Connection */
1066 const char *cookie
) /* I - Cookie string */
1075 http
->cookie
= strdup(cookie
);
1077 http
->cookie
= NULL
;
1082 * 'httpWait()' - Wait for data available on a connection.
1085 int /* O - 1 if data is available, 0 otherwise */
1086 httpWait(http_t
*http
, /* I - HTTP data */
1087 int msec
) /* I - Milliseconds to wait */
1090 struct rlimit limit
; /* Runtime limit */
1092 struct timeval timeout
; /* Timeout */
1093 int nfds
; /* Result from select() */
1097 * First see if there is data in the buffer...
1110 if (SSL_pending((SSL
*)(http
->tls
)))
1112 # elif defined(HAVE_GNUTLS)
1113 if (gnutls_record_check_pending(((http_tls_t
*)(http
->tls
))->session
))
1115 # elif defined(HAVE_CDSASSL)
1116 size_t bytes
; /* Bytes that are available */
1118 if (!SSLGetBufferedReadSize((SSLContextRef
)http
->tls
, &bytes
) && bytes
> 0)
1120 # endif /* HAVE_LIBSSL */
1122 #endif /* HAVE_SSL */
1125 * Then try doing a select() to poll the socket...
1128 if (!http
->input_set
)
1132 * Windows has a fixed-size select() structure, different (surprise,
1133 * surprise!) from all UNIX implementations. Just allocate this
1134 * fixed structure...
1137 http
->input_set
= calloc(1, sizeof(fd_set
));
1140 * Allocate the select() input set based upon the max number of file
1141 * descriptors available for this process...
1144 getrlimit(RLIMIT_NOFILE
, &limit
);
1146 http
->input_set
= calloc(1, (limit
.rlim_cur
+ 7) / 8);
1149 if (!http
->input_set
)
1153 FD_SET(http
->fd
, http
->input_set
);
1157 timeout
.tv_sec
= msec
/ 1000;
1158 timeout
.tv_usec
= (msec
% 1000) * 1000;
1160 nfds
= select(http
->fd
+ 1, http
->input_set
, NULL
, NULL
, &timeout
);
1163 nfds
= select(http
->fd
+ 1, http
->input_set
, NULL
, NULL
, NULL
);
1165 FD_CLR(http
->fd
, http
->input_set
);
1172 * 'httpWrite()' - Write data to a HTTP connection.
1175 int /* O - Number of bytes written */
1176 httpWrite(http_t
*http
, /* I - HTTP data */
1177 const char *buffer
, /* I - Buffer for data */
1178 int length
) /* I - Number of bytes to write */
1180 int tbytes
, /* Total bytes sent */
1181 bytes
; /* Bytes sent */
1184 if (http
== NULL
|| buffer
== NULL
)
1187 http
->activity
= time(NULL
);
1189 if (http
->data_encoding
== HTTP_ENCODE_CHUNKED
)
1191 if (httpPrintf(http
, "%x\r\n", length
) < 0)
1197 * A zero-length chunk ends a transfer; unless we are sending POST
1201 DEBUG_puts("httpWrite: changing states...");
1203 if (http
->state
== HTTP_POST_RECV
)
1205 else if (http
->state
== HTTP_PUT_RECV
)
1206 http
->state
= HTTP_STATUS
;
1208 http
->state
= HTTP_WAITING
;
1210 if (httpPrintf(http
, "\r\n") < 0)
1223 bytes
= http_write_ssl(http
, buffer
, length
);
1225 #endif /* HAVE_SSL */
1226 bytes
= send(http
->fd
, buffer
, length
, 0);
1231 if (WSAGetLastError() != http
->error
)
1233 http
->error
= WSAGetLastError();
1239 else if (errno
!= http
->error
)
1241 http
->error
= errno
;
1246 DEBUG_puts("httpWrite: error writing data...\n");
1254 if (http
->data_encoding
== HTTP_ENCODE_LENGTH
)
1255 http
->data_remaining
-= bytes
;
1258 if (http
->data_encoding
== HTTP_ENCODE_CHUNKED
)
1259 if (httpPrintf(http
, "\r\n") < 0)
1262 if (http
->data_remaining
== 0 && http
->data_encoding
== HTTP_ENCODE_LENGTH
)
1265 * Finished with the transfer; unless we are sending POST data, go idle...
1268 DEBUG_puts("httpWrite: changing states...");
1270 if (http
->state
== HTTP_POST_RECV
)
1273 http
->state
= HTTP_WAITING
;
1279 printf("httpWrite: wrote %d bytes: \n", tbytes
);
1280 for (i
= 0, buffer
-= tbytes
; i
< tbytes
; i
+= 16)
1284 for (j
= 0; j
< 16 && (i
+ j
) < tbytes
; j
++)
1285 printf(" %02X", buffer
[i
+ j
] & 255);
1294 for (j
= 0; j
< 16 && (i
+ j
) < tbytes
; j
++)
1296 ch
= buffer
[i
+ j
] & 255;
1298 if (ch
< ' ' || ch
== 127)
1312 * 'httpGets()' - Get a line of text from a HTTP connection.
1315 char * /* O - Line or NULL */
1316 httpGets(char *line
, /* I - Line to read into */
1317 int length
, /* I - Max length of buffer */
1318 http_t
*http
) /* I - HTTP data */
1320 char *lineptr
, /* Pointer into line */
1321 *bufptr
, /* Pointer into input buffer */
1322 *bufend
; /* Pointer to end of buffer */
1323 int bytes
; /* Number of bytes read */
1326 DEBUG_printf(("httpGets(%p, %d, %p)\n", line
, length
, http
));
1328 if (http
== NULL
|| line
== NULL
)
1332 * Pre-scan the buffer and see if there is a newline in there...
1343 bufptr
= http
->buffer
;
1344 bufend
= http
->buffer
+ http
->used
;
1346 while (bufptr
< bufend
)
1347 if (*bufptr
== 0x0a)
1352 if (bufptr
>= bufend
&& http
->used
< HTTP_MAX_BUFFER
)
1355 * No newline; see if there is more data to be read...
1358 if (!http
->blocking
&& !httpWait(http
, 1000))
1363 bytes
= http_read_ssl(http
, bufend
, HTTP_MAX_BUFFER
- http
->used
);
1365 #endif /* HAVE_SSL */
1366 bytes
= recv(http
->fd
, bufend
, HTTP_MAX_BUFFER
- http
->used
, 0);
1371 * Nope, can't get a line this time...
1375 if (WSAGetLastError() != http
->error
)
1377 http
->error
= WSAGetLastError();
1381 DEBUG_printf(("httpGets(): recv() error %d!\n", WSAGetLastError()));
1385 else if (errno
!= http
->error
)
1387 http
->error
= errno
;
1391 DEBUG_printf(("httpGets(): recv() error %d!\n", errno
));
1396 else if (bytes
== 0)
1398 http
->error
= EPIPE
;
1404 * Yup, update the amount used and the end pointer...
1407 http
->used
+= bytes
;
1412 while (bufptr
>= bufend
&& http
->used
< HTTP_MAX_BUFFER
);
1414 http
->activity
= time(NULL
);
1417 * Read a line from the buffer...
1421 bufptr
= http
->buffer
;
1425 while (bufptr
< bufend
&& bytes
< length
)
1429 if (*bufptr
== 0x0a)
1434 else if (*bufptr
== 0x0d)
1437 *lineptr
++ = *bufptr
++;
1444 http
->used
-= bytes
;
1446 memmove(http
->buffer
, bufptr
, http
->used
);
1448 DEBUG_printf(("httpGets(): Returning \"%s\"\n", line
));
1452 DEBUG_puts("httpGets(): No new line available!");
1459 * 'httpPrintf()' - Print a formatted string to a HTTP connection.
1462 int /* O - Number of bytes written */
1463 httpPrintf(http_t
*http
, /* I - HTTP data */
1464 const char *format
, /* I - printf-style format string */
1465 ...) /* I - Additional args as needed */
1467 int bytes
, /* Number of bytes to write */
1468 nbytes
, /* Number of bytes written */
1469 tbytes
; /* Number of bytes all together */
1470 char buf
[HTTP_MAX_BUFFER
], /* Buffer for formatted string */
1471 *bufptr
; /* Pointer into buffer */
1472 va_list ap
; /* Variable argument pointer */
1475 va_start(ap
, format
);
1476 bytes
= vsnprintf(buf
, sizeof(buf
), format
, ap
);
1479 DEBUG_printf(("httpPrintf: %s", buf
));
1481 for (tbytes
= 0, bufptr
= buf
; tbytes
< bytes
; tbytes
+= nbytes
, bufptr
+= nbytes
)
1485 nbytes
= http_write_ssl(http
, bufptr
, bytes
- tbytes
);
1487 #endif /* HAVE_SSL */
1488 nbytes
= send(http
->fd
, bufptr
, bytes
- tbytes
, 0);
1495 if (WSAGetLastError() != http
->error
)
1497 http
->error
= WSAGetLastError();
1503 else if (errno
!= http
->error
)
1505 http
->error
= errno
;
1519 * 'httpGetDateString()' - Get a formatted date/time string from a time value.
1522 const char * /* O - Date/time string */
1523 httpGetDateString(time_t t
) /* I - UNIX time */
1526 static char datetime
[256];
1530 snprintf(datetime
, sizeof(datetime
), "%s, %02d %s %d %02d:%02d:%02d GMT",
1531 days
[tdate
->tm_wday
], tdate
->tm_mday
, months
[tdate
->tm_mon
],
1532 tdate
->tm_year
+ 1900, tdate
->tm_hour
, tdate
->tm_min
, tdate
->tm_sec
);
1539 * 'httpGetDateTime()' - Get a time value from a formatted date/time string.
1542 time_t /* O - UNIX time */
1543 httpGetDateTime(const char *s
) /* I - Date/time string */
1545 int i
; /* Looping var */
1546 struct tm tdate
; /* Time/date structure */
1547 char mon
[16]; /* Abbreviated month name */
1548 int day
, year
; /* Day of month and year */
1549 int hour
, min
, sec
; /* Time */
1552 if (sscanf(s
, "%*s%d%15s%d%d:%d:%d", &day
, mon
, &year
, &hour
, &min
, &sec
) < 6)
1555 for (i
= 0; i
< 12; i
++)
1556 if (strcasecmp(mon
, months
[i
]) == 0)
1563 tdate
.tm_mday
= day
;
1564 tdate
.tm_year
= year
- 1900;
1565 tdate
.tm_hour
= hour
;
1570 return (mktime(&tdate
));
1575 * 'httpUpdate()' - Update the current HTTP state for incoming data.
1578 http_status_t
/* O - HTTP status */
1579 httpUpdate(http_t
*http
) /* I - HTTP data */
1581 char line
[1024], /* Line from connection... */
1582 *value
; /* Pointer to value on line */
1583 http_field_t field
; /* Field index */
1584 int major
, minor
; /* HTTP version numbers */
1585 http_status_t status
; /* Authorization status */
1588 DEBUG_printf(("httpUpdate(%p)\n", http
));
1591 * If we haven't issued any commands, then there is nothing to "update"...
1594 if (http
->state
== HTTP_WAITING
)
1595 return (HTTP_CONTINUE
);
1598 * Grab all of the lines we can from the connection...
1601 while (httpGets(line
, sizeof(line
), http
) != NULL
)
1605 if (line
[0] == '\0')
1608 * Blank line means the start of the data section (if any). Return
1609 * the result code, too...
1611 * If we get status 100 (HTTP_CONTINUE), then we *don't* change states.
1612 * Instead, we just return HTTP_CONTINUE to the caller and keep on
1616 if (http
->status
== HTTP_CONTINUE
)
1617 return (http
->status
);
1620 if (http
->status
== HTTP_SWITCHING_PROTOCOLS
&& !http
->tls
)
1622 if (http_setup_ssl(http
) != 0)
1625 closesocket(http
->fd
);
1630 return (HTTP_ERROR
);
1633 return (HTTP_CONTINUE
);
1635 #endif /* HAVE_SSL */
1637 httpGetLength(http
);
1639 switch (http
->state
)
1643 case HTTP_POST_RECV
:
1646 case HTTP_POST_SEND
:
1650 http
->state
= HTTP_WAITING
;
1654 return (http
->status
);
1656 else if (strncmp(line
, "HTTP/", 5) == 0)
1659 * Got the beginning of a response...
1662 if (sscanf(line
, "HTTP/%d.%d%d", &major
, &minor
, (int *)&status
) != 3)
1663 return (HTTP_ERROR
);
1665 http
->version
= (http_version_t
)(major
* 100 + minor
);
1666 http
->status
= status
;
1668 else if ((value
= strchr(line
, ':')) != NULL
)
1675 while (isspace(*value
))
1679 * Be tolerants of servers that send unknown attribute fields...
1682 if (!strcasecmp(line
, "expect"))
1685 * "Expect: 100-continue" or similar...
1688 http
->expect
= (http_status_t
)atoi(value
);
1690 else if (!strcasecmp(line
, "cookie"))
1693 * "Cookie: name=value[; name=value ...]" - replaces previous cookies...
1696 httpSetCookie(http
, value
);
1698 else if ((field
= http_field(line
)) == HTTP_FIELD_UNKNOWN
)
1700 DEBUG_printf(("httpUpdate: unknown field %s seen!\n", line
));
1704 httpSetField(http
, field
, value
);
1708 http
->status
= HTTP_ERROR
;
1709 return (HTTP_ERROR
);
1714 * See if there was an error...
1719 http
->status
= HTTP_ERROR
;
1720 return (HTTP_ERROR
);
1724 * If we haven't already returned, then there is nothing new...
1727 return (HTTP_CONTINUE
);
1732 * 'httpDecode64()' - Base64-decode a string.
1735 char * /* O - Decoded string */
1736 httpDecode64(char *out
, /* I - String to write to */
1737 const char *in
) /* I - String to read from */
1739 int pos
, /* Bit position */
1740 base64
; /* Value of this character */
1741 char *outptr
; /* Output pointer */
1744 for (outptr
= out
, pos
= 0; *in
!= '\0'; in
++)
1747 * Decode this character into a number from 0 to 63...
1750 if (*in
>= 'A' && *in
<= 'Z')
1752 else if (*in
>= 'a' && *in
<= 'z')
1753 base64
= *in
- 'a' + 26;
1754 else if (*in
>= '0' && *in
<= '9')
1755 base64
= *in
- '0' + 52;
1756 else if (*in
== '+')
1758 else if (*in
== '/')
1760 else if (*in
== '=')
1766 * Store the result in the appropriate chars...
1772 *outptr
= base64
<< 2;
1776 *outptr
++ |= (base64
>> 4) & 3;
1777 *outptr
= (base64
<< 4) & 255;
1781 *outptr
++ |= (base64
>> 2) & 15;
1782 *outptr
= (base64
<< 6) & 255;
1786 *outptr
++ |= base64
;
1795 * Return the decoded string...
1803 * 'httpEncode64()' - Base64-encode a string.
1806 char * /* O - Encoded string */
1807 httpEncode64(char *out
, /* I - String to write to */
1808 const char *in
) /* I - String to read from */
1810 char *outptr
; /* Output pointer */
1811 static const char base64
[] = /* Base64 characters... */
1813 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1814 "abcdefghijklmnopqrstuvwxyz"
1820 for (outptr
= out
; *in
!= '\0'; in
++)
1823 * Encode the up to 3 characters as 4 Base64 numbers...
1826 *outptr
++ = base64
[in
[0] >> 2];
1827 *outptr
++ = base64
[((in
[0] << 4) | (in
[1] >> 4)) & 63];
1836 *outptr
++ = base64
[((in
[0] << 2) | (in
[1] >> 6)) & 63];
1842 *outptr
++ = base64
[in
[0] & 63];
1849 * Return the encoded string...
1857 * 'httpGetLength()' - Get the amount of data remaining from the
1858 * content-length or transfer-encoding fields.
1861 int /* O - Content length */
1862 httpGetLength(http_t
*http
) /* I - HTTP data */
1864 DEBUG_printf(("httpGetLength(%p), state = %d\n", http
, http
->state
));
1866 if (strcasecmp(http
->fields
[HTTP_FIELD_TRANSFER_ENCODING
], "chunked") == 0)
1868 DEBUG_puts("httpGetLength: chunked request!");
1870 http
->data_encoding
= HTTP_ENCODE_CHUNKED
;
1871 http
->data_remaining
= 0;
1875 http
->data_encoding
= HTTP_ENCODE_LENGTH
;
1878 * The following is a hack for HTTP servers that don't send a
1879 * content-length or transfer-encoding field...
1881 * If there is no content-length then the connection must close
1882 * after the transfer is complete...
1885 if (http
->fields
[HTTP_FIELD_CONTENT_LENGTH
][0] == '\0')
1886 http
->data_remaining
= 2147483647;
1888 http
->data_remaining
= atoi(http
->fields
[HTTP_FIELD_CONTENT_LENGTH
]);
1890 DEBUG_printf(("httpGetLength: content_length = %d\n", http
->data_remaining
));
1893 return (http
->data_remaining
);
1898 * 'http_field()' - Return the field index for a field name.
1901 static http_field_t
/* O - Field index */
1902 http_field(const char *name
) /* I - String name */
1904 int i
; /* Looping var */
1907 for (i
= 0; i
< HTTP_FIELD_MAX
; i
++)
1908 if (strcasecmp(name
, http_fields
[i
]) == 0)
1909 return ((http_field_t
)i
);
1911 return (HTTP_FIELD_UNKNOWN
);
1916 * 'http_send()' - Send a request with all fields and the trailing blank line.
1919 static int /* O - 0 on success, non-zero on error */
1920 http_send(http_t
*http
, /* I - HTTP data */
1921 http_state_t request
, /* I - Request code */
1922 const char *uri
) /* I - URI */
1924 int i
; /* Looping var */
1925 char *ptr
, /* Pointer in buffer */
1926 buf
[1024]; /* Encoded URI buffer */
1927 static const char * const codes
[] =
1928 { /* Request code strings */
1943 static const char hex
[] = "0123456789ABCDEF";
1947 if (http
== NULL
|| uri
== NULL
)
1951 * Encode the URI as needed...
1954 for (ptr
= buf
; *uri
!= '\0' && ptr
< (buf
+ sizeof(buf
) - 1); uri
++)
1955 if (*uri
<= ' ' || *uri
>= 127)
1957 if (ptr
< (buf
+ sizeof(buf
) - 1))
1959 if (ptr
< (buf
+ sizeof(buf
) - 1))
1960 *ptr
++ = hex
[(*uri
>> 4) & 15];
1961 if (ptr
< (buf
+ sizeof(buf
) - 1))
1962 *ptr
++ = hex
[*uri
& 15];
1970 * See if we had an error the last time around; if so, reconnect...
1973 if (http
->status
== HTTP_ERROR
|| http
->status
>= HTTP_BAD_REQUEST
)
1974 httpReconnect(http
);
1977 * Send the request header...
1980 http
->state
= request
;
1981 if (request
== HTTP_POST
|| request
== HTTP_PUT
)
1984 http
->status
= HTTP_CONTINUE
;
1987 if (http
->encryption
== HTTP_ENCRYPT_REQUIRED
&& !http
->tls
)
1989 httpSetField(http
, HTTP_FIELD_CONNECTION
, "Upgrade");
1990 httpSetField(http
, HTTP_FIELD_UPGRADE
, "TLS/1.0,SSL/2.0,SSL/3.0");
1992 #endif /* HAVE_SSL */
1994 if (httpPrintf(http
, "%s %s HTTP/1.1\r\n", codes
[request
], buf
) < 1)
1996 http
->status
= HTTP_ERROR
;
2000 for (i
= 0; i
< HTTP_FIELD_MAX
; i
++)
2001 if (http
->fields
[i
][0] != '\0')
2003 DEBUG_printf(("%s: %s\n", http_fields
[i
], http
->fields
[i
]));
2005 if (httpPrintf(http
, "%s: %s\r\n", http_fields
[i
], http
->fields
[i
]) < 1)
2007 http
->status
= HTTP_ERROR
;
2012 if (httpPrintf(http
, "\r\n") < 1)
2014 http
->status
= HTTP_ERROR
;
2018 httpClearFields(http
);
2026 * 'http_upgrade()' - Force upgrade to TLS encryption.
2029 static int /* O - Status of connection */
2030 http_upgrade(http_t
*http
) /* I - HTTP data */
2032 int ret
; /* Return value */
2033 http_t myhttp
; /* Local copy of HTTP data */
2036 DEBUG_printf(("http_upgrade(%p)\n", http
));
2039 * Copy the HTTP data to a local variable so we can do the OPTIONS
2040 * request without interfering with the existing request data...
2043 memcpy(&myhttp
, http
, sizeof(myhttp
));
2046 * Send an OPTIONS request to the server, requiring SSL or TLS
2047 * encryption on the link...
2050 httpClearFields(&myhttp
);
2051 httpSetField(&myhttp
, HTTP_FIELD_CONNECTION
, "upgrade");
2052 httpSetField(&myhttp
, HTTP_FIELD_UPGRADE
, "TLS/1.0, SSL/2.0, SSL/3.0");
2054 if ((ret
= httpOptions(&myhttp
, "*")) == 0)
2057 * Wait for the secure connection...
2060 while (httpUpdate(&myhttp
) == HTTP_CONTINUE
);
2066 * Copy the HTTP data back over, if any...
2069 http
->fd
= myhttp
.fd
;
2070 http
->error
= myhttp
.error
;
2071 http
->activity
= myhttp
.activity
;
2072 http
->status
= myhttp
.status
;
2073 http
->version
= myhttp
.version
;
2074 http
->keep_alive
= myhttp
.keep_alive
;
2075 http
->used
= myhttp
.used
;
2078 memcpy(http
->buffer
, myhttp
.buffer
, http
->used
);
2080 http
->auth_type
= myhttp
.auth_type
;
2081 http
->nonce_count
= myhttp
.nonce_count
;
2083 memcpy(http
->nonce
, myhttp
.nonce
, sizeof(http
->nonce
));
2085 http
->tls
= myhttp
.tls
;
2086 http
->encryption
= myhttp
.encryption
;
2089 * See if we actually went secure...
2095 * Server does not support HTTP upgrade...
2098 DEBUG_puts("Server does not support HTTP upgrade!");
2101 closesocket(http
->fd
);
2116 * 'http_setup_ssl()' - Set up SSL/TLS support on a connection.
2119 static int /* O - Status of connection */
2120 http_setup_ssl(http_t
*http
) /* I - HTTP data */
2123 SSL_CTX
*context
; /* Context for encryption */
2124 SSL
*conn
; /* Connection for encryption */
2125 # elif defined(HAVE_GNUTLS)
2126 http_tls_t
*conn
; /* TLS session object */
2127 gnutls_certificate_client_credentials
*credentials
;
2128 /* TLS credentials */
2129 # elif defined(HAVE_CDSASSL)
2130 SSLContextRef conn
; /* Context for encryption */
2131 OSStatus error
; /* Error info */
2132 # endif /* HAVE_LIBSSL */
2136 context
= SSL_CTX_new(SSLv23_client_method());
2137 conn
= SSL_new(context
);
2139 SSL_set_fd(conn
, http
->fd
);
2140 if (SSL_connect(conn
) != 1)
2142 SSL_CTX_free(context
);
2146 http
->error
= WSAGetLastError();
2148 http
->error
= errno
;
2150 http
->status
= HTTP_ERROR
;
2152 return (HTTP_ERROR
);
2155 # elif defined(HAVE_GNUTLS)
2156 conn
= (http_tls_t
*)malloc(sizeof(http_tls_t
));
2160 http
->error
= errno
;
2161 http
->status
= HTTP_ERROR
;
2166 credentials
= (gnutls_certificate_client_credentials
*)
2167 malloc(sizeof(gnutls_certificate_client_credentials
));
2168 if (credentials
== NULL
)
2172 http
->error
= errno
;
2173 http
->status
= HTTP_ERROR
;
2178 gnutls_certificate_allocate_credentials(credentials
);
2180 gnutls_init(&(conn
->session
), GNUTLS_CLIENT
);
2181 gnutls_set_default_priority(conn
->session
);
2182 gnutls_credentials_set(conn
->session
, GNUTLS_CRD_CERTIFICATE
, *credentials
);
2183 gnutls_transport_set_ptr(conn
->session
, http
->fd
);
2185 if ((gnutls_handshake(conn
->session
)) != GNUTLS_E_SUCCESS
)
2187 http
->error
= errno
;
2188 http
->status
= HTTP_ERROR
;
2193 conn
->credentials
= credentials
;
2195 # elif defined(HAVE_CDSASSL)
2196 error
= SSLNewContext(false, &conn
);
2199 error
= SSLSetIOFuncs(conn
, CDSAReadFunc
, CDSAWriteFunc
);
2202 error
= SSLSetConnection(conn
, (SSLConnectionRef
)http
->fd
);
2205 error
= SSLSetAllowsExpiredCerts(conn
, true);
2208 error
= SSLSetAllowsAnyRoot(conn
, true);
2211 error
= SSLHandshake(conn
);
2215 http
->error
= error
;
2216 http
->status
= HTTP_ERROR
;
2218 SSLDisposeContext(conn
);
2224 # endif /* HAVE_CDSASSL */
2232 * 'http_shutdown_ssl()' - Shut down SSL/TLS on a connection.
2236 http_shutdown_ssl(http_t
*http
) /* I - HTTP data */
2239 SSL_CTX
*context
; /* Context for encryption */
2240 SSL
*conn
; /* Connection for encryption */
2243 conn
= (SSL
*)(http
->tls
);
2244 context
= SSL_get_SSL_CTX(conn
);
2247 SSL_CTX_free(context
);
2250 # elif defined(HAVE_GNUTLS)
2251 http_tls_t
*conn
; /* Encryption session */
2252 gnutls_certificate_client_credentials
*credentials
;
2253 /* TLS credentials */
2256 conn
= (http_tls_t
*)(http
->tls
);
2257 credentials
= (gnutls_certificate_client_credentials
*)(conn
->credentials
);
2259 gnutls_bye(conn
->session
, GNUTLS_SHUT_RDWR
);
2260 gnutls_deinit(conn
->session
);
2261 gnutls_certificate_free_credentials(*credentials
);
2265 # elif defined(HAVE_CDSASSL)
2266 SSLClose((SSLContextRef
)http
->tls
);
2267 SSLDisposeContext((SSLContextRef
)http
->tls
);
2268 # endif /* HAVE_LIBSSL */
2275 * 'http_read_ssl()' - Read from a SSL/TLS connection.
2278 static int /* O - Bytes read */
2279 http_read_ssl(http_t
*http
, /* I - HTTP data */
2280 char *buf
, /* I - Buffer to store data */
2281 int len
) /* I - Length of buffer */
2283 # if defined(HAVE_LIBSSL)
2284 return (SSL_read((SSL
*)(http
->tls
), buf
, len
));
2286 # elif defined(HAVE_GNUTLS)
2287 return (gnutls_record_recv(((http_tls_t
*)(http
->tls
))->session
, buf
, len
));
2289 # elif defined(HAVE_CDSASSL)
2290 OSStatus error
; /* Error info */
2291 size_t processed
; /* Number of bytes processed */
2294 error
= SSLRead((SSLContextRef
)http
->tls
, buf
, len
, &processed
);
2300 http
->error
= error
;
2304 # endif /* HAVE_LIBSSL */
2309 * 'http_write_ssl()' - Write to a SSL/TLS connection.
2312 static int /* O - Bytes written */
2313 http_write_ssl(http_t
*http
, /* I - HTTP data */
2314 const char *buf
, /* I - Buffer holding data */
2315 int len
) /* I - Length of buffer */
2317 # if defined(HAVE_LIBSSL)
2318 return (SSL_write((SSL
*)(http
->tls
), buf
, len
));
2320 # elif defined(HAVE_GNUTLS)
2321 return (gnutls_record_send(((http_tls_t
*)(http
->tls
))->session
, buf
, len
));
2322 # elif defined(HAVE_CDSASSL)
2323 OSStatus error
; /* Error info */
2324 size_t processed
; /* Number of bytes processed */
2327 error
= SSLWrite((SSLContextRef
)http
->tls
, buf
, len
, &processed
);
2333 http
->error
= error
;
2336 # endif /* HAVE_LIBSSL */
2340 # if defined(HAVE_CDSASSL)
2342 * 'CDSAReadFunc()' - Read function for CDSA decryption code.
2345 static OSStatus
/* O - -1 on error, 0 on success */
2346 CDSAReadFunc(SSLConnectionRef connection
, /* I - SSL/TLS connection */
2347 void *data
, /* I - Data buffer */
2348 size_t *dataLength
) /* IO - Number of bytes */
2350 ssize_t bytes
; /* Number of bytes read */
2353 bytes
= recv((int)connection
, data
, *dataLength
, 0);
2356 *dataLength
= bytes
;
2365 * 'CDSAWriteFunc()' - Write function for CDSA encryption code.
2368 static OSStatus
/* O - -1 on error, 0 on success */
2369 CDSAWriteFunc(SSLConnectionRef connection
, /* I - SSL/TLS connection */
2370 const void *data
, /* I - Data buffer */
2371 size_t *dataLength
) /* IO - Number of bytes */
2376 bytes
= write((int)connection
, data
, *dataLength
);
2379 *dataLength
= bytes
;
2385 # endif /* HAVE_CDSASSL */
2386 #endif /* HAVE_SSL */
2390 * End of "$Id: http.c,v 1.120 2003/05/27 14:03:37 mike Exp $".