annotate dpi/bookmarks.c @ 2104:3e7e5395f0bc

non-ASCII keybindings Alexander Voigt has kindly done some testing, and it seems that this makes bindings to most keys on a German keyboard possible -- except those that need AltGr don't work yet.
author corvid <corvid@lavabit.com>
date Thu, 23 Jun 2011 19:24:11 +0000
parents 23fa79dc9664
children
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 * Bookmarks server (chat version).
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
4 * NOTE: this code illustrates how to make a dpi-program.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 *
35
d9e7b35430de Updated copyright lines
jcid
parents: 0
diff changeset
6 * Copyright 2002-2007 Jorge Arellano Cid <jcid@dillo.org>
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 * the Free Software Foundation; either version 3 of the License, or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11 * (at your option) any later version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14
368
2242da885677 - s/todo:/TODO:/g
jcid
parents: 335
diff changeset
15 /* TODO: this server is not assembling the received packets.
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
16 * This means it currently expects dillo to send full dpi tags
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17 * within the socket; if that fails, everything stops.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 * This is not hard to fix, mainly is a matter of expecting the
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19 * final '>' of a tag.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 #include <stdio.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23 #include <stdlib.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24 #include <stddef.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25 #include <string.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26 #include <unistd.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 #include <errno.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28 #include <ctype.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29 #include <sys/socket.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 #include <sys/stat.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31 #include <sys/types.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32 #include <sys/un.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33 #include <time.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
34 #include <netdb.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
35 #include <fcntl.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
36 #include <signal.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
37 #include "../dpip/dpip.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
38 #include "dpiutil.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
39
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
40
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
41 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
42 * Debugging macros
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
43 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
44 #define _MSG(...)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
45 #define MSG(...) printf("[bookmarks dpi]: " __VA_ARGS__)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
46
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 #define DOCTYPE \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48 "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51 * Notes on character escaping:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52 * - Basically things are saved unescaped and escaped when in memory.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53 * - &<>"' are escaped in titles and sections and saved unescaped.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
54 * - ' is escaped as %27 in URLs and saved escaped.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
56 typedef struct {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
57 int key;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
58 int section;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
59 char *url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
60 char *title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
61 } BmRec;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
62
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
63 typedef struct {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
64 int section;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
65 char *title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
66
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
67 int o_sec; /* private, for normalization */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
68 } BmSec;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
69
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
70
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
71 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
72 * Local data
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
73 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74 static char *Header = "Content-type: text/html\n\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
75 static char *BmFile = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
76 static time_t BmFileTimeStamp = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
77 static Dlist *B_bms = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
78 static int bm_key = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
79
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80 static Dlist *B_secs = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
81 static int sec_key = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
82
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
83 static int MODIFY_PAGE_NUM = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
84
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87 * Forward declarations
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
88 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
89
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
90
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
91 /* -- HTML templates ------------------------------------------------------- */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
92
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
93 static const char *mainpage_header =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
94 DOCTYPE
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
95 "<html>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
96 "<head>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
97 "<title>Bookmarks</title>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
98 "</head>\n"
1321
f532c54dea39 add id='dillo_bm' to the body element of bookmark pages
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1236
diff changeset
99 "<body id='dillo_bm' bgcolor='#778899' link='black' vlink='brown'>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
100 "<table border='1' cellpadding='0' width='100%'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
101 " <tr><td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
102 " <table width='100%' bgcolor='#b4b4b4'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
103 " <tr>\n"
1021
6236e198057c [mq]: consistent-delimiter-in-menu-bar.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1020
diff changeset
104 " <td> Bookmarks :: </td>\n"
6236e198057c [mq]: consistent-delimiter-in-menu-bar.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1020
diff changeset
105 " <td align='right'>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
106 " [<a href='dpi:/bm/modify'>modify</a>]\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
107 " </td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
108 " </table></td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
109 "</table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
110 "<br>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
111
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
112 static const char *modifypage_header =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
113 DOCTYPE
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
114 "<html>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
115 "<head>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
116 "<title>Bookmarks</title>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
117 "</head>\n"
1321
f532c54dea39 add id='dillo_bm' to the body element of bookmark pages
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1236
diff changeset
118 "<body id='dillo_bm' bgcolor='#778899' link='black' vlink='brown'>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
119 "<table border='1' cellpadding='0' width='100%'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
120 " <tr><td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
121 " <table width='100%' bgcolor='#b4b4b4'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
122 " <tr>\n"
1022
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
123 " <td> Bookmarks :: modify</td>\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
124 " <td align='right'>\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
125 " [<a href='dpi:/bm/'>cancel</a>]\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
126 " </td>\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
127 " </tr>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
128 " </table></td></tr> \n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
129 "</table> \n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
130 "\n"
1020
b991c2d1adef [mq]: fix-html-warning.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 445
diff changeset
131 "<form action='modify'>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
132 "<table width='100%' border='1' cellpadding='0'>\n"
1023
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
133 " <tr style='background-color: teal'>\n"
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
134 " <td>\n"
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
135 " <b>Select an operation</b>\n"
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
136 " <select name='operation'>\n"
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
137 " <option value='none' selected>--\n"
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
138 " <option value='delete'>Delete\n"
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
139 " <option value='move'>Move\n"
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
140 " <option value='modify'>Modify\n"
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
141 " <option value='add_sec'>Add Section\n"
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
142 " <option value='add_url'>Add URL\n"
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
143 " </select>\n"
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
144 " <b>, mark its operands, and</b>\n"
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
145 " <input type='submit' name='submit' value='submit.'>\n"
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
146 " </td>\n"
679481bb8625 [mq]: fix-width-problem.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1022
diff changeset
147 " </tr>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
148 "</table>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
149
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
150 static const char *mainpage_sections_header =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
151 "<table border='1' cellpadding='0' cellspacing='20' width='100%'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
152 " <tr valign='top'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
153 " <td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
154 " <table bgcolor='#b4b4b4' border='2' cellpadding='4' cellspacing='1'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
155 " <tr><td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
156 " <table width='100%' bgcolor='#b4b4b4'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
157 " <tr><td><small>Sections:</small></td></tr></table></td></tr>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
158
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
159 static const char *modifypage_sections_header =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
160 "<table border='1' cellpadding='0' cellspacing='20' width='100%'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
161 " <tr valign='top'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
162 " <td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
163 " <table bgcolor='#b4b4b4' border='1'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
164 " <tr><td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
165 " <table width='100%' bgcolor='#b4b4b4'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
166 " <tr><td><small>Sections:</small></td></tr></table></td></tr>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
167
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
168 static const char *mainpage_sections_item =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
169 " <tr><td align='center'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
170 " <a href='#s%d'>%s</a></td></tr>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
171
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
172 static const char *modifypage_sections_item =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
173 " <tr><td>\n"
76
4b35f4b6225a minor changes
jcid
parents: 35
diff changeset
174 " <table width='100%%'>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
175 " <tr align='center'>"
76
4b35f4b6225a minor changes
jcid
parents: 35
diff changeset
176 " <td><input type='checkbox' name='s%d'></td>\n"
4b35f4b6225a minor changes
jcid
parents: 35
diff changeset
177 " <td width='100%%'><a href='#s%d'>%s</a></td></tr></table></td></tr>\n";
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
178
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
179 static const char *mainpage_sections_footer =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
180 " </table>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
181
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
182 static const char *modifypage_sections_footer =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
183 " </table>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
184
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
185 static const char *mainpage_middle1 =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
186 " </td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
187 " <td width='100%'>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
188
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
189 static const char *modifypage_middle1 =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
190 " </td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
191 " <td width='100%'>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
192
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
193 static const char *mainpage_section_card_header =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
194 " <a name='s%d'></a>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
195 " <table bgcolor='#bfbfbf' width='100%%' cellspacing='2'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
196 " <tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
197 " <td bgcolor='#bf0c0c'><font color='white'><b>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
198 " &nbsp;&nbsp;&nbsp;%s&nbsp;&nbsp;&nbsp;</b></font></td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
199 " <td bgcolor='white' width='100%%'>&nbsp;</td></tr>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
200
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
201 static const char *modifypage_section_card_header =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
202 " <a name='s%d'></a>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
203 " <table bgcolor='#bfbfbf' width='100%%' cellspacing='2'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
204 " <tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
205 " <td bgcolor='#bf0c0c'><font color='white'><b>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
206 " &nbsp;&nbsp;&nbsp;%s&nbsp;&nbsp;&nbsp;</b></font></td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
207 " <td bgcolor='white' width='100%%'>&nbsp;</td></tr>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
208
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
209 static const char *mainpage_section_card_item =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
210 " <tr><td colspan='2'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
211 " <a href='%s'>%s</a> </td></tr>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
212
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
213 static const char *modifypage_section_card_item =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
214 " <tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
215 " <td colspan='2'><input type='checkbox' name='url%d'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
216 " <a href='%s'>%s</a></td></tr>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
217
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
218 static const char *mainpage_section_card_footer =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
219 " </table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
220 " <hr>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
221
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
222 static const char *modifypage_section_card_footer =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
223 " </table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
224 " <hr>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
225
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
226 static const char *mainpage_footer =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
227 " </td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
228 " </tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
229 "</table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
230 "</body>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
231 "</html>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
232
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
233 static const char *modifypage_footer =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
234 " </td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
235 " </tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
236 "</table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
237 "</form>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
238 "</body>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
239 "</html>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
240
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
241 /* ------------------------------------------------------------------------- */
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
242 static const char *modifypage_add_section_page =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
243 DOCTYPE
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
244 "<html>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
245 "<head>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
246 "<title>Bookmarks</title>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
247 "</head>\n"
1321
f532c54dea39 add id='dillo_bm' to the body element of bookmark pages
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1236
diff changeset
248 "<body id='dillo_bm' bgcolor='#778899' link='black' vlink='brown'>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
249 "<table border='1' cellpadding='0' width='100%'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
250 " <tr><td colspan='2'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
251 " <table bgcolor='#b4b4b4' width='100%'>\n"
1022
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
252 " <tr>\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
253 " <td bgcolor='#b4b4b4'>\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
254 " Modify bookmarks :: add section\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
255 " </td>\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
256 " <td align='right'>\n"
1439
79fcf67eeea0 Fixed bookmarks "cancel" link (Add/Mod URL, Add Sec). Also s/tmp_fd/sock_fd.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1438
diff changeset
257 " [<a href='dpi:/bm/'>cancel</a>]\n"
1022
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
258 " </td>\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
259 " </tr>\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
260 " </table></td></tr>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
261 "</table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
262 "<br>\n"
1020
b991c2d1adef [mq]: fix-html-warning.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 445
diff changeset
263 "<form action='modify'>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
264 " <input type='hidden' name='operation' value='add_section'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
265 "<table border='1' width='100%'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
266 " <tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
267 " <td bgcolor='olive'><b>New&nbsp;section:</b></td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
268 " <td bgcolor='white' width='100%'></td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
269 "</table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
270 "<table width='100%' cellpadding='10'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
271 "<tr><td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
272 " <table width='100%' bgcolor='teal'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
273 " <tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
274 " <td>Title:</td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
275 " <td><input type='text' name='title' size='64'></td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
276 " </table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
277 " </td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
278 "</table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
279 "<table width='100%' cellpadding='4' border='0'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
280 "<tr><td bgcolor='#a0a0a0'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
281 " <input type='submit' name='submit' value='submit.'></td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
282 "</table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
283 "</form>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
284 "</body>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
285 "</html>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
286 "\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
287
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
288 /* ------------------------------------------------------------------------- */
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
289 static const char *modifypage_update_header =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
290 DOCTYPE
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
291 "<html>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
292 "<head>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
293 "<title>Bookmarks</title>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
294 "</head>\n"
1321
f532c54dea39 add id='dillo_bm' to the body element of bookmark pages
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1236
diff changeset
295 "<body id='dillo_bm' bgcolor='#778899' link='black' vlink='brown'>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
296 "<table border='1' cellpadding='0' width='100%'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
297 " <tr><td colspan='2'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
298 " <table bgcolor='#b4b4b4' width='100%'>\n"
1021
6236e198057c [mq]: consistent-delimiter-in-menu-bar.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1020
diff changeset
299 " <tr><td bgcolor='#b4b4b4'> Modify bookmarks :: update\n"
1022
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
300 " </td>\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
301 " <td align='right'>\n"
1439
79fcf67eeea0 Fixed bookmarks "cancel" link (Add/Mod URL, Add Sec). Also s/tmp_fd/sock_fd.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1438
diff changeset
302 " [<a href='dpi:/bm/'>cancel</a>]\n"
1022
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
303 " </td>\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
304 " </tr>\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
305 " </table></td></tr>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
306 "</table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
307 "<br>\n"
1020
b991c2d1adef [mq]: fix-html-warning.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 445
diff changeset
308 "<form action='modify'>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
309 "<input type='hidden' name='operation' value='modify2'>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
310
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
311 static const char *modifypage_update_title =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
312 "<table border='1' width='100%%'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
313 " <tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
314 " <td bgcolor='olive'><b>%s</b></td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
315 " <td bgcolor='white' width='100%%'></td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
316 "</table>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
317
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
318 static const char *modifypage_update_item_header =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
319 "<table width='100%' cellpadding='10'>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
320
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
321 static const char *modifypage_update_item =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
322 "<tr><td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
323 " <table width='100%%' bgcolor='teal'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
324 " <tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
325 " <td>Title:</td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
326 " <td><input type='text' name='title%d' size='64'\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
327 " value='%s'></td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
328 " <tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
329 " <td>URL:</td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
330 " <td>%s</td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
331 " </table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
332 " </td></tr>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
333
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
334 static const char *modifypage_update_item2 =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
335 "<tr><td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
336 " <table width='100%%' bgcolor='teal'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
337 " <tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
338 " <td>Title:</td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
339 " <td><input type='text' name='s%d' size='64'\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
340 " value='%s'></td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
341 " </table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
342 " </td></tr>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
343
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
344 static const char *modifypage_update_item_footer =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
345 "</table>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
346
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
347 static const char *modifypage_update_footer =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
348 "<table width='100%' cellpadding='4' border='0'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
349 "<tr><td bgcolor='#a0a0a0'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
350 " <input type='submit' name='submit' value='submit.'></td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
351 "</table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
352 "</form>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
353 "</body>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
354 "</html>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
355
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
356 /* ------------------------------------------------------------------------- */
83
866d074448f6 - Added more statics in dpi, const in pixmaps, and removed redundant includes.
jcid
parents: 76
diff changeset
357 static const char *modifypage_add_url =
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
358 DOCTYPE
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
359 "<html>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
360 "<head>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
361 "<title>Bookmarks</title>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
362 "</head>\n"
1321
f532c54dea39 add id='dillo_bm' to the body element of bookmark pages
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1236
diff changeset
363 "<body id='dillo_bm' bgcolor='#778899' link='black' vlink='brown'>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
364 "<table border='1' cellpadding='0' width='100%'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
365 " <tr><td colspan='2'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
366 " <table bgcolor='#b4b4b4' width='100%'>\n"
1021
6236e198057c [mq]: consistent-delimiter-in-menu-bar.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1020
diff changeset
367 " <tr><td bgcolor='#b4b4b4'> Modify bookmarks :: add url\n"
1022
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
368 " </td>\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
369 " <td align='right'>\n"
1439
79fcf67eeea0 Fixed bookmarks "cancel" link (Add/Mod URL, Add Sec). Also s/tmp_fd/sock_fd.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1438
diff changeset
370 " [<a href='dpi:/bm/'>cancel</a>]\n"
1022
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
371 " </td>\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
372 " </tr>\n"
429aee7a706e [mq]: abort.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 1021
diff changeset
373 " </table></td></tr>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
374 "</table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
375 "<br>\n"
1020
b991c2d1adef [mq]: fix-html-warning.patch
Justus Winter <justus.winter@informatik.uni-hamburg.de>
parents: 445
diff changeset
376 "<form action='modify'>\n"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
377 "<input type='hidden' name='operation' value='add_url2'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
378 "<table border='1' width='100%'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
379 " <tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
380 " <td bgcolor='olive'><b>Add&nbsp;url:</b></td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
381 " <td bgcolor='white' width='100%'></td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
382 "</table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
383 "<table width='100%' cellpadding='10'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
384 "<tr><td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
385 " <table width='100%' bgcolor='teal'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
386 " <tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
387 " <td>Title:</td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
388 " <td><input type='text' name='title' size='64'></td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
389 " <tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
390 " <td>URL:</td>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
391 " <td><input type='text' name='url' size='64'></td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
392 " </table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
393 " </td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
394 "</table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
395 "<table width='100%' cellpadding='4' border='0'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
396 "<tr><td bgcolor='#a0a0a0'>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
397 " <input type='submit' name='submit' value='submit.'></td></tr>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
398 "</table>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
399 "</form>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
400 "</body>\n"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
401 "</html>\n";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
402
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
403
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
404 /* ------------------------------------------------------------------------- */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
405
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
406 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
407 * Return a new string with spaces changed with &nbsp;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
408 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
409 static char *make_one_line_str(char *str)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
410 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
411 char *new_str;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
412 int i, j, n;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
413
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
414 for (i = 0, n = 0; str[i]; ++i)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
415 if (str[i] == ' ')
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
416 ++n;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
417
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
418 new_str = dNew(char, strlen(str) + 6*n + 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
419 new_str[0] = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
420
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
421 for (i = 0, j = 0; str[i]; ++i) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
422 if (str[i] == ' ') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
423 strcpy(new_str + j, "&nbsp;");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
424 j += 6;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
425 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
426 new_str[j] = str[i];
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
427 new_str[++j] = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
428 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
429 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
430
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
431 return new_str;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
432 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
433
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
434 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
435 * Given an urlencoded string, return it to the original version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
436 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
437 static void Unencode_str(char *e_str)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
438 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
439 char *p, *e;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
440
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
441 for (p = e = e_str; *e; e++, p++) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
442 if (*e == '+') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
443 *p = ' ';
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
444 } else if (*e == '%') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
445 if (dStrncasecmp(e, "%0D%0A", 6) == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
446 *p = '\n';
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
447 e += 5;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
448 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
449 *p = (isdigit(e[1]) ? (e[1] - '0') : (e[1] - 'A' + 10)) * 16 +
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
450 (isdigit(e[2]) ? (e[2] - '0') : (e[2] - 'A' + 10));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
451 e += 2;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
452 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
453 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
454 *p = *e;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
455 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
456 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
457 *p = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
458 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
459
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
460 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
461 * Send a short message to dillo's status bar.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
462 */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
463 static int Bmsrv_dpi_send_status_msg(Dsh *sh, char *str)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
464 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
465 int st;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
466 char *d_cmd;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
467
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
468 d_cmd = a_Dpip_build_cmd("cmd=%s msg=%s", "send_status_message", str);
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
469 st = a_Dpip_dsh_write_str(sh, 1, d_cmd);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
470 dFree(d_cmd);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
471 return st;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
472 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
473
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
474 /* -- ADT for bookmarks ---------------------------------------------------- */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
475 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
476 * Compare function for searching a bookmark by its key
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
477 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
478 static int Bms_node_by_key_cmp(const void *node, const void *key)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
479 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
480 return ((BmRec *)node)->key - VOIDP2INT(key);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
481 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
482
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
483 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
484 * Compare function for searching a bookmark by section
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
485 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
486 static int Bms_node_by_section_cmp(const void *node, const void *key)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
487 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
488 return ((BmRec *)node)->section - VOIDP2INT(key);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
489 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
490
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
491 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
492 * Compare function for searching a section by its number
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
493 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
494 static int Bms_sec_by_number_cmp(const void *node, const void *key)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
495 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
496 return ((BmSec *)node)->section - VOIDP2INT(key);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
497 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
498
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
499 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
500 * Return the Bm record by key
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
501 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
502 static BmRec *Bms_get(int key)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
503 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
504 return dList_find_custom(B_bms, INT2VOIDP(key), Bms_node_by_key_cmp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
505 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
506
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
507 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
508 * Return the Section record by key
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
509 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
510 static BmSec *Bms_get_sec(int key)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
511 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
512 return dList_find_custom(B_secs, INT2VOIDP(key), Bms_sec_by_number_cmp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
513 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
514
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
515 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
516 * Add a bookmark
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
517 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
518 static void Bms_add(int section, char *url, char *title)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
519 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
520 BmRec *bm_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
521
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
522 bm_node = dNew(BmRec, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
523 bm_node->key = ++bm_key;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
524 bm_node->section = section;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
525 bm_node->url = Escape_uri_str(url, "'");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
526 bm_node->title = Escape_html_str(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
527 dList_append(B_bms, bm_node);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
528 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
529
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
530 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
531 * Add a section
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
532 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
533 static void Bms_sec_add(char *title)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
534 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
535 BmSec *sec_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
536
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
537 sec_node = dNew(BmSec, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
538 sec_node->section = sec_key++;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
539 sec_node->title = Escape_html_str(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
540 dList_append(B_secs, sec_node);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
541 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
542
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
543 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
544 * Delete a bookmark by its key
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
545 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
546 static void Bms_del(int key)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
547 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
548 BmRec *bm_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
549
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
550 bm_node = dList_find_custom(B_bms, INT2VOIDP(key), Bms_node_by_key_cmp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
551 if (bm_node) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
552 dList_remove(B_bms, bm_node);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
553 dFree(bm_node->title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
554 dFree(bm_node->url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
555 dFree(bm_node);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
556 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
557 if (dList_length(B_bms) == 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
558 bm_key = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
559 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
560
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
561 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
562 * Delete a section and its bookmarks by section number
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
563 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
564 static void Bms_sec_del(int section)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
565 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
566 BmSec *sec_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
567 BmRec *bm_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
568
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
569 sec_node = dList_find_custom(B_secs, INT2VOIDP(section),
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
570 Bms_sec_by_number_cmp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
571 if (sec_node) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
572 dList_remove(B_secs, sec_node);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
573 dFree(sec_node->title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
574 dFree(sec_node);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
575
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
576 /* iterate B_bms and remove those that match the section */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
577 while ((bm_node = dList_find_custom(B_bms, INT2VOIDP(section),
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
578 Bms_node_by_section_cmp))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
579 Bms_del(bm_node->key);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
580 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
581 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
582 if (dList_length(B_secs) == 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
583 sec_key = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
584 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
585
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
586 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
587 * Move a bookmark to another section
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
588 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
589 static void Bms_move(int key, int target_section)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
590 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
591 BmRec *bm_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
592
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
593 bm_node = dList_find_custom(B_bms, INT2VOIDP(key), Bms_node_by_key_cmp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
594 if (bm_node) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
595 bm_node->section = target_section;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
596 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
597 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
598
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
599 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
600 * Update a bookmark title by key
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
601 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
602 static void Bms_update_title(int key, char *n_title)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
603 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
604 BmRec *bm_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
605
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
606 bm_node = dList_find_custom(B_bms, INT2VOIDP(key), Bms_node_by_key_cmp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
607 if (bm_node) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
608 dFree(bm_node->title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
609 bm_node->title = Escape_html_str(n_title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
610 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
611 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
612
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
613 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
614 * Update a section title by key
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
615 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
616 static void Bms_update_sec_title(int key, char *n_title)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
617 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
618 BmSec *sec_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
619
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
620 sec_node = dList_find_custom(B_secs, INT2VOIDP(key), Bms_sec_by_number_cmp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
621 if (sec_node) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
622 dFree(sec_node->title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
623 sec_node->title = Escape_html_str(n_title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
624 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
625 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
626
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
627 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
628 * Free all the bookmarks data (bookmarks and sections)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
629 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
630 static void Bms_free(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
631 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
632 BmRec *bm_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
633 BmSec *sec_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
634
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
635 /* free B_bms */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
636 while ((bm_node = dList_nth_data(B_bms, 0))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
637 Bms_del(bm_node->key);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
638 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
639 /* free B_secs */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
640 while ((sec_node = dList_nth_data(B_secs, 0))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
641 Bms_sec_del(sec_node->section);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
642 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
643 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
644
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
645 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
646 * Enforce increasing correlative section numbers with no jumps.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
647 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
648 static void Bms_normalize(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
649 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
650 BmRec *bm_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
651 BmSec *sec_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
652 int i, j;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
653
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
654 /* we need at least one section */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
655 if (dList_length(B_secs) == 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
656 Bms_sec_add("Unclassified");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
657
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
658 /* make correlative section numbers */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
659 for (i = 0; (sec_node = dList_nth_data(B_secs, i)); ++i) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
660 sec_node->o_sec = sec_node->section;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
661 sec_node->section = i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
662 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
663
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
664 /* iterate B_secs and make the changes in B_bms */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
665 for (i = 0; (sec_node = dList_nth_data(B_secs, i)); ++i) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
666 if (sec_node->section != sec_node->o_sec) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
667 /* update section numbers */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
668 for (j = 0; (bm_node = dList_nth_data(B_bms, j)); ++j) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
669 if (bm_node->section == sec_node->o_sec)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
670 bm_node->section = sec_node->section;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
671 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
672 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
673 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
674 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
675
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
676 /* -- Load bookmarks file -------------------------------------------------- */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
677
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
678 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
679 * If there's no "bm.txt", create one from "bookmarks.html".
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
680 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
681 static void Bms_check_import(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
682 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
683 char *OldBmFile;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
684 char *cmd1 =
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
685 "echo \":s0: Unclassified\" > %s";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
686 char *cmd2 =
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
687 "grep -i \"href\" %s | "
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
688 "sed -e 's/<li><A HREF=\"/s0 /' -e 's/\">/ /' -e 's/<.*$//' >> %s";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
689 Dstr *dstr = dStr_new("");
1200
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1023
diff changeset
690 int rc;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
691
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
692
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
693 if (access(BmFile, F_OK) != 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
694 OldBmFile = dStrconcat(dGethomedir(), "/.dillo/bookmarks.html", NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
695 if (access(OldBmFile, F_OK) == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
696 dStr_sprintf(dstr, cmd1, BmFile);
1200
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1023
diff changeset
697 rc = system(dstr->str);
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1023
diff changeset
698 if (rc == 127) {
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1023
diff changeset
699 MSG("Bookmarks: /bin/sh could not be executed\n");
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1023
diff changeset
700 } else if (rc == -1) {
1326
02ef25700865 trim some spaces
corvid <corvid@lavabit.com>
parents: 1321
diff changeset
701 MSG("Bookmarks: process creation failure: %s\n",
1200
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1023
diff changeset
702 dStrerror(errno));
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1023
diff changeset
703 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
704 dStr_sprintf(dstr, cmd2, OldBmFile, BmFile);
1200
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1023
diff changeset
705 rc = system(dstr->str);
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1023
diff changeset
706 if (rc == 127) {
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1023
diff changeset
707 MSG("Bookmarks: /bin/sh could not be executed\n");
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1023
diff changeset
708 } else if (rc == -1) {
1326
02ef25700865 trim some spaces
corvid <corvid@lavabit.com>
parents: 1321
diff changeset
709 MSG("Bookmarks: process creation failure: %s\n",
1200
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1023
diff changeset
710 dStrerror(errno));
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1023
diff changeset
711 }
6bdf6ea2637a Removed compiler warnings for unused return values
Michal Nowak newman.x@gmail.com
parents: 1023
diff changeset
712
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
713 dStr_free(dstr, TRUE);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
714 dFree(OldBmFile);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
715 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
716 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
717 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
718
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
719 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
720 * Load bookmarks data from a file
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
721 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
722 static int Bms_load(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
723 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
724 FILE *BmTxt;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
725 char *buf, *p, *url, *title, *u_title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
726 int section;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
727 struct stat TimeStamp;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
728
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
729 /* clear current bookmarks */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
730 Bms_free();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
731
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
732 /* open bm file */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
733 if (!(BmTxt = fopen(BmFile, "r"))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
734 perror("[fopen]");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
735 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
736 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
737
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
738 /* load bm file into memory */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
739 while ((buf = dGetline(BmTxt)) != NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
740 if (buf[0] == 's') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
741 /* get section, url and title */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
742 section = strtol(buf + 1, NULL, 10);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
743 p = strchr(buf, ' '); *p = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
744 url = ++p;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
745 p = strchr(p, ' '); *p = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
746 title = ++p;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
747 p = strchr(p, '\n'); *p = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
748 u_title = Unescape_html_str(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
749 Bms_add(section, url, u_title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
750 dFree(u_title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
751
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
752 } else if (buf[0] == ':' && buf[1] == 's') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
753 /* section = strtol(buf + 2, NULL, 10); */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
754 p = strchr(buf + 2, ' ');
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
755 title = ++p;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
756 p = strchr(p, '\n'); *p = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
757 Bms_sec_add(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
758
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
759 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
760 MSG("Syntax error in bookmarks file:\n %s", buf);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
761 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
762 dFree(buf);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
763 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
764 fclose(BmTxt);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
765
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
766 /* keep track of the timestamp */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
767 stat(BmFile, &TimeStamp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
768 BmFileTimeStamp = TimeStamp.st_mtime;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
769
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
770 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
771 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
772
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
773 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
774 * Load bookmarks data if:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
775 * - file timestamp is newer than ours or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
776 * - we haven't loaded anything yet :)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
777 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
778 static int Bms_cond_load(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
779 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
780 int st = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
781 struct stat TimeStamp;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
782
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
783 if (stat(BmFile, &TimeStamp) != 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
784 /* try to import... */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
785 Bms_check_import();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
786 if (stat(BmFile, &TimeStamp) != 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
787 TimeStamp.st_mtime = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
788 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
789
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
790 if (!BmFileTimeStamp || !dList_length(B_bms) || !dList_length(B_secs) ||
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
791 BmFileTimeStamp < TimeStamp.st_mtime) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
792 Bms_load();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
793 st = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
794 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
795 return st;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
796 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
797
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
798 /* -- Save bookmarks file -------------------------------------------------- */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
799
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
800 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
801 * Update the bookmarks file from memory contents
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
802 * Return code: { 0:OK, 1:Abort }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
803 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
804 static int Bms_save(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
805 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
806 FILE *BmTxt;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
807 BmRec *bm_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
808 BmSec *sec_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
809 struct stat BmStat;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
810 char *u_title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
811 int i, j;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
812 Dstr *dstr = dStr_new("");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
813
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
814 /* make a safety backup */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
815 if (stat(BmFile, &BmStat) == 0 && BmStat.st_size > 256) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
816 char *BmFileBak = dStrconcat(BmFile, ".bak", NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
817 rename(BmFile, BmFileBak);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
818 dFree(BmFileBak);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
819 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
820
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
821 /* open bm file */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
822 if (!(BmTxt = fopen(BmFile, "w"))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
823 perror("[fopen]");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
824 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
825 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
826
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
827 /* normalize */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
828 Bms_normalize();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
829
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
830 /* save sections */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
831 for (i = 0; (sec_node = dList_nth_data(B_secs, i)); ++i) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
832 u_title = Unescape_html_str(sec_node->title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
833 dStr_sprintf(dstr, ":s%d: %s\n", sec_node->section, u_title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
834 fwrite(dstr->str, (size_t)dstr->len, 1, BmTxt);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
835 dFree(u_title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
836 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
837
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
838 /* save bookmarks (section url title) */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
839 for (i = 0; (sec_node = dList_nth_data(B_secs, i)); ++i) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
840 for (j = 0; (bm_node = dList_nth_data(B_bms, j)); ++j) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
841 if (bm_node->section == sec_node->section) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
842 u_title = Unescape_html_str(bm_node->title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
843 dStr_sprintf(dstr, "s%d %s %s\n",
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
844 bm_node->section, bm_node->url, u_title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
845 fwrite(dstr->str, (size_t)dstr->len, 1, BmTxt);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
846 dFree(u_title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
847 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
848 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
849 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
850
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
851 dStr_free(dstr, TRUE);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
852 fclose(BmTxt);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
853
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
854 /* keep track of the timestamp */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
855 stat(BmFile, &BmStat);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
856 BmFileTimeStamp = BmStat.st_mtime;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
857
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
858 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
859 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
860
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
861 /* -- Add bookmark --------------------------------------------------------- */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
862
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
863 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
864 * Add a new bookmark to DB :)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
865 */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
866 static int Bmsrv_add_bm(Dsh *sh, char *url, char *title)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
867 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
868 char *u_title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
869 char *msg="Added bookmark!";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
870 int section = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
871
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
872 /* Add in memory */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
873 u_title = Unescape_html_str(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
874 Bms_add(section, url, u_title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
875 dFree(u_title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
876
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
877 /* Write to file */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
878 Bms_save();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
879
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
880 if (Bmsrv_dpi_send_status_msg(sh, msg))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
881 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
882
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
883 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
884 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
885
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
886 /* -- Modify --------------------------------------------------------------- */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
887
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
888 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
889 * Count how many sections and urls were marked in a request
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
890 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
891 static void Bmsrv_count_urls_and_sections(char *url, int *n_sec, int *n_url)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
892 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
893 char *p, *q;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
894 int i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
895
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
896 /* Check marked urls and sections */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
897 *n_sec = *n_url = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
898 if ((p = strchr(url, '?'))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
899 for (q = p; (q = strstr(q, "&url")); ++q) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
900 for (i = 0; isdigit(q[4+i]); ++i);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
901 *n_url += (q[4+i] == '=') ? 1 : 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
902 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
903 for (q = p; (q = strstr(q, "&s")); ++q) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
904 for (i = 0; isdigit(q[2+i]); ++i);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
905 *n_sec += (q[2+i] == '=') ? 1 : 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
906 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
907 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
908 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
909
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
910 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
911 * Send a dpi reload request
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
912 * Return code: { 0:OK, 1:Abort, 2:Close }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
913 */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
914 static int Bmsrv_send_reload_request(Dsh *sh, char *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
915 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
916 int st;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
917 char *d_cmd;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
918
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
919 d_cmd = a_Dpip_build_cmd("cmd=%s url=%s", "reload_request", url);
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
920 st = a_Dpip_dsh_write_str(sh, 1, d_cmd) ? 1 : 0;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
921 dFree(d_cmd);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
922 return st;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
923 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
924
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
925 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
926 * Send the HTML for the modify page
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
927 * Return code: { 0:OK, 1:Abort, 2:Close }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
928 */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
929 static int Bmsrv_send_modify_page(Dsh *sh)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
930 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
931 static Dstr *dstr = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
932 char *l_title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
933 BmSec *sec_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
934 BmRec *bm_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
935 int i, j;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
936
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
937 if (!dstr)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
938 dstr = dStr_new("");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
939
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
940 /* send modify page header */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
941 if (a_Dpip_dsh_write_str(sh, 0, modifypage_header))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
942 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
943
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
944 /* write sections header */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
945 if (a_Dpip_dsh_write_str(sh, 0, modifypage_sections_header))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
946 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
947 /* write sections */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
948 for (i = 0; (sec_node = dList_nth_data(B_secs, i)); ++i) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
949 dStr_sprintf(dstr, modifypage_sections_item,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
950 sec_node->section, sec_node->section, sec_node->title);
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
951 if (a_Dpip_dsh_write_str(sh, 0, dstr->str))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
952 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
953 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
954 /* write sections footer */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
955 if (a_Dpip_dsh_write_str(sh, 0, modifypage_sections_footer))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
956 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
957
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
958 /* send page middle */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
959 if (a_Dpip_dsh_write_str(sh, 0, modifypage_middle1))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
960 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
961
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
962 /* send bookmark cards */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
963 for (i = 0; (sec_node = dList_nth_data(B_secs, i)); ++i) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
964 /* send card header */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
965 l_title = make_one_line_str(sec_node->title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
966 dStr_sprintf(dstr, modifypage_section_card_header,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
967 sec_node->section, l_title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
968 dFree(l_title);
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
969 if (a_Dpip_dsh_write_str(sh, 0, dstr->str))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
970 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
971
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
972 /* send section's bookmarks */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
973 for (j = 0; (bm_node = dList_nth_data(B_bms, j)); ++j) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
974 if (bm_node->section == sec_node->section) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
975 dStr_sprintf(dstr, modifypage_section_card_item,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
976 bm_node->key, bm_node->url, bm_node->title);
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
977 if (a_Dpip_dsh_write_str(sh, 0, dstr->str))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
978 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
979 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
980 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
981
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
982 /* send card footer */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
983 if (a_Dpip_dsh_write_str(sh, 0, modifypage_section_card_footer))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
984 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
985 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
986
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
987 /* finish page */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
988 if (a_Dpip_dsh_write_str(sh, 1, modifypage_footer))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
989 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
990
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
991 return 2;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
992 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
993
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
994 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
995 * Send the HTML for the modify page for "add section"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
996 * Return code: { 0:OK, 1:Abort, 2:Close }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
997 */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
998 static int Bmsrv_send_modify_page_add_section(Dsh *sh)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
999 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1000 /* send modify page2 */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1001 if (a_Dpip_dsh_write_str(sh, 1, modifypage_add_section_page))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1002 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1003
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1004 return 2;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1005 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1006
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1007 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1008 * Send the HTML for the modify page for "add url"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1009 * Return code: { 0:OK, 1:Abort, 2:Close }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1010 */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1011 static int Bmsrv_send_modify_page_add_url(Dsh *sh)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1012 {
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1013 if (a_Dpip_dsh_write_str(sh, 1, modifypage_add_url))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1014 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1015 return 2;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1016 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1017
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1018 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1019 * Parse a modify urls request and either:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1020 * - make a local copy of the url
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1021 * or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1022 * - send the modify page for the marked urls and sections
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1023 * Return code: { 0:OK, 1:Abort, 2:Close }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1024 */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1025 static int Bmsrv_send_modify_update(Dsh *sh, char *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1026 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1027 static char *url1 = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1028 static Dstr *dstr = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1029 char *p, *q;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1030 int i, key, n_sec, n_url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1031 BmRec *bm_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1032 BmSec *sec_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1033
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1034 /* bookmarks were loaded before */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1035
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1036 if (!dstr)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1037 dstr = dStr_new("");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1038
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1039 if (sh == NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1040 /* just copy url */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1041 dFree(url1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1042 url1 = dStrdup(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1043 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1044 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1045
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1046 /* send HTML here */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1047 if (a_Dpip_dsh_write_str(sh, 0, modifypage_update_header))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1048 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1049
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1050 /* Count number of marked urls and sections */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1051 Bmsrv_count_urls_and_sections(url1, &n_sec, &n_url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1052
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1053 if (n_sec) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1054 dStr_sprintf(dstr, modifypage_update_title, "Update&nbsp;sections:");
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1055 a_Dpip_dsh_write_str(sh, 0, dstr->str);
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1056 a_Dpip_dsh_write_str(sh, 0, modifypage_update_item_header);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1057 /* send items here */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1058 p = strchr(url1, '?');
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1059 for (q = p; (q = strstr(q, "&s")); ++q) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1060 for (i = 0; isdigit(q[2+i]); ++i);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1061 if (q[2+i] == '=') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1062 key = strtol(q + 2, NULL, 10);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1063 if ((sec_node = Bms_get_sec(key))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1064 dStr_sprintf(dstr, modifypage_update_item2,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1065 sec_node->section, sec_node->title);
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1066 a_Dpip_dsh_write_str(sh, 0, dstr->str);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1067 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1068 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1069 }
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1070 a_Dpip_dsh_write_str(sh, 0, modifypage_update_item_footer);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1071 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1072
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1073 if (n_url) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1074 dStr_sprintf(dstr, modifypage_update_title, "Update&nbsp;titles:");
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1075 a_Dpip_dsh_write_str(sh, 0, dstr->str);
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1076 a_Dpip_dsh_write_str(sh, 0, modifypage_update_item_header);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1077 /* send items here */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1078 p = strchr(url1, '?');
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1079 for (q = p; (q = strstr(q, "&url")); ++q) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1080 for (i = 0; isdigit(q[4+i]); ++i);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1081 if (q[4+i] == '=') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1082 key = strtol(q + 4, NULL, 10);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1083 bm_node = Bms_get(key);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1084 dStr_sprintf(dstr, modifypage_update_item,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1085 bm_node->key, bm_node->title, bm_node->url);
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1086 a_Dpip_dsh_write_str(sh, 0, dstr->str);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1087 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1088 }
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1089 a_Dpip_dsh_write_str(sh, 0, modifypage_update_item_footer);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1090 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1091
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1092 a_Dpip_dsh_write_str(sh, 1, modifypage_update_footer);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1093
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1094 return 2;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1095 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1096
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1097 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1098 * Make the modify-page and send it back
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1099 * Return code: { 0:OK, 1:Abort, 2:Close }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1100 */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1101 static int Bmsrv_send_modify_answer(Dsh *sh, char *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1102 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1103 char *d_cmd;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1104 int st;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1105
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1106 d_cmd = a_Dpip_build_cmd("cmd=%s url=%s", "start_send_page", url);
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1107 st = a_Dpip_dsh_write_str(sh, 1, d_cmd);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1108 dFree(d_cmd);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1109 if (st != 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1110 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1111
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1112 /* Send HTTP header */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1113 if (a_Dpip_dsh_write_str(sh, 0, Header) != 0) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1114 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1115 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1116
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1117 if (MODIFY_PAGE_NUM == 2) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1118 MODIFY_PAGE_NUM = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1119 return Bmsrv_send_modify_page_add_section(sh);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1120 } else if (MODIFY_PAGE_NUM == 3) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1121 MODIFY_PAGE_NUM = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1122 return Bmsrv_send_modify_update(sh, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1123 } else if (MODIFY_PAGE_NUM == 4) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1124 MODIFY_PAGE_NUM = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1125 return Bmsrv_send_modify_page_add_url(sh);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1126 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1127 return Bmsrv_send_modify_page(sh);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1128 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1129 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1130
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1131
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1132 /* Operations */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1133
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1134 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1135 * Parse a delete bms request, delete them, and update bm file.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1136 * Return code: { 0:OK, 1:Abort }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1137 */
335
4a6db4341660 - Made several cleanups according to compiler warnings with "-W -Wall".
jcid
parents: 83
diff changeset
1138 static int Bmsrv_modify_delete(char *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1139 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1140 char *p;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1141 int nb, ns, key;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1142
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1143 /* bookmarks were loaded before */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1144
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1145 /* Remove marked sections */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1146 p = strchr(url, '?');
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1147 for (ns = 0; (p = strstr(p, "&s")); ++p) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1148 if (isdigit(p[2])) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1149 key = strtol(p + 2, NULL, 10);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1150 Bms_sec_del(key);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1151 ++ns;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1152 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1153 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1154
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1155 /* Remove marked urls */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1156 p = strchr(url, '?');
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1157 for (nb = 0; (p = strstr(p, "&url")); ++p) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1158 if (isdigit(p[4])) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1159 key = strtol(p + 4, NULL, 10);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1160 Bms_del(key);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1161 ++nb;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1162 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1163 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1164
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1165 /* -- This doesn't work because dillo erases the message upon the
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1166 * receipt of the first data stream.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1167 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1168 sprintf(msg, "Deleted %d bookmark%s!>", n, (n > 1) ? "s" : "");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1169 if (Bmsrv_dpi_send_status_msg(sh, msg))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1170 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1171 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1172
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1173 /* Write new bookmarks file */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1174 if (nb || ns)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1175 Bms_save();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1176
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1177 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1178 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1179
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1180 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1181 * Parse a move urls request, move and update bm file.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1182 * Return code: { 0:OK, 1:Abort }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1183 */
335
4a6db4341660 - Made several cleanups according to compiler warnings with "-W -Wall".
jcid
parents: 83
diff changeset
1184 static int Bmsrv_modify_move(char *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1185 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1186 char *p;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1187 int n, section = 0, key;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1188
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1189 /* bookmarks were loaded before */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1190
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1191 /* get target section */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1192 for (p = url; (p = strstr(p, "&s")); ++p) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1193 if (isdigit(p[2])) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1194 section = strtol(p + 2, NULL, 10);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1195 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1196 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1197 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1198 if (!p)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1199 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1200
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1201 /* move marked urls */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1202 p = strchr(url, '?');
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1203 for (n = 0; (p = strstr(p, "&url")); ++p) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1204 if (isdigit(p[4])) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1205 key = strtol(p + 4, NULL, 10);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1206 Bms_move(key, section);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1207 ++n;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1208 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1209 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1210
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1211 /* Write new bookmarks file */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1212 if (n) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1213 Bms_save();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1214 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1215
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1216 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1217 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1218
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1219 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1220 * Parse a modify request: update urls and sections, then save.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1221 * Return code: { 0:OK, 1:Abort }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1222 */
335
4a6db4341660 - Made several cleanups according to compiler warnings with "-W -Wall".
jcid
parents: 83
diff changeset
1223 static int Bmsrv_modify_update(char *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1224 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1225 char *p, *q, *title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1226 int i, key;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1227
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1228 /* bookmarks were loaded before */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1229
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1230 p = strchr(url, '?');
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1231 for ( ; (p = strstr(p, "s")); ++p) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1232 if (p[-1] == '&' || p[-1] == '?' ) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1233 for (i = 0; isdigit(p[1 + i]); ++i);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1234 if (i && p[1 + i] == '=') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1235 /* we have a title/key to change */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1236 key = strtol(p + 1, NULL, 10);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1237 if ((q = strchr(p + 1, '&')))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1238 title = dStrndup(p + 2 + i, (uint_t)(q - (p + 2 + i)));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1239 else
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1240 title = dStrdup(p + 2 + i);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1241
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1242 Unencode_str(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1243 Bms_update_sec_title(key, title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1244 dFree(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1245 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1246 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1247 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1248
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1249 p = strchr(url, '?');
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1250 for ( ; (p = strstr(p, "title")); ++p) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1251 if (p[-1] == '&' || p[-1] == '?' ) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1252 for (i = 0; isdigit(p[5 + i]); ++i);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1253 if (i && p[5 + i] == '=') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1254 /* we have a title/key to change */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1255 key = strtol(p + 5, NULL, 10);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1256 if ((q = strchr(p + 5, '&')))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1257 title = dStrndup(p + 6 + i, (uint_t)(q - (p + 6 + i)));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1258 else
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1259 title = dStrdup(p + 6 + i);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1260
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1261 Unencode_str(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1262 Bms_update_title(key, title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1263 dFree(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1264 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1265 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1266 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1267
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1268 /* Write new bookmarks file */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1269 Bms_save();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1270
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1271 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1272 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1273
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1274 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1275 * Parse an "add section" request, and update the bm file.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1276 * Return code: { 0:OK, 1:Abort }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1277 */
335
4a6db4341660 - Made several cleanups according to compiler warnings with "-W -Wall".
jcid
parents: 83
diff changeset
1278 static int Bmsrv_modify_add_section(char *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1279 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1280 char *p, *title = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1281
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1282 /* bookmarks were loaded before */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1283
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1284 /* get new section's title */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1285 if ((p = strstr(url, "&title="))) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1286 title = dStrdup (p + 7);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1287 if ((p = strchr(title, '&')))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1288 *p = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1289 Unencode_str(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1290 } else
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1291 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1292
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1293 Bms_sec_add(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1294 dFree(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1295
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1296 /* Write new bookmarks file */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1297 Bms_save();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1298
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1299 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1300 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1301
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1302 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1303 * Parse an "add url" request, and update the bm file.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1304 * Return code: { 0:OK, 1:Abort }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1305 */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1306 static int Bmsrv_modify_add_url(Dsh *sh, char *s_url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1307 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1308 char *p, *q, *title, *u_title, *url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1309 int i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1310 static int section = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1311
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1312 /* bookmarks were loaded before */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1313
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1314 if (sh == NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1315 /* look for section */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1316 for (q = s_url; (q = strstr(q, "&s")); ++q) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1317 for (i = 0; isdigit(q[2+i]); ++i);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1318 if (q[2+i] == '=')
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1319 section = strtol(q + 2, NULL, 10);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1320 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1321 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1322 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1323
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1324 if (!(p = strstr(s_url, "&title=")) ||
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1325 !(q = strstr(s_url, "&url=")))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1326 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1327
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1328 title = dStrdup (p + 7);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1329 if ((p = strchr(title, '&')))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1330 *p = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1331 url = dStrdup (q + 5);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1332 if ((p = strchr(url, '&')))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1333 *p = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1334 if (strlen(title) && strlen(url)) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1335 Unencode_str(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1336 Unencode_str(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1337 u_title = Unescape_html_str(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1338 Bms_add(section, url, u_title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1339 dFree(u_title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1340 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1341 dFree(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1342 dFree(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1343 section = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1344
368
2242da885677 - s/todo:/TODO:/g
jcid
parents: 335
diff changeset
1345 /* TODO: we should send an "Bookmark added" message, but the
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1346 msg-after-HTML functionallity is still pending, not hard though. */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1347
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1348 /* Write new bookmarks file */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1349 Bms_save();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1350
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1351 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1352 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1353
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1354 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1355 * Check the parameters of a modify request, and return an error message
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1356 * when it's wrong.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1357 * Return code: { 0:OK, 2:Close }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1358 */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1359 static int Bmsrv_check_modify_request(Dsh *sh, char *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1360 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1361 char *p, *msg;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1362 int n_sec, n_url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1363
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1364 /* Count number of marked urls and sections */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1365 Bmsrv_count_urls_and_sections(url, &n_sec, &n_url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1366
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1367 p = strchr(url, '?');
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1368 if (strstr(p, "operation=delete&")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1369 if (n_url || n_sec)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1370 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1371 msg = "Delete: you must mark what to delete!";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1372
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1373 } else if (strstr(url, "operation=move&")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1374 if (n_url && n_sec)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1375 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1376 else if (n_url)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1377 msg = "Move: you must mark a target section!";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1378 else if (n_sec)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1379 msg = "Move: can not move a section (yet).";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1380 else
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1381 msg = "Move: you must mark some urls, and a target section!";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1382
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1383 } else if (strstr(url, "operation=modify&")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1384 if (n_url || n_sec)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1385 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1386 msg = "Modify: you must mark what to update!";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1387
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1388 } else if (strstr(url, "operation=modify2&")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1389 /* nothing to check here */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1390 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1391
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1392 } else if (strstr(url, "operation=add_sec&")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1393 /* nothing to check here */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1394 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1395
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1396 } else if (strstr(url, "operation=add_section&")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1397 /* nothing to check here */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1398 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1399
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1400 } else if (strstr(url, "operation=add_url&")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1401 if (n_sec <= 1)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1402 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1403 msg = "Add url: only one target section is allowed!";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1404
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1405 } else if (strstr(url, "operation=add_url2&")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1406 /* nothing to check here */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1407 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1408
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1409 } else if (strstr(url, "operation=none&")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1410 msg = "No operation, just do nothing!";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1411
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1412 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1413 msg = "Sorry, not implemented yet.";
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1414 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1415
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1416 Bmsrv_dpi_send_status_msg(sh, msg);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1417 return 2;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1418 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1419
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1420 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1421 * Parse a and process a modify request.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1422 * Return code: { 0:OK, 1:Abort, 2:Close }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1423 */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1424 static int Bmsrv_process_modify_request(Dsh *sh, char *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1425 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1426 /* check the provided parameters */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1427 if (Bmsrv_check_modify_request(sh, url) != 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1428 return 2;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1429
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1430 if (strstr(url, "operation=delete&")) {
335
4a6db4341660 - Made several cleanups according to compiler warnings with "-W -Wall".
jcid
parents: 83
diff changeset
1431 if (Bmsrv_modify_delete(url) == 1)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1432 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1433 if (Bmsrv_send_reload_request(sh, "dpi:/bm/modify") == 1)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1434 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1435
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1436 } else if (strstr(url, "operation=move&")) {
335
4a6db4341660 - Made several cleanups according to compiler warnings with "-W -Wall".
jcid
parents: 83
diff changeset
1437 if (Bmsrv_modify_move(url) == 1)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1438 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1439 if (Bmsrv_send_reload_request(sh, "dpi:/bm/modify") == 1)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1440 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1441
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1442 } else if (strstr(url, "operation=modify&")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1443 /* make a local copy of 'url' */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1444 Bmsrv_send_modify_update(NULL, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1445 MODIFY_PAGE_NUM = 3;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1446 if (Bmsrv_send_reload_request(sh, "dpi:/bm/modify") == 1)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1447 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1448
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1449 } else if (strstr(url, "operation=modify2&")) {
335
4a6db4341660 - Made several cleanups according to compiler warnings with "-W -Wall".
jcid
parents: 83
diff changeset
1450 if (Bmsrv_modify_update(url) == 1)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1451 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1452 if (Bmsrv_send_reload_request(sh, "dpi:/bm/modify") == 1)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1453 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1454
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1455 } else if (strstr(url, "operation=add_sec&")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1456 /* this global variable tells which page to send (--hackish...) */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1457 MODIFY_PAGE_NUM = 2;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1458 if (Bmsrv_send_reload_request(sh, "dpi:/bm/modify") == 1)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1459 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1460
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1461 } else if (strstr(url, "operation=add_section&")) {
335
4a6db4341660 - Made several cleanups according to compiler warnings with "-W -Wall".
jcid
parents: 83
diff changeset
1462 if (Bmsrv_modify_add_section(url) == 1)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1463 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1464 if (Bmsrv_send_reload_request(sh, "dpi:/bm/modify") == 1)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1465 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1466
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1467 } else if (strstr(url, "operation=add_url&")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1468 /* this global variable tells which page to send (--hackish...) */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1469 MODIFY_PAGE_NUM = 4;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1470 /* parse section if present */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1471 Bmsrv_modify_add_url(NULL, url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1472 if (Bmsrv_send_reload_request(sh, "dpi:/bm/modify") == 1)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1473 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1474
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1475 } else if (strstr(url, "operation=add_url2&")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1476 if (Bmsrv_modify_add_url(sh, url) == 1)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1477 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1478 if (Bmsrv_send_reload_request(sh, "dpi:/bm/modify") == 1)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1479 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1480 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1481
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1482 return 2;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1483 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1484
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1485 /* -- Bookmarks ------------------------------------------------------------ */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1486
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1487 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1488 * Send the current bookmarks page (in HTML)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1489 */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1490 static int send_bm_page(Dsh *sh)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1491 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1492 static Dstr *dstr = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1493 char *l_title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1494 BmSec *sec_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1495 BmRec *bm_node;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1496 int i, j;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1497
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1498 if (!dstr)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1499 dstr = dStr_new("");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1500
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1501 if (a_Dpip_dsh_write_str(sh, 0, mainpage_header))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1502 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1503
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1504 /* write sections header */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1505 if (a_Dpip_dsh_write_str(sh, 0, mainpage_sections_header))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1506 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1507 /* write sections */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1508 for (i = 0; (sec_node = dList_nth_data(B_secs, i)); ++i) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1509 dStr_sprintf(dstr, mainpage_sections_item,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1510 sec_node->section, sec_node->title);
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1511 if (a_Dpip_dsh_write_str(sh, 0, dstr->str))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1512 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1513 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1514 /* write sections footer */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1515 if (a_Dpip_dsh_write_str(sh, 0, mainpage_sections_footer))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1516 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1517
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1518 /* send page middle */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1519 if (a_Dpip_dsh_write_str(sh, 0, mainpage_middle1))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1520 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1521
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1522 /* send bookmark cards */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1523 for (i = 0; (sec_node = dList_nth_data(B_secs, i)); ++i) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1524 /* send card header */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1525 l_title = make_one_line_str(sec_node->title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1526 dStr_sprintf(dstr, mainpage_section_card_header,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1527 sec_node->section, l_title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1528 dFree(l_title);
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1529 if (a_Dpip_dsh_write_str(sh, 0, dstr->str))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1530 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1531
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1532 /* send section's bookmarks */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1533 for (j = 0; (bm_node = dList_nth_data(B_bms, j)); ++j) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1534 if (bm_node->section == sec_node->section) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1535 dStr_sprintf(dstr, mainpage_section_card_item,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1536 bm_node->url, bm_node->title);
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1537 if (a_Dpip_dsh_write_str(sh, 0, dstr->str))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1538 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1539 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1540 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1541
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1542 /* send card footer */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1543 if (a_Dpip_dsh_write_str(sh, 0, mainpage_section_card_footer))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1544 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1545 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1546
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1547 /* finish page */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1548 if (a_Dpip_dsh_write_str(sh, 1, mainpage_footer))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1549 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1550
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1551 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1552 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1553
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1554
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1555 /* -- Dpi parser ----------------------------------------------------------- */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1556
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1557 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1558 * Parse a data stream (dpi protocol)
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1559 * Note: Buf is a dpip token (zero terminated string)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1560 * Return code: { 0:OK, 1:Abort, 2:Close }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1561 */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1562 static int Bmsrv_parse_token(Dsh *sh, char *Buf)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1563 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1564 static char *msg1=NULL, *msg2=NULL, *msg3=NULL;
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1565 char *cmd, *d_cmd, *url, *title, *msg;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1566 size_t BufSize;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1567 int st;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1568
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1569 if (!msg1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1570 /* Initialize data for the "chat" command. */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1571 msg1 = a_Dpip_build_cmd("cmd=%s msg=%s", "chat", "Hi browser");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1572 msg2 = a_Dpip_build_cmd("cmd=%s msg=%s", "chat", "Is it worth?");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1573 msg3 = a_Dpip_build_cmd("cmd=%s msg=%s", "chat", "Ok, send it");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1574 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1575
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1576 if (sh->mode & DPIP_RAW) {
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1577 MSG("ERROR: Unhandled DPIP_RAW mode!\n");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1578 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1579 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1580
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1581 BufSize = strlen(Buf);
1236
b912173aecd1 Added a_Dpip_get_attr_l() to DPIP's API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
1582 cmd = a_Dpip_get_attr_l(Buf, BufSize, "cmd");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1583
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1584 if (cmd && strcmp(cmd, "chat") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1585 dFree(cmd);
1236
b912173aecd1 Added a_Dpip_get_attr_l() to DPIP's API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
1586 msg = a_Dpip_get_attr_l(Buf, BufSize, "msg");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1587 if (*msg == 'H') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1588 /* "Hi server" */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1589 if (a_Dpip_dsh_write_str(sh, 1, msg1))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1590 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1591 } else if (*msg == 'I') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1592 /* "I want to set abookmark" */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1593 if (a_Dpip_dsh_write_str(sh, 1, msg2))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1594 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1595 } else if (*msg == 'S') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1596 /* "Sure" */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1597 if (a_Dpip_dsh_write_str(sh, 1, msg3))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1598 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1599 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1600 dFree(msg);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1601 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1602 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1603
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1604 /* sync with the bookmarks file */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1605 Bms_cond_load();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1606
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1607 if (cmd && strcmp(cmd, "DpiBye") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1608 MSG("(pid %d): Got DpiBye.\n", (int)getpid());
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1609 exit(0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1610
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1611 } else if (cmd && strcmp(cmd, "add_bookmark") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1612 dFree(cmd);
1236
b912173aecd1 Added a_Dpip_get_attr_l() to DPIP's API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
1613 url = a_Dpip_get_attr_l(Buf, BufSize, "url");
b912173aecd1 Added a_Dpip_get_attr_l() to DPIP's API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
1614 title = a_Dpip_get_attr_l(Buf, BufSize, "title");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1615 if (strlen(title) == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1616 dFree(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1617 title = dStrdup("(Untitled)");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1618 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1619 if (url && title)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1620 Bmsrv_add_bm(sh, url, title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1621 dFree(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1622 dFree(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1623 return 2;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1624
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1625 } else if (cmd && strcmp(cmd, "open_url") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1626 dFree(cmd);
1236
b912173aecd1 Added a_Dpip_get_attr_l() to DPIP's API
Jorge Arellano Cid <jcid@dillo.org>
parents: 1200
diff changeset
1627 url = a_Dpip_get_attr_l(Buf, BufSize, "url");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1628
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1629 if (strcmp(url, "dpi:/bm/modify") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1630 st = Bmsrv_send_modify_answer(sh, url);
1706
23fa79dc9664 bookmarks dpi urlstr leak
corvid <corvid@lavabit.com>
parents: 1442
diff changeset
1631 dFree(url);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1632 return st;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1633
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1634 } else if (strncmp(url, "dpi:/bm/modify?", 15) == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1635 /* process request */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1636 st = Bmsrv_process_modify_request(sh, url);
1706
23fa79dc9664 bookmarks dpi urlstr leak
corvid <corvid@lavabit.com>
parents: 1442
diff changeset
1637 dFree(url);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1638 return st;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1639 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1640
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1641
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1642 d_cmd = a_Dpip_build_cmd("cmd=%s url=%s", "start_send_page", url);
1706
23fa79dc9664 bookmarks dpi urlstr leak
corvid <corvid@lavabit.com>
parents: 1442
diff changeset
1643 dFree(url);
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1644 st = a_Dpip_dsh_write_str(sh, 1, d_cmd);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1645 dFree(d_cmd);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1646 if (st != 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1647 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1648
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1649 /* Send HTTP header */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1650 if (a_Dpip_dsh_write_str(sh, 1, Header) != 0) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1651 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1652 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1653
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1654 st = send_bm_page(sh);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1655 if (st != 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1656 char *err =
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1657 DOCTYPE
1384
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1326
diff changeset
1658 "<HTML><body id='dillo_bm'> Error on the bookmarks server..."
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1326
diff changeset
1659 " </body></html>";
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1660 if (a_Dpip_dsh_write_str(sh, 1, err) != 0) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1661 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1662 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1663 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1664 return 2;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1665 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1666
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1667 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1668 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1669
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1670 /* -- Termination handlers ----------------------------------------------- */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1671 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1672 * (was to delete the local namespace socket),
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1673 * but this is handled by 'dpid' now.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1674 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1675 static void cleanup(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1676 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1677 /* no cleanup required */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1678 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1679
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1680 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1681 * Perform any necessary cleanups upon abnormal termination
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1682 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1683 static void termination_handler(int signum)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1684 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1685 exit(signum);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1686 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1687
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1688
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1689 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1690 * -- MAIN -------------------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1691 */
1384
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1326
diff changeset
1692 int main(void) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1693 struct sockaddr_un spun;
1439
79fcf67eeea0 Fixed bookmarks "cancel" link (Add/Mod URL, Add Sec). Also s/tmp_fd/sock_fd.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1438
diff changeset
1694 int sock_fd, code;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1695 socklen_t address_size;
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1696 char *tok;
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1697 Dsh *sh;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1698
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1699 /* Arrange the cleanup function for terminations via exit() */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1700 atexit(cleanup);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1701
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1702 /* Arrange the cleanup function for abnormal terminations */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1703 if (signal (SIGINT, termination_handler) == SIG_IGN)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1704 signal (SIGINT, SIG_IGN);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1705 if (signal (SIGHUP, termination_handler) == SIG_IGN)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1706 signal (SIGHUP, SIG_IGN);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1707 if (signal (SIGTERM, termination_handler) == SIG_IGN)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1708 signal (SIGTERM, SIG_IGN);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1709
1425
838f2687e9a2 Fixed a couple file descriptor leaks in dillo's DPI code
Jorge Arellano Cid <jcid@dillo.org>
parents: 1400
diff changeset
1710 /* We may receive SIGPIPE (e.g. socket is closed early by our client) */
838f2687e9a2 Fixed a couple file descriptor leaks in dillo's DPI code
Jorge Arellano Cid <jcid@dillo.org>
parents: 1400
diff changeset
1711 signal(SIGPIPE, SIG_IGN);
838f2687e9a2 Fixed a couple file descriptor leaks in dillo's DPI code
Jorge Arellano Cid <jcid@dillo.org>
parents: 1400
diff changeset
1712
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1713 /* Initialize local data */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1714 B_bms = dList_new(512);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1715 B_secs = dList_new(32);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1716 BmFile = dStrconcat(dGethomedir(), "/.dillo/bm.txt", NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1717 /* some OSes may need this... */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1718 address_size = sizeof(struct sockaddr_un);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1719
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1720 MSG("(v.13): accepting connections...\n");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1721
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1722 while (1) {
1439
79fcf67eeea0 Fixed bookmarks "cancel" link (Add/Mod URL, Add Sec). Also s/tmp_fd/sock_fd.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1438
diff changeset
1723 sock_fd = accept(STDIN_FILENO, (struct sockaddr *)&spun, &address_size);
79fcf67eeea0 Fixed bookmarks "cancel" link (Add/Mod URL, Add Sec). Also s/tmp_fd/sock_fd.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1438
diff changeset
1724 if (sock_fd == -1) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1725 perror("[accept]");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1726 exit(1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1727 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1728
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1729 /* create the Dsh structure */
1439
79fcf67eeea0 Fixed bookmarks "cancel" link (Add/Mod URL, Add Sec). Also s/tmp_fd/sock_fd.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1438
diff changeset
1730 sh = a_Dpip_dsh_new(sock_fd, sock_fd, 8*1024);
1400
af8b2297ff11 bookmarks dpi: added dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1388
diff changeset
1731
af8b2297ff11 bookmarks dpi: added dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1388
diff changeset
1732 /* Authenticate our client... */
af8b2297ff11 bookmarks dpi: added dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1388
diff changeset
1733 if (!(tok = a_Dpip_dsh_read_token(sh, 1)) ||
af8b2297ff11 bookmarks dpi: added dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1388
diff changeset
1734 a_Dpip_check_auth(tok) < 0) {
af8b2297ff11 bookmarks dpi: added dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1388
diff changeset
1735 MSG("can't authenticate request: %s\n", dStrerror(errno));
af8b2297ff11 bookmarks dpi: added dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1388
diff changeset
1736 a_Dpip_dsh_close(sh);
af8b2297ff11 bookmarks dpi: added dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1388
diff changeset
1737 exit(1);
af8b2297ff11 bookmarks dpi: added dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1388
diff changeset
1738 }
af8b2297ff11 bookmarks dpi: added dsh auth
Jorge Arellano Cid <jcid@dillo.org>
parents: 1388
diff changeset
1739 dFree(tok);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1740
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1741 while (1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1742 code = 1;
1388
eb35203124e4 Implemented the file dpi based on select() (removed its pthreads dependency)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1385
diff changeset
1743 if ((tok = a_Dpip_dsh_read_token(sh, 1)) != NULL) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1744 /* Let's see what we fished... */
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1745 code = Bmsrv_parse_token(sh, tok);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1746 }
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1747 dFree(tok);
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1748
1425
838f2687e9a2 Fixed a couple file descriptor leaks in dillo's DPI code
Jorge Arellano Cid <jcid@dillo.org>
parents: 1400
diff changeset
1749 if (code != 0) {
838f2687e9a2 Fixed a couple file descriptor leaks in dillo's DPI code
Jorge Arellano Cid <jcid@dillo.org>
parents: 1400
diff changeset
1750 /* socket is not operative (e.g. closed by client) */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1751 break;
1425
838f2687e9a2 Fixed a couple file descriptor leaks in dillo's DPI code
Jorge Arellano Cid <jcid@dillo.org>
parents: 1400
diff changeset
1752 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1753 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1754
1385
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1755 a_Dpip_dsh_close(sh);
eb98997886ec Introduced the new tokenizing dsh API to DPIP
Jorge Arellano Cid <jcid@dillo.org>
parents: 1384
diff changeset
1756 a_Dpip_dsh_free(sh);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1757
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1758 }/*while*/
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1759 }