Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
bookmarks.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>
#include <time.h>
#include <netdb.h>
#include <fcntl.h>
#include <signal.h>
#include "../dpip/dpip.h"
#include "dpiutil.h"
Include dependency graph for bookmarks.c:

Go to the source code of this file.

Macros

#define _MSG(...)
 
#define MSG(...)   printf("[bookmarks dpi]: " __VA_ARGS__)
 
#define DOCTYPE    "<!DOCTYPE html>\n"
 
#define CSS_STYLE
 
#define modifypage_sections_header   mainpage_sections_header
 
#define modifypage_sections_footer   mainpage_sections_footer
 
#define modifypage_section_card_footer   mainpage_section_card_footer
 

Functions

static char * make_one_line_str (char *str)
 
static void Unencode_str (char *e_str)
 
static int Bmsrv_dpi_send_status_msg (Dsh *sh, char *str)
 
static int Bms_node_by_key_cmp (const void *node, const void *key)
 
static int Bms_node_by_section_cmp (const void *node, const void *key)
 
static int Bms_sec_by_number_cmp (const void *node, const void *key)
 
static BmRec * Bms_get (int key)
 
static BmSec * Bms_get_sec (int key)
 
static void Bms_add (int section, char *url, char *title)
 
static void Bms_sec_add (char *title)
 
static void Bms_del (int key)
 
static void Bms_sec_del (int section)
 
static void Bms_move (int key, int target_section)
 
static void Bms_update_title (int key, char *n_title)
 
static void Bms_update_sec_title (int key, char *n_title)
 
static void Bms_free (void)
 
static void Bms_normalize (void)
 
static void Bms_check_import (void)
 
static int Bms_load (void)
 
static int Bms_cond_load (void)
 
static int Bms_save (void)
 
static int Bmsrv_add_bm (Dsh *sh, char *url, char *title)
 
static void Bmsrv_count_urls_and_sections (char *url, int *n_sec, int *n_url)
 
static int Bmsrv_send_reload_request (Dsh *sh, char *url)
 
static int Bmsrv_send_modify_page (Dsh *sh)
 
static int Bmsrv_send_modify_page_add_section (Dsh *sh)
 
static int Bmsrv_send_modify_page_add_url (Dsh *sh)
 
static int Bmsrv_send_modify_update (Dsh *sh, char *url)
 
static int Bmsrv_send_modify_answer (Dsh *sh, char *url)
 
static int Bmsrv_modify_delete (char *url)
 
static int Bmsrv_modify_move (char *url)
 
static int Bmsrv_modify_update (char *url)
 
static int Bmsrv_modify_add_section (char *url)
 
static int Bmsrv_modify_add_url (Dsh *sh, char *s_url)
 
static int Bmsrv_check_modify_request (Dsh *sh, char *url)
 
static int Bmsrv_process_modify_request (Dsh *sh, char *url)
 
static int send_bm_page (Dsh *sh)
 
static int Bmsrv_parse_token (Dsh *sh, char *Buf)
 
static void cleanup (void)
 
static void termination_handler (int signum)
 
int main (void)
 

Variables

static char * Header = "Content-type: text/html\n\n"
 
static char * BmFile = NULL
 
static time_t BmFileTimeStamp = 0
 
static DlistB_bms = NULL
 
static int bm_key = 0
 
static DlistB_secs = NULL
 
static int sec_key = 0
 
static int MODIFY_PAGE_NUM = 1
 
static const char * mainpage_header
 
static const char * modifypage_header
 
static const char * mainpage_sections_header
 
static const char * mainpage_sections_item
 
static const char * sections_sep
 
static const char * modifypage_sections_item
 
static const char * mainpage_sections_footer
 
static const char * mainpage_middle1 = "\n"
 
static const char * modifypage_middle1 = "\n"
 
static const char * mainpage_section_card_header
 
static const char * modifypage_section_card_header
 
static const char * mainpage_section_card_item
 
static const char * modifypage_section_card_item
 
static const char * mainpage_section_card_footer
 
static const char * mainpage_footer
 
