NetSurf
Data Structures | Functions | Variables
searchweb.c File Reference

core web search facilities implementation. More...

#include <stdlib.h>
#include <string.h>
#include "utils/utils.h"
#include "utils/log.h"
#include "utils/url.h"
#include "utils/nsoption.h"
#include "netsurf/content.h"
#include "content/hlcache.h"
#include "desktop/searchweb.h"
#include "desktop/gui_internal.h"
Include dependency graph for searchweb.c:

Go to the source code of this file.

Data Structures

struct  search_provider
 
struct  search_web_ctx_s
 

Functions

static nserror read_providers (const char *fname, char **providers_out, size_t *providers_size_out)
 Read providers file. More...
 
static nserror parse_providers (char *providersd, size_t providers_size, struct search_provider **providers_out, size_t *providers_count)
 parse search providers from a memory block. More...
 
static nserror make_search_nsurl (struct search_provider *provider, const char *term, nsurl **url_out)
 create a url for a search provider and a term More...
 
static nserror search_web_ico_callback (hlcache_handle *ico, const hlcache_event *event, void *pw)
 callback for hlcache icon fetch events. More...
 
nserror search_web_omni (const char *term, enum search_web_omni_flags flags, struct nsurl **url_out)
 Generate a nsurl from a search term. More...
 
nserror search_web_get_provider_bitmap (struct bitmap **bitmap_out)
 obtain the current providers bitmap More...
 
nserror search_web_select_provider (const char *selection)
 Change the currently selected web search provider. More...
 
static nserror default_ico_callback (hlcache_handle *ico, const hlcache_event *event, void *pw)
 callback for hlcache icon fetch events. More...
 
ssize_t search_web_iterate_providers (ssize_t iter, const char **name)
 Iterate the search providers, returning their names. More...
 
nserror search_web_init (const char *provider_fname)
 Initialise the web search operations. More...
 
nserror search_web_finalise (void)
 Finalise the web search operations freeing all resources. More...
 

Variables

static struct search_web_ctx_s search_web_ctx
 
static const char * default_providers = "Google|www.google.com|https://www.google.com/search?q=%s|https://www.google.com/favicon.ico|\n"
 
static const char * default_search_icon_url = "resource:icons/search.png"
 

Detailed Description

core web search facilities implementation.

Definition in file searchweb.c.

Function Documentation

◆ default_ico_callback()

static nserror default_ico_callback ( hlcache_handle ico,
const hlcache_event event,
void *  pw 
)
static

callback for hlcache icon fetch events.

Definition at line 468 of file searchweb.c.

References content_get_bitmap(), CONTENT_MSG_DONE, CONTENT_MSG_ERROR, search_web_ctx_s::current, hlcache_event::data, search_web_ctx_s::default_ico_handle, content_msg_data::errordata, content_msg_data::errormsg, guit, hlcache_handle_get_url(), hlcache_handle_release(), search_provider::ico_handle, search_provider::name, NSERROR_OK, NSLOG, nsurl_access(), gui_search_web_table::provider_update, search_web_ctx_s::providers, netsurf_table::search_web, search_web_ctx, and hlcache_event::type.

Referenced by search_web_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_search_nsurl()

static nserror make_search_nsurl ( struct search_provider provider,
const char *  term,
nsurl **  url_out 
)
static

create a url for a search provider and a term

Parameters
providerThe provider to use.
termThe term being searched for.
url_outThe resulting url.
Returns
NSERROR_OK on success or appropriate error code.

Definition at line 231 of file searchweb.c.

References NSERROR_NOMEM, NSERROR_OK, nsurl_create(), search_provider::searchstring, and url_escape().

Referenced by search_web_omni().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_providers()

static nserror parse_providers ( char *  providersd,
size_t  providers_size,
struct search_provider **  providers_out,
size_t *  providers_count 
)
static

parse search providers from a memory block.

Parameters
providersdThe provider info data.
providers_sizeThe size of the provider data.
providers_outThe resulting provider array.
providers_countThe number of providers in the output array.
Returns
NSERROR_OK on success or error code on failure.

Definition at line 139 of file searchweb.c.

References search_provider::hostname, search_provider::ico, search_provider::ico_handle, search_provider::name, NSERROR_INVALID, NSERROR_NOMEM, NSERROR_OK, and search_provider::searchstring.

Referenced by search_web_init().

Here is the caller graph for this function:

◆ read_providers()

static nserror read_providers ( const char *  fname,
char **  providers_out,
size_t *  providers_size_out 
)
static

Read providers file.

Allocates storage of sufficient size for the providers file and reads the entire file in.

Parameters
fnameThe filename to read.
providers_outA pointer to place the result buffer in.
providers_size_outSize of buffer.
Returns
NSERROR_OK and providers_out updated or appropriate error code.

Definition at line 73 of file searchweb.c.

References NSERROR_BAD_PARAMETER, NSERROR_BAD_SIZE, NSERROR_INVALID, NSERROR_NOMEM, NSERROR_NOT_FOUND, and NSERROR_OK.

Referenced by search_web_init().

Here is the caller graph for this function:

◆ search_web_finalise()

nserror search_web_finalise ( void  )

Finalise the web search operations freeing all resources.

Returns
NSERROR_OK on success or appropriate error code.

Definition at line 582 of file searchweb.c.

References search_web_ctx_s::default_ico_handle, hlcache_handle_release(), search_provider::ico_handle, search_provider::name, NSERROR_INIT_FAILED, NSERROR_OK, search_web_ctx_s::providers, search_web_ctx_s::providers_count, and search_web_ctx.

Referenced by netsurf_exit(), and nsbeos_scaffolding_dispatch_event().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_web_get_provider_bitmap()

