Lines Matching refs:http
43 static void http_content_coding_finish(http_t *http);
44 static void http_content_coding_start(http_t *http,
55 static ssize_t http_read(http_t *http, char *buffer, size_t length);
56 static ssize_t http_read_buffered(http_t *http, char *buffer, size_t length);
57 static ssize_t http_read_chunk(http_t *http, char *buffer, size_t length);
58 static int http_send(http_t *http, http_state_t request,
60 static ssize_t http_write(http_t *http, const char *buffer,
62 static ssize_t http_write_chunk(http_t *http, const char *buffer,
64 static off_t http_set_length(http_t *http);
66 static void http_set_wait(http_t *http);
69 static int http_tls_upgrade(http_t *http);
124 http_t *http; /* HTTP connection */ in httpAcceptConnection() local
143 if ((http = http_create(NULL, 0, &addrlist, AF_UNSPEC, in httpAcceptConnection()
154 if ((http->fd = accept(fd, (struct sockaddr *)&(http->addrlist->addr), in httpAcceptConnection()
158 httpClose(http); in httpAcceptConnection()
163 http->hostaddr = &(http->addrlist->addr); in httpAcceptConnection()
165 if (httpAddrLocalhost(http->hostaddr)) in httpAcceptConnection()
166 strlcpy(http->hostname, "localhost", sizeof(http->hostname)); in httpAcceptConnection()
168 httpAddrString(http->hostaddr, http->hostname, sizeof(http->hostname)); in httpAcceptConnection()
176 setsockopt(http->fd, SOL_SOCKET, SO_NOSIGPIPE, CUPS_SOCAST &val, sizeof(val)); in httpAcceptConnection()
187 setsockopt(http->fd, IPPROTO_TCP, TCP_NODELAY, CUPS_SOCAST &val, sizeof(val)); in httpAcceptConnection()
194 fcntl(http->fd, F_SETFD, FD_CLOEXEC); in httpAcceptConnection()
197 return (http); in httpAcceptConnection()
241 httpBlocking(http_t *http, /* I - HTTP connection */ in httpBlocking() argument
244 if (http) in httpBlocking()
246 http->blocking = b; in httpBlocking()
247 http_set_wait(http); in httpBlocking()
257 httpCheck(http_t *http) /* I - HTTP connection */ in httpCheck() argument
259 return (httpWait(http, 0)); in httpCheck()
270 httpClearCookie(http_t *http) /* I - HTTP connection */ in httpClearCookie() argument
272 if (!http) in httpClearCookie()
275 if (http->cookie) in httpClearCookie()
277 free(http->cookie); in httpClearCookie()
278 http->cookie = NULL; in httpClearCookie()
288 httpClearFields(http_t *http) /* I - HTTP connection */ in httpClearFields() argument
290 DEBUG_printf(("httpClearFields(http=%p)", (void *)http)); in httpClearFields()
292 if (http) in httpClearFields()
294 memset(http->fields, 0, sizeof(http->fields)); in httpClearFields()
296 if (http->mode == _HTTP_MODE_CLIENT) in httpClearFields()
298 if (http->hostname[0] == '/') in httpClearFields()
299 httpSetField(http, HTTP_FIELD_HOST, "localhost"); in httpClearFields()
301 httpSetField(http, HTTP_FIELD_HOST, http->hostname); in httpClearFields()
304 if (http->field_authorization) in httpClearFields()
306 free(http->field_authorization); in httpClearFields()
307 http->field_authorization = NULL; in httpClearFields()
310 if (http->accept_encoding) in httpClearFields()
312 _cupsStrFree(http->accept_encoding); in httpClearFields()
313 http->accept_encoding = NULL; in httpClearFields()
316 if (http->allow) in httpClearFields()
318 _cupsStrFree(http->allow); in httpClearFields()
319 http->allow = NULL; in httpClearFields()
322 if (http->server) in httpClearFields()
324 _cupsStrFree(http->server); in httpClearFields()
325 http->server = NULL; in httpClearFields()
328 http->expect = (http_status_t)0; in httpClearFields()
338 httpClose(http_t *http) /* I - HTTP connection */ in httpClose() argument
345 DEBUG_printf(("httpClose(http=%p)", (void *)http)); in httpClose()
351 if (!http) in httpClose()
358 _httpDisconnect(http); in httpClose()
364 httpAddrFreeList(http->addrlist); in httpClose()
366 if (http->cookie) in httpClose()
367 free(http->cookie); in httpClose()
370 if (http->gssctx != GSS_C_NO_CONTEXT) in httpClose()
371 gss_delete_sec_context(&minor_status, &http->gssctx, GSS_C_NO_BUFFER); in httpClose()
373 if (http->gssname != GSS_C_NO_NAME) in httpClose()
374 gss_release_name(&minor_status, &http->gssname); in httpClose()
378 if (http->auth_ref) in httpClose()
379 AuthorizationFree(http->auth_ref, kAuthorizationFlagDefaults); in httpClose()
382 httpClearFields(http); in httpClose()
384 if (http->authstring && http->authstring != http->_authstring) in httpClose()
385 free(http->authstring); in httpClose()
387 free(http); in httpClose()
449 http_t *http; /* New HTTP connection */ in httpConnect2() local
458 if ((http = http_create(host, port, addrlist, family, encryption, blocking, in httpConnect2()
466 if (msec == 0 || !httpReconnect2(http, msec, cancel)) in httpConnect2()
467 return (http); in httpConnect2()
473 httpClose(http); in httpConnect2()
507 httpDelete(http_t *http, /* I - HTTP connection */ in httpDelete() argument
510 return (http_send(http, HTTP_STATE_DELETE, uri)); in httpDelete()
519 _httpDisconnect(http_t *http) /* I - HTTP connection */ in _httpDisconnect() argument
522 if (http->tls) in _httpDisconnect()
523 _httpTLSStop(http); in _httpDisconnect()
526 httpAddrClose(NULL, http->fd); in _httpDisconnect()
528 http->fd = -1; in _httpDisconnect()
537 httpEncryption(http_t *http, /* I - HTTP connection */ in httpEncryption() argument
540 DEBUG_printf(("httpEncryption(http=%p, e=%d)", (void *)http, e)); in httpEncryption()
543 if (!http) in httpEncryption()
546 if (http->mode == _HTTP_MODE_CLIENT) in httpEncryption()
548 http->encryption = e; in httpEncryption()
550 if ((http->encryption == HTTP_ENCRYPTION_ALWAYS && !http->tls) || in httpEncryption()
551 (http->encryption == HTTP_ENCRYPTION_NEVER && http->tls)) in httpEncryption()
552 return (httpReconnect2(http, 30000, NULL)); in httpEncryption()
553 else if (http->encryption == HTTP_ENCRYPTION_REQUIRED && !http->tls) in httpEncryption()
554 return (http_tls_upgrade(http)); in httpEncryption()
560 if (e == HTTP_ENCRYPTION_NEVER && http->tls) in httpEncryption()
563 http->encryption = e; in httpEncryption()
564 if (e != HTTP_ENCRYPTION_IF_REQUESTED && !http->tls) in httpEncryption()
565 return (_httpTLSStart(http)); in httpEncryption()
583 httpError(http_t *http) /* I - HTTP connection */ in httpError() argument
585 if (http) in httpError()
586 return (http->error); in httpError()
616 httpFlush(http_t *http) /* I - HTTP connection */ in httpFlush() argument
623 DEBUG_printf(("httpFlush(http=%p), state=%s", (void *)http, httpStateString(http->state))); in httpFlush()
629 if (http->state == HTTP_STATE_WAITING) in httpFlush()
636 blocking = http->blocking; in httpFlush()
637 http->blocking = 0; in httpFlush()
643 oldstate = http->state; in httpFlush()
644 while (httpRead2(http, buffer, sizeof(buffer)) > 0); in httpFlush()
651 http->blocking = blocking; in httpFlush()
653 if (http->state == oldstate && http->state != HTTP_STATE_WAITING && in httpFlush()
654 http->fd >= 0) in httpFlush()
661 if (http->coding) in httpFlush()
662 http_content_coding_finish(http); in httpFlush()
667 http->state = HTTP_STATE_WAITING; in httpFlush()
670 if (http->tls) in httpFlush()
671 _httpTLSStop(http); in httpFlush()
674 httpAddrClose(NULL, http->fd); in httpFlush()
676 http->fd = -1; in httpFlush()
688 httpFlushWrite(http_t *http) /* I - HTTP connection */ in httpFlushWrite() argument
693 …DEBUG_printf(("httpFlushWrite(http=%p) data_encoding=%d", (void *)http, http ? http->data_encoding… in httpFlushWrite()
695 if (!http || !http->wused) in httpFlushWrite()
697 DEBUG_puts(http ? "1httpFlushWrite: Write buffer is empty." : in httpFlushWrite()
702 if (http->data_encoding == HTTP_ENCODING_CHUNKED) in httpFlushWrite()
703 bytes = http_write_chunk(http, http->wbuffer, (size_t)http->wused); in httpFlushWrite()
705 bytes = http_write(http, http->wbuffer, (size_t)http->wused); in httpFlushWrite()
707 http->wused = 0; in httpFlushWrite()
744 httpGet(http_t *http, /* I - HTTP connection */ in httpGet() argument
747 return (http_send(http, HTTP_STATE_GET, uri)); in httpGet()
760 httpGetActivity(http_t *http) /* I - HTTP connection */ in httpGetActivity() argument
762 return (http ? http->activity : 0); in httpGetActivity()
778 httpGetAuthString(http_t *http) /* I - HTTP connection */ in httpGetAuthString() argument
780 if (http) in httpGetAuthString()
781 return (http->authstring); in httpGetAuthString()
794 httpGetBlocking(http_t *http) /* I - HTTP connection */ in httpGetBlocking() argument
796 return (http ? http->blocking : 0); in httpGetBlocking()
815 httpGetContentEncoding(http_t *http) /* I - HTTP connection */ in httpGetContentEncoding() argument
818 if (http && http->accept_encoding) in httpGetContentEncoding()
834 strlcpy(temp, http->accept_encoding, sizeof(temp)); in httpGetContentEncoding()
895 httpGetCookie(http_t *http) /* I - HTTP connection */ in httpGetCookie() argument
897 return (http ? http->cookie : NULL); in httpGetCookie()
912 httpGetEncryption(http_t *http) /* I - HTTP connection */ in httpGetEncryption() argument
914 return (http ? http->encryption : HTTP_ENCRYPTION_IF_REQUESTED); in httpGetEncryption()
928 httpGetExpect(http_t *http) /* I - HTTP connection */ in httpGetExpect() argument
930 if (!http) in httpGetExpect()
933 return (http->expect); in httpGetExpect()
944 httpGetFd(http_t *http) /* I - HTTP connection */ in httpGetFd() argument
946 return (http ? http->fd : -1); in httpGetFd()
955 httpGetField(http_t *http, /* I - HTTP connection */ in httpGetField() argument
958 if (!http || field <= HTTP_FIELD_UNKNOWN || field >= HTTP_FIELD_MAX) in httpGetField()
964 return (http->accept_encoding); in httpGetField()
967 return (http->allow); in httpGetField()
970 return (http->server); in httpGetField()
973 if (http->field_authorization) in httpGetField()
980 return (http->field_authorization); in httpGetField()
984 return (http->fields[field]); in httpGetField()
996 httpGetKeepAlive(http_t *http) /* I - HTTP connection */ in httpGetKeepAlive() argument
998 return (http ? http->keep_alive : HTTP_KEEPALIVE_OFF); in httpGetKeepAlive()
1013 httpGetLength(http_t *http) /* I - HTTP connection */ in httpGetLength() argument
1019 if (http) in httpGetLength()
1021 httpGetLength2(http); in httpGetLength()
1023 return (http->_data_remaining); in httpGetLength()
1041 httpGetLength2(http_t *http) /* I - HTTP connection */ in httpGetLength2() argument
1046 DEBUG_printf(("2httpGetLength2(http=%p), state=%s", (void *)http, httpStateString(http->state))); in httpGetLength2()
1048 if (!http) in httpGetLength2()
1051 if (!_cups_strcasecmp(http->fields[HTTP_FIELD_TRANSFER_ENCODING], "chunked")) in httpGetLength2()
1066 if (!http->fields[HTTP_FIELD_CONTENT_LENGTH][0]) in httpGetLength2()
1073 if (http->status >= HTTP_STATUS_MULTIPLE_CHOICES || in httpGetLength2()
1074 http->state == HTTP_STATE_OPTIONS || in httpGetLength2()
1075 (http->state == HTTP_STATE_GET && http->mode == _HTTP_MODE_SERVER) || in httpGetLength2()
1076 http->state == HTTP_STATE_HEAD || in httpGetLength2()
1077 (http->state == HTTP_STATE_PUT && http->mode == _HTTP_MODE_CLIENT) || in httpGetLength2()
1078 http->state == HTTP_STATE_DELETE || in httpGetLength2()
1079 http->state == HTTP_STATE_TRACE || in httpGetLength2()
1080 http->state == HTTP_STATE_CONNECT) in httpGetLength2()
1085 else if ((remaining = strtoll(http->fields[HTTP_FIELD_CONTENT_LENGTH], in httpGetLength2()
1104 httpGetPending(http_t *http) /* I - HTTP connection */ in httpGetPending() argument
1106 return (http ? (size_t)http->wused : 0); in httpGetPending()
1117 httpGetReady(http_t *http) /* I - HTTP connection */ in httpGetReady() argument
1119 if (!http) in httpGetReady()
1121 else if (http->used > 0) in httpGetReady()
1122 return ((size_t)http->used); in httpGetReady()
1124 else if (http->tls) in httpGetReady()
1125 return (_httpTLSPending(http)); in httpGetReady()
1143 httpGetRemaining(http_t *http) /* I - HTTP connection */ in httpGetRemaining() argument
1145 return (http ? (size_t)http->data_remaining : 0); in httpGetRemaining()
1156 http_t *http) /* I - HTTP connection */ in httpGets() argument
1166 DEBUG_printf(("2httpGets(line=%p, length=%d, http=%p)", (void *)line, length, (void *)http)); in httpGets()
1168 if (!http || !line || length <= 1) in httpGets()
1175 http->error = 0; in httpGets()
1192 while (http->used == 0) in httpGets()
1198 while (!_httpWait(http, http->wait_value, 1)) in httpGets()
1200 if (http->timeout_cb && (*http->timeout_cb)(http, http->timeout_data)) in httpGets()
1205 http->error = WSAETIMEDOUT; in httpGets()
1207 http->error = ETIMEDOUT; in httpGets()
1212 bytes = http_read(http, http->buffer + http->used, (size_t)(HTTP_MAX_BUFFER - http->used)); in httpGets()
1229 if (http->timeout_cb && (*http->timeout_cb)(http, http->timeout_data)) in httpGets()
1232 http->error = WSAGetLastError(); in httpGets()
1234 else if (WSAGetLastError() != http->error) in httpGets()
1236 http->error = WSAGetLastError(); in httpGets()
1247 if (http->timeout_cb && (*http->timeout_cb)(http, http->timeout_data)) in httpGets()
1249 else if (!http->timeout_cb && errno == EAGAIN) in httpGets()
1252 http->error = errno; in httpGets()
1254 else if (errno != http->error) in httpGets()
1256 http->error = errno; in httpGets()
1265 http->error = EPIPE; in httpGets()
1274 http->used += (int)bytes; in httpGets()
1281 for (bufptr = http->buffer, bufend = http->buffer + http->used; in httpGets()
1296 http->used -= (int)(bufptr - http->buffer); in httpGets()
1297 if (http->used > 0) in httpGets()
1298 memmove(http->buffer, bufptr, (size_t)http->used); in httpGets()
1306 http->activity = time(NULL); in httpGets()
1327 httpGetState(http_t *http) /* I - HTTP connection */ in httpGetState() argument
1329 return (http ? http->state : HTTP_STATE_ERROR); in httpGetState()
1340 httpGetStatus(http_t *http) /* I - HTTP connection */ in httpGetStatus() argument
1342 return (http ? http->status : HTTP_STATUS_ERROR); in httpGetStatus()
1353 httpGetSubField(http_t *http, /* I - HTTP connection */ in httpGetSubField() argument
1358 return (httpGetSubField2(http, field, name, value, HTTP_MAX_VALUE)); in httpGetSubField()
1369 httpGetSubField2(http_t *http, /* I - HTTP connection */ in httpGetSubField2() argument
1380 …ubField2(http=%p, field=%d, name=\"%s\", value=%p, valuelen=%d)", (void *)http, field, name, (void… in httpGetSubField2()
1382 if (!http || !name || !value || valuelen < 2 || in httpGetSubField2()
1388 for (fptr = http->fields[field]; *fptr;) in httpGetSubField2()
1498 httpGetVersion(http_t *http) /* I - HTTP connection */ in httpGetVersion() argument
1500 return (http ? http->version : HTTP_VERSION_1_0); in httpGetVersion()
1509 httpHead(http_t *http, /* I - HTTP connection */ in httpHead() argument
1512 DEBUG_printf(("httpHead(http=%p, uri=\"%s\")", (void *)http, uri)); in httpHead()
1513 return (http_send(http, HTTP_STATE_HEAD, uri)); in httpHead()
1581 httpIsChunked(http_t *http) /* I - HTTP connection */ in httpIsChunked() argument
1583 return (http ? http->data_encoding == HTTP_ENCODING_CHUNKED : 0); in httpIsChunked()
1596 httpIsEncrypted(http_t *http) /* I - HTTP connection */ in httpIsEncrypted() argument
1598 return (http ? http->tls != NULL : 0); in httpIsEncrypted()
1607 httpOptions(http_t *http, /* I - HTTP connection */ in httpOptions() argument
1610 return (http_send(http, HTTP_STATE_OPTIONS, uri)); in httpOptions()
1627 httpPeek(http_t *http, /* I - HTTP connection */ in httpPeek() argument
1635 …DEBUG_printf(("httpPeek(http=%p, buffer=%p, length=" CUPS_LLFMT ")", (void *)http, (void *)buffer,… in httpPeek()
1637 if (http == NULL || buffer == NULL) in httpPeek()
1640 http->activity = time(NULL); in httpPeek()
1641 http->error = 0; in httpPeek()
1646 if (http->data_encoding == HTTP_ENCODING_CHUNKED && in httpPeek()
1647 http->data_remaining <= 0) in httpPeek()
1651 if (httpGets(len, sizeof(len), http) == NULL) in httpPeek()
1660 if (!httpGets(len, sizeof(len), http)) in httpPeek()
1667 http->data_remaining = strtoll(len, NULL, 16); in httpPeek()
1669 if (http->data_remaining < 0) in httpPeek()
1677 CUPS_LLCAST http->data_remaining)); in httpPeek()
1679 if (http->data_remaining <= 0 && http->data_encoding != HTTP_ENCODING_FIELDS) in httpPeek()
1687 if (http->coding >= _HTTP_CODING_GUNZIP) in httpPeek()
1688 http_content_coding_finish(http); in httpPeek()
1691 if (http->data_encoding == HTTP_ENCODING_CHUNKED) in httpPeek()
1692 httpGets(len, sizeof(len), http); in httpPeek()
1694 if (http->state == HTTP_STATE_POST_RECV) in httpPeek()
1695 http->state ++; in httpPeek()
1697 http->state = HTTP_STATE_STATUS; in httpPeek()
1700 httpStateString(http->state))); in httpPeek()
1706 http->data_encoding = HTTP_ENCODING_FIELDS; in httpPeek()
1710 else if (length > (size_t)http->data_remaining) in httpPeek()
1711 length = (size_t)http->data_remaining; in httpPeek()
1714 if (http->used == 0 && in httpPeek()
1715 (http->coding == _HTTP_CODING_IDENTITY || in httpPeek()
1716 (http->coding >= _HTTP_CODING_GUNZIP && http->stream.avail_in == 0))) in httpPeek()
1718 if (http->used == 0) in httpPeek()
1727 if (!http->blocking) in httpPeek()
1729 while (!httpWait(http, http->wait_value)) in httpPeek()
1731 if (http->timeout_cb && (*http->timeout_cb)(http, http->timeout_data)) in httpPeek()
1738 if ((size_t)http->data_remaining > sizeof(http->buffer)) in httpPeek()
1739 buflen = sizeof(http->buffer); in httpPeek()
1741 buflen = (ssize_t)http->data_remaining; in httpPeek()
1744 bytes = http_read(http, http->buffer, (size_t)buflen); in httpPeek()
1751 http_debug_hex("httpPeek", http->buffer, (int)bytes); in httpPeek()
1754 http->used = (int)bytes; in httpPeek()
1759 if (http->coding >= _HTTP_CODING_GUNZIP) in httpPeek()
1765 if (http->used > 0 && http->stream.avail_in < HTTP_MAX_BUFFER) in httpPeek()
1767 size_t buflen = buflen = HTTP_MAX_BUFFER - http->stream.avail_in; in httpPeek()
1770 if (http->stream.avail_in > 0 && in httpPeek()
1771 http->stream.next_in > http->sbuffer) in httpPeek()
1772 memmove(http->sbuffer, http->stream.next_in, http->stream.avail_in); in httpPeek()
1774 http->stream.next_in = http->sbuffer; in httpPeek()
1776 if (buflen > (size_t)http->data_remaining) in httpPeek()
1777 buflen = (size_t)http->data_remaining; in httpPeek()
1779 if (buflen > (size_t)http->used) in httpPeek()
1780 buflen = (size_t)http->used; in httpPeek()
1785 memcpy(http->sbuffer + http->stream.avail_in, http->buffer, buflen); in httpPeek()
1786 http->stream.avail_in += buflen; in httpPeek()
1787 http->used -= (int)buflen; in httpPeek()
1788 http->data_remaining -= (off_t)buflen; in httpPeek()
1790 if (http->used > 0) in httpPeek()
1791 memmove(http->buffer, http->buffer + buflen, (size_t)http->used); in httpPeek()
1795 (int)http->stream.avail_in)); in httpPeek()
1797 if (inflateCopy(&stream, &(http->stream)) != Z_OK) in httpPeek()
1800 http->error = ENOMEM; in httpPeek()
1814 http_debug_hex("2httpPeek", (char *)http->sbuffer, (int)http->stream.avail_in); in httpPeek()
1817 http->error = EIO; in httpPeek()
1821 bytes = (ssize_t)(length - http->stream.avail_out); in httpPeek()
1831 if (http->used > 0) in httpPeek()
1833 if (length > (size_t)http->used) in httpPeek()
1834 length = (size_t)http->used; in httpPeek()
1841 memcpy(buffer, http->buffer, length); in httpPeek()
1852 http->error = WSAGetLastError(); in httpPeek()
1857 http->error = errno; in httpPeek()
1862 http->error = EPIPE; in httpPeek()
1875 httpPost(http_t *http, /* I - HTTP connection */ in httpPost() argument
1878 return (http_send(http, HTTP_STATE_POST, uri)); in httpPost()
1889 httpPrintf(http_t *http, /* I - HTTP connection */ in httpPrintf() argument
1898 DEBUG_printf(("2httpPrintf(http=%p, format=\"%s\", ...)", (void *)http, format)); in httpPrintf()
1906 if (http->data_encoding == HTTP_ENCODING_FIELDS) in httpPrintf()
1907 return ((int)httpWrite2(http, buf, (size_t)bytes)); in httpPrintf()
1910 if (http->wused) in httpPrintf()
1914 if (httpFlushWrite(http) < 0) in httpPrintf()
1918 return ((int)http_write(http, buf, (size_t)bytes)); in httpPrintf()
1928 httpPut(http_t *http, /* I - HTTP connection */ in httpPut() argument
1931 DEBUG_printf(("httpPut(http=%p, uri=\"%s\")", (void *)http, uri)); in httpPut()
1932 return (http_send(http, HTTP_STATE_PUT, uri)); in httpPut()
1946 httpRead(http_t *http, /* I - HTTP connection */ in httpRead() argument
1950 return ((int)httpRead2(http, buffer, (size_t)length)); in httpRead()
1961 httpRead2(http_t *http, /* I - HTTP connection */ in httpRead2() argument
1969 …maining=" CUPS_LLFMT, (void *)http, (void *)buffer, CUPS_LLCAST length, http->coding, http->data_e… in httpRead2()
1971 …data_remaining=" CUPS_LLFMT, (void *)http, (void *)buffer, CUPS_LLCAST length, http->data_encoding… in httpRead2()
1974 if (http == NULL || buffer == NULL) in httpRead2()
1977 http->activity = time(NULL); in httpRead2()
1978 http->error = 0; in httpRead2()
1984 if (http->coding >= _HTTP_CODING_GUNZIP) in httpRead2()
1988 if (http->stream.avail_in > 0) in httpRead2()
1993 (int)http->stream.avail_in, (int)length)); in httpRead2()
1995 http->stream.next_out = (Bytef *)buffer; in httpRead2()
1996 http->stream.avail_out = (uInt)length; in httpRead2()
1998 if ((zerr = inflate(&(http->stream), Z_SYNC_FLUSH)) < Z_OK) in httpRead2()
2002 http_debug_hex("2httpRead2", (char *)http->sbuffer, (int)http->stream.avail_in); in httpRead2()
2005 http->error = EIO; in httpRead2()
2009 bytes = (ssize_t)(length - http->stream.avail_out); in httpRead2()
2012 http->stream.avail_in, http->stream.avail_out, in httpRead2()
2020 ssize_t buflen = HTTP_MAX_BUFFER - (ssize_t)http->stream.avail_in; in httpRead2()
2025 if (http->stream.avail_in > 0 && in httpRead2()
2026 http->stream.next_in > http->sbuffer) in httpRead2()
2027 memmove(http->sbuffer, http->stream.next_in, http->stream.avail_in); in httpRead2()
2029 http->stream.next_in = http->sbuffer; in httpRead2()
2034 if (http->data_remaining > 0) in httpRead2()
2036 if (buflen > http->data_remaining) in httpRead2()
2037 buflen = (ssize_t)http->data_remaining; in httpRead2()
2039 … bytes = http_read_buffered(http, (char *)http->sbuffer + http->stream.avail_in, (size_t)buflen); in httpRead2()
2041 else if (http->data_encoding == HTTP_ENCODING_CHUNKED) in httpRead2()
2042 … bytes = http_read_chunk(http, (char *)http->sbuffer + http->stream.avail_in, (size_t)buflen); in httpRead2()
2054 http->data_remaining -= bytes; in httpRead2()
2055 http->stream.avail_in += (uInt)bytes; in httpRead2()
2057 if (http->data_remaining <= 0 && in httpRead2()
2058 http->data_encoding == HTTP_ENCODING_CHUNKED) in httpRead2()
2066 httpGets(len, sizeof(len), http); in httpRead2()
2079 if (http->data_remaining == 0 && http->data_encoding == HTTP_ENCODING_CHUNKED) in httpRead2()
2081 if ((bytes = http_read_chunk(http, buffer, length)) > 0) in httpRead2()
2083 http->data_remaining -= bytes; in httpRead2()
2085 if (http->data_remaining <= 0) in httpRead2()
2093 httpGets(len, sizeof(len), http); in httpRead2()
2097 else if (http->data_remaining <= 0) in httpRead2()
2110 if (length > (size_t)http->data_remaining) in httpRead2()
2111 length = (size_t)http->data_remaining; in httpRead2()
2113 if ((bytes = http_read_buffered(http, buffer, length)) > 0) in httpRead2()
2115 http->data_remaining -= bytes; in httpRead2()
2117 if (http->data_remaining <= 0 && in httpRead2()
2118 http->data_encoding == HTTP_ENCODING_CHUNKED) in httpRead2()
2126 httpGets(len, sizeof(len), http); in httpRead2()
2133 (http->coding == _HTTP_CODING_IDENTITY || in httpRead2()
2134 (http->coding >= _HTTP_CODING_GUNZIP && http->stream.avail_in == 0)) && in httpRead2()
2136 ((http->data_remaining <= 0 && in httpRead2()
2137 http->data_encoding == HTTP_ENCODING_LENGTH) || in httpRead2()
2138 (http->data_encoding == HTTP_ENCODING_CHUNKED && bytes == 0))) in httpRead2()
2141 if (http->coding >= _HTTP_CODING_GUNZIP) in httpRead2()
2142 http_content_coding_finish(http); in httpRead2()
2145 if (http->state == HTTP_STATE_POST_RECV) in httpRead2()
2146 http->state ++; in httpRead2()
2147 else if (http->state == HTTP_STATE_GET_SEND || in httpRead2()
2148 http->state == HTTP_STATE_POST_SEND) in httpRead2()
2149 http->state = HTTP_STATE_WAITING; in httpRead2()
2151 http->state = HTTP_STATE_STATUS; in httpRead2()
2154 httpStateString(http->state))); in httpRead2()
2168 httpReadRequest(http_t *http, /* I - HTTP connection */ in httpReadRequest() argument
2182 …DEBUG_printf(("httpReadRequest(http=%p, uri=%p, urilen=" CUPS_LLFMT ")", (void *)http, (void *)uri… in httpReadRequest()
2187 if (!http || !uri || urilen < 1) in httpReadRequest()
2192 else if (http->state != HTTP_STATE_WAITING) in httpReadRequest()
2195 httpStateString(http->state))); in httpReadRequest()
2203 httpClearFields(http); in httpReadRequest()
2205 http->activity = time(NULL); in httpReadRequest()
2206 http->data_encoding = HTTP_ENCODING_FIELDS; in httpReadRequest()
2207 http->data_remaining = 0; in httpReadRequest()
2208 http->keep_alive = HTTP_KEEPALIVE_OFF; in httpReadRequest()
2209 http->status = HTTP_STATUS_OK; in httpReadRequest()
2210 http->version = HTTP_VERSION_1_1; in httpReadRequest()
2216 if (!httpGets(line, sizeof(line), http)) in httpReadRequest()
2274 http->state = HTTP_STATE_OPTIONS; in httpReadRequest()
2276 http->state = HTTP_STATE_GET; in httpReadRequest()
2278 http->state = HTTP_STATE_HEAD; in httpReadRequest()
2280 http->state = HTTP_STATE_POST; in httpReadRequest()
2282 http->state = HTTP_STATE_PUT; in httpReadRequest()
2284 http->state = HTTP_STATE_DELETE; in httpReadRequest()
2286 http->state = HTTP_STATE_TRACE; in httpReadRequest()
2288 http->state = HTTP_STATE_CONNECT; in httpReadRequest()
2297 httpStateString(http->state))); in httpReadRequest()
2301 http->version = HTTP_VERSION_1_0; in httpReadRequest()
2302 http->keep_alive = HTTP_KEEPALIVE_OFF; in httpReadRequest()
2306 http->version = HTTP_VERSION_1_1; in httpReadRequest()
2307 http->keep_alive = HTTP_KEEPALIVE_ON; in httpReadRequest()
2319 return (http->state); in httpReadRequest()
2333 httpReconnect(http_t *http) /* I - HTTP connection */ in httpReconnect() argument
2335 DEBUG_printf(("httpReconnect(http=%p)", (void *)http)); in httpReconnect()
2337 return (httpReconnect2(http, 30000, NULL)); in httpReconnect()
2347 httpReconnect2(http_t *http, /* I - HTTP connection */ in httpReconnect2() argument
2358 DEBUG_printf(("httpReconnect2(http=%p, msec=%d, cancel=%p)", (void *)http, msec, (void *)cancel)); in httpReconnect2()
2360 if (!http) in httpReconnect2()
2367 if (http->tls) in httpReconnect2()
2370 _httpTLSStop(http); in httpReconnect2()
2378 if (http->fd >= 0) in httpReconnect2()
2380 DEBUG_printf(("2httpReconnect2: Closing socket %d...", http->fd)); in httpReconnect2()
2382 httpAddrClose(NULL, http->fd); in httpReconnect2()
2384 http->fd = -1; in httpReconnect2()
2391 http->state = HTTP_STATE_WAITING; in httpReconnect2()
2392 http->version = HTTP_VERSION_1_1; in httpReconnect2()
2393 http->keep_alive = HTTP_KEEPALIVE_OFF; in httpReconnect2()
2394 memset(&http->_hostaddr, 0, sizeof(http->_hostaddr)); in httpReconnect2()
2395 http->data_encoding = HTTP_ENCODING_FIELDS; in httpReconnect2()
2396 http->_data_remaining = 0; in httpReconnect2()
2397 http->used = 0; in httpReconnect2()
2398 http->data_remaining = 0; in httpReconnect2()
2399 http->hostaddr = NULL; in httpReconnect2()
2400 http->wused = 0; in httpReconnect2()
2407 for (current = http->addrlist; current; current = current->next) in httpReconnect2()
2413 if ((addr = httpAddrConnect2(http->addrlist, &(http->fd), msec, cancel)) == NULL) in httpReconnect2()
2420 http->error = WSAGetLastError(); in httpReconnect2()
2422 http->error = errno; in httpReconnect2()
2424 http->status = HTTP_STATUS_ERROR; in httpReconnect2()
2427 strerror(http->error))); in httpReconnect2()
2432 DEBUG_printf(("2httpReconnect2: New socket=%d", http->fd)); in httpReconnect2()
2434 if (http->timeout_value > 0) in httpReconnect2()
2435 http_set_timeout(http->fd, http->timeout_value); in httpReconnect2()
2437 http->hostaddr = &(addr->addr); in httpReconnect2()
2438 http->error = 0; in httpReconnect2()
2441 if (http->encryption == HTTP_ENCRYPTION_ALWAYS) in httpReconnect2()
2447 if (_httpTLSStart(http) != 0) in httpReconnect2()
2449 httpAddrClose(NULL, http->fd); in httpReconnect2()
2454 else if (http->encryption == HTTP_ENCRYPTION_REQUIRED && !http->tls_upgrade) in httpReconnect2()
2455 return (http_tls_upgrade(http)); in httpReconnect2()
2459 httpAddrString(http->hostaddr, temp, sizeof(temp)), in httpReconnect2()
2460 httpAddrPort(http->hostaddr))); in httpReconnect2()
2478 httpSetAuthString(http_t *http, /* I - HTTP connection */ in httpSetAuthString() argument
2486 if (!http) in httpSetAuthString()
2489 if (http->authstring && http->authstring != http->_authstring) in httpSetAuthString()
2490 free(http->authstring); in httpSetAuthString()
2492 http->authstring = http->_authstring; in httpSetAuthString()
2503 if (len > sizeof(http->_authstring)) in httpSetAuthString()
2506 len = sizeof(http->_authstring); in httpSetAuthString()
2508 http->authstring = temp; in httpSetAuthString()
2512 snprintf(http->authstring, len, "%s %s", scheme, data); in httpSetAuthString()
2514 strlcpy(http->authstring, scheme, len); in httpSetAuthString()
2522 http->_authstring[0] = '\0'; in httpSetAuthString()
2535 httpSetCredentials(http_t *http, /* I - HTTP connection */ in httpSetCredentials() argument
2538 if (!http || cupsArrayCount(credentials) < 1) in httpSetCredentials()
2542 _httpFreeCredentials(http->tls_credentials); in httpSetCredentials()
2544 http->tls_credentials = _httpCreateCredentials(credentials); in httpSetCredentials()
2547 return (http->tls_credentials ? 0 : -1); in httpSetCredentials()
2558 httpSetCookie(http_t *http, /* I - Connection */ in httpSetCookie() argument
2561 if (!http) in httpSetCookie()
2564 if (http->cookie) in httpSetCookie()
2565 free(http->cookie); in httpSetCookie()
2568 http->cookie = strdup(cookie); in httpSetCookie()
2570 http->cookie = NULL; in httpSetCookie()
2584 httpSetDefaultField(http_t *http, /* I - HTTP connection */ in httpSetDefaultField() argument
2588 …DEBUG_printf(("httpSetDefaultField(http=%p, field=%d(%s), value=\"%s\")", (void *)http, field, htt… in httpSetDefaultField()
2590 if (!http) in httpSetDefaultField()
2596 if (http->default_accept_encoding) in httpSetDefaultField()
2597 _cupsStrFree(http->default_accept_encoding); in httpSetDefaultField()
2599 http->default_accept_encoding = value ? _cupsStrAlloc(value) : NULL; in httpSetDefaultField()
2603 if (http->default_server) in httpSetDefaultField()
2604 _cupsStrFree(http->default_server); in httpSetDefaultField()
2606 http->default_server = value ? _cupsStrAlloc(value) : NULL; in httpSetDefaultField()
2610 if (http->default_user_agent) in httpSetDefaultField()
2611 _cupsStrFree(http->default_user_agent); in httpSetDefaultField()
2613 http->default_user_agent = value ? _cupsStrAlloc(value) : NULL; in httpSetDefaultField()
2633 httpSetExpect(http_t *http, /* I - HTTP connection */ in httpSetExpect() argument
2637 DEBUG_printf(("httpSetExpect(http=%p, expect=%d)", (void *)http, expect)); in httpSetExpect()
2639 if (http) in httpSetExpect()
2640 http->expect = expect; in httpSetExpect()
2649 httpSetField(http_t *http, /* I - HTTP connection */ in httpSetField() argument
2653 …DEBUG_printf(("httpSetField(http=%p, field=%d(%s), value=\"%s\")", (void *)http, field, http_field… in httpSetField()
2655 if (http == NULL || in httpSetField()
2664 if (http->accept_encoding) in httpSetField()
2665 _cupsStrFree(http->accept_encoding); in httpSetField()
2667 http->accept_encoding = _cupsStrAlloc(value); in httpSetField()
2671 if (http->allow) in httpSetField()
2672 _cupsStrFree(http->allow); in httpSetField()
2674 http->allow = _cupsStrAlloc(value); in httpSetField()
2678 if (http->server) in httpSetField()
2679 _cupsStrFree(http->server); in httpSetField()
2681 http->server = _cupsStrAlloc(value); in httpSetField()
2686 if (http->fields[HTTP_FIELD_WWW_AUTHENTICATE][0] && in httpSetField()
2698 strlcpy(http->fields[field], value, HTTP_MAX_VALUE); in httpSetField()
2709 if (http->field_authorization) in httpSetField()
2710 free(http->field_authorization); in httpSetField()
2712 http->field_authorization = strdup(value); in httpSetField()
2732 snprintf(http->fields[HTTP_FIELD_HOST], in httpSetField()
2733 sizeof(http->fields[HTTP_FIELD_HOST]), "[%s]", value); in httpSetField()
2741 ptr = http->fields[HTTP_FIELD_HOST]; in httpSetField()
2754 http->data_encoding != HTTP_ENCODING_FIELDS) in httpSetField()
2757 http_content_coding_start(http, value); in httpSetField()
2771 http_t *http, /* I - HTTP connection */ in httpSetKeepAlive() argument
2774 if (http) in httpSetKeepAlive()
2775 http->keep_alive = keep_alive; in httpSetKeepAlive()
2786 httpSetLength(http_t *http, /* I - HTTP connection */ in httpSetLength() argument
2789 DEBUG_printf(("httpSetLength(http=%p, length=" CUPS_LLFMT ")", (void *)http, CUPS_LLCAST length)); in httpSetLength()
2791 if (!http) in httpSetLength()
2796 strlcpy(http->fields[HTTP_FIELD_TRANSFER_ENCODING], "chunked", in httpSetLength()
2798 http->fields[HTTP_FIELD_CONTENT_LENGTH][0] = '\0'; in httpSetLength()
2802 http->fields[HTTP_FIELD_TRANSFER_ENCODING][0] = '\0'; in httpSetLength()
2803 snprintf(http->fields[HTTP_FIELD_CONTENT_LENGTH], HTTP_MAX_VALUE, in httpSetLength()
2820 http_t *http, /* I - HTTP connection */ in httpSetTimeout() argument
2826 if (!http || timeout <= 0.0) in httpSetTimeout()
2829 http->timeout_cb = cb; in httpSetTimeout()
2830 http->timeout_data = user_data; in httpSetTimeout()
2831 http->timeout_value = timeout; in httpSetTimeout()
2833 if (http->fd >= 0) in httpSetTimeout()
2834 http_set_timeout(http->fd, timeout); in httpSetTimeout()
2836 http_set_wait(http); in httpSetTimeout()
2847 httpShutdown(http_t *http) /* I - HTTP connection */ in httpShutdown() argument
2849 if (!http || http->fd < 0) in httpShutdown()
2853 if (http->tls) in httpShutdown()
2854 _httpTLSStop(http); in httpShutdown()
2858 shutdown(http->fd, SD_RECEIVE); /* Microsoft-ism... */ in httpShutdown()
2860 shutdown(http->fd, SHUT_RD); in httpShutdown()
2870 httpTrace(http_t *http, /* I - HTTP connection */ in httpTrace() argument
2873 return (http_send(http, HTTP_STATE_TRACE, uri)); in httpTrace()
2885 _httpUpdate(http_t *http, /* I - HTTP connection */ in _httpUpdate() argument
2894 …(("_httpUpdate(http=%p, status=%p), state=%s", (void *)http, (void *)status, httpStateString(http-… in _httpUpdate()
2900 if (!httpGets(line, sizeof(line), http)) in _httpUpdate()
2919 if (http->status == HTTP_STATUS_CONTINUE) in _httpUpdate()
2921 *status = http->status; in _httpUpdate()
2925 if (http->status < HTTP_STATUS_BAD_REQUEST) in _httpUpdate()
2926 http->digest_tries = 0; in _httpUpdate()
2929 if (http->status == HTTP_STATUS_SWITCHING_PROTOCOLS && !http->tls) in _httpUpdate()
2931 if (_httpTLSStart(http) != 0) in _httpUpdate()
2933 httpAddrClose(NULL, http->fd); in _httpUpdate()
2935 *status = http->status = HTTP_STATUS_ERROR; in _httpUpdate()
2944 if (http_set_length(http) < 0) in _httpUpdate()
2947 http->error = EINVAL; in _httpUpdate()
2948 http->status = *status = HTTP_STATUS_ERROR; in _httpUpdate()
2952 switch (http->state) in _httpUpdate()
2958 http->state ++; in _httpUpdate()
2961 httpStateString(http->state))); in _httpUpdate()
2968 http->state = HTTP_STATE_WAITING; in _httpUpdate()
2976 http_content_coding_start(http, in _httpUpdate()
2977 httpGetField(http, HTTP_FIELD_CONTENT_ENCODING)); in _httpUpdate()
2980 *status = http->status; in _httpUpdate()
2983 else if (!strncmp(line, "HTTP/", 5) && http->mode == _HTTP_MODE_CLIENT) in _httpUpdate()
2993 *status = http->status = HTTP_STATUS_ERROR; in _httpUpdate()
2997 httpClearFields(http); in _httpUpdate()
2999 http->version = (http_version_t)(major * 100 + minor); in _httpUpdate()
3000 *status = http->status = (http_status_t)intstatus; in _httpUpdate()
3024 http->expect = (http_status_t)atoi(value); in _httpUpdate()
3032 httpSetCookie(http, value); in _httpUpdate()
3035 httpSetField(http, field, value); in _httpUpdate()
3044 http->error = EINVAL; in _httpUpdate()
3045 http->status = *status = HTTP_STATUS_ERROR; in _httpUpdate()
3058 httpUpdate(http_t *http) /* I - HTTP connection */ in httpUpdate() argument
3063 DEBUG_printf(("httpUpdate(http=%p), state=%s", (void *)http, httpStateString(http->state))); in httpUpdate()
3069 if (http->wused) in httpUpdate()
3073 if (httpFlushWrite(http) < 0) in httpUpdate()
3081 if (http->state == HTTP_STATE_WAITING) in httpUpdate()
3088 while (_httpUpdate(http, &status)); in httpUpdate()
3094 if (http->error == EPIPE && http->status > HTTP_STATUS_CONTINUE) in httpUpdate()
3096 DEBUG_printf(("1httpUpdate: Returning status %d...", http->status)); in httpUpdate()
3097 return (http->status); in httpUpdate()
3100 if (http->error) in httpUpdate()
3102 DEBUG_printf(("1httpUpdate: socket error %d - %s", http->error, in httpUpdate()
3103 strerror(http->error))); in httpUpdate()
3104 http->status = HTTP_STATUS_ERROR; in httpUpdate()
3121 _httpWait(http_t *http, /* I - HTTP connection */ in _httpWait() argument
3134 DEBUG_printf(("4_httpWait(http=%p, msec=%d, usessl=%d)", (void *)http, msec, usessl)); in _httpWait()
3136 if (http->fd < 0) in _httpWait()
3138 DEBUG_printf(("5_httpWait: Returning 0 since fd=%d", http->fd)); in _httpWait()
3147 if (http->tls && _httpTLSPending(http)) in _httpWait()
3159 pfd.fd = http->fd; in _httpWait()
3172 FD_SET(http->fd, &input_set); in _httpWait()
3174 DEBUG_printf(("6_httpWait: msec=%d, http->fd=%d", msec, http->fd)); in _httpWait()
3181 nfds = select(http->fd + 1, &input_set, NULL, NULL, &timeout); in _httpWait()
3184 nfds = select(http->fd + 1, &input_set, NULL, NULL, NULL); in _httpWait()
3210 httpWait(http_t *http, /* I - HTTP connection */ in httpWait() argument
3217 DEBUG_printf(("2httpWait(http=%p, msec=%d)", (void *)http, msec)); in httpWait()
3219 if (http == NULL) in httpWait()
3222 if (http->used) in httpWait()
3229 if (http->coding >= _HTTP_CODING_GUNZIP && http->stream.avail_in > 0) in httpWait()
3240 if (http->wused) in httpWait()
3244 if (httpFlushWrite(http) < 0) in httpWait()
3252 return (_httpWait(http, msec, 1)); in httpWait()
3266 httpWrite(http_t *http, /* I - HTTP connection */ in httpWrite() argument
3270 return ((int)httpWrite2(http, buffer, (size_t)length)); in httpWrite()
3281 httpWrite2(http_t *http, /* I - HTTP connection */ in httpWrite2() argument
3288 …DEBUG_printf(("httpWrite2(http=%p, buffer=%p, length=" CUPS_LLFMT ")", (void *)http, (void *)buffe… in httpWrite2()
3294 if (!http || !buffer) in httpWrite2()
3304 http->activity = time(NULL); in httpWrite2()
3311 if (http->coding == _HTTP_CODING_GZIP || http->coding == _HTTP_CODING_DEFLATE) in httpWrite2()
3313 DEBUG_printf(("1httpWrite2: http->coding=%d", http->coding)); in httpWrite2()
3317 http_content_coding_finish(http); in httpWrite2()
3325 http->stream.next_in = (Bytef *)buffer; in httpWrite2()
3326 http->stream.avail_in = (uInt)length; in httpWrite2()
3328 while (deflate(&(http->stream), Z_NO_FLUSH) == Z_OK) in httpWrite2()
3330 DEBUG_printf(("1httpWrite2: avail_out=%d", http->stream.avail_out)); in httpWrite2()
3332 if (http->stream.avail_out > 0) in httpWrite2()
3335 slen = _HTTP_MAX_SBUFFER - http->stream.avail_out; in httpWrite2()
3339 if (slen > 0 && http->data_encoding == HTTP_ENCODING_CHUNKED) in httpWrite2()
3340 sret = http_write_chunk(http, (char *)http->sbuffer, slen); in httpWrite2()
3342 sret = http_write(http, (char *)http->sbuffer, slen); in httpWrite2()
3352 http->stream.next_out = (Bytef *)http->sbuffer; in httpWrite2()
3353 http->stream.avail_out = (uInt)_HTTP_MAX_SBUFFER; in httpWrite2()
3363 if (http->wused && (length + (size_t)http->wused) > sizeof(http->wbuffer)) in httpWrite2()
3366 CUPS_LLFMT ")", http->wused, CUPS_LLCAST length)); in httpWrite2()
3368 httpFlushWrite(http); in httpWrite2()
3371 if ((length + (size_t)http->wused) <= sizeof(http->wbuffer) && length < sizeof(http->wbuffer)) in httpWrite2()
3380 memcpy(http->wbuffer + http->wused, buffer, length); in httpWrite2()
3381 http->wused += (int)length; in httpWrite2()
3393 if (http->data_encoding == HTTP_ENCODING_CHUNKED) in httpWrite2()
3394 bytes = (ssize_t)http_write_chunk(http, buffer, length); in httpWrite2()
3396 bytes = (ssize_t)http_write(http, buffer, length); in httpWrite2()
3402 if (http->data_encoding == HTTP_ENCODING_LENGTH) in httpWrite2()
3403 http->data_remaining -= bytes; in httpWrite2()
3412 if ((http->data_encoding == HTTP_ENCODING_CHUNKED && length == 0) || in httpWrite2()
3413 (http->data_encoding == HTTP_ENCODING_LENGTH && http->data_remaining == 0)) in httpWrite2()
3421 if (http->coding == _HTTP_CODING_GZIP || http->coding == _HTTP_CODING_DEFLATE) in httpWrite2()
3422 http_content_coding_finish(http); in httpWrite2()
3425 if (http->wused) in httpWrite2()
3427 if (httpFlushWrite(http) < 0) in httpWrite2()
3431 if (http->data_encoding == HTTP_ENCODING_CHUNKED) in httpWrite2()
3437 http_write(http, "0\r\n\r\n", 5); in httpWrite2()
3443 http->data_encoding = HTTP_ENCODING_FIELDS; in httpWrite2()
3444 http->data_remaining = 0; in httpWrite2()
3447 if (http->state == HTTP_STATE_POST_RECV) in httpWrite2()
3448 http->state ++; in httpWrite2()
3449 else if (http->state == HTTP_STATE_POST_SEND || in httpWrite2()
3450 http->state == HTTP_STATE_GET_SEND) in httpWrite2()
3451 http->state = HTTP_STATE_WAITING; in httpWrite2()
3453 http->state = HTTP_STATE_STATUS; in httpWrite2()
3456 httpStateString(http->state))); in httpWrite2()
3472 httpWriteResponse(http_t *http, /* I - HTTP connection */ in httpWriteResponse() argument
3483 DEBUG_printf(("httpWriteResponse(http=%p, status=%d)", (void *)http, status)); in httpWriteResponse()
3485 if (!http || status < HTTP_STATUS_CONTINUE) in httpWriteResponse()
3495 if (!http->fields[HTTP_FIELD_DATE][0]) in httpWriteResponse()
3496 httpSetField(http, HTTP_FIELD_DATE, httpGetDateString(time(NULL))); in httpWriteResponse()
3498 if (status >= HTTP_STATUS_BAD_REQUEST && http->keep_alive) in httpWriteResponse()
3500 http->keep_alive = HTTP_KEEPALIVE_OFF; in httpWriteResponse()
3501 httpSetField(http, HTTP_FIELD_KEEP_ALIVE, ""); in httpWriteResponse()
3504 if (http->version == HTTP_VERSION_1_1) in httpWriteResponse()
3506 if (!http->fields[HTTP_FIELD_CONNECTION][0]) in httpWriteResponse()
3508 if (http->keep_alive) in httpWriteResponse()
3509 httpSetField(http, HTTP_FIELD_CONNECTION, "Keep-Alive"); in httpWriteResponse()
3511 httpSetField(http, HTTP_FIELD_CONNECTION, "close"); in httpWriteResponse()
3514 if (http->keep_alive && !http->fields[HTTP_FIELD_KEEP_ALIVE][0]) in httpWriteResponse()
3515 httpSetField(http, HTTP_FIELD_KEEP_ALIVE, "timeout=10"); in httpWriteResponse()
3522 if (!http->fields[HTTP_FIELD_CONNECTION][0]) in httpWriteResponse()
3523 httpSetField(http, HTTP_FIELD_CONNECTION, "Upgrade"); in httpWriteResponse()
3525 if (!http->fields[HTTP_FIELD_UPGRADE][0]) in httpWriteResponse()
3526 httpSetField(http, HTTP_FIELD_UPGRADE, "TLS/1.2,TLS/1.1,TLS/1.0"); in httpWriteResponse()
3528 if (!http->fields[HTTP_FIELD_CONTENT_LENGTH][0]) in httpWriteResponse()
3529 httpSetField(http, HTTP_FIELD_CONTENT_LENGTH, "0"); in httpWriteResponse()
3533 if (!http->server) in httpWriteResponse()
3534 httpSetField(http, HTTP_FIELD_SERVER, in httpWriteResponse()
3535 http->default_server ? http->default_server : CUPS_MINIMAL); in httpWriteResponse()
3541 if (!http->accept_encoding) in httpWriteResponse()
3542 httpSetField(http, HTTP_FIELD_ACCEPT_ENCODING, in httpWriteResponse()
3543 http->default_accept_encoding ? http->default_accept_encoding : in httpWriteResponse()
3554 old_encoding = http->data_encoding; in httpWriteResponse()
3555 old_remaining = http->data_remaining; in httpWriteResponse()
3556 http->data_encoding = HTTP_ENCODING_FIELDS; in httpWriteResponse()
3558 if (httpPrintf(http, "HTTP/%d.%d %d %s\r\n", http->version / 100, in httpWriteResponse()
3559 http->version % 100, (int)status, httpStatus(status)) < 0) in httpWriteResponse()
3561 http->status = HTTP_STATUS_ERROR; in httpWriteResponse()
3576 if ((value = httpGetField(http, i)) != NULL && *value) in httpWriteResponse()
3578 if (httpPrintf(http, "%s: %s\r\n", http_fields[i], value) < 1) in httpWriteResponse()
3580 http->status = HTTP_STATUS_ERROR; in httpWriteResponse()
3586 if (http->cookie) in httpWriteResponse()
3588 if (strchr(http->cookie, ';')) in httpWriteResponse()
3590 if (httpPrintf(http, "Set-Cookie: %s\r\n", http->cookie) < 1) in httpWriteResponse()
3592 http->status = HTTP_STATUS_ERROR; in httpWriteResponse()
3596 …else if (httpPrintf(http, "Set-Cookie: %s; path=/; httponly;%s\r\n", http->cookie, http->tls ? " s… in httpWriteResponse()
3598 http->status = HTTP_STATUS_ERROR; in httpWriteResponse()
3607 if (httpPrintf(http, "X-Frame-Options: DENY\r\n" in httpWriteResponse()
3610 http->status = HTTP_STATUS_ERROR; in httpWriteResponse()
3615 if (httpWrite2(http, "\r\n", 2) < 2) in httpWriteResponse()
3617 http->status = HTTP_STATUS_ERROR; in httpWriteResponse()
3621 if (httpFlushWrite(http) < 0) in httpWriteResponse()
3623 http->status = HTTP_STATUS_ERROR; in httpWriteResponse()
3634 http->data_encoding = old_encoding; in httpWriteResponse()
3635 http->data_remaining = old_remaining; in httpWriteResponse()
3638 http->_data_remaining = (int)old_remaining; in httpWriteResponse()
3640 http->_data_remaining = INT_MAX; in httpWriteResponse()
3642 else if (http->state == HTTP_STATE_OPTIONS || in httpWriteResponse()
3643 http->state == HTTP_STATE_HEAD || in httpWriteResponse()
3644 http->state == HTTP_STATE_PUT || in httpWriteResponse()
3645 http->state == HTTP_STATE_TRACE || in httpWriteResponse()
3646 http->state == HTTP_STATE_CONNECT || in httpWriteResponse()
3647 http->state == HTTP_STATE_STATUS) in httpWriteResponse()
3650 "was %s.", httpStateString(http->state))); in httpWriteResponse()
3651 http->state = HTTP_STATE_WAITING; in httpWriteResponse()
3660 http_set_length(http); in httpWriteResponse()
3662 if (http->data_encoding == HTTP_ENCODING_LENGTH && http->data_remaining == 0) in httpWriteResponse()
3665 "was %s.", httpStateString(http->state))); in httpWriteResponse()
3666 http->state = HTTP_STATE_WAITING; in httpWriteResponse()
3670 if (http->state == HTTP_STATE_POST_RECV || http->state == HTTP_STATE_GET) in httpWriteResponse()
3671 http->state ++; in httpWriteResponse()
3679 http_content_coding_start(http, in httpWriteResponse()
3680 httpGetField(http, HTTP_FIELD_CONTENT_ENCODING)); in httpWriteResponse()
3696 http_t *http) /* I - HTTP connection */ in http_content_coding_finish() argument
3703 DEBUG_printf(("http_content_coding_finish(http=%p)", (void *)http)); in http_content_coding_finish()
3704 DEBUG_printf(("1http_content_coding_finishing: http->coding=%d", http->coding)); in http_content_coding_finish()
3706 switch (http->coding) in http_content_coding_finish()
3710 http->stream.next_in = dummy; in http_content_coding_finish()
3711 http->stream.avail_in = 0; in http_content_coding_finish()
3715 zerr = deflate(&(http->stream), Z_FINISH); in http_content_coding_finish()
3716 bytes = _HTTP_MAX_SBUFFER - http->stream.avail_out; in http_content_coding_finish()
3722 if (http->data_encoding == HTTP_ENCODING_CHUNKED) in http_content_coding_finish()
3723 http_write_chunk(http, (char *)http->sbuffer, bytes); in http_content_coding_finish()
3725 http_write(http, (char *)http->sbuffer, bytes); in http_content_coding_finish()
3728 http->stream.next_out = (Bytef *)http->sbuffer; in http_content_coding_finish()
3729 http->stream.avail_out = (uInt)_HTTP_MAX_SBUFFER; in http_content_coding_finish()
3733 deflateEnd(&(http->stream)); in http_content_coding_finish()
3735 free(http->sbuffer); in http_content_coding_finish()
3736 http->sbuffer = NULL; in http_content_coding_finish()
3738 if (http->wused) in http_content_coding_finish()
3739 httpFlushWrite(http); in http_content_coding_finish()
3744 inflateEnd(&(http->stream)); in http_content_coding_finish()
3745 free(http->sbuffer); in http_content_coding_finish()
3746 http->sbuffer = NULL; in http_content_coding_finish()
3753 http->coding = _HTTP_CODING_IDENTITY; in http_content_coding_finish()
3763 http_t *http, /* I - HTTP connection */ in http_content_coding_start() argument
3770 DEBUG_printf(("http_content_coding_start(http=%p, value=\"%s\")", (void *)http, value)); in http_content_coding_start()
3772 if (http->coding != _HTTP_CODING_IDENTITY) in http_content_coding_start()
3775 http->coding)); in http_content_coding_start()
3780 if (http->state == HTTP_STATE_GET_SEND || in http_content_coding_start()
3781 http->state == HTTP_STATE_POST_SEND) in http_content_coding_start()
3782 coding = http->mode == _HTTP_MODE_SERVER ? _HTTP_CODING_GZIP : in http_content_coding_start()
3784 else if (http->state == HTTP_STATE_POST_RECV || in http_content_coding_start()
3785 http->state == HTTP_STATE_PUT_RECV) in http_content_coding_start()
3786 coding = http->mode == _HTTP_MODE_CLIENT ? _HTTP_CODING_GZIP : in http_content_coding_start()
3796 if (http->state == HTTP_STATE_GET_SEND || in http_content_coding_start()
3797 http->state == HTTP_STATE_POST_SEND) in http_content_coding_start()
3798 coding = http->mode == _HTTP_MODE_SERVER ? _HTTP_CODING_DEFLATE : in http_content_coding_start()
3800 else if (http->state == HTTP_STATE_POST_RECV || in http_content_coding_start()
3801 http->state == HTTP_STATE_PUT_RECV) in http_content_coding_start()
3802 coding = http->mode == _HTTP_MODE_CLIENT ? _HTTP_CODING_DEFLATE : in http_content_coding_start()
3816 memset(&(http->stream), 0, sizeof(http->stream)); in http_content_coding_start()
3822 if (http->wused) in http_content_coding_start()
3823 httpFlushWrite(http); in http_content_coding_start()
3825 if ((http->sbuffer = malloc(_HTTP_MAX_SBUFFER)) == NULL) in http_content_coding_start()
3827 http->status = HTTP_STATUS_ERROR; in http_content_coding_start()
3828 http->error = errno; in http_content_coding_start()
3838 if ((zerr = deflateInit2(&(http->stream), Z_DEFAULT_COMPRESSION, in http_content_coding_start()
3843 http->status = HTTP_STATUS_ERROR; in http_content_coding_start()
3844 http->error = zerr == Z_MEM_ERROR ? ENOMEM : EINVAL; in http_content_coding_start()
3848 http->stream.next_out = (Bytef *)http->sbuffer; in http_content_coding_start()
3849 http->stream.avail_out = (uInt)_HTTP_MAX_SBUFFER; in http_content_coding_start()
3854 if ((http->sbuffer = malloc(_HTTP_MAX_SBUFFER)) == NULL) in http_content_coding_start()
3856 http->status = HTTP_STATUS_ERROR; in http_content_coding_start()
3857 http->error = errno; in http_content_coding_start()
3866 if ((zerr = inflateInit2(&(http->stream), in http_content_coding_start()
3870 free(http->sbuffer); in http_content_coding_start()
3871 http->sbuffer = NULL; in http_content_coding_start()
3872 http->status = HTTP_STATUS_ERROR; in http_content_coding_start()
3873 http->error = zerr == Z_MEM_ERROR ? ENOMEM : EINVAL; in http_content_coding_start()
3877 http->stream.avail_in = 0; in http_content_coding_start()
3878 http->stream.next_in = http->sbuffer; in http_content_coding_start()
3885 http->coding = coding; in http_content_coding_start()
3888 http->coding)); in http_content_coding_start()
3907 http_t *http; /* New HTTP connection */ in http_create() local
3941 if ((http = calloc(sizeof(http_t), 1)) == NULL) in http_create()
3952 http->mode = mode; in http_create()
3953 http->activity = time(NULL); in http_create()
3954 http->addrlist = myaddrlist; in http_create()
3955 http->blocking = blocking; in http_create()
3956 http->fd = -1; in http_create()
3958 http->gssctx = GSS_C_NO_CONTEXT; in http_create()
3959 http->gssname = GSS_C_NO_NAME; in http_create()
3961 http->status = HTTP_STATUS_CONTINUE; in http_create()
3962 http->version = HTTP_VERSION_1_1; in http_create()
3965 strlcpy(http->hostname, host, sizeof(http->hostname)); in http_create()
3968 http->encryption = HTTP_ENCRYPTION_ALWAYS; in http_create()
3970 http->encryption = encryption; in http_create()
3972 http_set_wait(http); in http_create()
3978 return (http); in http_create()
4047 http_read(http_t *http, /* I - HTTP connection */ in http_read() argument
4054 …DEBUG_printf(("http_read(http=%p, buffer=%p, length=" CUPS_LLFMT ")", (void *)http, (void *)buffer… in http_read()
4056 if (!http->blocking) in http_read()
4058 while (!httpWait(http, http->wait_value)) in http_read()
4060 if (http->timeout_cb && (*http->timeout_cb)(http, http->timeout_data)) in http_read()
4073 if (http->tls) in http_read()
4074 bytes = _httpTLSRead(http, buffer, (int)length); in http_read()
4077 bytes = recv(http->fd, buffer, length, 0); in http_read()
4084 http->error = WSAGetLastError(); in http_read()
4089 if (!http->timeout_cb || in http_read()
4090 !(*http->timeout_cb)(http, http->timeout_data)) in http_read()
4092 http->error = WSAEWOULDBLOCK; in http_read()
4101 if (http->timeout_cb && !(*http->timeout_cb)(http, http->timeout_data)) in http_read()
4103 http->error = errno; in http_read()
4106 else if (!http->timeout_cb && errno != EAGAIN) in http_read()
4108 http->error = errno; in http_read()
4114 http->error = errno; in http_read()
4135 http->error = WSAGetLastError(); in http_read()
4137 if (errno == EINTR || (errno == EAGAIN && !http->timeout_cb)) in http_read()
4140 http->error = errno; in http_read()
4145 http->error = EPIPE; in http_read()
4160 http_read_buffered(http_t *http, /* I - HTTP connection */ in http_read_buffered() argument
4167 … buffer=%p, length=" CUPS_LLFMT ") used=%d", (void *)http, (void *)buffer, CUPS_LLCAST length, htt… in http_read_buffered()
4169 if (http->used > 0) in http_read_buffered()
4171 if (length > (size_t)http->used) in http_read_buffered()
4172 bytes = (ssize_t)http->used; in http_read_buffered()
4179 memcpy(buffer, http->buffer, (size_t)bytes); in http_read_buffered()
4180 http->used -= (int)bytes; in http_read_buffered()
4182 if (http->used > 0) in http_read_buffered()
4183 memmove(http->buffer, http->buffer + bytes, (size_t)http->used); in http_read_buffered()
4186 bytes = http_read(http, buffer, length); in http_read_buffered()
4200 http_read_chunk(http_t *http, /* I - HTTP connection */ in http_read_chunk() argument
4204 …DEBUG_printf(("http_read_chunk(http=%p, buffer=%p, length=" CUPS_LLFMT ")", (void *)http, (void *)… in http_read_chunk()
4206 if (http->data_remaining <= 0) in http_read_chunk()
4210 if (!httpGets(len, sizeof(len), http)) in http_read_chunk()
4219 if (!httpGets(len, sizeof(len), http)) in http_read_chunk()
4226 http->data_remaining = strtoll(len, NULL, 16); in http_read_chunk()
4228 if (http->data_remaining < 0) in http_read_chunk()
4231 CUPS_LLFMT ")", len, CUPS_LLCAST http->data_remaining)); in http_read_chunk()
4236 len, CUPS_LLCAST http->data_remaining)); in http_read_chunk()
4238 if (http->data_remaining == 0) in http_read_chunk()
4244 httpGets(len, sizeof(len), http); in http_read_chunk()
4249 CUPS_LLCAST http->data_remaining)); in http_read_chunk()
4251 if (http->data_remaining <= 0) in http_read_chunk()
4253 else if (length > (size_t)http->data_remaining) in http_read_chunk()
4254 length = (size_t)http->data_remaining; in http_read_chunk()
4256 return (http_read_buffered(http, buffer, length)); in http_read_chunk()
4265 http_send(http_t *http, /* I - HTTP connection */ in http_send() argument
4292 …DEBUG_printf(("4http_send(http=%p, request=HTTP_%s, uri=\"%s\")", (void *)http, codes[request], ur… in http_send()
4294 if (http == NULL || uri == NULL) in http_send()
4301 if (!http->fields[HTTP_FIELD_USER_AGENT][0]) in http_send()
4303 if (http->default_user_agent) in http_send()
4304 httpSetField(http, HTTP_FIELD_USER_AGENT, http->default_user_agent); in http_send()
4306 httpSetField(http, HTTP_FIELD_USER_AGENT, cupsUserAgent()); in http_send()
4313 if (!http->accept_encoding && http->default_accept_encoding) in http_send()
4314 httpSetField(http, HTTP_FIELD_ACCEPT_ENCODING, in http_send()
4315 http->default_accept_encoding); in http_send()
4327 if (http->fd < 0 || http->status == HTTP_STATUS_ERROR || in http_send()
4328 http->status >= HTTP_STATUS_BAD_REQUEST) in http_send()
4331 http->fd, http->status, http->tls_upgrade)); in http_send()
4333 if (httpReconnect2(http, 30000, NULL)) in http_send()
4341 if (http->wused) in http_send()
4343 if (httpFlushWrite(http) < 0) in http_send()
4344 if (httpReconnect2(http, 30000, NULL)) in http_send()
4352 http->state = request; in http_send()
4353 http->data_encoding = HTTP_ENCODING_FIELDS; in http_send()
4356 http->state ++; in http_send()
4358 http->status = HTTP_STATUS_CONTINUE; in http_send()
4361 if (http->encryption == HTTP_ENCRYPTION_REQUIRED && !http->tls) in http_send()
4363 httpSetField(http, HTTP_FIELD_CONNECTION, "Upgrade"); in http_send()
4364 httpSetField(http, HTTP_FIELD_UPGRADE, "TLS/1.2,TLS/1.1,TLS/1.0"); in http_send()
4368 if (httpPrintf(http, "%s %s HTTP/1.1\r\n", codes[request], buf) < 1) in http_send()
4370 http->status = HTTP_STATUS_ERROR; in http_send()
4375 if ((value = httpGetField(http, i)) != NULL && *value) in http_send()
4381 if (httpPrintf(http, "Host: %s:%d\r\n", value, in http_send()
4382 httpAddrPort(http->hostaddr)) < 1) in http_send()
4384 http->status = HTTP_STATUS_ERROR; in http_send()
4388 else if (httpPrintf(http, "%s: %s\r\n", http_fields[i], value) < 1) in http_send()
4390 http->status = HTTP_STATUS_ERROR; in http_send()
4395 if (http->cookie) in http_send()
4396 if (httpPrintf(http, "Cookie: $Version=0; %s\r\n", http->cookie) < 1) in http_send()
4398 http->status = HTTP_STATUS_ERROR; in http_send()
4402 DEBUG_printf(("5http_send: expect=%d, mode=%d, state=%d", http->expect, in http_send()
4403 http->mode, http->state)); in http_send()
4405 if (http->expect == HTTP_STATUS_CONTINUE && http->mode == _HTTP_MODE_CLIENT && in http_send()
4406 (http->state == HTTP_STATE_POST_RECV || in http_send()
4407 http->state == HTTP_STATE_PUT_RECV)) in http_send()
4408 if (httpPrintf(http, "Expect: 100-continue\r\n") < 1) in http_send()
4410 http->status = HTTP_STATUS_ERROR; in http_send()
4414 if (httpPrintf(http, "\r\n") < 1) in http_send()
4416 http->status = HTTP_STATUS_ERROR; in http_send()
4420 if (httpFlushWrite(http) < 0) in http_send()
4423 http_set_length(http); in http_send()
4424 httpClearFields(http); in http_send()
4430 if (http->field_authorization && http->authstring && in http_send()
4431 (!strncmp(http->authstring, "Negotiate", 9) || in http_send()
4432 !strncmp(http->authstring, "AuthRef", 7))) in http_send()
4434 http->_authstring[0] = '\0'; in http_send()
4436 if (http->authstring != http->_authstring) in http_send()
4437 free(http->authstring); in http_send()
4439 http->authstring = http->_authstring; in http_send()
4451 http_set_length(http_t *http) /* I - Connection */ in http_set_length() argument
4456 …tf(("http_set_length(http=%p) mode=%d state=%s", (void *)http, http->mode, httpStateString(http->s… in http_set_length()
4458 if ((remaining = httpGetLength2(http)) >= 0) in http_set_length()
4460 if (http->mode == _HTTP_MODE_SERVER && in http_set_length()
4461 http->state != HTTP_STATE_GET_SEND && in http_set_length()
4462 http->state != HTTP_STATE_PUT && in http_set_length()
4463 http->state != HTTP_STATE_POST && in http_set_length()
4464 http->state != HTTP_STATE_POST_SEND) in http_set_length()
4470 if (!_cups_strcasecmp(http->fields[HTTP_FIELD_TRANSFER_ENCODING], in http_set_length()
4475 http->data_encoding = HTTP_ENCODING_CHUNKED; in http_set_length()
4481 http->data_encoding = HTTP_ENCODING_LENGTH; in http_set_length()
4486 http->data_remaining = remaining; in http_set_length()
4489 http->_data_remaining = (int)remaining; in http_set_length()
4491 http->_data_remaining = INT_MAX; in http_set_length()
4529 http_set_wait(http_t *http) /* I - HTTP connection */ in http_set_wait() argument
4531 if (http->blocking) in http_set_wait()
4533 http->wait_value = (int)(http->timeout_value * 1000); in http_set_wait()
4535 if (http->wait_value <= 0) in http_set_wait()
4536 http->wait_value = 60000; in http_set_wait()
4539 http->wait_value = 10000; in http_set_wait()
4549 http_tls_upgrade(http_t *http) /* I - HTTP connection */ in http_tls_upgrade() argument
4555 DEBUG_printf(("7http_tls_upgrade(%p)", (void *)http)); in http_tls_upgrade()
4562 httpFlush(http); in http_tls_upgrade()
4569 memcpy(&myhttp, http, sizeof(myhttp)); in http_tls_upgrade()
4576 http->tls_upgrade = 1; in http_tls_upgrade()
4577 http->field_authorization = NULL; /* Don't free the auth string */ in http_tls_upgrade()
4579 httpClearFields(http); in http_tls_upgrade()
4580 httpSetField(http, HTTP_FIELD_CONNECTION, "upgrade"); in http_tls_upgrade()
4581 httpSetField(http, HTTP_FIELD_UPGRADE, "TLS/1.2,TLS/1.1,TLS/1.0"); in http_tls_upgrade()
4583 if ((ret = httpOptions(http, "*")) == 0) in http_tls_upgrade()
4589 while (httpUpdate(http) == HTTP_STATUS_CONTINUE); in http_tls_upgrade()
4596 memcpy(http->fields, myhttp.fields, sizeof(http->fields)); in http_tls_upgrade()
4597 http->data_encoding = myhttp.data_encoding; in http_tls_upgrade()
4598 http->data_remaining = myhttp.data_remaining; in http_tls_upgrade()
4599 http->_data_remaining = myhttp._data_remaining; in http_tls_upgrade()
4600 http->expect = myhttp.expect; in http_tls_upgrade()
4601 http->field_authorization = myhttp.field_authorization; in http_tls_upgrade()
4602 http->digest_tries = myhttp.digest_tries; in http_tls_upgrade()
4603 http->tls_upgrade = 0; in http_tls_upgrade()
4609 if (!http->tls) in http_tls_upgrade()
4618 httpAddrClose(NULL, http->fd); in http_tls_upgrade()
4620 http->fd = -1; in http_tls_upgrade()
4635 http_write(http_t *http, /* I - HTTP connection */ in http_write() argument
4643 …DEBUG_printf(("2http_write(http=%p, buffer=%p, length=" CUPS_LLFMT ")", (void *)http, (void *)buff… in http_write()
4644 http->error = 0; in http_write()
4651 if (http->timeout_cb) in http_write()
4664 pfd.fd = http->fd; in http_write()
4667 while ((nfds = poll(&pfd, 1, http->wait_value)) < 0 && in http_write()
4675 FD_SET(http->fd, &output_set); in http_write()
4677 timeout.tv_sec = http->wait_value / 1000; in http_write()
4678 timeout.tv_usec = 1000 * (http->wait_value % 1000); in http_write()
4680 nfds = select(http->fd + 1, NULL, &output_set, NULL, &timeout); in http_write()
4692 http->error = errno; in http_write()
4695 else if (nfds == 0 && !(*http->timeout_cb)(http, http->timeout_data)) in http_write()
4698 http->error = WSAEWOULDBLOCK; in http_write()
4700 http->error = EWOULDBLOCK; in http_write()
4709 if (http->tls) in http_write()
4710 bytes = _httpTLSWrite(http, buffer, (int)length); in http_write()
4713 bytes = send(http->fd, buffer, length, 0); in http_write()
4725 if (http->timeout_cb && (*http->timeout_cb)(http, http->timeout_data)) in http_write()
4728 http->error = WSAGetLastError(); in http_write()
4730 else if (WSAGetLastError() != http->error && in http_write()
4733 http->error = WSAGetLastError(); in http_write()
4742 if (http->timeout_cb && (*http->timeout_cb)(http, http->timeout_data)) in http_write()
4744 else if (!http->timeout_cb && errno == EAGAIN) in http_write()
4747 http->error = errno; in http_write()
4749 else if (errno != http->error && errno != ECONNRESET) in http_write()
4751 http->error = errno; in http_write()
4757 strerror(http->error))); in http_write()
4782 http_write_chunk(http_t *http, /* I - HTTP connection */ in http_write_chunk() argument
4790 …DEBUG_printf(("7http_write_chunk(http=%p, buffer=%p, length=" CUPS_LLFMT ")", (void *)http, (void … in http_write_chunk()
4797 if (http_write(http, header, strlen(header)) < 0) in http_write_chunk()
4803 if ((bytes = http_write(http, buffer, length)) < 0) in http_write_chunk()
4809 if (http_write(http, "\r\n", 2) < 0) in http_write_chunk()