diff options
-rw-r--r-- | about.c | 192 | ||||
-rw-r--r-- | xombrero.1 | 3 | ||||
-rw-r--r-- | xombrero.c | 10 | ||||
-rw-r--r-- | xombrero.conf | 8 | ||||
-rw-r--r-- | xombrero.h | 5 |
5 files changed, 204 insertions, 14 deletions
diff --git a/about.c b/about.c index b1a8fbf..91cf034 100644 --- a/about.c +++ b/about.c @@ -65,6 +65,7 @@ #define XT_XTP_HL (2) /* history */ #define XT_XTP_CL (3) /* cookies */ #define XT_XTP_FL (4) /* favorites */ +#define XT_XTP_SL (5) /* search */ /* XTP download actions */ #define XT_XTP_DL_LIST (1) @@ -87,6 +88,9 @@ #define XT_XTP_FL_LIST (1) #define XT_XTP_FL_REMOVE (2) +/* XPT search actions */ +#define XT_XTP_SL_SET (1) + int js_show_wl(struct tab *, struct karg *); int pl_show_wl(struct tab *, struct karg *); int set(struct tab *, struct karg *); @@ -115,6 +119,21 @@ struct about_type about_list[] = { { XT_URI_ABOUT_STARTPAGE, startpage }, { XT_URI_ABOUT_PLUGINWL, pl_show_wl }, { XT_URI_ABOUT_WEBKIT, about_webkit }, + { XT_URI_ABOUT_SEARCH, xtp_page_sl }, +}; + +struct search_type { + const char *name; + const char *url; +} search_list[] = { + { "Google (SSL)", "https://encrypted.google.com/search?q=%s&&client=xombrero" }, + { "Bing", "http://www.bing.com/search?q=%s" }, + { "Yahoo", "http://search.yahoo.com/search?p=%s" }, + { "DuckDuckGo", "https://duckduckgo.com/?q=%s" }, + { "DuckDuckGo (HTML)", "https://duckduckgo.com/html?q=%s" }, + { "DuckDuckGo (Lite)", "https://duckduckgo.com/lite?q=%s" }, + { "Ixquick", "https://ixquick.com/do/search?q=%s" }, + { "Startpage", "https://startpage.com/do/search?q=%s" }, }; /* @@ -130,11 +149,13 @@ char *dl_session_key; /* downloads */ char *hl_session_key; /* history list */ char *cl_session_key; /* cookie list */ char *fl_session_key; /* favorites list */ +char *sl_session_key; /* search */ int updating_fl_tabs = 0; int updating_dl_tabs = 0; int updating_hl_tabs = 0; int updating_cl_tabs = 0; +int updating_sl_tabs = 0; struct download_list downloads; size_t @@ -722,6 +743,25 @@ done: return (0); } +char * +search_engine_add(char *body, const char *name, const char *url, int select) +{ + char *b = body; + + body = g_strdup_printf("%s<tr>" + "<td>%s</td>" + "<td>%s</td>" + "<td style='text-align: center'>" + "<a href='%s%d/%s/%d/%d'>[ Select ]</a></td>" + "</tr>\n", + body, + name, + url, + XT_XTP_STR, XT_XTP_SL, sl_session_key, XT_XTP_SL_SET, select); + g_free(b); + return (body); +} + void xtp_handle_fl(struct tab *t, uint8_t cmd, int arg) { @@ -764,6 +804,80 @@ xtp_handle_cl(struct tab *t, uint8_t cmd, int arg) xtp_page_cl(t, NULL); } +void +xtp_handle_sl(struct tab *t, uint8_t cmd, int arg) +{ + struct stat sb; + FILE *f; + size_t linelen; + int found = 0; + const char *search; + char file[PATH_MAX]; + char delim[3] = { '\0', '\0', '\0' }; + char *line, *lt, *enc_search, *uri; + char *contents, *tmp; + + switch (cmd) { + case XT_XTP_SL_SET: + set_search_string((char *)search_list[arg].url); + if (runtime_settings == NULL || strlen(runtime_settings) == 0) { + show_oops(t, "could not set search_string in " + "runtime"); + break; + } + snprintf(file, sizeof file, "%s" PS "%s", work_dir, + runtime_settings); + if (stat(file, &sb) || (f = fopen(file, "r+")) == NULL) { + show_oops(t, "could not set search_string in runtime"); + break; + } + lt = g_strdup_printf("search_string=%s", + (char *)search_list[arg].url); + contents = g_strdup(""); + while (!feof(f)) { + line = fparseln(f, &linelen, NULL, delim, 0); + if (line == NULL || linelen == 0) + continue; + tmp = contents; + if (strstr(line, "search_string=") == NULL) + contents = g_strdup_printf("%s%s\n", contents, + line); + else { + found = 1; + contents = g_strdup_printf("%s%s\n", contents, + lt); + } + g_free(tmp); + free(line); + line = NULL; + } + if (found == 0) { + tmp = contents; + contents = g_strdup_printf("%s%s\n", contents, lt); + g_free(tmp); + } + if ((f = freopen(file, "w", f)) == NULL) + show_oops(t, "could not set search_string in runtime"); + else { + fputs(contents, f); + fclose(f); + } + g_free(lt); + g_free(contents); + break; + default: + show_oops(t, "%s: unknown search xtp command", __func__); + break; + }; + + search = gtk_entry_get_text(GTK_ENTRY(t->search_entry)); /* static */ + enc_search = soup_uri_encode(search, XT_RESERVED_CHARS); + uri = g_strdup_printf(search_string, enc_search); + load_uri(t, uri); + g_free(enc_search); + g_free(uri); +} + /* link an XTP class to it's session key and handler function */ struct xtp_despatch { uint8_t xtp_class; @@ -776,6 +890,7 @@ struct xtp_despatch xtp_despatches[] = { { XT_XTP_HL, &hl_session_key, xtp_handle_hl }, { XT_XTP_FL, &fl_session_key, xtp_handle_fl }, { XT_XTP_CL, &cl_session_key, xtp_handle_cl }, + { XT_XTP_SL, &sl_session_key, xtp_handle_sl }, { XT_XTP_INVALID, NULL, NULL } }; @@ -970,6 +1085,25 @@ update_history_tabs(struct tab *apart_from) } } +/* + * update all search tabs apart from one. Pass NULL if + * you want to update all. + */ +void +update_search_tabs(struct tab *apart_from) +{ + struct tab *t; + + if (!updating_sl_tabs) { + updating_sl_tabs = 1; /* stop infinite recursion */ + TAILQ_FOREACH(t, &tabs, entry) + if ((t->xtp_meaning == XT_XTP_TAB_MEANING_SL) + && (t != apart_from)) + xtp_page_sl(t, NULL); + updating_sl_tabs = 0; + } +} + /* show a list of favorites (bookmarks) */ int xtp_page_fl(struct tab *t, struct karg *args) @@ -1467,6 +1601,64 @@ xtp_page_dl(struct tab *t, struct karg *args) } int +xtp_page_sl(struct tab *t, struct karg *args) +{ + int i; + char *page, *body, *tmp; + + DNPRINTF(XT_D_SEARCH, "%s", __func__); + + /* + * Generate a new session key for next page instance. + * This only happens for the top level call to xtp_page_sl() + * in which case updating_sl_tabs is 0. + */ + if (!updating_sl_tabs) + generate_xtp_session_key(&sl_session_key); + + if (t == NULL) { + show_oops(NULL, "%s invalid parameters", __func__); + return (1); + } + + body = g_strdup_printf("<p>The Xombrero authors will not choose a " + "default search engine for you. What follows is a list of search " + "engines (in no particular order) you may be interested in. " + "To permanently choose a search engine, click [ Select ] to save " + "<tt>search_string</tt> as a runtime setting, or set " + "<tt>search_string</tt> to the appropriate URL in your Xombrero " + "configuration.</p>"); + + tmp = body; + body = g_strdup_printf("%s\n<table style='table-layout:fixed'><tr>" + "<th style='width: 200px'>Name</th><th>URL</th>" + "<th style='width: 100px'>Select</th></tr>\n", body); + g_free(tmp); + + for (i = 0; i < (sizeof search_list / sizeof (struct search_type)); ++i) + body = search_engine_add(body, search_list[i].name, + search_list[i].url, i); + + tmp = body; + body = g_strdup_printf("%s</table>", body); + g_free(tmp); + + page = get_html_page("Choose a search engine", body, "", 1); + g_free(body); + + /* + * update all search tabs as the xtp session key has now changed. No + * need to update the current tab. Already did that above. + */ + update_search_tabs(t); + + load_webkit_string(t, page, XT_URI_ABOUT_SEARCH); + g_free(page); + + return (0); +} + +int startpage(struct tab *t, struct karg *args) { char *page, *body, *b; diff --git a/xombrero.1 b/xombrero.1 index 336ca77..2ca1fbc 100644 --- a/xombrero.1 +++ b/xombrero.1 @@ -908,6 +908,9 @@ tries to open the user specific file, .Pa ~/.xombrero.conf . If that file is unavailable, it then uses built-in defaults. +Any settings saved at runtime will be saved to the file +.Pa ~/.xombrero/runtime +and will be loaded as well. .Pp The format of the file is \*(Ltkeyword\*(Gt = \*(Ltsetting\*(Gt. For example: diff --git a/xombrero.c b/xombrero.c index d02ce21..f3d79c8 100644 --- a/xombrero.c +++ b/xombrero.c @@ -98,7 +98,6 @@ TAILQ_HEAD(command_list, command_entry); #define XT_DLMAN_REFRESH "10" #define XT_MAX_URL_LENGTH (4096) /* 1 page is atomic, don't make bigger */ #define XT_MAX_UNDO_CLOSE_TAB (32) -#define XT_RESERVED_CHARS "$&+,/:;=?@ \"<>#%%{}|^~[]`" #define XT_PRINT_EXTRA_MARGIN 10 #define XT_URL_REGEX ("^[[:blank:]]*[^[:blank:]]*([[:alnum:]-]+\\.)+[[:alnum:]-][^[:blank:]]*[[:blank:]]*$") #define XT_INVALID_MARK (-1) /* XXX this is a double, maybe use something else, like a nan */ @@ -3346,7 +3345,7 @@ activate_search_entry_cb(GtkWidget* entry, struct tab *t) g_free(enc_search); marks_clear(t); - webkit_web_view_load_uri(t->wv, newuri); + load_uri(t, newuri); focus_webview(t); if (newuri) @@ -7676,11 +7675,6 @@ welcome(void) startpage_add("Details at " "<a href=https://opensource.conformal.com/wiki/xombrero>xombrero " "wiki page</a><p>"); - startpage_add("Unfortunately scroogle has shut it's doors and due to " - "that one has to edit search_string in ~/.xombrero.conf.<br>" - "There are various examples in the configuration file.<br>" - "The authors of xombrero are not in a position to suggest a search " - "engine."); } int @@ -7825,7 +7819,7 @@ main(int argc, char **argv) /* set default string settings */ home = g_strdup("https://www.cyphertite.com"); - search_string = g_strdup("https://ssl.scroogle.org/cgi-bin/nbbwssl.cgi?Gw=%s"); + search_string = g_strdup("about:search"); resource_dir = g_strdup("/usr/local/share/xombrero/"); strlcpy(runtime_settings, "runtime", sizeof runtime_settings); cmd_font_name = g_strdup("monospace normal 9"); diff --git a/xombrero.conf b/xombrero.conf index 9dc1157..0bd2878 100644 --- a/xombrero.conf +++ b/xombrero.conf @@ -69,12 +69,8 @@ # Search engines; uncomment one of these lines for you favorite search # engine. # -# Scroogle (default) -# search_string = https://ssl.scroogle.org/cgi-bin/nbbwssl.cgi?Gw=%s -# search_string = http://www.scroogle.org/cgi-bin/nbbw.cgi?Gw=%s -# # Google -# search_string = http://www.google.com/search?q=%s&&client=xombrero +# search_string = https://www.google.com/search?q=%s&&client=xombrero # # Yahoo # search_string = http://search.yahoo.com/search?p=%s @@ -120,7 +116,7 @@ # Where the link part might contain "%s", the "%s" will be substituted # with the user's input when the alias is expanded. -# alias = s, https://ssl.scroogle.org/cgi-bin/nbbwssl.cgi?Gw=%s +# alias = s, https://www.google.com/search?q=%s&&client=xombrero # alias = w, https://secure.wikimedia.org/wikipedia/en/w/index.php?title=Special%3ASearch&search=%s # alias = ports, http://openports.se/search.php?so=%s diff --git a/xombrero.h b/xombrero.h index cf90314..06049a3 100644 --- a/xombrero.h +++ b/xombrero.h @@ -322,6 +322,7 @@ RB_PROTOTYPE(strict_transport_tree, strict_transport, entry, strict_transport_rb #define XT_CB_PASSTHROUGH (FALSE) #define XT_FAVS_FILE ("favorites") #define XT_SOD_FILE ("startofday") +#define XT_RESERVED_CHARS "$&+,/:;=?@ \"<>#%%{}|^~[]`" int run_script(struct tab *, char *); void xt_icon_from_file(struct tab *, char *); @@ -399,6 +400,7 @@ char *tld_get_suffix(const char *); #define XT_URI_ABOUT_MARCO ("marco") #define XT_URI_ABOUT_STARTPAGE ("startpage") #define XT_URI_ABOUT_WEBKIT ("webkit") +#define XT_URI_ABOUT_SEARCH ("search") struct about_type { char *name; @@ -423,6 +425,7 @@ int xtp_page_cl(struct tab *, struct karg *); int xtp_page_dl(struct tab *, struct karg *); int xtp_page_fl(struct tab *, struct karg *); int xtp_page_hl(struct tab *, struct karg *); +int xtp_page_sl(struct tab *, struct karg *); int parse_xtp_url(struct tab *, const char *); int add_favorite(struct tab *, struct karg *); void update_favorite_tabs(struct tab *); @@ -445,6 +448,7 @@ void startpage_add(const char *, ...); #define XT_XTP_TAB_MEANING_DL (5) /* download manager in this tab */ #define XT_XTP_TAB_MEANING_FL (6) /* favorite manager in this tab */ #define XT_XTP_TAB_MEANING_HL (8) /* history manager in this tab */ +#define XT_XTP_TAB_MEANING_SL (9) /* XXX whut? */ /* whitelists */ #define XT_WL_TOGGLE (1<<0) @@ -599,6 +603,7 @@ int set_browser_mode(struct settings *, char *); int set_encoding(struct tab *, struct karg *); int set_gui_mode(struct settings *, char *); int set_cookie_policy(struct settings *, char *); +int set_search_string(char *); int set_ssl_ca_file(char *); char *get_browser_mode(struct settings *); char *get_gui_mode(struct settings *); |