83 lines
2.4 KiB
C
83 lines
2.4 KiB
C
#ifndef LNM_COMMON
|
|
#define LNM_COMMON
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
|
|
#define LNM_RES(x) \
|
|
{ \
|
|
lnm_err res = x; \
|
|
if (res != lnm_err_ok) \
|
|
return res; \
|
|
}
|
|
|
|
#define LNM_RES2(x, e) \
|
|
{ \
|
|
lnm_err res = x; \
|
|
if (res != lnm_err_ok) { \
|
|
e; \
|
|
return res; \
|
|
} \
|
|
}
|
|
|
|
#define LNM_MIN(x, y) ((x) < (y) ? (x) : (y))
|
|
#define LNM_MAX(x, y) ((x) > (y) ? (x) : (y))
|
|
|
|
typedef enum lnm_err {
|
|
lnm_err_ok = 0,
|
|
lnm_err_failed_alloc,
|
|
lnm_err_failed_network,
|
|
lnm_err_failed_poll,
|
|
lnm_err_not_setup,
|
|
lnm_err_bad_regex,
|
|
lnm_err_not_found,
|
|
} lnm_err;
|
|
|
|
typedef struct lnm_loop lnm_http_loop;
|
|
|
|
typedef struct lnm_loop_conn lnm_http_conn;
|
|
|
|
typedef struct lnm_http_step lnm_http_step;
|
|
|
|
typedef struct lnm_http_route lnm_http_route;
|
|
|
|
/**
|
|
* Returns whether the two strings are equal.
|
|
*
|
|
* @param s1 first string to compare
|
|
* @param s1_len length of `s1`
|
|
* @param s2 second string to compare
|
|
* @param s2_len length of `s2`
|
|
*/
|
|
bool lnm_strneq(const char *s1, size_t s1_len, const char *s2, size_t s2_len);
|
|
|
|
/**
|
|
* Returns whether the two strings are equal, ignoring capitalisation.
|
|
*
|
|
* @param s1 first string to compare
|
|
* @param s1_len length of `s1`
|
|
* @param s2 second string to compare
|
|
* @param s2_len length of `s2`
|
|
*/
|
|
bool lnm_strnieq(const char *s1, size_t s1_len, const char *s2, size_t s2_len);
|
|
|
|
/**
|
|
* Calculate integer exponentation.
|
|
*
|
|
* @param base
|
|
* @param power
|
|
*/
|
|
uint64_t lnm_ipow(uint64_t base, uint64_t power);
|
|
|
|
/**
|
|
* Parse the given string into a number.
|
|
*
|
|
* @param s string to parse
|
|
* @param len length of s
|
|
* @return the parsed number, or 0 if the number is invalid
|
|
*/
|
|
uint64_t lnm_atoi(const char *s, size_t len);
|
|
|
|
#endif
|