|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
Reusable validation macros for protocol handlers. More...
Modules | |
| Image Validation Functions | |
Files | |
| file | validation.h |
| Common validation macros to reduce duplication in protocol handlers. | |
Macros | |
| #define | VALIDATE_NOTNULL_DATA(client, data, packet_name) |
| #define | VALIDATE_MIN_SIZE(client, len, min_size, packet_name) |
| #define | VALIDATE_EXACT_SIZE(client, len, expected_size, packet_name) |
| #define | VALIDATE_AUDIO_STREAM_ENABLED(client, packet_name) |
| #define | VALIDATE_AUDIO_SAMPLE_COUNT(client, num_samples, max_samples, packet_name) |
| #define | VALIDATE_AUDIO_ALIGNMENT(client, len, sample_size, packet_name) |
| #define | VALIDATE_RESOURCE_INITIALIZED(client, resource, resource_name) |
| #define | VALIDATE_PACKET_SIZE(client, data, len, expected_size, packet_name) |
| #define | VALIDATE_NONZERO(client, value, value_name, packet_name) |
| #define | VALIDATE_RANGE(client, value, min_val, max_val, value_name, packet_name) |
| #define | VALIDATE_CAPABILITY_FLAGS(client, flags, valid_mask, packet_name) |
| #define | VALIDATE_FLAGS_MASK(client, flags, valid_mask, packet_name) |
| #define | VALIDATE_PACKET_NOT_NULL(client, data, packet_name) |
Typedefs | |
| typedef struct client_info | client_info_t |
Functions | |
| void | disconnect_client_for_bad_data (client_info_t *client, const char *format,...) |
Reusable validation macros for protocol handlers.
Provides standardized validation macros for protocol handlers to:
All macros call disconnect_client_for_bad_data() on validation failure and return from the calling function immediately.
Usage:
| #define VALIDATE_AUDIO_ALIGNMENT | ( | client, | |
| len, | |||
| sample_size, | |||
| packet_name | |||
| ) |
#include <validation.h>
Validate that audio sample alignment is correct (must be multiple of sample size). Disconnects client and returns if alignment is incorrect.
Definition at line 111 of file util/validation.h.
| #define VALIDATE_AUDIO_SAMPLE_COUNT | ( | client, | |
| num_samples, | |||
| max_samples, | |||
| packet_name | |||
| ) |
#include <validation.h>
Validate that audio sample count is within acceptable bounds. Disconnects client and returns if sample count is invalid.
Definition at line 98 of file util/validation.h.
| #define VALIDATE_AUDIO_STREAM_ENABLED | ( | client, | |
| packet_name | |||
| ) |
#include <validation.h>
Validate that audio stream is enabled for this client. Disconnects client and returns if audio stream is not enabled.
Definition at line 86 of file util/validation.h.
| #define VALIDATE_CAPABILITY_FLAGS | ( | client, | |
| flags, | |||
| valid_mask, | |||
| packet_name | |||
| ) |
#include <validation.h>
Validate that at least one capability flag is set. Disconnects client and returns if all flags are zero or invalid.
Definition at line 178 of file util/validation.h.
| #define VALIDATE_EXACT_SIZE | ( | client, | |
| len, | |||
| expected_size, | |||
| packet_name | |||
| ) |
#include <validation.h>
Validate that payload size is exactly the expected size. Disconnects client and returns if len != expected_size.
Definition at line 73 of file util/validation.h.
| #define VALIDATE_FLAGS_MASK | ( | client, | |
| flags, | |||
| valid_mask, | |||
| packet_name | |||
| ) |
#include <validation.h>
Validate that only known/valid flags are set. Disconnects client and returns if unknown flags are present.
Definition at line 191 of file util/validation.h.
| #define VALIDATE_MIN_SIZE | ( | client, | |
| len, | |||
| min_size, | |||
| packet_name | |||
| ) |
#include <validation.h>
Validate that payload size is at least the minimum required. Disconnects client and returns if len < min_size.
Definition at line 60 of file util/validation.h.
| #define VALIDATE_NONZERO | ( | client, | |
| value, | |||
| value_name, | |||
| packet_name | |||
| ) |
#include <validation.h>
Validate that a numeric value is non-zero (for dimensions, counts, etc). Disconnects client and returns if value is zero.
Definition at line 153 of file util/validation.h.
| #define VALIDATE_NOTNULL_DATA | ( | client, | |
| data, | |||
| packet_name | |||
| ) |
#include <validation.h>
Validate that payload data pointer is not NULL. Disconnects client and returns if data is NULL.
Definition at line 48 of file util/validation.h.
| #define VALIDATE_PACKET_NOT_NULL | ( | client, | |
| data, | |||
| packet_name | |||
| ) |
#include <validation.h>
Validate packet payload pointer is not NULL. Returns true if validation failed (data is NULL), false if valid.
Definition at line 204 of file util/validation.h.
| #define VALIDATE_PACKET_SIZE | ( | client, | |
| data, | |||
| len, | |||
| expected_size, | |||
| packet_name | |||
| ) |
#include <validation.h>
Validate packet payload size and presence. Checks if data pointer is non-NULL and payload matches expected size.
Definition at line 136 of file util/validation.h.
| #define VALIDATE_RANGE | ( | client, | |
| value, | |||
| min_val, | |||
| max_val, | |||
| value_name, | |||
| packet_name | |||
| ) |
#include <validation.h>
Validate that a numeric value is within a specified range (inclusive). Disconnects client and returns if value is outside range.
Definition at line 165 of file util/validation.h.
| #define VALIDATE_RESOURCE_INITIALIZED | ( | client, | |
| resource, | |||
| resource_name | |||
| ) |
#include <validation.h>
Validate that a required resource/buffer is initialized. Disconnects client and returns if resource is NULL.
Definition at line 124 of file util/validation.h.
| typedef struct client_info client_info_t |
#include <validation.h>
Definition at line 39 of file util/validation.h.
| void disconnect_client_for_bad_data | ( | client_info_t * | client, |
| const char * | format, | ||
| ... | |||
| ) |
#include <validation.h>
Definition at line 157 of file server/protocol.c.
References client_info::active, ASCIICHAT_OK, client_info::audio_queue, client_info::audio_render_thread_running, client_info::client_id, client_info::client_state_mutex, client_info::crypto_handshake_ctx, crypto_handshake_get_context(), client_info::crypto_initialized, ERROR_NETWORK_PROTOCOL, INVALID_SOCKET_VALUE, LOG_ERROR, log_network_message(), log_warn, mutex_lock, mutex_unlock, packet_queue_shutdown(), packet_send_error(), platform_sleep_ms(), client_info::protocol_disconnect_requested, REMOTE_LOG_DIRECTION_SERVER_TO_CLIENT, SAFE_STRNCPY, client_info::send_mutex, client_info::send_thread_running, client_info::shutting_down, client_info::socket, socket_close(), socket_shutdown(), and client_info::video_render_thread_running.
Referenced by process_decrypted_packet().