static const char * modifypage_footer
 
static const char * modifypage_add_section_page
 
static const char * modifypage_update_header
 
static const char * modifypage_update_title
 
static const char * modifypage_update_item_header
 
static const char * modifypage_update_item
 
static const char * modifypage_update_item2
 
static const char * modifypage_update_item_footer
 
static const char * modifypage_update_footer
 
static const char * modifypage_add_url
 

Macro Definition Documentation

◆ _MSG

#define _MSG (   ...)

Definition at line 45 of file bookmarks.c.

◆ CSS_STYLE

#define CSS_STYLE
Value:
"<style type='text/css'>\n"\
"body { margin: 2em; background: white; font-size: 14px }\n" \
"ul { font-size: inherit; margin-left: 1em; margin-top: 0.5em; list-style-type: none; }\n" \
"ul.main { list-style-type: none; }\n" \
"li { min-height: 1.6em; }\n" \
"div.modify-menu { background-color: #f0f0f0; border: solid 1px #ccc; padding: 1em }\n" \
"nav ul { margin-top: 1em }\n" \
"nav li { display: inline; }\n" \
"a { color: black; }\n" \
"</style>\n"

Definition at line 51 of file bookmarks.c.

◆ DOCTYPE

#define DOCTYPE    "<!DOCTYPE html>\n"

Definition at line 48 of file bookmarks.c.

◆ modifypage_section_card_footer

#define modifypage_section_card_footer   mainpage_section_card_footer

Definition at line 196 of file bookmarks.c.

◆ modifypage_sections_footer

#define modifypage_sections_footer   mainpage_sections_footer

Definition at line 168 of file bookmarks.c.

◆ modifypage_sections_header

#define modifypage_sections_header   mainpage_sections_header

Definition at line 153 of file bookmarks.c.

◆ MSG

#define MSG (   ...)    printf("[bookmarks dpi]: " __VA_ARGS__)

Definition at line 46 of file bookmarks.c.

Function Documentation

◆ Bms_add()

static void Bms_add ( int  section,
char *  url,
char *  title 
)
static

Definition at line 410 of file bookmarks.c.

References B_bms, bm_key, dList_append(), dNew, Escape_html_str(), and Escape_uri_str().

Referenced by Bms_load(), Bmsrv_add_bm(), and Bmsrv_modify_add_url().

◆ Bms_check_import()

static void Bms_check_import ( void  )
static

◆ Bms_cond_load()

static int Bms_cond_load ( void  )
static

Definition at line 688 of file bookmarks.c.

References B_bms, B_secs, BmFile, BmFileTimeStamp, Bms_check_import(), Bms_load(), and dList_length().

Referenced by Bmsrv_parse_token().

◆ Bms_del()

static void Bms_del ( int  key)
static

◆ Bms_free()

static void Bms_free ( void  )
static

Definition at line 522 of file bookmarks.c.

References B_bms, B_secs, Bms_del(), Bms_sec_del(), and dList_nth_data().

Referenced by Bms_load().

◆ Bms_get()

static BmRec * Bms_get ( int  key)
static

Definition at line 394 of file bookmarks.c.

References B_bms, Bms_node_by_key_cmp(), dList_find_custom(), and INT2VOIDP.

Referenced by Bmsrv_send_modify_update().

◆ Bms_get_sec()

static BmSec * Bms_get_sec ( int  key)
static

Definition at line 402 of file bookmarks.c.

References B_secs, Bms_sec_by_number_cmp(), dList_find_custom(), and INT2VOIDP.

Referenced by Bmsrv_send_modify_update().

◆ Bms_load()

static int Bms_load ( void  )
static

◆ Bms_move()

static void Bms_move ( int  key,
int  target_section 
)
static

Definition at line 481 of file bookmarks.c.

References B_bms, Bms_node_by_key_cmp(), dList_find_custom(), and INT2VOIDP.

Referenced by Bmsrv_modify_move().

◆ Bms_node_by_key_cmp()

static int Bms_node_by_key_cmp ( const void *  node,
const void *  key 
)
static

