Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGES.TXT
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
0.96.7 (unreleased)
-------------------
- Fix: Replace DEBUG_OUT 0/1 integer toggle in networking.c with CMake opt-in (-DNETWORKING_DEBUG=ON); fix 3 error messages using printf() instead of fprintf(stderr) (#2174)
- Fix: Remove strdup() memory leaks in WebVTT styling encoder, fix invalid CSS rgba(0,256,0) green value, fix missing free(unescaped) on write-error path (#2154)
- Fix: Prevent crash in Rust timing module when logging out-of-range PTS/FTS timestamps from malformed streams.

Expand Down
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include (CTest)
option (WITH_FFMPEG "Build using FFmpeg demuxer and decoder" OFF)
option (WITH_OCR "Build with OCR (Optical Character Recognition) feature" OFF)
option (WITH_HARDSUBX "Build with support for burned-in subtitles" OFF)
option (NETWORKING_DEBUG "Enable networking debug output" OFF)

# Version number
set (CCEXTRACTOR_VERSION_MAJOR 0)
Expand Down Expand Up @@ -145,6 +146,10 @@ else (MSVC)
endif(MSVC)

set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64")
if (NETWORKING_DEBUG)
add_definitions(-DNETWORKING_DEBUG)
message(STATUS "Networking debug output enabled")
endif (NETWORKING_DEBUG)
add_subdirectory (lib_ccx)

aux_source_directory(${PROJECT_SOURCE_DIR} SOURCEFILE)
Expand Down
52 changes: 25 additions & 27 deletions src/lib_ccx/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <errno.h>
#include <assert.h>

#define DEBUG_OUT 0

/* Protocol constants: */
#define INT_LEN 10
#define OK 1
Expand Down Expand Up @@ -93,7 +91,7 @@ ssize_t read_byte(int fd, char *status);

void init_sockets(void);

#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
void pr_command(char c);
#endif

Expand Down Expand Up @@ -143,15 +141,15 @@ void net_send_header(const unsigned char *data, size_t len)
#endif
assert(srv_sd > 0);

#if DEBUG_OUT
fprintf(stderr, "Sending header (len = %u): \n", len);
#ifdef NETWORKING_DEBUG
fprintf(stderr, "Sending header (len = %zu): \n", len);
fprintf(stderr, "File created by %02X version %02X%02X\n", data[3], data[4], data[5]);
fprintf(stderr, "File format revision: %02X%02X\n", data[6], data[7]);
#endif

if (write_block(srv_sd, BIN_HEADER, data, len) <= 0)
{
printf("Can't send BIN header\n");
fprintf(stderr, "Can't send BIN header\n");
return;
}

Expand All @@ -172,13 +170,13 @@ int net_send_cc(const unsigned char *data, int len, void *private_data, struct c
#endif
assert(srv_sd > 0);

#if DEBUG_OUT
fprintf(stderr, "[C] Sending %u bytes\n", len);
#ifdef NETWORKING_DEBUG
fprintf(stderr, "[C] Sending %d bytes\n", len);
#endif

if (write_block(srv_sd, BIN_DATA, data, len) <= 0)
{
printf("Can't send BIN data\n");
fprintf(stderr, "Can't send BIN data\n");
return -1;
}

Expand Down Expand Up @@ -212,7 +210,7 @@ void net_check_conn()
rc = read_byte(srv_sd, &c);
if (c == PING)
{
#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
fprintf(stderr, "[S] Received PING\n");
#endif
last_ping = now;
Expand All @@ -238,7 +236,7 @@ void net_check_conn()
{
if (write_block(srv_sd, PING, NULL, 0) < 0)
{
printf("Unable to send data\n");
fprintf(stderr, "Unable to send data\n");
exit(EXIT_FAILURE);
}

Expand Down Expand Up @@ -324,8 +322,8 @@ void net_send_epg(
memcpy(end, category, c);
end += c;

#if DEBUG_OUT
fprintf(stderr, "[C] Sending EPG: %u bytes\n", len);
#ifdef NETWORKING_DEBUG
fprintf(stderr, "[C] Sending EPG: %zu bytes\n", len);
#endif

if (write_block(srv_sd, EPG_DATA, epg, len) <= 0)
Expand Down Expand Up @@ -420,7 +418,7 @@ int net_udp_read(int socket, void *buffer, size_t length, const char *src_str, c
ssize_t write_block(int fd, char command, const char *buf, size_t buf_len)
{
assert(fd > 0);
#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
fprintf(stderr, "[C] ");
#endif

Expand All @@ -433,7 +431,7 @@ ssize_t write_block(int fd, char command, const char *buf, size_t buf_len)
return 0;
nwritten++;

#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
pr_command(command);
fprintf(stderr, " ");
#endif
Expand All @@ -446,7 +444,7 @@ ssize_t write_block(int fd, char command, const char *buf, size_t buf_len)
return 0;
nwritten += rc;

#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
fwrite(len_str, sizeof(char), INT_LEN, stderr);
fprintf(stderr, " ");
#endif
Expand All @@ -460,7 +458,7 @@ ssize_t write_block(int fd, char command, const char *buf, size_t buf_len)
nwritten += rc;
}

#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
if (buf != NULL && command != BIN_HEADER && command != BIN_DATA)
{
fwrite(buf, sizeof(char), buf_len, stderr);
Expand All @@ -474,7 +472,7 @@ ssize_t write_block(int fd, char command, const char *buf, size_t buf_len)
return 0;
nwritten++;

#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
fprintf(stderr, "\\r");
#endif

Expand All @@ -484,7 +482,7 @@ ssize_t write_block(int fd, char command, const char *buf, size_t buf_len)
return 0;
nwritten++;

#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
fprintf(stderr, "\\n\n");
#endif

Expand Down Expand Up @@ -667,11 +665,11 @@ int check_password(int fd, const char *pwd)
return 1;
}

#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
fprintf(stderr, "[C] Wrong password\n");
#endif

#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
fprintf(stderr, "[S] PASSWORD\n");
#endif
if (write_byte(fd, PASSWORD) < 0)
Expand Down Expand Up @@ -792,7 +790,7 @@ ssize_t read_block(int fd, char *command, char *buf, size_t *buf_len)
return 0;
nread += rc;

#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
fprintf(stderr, "[C] ");
pr_command(*command);
fprintf(stderr, " ");
Expand All @@ -805,7 +803,7 @@ ssize_t read_block(int fd, char *command, char *buf, size_t *buf_len)
return 0;
nread += rc;

#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
fwrite(len_str, sizeof(char), INT_LEN, stderr);
fprintf(stderr, " ");
#endif
Expand Down Expand Up @@ -836,7 +834,7 @@ ssize_t read_block(int fd, char *command, char *buf, size_t *buf_len)
return 0;
nread += rc;

#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
if (*command != BIN_DATA && *command != BIN_HEADER)
{
fwrite(buf, sizeof(char), len, stderr);
Expand All @@ -854,21 +852,21 @@ ssize_t read_block(int fd, char *command, char *buf, size_t *buf_len)

if (end[0] != '\r' || end[1] != '\n')
{
#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
fprintf(stderr, "read_block(): No end marker present\n");
fprintf(stderr, "Closing connection\n");
#endif
return 0;
}

#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
fprintf(stderr, "\\r\\n\n");
#endif

return nread;
}

#if DEBUG_OUT
#ifdef NETWORKING_DEBUG
void pr_command(char c)
{
switch (c)
Expand Down
Loading