|
Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
|
Request parameter validation middleware (required, type checking, email). More...
#include <ctype.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include "csilk/core/internal.h"#include "csilk/csilk.h"
Functions | |
| static const char * | str_find (const char *s, char c) |
| Find the first occurrence of a character in a string (helper). | |
| static int | is_valid_email (const char *s) |
| Check if a string looks like a valid email address. | |
| const char * | csilk_validate (csilk_ctx_t *c, const csilk_valid_rule_t *rules) |
| Run all validation rules and return the first error, or NULL on success. | |
Request parameter validation middleware (required, type checking, email).
| const char * csilk_validate | ( | csilk_ctx_t * | c, |
| const csilk_valid_rule_t * | rules | ||
| ) |
Run all validation rules and return the first error, or NULL on success.
Validate request parameters against a set of rules.
Iterates through an array of validation rules, stopping at the first rule that fails. Each rule specifies the source of the value (query, form, header, cookie, or automatic fallback) and the validation flags to apply (CSILK_VALID_REQUIRED, CSILK_VALID_INT, CSILK_VALID_STRING, CSILK_VALID_EMAIL).
For integer validation, an optional [min, max] range can be specified. For string validation, an optional [min, max] length range can be specified. Ranges are ignored when min >= max.
| c | The request context to extract values from. |
| rules | A null-terminated array of csilk_valid_rule_t rules (the last entry must have field == NULL). Must not be NULL. |
|
static |
Check if a string looks like a valid email address.
Performs a basic syntactic validation: the string must contain exactly one '@' character, the local part and domain must be non-empty, and the domain must contain at least one dot after the '@' with non-empty segments. No whitespace characters are permitted anywhere in the address.
| s | The string to validate. Must be null-terminated. |
|
static |
Find the first occurrence of a character in a string (helper).
| s | The string to search (may be NULL). |
| c | The character to locate. |