dillo
3.0.5
About: dillo is a small, fast, extensible Web browser particularly suitable for older or smaller computers and embedded systems (but only limited or no support for frames, CSS, JavaScript, Java). Fossies Dox: dillo-3.0.5.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) 
|
Go to the documentation of this file. 29 #include <sys/socket.h> 31 #include <sys/types.h> 37 #include "../dpip/dpip.h" 45 #define MSG(...) printf("[bookmarks dpi]: " __VA_ARGS__) 48 "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n" 74 static char *
Header =
"Content-type: text/html\n\n";
97 "<title>Bookmarks</title>\n" 99 "<body id='dillo_bm' bgcolor='#778899' link='black' vlink='brown'>\n" 100 "<table border='1' cellpadding='0' width='100%'>\n" 102 " <table width='100%' bgcolor='#b4b4b4'>\n" 104 " <td> Bookmarks :: </td>\n" 105 " <td align='right'>\n" 106 " [<a href='dpi:/bm/modify'>modify</a>]\n" 108 " </table></td></tr>\n" 116 "<title>Bookmarks</title>\n" 118 "<body id='dillo_bm' bgcolor='#778899' link='black' vlink='brown'>\n" 119 "<table border='1' cellpadding='0' width='100%'>\n" 121 " <table width='100%' bgcolor='#b4b4b4'>\n" 123 " <td> Bookmarks :: modify</td>\n" 124 " <td align='right'>\n" 125 " [<a href='dpi:/bm/'>cancel</a>]\n" 128 " </table></td></tr> \n" 131 "<form action='modify'>\n" 132 "<table width='100%' border='1' cellpadding='0'>\n" 133 " <tr style='background-color: teal'>\n" 135 " <b>Select an operation</b>\n" 136 " <select name='operation'>\n" 137 " <option value='none' selected>--\n" 138 " <option value='delete'>Delete\n" 139 " <option value='move'>Move\n" 140 " <option value='modify'>Modify\n" 141 " <option value='add_sec'>Add Section\n" 142 " <option value='add_url'>Add URL\n" 144 " <b>, mark its operands, and</b>\n" 145 " <input type='submit' name='submit' value='submit.'>\n" 151 "<table border='1' cellpadding='0' cellspacing='20' width='100%'>\n" 152 " <tr valign='top'>\n" 154 " <table bgcolor='#b4b4b4' border='2' cellpadding='4' cellspacing='1'>\n" 156 " <table width='100%' bgcolor='#b4b4b4'>\n" 157 " <tr><td><small>Sections:</small></td></tr></table></td></tr>\n";
160 "<table border='1' cellpadding='0' cellspacing='20' width='100%'>\n" 161 " <tr valign='top'>\n" 163 " <table bgcolor='#b4b4b4' border='1'>\n" 165 " <table width='100%' bgcolor='#b4b4b4'>\n" 166 " <tr><td><small>Sections:</small></td></tr></table></td></tr>\n";
169 " <tr><td align='center'>\n" 170 " <a href='#s%d'>%s</a></td></tr>\n";
174 " <table width='100%%'>\n" 175 " <tr align='center'>" 176 " <td><input type='checkbox' name='s%d'></td>\n" 177 " <td width='100%%'><a href='#s%d'>%s</a></td></tr></table></td></tr>\n";
187 " <td width='100%'>\n";
191 " <td width='100%'>\n";
194 " <a name='s%d'></a>\n" 195 " <table bgcolor='#bfbfbf' width='100%%' cellspacing='2'>\n" 197 " <td bgcolor='#bf0c0c'><font color='white'><b>\n" 198 " %s </b></font></td>\n" 199 " <td bgcolor='white' width='100%%'> </td></tr>\n";
202 " <a name='s%d'></a>\n" 203 " <table bgcolor='#bfbfbf' width='100%%' cellspacing='2'>\n" 205 " <td bgcolor='#bf0c0c'><font color='white'><b>\n" 206 " %s </b></font></td>\n" 207 " <td bgcolor='white' width='100%%'> </td></tr>\n";
210 " <tr><td colspan='2'>\n" 211 " <a href='%s'>%s</a> </td></tr>\n";
215 " <td colspan='2'><input type='checkbox' name='url%d'>\n" 216 " <a href='%s'>%s</a></td></tr>\n";
246 "<title>Bookmarks</title>\n" 248 "<body id='dillo_bm' bgcolor='#778899' link='black' vlink='brown'>\n" 249 "<table border='1' cellpadding='0' width='100%'>\n" 250 " <tr><td colspan='2'>\n" 251 " <table bgcolor='#b4b4b4' width='100%'>\n" 253 " <td bgcolor='#b4b4b4'>\n" 254 " Modify bookmarks :: add section\n" 256 " <td align='right'>\n" 257 " [<a href='dpi:/bm/'>cancel</a>]\n" 260 " </table></td></tr>\n" 263 "<form action='modify'>\n" 264 " <input type='hidden' name='operation' value='add_section'>\n" 265 "<table border='1' width='100%'>\n" 267 " <td bgcolor='olive'><b>New section:</b></td>\n" 268 " <td bgcolor='white' width='100%'></td></tr>\n" 270 "<table width='100%' cellpadding='10'>\n" 272 " <table width='100%' bgcolor='teal'>\n" 275 " <td><input type='text' name='title' size='64'></td></tr>\n" 279 "<table width='100%' cellpadding='4' border='0'>\n" 280 "<tr><td bgcolor='#a0a0a0'>\n" 281 " <input type='submit' name='submit' value='submit.'></td></tr>\n" 293 "<title>Bookmarks</title>\n" 295 "<body id='dillo_bm' bgcolor='#778899' link='black' vlink='brown'>\n" 296 "<table border='1' cellpadding='0' width='100%'>\n" 297 " <tr><td colspan='2'>\n" 298 " <table bgcolor='#b4b4b4' width='100%'>\n" 299 " <tr><td bgcolor='#b4b4b4'> Modify bookmarks :: update\n" 301 " <td align='right'>\n" 302 " [<a href='dpi:/bm/'>cancel</a>]\n" 305 " </table></td></tr>\n" 308 "<form action='modify'>\n" 309 "<input type='hidden' name='operation' value='modify2'>\n";
312 "<table border='1' width='100%%'>\n" 314 " <td bgcolor='olive'><b>%s</b></td>\n" 315 " <td bgcolor='white' width='100%%'></td></tr>\n" 319 "<table width='100%' cellpadding='10'>\n";
323 " <table width='100%%' bgcolor='teal'>\n" 326 " <td><input type='text' name='title%d' size='64'\n" 327 " value='%s'></td></tr>\n" 330 " <td>%s</td></tr>\n" 336 " <table width='100%%' bgcolor='teal'>\n" 339 " <td><input type='text' name='s%d' size='64'\n" 340 " value='%s'></td></tr>\n" 348 "<table width='100%' cellpadding='4' border='0'>\n" 349 "<tr><td bgcolor='#a0a0a0'>\n" 350 " <input type='submit' name='submit' value='submit.'></td></tr>\n" 361 "<title>Bookmarks</title>\n" 363 "<body id='dillo_bm' bgcolor='#778899' link='black' vlink='brown'>\n" 364 "<table border='1' cellpadding='0' width='100%'>\n" 365 " <tr><td colspan='2'>\n" 366 " <table bgcolor='#b4b4b4' width='100%'>\n" 367 " <tr><td bgcolor='#b4b4b4'> Modify bookmarks :: add url\n" 369 " <td align='right'>\n" 370 " [<a href='dpi:/bm/'>cancel</a>]\n" 373 " </table></td></tr>\n" 376 "<form action='modify'>\n" 377 "<input type='hidden' name='operation' value='add_url2'>\n" 378 "<table border='1' width='100%'>\n" 380 " <td bgcolor='olive'><b>Add url:</b></td>\n" 381 " <td bgcolor='white' width='100%'></td></tr>\n" 383 "<table width='100%' cellpadding='10'>\n" 385 " <table width='100%' bgcolor='teal'>\n" 388 " <td><input type='text' name='title' size='64'></td></tr>\n" 391 " <td><input type='text' name='url' size='64'></td></tr>\n" 395 "<table width='100%' cellpadding='4' border='0'>\n" 396 "<tr><td bgcolor='#a0a0a0'>\n" 397 " <input type='submit' name='submit' value='submit.'></td></tr>\n" 414 for (i = 0, n = 0; str[i]; ++i)
418 new_str =
dNew(
char, strlen(str) + 6*n + 1);
421 for (i = 0, j = 0; str[i]; ++i) {
423 strcpy(new_str + j,
" ");
441 for (p = e = e_str; *e; e++, p++) {
444 }
else if (*e ==
'%') {
449 *p = (isdigit(e[1]) ? (e[1] -
'0') : (e[1] -
'A' + 10)) * 16 +
450 (isdigit(e[2]) ? (e[2] -
'0') : (e[2] -
'A' + 10));
518 static void Bms_add(
int section,
char *url,
char *title)
595 bm_node->
section = target_section;
685 "echo \":s0: Unclassified\" > %s";
687 "grep -i \"href\" %s | " 688 "sed -e 's/<li><A HREF=\"/s0 /' -e 's/\">/ /' -e 's/<.*$//' >> %s";
693 if (access(
BmFile, F_OK) != 0) {
695 if (access(OldBmFile, F_OK) == 0) {
697 rc = system(dstr->
str);
699 MSG(
"Bookmarks: /bin/sh could not be executed\n");
700 }
else if (rc == -1) {
701 MSG(
"Bookmarks: process creation failure: %s\n",
705 rc = system(dstr->
str);
707 MSG(
"Bookmarks: /bin/sh could not be executed\n");
708 }
else if (rc == -1) {
709 MSG(
"Bookmarks: process creation failure: %s\n",
725 char *buf, *p, *url, *title, *u_title;
727 struct stat TimeStamp;
733 if (!(BmTxt = fopen(
BmFile,
"r"))) {
739 while ((buf =
dGetline(BmTxt)) != NULL) {
742 section = strtol(buf + 1, NULL, 10);
743 p = strchr(buf,
' '); *p = 0;
745 p = strchr(p,
' '); *p = 0;
747 p = strchr(p,
'\n'); *p = 0;
749 Bms_add(section, url, u_title);
752 }
else if (buf[0] ==
':' && buf[1] ==
's') {
754 p = strchr(buf + 2,
' ');
756 p = strchr(p,
'\n'); *p = 0;
760 MSG(
"Syntax error in bookmarks file:\n %s", buf);
781 struct stat TimeStamp;
783 if (stat(
BmFile, &TimeStamp) != 0) {
786 if (stat(
BmFile, &TimeStamp) != 0)
787 TimeStamp.st_mtime = 0;
815 if (stat(
BmFile, &BmStat) == 0 && BmStat.st_size > 256) {
817 rename(
BmFile, BmFileBak);
822 if (!(BmTxt = fopen(
BmFile,
"w"))) {
834 fwrite(dstr->
str, (
size_t)dstr->
len, 1, BmTxt);
845 fwrite(dstr->
str, (
size_t)dstr->
len, 1, BmTxt);
869 char *msg=
"Added bookmark!";
874 Bms_add(section, url, u_title);
898 if ((p = strchr(url,
'?'))) {
899 for (q = p; (q = strstr(q,
"&url")); ++q) {
900 for (i = 0; isdigit(q[4+i]); ++i);
901 *n_url += (q[4+i] ==
'=') ? 1 : 0;
903 for (q = p; (q = strstr(q,
"&s")); ++q) {
904 for (i = 0; isdigit(q[2+i]); ++i);
905 *n_sec += (q[2+i] ==
'=') ? 1 : 0;
931 static Dstr *dstr = NULL;
1027 static char *url1 = NULL;
1028 static Dstr *dstr = NULL;
1030 int i,
key, n_sec, n_url;
1058 p = strchr(url1,
'?');
1059 for (q = p; (q = strstr(q,
"&s")); ++q) {
1060 for (i = 0; isdigit(q[2+i]); ++i);
1061 if (q[2+i] ==
'=') {
1062 key = strtol(q + 2, NULL, 10);
1078 p = strchr(url1,
'?');
1079 for (q = p; (q = strstr(q,
"&url")); ++q) {
1080 for (i = 0; isdigit(q[4+i]); ++i);
1081 if (q[4+i] ==
'=') {
1082 key = strtol(q + 4, NULL, 10);
1146 p = strchr(url,
'?');
1147 for (ns = 0; (p = strstr(p,
"&s")); ++p) {
1148 if (isdigit(p[2])) {
1149 key = strtol(p + 2, NULL, 10);
1156 p = strchr(url,
'?');
1157 for (nb = 0; (p = strstr(p,
"&url")); ++p) {
1158 if (isdigit(p[4])) {
1159 key = strtol(p + 4, NULL, 10);
1187 int n, section = 0,
key;
1192 for (p = url; (p = strstr(p,
"&s")); ++p) {
1193 if (isdigit(p[2])) {
1194 section = strtol(p + 2, NULL, 10);
1202 p = strchr(url,
'?');
1203 for (n = 0; (p = strstr(p,
"&url")); ++p) {
1204 if (isdigit(p[4])) {
1205 key = strtol(p + 4, NULL, 10);
1225 char *p, *q, *title;
1230 p = strchr(url,
'?');
1231 for ( ; (p = strstr(p,
"s")); ++p) {
1232 if (p[-1] ==
'&' || p[-1] ==
'?' ) {
1233 for (i = 0; isdigit(p[1 + i]); ++i);
1234 if (i && p[1 + i] ==
'=') {
1236 key = strtol(p + 1, NULL, 10);
1237 if ((q = strchr(p + 1,
'&')))
1249 p = strchr(url,
'?');
1250 for ( ; (p = strstr(p,
"title")); ++p) {
1251 if (p[-1] ==
'&' || p[-1] ==
'?' ) {
1252 for (i = 0; isdigit(p[5 + i]); ++i);
1253 if (i && p[5 + i] ==
'=') {
1255 key = strtol(p + 5, NULL, 10);
1256 if ((q = strchr(p + 5,
'&')))
1280 char *p, *title = NULL;
1285 if ((p = strstr(url,
"&title="))) {
1287 if ((p = strchr(title,
'&')))
1308 char *p, *q, *title, *u_title, *url;
1310 static int section = 0;
1316 for (q = s_url; (q = strstr(q,
"&s")); ++q) {
1317 for (i = 0; isdigit(q[2+i]); ++i);
1319 section = strtol(q + 2, NULL, 10);
1324 if (!(p = strstr(s_url,
"&title=")) ||
1325 !(q = strstr(s_url,
"&url=")))
1329 if ((p = strchr(title,
'&')))
1332 if ((p = strchr(url,
'&')))
1334 if (strlen(title) && strlen(url)) {
1338 Bms_add(section, url, u_title);
1367 p = strchr(url,
'?');
1368 if (strstr(p,
"operation=delete&")) {
1371 msg =
"Delete: you must mark what to delete!";
1373 }
else if (strstr(url,
"operation=move&")) {
1377 msg =
"Move: you must mark a target section!";
1379 msg =
"Move: can not move a section (yet).";
1381 msg =
"Move: you must mark some urls, and a target section!";
1383 }
else if (strstr(url,
"operation=modify&")) {
1386 msg =
"Modify: you must mark what to update!";
1388 }
else if (strstr(url,
"operation=modify2&")) {
1392 }
else if (strstr(url,
"operation=add_sec&")) {
1396 }
else if (strstr(url,
"operation=add_section&")) {
1400 }
else if (strstr(url,
"operation=add_url&")) {
1403 msg =
"Add url: only one target section is allowed!";
1405 }
else if (strstr(url,
"operation=add_url2&")) {
1409 }
else if (strstr(url,
"operation=none&")) {
1410 msg =
"No operation, just do nothing!";
1413 msg =
"Sorry, not implemented yet.";
1430 if (strstr(url,
"operation=delete&")) {
1436 }
else if (strstr(url,
"operation=move&")) {
1442 }
else if (strstr(url,
"operation=modify&")) {
1449 }
else if (strstr(url,
"operation=modify2&")) {
1455 }
else if (strstr(url,
"operation=add_sec&")) {
1461 }
else if (strstr(url,
"operation=add_section&")) {
1467 }
else if (strstr(url,
"operation=add_url&")) {
1475 }
else if (strstr(url,
"operation=add_url2&")) {
1492 static Dstr *dstr = NULL;
1564 static char *msg1=NULL, *msg2=NULL, *msg3=NULL;
1565 char *cmd, *d_cmd, *url, *title, *msg;
1577 MSG(
"ERROR: Unhandled DPIP_RAW mode!\n");
1581 BufSize = strlen(Buf);
1584 if (cmd && strcmp(cmd,
"chat") == 0) {
1591 }
else if (*msg ==
'I') {
1595 }
else if (*msg ==
'S') {
1607 if (cmd && strcmp(cmd,
"DpiBye") == 0) {
1608 MSG(
"(pid %d): Got DpiBye.\n", (
int)getpid());
1611 }
else if (cmd && strcmp(cmd,
"add_bookmark") == 0) {
1615 if (strlen(title) == 0) {
1617 title =
dStrdup(
"(Untitled)");
1625 }
else if (cmd && strcmp(cmd,
"open_url") == 0) {
1630 if (strcmp(url+4,
"/bm/modify") == 0) {
1634 }
else if (strncmp(url+4,
"/bm/modify?", 11) == 0) {
1659 "<HTML><body id='dillo_bm'> Error on the bookmarks server..." 1694 struct sockaddr_un spun;
1696 socklen_t address_size;
1705 signal (SIGINT, SIG_IGN);
1707 signal (SIGHUP, SIG_IGN);
1709 signal (SIGTERM, SIG_IGN);
1712 signal(SIGPIPE, SIG_IGN);
1719 address_size =
sizeof(
struct sockaddr_un);
1721 MSG(
"(v.13): accepting connections...\n");
1724 sock_fd = accept(STDIN_FILENO, (
struct sockaddr *)&spun, &address_size);
1725 if (sock_fd == -1) {
1736 MSG(
"can't authenticate request: %s\n",
dStrerror(errno));
void dStr_free(Dstr *ds, int all)
Dsh * a_Dpip_dsh_new(int fd_in, int fd_out, int flush_sz)
static BmSec * Bms_get_sec(int key)
static const char * mainpage_middle1
static const char * mainpage_section_card_footer
static const char * modifypage_update_item2
static const char * modifypage_add_section_page
static void cleanup(void)
int dList_length(Dlist *lp)
static const char * modifypage_sections_header
char * dStrconcat(const char *s1,...)
static time_t BmFileTimeStamp
static int Bmsrv_send_modify_page(Dsh *sh)
static int Bmsrv_check_modify_request(Dsh *sh, char *url)
static int Bms_node_by_section_cmp(const void *node, const void *key)
static int Bmsrv_modify_add_url(Dsh *sh, char *s_url)
static const char * modifypage_header
static const char * modifypage_section_card_header
char * Escape_uri_str(const char *str, const char *p_esc_set)
static const char * modifypage_update_item
static const char * modifypage_middle1
void * dList_nth_data(Dlist *lp, int n0)
static int Bms_cond_load(void)
static const char * mainpage_section_card_item
static const char * mainpage_sections_footer
void * dList_find_custom(Dlist *lp, const void *data, dCompareFunc func)
char * Escape_html_str(const char *str)
#define dNew(type, count)
char * dStrndup(const char *s, size_t sz)
static int Bmsrv_send_modify_update(Dsh *sh, char *url)
char * a_Dpip_dsh_read_token(Dsh *dsh, int blocking)
static void Bmsrv_count_urls_and_sections(char *url, int *n_sec, int *n_url)
static void Bms_check_import(void)
static int Bmsrv_parse_token(Dsh *sh, char *Buf)
static const char * modifypage_update_item_footer
static const char * mainpage_footer
int a_Dpip_check_auth(const char *auth_tag)
static int Bms_node_by_key_cmp(const void *node, const void *key)
Dstr * dStr_new(const char *s)
static void Bms_del(int key)
static int Bmsrv_modify_delete(char *url)
static void Unencode_str(char *e_str)
static int Bmsrv_send_reload_request(Dsh *sh, char *url)
static const char * modifypage_section_card_item
static int Bmsrv_send_modify_page_add_section(Dsh *sh)
static const char * modifypage_update_item_header
static int Bmsrv_send_modify_page_add_url(Dsh *sh)
static BmRec * Bms_get(int key)
static const char * mainpage_section_card_header
static int Bmsrv_process_modify_request(Dsh *sh, char *url)
static const char * modifypage_section_card_footer
static int Bmsrv_modify_update(char *url)
char * a_Dpip_build_cmd(const char *format,...)
char * dGetline(FILE *stream)
static int Bmsrv_modify_move(char *url)
void a_Dpip_dsh_free(Dsh *dsh)
static const char * modifypage_update_footer
static const char * modifypage_update_header
static void Bms_free(void)
static void Bms_sec_del(int section)
static void Bms_update_sec_title(int key, char *n_title)
static int send_bm_page(Dsh *sh)
static void Bms_move(int key, int target_section)
void dList_append(Dlist *lp, void *data)
char * Unescape_html_str(const char *str)
static void Bms_add(int section, char *url, char *title)
static void Bms_sec_add(char *title)
void dStr_sprintf(Dstr *ds, const char *format,...)
static int Bms_save(void)
static int Bms_sec_by_number_cmp(const void *node, const void *key)
static int Bmsrv_send_modify_answer(Dsh *sh, char *url)
static int Bmsrv_dpi_send_status_msg(Dsh *sh, char *str)
char * a_Dpip_get_attr_l(const char *tag, size_t tagsize, const char *attrname)
static int Bmsrv_add_bm(Dsh *sh, char *url, char *title)
static void Bms_normalize(void)
static int Bmsrv_modify_add_section(char *url)
static const char * modifypage_sections_footer
static const char * mainpage_sections_item
Dlist * dList_new(int size)
static void termination_handler(int signum)
void a_Dpip_dsh_close(Dsh *dsh)
void dList_remove(Dlist *lp, const void *data)
static char * make_one_line_str(char *str)
static const char * modifypage_footer
static const char * modifypage_add_url
static int Bms_load(void)
static const char * mainpage_header
int a_Dpip_dsh_write_str(Dsh *dsh, int flush, const char *str)
char * dStrdup(const char *s)
static const char * modifypage_sections_item
static const char * mainpage_sections_header
static const char * modifypage_update_title
static void Bms_update_title(int key, char *n_title)
static int MODIFY_PAGE_NUM
int dStrnAsciiCasecmp(const char *s1, const char *s2, size_t n)