diff options
Diffstat (limited to 'include/dbs')
-rw-r--r-- | include/dbs/api.h | 30 | ||||
-rw-r--r-- | include/dbs/init.h | 23 | ||||
-rw-r--r-- | include/dbs/log.h | 67 | ||||
-rw-r--r-- | include/dbs/subsys.h | 12 | ||||
-rw-r--r-- | include/dbs/util.h | 3 |
5 files changed, 135 insertions, 0 deletions
diff --git a/include/dbs/api.h b/include/dbs/api.h new file mode 100644 index 0000000..d421f08 --- /dev/null +++ b/include/dbs/api.h @@ -0,0 +1,30 @@ +#ifndef __API_H +#define __API_H + +typedef enum { + HTTP_GET, + HTTP_POST, + HTTP_PUT, + HTTP_DELETE, + HTTP_PATCH +} HTTPMethod; + +int http_request(HTTPMethod method, char *url, + struct curl_slist *headers, char *writebuf, size_t bufsiz); + +int api_request(HTTPMethod method, char * url, + struct curl_slist *headers, char *writebuf, size_t bufsiz); + +#define http_get(...) http_request(HTTP_GET, __VA_ARGS__) +#define http_post(...) http_request(HTTP_POST, __VA_ARGS__) +#define http_put(...) http_request(HTTP_PUT, __VA_ARGS__) +#define http_delete(...) http_request(HTTP_DELETE, __VA_ARGS__) +#define http_patch(...) http_request(HTTP_PATCH, __VA_ARGS__) + +#define api_get(...) api_request(HTTP_GET, __VA_ARGS__) +#define api_post(...) api_request(HTTP_POST, __VA_ARGS__) +#define api_put(...) api_request(HTTP_PUT, __VA_ARGS__) +#define api_delete(...) api_request(HTTP_DELETE, __VA_ARGS__) +#define api_patch(...) api_request(HTTP_PATCH, __VA_ARGS__) + +#endif diff --git a/include/dbs/init.h b/include/dbs/init.h new file mode 100644 index 0000000..79e60f1 --- /dev/null +++ b/include/dbs/init.h @@ -0,0 +1,23 @@ +#ifndef __INIT_H +#define __INIT_H + +typedef void (*initcall_t)(void); +typedef initcall_t initcall_entry_t; + +#define __define_initcall(fn, id) \ + static initcall_t __initcall_##fn##id \ + __attribute__((used)) \ + __attribute__((section(".initcall" #id ".init"))) = fn + +#define l1_initcall(fn) __define_initcall(fn, 1) +#define l2_initcall(fn) __define_initcall(fn, 2) +#define l3_initcall(fn) __define_initcall(fn, 3) +#define l4_initcall(fn) __define_initcall(fn, 4) +#define l5_initcall(fn) __define_initcall(fn, 5) + +static inline initcall_t initcall_from_entry(initcall_entry_t *entry) +{ + return *entry; +} + +#endif diff --git a/include/dbs/log.h b/include/dbs/log.h new file mode 100644 index 0000000..30fec81 --- /dev/null +++ b/include/dbs/log.h @@ -0,0 +1,67 @@ +#define LOG_SOH "\001" +#define LOG_SOH_ASCII '\001' + +#define EMERG_LOGLEVEL 0 +#define ALERT_LOGLEVEL 1 +#define CRIT_LOGLEVEL 2 +#define ERR_LOGLEVEL 3 +#define WARNING_LOGLEVEL 4 +#define NOTICE_LOGLEVEL 5 +#define INFO_LOGLEVEL 6 +#define DEBUG_LOGLEVEL 7 + +#define DEFAULT_LOGLEVEL NOTICE_LOGLEVEL +#define CONSOLE_LOGLEVEL DEBUG_LOGLEVEL + +#define LOG_EMERG LOG_SOH "\1" "0" +#define LOG_ALERT LOG_SOH "\1" "1" +#define LOG_CRIT LOG_SOH "\1" "2" +#define LOG_ERR LOG_SOH "\1" "3" +#define LOG_WARNING LOG_SOH "\1" "4" +#define LOG_NOTICE LOG_SOH "\1" "5" +#define LOG_INFO LOG_SOH "\1" "6" +#define LOG_DEBUG LOG_SOH "\1" "7" + +#define LOG_DEFAULT "" + +int print(const char *fmt, ...); + +#define PANICMODE_DEBUGONLY 'o' +#define PANICMODE_RESPAWN 'r' +#define PANICMODE_DIE 'd' + +#define PANIC_OOPS LOG_SOH "o" +#define PANIC_RESPAWN LOG_SOH "r" +#define PANIC_PANIC LOG_SOH "d" + +#define PANIC_DEFAULT PANIC_PANIC + +void _panic(const char *fileorigin, const int lineorigin, const char *fmt, ...); +#define panic(...) _panic(__FILE__, __LINE__, __VA_ARGS__) +#define oops(...) _panic(__FILE__, __LINE__, PANIC_OOPS __VA_ARGS__) + +#define ANSI_CSI "\x1b[" + +#define ANSI_BOLD ANSI_CSI "1m" +#define ANSI_ITALIC ANSI_CSI "3m" +#define ANSI_BLINK ANSI_CSI "5m" +#define ANSI_REVERSE ANSI_CSI "7m" +#define ANSI_RESET ANSI_CSI "0m" + +#define ANSI_BLACK ANSI_CSI "30m" +#define ANSI_RED ANSI_CSI "31m" +#define ANSI_GREEN ANSI_CSI "32m" +#define ANSI_YELLOW ANSI_CSI "33m" +#define ANSI_BLUE ANSI_CSI "34m" +#define ANSI_MAGENTA ANSI_CSI "35m" +#define ANSI_CYAN ANSI_CSI "36m" +#define ANSI_WHITE ANSI_CSI "37m" + +#define ANSI_BRIGHT_BLACK ANSI_CSI "90m" +#define ANSI_BRIGHT_RED ANSI_CSI "91m" +#define ANSI_BRIGHT_GREEN ANSI_CSI "92m" +#define ANSI_BRIGHT_YELLOW ANSI_CSI "93m" +#define ANSI_BRIGHT_BLUE ANSI_CSI "94m" +#define ANSI_BRIGHT_MAGENTA ANSI_CSI "95m" +#define ANSI_BRIGHT_CYAN ANSI_CSI "96m" +#define ANSI_BRIGHT_WHITE ANSI_CSI "97m" diff --git a/include/dbs/subsys.h b/include/dbs/subsys.h new file mode 100644 index 0000000..1885a80 --- /dev/null +++ b/include/dbs/subsys.h @@ -0,0 +1,12 @@ +#ifndef __SUBSYS_H +#define __SUBSYS_H + +int __impl_start_subsystem(char *name, int (*fn)(void)); +#define start_subsystem(fn) __impl_start_subsystem(#fn, fn) +#define declare_subsystem(fn) \ + void subsys_start_##fn(void) { \ + start_subsystem(fn); \ + } \ + l5_initcall(subsys_start_##fn) + +#endif diff --git a/include/dbs/util.h b/include/dbs/util.h new file mode 100644 index 0000000..bad4a33 --- /dev/null +++ b/include/dbs/util.h @@ -0,0 +1,3 @@ +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +#define writeputs(str) write(STDOUT_FILENO, str, strlen(str)); |