MCPcopy Create free account
hub / github.com/OpenPrinting/cups / _httpTLSWrite

Function _httpTLSWrite

cups/tls-sspi.c:1126–1225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1124 */
1125
1126int /* O - Bytes written */
1127_httpTLSWrite(http_t *http, /* I - HTTP connection */
1128 const char *buf, /* I - Buffer holding data */
1129 int len) /* I - Length of buffer */
1130{
1131 _http_sspi_t *sspi = http->tls; /* SSPI data */
1132 SecBufferDesc message; /* Array of SecBuffer struct */
1133 SecBuffer buffers[4] = { 0 }; /* Security package buffer */
1134 int bufferLen; /* Buffer length */
1135 int bytesLeft; /* Bytes left to write */
1136 const char *bufptr; /* Pointer into buffer */
1137 int num = 0; /* Return value */
1138
1139
1140 bufferLen = sspi->streamSizes.cbMaximumMessage + sspi->streamSizes.cbHeader + sspi->streamSizes.cbTrailer;
1141
1142 if (bufferLen > sspi->writeBufferLength)
1143 {
1144 BYTE *temp; /* New buffer pointer */
1145
1146 if ((temp = (BYTE *)realloc(sspi->writeBuffer, bufferLen)) == NULL)
1147 {
1148 _cupsSetHTTPError(HTTP_STATUS_ERROR);
1149 DEBUG_printf(("5_httpTLSWrite: Unable to allocate buffer of %d bytes.", bufferLen));
1150 WSASetLastError(E_OUTOFMEMORY);
1151 return (-1);
1152 }
1153
1154 sspi->writeBuffer = temp;
1155 sspi->writeBufferLength = bufferLen;
1156 }
1157
1158 bytesLeft = len;
1159 bufptr = buf;
1160
1161 while (bytesLeft)
1162 {
1163 int chunk = min((int)sspi->streamSizes.cbMaximumMessage, bytesLeft);
1164 /* Size of data to write */
1165 SECURITY_STATUS scRet; /* SSPI status */
1166
1167 /*
1168 * Copy user data into the buffer, starting just past the header...
1169 */
1170
1171 memcpy(sspi->writeBuffer + sspi->streamSizes.cbHeader, bufptr, chunk);
1172
1173 /*
1174 * Setup the SSPI buffers
1175 */
1176
1177 message.ulVersion = SECBUFFER_VERSION;
1178 message.cBuffers = 4;
1179 message.pBuffers = buffers;
1180
1181 buffers[0].pvBuffer = sspi->writeBuffer;
1182 buffers[0].cbBuffer = sspi->streamSizes.cbHeader;
1183 buffers[0].BufferType = SECBUFFER_STREAM_HEADER;

Callers 1

http_writeFunction · 0.70

Calls 3

_cupsSetHTTPErrorFunction · 0.85
http_sspi_set_errorFunction · 0.85
http_sspi_strerrorFunction · 0.85

Tested by

no test coverage detected