| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "test.h" |
| 20 |
|
| 21 |
|
| 22 |
#if INCLUDE_XML_TEST |
| 23 |
|
| 24 |
#include <pjlib-util/xml.h> |
| 25 |
#include <pjlib.h> |
| 26 |
|
| 27 |
#define THIS_FILE "xml_test" |
| 28 |
|
| 29 |
static const char *xml_doc[] = |
| 30 |
{ |
| 31 |
" <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 32 |
" <p:pidf-full xmlns=\"urn:ietf:params:xml:ns:pidf\"\n" |
| 33 |
" xmlns:p=\"urn:ietf:params:xml:ns:pidf-diff\"\n" |
| 34 |
" xmlns:r=\"urn:ietf:params:xml:ns:pidf:rpid\"\n" |
| 35 |
" xmlns:c=\"urn:ietf:params:xml:ns:pidf:caps\"\n" |
| 36 |
" entity=\"pres:[email protected]\"\n" |
| 37 |
" version=\"567\">\n" |
| 38 |
"\n" |
| 39 |
" <tuple id=\"sg89ae\">\n" |
| 40 |
" <status>\n" |
| 41 |
" <basic>open</basic>\n" |
| 42 |
" <r:relationship>assistant</r:relationship>\n" |
| 43 |
" </status>\n" |
| 44 |
" <c:servcaps>\n" |
| 45 |
" <c:audio>true</c:audio>\n" |
| 46 |
" <c:video>false</c:video>\n" |
| 47 |
" <c:message>true</c:message>\n" |
| 48 |
" </c:servcaps>\n" |
| 49 |
" <contact priority=\"0.8\">tel:09012345678</contact>\n" |
| 50 |
" </tuple>\n" |
| 51 |
"\n" |
| 52 |
" <tuple id=\"cg231jcr\">\n" |
| 53 |
" <status>\n" |
| 54 |
" <basic>open</basic>\n" |
| 55 |
" </status>\n" |
| 56 |
" <contact priority=\"1.0\">im:[email protected]</contact>\n" |
| 57 |
" </tuple>\n" |
| 58 |
"\n" |
| 59 |
" <tuple id=\"r1230d\">\n" |
| 60 |
" <status>\n" |
| 61 |
" <basic>closed</basic>\n" |
| 62 |
" <r:activity>meeting</r:activity>\n" |
| 63 |
" </status>\n" |
| 64 |
" <r:homepage>http://example.com/~pep/</r:homepage>\n" |
| 65 |
" <r:icon>http://example.com/~pep/icon.gif</r:icon>\n" |
| 66 |
" <r:card>http://example.com/~pep/card.vcd</r:card>\n" |
| 67 |
" <contact priority=\"0.9\">sip:[email protected]</contact>\n" |
| 68 |
" </tuple>\n" |
| 69 |
"\n" |
| 70 |
" <note xml:lang=\"en\">Full state presence document</note>\n" |
| 71 |
"\n" |
| 72 |
" <r:person>\n" |
| 73 |
" <r:status>\n" |
| 74 |
" <r:activities>\n" |
| 75 |
" <r:on-the-phone/>\n" |
| 76 |
" <r:busy/>\n" |
| 77 |
" </r:activities>\n" |
| 78 |
" </r:status>\n" |
| 79 |
" </r:person>\n" |
| 80 |
"\n" |
| 81 |
" <r:device id=\"urn:esn:600b40c7\">\n" |
| 82 |
" <r:status>\n" |
| 83 |
" <c:devcaps>\n" |
| 84 |
" <c:mobility>\n" |
| 85 |
" <c:supported>\n" |
| 86 |
" <c:mobile/>\n" |
| 87 |
" </c:supported>\n" |
| 88 |
" </c:mobility>\n" |
| 89 |
" </c:devcaps>\n" |
| 90 |
" </r:status>\n" |
| 91 |
" </r:device>\n" |
| 92 |
"\n" |
| 93 |
" </p:pidf-full>\n" |
| 94 |
} |
| 95 |
; |
| 96 |
|
| 97 |
static int xml_parse_print_test(const char *doc) |
| 98 |
{ |
| 99 |
pj_str_t msg; |
| 100 |
pj_pool_t *pool; |
| 101 |
pj_xml_node *root; |
| 102 |
char *output; |
| 103 |
int output_len; |
| 104 |
|
| 105 |
pool = pj_pool_create(mem, "xml", 4096, 1024, NULL); |
| 106 |
pj_strdup2(pool, &msg, doc); |
| 107 |
root = pj_xml_parse(pool, msg.ptr, msg.slen); |
| 108 |
if (!root) { |
| 109 |
PJ_LOG(1, (THIS_FILE, " Error: unable to parse XML")); |
| 110 |
return -10; |
| 111 |
} |
| 112 |
|
| 113 |
output = (char*)pj_pool_zalloc(pool, msg.slen + 512); |
| 114 |
output_len = pj_xml_print(root, output, msg.slen+512, PJ_TRUE); |
| 115 |
if (output_len < 1) { |
| 116 |
PJ_LOG(1, (THIS_FILE, " Error: buffer too small to print XML file")); |
| 117 |
return -20; |
| 118 |
} |
| 119 |
output[output_len] = '\0'; |
| 120 |
|
| 121 |
|
| 122 |
pj_pool_release(pool); |
| 123 |
return 0; |
| 124 |
} |
| 125 |
|
| 126 |
int xml_test() |
| 127 |
{ |
| 128 |
unsigned i; |
| 129 |
for (i=0; i<PJ_ARRAY_SIZE(xml_doc); ++i) { |
| 130 |
int status; |
| 131 |
if ((status=xml_parse_print_test(xml_doc[i])) != 0) |
| 132 |
return status; |
| 133 |
} |
| 134 |
return 0; |
| 135 |
} |
| 136 |
|
| 137 |
#else |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
int dummy_xml_test; |
| 142 |
#endif |
| 143 |
|
| 144 |
|