1#ifndef __DILLO_MISC_H__
2#define __DILLO_MISC_H__
30 static const char tspecials_space[] =
"()<>@,;:\\\"/[]?= ";
31 const char terminators[] =
" ;\t";
35 if (!disposition || !type || !filename)
44 !strchr(tspecials_space, *s); s++) ;
54 if (!strchr(terminators, *s)) {
61 while (*s ==
' ' || *s ==
'\t')
70 const char key[] =
"filename";
78 if (s != str && !strchr(terminators, s[-1]))
85 while (*s ==
' ' || *s ==
'\t')
96 while (*s ==
' ' || *s ==
'\t')
110 size_t maxlen = strlen(s);
116 for (
size_t i = 1; i < maxlen; i++) {
118 if (s[i - 1] !=
'\\' && s[i] ==
'"') {
131 if ((len = strcspn(s, terminators))) {
137 if (*filename == NULL)
141 const char bad_characters[] =
"/\\|~";
144 char *src =
dStrndup(*filename, len);
145 char *dst = *filename;
149 for (
size_t i = 0; i < len; i++) {
151 if (i + 1 < len && c ==
'\\' && src[i + 1] ==
'\"') {
155 }
else if (strchr(bad_characters, c)) {
char * dStriAsciiStr(const char *haystack, const char *needle)
Case insensitive strstr.
char * dStrndup(const char *s, size_t sz)
static int dIsascii(unsigned char c)
static int dIscntrl(unsigned char c)
int a_Misc_parse_search_url(char *source, char **label, char **urlstr)
Parse dillorc's search_url string ([<label> ]<url>) Return value: -1 on error, 0 on success (and labe...
static void a_Misc_parse_content_disposition(const char *disposition, char **type, char **filename)
Parse Content-Disposition string, e.g., "attachment; filename="file name.jpg"".
int a_Misc_content_type_check(const char *EntryType, const char *DetectedType)
Check the server-supplied 'Content-Type' against our detected type.
void a_Misc_parse_content_type(const char *str, char **major, char **minor, char **charset)
Parse Content-Type string, e.g., "text/html; charset=utf-8".
int a_Misc_expand_tabs(char **start, char *end, char *buf, int buflen)
Takes a string and converts any tabs to spaces.
Dstr * a_Misc_file2dstr(const char *filename)
Load a local file into a dStr.
char * a_Misc_encode_base64(const char *in)
Encodes string using base64 encoding.
char * a_Misc_escape_chars(const char *str, const char *esc_set)
Escape characters as XX sequences.
int a_Misc_parse_geometry(char *geom, int *x, int *y, int *w, int *h)
Parse a geometry string.
int a_Misc_content_type_cmp(const char *ct1, const char *ct2)
Compare two Content-Type strings.
int a_Misc_get_content_type_from_data(void *Data, size_t Size, const char **PT)
Detects 'Content-Type' from a data stream sample.