1
/* Internal bookmarks support - file format backends multiplexing */
2
/* $Id: common.c,v 1.16 2004/01/01 15:12:12 pasky Exp $ */
8
#ifdef CONFIG_BOOKMARKS
16
#include "bfu/listbox.h"
17
#include "bookmarks/bookmarks.h"
18
#include "bookmarks/backend/common.h"
19
#include "lowlevel/home.h"
20
#include "util/memory.h"
21
#include "util/secsave.h"
22
#include "util/string.h"
25
/* Backends dynamic area: */
27
#include "bookmarks/backend/default.h"
28
#include "bookmarks/backend/xbel.h"
30
/* Note that the numbering is static, that means that you have to provide at
31
* least dummy NULL handlers even when no support is compiled in. */
33
static struct bookmarks_backend *bookmarks_backends[] = {
34
&default_bookmarks_backend,
35
&xbel_bookmarks_backend,
39
/* Loads the bookmarks from file */
43
int backend = get_opt_int("bookmarks.file_format");
44
unsigned char *file_name;
47
if (!bookmarks_backends[backend]->read
48
|| !bookmarks_backends[backend]->filename) return;
50
file_name = bookmarks_backends[backend]->filename(0);
51
if (!file_name) return;
53
file_name = straconcat(elinks_home, file_name, NULL);
54
if (!file_name) return;
57
f = fopen(file_name, "r");
58
if (elinks_home) mem_free(file_name);
61
bookmarks_backends[backend]->read(f);
68
bookmarks_write(struct list_head *bookmarks_list)
70
int backend = get_opt_int("bookmarks.file_format");
71
struct secure_save_info *ssi;
72
unsigned char *file_name;
74
if (!bookmarks_dirty) return;
75
if (!bookmarks_backends[backend]->write
77
|| !bookmarks_backends[backend]->filename) return;
79
/* We do this two-passes because we want backend to possibly decide to
80
* return NULL if it's not suitable to save the bookmarks (otherwise
81
* they would be just truncated to zero by secure_open()). */
82
file_name = bookmarks_backends[backend]->filename(1);
83
if (!file_name) return;
84
file_name = straconcat(elinks_home, file_name, NULL);
85
if (!file_name) return;
87
ssi = secure_open(file_name, 0177);
91
bookmarks_backends[backend]->write(ssi, bookmarks_list);
93
if (!secure_close(ssi)) bookmarks_dirty = 0;
96
#endif /* CONFIG_BOOKMARKS */