annotate dpi/bookmarks.c @ 0:6ee11bf9e3ea

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