~kris/hacks

sbot

ref: e3abbc9a0c1e91ca48fac4480588c42276b8f538 sbot/util.h -rw-r--r-- 1011 bytes
e3abbc9a — Kris Yotam archiver-bot v0.2: hash table, robots.txt, retry logic 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* See LICENSE file for copyright and license details. */

#ifndef UTIL_H
#define UTIL_H

#include <stddef.h>

/* Memory allocation with error handling */
void *xmalloc(size_t size);
void *xrealloc(void *ptr, size_t size);
char *xstrdup(const char *s);

/* Base64 encoding */
char *base64_encode(const unsigned char *data, size_t input_len,
                    size_t *output_len);

/* String utilities */
int str_starts_with(const char *str, const char *prefix);
int str_ends_with(const char *str, const char *suffix);
char *str_tolower(char *str);
char *str_trim(char *str);

/* URL utilities */
char *url_resolve(const char *base, const char *relative);
char *url_get_domain(const char *url);
int url_same_domain(const char *url1, const char *url2);

/* File utilities */
char *get_mime_type(const char *url);
char *sanitize_filename(const char *url);

/* Time utilities */
char *get_iso_date(void);

/* Error handling */
void die(const char *fmt, ...);
void warn(const char *fmt, ...);

#endif /* UTIL_H */