28 static const char *
const hex =
"0123456789ABCDEF";
34 for (i = 0; str[i]; ++i) {
35 if (str[i] <= 0x1F || str[i] == 0x7F || strchr(esc_set, str[i])) {
56 int j, pos = 0, written = 0, old_pos, char_len;
58 static const int combining_char_space = 32;
60 while (*start < end && written < buflen -
TAB_SIZE - combining_char_space) {
67 for (j = old_pos; j < pos; j++)
70 assert(char_len <= 4);
71 for (j = 0; j < char_len; j++)
72 buf[written++] = (*start)[j];
83 while (*start < end && written < buflen - 4) {
89 assert(char_len <= 4);
90 for (j = 0; j < char_len; j++)
91 buf[written++] = (*start)[j];
106 {
"application/octet-stream", 24 },
107 {
"application/xhtml+xml", 21 },
109 {
"text/plain", 10 },
112 {
"image/jpeg", 10 },
138 size_t i, non_ascci, non_ascci_text, bin_chars;
144 for (i = 0; i < Size &&
dIsspace(p[i]); ++i);
155 }
else if (Size >= 4 && !strncmp(p,
"GIF8", 4)) {
158 }
else if (Size >= 4 && !strncmp(p,
"\x89PNG", 4)) {
161 }
else if (Size >= 2 && !strncmp(p,
"\xff\xd8", 2)) {
178 non_ascci = non_ascci_text = bin_chars = 0;
179 Size =
MIN (Size, 256);
180 for (i = 0; i < Size; i++) {
189 if (bin_chars == 0 && (non_ascci - non_ascci_text) <= Size/10) {
192 }
else if (Size > 0) {
213 static const char tspecials_space[] =
"()<>@,;:\\\"/[]?= ";
226 !strchr(tspecials_space, *s); s++) ;
232 !strchr(tspecials_space, *s); s++) ;
247 const char terminators[] =
" ;\t";
248 const char key[] =
"charset";
251 (s == str || strchr(terminators, s[-1]))) {
252 s +=
sizeof(key) - 1;
253 for ( ; *s ==
' ' || *s ==
'\t'; ++s);
256 for (++s; *s ==
' ' || *s ==
'\t'; ++s);
257 if ((len = strcspn(s, terminators))) {
258 if (*s ==
'"' && s[len-1] ==
'"' && len > 1) {
276 char *major1, *major2, *minor1, *minor2, *charset1, *charset2;
279 if ((!ct1 || !*ct1) && (!ct2 || !*ct2))
281 if ((!ct1 || !*ct1) || (!ct2 || !*ct2))
289 ((!charset1 && !charset2) ||
326 _MSG(
"Type check: [Srv: %s Det: %s]\n", EntryType, DetectedType);
352 _MSG(
"Type check: %s\n", st == 0 ?
"MATCH" :
"MISMATCH");
366 if ((p = strchr(str,
'x')) || (p = strchr(str,
'X'))) {
367 n1 = strtol(str, &t1, 10);
368 n2 = strtol(++p, &t2, 10);
369 if (t1 != str && t2 != p) {
375 n1 = strtol(p, &t1, 10);
376 n2 = strtol(t1, &t2, 10);
377 if (t1 != p && t2 != t1) {
383 _MSG(
"geom: w,h,x,y = (%d,%d,%d,%d)\n", *w, *h, *x, *y);
397 if ((p = strrchr(source,
' '))) {
399 strncpy(buf,source,
MIN(p-source,31));
400 buf[
MIN(p-source,31)] = 0;
402 if ((p = strchr(source,
'/')) && p[1] && (q = strchr(p+2,
'/'))) {
408 if ((p = strchr(source,
'/')) && p[1] && (q = strchr(p+2,
'/'))) {
409 strncpy(buf,p+2,
MIN(q-p-2,31));
410 buf[
MIN(q-p-2,31)] = 0;
417 MSG(
"Invalid search_url: \"%s\"\n", source);
427 static const char *
const base64_hex =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
428 "abcdefghijklmnopqrstuvwxyz"
433 if (in == NULL)
return NULL;
436 out = (
char *)
dMalloc((len + 2) / 3 * 4 + 1);
438 for (; len >= 3; len -= 3) {
439 out[i++] = base64_hex[in[0] >> 2];
440 out[i++] = base64_hex[((in[0]<<4) & 0x30) | (in[1]>>4)];
441 out[i++] = base64_hex[((in[1]<<2) & 0x3c) | (in[2]>>6)];
442 out[i++] = base64_hex[in[2] & 0x3f];
447 unsigned char fragment;
448 out[i++] = base64_hex[in[0] >> 2];
449 fragment = (in[0] << 4) & 0x30;
450 if (len > 1) fragment |= in[1] >> 4;
451 out[i++] = base64_hex[fragment];
452 out[i++] = (len < 2) ?
'=' : base64_hex[(in[1] << 2) & 0x3c];
471 if ((F_in = fopen(filename,
"r"))) {
473 while ((n = fread (buf, 1, 4096, F_in)) > 0) {
int dStrAsciiCasecmp(const char *s1, const char *s2)
Dstr * dStr_sized_new(int sz)
Create a new string with a given size.
int dStrnAsciiCasecmp(const char *s1, const char *s2, size_t n)
void * dMalloc(size_t size)
void dStr_free(Dstr *ds, int all)
Free a dillo string.
char * dStriAsciiStr(const char *haystack, const char *needle)
Case insensitive strstr.
void dStr_append_l(Dstr *ds, const char *s, int l)
Append a C string to a Dstr (providing length).
void dStr_append_c(Dstr *ds, int c)
Append one character.
char * dStrndup(const char *s, size_t sz)
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...
int a_Misc_content_type_check(const char *EntryType, const char *DetectedType)
Check the server-supplied 'Content-Type' against our detected type.
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.
int a_Misc_parse_geometry(char *str, int *x, int *y, int *w, int *h)
Parse a geometry string.
char * a_Misc_encode_base64(const char *in)
Encodes string using base64 encoding.
static const ContentType_t MimeTypes[]
char * a_Misc_escape_chars(const char *str, const char *esc_set)
Escape characters as XX sequences.
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.
void a_Misc_parse_content_type(const char *type, char **major, char **minor, char **charset)
Parse Content-Type string, e.g., "text/html; charset=utf-8".
uint_t a_Utf8_decode(const char *str, const char *end, int *len)
Decode a single UTF-8-encoded character starting at p.
int a_Utf8_test(const char *src, unsigned int srclen)
Examine first srclen bytes of src.
uint_t a_Utf8_end_of_char(const char *str, uint_t i)
Return index of the last byte of the UTF-8-encoded character that str + i points to or into.
bool_t a_Utf8_combining_char(int unicode)