aboutsummaryrefslogtreecommitdiff
path: root/vendor/voclient/libsamp/libxrpc/xmlrpc-c-1.16.29/src/trace.c
blob: 6fe65937a991ed5f6dfe86428c3b11c1dde7345b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

#include "xmlrpc-c/base_int.h"
#include "xmlrpc-c/string_int.h"


static size_t
nextLineSize(const char * const string,
             size_t       const startPos,
             size_t       const stringSize) {
/*----------------------------------------------------------------------------
   Return the length of the line that starts at offset 'startPos' in the
   string 'string', which is 'stringSize' characters long.

   'string' in not NUL-terminated.
   
   A line begins at beginning of string or after a newline character and
   runs through the next newline character or end of string.  The line
   includes the newline character at the end, if any.
-----------------------------------------------------------------------------*/
    size_t i;

    for (i = startPos; i < stringSize && string[i] != '\n'; ++i);

    if (i < stringSize)
        ++i;  /* Include the newline */

    return i - startPos;
}



void
xmlrpc_traceXml(const char * const label, 
                const char * const xml,
                unsigned int const xmlLength) {

    if (getenv("XMLRPC_TRACE_XML")) {
        size_t cursor;  /* Index into xml[] */

        fprintf(stderr, "%s:\n\n", label);

        for (cursor = 0; cursor < xmlLength; ) {
            /* Print one line of XML */

            size_t const lineSize = nextLineSize(xml, cursor, xmlLength);
#ifdef ORIG
            const char * const xmlPrintableLine =
                xmlrpc_makePrintable_lp(&xml[cursor], lineSize);
#else
            char *xmlPrintableLine =
                xmlrpc_makePrintable_lp(&xml[cursor], lineSize);
#endif

            fprintf(stderr, "%s\n", xmlPrintableLine);

            cursor += lineSize;

#ifdef ORIG
            xmlrpc_strfree(xmlPrintableLine);
#else
	    free (xmlPrintableLine);
#endif
        }
        fprintf(stderr, "\n");
    }
}