Definition at line 370 of file bookmarks.c.

References VOIDP2INT.

Referenced by Bms_del(), Bms_get(), Bms_move(), and Bms_update_title().

◆ Bms_node_by_section_cmp()

static int Bms_node_by_section_cmp ( const void *  node,
const void *  key 
)
static

Definition at line 378 of file bookmarks.c.

References VOIDP2INT.

Referenced by Bms_sec_del().

◆ Bms_normalize()

static void Bms_normalize ( void  )
static

Definition at line 540 of file bookmarks.c.

References B_bms, B_secs, Bms_sec_add(), dList_length(), and dList_nth_data().

Referenced by Bms_save().

◆ Bms_save()

◆ Bms_sec_add()

static void Bms_sec_add ( char *  title)
static

Definition at line 425 of file bookmarks.c.

References B_secs, dList_append(), dNew, Escape_html_str(), and sec_key.

Referenced by Bms_load(), Bms_normalize(), and Bmsrv_modify_add_section().

◆ Bms_sec_by_number_cmp()

static int Bms_sec_by_number_cmp ( const void *  node,
const void *  key 
)
static

Definition at line 386 of file bookmarks.c.

References VOIDP2INT.

Referenced by Bms_get_sec(), Bms_sec_del(), and Bms_update_sec_title().

◆ Bms_sec_del()

static void Bms_sec_del ( int  section)
static

◆ Bms_update_sec_title()

static void Bms_update_sec_title ( int  key,
char *  n_title 
)
static

◆ Bms_update_title()

static void Bms_update_title ( int  key,
char *  n_title 
)
static

◆ Bmsrv_add_bm()

static int Bmsrv_add_bm ( Dsh sh,
char *  url,
char *  title 
)
static

Definition at line 776 of file bookmarks.c.

References Bms_add(), Bms_save(), Bmsrv_dpi_send_status_msg(), dFree(), sh, and Unescape_html_str().

Referenced by Bmsrv_parse_token().

◆ Bmsrv_check_modify_request()

static int Bmsrv_check_modify_request ( Dsh sh,
char *  url 
)
static

◆ Bmsrv_count_urls_and_sections()

static void Bmsrv_count_urls_and_sections ( char *  url,
int *  n_sec,
int *  n_url 
)
static

Definition at line 801 of file bookmarks.c.

Referenced by Bmsrv_check_modify_request(), and Bmsrv_send_modify_update().

◆ Bmsrv_dpi_send_status_msg()

static int Bmsrv_dpi_send_status_msg ( Dsh sh,
char *  str 
)
static

Definition at line 355 of file bookmarks.c.

References a_Dpip_build_cmd(), a_Dpip_dsh_write_str(), dFree(), and sh.

Referenced by Bmsrv_add_bm(), and Bmsrv_check_modify_request().

◆ Bmsrv_modify_add_section()

static int Bmsrv_modify_add_section ( char *  url)
static

Definition at line 1193 of file bookmarks.c.

References Bms_save(), Bms_sec_add(), dFree(), dStrdup(), and Unencode_str().

Referenced by Bmsrv_process_modify_request().

◆ Bmsrv_modify_add_url()

static int Bmsrv_modify_add_url ( Dsh sh,
char *  s_url 
)
static

◆ Bmsrv_modify_delete()

static int Bmsrv_modify_delete ( char *  url)
static

Definition at line 1053 of file bookmarks.c.

References Bms_del(), Bms_save(), and Bms_sec_del().

Referenced by Bmsrv_process_modify_request().

◆ Bmsrv_modify_move()

static int Bmsrv_modify_move ( char *  url)
static

Definition at line 1099 of file bookmarks.c.

References Bms_move(), and Bms_save().

Referenced by Bmsrv_process_modify_request().

◆ Bmsrv_modify_update()

static int Bmsrv_modify_update ( char *  url)
static

◆ Bmsrv_parse_token()

◆ Bmsrv_process_modify_request()

◆ Bmsrv_send_modify_answer()

static int Bmsrv_send_modify_answer ( Dsh sh,
char *  url 
)
static

