mirror of
https://github.com/morgan9e/UxPlay
synced 2026-04-14 00:04:13 +09:00
fixes for plist_xml data stripping
This commit is contained in:
@@ -101,7 +101,11 @@ else ()
|
||||
target_link_libraries ( airplay PUBLIC ${LIBPLIST} )
|
||||
endif()
|
||||
if ( PLIST_FOUND )
|
||||
message( STATUS "found libplist-${PLIST_VERSION}" )
|
||||
message( STATUS "found libplist-${PLIST_VERSION}")
|
||||
pkg_check_modules ( PLIST_23 libplist-2.0>=2.3.0 )
|
||||
if ( PLIST_23_FOUND )
|
||||
add_definitions( -DPLIST_23 )
|
||||
endif()
|
||||
endif()
|
||||
target_include_directories( airplay PRIVATE ${PLIST_INCLUDE_DIRS} )
|
||||
|
||||
|
||||
36
lib/raop.c
36
lib/raop.c
@@ -307,12 +307,22 @@ conn_request(void *ptr, http_request_t *request, http_response_t **response) {
|
||||
if (data_is_plist) {
|
||||
plist_t req_root_node = NULL;
|
||||
plist_from_bin(request_data, request_datalen, &req_root_node);
|
||||
char * plist_xml;
|
||||
char * plist_xml = NULL;
|
||||
char * stripped_xml = NULL;
|
||||
uint32_t plist_len;
|
||||
plist_to_xml(req_root_node, &plist_xml, &plist_len);
|
||||
plist_xml = utils_strip_data_from_plist_xml(plist_xml);
|
||||
logger_log(conn->raop->logger, LOGGER_DEBUG, "%s", plist_xml);
|
||||
free(plist_xml);
|
||||
stripped_xml = utils_strip_data_from_plist_xml(plist_xml);
|
||||
logger_log(conn->raop->logger, LOGGER_DEBUG, "%s", (stripped_xml ? stripped_xml : plist_xml));
|
||||
if (stripped_xml) {
|
||||
free(stripped_xml);
|
||||
}
|
||||
if (plist_xml) {
|
||||
#ifdef PLIST_230
|
||||
plist_mem_free(plist_xml);
|
||||
#else
|
||||
plist_to_xml_free(plist_xml);
|
||||
#endif
|
||||
}
|
||||
plist_free(req_root_node);
|
||||
} else if (data_is_text) {
|
||||
char *data_str = utils_data_to_text((char *) request_data, request_datalen);
|
||||
@@ -442,12 +452,22 @@ conn_request(void *ptr, http_request_t *request, http_response_t **response) {
|
||||
if (data_is_plist) {
|
||||
plist_t res_root_node = NULL;
|
||||
plist_from_bin(response_data, response_datalen, &res_root_node);
|
||||
char * plist_xml;
|
||||
char * plist_xml = NULL;
|
||||
char * stripped_xml = NULL;
|
||||
uint32_t plist_len;
|
||||
plist_to_xml(res_root_node, &plist_xml, &plist_len);
|
||||
plist_xml = utils_strip_data_from_plist_xml(plist_xml);
|
||||
logger_log(conn->raop->logger, LOGGER_DEBUG, "%s", plist_xml);
|
||||
free(plist_xml);
|
||||
stripped_xml = utils_strip_data_from_plist_xml(plist_xml);
|
||||
logger_log(conn->raop->logger, LOGGER_DEBUG, "%s", (stripped_xml ? stripped_xml : plist_xml));
|
||||
if (stripped_xml) {
|
||||
free(stripped_xml);
|
||||
}
|
||||
if (plist_xml) {
|
||||
#ifdef PLIST_230
|
||||
plist_mem_free(plist_xml);
|
||||
#else
|
||||
plist_to_xml_free(plist_xml);
|
||||
#endif
|
||||
}
|
||||
plist_free(res_root_node);
|
||||
} else if (data_is_text) {
|
||||
char *data_str = utils_data_to_text((char*) response_data, response_datalen);
|
||||
|
||||
33
lib/utils.c
33
lib/utils.c
@@ -284,7 +284,7 @@ int utils_ipaddress_to_string(int addresslen, const unsigned char *address, unsi
|
||||
}
|
||||
|
||||
char *utils_strip_data_from_plist_xml(char *plist_xml) {
|
||||
/* returns pointer to *plist_xml unchanged if no data needs to be stripped out.
|
||||
/* returns NULL if no data needs to be stripped out.
|
||||
* otherwise frees plist_xml and returns pointer to newly-allocated stripped text char *xml
|
||||
* WHICH (like plist_xml) MUST BE FREED AFTER USE*/
|
||||
assert(plist_xml);
|
||||
@@ -292,20 +292,19 @@ char *utils_strip_data_from_plist_xml(char *plist_xml) {
|
||||
char *last = plist_xml + len * sizeof(char); // position of null termination of plist_xml
|
||||
|
||||
char *eol;
|
||||
char *xml;
|
||||
char *eol_data;
|
||||
char *xml = NULL;
|
||||
int nchars;
|
||||
char line[81];
|
||||
int count;
|
||||
char *begin = strstr(plist_xml, "<data>");
|
||||
char *end;
|
||||
|
||||
if (!begin) {
|
||||
/* there are no data lines, nothing to do */
|
||||
return plist_xml;
|
||||
return NULL;
|
||||
} else {
|
||||
xml = (char *) calloc((len + 1), sizeof(char));
|
||||
}
|
||||
|
||||
char *ptr1 = plist_xml;
|
||||
char *ptr2 = xml;
|
||||
do {
|
||||
@@ -318,17 +317,23 @@ char *utils_strip_data_from_plist_xml(char *plist_xml) {
|
||||
assert(end);
|
||||
count = 0;
|
||||
do {
|
||||
ptr1 = eol + 1;
|
||||
eol = strchr(ptr1, '\n');
|
||||
eol_data = eol;
|
||||
eol = strchr(eol + 1, '\n');
|
||||
count++;
|
||||
} while (eol < end);
|
||||
count--; // last '\n' counted ends the first non-data line (contains "</data>")
|
||||
if (count) {
|
||||
snprintf(line, sizeof(line), " ... (%d line%s of base64-encoded data not shown, 64 chars/line) ...\n",
|
||||
count, (count == 1 ? "" : "s"));
|
||||
}
|
||||
memcpy(ptr2, line, strlen(line));
|
||||
ptr2 += strlen(line);
|
||||
if (count > 1) {
|
||||
snprintf(line, sizeof(line), " (%d lines data omitted, 64 chars/line)\n", count);
|
||||
nchars = strlen(line);
|
||||
memcpy(ptr2, line, nchars);
|
||||
ptr2 += nchars;
|
||||
ptr1 = eol_data + 1;
|
||||
} else {
|
||||
nchars = eol_data + 1 - ptr1;
|
||||
memcpy(ptr2, ptr1, nchars);
|
||||
ptr2 += nchars;
|
||||
ptr1 += nchars;
|
||||
}
|
||||
begin = strstr(ptr1, "<data>");
|
||||
if (begin == NULL) {
|
||||
nchars = (int) (last + 1 - ptr1);
|
||||
@@ -336,8 +341,6 @@ char *utils_strip_data_from_plist_xml(char *plist_xml) {
|
||||
break;
|
||||
}
|
||||
} while (ptr1 <= last);
|
||||
|
||||
free (plist_xml);
|
||||
return xml;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user