2 * "$Id: http.c,v 1.117 2003/05/09 16:05:27 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
->data_remaining
> sizeof(http
->buffer
))
913 bytes
= sizeof(http
->buffer
);
915 bytes
= http
->data_remaining
;
917 if (!http
->blocking
&& !httpWait(http
, 1000))
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))
977 bytes
= http_read_ssl(http
, buffer
, length
);
979 #endif /* HAVE_SSL */
982 if (!http
->blocking
&& !httpWait(http
, 1000))
984 DEBUG_printf(("httpRead: reading %d bytes from socket...\n", length
));
985 bytes
= recv(http
->fd
, buffer
, length
, 0);
986 DEBUG_printf(("httpRead: read %d bytes from socket...\n", bytes
));
990 http
->data_remaining
-= bytes
;
994 http
->error
= WSAGetLastError();
1002 else if (bytes
== 0)
1004 http
->error
= EPIPE
;
1008 if (http
->data_remaining
== 0)
1010 if (http
->data_encoding
== HTTP_ENCODE_CHUNKED
)
1011 httpGets(len
, sizeof(len
), http
);
1013 if (http
->data_encoding
!= HTTP_ENCODE_CHUNKED
)
1015 if (http
->state
== HTTP_POST_RECV
)
1018 http
->state
= HTTP_WAITING
;
1025 printf("httpRead: Read %d bytes:\n", bytes
);
1026 for (i
= 0; i
< bytes
; i
+= 16)
1030 for (j
= 0; j
< 16 && (i
+ j
) < bytes
; j
++)
1031 printf(" %02X", buffer
[i
+ j
] & 255);
1040 for (j
= 0; j
< 16 && (i
+ j
) < bytes
; j
++)
1042 ch
= buffer
[i
+ j
] & 255;
1044 if (ch
< ' ' || ch
== 127)
1059 * 'httpSetCookie()' - Set the cookie value(s)...
1063 httpSetCookie(http_t
*http
, /* I - Connection */
1064 const char *cookie
) /* I - Cookie string */
1073 http
->cookie
= strdup(cookie
);
1075 http
->cookie
= NULL
;
1080 * 'httpWait()' - Wait for data available on a connection.
1083 int /* O - 1 if data is available, 0 otherwise */
1084 httpWait(http_t
*http
, /* I - HTTP data */
1085 int msec
) /* I - Milliseconds to wait */
1088 struct rlimit limit
; /* Runtime limit */
1090 struct timeval timeout
; /* Timeout */
1091 int nfds
; /* Result from select() */
1095 * First see if there is data in the buffer...
1105 * Then try doing a select() to poll the socket...
1108 if (!http
->input_set
)
1112 * Windows has a fixed-size select() structure, different (surprise,
1113 * surprise!) from all UNIX implementations. Just allocate this
1114 * fixed structure...
1117 http
->input_set
= calloc(1, sizeof(fd_set
));
1120 * Allocate the select() input set based upon the max number of file
1121 * descriptors available for this process...
1124 getrlimit(RLIMIT_NOFILE
, &limit
);
1126 http
->input_set
= calloc(1, (limit
.rlim_cur
+ 7) / 8);
1129 if (!http
->input_set
)
1133 FD_SET(http
->fd
, http
->input_set
);
1137 timeout
.tv_sec
= msec
/ 1000;
1138 timeout
.tv_usec
= (msec
% 1000) * 1000;
1140 nfds
= select(http
->fd
+ 1, http
->input_set
, NULL
, NULL
, &timeout
);
1143 nfds
= select(http
->fd
+ 1, http
->input_set
, NULL
, NULL
, NULL
);
1145 FD_CLR(http
->fd
, http
->input_set
);
1152 * 'httpWrite()' - Write data to a HTTP connection.
1155 int /* O - Number of bytes written */
1156 httpWrite(http_t
*http
, /* I - HTTP data */
1157 const char *buffer
, /* I - Buffer for data */
1158 int length
) /* I - Number of bytes to write */
1160 int tbytes
, /* Total bytes sent */
1161 bytes
; /* Bytes sent */
1164 if (http
== NULL
|| buffer
== NULL
)
1167 http
->activity
= time(NULL
);
1169 if (http
->data_encoding
== HTTP_ENCODE_CHUNKED
)
1171 if (httpPrintf(http
, "%x\r\n", length
) < 0)
1177 * A zero-length chunk ends a transfer; unless we are sending POST
1181 DEBUG_puts("httpWrite: changing states...");
1183 if (http
->state
== HTTP_POST_RECV
)
1185 else if (http
->state
== HTTP_PUT_RECV
)
1186 http
->state
= HTTP_STATUS
;
1188 http
->state
= HTTP_WAITING
;
1190 if (httpPrintf(http
, "\r\n") < 0)
1203 bytes
= http_write_ssl(http
, buffer
, length
);
1205 #endif /* HAVE_SSL */
1206 bytes
= send(http
->fd
, buffer
, length
, 0);
1211 if (WSAGetLastError() != http
->error
)
1213 http
->error
= WSAGetLastError();
1219 else if (errno
!= http
->error
)
1221 http
->error
= errno
;
1226 DEBUG_puts("httpWrite: error writing data...\n");
1234 if (http
->data_encoding
== HTTP_ENCODE_LENGTH
)
1235 http
->data_remaining
-= bytes
;
1238 if (http
->data_encoding
== HTTP_ENCODE_CHUNKED
)
1239 if (httpPrintf(http
, "\r\n") < 0)
1242 if (http
->data_remaining
== 0 && http
->data_encoding
== HTTP_ENCODE_LENGTH
)
1245 * Finished with the transfer; unless we are sending POST data, go idle...
1248 DEBUG_puts("httpWrite: changing states...");
1250 if (http
->state
== HTTP_POST_RECV
)
1253 http
->state
= HTTP_WAITING
;
1259 printf("httpWrite: wrote %d bytes: \n", tbytes
);
1260 for (i
= 0, buffer
-= tbytes
; i
< tbytes
; i
+= 16)
1264 for (j
= 0; j
< 16 && (i
+ j
) < tbytes
; j
++)
1265 printf(" %02X", buffer
[i
+ j
] & 255);
1274 for (j
= 0; j
< 16 && (i
+ j
) < tbytes
; j
++)
1276 ch
= buffer
[i
+ j
] & 255;
1278 if (ch
< ' ' || ch
== 127)
1292 * 'httpGets()' - Get a line of text from a HTTP connection.
1295 char * /* O - Line or NULL */
1296 httpGets(char *line
, /* I - Line to read into */
1297 int length
, /* I - Max length of buffer */
1298 http_t
*http
) /* I - HTTP data */
1300 char *lineptr
, /* Pointer into line */
1301 *bufptr
, /* Pointer into input buffer */
1302 *bufend
; /* Pointer to end of buffer */
1303 int bytes
; /* Number of bytes read */
1306 DEBUG_printf(("httpGets(%p, %d, %p)\n", line
, length
, http
));
1308 if (http
== NULL
|| line
== NULL
)
1312 * Pre-scan the buffer and see if there is a newline in there...
1323 bufptr
= http
->buffer
;
1324 bufend
= http
->buffer
+ http
->used
;
1326 while (bufptr
< bufend
)
1327 if (*bufptr
== 0x0a)
1332 if (bufptr
>= bufend
&& http
->used
< HTTP_MAX_BUFFER
)
1335 * No newline; see if there is more data to be read...
1338 if (!http
->blocking
&& !httpWait(http
, 1000))
1343 bytes
= http_read_ssl(http
, bufend
, HTTP_MAX_BUFFER
- http
->used
);
1345 #endif /* HAVE_SSL */
1346 bytes
= recv(http
->fd
, bufend
, HTTP_MAX_BUFFER
- http
->used
, 0);
1351 * Nope, can't get a line this time...
1355 if (WSAGetLastError() != http
->error
)
1357 http
->error
= WSAGetLastError();
1361 DEBUG_printf(("httpGets(): recv() error %d!\n", WSAGetLastError()));
1365 else if (errno
!= http
->error
)
1367 http
->error
= errno
;
1371 DEBUG_printf(("httpGets(): recv() error %d!\n", errno
));
1376 else if (bytes
== 0)
1378 http
->error
= EPIPE
;
1384 * Yup, update the amount used and the end pointer...
1387 http
->used
+= bytes
;
1392 while (bufptr
>= bufend
&& http
->used
< HTTP_MAX_BUFFER
);
1394 http
->activity
= time(NULL
);
1397 * Read a line from the buffer...
1401 bufptr
= http
->buffer
;
1405 while (bufptr
< bufend
&& bytes
< length
)
1409 if (*bufptr
== 0x0a)
1414 else if (*bufptr
== 0x0d)
1417 *lineptr
++ = *bufptr
++;
1424 http
->used
-= bytes
;
1426 memmove(http
->buffer
, bufptr
, http
->used
);
1428 DEBUG_printf(("httpGets(): Returning \"%s\"\n", line
));
1432 DEBUG_puts("httpGets(): No new line available!");
1439 * 'httpPrintf()' - Print a formatted string to a HTTP connection.
1442 int /* O - Number of bytes written */
1443 httpPrintf(http_t
*http
, /* I - HTTP data */
1444 const char *format
, /* I - printf-style format string */
1445 ...) /* I - Additional args as needed */
1447 int bytes
, /* Number of bytes to write */
1448 nbytes
, /* Number of bytes written */
1449 tbytes
; /* Number of bytes all together */
1450 char buf
[HTTP_MAX_BUFFER
], /* Buffer for formatted string */
1451 *bufptr
; /* Pointer into buffer */
1452 va_list ap
; /* Variable argument pointer */
1455 va_start(ap
, format
);
1456 bytes
= vsnprintf(buf
, sizeof(buf
), format
, ap
);
1459 DEBUG_printf(("httpPrintf: %s", buf
));
1461 for (tbytes
= 0, bufptr
= buf
; tbytes
< bytes
; tbytes
+= nbytes
, bufptr
+= nbytes
)
1465 nbytes
= http_write_ssl(http
, bufptr
, bytes
- tbytes
);
1467 #endif /* HAVE_SSL */
1468 nbytes
= send(http
->fd
, bufptr
, bytes
- tbytes
, 0);
1475 if (WSAGetLastError() != http
->error
)
1477 http
->error
= WSAGetLastError();
1483 else if (errno
!= http
->error
)
1485 http
->error
= errno
;
1499 * 'httpGetDateString()' - Get a formatted date/time string from a time value.
1502 const char * /* O - Date/time string */
1503 httpGetDateString(time_t t
) /* I - UNIX time */
1506 static char datetime
[256];
1510 snprintf(datetime
, sizeof(datetime
), "%s, %02d %s %d %02d:%02d:%02d GMT",
1511 days
[tdate
->tm_wday
], tdate
->tm_mday
, months
[tdate
->tm_mon
],
1512 tdate
->tm_year
+ 1900, tdate
->tm_hour
, tdate
->tm_min
, tdate
->tm_sec
);
1519 * 'httpGetDateTime()' - Get a time value from a formatted date/time string.
1522 time_t /* O - UNIX time */
1523 httpGetDateTime(const char *s
) /* I - Date/time string */
1525 int i
; /* Looping var */
1526 struct tm tdate
; /* Time/date structure */
1527 char mon
[16]; /* Abbreviated month name */
1528 int day
, year
; /* Day of month and year */
1529 int hour
, min
, sec
; /* Time */
1532 if (sscanf(s
, "%*s%d%15s%d%d:%d:%d", &day
, mon
, &year
, &hour
, &min
, &sec
) < 6)
1535 for (i
= 0; i
< 12; i
++)
1536 if (strcasecmp(mon
, months
[i
]) == 0)
1543 tdate
.tm_mday
= day
;
1544 tdate
.tm_year
= year
- 1900;
1545 tdate
.tm_hour
= hour
;
1550 return (mktime(&tdate
));
1555 * 'httpUpdate()' - Update the current HTTP state for incoming data.
1558 http_status_t
/* O - HTTP status */
1559 httpUpdate(http_t
*http
) /* I - HTTP data */
1561 char line
[1024], /* Line from connection... */
1562 *value
; /* Pointer to value on line */
1563 http_field_t field
; /* Field index */
1564 int major
, minor
; /* HTTP version numbers */
1565 http_status_t status
; /* Authorization status */
1568 DEBUG_printf(("httpUpdate(%p)\n", http
));
1571 * If we haven't issued any commands, then there is nothing to "update"...
1574 if (http
->state
== HTTP_WAITING
)
1575 return (HTTP_CONTINUE
);
1578 * Grab all of the lines we can from the connection...
1581 while (httpGets(line
, sizeof(line
), http
) != NULL
)
1585 if (line
[0] == '\0')
1588 * Blank line means the start of the data section (if any). Return
1589 * the result code, too...
1591 * If we get status 100 (HTTP_CONTINUE), then we *don't* change states.
1592 * Instead, we just return HTTP_CONTINUE to the caller and keep on
1596 if (http
->status
== HTTP_CONTINUE
)
1597 return (http
->status
);
1600 if (http
->status
== HTTP_SWITCHING_PROTOCOLS
&& !http
->tls
)
1602 if (http_setup_ssl(http
) != 0)
1605 closesocket(http
->fd
);
1610 return (HTTP_ERROR
);
1613 return (HTTP_CONTINUE
);
1615 #endif /* HAVE_SSL */
1617 httpGetLength(http
);
1619 switch (http
->state
)
1623 case HTTP_POST_RECV
:
1626 case HTTP_POST_SEND
:
1630 http
->state
= HTTP_WAITING
;
1634 return (http
->status
);
1636 else if (strncmp(line
, "HTTP/", 5) == 0)
1639 * Got the beginning of a response...
1642 if (sscanf(line
, "HTTP/%d.%d%d", &major
, &minor
, (int *)&status
) != 3)
1643 return (HTTP_ERROR
);
1645 http
->version
= (http_version_t
)(major
* 100 + minor
);
1646 http
->status
= status
;
1648 else if ((value
= strchr(line
, ':')) != NULL
)
1655 while (isspace(*value
))
1659 * Be tolerants of servers that send unknown attribute fields...
1662 if (!strcasecmp(line
, "expect"))
1665 * "Expect: 100-continue" or similar...
1668 http
->expect
= (http_status_t
)atoi(value
);
1670 else if (!strcasecmp(line
, "cookie"))
1673 * "Cookie: name=value[; name=value ...]" - replaces previous cookies...
1676 httpSetCookie(http
, value
);
1678 else if ((field
= http_field(line
)) == HTTP_FIELD_UNKNOWN
)
1680 DEBUG_printf(("httpUpdate: unknown field %s seen!\n", line
));
1684 httpSetField(http
, field
, value
);
1688 http
->status
= HTTP_ERROR
;
1689 return (HTTP_ERROR
);
1694 * See if there was an error...
1699 http
->status
= HTTP_ERROR
;
1700 return (HTTP_ERROR
);
1704 * If we haven't already returned, then there is nothing new...
1707 return (HTTP_CONTINUE
);
1712 * 'httpDecode64()' - Base64-decode a string.
1715 char * /* O - Decoded string */
1716 httpDecode64(char *out
, /* I - String to write to */
1717 const char *in
) /* I - String to read from */
1719 int pos
, /* Bit position */
1720 base64
; /* Value of this character */
1721 char *outptr
; /* Output pointer */
1724 for (outptr
= out
, pos
= 0; *in
!= '\0'; in
++)
1727 * Decode this character into a number from 0 to 63...
1730 if (*in
>= 'A' && *in
<= 'Z')
1732 else if (*in
>= 'a' && *in
<= 'z')
1733 base64
= *in
- 'a' + 26;
1734 else if (*in
>= '0' && *in
<= '9')
1735 base64
= *in
- '0' + 52;
1736 else if (*in
== '+')
1738 else if (*in
== '/')
1740 else if (*in
== '=')
1746 * Store the result in the appropriate chars...
1752 *outptr
= base64
<< 2;
1756 *outptr
++ |= (base64
>> 4) & 3;
1757 *outptr
= (base64
<< 4) & 255;
1761 *outptr
++ |= (base64
>> 2) & 15;
1762 *outptr
= (base64
<< 6) & 255;
1766 *outptr
++ |= base64
;
1775 * Return the decoded string...
1783 * 'httpEncode64()' - Base64-encode a string.
1786 char * /* O - Encoded string */
1787 httpEncode64(char *out
, /* I - String to write to */
1788 const char *in
) /* I - String to read from */
1790 char *outptr
; /* Output pointer */
1791 static const char base64
[] = /* Base64 characters... */
1793 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1794 "abcdefghijklmnopqrstuvwxyz"
1800 for (outptr
= out
; *in
!= '\0'; in
++)
1803 * Encode the up to 3 characters as 4 Base64 numbers...
1806 *outptr
++ = base64
[in
[0] >> 2];
1807 *outptr
++ = base64
[((in
[0] << 4) | (in
[1] >> 4)) & 63];
1816 *outptr
++ = base64
[((in
[0] << 2) | (in
[1] >> 6)) & 63];
1822 *outptr
++ = base64
[in
[0] & 63];
1829 * Return the encoded string...
1837 * 'httpGetLength()' - Get the amount of data remaining from the
1838 * content-length or transfer-encoding fields.
1841 int /* O - Content length */
1842 httpGetLength(http_t
*http
) /* I - HTTP data */
1844 DEBUG_printf(("httpGetLength(%p), state = %d\n", http
, http
->state
));
1846 if (strcasecmp(http
->fields
[HTTP_FIELD_TRANSFER_ENCODING
], "chunked") == 0)
1848 DEBUG_puts("httpGetLength: chunked request!");
1850 http
->data_encoding
= HTTP_ENCODE_CHUNKED
;
1851 http
->data_remaining
= 0;
1855 http
->data_encoding
= HTTP_ENCODE_LENGTH
;
1858 * The following is a hack for HTTP servers that don't send a
1859 * content-length or transfer-encoding field...
1861 * If there is no content-length then the connection must close
1862 * after the transfer is complete...
1865 if (http
->fields
[HTTP_FIELD_CONTENT_LENGTH
][0] == '\0')
1866 http
->data_remaining
= 2147483647;
1868 http
->data_remaining
= atoi(http
->fields
[HTTP_FIELD_CONTENT_LENGTH
]);
1870 DEBUG_printf(("httpGetLength: content_length = %d\n", http
->data_remaining
));
1873 return (http
->data_remaining
);
1878 * 'http_field()' - Return the field index for a field name.
1881 static http_field_t
/* O - Field index */
1882 http_field(const char *name
) /* I - String name */
1884 int i
; /* Looping var */
1887 for (i
= 0; i
< HTTP_FIELD_MAX
; i
++)
1888 if (strcasecmp(name
, http_fields
[i
]) == 0)
1889 return ((http_field_t
)i
);
1891 return (HTTP_FIELD_UNKNOWN
);
1896 * 'http_send()' - Send a request with all fields and the trailing blank line.
1899 static int /* O - 0 on success, non-zero on error */
1900 http_send(http_t
*http
, /* I - HTTP data */
1901 http_state_t request
, /* I - Request code */
1902 const char *uri
) /* I - URI */
1904 int i
; /* Looping var */
1905 char *ptr
, /* Pointer in buffer */
1906 buf
[1024]; /* Encoded URI buffer */
1907 static const char * const codes
[] =
1908 { /* Request code strings */
1923 static const char hex
[] = "0123456789ABCDEF";
1927 if (http
== NULL
|| uri
== NULL
)
1931 * Encode the URI as needed...
1934 for (ptr
= buf
; *uri
!= '\0' && ptr
< (buf
+ sizeof(buf
) - 1); uri
++)
1935 if (*uri
<= ' ' || *uri
>= 127)
1937 if (ptr
< (buf
+ sizeof(buf
) - 1))
1939 if (ptr
< (buf
+ sizeof(buf
) - 1))
1940 *ptr
++ = hex
[(*uri
>> 4) & 15];
1941 if (ptr
< (buf
+ sizeof(buf
) - 1))
1942 *ptr
++ = hex
[*uri
& 15];
1950 * See if we had an error the last time around; if so, reconnect...
1953 if (http
->status
== HTTP_ERROR
|| http
->status
>= HTTP_BAD_REQUEST
)
1954 httpReconnect(http
);
1957 * Send the request header...
1960 http
->state
= request
;
1961 if (request
== HTTP_POST
|| request
== HTTP_PUT
)
1964 http
->status
= HTTP_CONTINUE
;
1967 if (http
->encryption
== HTTP_ENCRYPT_REQUIRED
&& !http
->tls
)
1969 httpSetField(http
, HTTP_FIELD_CONNECTION
, "Upgrade");
1970 httpSetField(http
, HTTP_FIELD_UPGRADE
, "TLS/1.0,SSL/2.0,SSL/3.0");
1972 #endif /* HAVE_SSL */
1974 if (httpPrintf(http
, "%s %s HTTP/1.1\r\n", codes
[request
], buf
) < 1)
1976 http
->status
= HTTP_ERROR
;
1980 for (i
= 0; i
< HTTP_FIELD_MAX
; i
++)
1981 if (http
->fields
[i
][0] != '\0')
1983 DEBUG_printf(("%s: %s\n", http_fields
[i
], http
->fields
[i
]));
1985 if (httpPrintf(http
, "%s: %s\r\n", http_fields
[i
], http
->fields
[i
]) < 1)
1987 http
->status
= HTTP_ERROR
;
1992 if (httpPrintf(http
, "\r\n") < 1)
1994 http
->status
= HTTP_ERROR
;
1998 httpClearFields(http
);
2006 * 'http_upgrade()' - Force upgrade to TLS encryption.
2009 static int /* O - Status of connection */
2010 http_upgrade(http_t
*http
) /* I - HTTP data */
2012 int ret
; /* Return value */
2013 http_t myhttp
; /* Local copy of HTTP data */
2016 DEBUG_printf(("http_upgrade(%p)\n", http
));
2019 * Copy the HTTP data to a local variable so we can do the OPTIONS
2020 * request without interfering with the existing request data...
2023 memcpy(&myhttp
, http
, sizeof(myhttp
));
2026 * Send an OPTIONS request to the server, requiring SSL or TLS
2027 * encryption on the link...
2030 httpClearFields(&myhttp
);
2031 httpSetField(&myhttp
, HTTP_FIELD_CONNECTION
, "upgrade");
2032 httpSetField(&myhttp
, HTTP_FIELD_UPGRADE
, "TLS/1.0, SSL/2.0, SSL/3.0");
2034 if ((ret
= httpOptions(&myhttp
, "*")) == 0)
2037 * Wait for the secure connection...
2040 while (httpUpdate(&myhttp
) == HTTP_CONTINUE
);
2046 * Copy the HTTP data back over, if any...
2049 http
->fd
= myhttp
.fd
;
2050 http
->error
= myhttp
.error
;
2051 http
->activity
= myhttp
.activity
;
2052 http
->status
= myhttp
.status
;
2053 http
->version
= myhttp
.version
;
2054 http
->keep_alive
= myhttp
.keep_alive
;
2055 http
->used
= myhttp
.used
;
2058 memcpy(http
->buffer
, myhttp
.buffer
, http
->used
);
2060 http
->auth_type
= myhttp
.auth_type
;
2061 http
->nonce_count
= myhttp
.nonce_count
;
2063 memcpy(http
->nonce
, myhttp
.nonce
, sizeof(http
->nonce
));
2065 http
->tls
= myhttp
.tls
;
2066 http
->encryption
= myhttp
.encryption
;
2069 * See if we actually went secure...
2075 * Server does not support HTTP upgrade...
2078 DEBUG_puts("Server does not support HTTP upgrade!");
2081 closesocket(http
->fd
);
2096 * 'http_setup_ssl()' - Set up SSL/TLS support on a connection.
2099 static int /* O - Status of connection */
2100 http_setup_ssl(http_t
*http
) /* I - HTTP data */
2103 SSL_CTX
*context
; /* Context for encryption */
2104 SSL
*conn
; /* Connection for encryption */
2105 # elif defined(HAVE_GNUTLS)
2106 http_tls_t
*conn
; /* TLS session object */
2107 gnutls_certificate_client_credentials
*credentials
;
2108 /* TLS credentials */
2109 # elif defined(HAVE_CDSASSL)
2110 SSLContextRef conn
; /* Context for encryption */
2111 OSStatus error
; /* Error info */
2112 # endif /* HAVE_LIBSSL */
2116 context
= SSL_CTX_new(SSLv23_client_method());
2117 conn
= SSL_new(context
);
2119 SSL_set_fd(conn
, http
->fd
);
2120 if (SSL_connect(conn
) != 1)
2122 SSL_CTX_free(context
);
2126 http
->error
= WSAGetLastError();
2128 http
->error
= errno
;
2130 http
->status
= HTTP_ERROR
;
2132 return (HTTP_ERROR
);
2135 # elif defined(HAVE_GNUTLS)
2136 conn
= (http_tls_t
*)malloc(sizeof(http_tls_t
));
2140 http
->error
= errno
;
2141 http
->status
= HTTP_ERROR
;
2146 credentials
= (gnutls_certificate_client_credentials
*)
2147 malloc(sizeof(gnutls_certificate_client_credentials
));
2148 if (credentials
== NULL
)
2152 http
->error
= errno
;
2153 http
->status
= HTTP_ERROR
;
2158 gnutls_certificate_allocate_credentials(credentials
);
2160 gnutls_init(&(conn
->session
), GNUTLS_CLIENT
);
2161 gnutls_set_default_priority(conn
->session
);
2162 gnutls_credentials_set(conn
->session
, GNUTLS_CRD_CERTIFICATE
, *credentials
);
2163 gnutls_transport_set_ptr(conn
->session
, http
->fd
);
2165 if ((gnutls_handshake(conn
->session
)) != GNUTLS_E_SUCCESS
)
2167 http
->error
= errno
;
2168 http
->status
= HTTP_ERROR
;
2173 conn
->credentials
= credentials
;
2175 # elif defined(HAVE_CDSASSL)
2176 error
= SSLNewContext(false, &conn
);
2179 error
= SSLSetIOFuncs(conn
, CDSAReadFunc
, CDSAWriteFunc
);
2182 error
= SSLSetConnection(conn
, (SSLConnectionRef
)http
->fd
);
2185 error
= SSLSetAllowsExpiredCerts(conn
, true);
2188 error
= SSLSetAllowsAnyRoot(conn
, true);
2191 error
= SSLHandshake(conn
);
2195 http
->error
= error
;
2196 http
->status
= HTTP_ERROR
;
2198 SSLDisposeContext(conn
);
2204 # endif /* HAVE_CDSASSL */
2212 * 'http_shutdown_ssl()' - Shut down SSL/TLS on a connection.
2216 http_shutdown_ssl(http_t
*http
) /* I - HTTP data */
2219 SSL_CTX
*context
; /* Context for encryption */
2220 SSL
*conn
; /* Connection for encryption */
2223 conn
= (SSL
*)(http
->tls
);
2224 context
= SSL_get_SSL_CTX(conn
);
2227 SSL_CTX_free(context
);
2230 # elif defined(HAVE_GNUTLS)
2231 http_tls_t
*conn
; /* Encryption session */
2232 gnutls_certificate_client_credentials
*credentials
;
2233 /* TLS credentials */
2236 conn
= (http_tls_t
*)(http
->tls
);
2237 credentials
= (gnutls_certificate_client_credentials
*)(conn
->credentials
);
2239 gnutls_bye(conn
->session
, GNUTLS_SHUT_RDWR
);
2240 gnutls_deinit(conn
->session
);
2241 gnutls_certificate_free_credentials(*credentials
);
2245 # elif defined(HAVE_CDSASSL)
2246 SSLClose((SSLContextRef
)http
->tls
);
2247 SSLDisposeContext((SSLContextRef
)http
->tls
);
2248 # endif /* HAVE_LIBSSL */
2255 * 'http_read_ssl()' - Read from a SSL/TLS connection.
2258 static int /* O - Bytes read */
2259 http_read_ssl(http_t
*http
, /* I - HTTP data */
2260 char *buf
, /* I - Buffer to store data */
2261 int len
) /* I - Length of buffer */
2263 # if defined(HAVE_LIBSSL)
2264 return (SSL_read((SSL
*)(http
->tls
), buf
, len
));
2266 # elif defined(HAVE_GNUTLS)
2267 return (gnutls_record_recv(((http_tls_t
*)(http
->tls
))->session
, buf
, len
));
2269 # elif defined(HAVE_CDSASSL)
2270 OSStatus error
; /* Error info */
2271 size_t processed
; /* Number of bytes processed */
2274 error
= SSLRead((SSLContextRef
)http
->tls
, buf
, len
, &processed
);
2280 http
->error
= error
;
2284 # endif /* HAVE_LIBSSL */
2289 * 'http_write_ssl()' - Write to a SSL/TLS connection.
2292 static int /* O - Bytes written */
2293 http_write_ssl(http_t
*http
, /* I - HTTP data */
2294 const char *buf
, /* I - Buffer holding data */
2295 int len
) /* I - Length of buffer */
2297 # if defined(HAVE_LIBSSL)
2298 return (SSL_write((SSL
*)(http
->tls
), buf
, len
));
2300 # elif defined(HAVE_GNUTLS)
2301 return (gnutls_record_send(((http_tls_t
*)(http
->tls
))->session
, buf
, len
));
2302 # elif defined(HAVE_CDSASSL)
2303 OSStatus error
; /* Error info */
2304 size_t processed
; /* Number of bytes processed */
2307 error
= SSLWrite((SSLContextRef
)http
->tls
, buf
, len
, &processed
);
2313 http
->error
= error
;
2316 # endif /* HAVE_LIBSSL */
2320 # if defined(HAVE_CDSASSL)
2322 * 'CDSAReadFunc()' - Read function for CDSA decryption code.
2325 static OSStatus
/* O - -1 on error, 0 on success */
2326 CDSAReadFunc(SSLConnectionRef connection
, /* I - SSL/TLS connection */
2327 void *data
, /* I - Data buffer */
2328 size_t *dataLength
) /* IO - Number of bytes */
2330 ssize_t bytes
; /* Number of bytes read */
2333 bytes
= recv((int)connection
, data
, *dataLength
, 0);
2336 *dataLength
= bytes
;
2345 * 'CDSAWriteFunc()' - Write function for CDSA encryption code.
2348 static OSStatus
/* O - -1 on error, 0 on success */
2349 CDSAWriteFunc(SSLConnectionRef connection
, /* I - SSL/TLS connection */
2350 const void *data
, /* I - Data buffer */
2351 size_t *dataLength
) /* IO - Number of bytes */
2356 bytes
= write((int)connection
, data
, *dataLength
);
2359 *dataLength
= bytes
;
2365 # endif /* HAVE_CDSASSL */
2366 #endif /* HAVE_SSL */
2370 * End of "$Id: http.c,v 1.117 2003/05/09 16:05:27 mike Exp $".