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

Function httpGetLength2

cups/http.c:1037–1091  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1035 */
1036
1037off_t /* O - Content length */
1038httpGetLength2(http_t *http) /* I - HTTP connection */
1039{
1040 off_t remaining; /* Remaining length */
1041
1042
1043 DEBUG_printf(("2httpGetLength2(http=%p), state=%s", (void *)http, http ? httpStateString(http->state) : "NONE"));
1044
1045 if (!http)
1046 return (-1);
1047
1048 if (http->fields[HTTP_FIELD_TRANSFER_ENCODING] && !_cups_strcasecmp(http->fields[HTTP_FIELD_TRANSFER_ENCODING], "chunked"))
1049 {
1050 DEBUG_puts("4httpGetLength2: chunked request!");
1051 remaining = 0;
1052 }
1053 else
1054 {
1055 /*
1056 * The following is a hack for HTTP servers that don't send a
1057 * Content-Length or Transfer-Encoding field...
1058 *
1059 * If there is no Content-Length then the connection must close
1060 * after the transfer is complete...
1061 */
1062
1063 if (!http->fields[HTTP_FIELD_CONTENT_LENGTH] || !http->fields[HTTP_FIELD_CONTENT_LENGTH][0])
1064 {
1065 /*
1066 * Default content length is 0 for errors and certain types of operations,
1067 * and 2^31-1 for other successful requests...
1068 */
1069
1070 if (http->status >= HTTP_STATUS_MULTIPLE_CHOICES ||
1071 http->state == HTTP_STATE_OPTIONS ||
1072 (http->state == HTTP_STATE_GET && http->mode == _HTTP_MODE_SERVER) ||
1073 http->state == HTTP_STATE_HEAD ||
1074 (http->state == HTTP_STATE_PUT && http->mode == _HTTP_MODE_CLIENT) ||
1075 http->state == HTTP_STATE_DELETE ||
1076 http->state == HTTP_STATE_TRACE ||
1077 http->state == HTTP_STATE_CONNECT)
1078 remaining = 0;
1079 else
1080 remaining = 2147483647;
1081 }
1082 else if ((remaining = strtoll(http->fields[HTTP_FIELD_CONTENT_LENGTH],
1083 NULL, 10)) < 0)
1084 remaining = -1;
1085
1086 DEBUG_printf(("4httpGetLength2: content_length=" CUPS_LLFMT,
1087 CUPS_LLCAST remaining));
1088 }
1089
1090 return (remaining);
1091}
1092
1093
1094/*

Callers 5

cupsdReadClientFunction · 0.85
cupsdWriteClientFunction · 0.85
mainFunction · 0.85
httpGetLengthFunction · 0.85
http_set_lengthFunction · 0.85

Calls 2

httpStateStringFunction · 0.85
_cups_strcasecmpFunction · 0.85

Tested by 1

mainFunction · 0.68