nserror search_web_get_provider_bitmap ( struct bitmap **  bitmap_out)

obtain the current providers bitmap

obtain the icon representing the current web search provider

Parameters
bitmap_outrecives the resulting bitmap which may be NULL
Returns
NSERROR_OK on success or NSERROR_INIT_FAILED if not initialised

Definition at line 370 of file searchweb.c.

References content_get_bitmap(), search_web_ctx_s::current, search_web_ctx_s::default_ico_handle, search_provider::ico_handle, NSERROR_INIT_FAILED, NSERROR_OK, search_web_ctx_s::providers, and search_web_ctx.

Referenced by make_toolbar_item_websearch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_web_ico_callback()

static nserror search_web_ico_callback ( hlcache_handle ico,
const hlcache_event event,
void *  pw 
)
static

callback for hlcache icon fetch events.

Definition at line 284 of file searchweb.c.

References content_get_bitmap(), CONTENT_MSG_DONE, CONTENT_MSG_ERROR, hlcache_event::data, content_msg_data::errordata, content_msg_data::errormsg, guit, hlcache_handle_get_url(), hlcache_handle_release(), search_provider::ico, search_provider::ico_handle, search_provider::name, NSERROR_OK, NSLOG, nsurl_access(), gui_search_web_table::provider_update, netsurf_table::search_web, and hlcache_event::type.

Referenced by search_web_select_provider().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_web_init()

nserror search_web_init ( const char *  provider_fname)

Initialise the web search operations.

Parameters
provider_fnamePath to web search providers file.
Returns
NSERROR_OK on successful initialisation or appropriate error code.

Definition at line 525 of file searchweb.c.

References CONTENT_IMAGE, default_ico_callback(), search_web_ctx_s::default_ico_handle, default_providers, default_search_icon_url, hlcache_handle_retrieve(), NSERROR_NOMEM, NSERROR_OK, nsurl_create(), nsurl_unref(), parse_providers(), search_web_ctx_s::providers, search_web_ctx_s::providers_count, read_providers(), and search_web_ctx.

Referenced by main(), nsbeos_scaffolding_dispatch_event(), and nsgtk_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_web_iterate_providers()

ssize_t search_web_iterate_providers ( ssize_t  iter,
const char **  name 
)

Iterate the search providers, returning their names.

Parameters
fromIndex to start iteration from. Use -1 to begin iteration. Use the value returned from search_web_iterate_providers to continue an iteration.
namePointer to fill in with the search provider name requested.
Returns
-1 if there are no more, otherwise the iterator for the next item.
*     ssize_t iter = -1;
*     const char *name;
*     ...
*     iter = search_web_iterate_providers(iter, &name);
*     while(iter !=-1) {
*         do_something_with(name);
*         iter = search_web_iterate_providers(iter, &name);
*     }
* 

Definition at line 506 of file searchweb.c.

References search_provider::name, search_web_ctx_s::providers, search_web_ctx_s::providers_count, and search_web_ctx.

Referenced by ami_gui_opts_websearch(), nsgtk_preferences_comboSearch_changed(), and nsgtk_preferences_comboSearch_realize().

Here is the caller graph for this function:

◆ search_web_omni()

nserror search_web_omni ( const char *  term,
enum search_web_omni_flags  flags,
struct nsurl **  url_out 
)

Generate a nsurl from a search term.

This interface obtains a url appropriate for the given search term. The flags allow control over the operation. By default the operations are:

  • interpret the term as a url
  • if missing a scheme as a https: url
  • combined with the search providers url into a url for that provider.
Parameters
termThe search term.
flagsFlags to control operation.
url_outThe ourput url on success.
Returns
NSERROR_OK on success or appropriate error code.

Definition at line 318 of file searchweb.c.

References search_web_ctx_s::current, make_search_nsurl(), NSERROR_BAD_URL, NSERROR_INIT_FAILED, NSERROR_NOMEM, NSERROR_OK, nsoption_bool, nsurl_create(), search_web_ctx_s::providers, search_web_ctx, SEARCH_WEB_OMNI_SEARCHONLY, and SLEN.

Referenced by ami_gui_event(), nsbeos_scaffolding_dispatch_event(), nsgtk_completion_match_select(), ro_gui_dialog_openurl_apply(), ro_gui_window_launch_url(), url_entry_activate_cb(), and websearch_entry_activate_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_web_select_provider()

nserror search_web_select_provider ( const char *  selection)

Change the currently selected web search provider.

Parameters
selectionName of the search provider to select or NULL to reselect the current provider
Returns
NSERROR_OK on success or appropriate error code.

Definition at line 397 of file searchweb.c.

References content_get_bitmap(), CONTENT_IMAGE, search_web_ctx_s::current, search_web_ctx_s::default_ico_handle, guit, hlcache_handle_retrieve(), search_provider::ico, search_provider::ico_handle, search_provider::name, NSERROR_INIT_FAILED, NSERROR_OK, nsurl_create(), nsurl_unref(), gui_search_web_table::provider_update, search_web_ctx_s::providers, search_web_ctx_s::providers_count, netsurf_table::search_web, search_web_ctx, and search_web_ico_callback().

Referenced by ami_gui_event(), ami_gui_opts_use(), gui_init2(), nsgtk_preferences_comboSearch_changed(), and nsgtk_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ default_providers

const char* default_providers = "Google|www.google.com|https://www.google.com/search?q=%s|https://www.google.com/favicon.ico|\n"
static

Definition at line 56 of file searchweb.c.

Referenced by search_web_init().

◆ default_search_icon_url

const char* default_search_icon_url = "resource:icons/search.png"
static

Definition at line 58 of file searchweb.c.

Referenced by search_web_init().

◆ search_web_ctx

struct search_web_ctx_s search_web_ctx
static