1#include "mupdf/fitz.h"
2#include "fitz-imp.h"
3
4fz_link *
5fz_new_link(fz_context *ctx, fz_rect bbox, void *doc, const char *uri)
6{
7 fz_link *link;
8
9 link = fz_malloc_struct(ctx, fz_link);
10 link->refs = 1;
11 link->rect = bbox;
12 link->next = NULL;
13 link->doc = doc; /* don't take reference */
14 link->uri = NULL;
15
16 fz_try(ctx)
17 link->uri = fz_strdup(ctx, uri);
18 fz_catch(ctx)
19 {
20 fz_drop_link(ctx, link);
21 fz_rethrow(ctx);
22 }
23
24 return link;
25}
26
27fz_link *
28fz_keep_link(fz_context *ctx, fz_link *link)
29{
30 return fz_keep_imp(ctx, link, &link->refs);
31}
32
33void
34fz_drop_link(fz_context *ctx, fz_link *link)
35{
36 while (fz_drop_imp(ctx, link, &link->refs))
37 {
38 fz_link *next = link->next;
39 fz_free(ctx, link->uri);
40 fz_free(ctx, link);
41 link = next;
42 }
43}
44
45int
46fz_is_external_link(fz_context *ctx, const char *uri)
47{
48 while (*uri >= 'a' && *uri <= 'z')
49 ++uri;
50 return uri[0] == ':';
51}
52