uvhttp_utils.c
Functions
uvhttp_safe_strcpy(char *dest, size_t dest_size, const char *src)
Return Type: int
uvhttp_safe_strncpy(char *dest, const char *src, size_t dest_size)
Return Type: int
Safe string copy with size checking.
Parameters:
dest: Destination buffersrc: Source string to copydest_size: Size of destination buffer
Returns: int Number of characters copied (excluding null terminator)
Note: Ensures destination is null-terminated Note: Returns 0 if dest_size is 0
is_valid_status_code(int code)
Return Type: int
is_valid_string_length(const char *str, size_t max_len)
Return Type: int
uvhttp_send_unified_response(uvhttp_response_t *response, const char *content, size_t length, int status_code)
Unified response sending function - caller sets Content-Type.
Parameters:
response: Response objectcontent: Content datalength: Content length (auto-calculated if 0)status_code: HTTP status code (uses existing code if 0)
Returns: UVHTTP_OK on success, error code otherwise
json_escape(const char *src, char *dst, size_t dst_size)
Return Type: void
uvhttp_send_error_response(uvhttp_response_t *response, int error_code, const char *error_message, const char *details)
Create standard error response (JSON format)
Parameters:
response: Response objecterror_code: Error codeerror_message: Error messagedetails: Detailed information (optional)
Returns: UVHTTP_OK on success, error code otherwise
uvhttp_is_valid_status_code(int status_code)
Return Type: int
Validate HTTP status code.
Parameters:
status_code: HTTP status code
uvhttp_is_valid_ip_address(const char *ip)
Return Type: int
Validate IP address format (IPv4 or IPv6)
Parameters:
ip: IP address string to validate
Returns: int TRUE if valid, FALSE otherwise
Note: Supports both IPv4 (e.g., "192.168.1.1") and IPv6 (e.g., "::1") Note: Simplified validation, does not check all edge cases