1 #include "ProxyReadBuffer.H"
2 
3 
locateMessage(const unsigned char * start,const unsigned char * end,unsigned int & headerLength,unsigned int & dataLength,unsigned int & trailerLength)4 int ProxyReadBuffer::locateMessage(const unsigned char *start,
5                                    const unsigned char *end,
6                                    unsigned int &headerLength,
7                                    unsigned int &dataLength,
8                                    unsigned int &trailerLength)
9 {
10     unsigned int lengthLength = 0;
11 
12     dataLength = 0;
13     const unsigned char *nextSrc = start;
14     unsigned char next;
15 
16     do
17     {
18         if (nextSrc >= end)
19             return 0;
20         next = *nextSrc++;
21         dataLength <<= 7;
22         dataLength |= (unsigned int) (next & 0x7f);
23         lengthLength++;
24     }
25     while (next & 0x80);
26 
27     trailerLength = 0;
28 
29     headerLength = (dataLength == 0) ? 3 : lengthLength;
30 
31     unsigned int totalLength = headerLength + dataLength + trailerLength;
32 
33     if (start + totalLength > end)
34         return 0;
35     else
36         return 1;
37 }
38