◆ Bmsrv_send_modify_page()

◆ Bmsrv_send_modify_page_add_section()

static int Bmsrv_send_modify_page_add_section ( Dsh sh)
static

Definition at line 913 of file bookmarks.c.

References a_Dpip_dsh_write_str(), modifypage_add_section_page, and sh.

Referenced by Bmsrv_send_modify_answer().

◆ Bmsrv_send_modify_page_add_url()

static int Bmsrv_send_modify_page_add_url ( Dsh sh)
static

Definition at line 926 of file bookmarks.c.

References a_Dpip_dsh_write_str(), modifypage_add_url, and sh.

Referenced by Bmsrv_send_modify_answer().

◆ Bmsrv_send_modify_update()

◆ Bmsrv_send_reload_request()

static int Bmsrv_send_reload_request ( Dsh sh,
char *  url 
)
static

Definition at line 824 of file bookmarks.c.

References a_Dpip_build_cmd(), a_Dpip_dsh_write_str(), dFree(), and sh.

Referenced by Bmsrv_process_modify_request().

◆ cleanup()

static void cleanup ( void  )
static

Definition at line 1596 of file bookmarks.c.

Referenced by main().

◆ main()

◆ make_one_line_str()

static char * make_one_line_str ( char *  str)
static

Definition at line 301 of file bookmarks.c.

References dNew.

Referenced by Bmsrv_send_modify_page(), and send_bm_page().

◆ send_bm_page()

◆ termination_handler()

static void termination_handler ( int  signum)
static

Definition at line 1604 of file bookmarks.c.

Referenced by main().

◆ Unencode_str()

static void Unencode_str ( char *  e_str)
static

Definition at line 329 of file bookmarks.c.

References dStrnAsciiCasecmp().

Referenced by Bmsrv_modify_add_section(), Bmsrv_modify_add_url(), and Bmsrv_modify_update().

Variable Documentation

◆ B_bms

◆ B_secs

◆ bm_key

int bm_key = 0
static

Definition at line 90 of file bookmarks.c.

Referenced by Bms_add(), and Bms_del().

◆ BmFile

char* BmFile = NULL
static

Definition at line 87 of file bookmarks.c.

Referenced by Bms_check_import(), Bms_cond_load(), Bms_load(), Bms_save(), and main().

◆ BmFileTimeStamp

time_t BmFileTimeStamp = 0
static

Definition at line 88 of file bookmarks.c.

Referenced by Bms_cond_load(), Bms_load(), and Bms_save().

◆ Header

char* Header = "Content-type: text/html\n\n"
static

Definition at line 86 of file bookmarks.c.

Referenced by Bmsrv_parse_token(), and Bmsrv_send_modify_answer().

◆ mainpage_footer

const char* mainpage_footer
static
Initial value:
=
"</body>\n"
"</html>\n"

Definition at line 198 of file bookmarks.c.

Referenced by send_bm_page().

◆ mainpage_header

const char* mainpage_header
static
Initial value:
=
"<html>\n"
"<head>\n"
"<title>Bookmarks</title>\n"
"</head>\n"
"<body id='dillo_bm'>\n"
"\n"
" <h1>Bookmarks</h1>\n"
" <div style='float: right; padding: 1em'>\n"
" [<a href='dpi:/bm/modify'>Modify</a>]\n"
" </div>\n"
#define DOCTYPE
Definition bookmarks.c:48
#define CSS_STYLE
Definition bookmarks.c:51

Definition at line 105 of file bookmarks.c.

Referenced by send_bm_page().

◆ mainpage_middle1

const char* mainpage_middle1 = "\n"
static

Definition at line 170 of file bookmarks.c.

Referenced by send_bm_page().

◆ mainpage_section_card_footer

const char* mainpage_section_card_footer
static
Initial value:
=
"</ul>\n"

Definition at line 193 of file bookmarks.c.

Referenced by send_bm_page().

◆ mainpage_section_card_header

const char* mainpage_section_card_header
static
Initial value:
=
"<h2 id='s%d'>%s</h2>\n"
"<ul class='main'>\n"

