MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / encodeCPL

Function encodeCPL

modules/cpl_c/cpl_parser.c:1480–1534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1478#define ENC_ERR_LEN (sizeof(ENC_ERR)-1)
1479
1480int encodeCPL( str *xml, str *bin, str *log)
1481{
1482 static char buf[ENCONDING_BUFFER_SIZE];
1483 xmlDocPtr doc;
1484 xmlNodePtr cur;
1485
1486 doc = 0;
1487 list = 0;
1488
1489 /* reset all the logs (if any) to catch some possible err/warn/notice
1490 * from the parser/validater/encoder */
1491 reset_logs();
1492
1493 /* parse the xml */
1494 doc = xmlParseDoc( (unsigned char*)xml->s );
1495 if (!doc) {
1496 append_log( 1, ERR BAD_XML LF, ERR_LEN+BAD_XML_LEN+LF_LEN);
1497 LM_ERR( BAD_XML "\n");
1498 goto error;
1499 }
1500
1501 /* check the xml against dtd */
1502 if (xmlValidateDtd(&cvp, doc, dtd)!=1) {
1503 append_log( 1, ERR BAD_CPL LF, ERR_LEN+BAD_CPL_LEN+LF_LEN);
1504 LM_ERR( BAD_CPL "\n");
1505 goto error;
1506 }
1507
1508 cur = xmlDocGetRootElement(doc);
1509 if (!cur) {
1510 append_log( 1, ERR NULL_CPL LF, ERR_LEN+NULL_CPL_LEN+LF_LEN);
1511 LM_ERR( NULL_CPL "\n");
1512 goto error;
1513 }
1514
1515 bin->len = encode_node( cur, buf, buf+ENCONDING_BUFFER_SIZE);
1516 if (bin->len<0) {
1517 append_log( 1, ERR ENC_ERR LF, ERR_LEN+ENC_ERR_LEN+LF_LEN);
1518 LM_ERR( ENC_ERR "\n");
1519 goto error;
1520 }
1521
1522 xmlFreeDoc(doc);
1523 if (list) delete_list(list);
1524 /* compile the log buffer */
1525 compile_logs( log );
1526 bin->s = buf;
1527 return 1;
1528error:
1529 if (doc) xmlFreeDoc(doc);
1530 if (list) delete_list(list);
1531 /* compile the log buffer */
1532 compile_logs( log );
1533 return 0;
1534}
1535
1536
1537

Callers 2

do_script_actionFunction · 0.85
mi_cpl_loadFunction · 0.85

Calls 5

reset_logsFunction · 0.85
append_logFunction · 0.85
encode_nodeFunction · 0.85
delete_listFunction · 0.85
compile_logsFunction · 0.85

Tested by

no test coverage detected