ptg10805159
Section 21.5 Source Code 841
887 if (i >= datsz) { /* get more header */
888 if ((nr = readmore(sfd, &bp, i, &bufsz)) < 0) {
889 goto out;
890 } else {
891 cp =&bp[i];
892 datsz += nr;
893 }
894 }
895 found=0;
896 while (!found) { /* look for end of HTTP header */
897 while (i < datsz - 2) {
898 if (*cp == ’\n’ && *(cp + 1) == ’\r’ &&
899 *(cp + 2) == ’\n’) {
900 found=1;
901 cp += 3;
902 i += 3;
903 break;
904 }
905 cp++;
906 i++;
907 }
908 if (i >= datsz) { /* get more header */
909 if ((nr = readmore(sfd, &bp, i, &bufsz)) < 0) {
910 goto out;
911 } else {
912 cp =&bp[i];
913 datsz += nr;
914 }
915 }
916 }
917 if (datsz - i < len) { /* get more header */
918 if ((nr = readmore(sfd, &bp, i, &bufsz)) < 0) {
919 goto out;
920 } else {
921 cp =&bp[i];
922 datsz += nr;
[887 – 916] We now know the length of the message (specified by theContent-Length
attribute). If we’ve exhausted the contents of the buffer, we read morefrom
the printer.Next we search for the end of the HTTP header (a blank line). If
we find it, we set thefoundflag and skip the blank line. Whenever we call
readmore, we setcpto point to the same offset in the buffer that it had
previously just in case the buffer address changed when it was reallocated.
[917 – 922] When we find the end of the HTTP header, we calculate the number of bytes
that the HTTP header consumed. If the amount we’ve read minus the size of
the HTTP header is not equal to the amount of data in the IPP message (the
value we calculated from the content length), then we read some more.