Definition at line 174 of file bookmarks.c.

Referenced by send_bm_page().

◆ mainpage_section_card_item

const char* mainpage_section_card_item
static
Initial value:
=
" <li>\n"
" <a href='%s'>%s</a>\n"
" </li>\n"

Definition at line 182 of file bookmarks.c.

Referenced by send_bm_page().

◆ mainpage_sections_footer

const char* mainpage_sections_footer
static
Initial value:
=
" </ul>\n"
"</nav>\n"

Definition at line 164 of file bookmarks.c.

Referenced by send_bm_page().

◆ mainpage_sections_header

const char* mainpage_sections_header
static
Initial value:
=
"<nav>\n"
" <ul>\n"

Definition at line 149 of file bookmarks.c.

Referenced by send_bm_page().

◆ mainpage_sections_item

const char* mainpage_sections_item
static
Initial value:
=
" <li><a href='#s%d'>%s</a></li>\n"

Definition at line 155 of file bookmarks.c.

Referenced by send_bm_page().

◆ MODIFY_PAGE_NUM

int MODIFY_PAGE_NUM = 1
static

Definition at line 95 of file bookmarks.c.

Referenced by Bmsrv_process_modify_request(), and Bmsrv_send_modify_answer().

◆ modifypage_add_section_page

const char* modifypage_add_section_page
static
Initial value:
=
"<html>\n"
"<head>\n"
"<title>Bookmarks</title>\n"
"</head>\n"
"<body id='dillo_bm'>\n"
"<h1>Boorkmarks: New section</h1>\n"
"<form action='modify'>\n"
" <input type='hidden' name='operation' value='add_section'>\n"
" <p>\n"
" New section title:\n"
" <input type='text' name='title' size='32'>\n"
" <input type='submit' name='submit' value='Submit'>\n"
" or <a href='dpi:/bm/'>Cancel</a>\n"
" </p>\n"
"</form>\n"
"</body>\n"
"</html>\n"
"\n"

Definition at line 208 of file bookmarks.c.

Referenced by Bmsrv_send_modify_page_add_section().

◆ modifypage_add_url

const char* modifypage_add_url
static
Initial value:
=
"<html>\n"
"<head>\n"
"<title>Bookmarks</title>\n"
"</head>\n"
"<body id='dillo_bm'>\n"
"<h1>Bookmarks: Add URL</h1>\n"
"<form action='modify'>\n"
"<input type='hidden' name='operation' value='add_url2'>\n"
"<p>Title:\n"
" <input type='text' name='title' size='64'>\n"
"</p>\n"
"<p>URL:\n"
" <input type='text' name='url' size='64'>\n"
"</p>\n"
"<p>\n"
" <input type='submit' name='submit' value='Submit'>\n"
" or <a href='dpi:/bm/'>Cancel</a>\n"
"</p>\n"
"</form>\n"
"</body>\n"
"</html>\n"

Definition at line 270 of file bookmarks.c.

Referenced by Bmsrv_send_modify_page_add_url().

◆ modifypage_footer

const char* modifypage_footer
static
Initial value:
=
"</form>\n"
"</body>\n"
"</html>\n"

Definition at line 202 of file bookmarks.c.

Referenced by Bmsrv_send_modify_page().

◆ modifypage_header

const char* modifypage_header
static
Initial value:
=
"<html>\n"
"<head>\n"
"<title>Bookmarks</title>\n"
"</head>\n"
"<body id='dillo_bm'>\n"
" <h1>Bookmarks</h1>\n"
"\n"
"<form action='modify'>\n"
"<div class='modify-menu'>\n"
" <div style='float: right'>\n"
" [<a href='dpi:/bm/'>Dismiss</a>]\n"
" </div>\n"
" <p>Select an operation\n"
" <select name='operation'>\n"
" <option value='none' selected>--\n"
" <option value='delete'>Delete\n"
" <option value='move'>Move\n"
" <option value='modify'>Modify\n"
" <option value='add_sec'>Add Section\n"
" <option value='add_url'>Add URL\n"
" </select>\n"
" , mark its operands and\n"
" <input type='submit' name='submit' value='Submit'>\n"
" <p>You can also modify the bookmarks by editting the\n"
" <a href='file:~/.dillo/bm.txt'><code>~/.dillo/bm.txt</code></a> file.\n"
"</div>\n"

