* Dump the given number of bytes on an AJP Message * * @param pool pool to allocate from * @param msg AJP Message to dump * @param err error string to display * @param count the number of bytes to dump * @param buf buffer pointer for dump message * @return APR_SUCCESS or error */
| 40 | * @return APR_SUCCESS or error |
| 41 | */ |
| 42 | apr_status_t ajp_msg_dump(apr_pool_t *pool, ajp_msg_t *msg, char *err, |
| 43 | apr_size_t count, char **buf) |
| 44 | { |
| 45 | apr_size_t i, j; |
| 46 | char *current; |
| 47 | apr_size_t bl, rl; |
| 48 | apr_byte_t x; |
| 49 | apr_size_t len = msg->len; |
| 50 | apr_size_t line_len; |
| 51 | |
| 52 | /* Display only first "count" bytes */ |
| 53 | if (len > count) |
| 54 | len = count; |
| 55 | /* First the space needed for the first line */ |
| 56 | bl = strlen(err) + 3 * (strlen(" XXX=") + 20) + 1 + |
| 57 | /* Now for the data lines */ |
| 58 | (len + 15) / 16 * AJP_MSG_DUMP_LINE_LENGTH; |
| 59 | *buf = apr_palloc(pool, bl); |
| 60 | if (!*buf) |
| 61 | return APR_ENOMEM; |
| 62 | apr_snprintf(*buf, bl, |
| 63 | "%s pos=%" APR_SIZE_T_FMT |
| 64 | " len=%" APR_SIZE_T_FMT " max=%" APR_SIZE_T_FMT "\n", |
| 65 | err, msg->pos, msg->len, msg->max_size); |
| 66 | current = *buf + strlen(*buf); |
| 67 | for (i = 0; i < len; i += AJP_MSG_DUMP_BYTES_PER_LINE) { |
| 68 | /* Safety check: do we have enough buffer for another line? */ |
| 69 | rl = bl - (current - *buf); |
| 70 | if (AJP_MSG_DUMP_LINE_LENGTH > rl) { |
| 71 | *(current - 1) = '\0'; |
| 72 | return APR_ENOMEM; |
| 73 | } |
| 74 | apr_snprintf(current, rl, "%.4lx ", (unsigned long)i); |
| 75 | current += AJP_MSG_DUMP_PREFIX_LENGTH; |
| 76 | line_len = len - i; |
| 77 | if (line_len > AJP_MSG_DUMP_BYTES_PER_LINE) { |
| 78 | line_len = AJP_MSG_DUMP_BYTES_PER_LINE; |
| 79 | } |
| 80 | for (j = 0; j < line_len; j++) { |
| 81 | x = msg->buf[i + j]; |
| 82 | |
| 83 | *current++ = hex_table[x >> 4]; |
| 84 | *current++ = hex_table[x & 0x0f]; |
| 85 | *current++ = ' '; |
| 86 | } |
| 87 | *current++ = ' '; |
| 88 | *current++ = '-'; |
| 89 | *current++ = ' '; |
| 90 | for (j = 0; j < line_len; j++) { |
| 91 | x = msg->buf[i + j]; |
| 92 | |
| 93 | if (x > 0x20 && x < 0x7F) { |
| 94 | *current++ = x; |
| 95 | } |
| 96 | else { |
| 97 | *current++ = '.'; |
| 98 | } |
| 99 | } |