~kris/hacks

sbot

ref: a6258c0c45f7c5d08ff77d4bcf9d747a24199a15 sbot/parse.h -rw-r--r-- 1.1 KiB
a6258c0c — Kris Yotam update sbot 6 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
40
41
42
43
44
45
46
47
48
49
50
51
/* See LICENSE file for copyright and license details. */

#ifndef PARSE_H
#define PARSE_H

#include <stddef.h>

/* Resource types */
typedef enum {
    RES_IMAGE,
    RES_CSS,
    RES_FONT,
    RES_PAGE,
    RES_OTHER
} ResourceType;

/* Extracted resource */
typedef struct Resource {
    char *url;
    ResourceType type;
    struct Resource *next;
} Resource;

/* Resource list */
typedef struct {
    Resource *head;
    Resource *tail;
    size_t count;
} ResourceList;

/* Create/destroy resource list */
ResourceList *reslist_new(void);
void reslist_free(ResourceList *list);

/* Add a resource (url is copied) */
void reslist_add(ResourceList *list, const char *url, ResourceType type);

/* Check if URL already in list */
int reslist_contains(ResourceList *list, const char *url);

/* Extract resources from HTML */
ResourceList *parse_html(const char *html, const char *base_url);

/* Extract title from HTML */
char *parse_title(const char *html);

/* Find and inline resources in HTML */
char *inline_resources(const char *html, const char *base_url,
                       char *(*fetch_and_encode)(const char *url, const char *base_url));

#endif /* PARSE_H */