Definition at line 119 of file bookmarks.c.

Referenced by Bmsrv_send_modify_page().

◆ modifypage_middle1

const char* modifypage_middle1 = "\n"
static

Definition at line 172 of file bookmarks.c.

Referenced by Bmsrv_send_modify_page().

◆ modifypage_section_card_header

const char* modifypage_section_card_header
static
Initial value:
=
"<h2 id='s%d'>%s</h2>\n"
"<ul class='main'>\n"

Definition at line 178 of file bookmarks.c.

Referenced by Bmsrv_send_modify_page().

◆ modifypage_section_card_item

const char* modifypage_section_card_item
static
Initial value:
=
" <li>\n"
" <input type='checkbox' name='url%d'>\n"
" <a href='%s'>%s</a>\n"
" </li>\n"

Definition at line 187 of file bookmarks.c.

Referenced by Bmsrv_send_modify_page().

◆ modifypage_sections_item

const char* modifypage_sections_item
static
Initial value:
=
" <li><input type='checkbox' name='s%d'><a href='#s%d'>%s</a></li>\n"

Definition at line 161 of file bookmarks.c.

Referenced by Bmsrv_send_modify_page().

◆ modifypage_update_footer

const char* modifypage_update_footer
static
Initial value:
=
"<input type='submit' name='submit' value='Submit'>\n"
"</form>\n"
"</body>\n"
"</html>\n"

Definition at line 263 of file bookmarks.c.

Referenced by Bmsrv_send_modify_update().

◆ modifypage_update_header

const char* modifypage_update_header
static
Initial value:
=
"<html>\n"
"<head>\n"
"<title>Bookmarks</title>\n"
"</head>\n"
"<body id='dillo_bm'>\n"
"<h1>Bookmarks: Update</h1>\n"
"<form action='modify'>\n"
"<input type='hidden' name='operation' value='modify2'>\n"

Definition at line 231 of file bookmarks.c.

Referenced by Bmsrv_send_modify_update().

◆ modifypage_update_item

const char* modifypage_update_item
static
Initial value:
=
"<li style='padding: 0.5em'>\n"
" <input type='text' name='title%d' size='64'\n value='%s'>\n"
" <br>URL: <code>%s</code>\n"
"</li>\n"

Definition at line 249 of file bookmarks.c.

Referenced by Bmsrv_send_modify_update().

◆ modifypage_update_item2

const char* modifypage_update_item2
static
Initial value:
=
"<li style='padding: 0.5em'>\n"
" <input type='text' name='s%d' size='64' value='%s'>\n"
"</li>\n"

Definition at line 255 of file bookmarks.c.

Referenced by Bmsrv_send_modify_update().

◆ modifypage_update_item_footer

const char* modifypage_update_item_footer
static
Initial value:
=
"</ul>\n"

Definition at line 260 of file bookmarks.c.

Referenced by Bmsrv_send_modify_update().

◆ modifypage_update_item_header

const char* modifypage_update_item_header
static
Initial value:
=
"<ul>\n"

Definition at line 246 of file bookmarks.c.

Referenced by Bmsrv_send_modify_update().

◆ modifypage_update_title

const char* modifypage_update_title
static
Initial value:
=
"<h2>%s</h2>\n"

Definition at line 243 of file bookmarks.c.

Referenced by Bmsrv_send_modify_update().

◆ sec_key

int sec_key = 0
static

Definition at line 93 of file bookmarks.c.

Referenced by Bms_sec_add(), and Bms_sec_del().

◆ sections_sep

const char* sections_sep
static
Initial value:
=
" | \n"

Definition at line 158 of file bookmarks.c.

Referenced by Bmsrv_send_modify_page(), and send_bm_page().