Compare commits
43 Commits
e48c6366d0
...
05cb1387f4
| Author | SHA1 | Date | |
|---|---|---|---|
| 05cb1387f4 | |||
| 1e0eb470c6 | |||
| 6a60c0fd5d | |||
|
|
e72fadc791 | ||
|
|
186f66619c | ||
|
|
b8c920ef0a | ||
|
|
09e1f7e1ea | ||
|
|
250898c638 | ||
|
|
bd3da22325 | ||
|
|
e5a836e135 | ||
|
|
c9471adb9c | ||
|
|
2d2bb4916d | ||
|
|
7a584d8a97 | ||
|
|
3fb6f96d13 | ||
|
|
a17f023821 | ||
|
|
f41fa9e4b3 | ||
|
|
acdff2d3a2 | ||
|
|
892acdc7f2 | ||
|
|
4a705bd1b8 | ||
|
|
aace4b8f91 | ||
|
|
e352971bc5 | ||
|
|
12f046669e | ||
|
|
68d9d46e5e | ||
|
|
bc0bc73044 | ||
|
|
b23e5eeb6d | ||
|
|
f1c35fde85 | ||
|
|
a20a9e8878 | ||
|
|
10d44e7ff5 | ||
|
|
f20d8f7115 | ||
|
|
d93fead0ae | ||
|
|
296021e0ce | ||
|
|
499bb9b126 | ||
|
|
11acc93f43 | ||
|
|
2419dec7f8 | ||
|
|
7b587d82c8 | ||
|
|
9c68a8ae6f | ||
|
|
953937cfa2 | ||
|
|
1b36b1a23e | ||
|
|
de6d8d1bfd | ||
|
|
36a7cabc3b | ||
|
|
4d54ded6e6 | ||
|
|
ad949a452f | ||
|
|
24f9909bad |
@@ -12,7 +12,7 @@ RUN apk add --no-cache \
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . /app
|
COPY . /app
|
||||||
|
|
||||||
RUN git clone https://git.bwaaa.monster/beaker /tmp/beaker && \
|
RUN git clone https://git.bwaaa.space/beaker /tmp/beaker && \
|
||||||
cd /tmp/beaker && \
|
cd /tmp/beaker && \
|
||||||
make && make install && \
|
make && make install && \
|
||||||
rm -rf /tmp/beaker
|
rm -rf /tmp/beaker
|
||||||
|
|||||||
3
Makefile
3
Makefile
@@ -7,8 +7,9 @@ GIT_HASH := $(shell git rev-parse --short HEAD)
|
|||||||
GIT_DATE := $(shell git log -1 --format='%ad' --date='format:%y.%m.%d')
|
GIT_DATE := $(shell git log -1 --format='%ad' --date='format:%y.%m.%d')
|
||||||
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
||||||
GIT_REMOTE := $(shell git remote get-url origin)
|
GIT_REMOTE := $(shell git remote get-url origin)
|
||||||
|
GIT_TAG := $(shell git describe --tags --exact-match HEAD 2>/dev/null)
|
||||||
|
|
||||||
VERSION := $(GIT_DATE)+$(GIT_HASH)_$(GIT_BRANCH)
|
VERSION := $(if $(GIT_TAG),$(GIT_TAG),$(GIT_DATE)+$(GIT_HASH)_$(GIT_BRANCH))
|
||||||
|
|
||||||
CFLAGS := -Wall -Wextra -O2 -Isrc -DVERSION='"$(VERSION)"' -DGIT_REMOTE='"$(GIT_REMOTE)"'
|
CFLAGS := -Wall -Wextra -O2 -Isrc -DVERSION='"$(VERSION)"' -DGIT_REMOTE='"$(GIT_REMOTE)"'
|
||||||
|
|
||||||
|
|||||||
36
README.md
36
README.md
@@ -11,7 +11,7 @@ Create a config.ini, there is an example included in the root. Or if you install
|
|||||||
## Dependencies
|
## Dependencies
|
||||||
- libxml2
|
- libxml2
|
||||||
- libcurl (may be replaced in the future with curl-impersonate)
|
- libcurl (may be replaced in the future with curl-impersonate)
|
||||||
- beaker [(source)](https://git.bwaaa.monster/beaker/)
|
- beaker [(source)](https://git.bwaaa.space/beaker/)
|
||||||
|
|
||||||
## First Setup
|
## First Setup
|
||||||
Depending on your system, you may first need to install libcurl and libxml2.
|
Depending on your system, you may first need to install libcurl and libxml2.
|
||||||
@@ -47,32 +47,6 @@ On Alpine, `shadow` is needed for the user creation process during the install.
|
|||||||
# xbps-install -S libxml2-devel libcurl-devel
|
# xbps-install -S libxml2-devel libcurl-devel
|
||||||
```
|
```
|
||||||
|
|
||||||
### NixOS
|
|
||||||
Add the flake to your inputs and import the module. That is all you need.
|
|
||||||
Here's an example of using the modules in a flake:
|
|
||||||
```nix
|
|
||||||
# flake.nix
|
|
||||||
{
|
|
||||||
inputs = {
|
|
||||||
omnisearch = {
|
|
||||||
url = "git+https://git.bwaaa.monster/omnisearch";
|
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
outputs = { self, nixpkgs, omnisearch, ... }: {
|
|
||||||
nixosConfigurations.mySystem = nixpkgs.lib.nixosSystem {
|
|
||||||
modules = [
|
|
||||||
omnisearch.nixosModules.default
|
|
||||||
{
|
|
||||||
services.omnisearch.enable = true;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### macOS (Homebrew)
|
### macOS (Homebrew)
|
||||||
```
|
```
|
||||||
$ brew install libxml2 curl openssl pkg-config
|
$ brew install libxml2 curl openssl pkg-config
|
||||||
@@ -87,7 +61,7 @@ On macOS the build uses `pkg-config` to discover `libxml2`, `libcurl` and OpenSS
|
|||||||
|
|
||||||
Install libbeaker:
|
Install libbeaker:
|
||||||
```
|
```
|
||||||
$ git clone https://git.bwaaa.monster/beaker
|
$ git clone https://git.bwaaa.space/beaker
|
||||||
$ cd beaker
|
$ cd beaker
|
||||||
$ make
|
$ make
|
||||||
# make install
|
# make install
|
||||||
@@ -97,7 +71,7 @@ On macOS `beaker` installs to `/usr/local/` by default and installs `libbeaker.d
|
|||||||
|
|
||||||
And then install omnisearch:
|
And then install omnisearch:
|
||||||
```
|
```
|
||||||
$ git clone https://git.bwaaa.monster/omnisearch
|
$ git clone https://git.bwaaa.space/omnisearch
|
||||||
$ cd omnisearch
|
$ cd omnisearch
|
||||||
$ make
|
$ make
|
||||||
# make install-<init>
|
# make install-<init>
|
||||||
@@ -115,7 +89,7 @@ You need Docker or Podman and Docker Compose installed on your system.
|
|||||||
Run the container:
|
Run the container:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ git clone https://git.bwaaa.monster/omnisearch
|
$ git clone https://git.bwaaa.space/omnisearch
|
||||||
$ cd omnisearch
|
$ cd omnisearch
|
||||||
$ docker compose up -d --build
|
$ docker compose up -d --build
|
||||||
```
|
```
|
||||||
@@ -139,6 +113,6 @@ $ git merge origin/master
|
|||||||
If there are conflicts in the files you modified, resolve them manually. You should also make the changes to the cloned repository, and then run the install command again if you installed omnisearch. Changes made directly to the configuration/assets folder will be overwritten on reinstall.
|
If there are conflicts in the files you modified, resolve them manually. You should also make the changes to the cloned repository, and then run the install command again if you installed omnisearch. Changes made directly to the configuration/assets folder will be overwritten on reinstall.
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
Generate a patch with ```git format-patch HEAD~1``` and email to [gabriel@bwaaa.monster](mailto:gabriel@bwaaa.monster), beginning the subject line with [PATCH omnisearch]
|
Generate a patch with ```git format-patch HEAD~1``` and email to [frostinator33@airmail.cc](mailto:frostinator33@airmail.cc), beginning the subject line with [PATCH omnisearch]
|
||||||
|
|
||||||
*If you are sending a revised version of a previous patch, please use [PATCH omnisearch v2, v3, etc].*
|
*If you are sending a revised version of a previous patch, please use [PATCH omnisearch v2, v3, etc].*
|
||||||
|
|||||||
@@ -31,8 +31,11 @@ port = 8087
|
|||||||
[engines]
|
[engines]
|
||||||
# Use * for all engines, or specify comma-separated list (e.g., ddg,yahoo)
|
# Use * for all engines, or specify comma-separated list (e.g., ddg,yahoo)
|
||||||
# Use *,-engine to exclude specific engines (e.g., *,-startpage)
|
# Use *,-engine to exclude specific engines (e.g., *,-startpage)
|
||||||
# Available engines: ddg, startpage, yahoo, mojeek
|
# Available engines: ddg, startpage, yahoo, mojeek, yacy
|
||||||
engines="*"
|
engines="*"
|
||||||
|
# YaCy instance to use for the yacy engine (optional, default: http://127.0.0.1:8090)
|
||||||
|
# Requires "yacy" to be in the engines list above.
|
||||||
|
#yacy_instance = http://127.0.0.1:8090
|
||||||
|
|
||||||
[rate_limit]
|
[rate_limit]
|
||||||
# Rate limit searches per interval
|
# Rate limit searches per interval
|
||||||
|
|||||||
18
flake.lock
generated
18
flake.lock
generated
@@ -3,28 +3,28 @@
|
|||||||
"beaker-src": {
|
"beaker-src": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1780436704,
|
"lastModified": 1793900580,
|
||||||
"narHash": "sha256-3aMH1YblnpiXKdkQVMRLmMZ5/8G7vB4HAfLg7+izyHg=",
|
"narHash": "sha256-TWJAVS60lHQO+4Gmt86qlT7RN25HrqCSl3n7EE+OP1o=",
|
||||||
"ref": "refs/heads/master",
|
"ref": "refs/heads/master",
|
||||||
"rev": "360d6271e1a20d128430e52637d5d35f4c706ca5",
|
"rev": "aedf6c0c93acb2a8f57ef3f94498332b3ab6db89",
|
||||||
"revCount": 34,
|
"revCount": 48,
|
||||||
"shallow": false,
|
"shallow": false,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.bwaaa.monster/beaker"
|
"url": "https://git.bwaaa.space/beaker"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"shallow": false,
|
"shallow": false,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.bwaaa.monster/beaker"
|
"url": "https://git.bwaaa.space/beaker"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1780243769,
|
"lastModified": 1794386569,
|
||||||
"narHash": "sha256-x5UQuRsH3MqI0U9afaXSNqzTPSeZlRLvFAav2Ux1pNw=",
|
"narHash": "sha256-x9sADJvoVG0L6RejZB+/BB4YiGZFBZrfTlhF4uBq1tQ=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "331800de5053fcebacf6813adb5db9c9dca22a0c",
|
"rev": "d4f25a3e562008648d45bcf2d70bcc7422cad84e",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
125
flake.nix
125
flake.nix
@@ -2,75 +2,70 @@
|
|||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
beaker-src = {
|
beaker-src = {
|
||||||
url = "git+https://git.bwaaa.monster/beaker?shallow=0";
|
url = "git+https://git.bwaaa.space/beaker?shallow=0";
|
||||||
flake = false;
|
flake = false;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs = {
|
||||||
{
|
self,
|
||||||
self,
|
nixpkgs,
|
||||||
nixpkgs,
|
beaker-src,
|
||||||
beaker-src,
|
}: let
|
||||||
}:
|
supportedSystems = [
|
||||||
let
|
"x86_64-linux"
|
||||||
supportedSystems = [
|
"aarch64-linux"
|
||||||
"x86_64-linux"
|
];
|
||||||
"aarch64-linux"
|
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||||
];
|
in {
|
||||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt);
|
||||||
in
|
packages = forAllSystems (
|
||||||
{
|
system: let
|
||||||
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt);
|
pkgs = import nixpkgs {inherit system;};
|
||||||
packages = forAllSystems (
|
|
||||||
system:
|
|
||||||
let
|
|
||||||
pkgs = import nixpkgs { inherit system; };
|
|
||||||
|
|
||||||
beaker = pkgs.stdenv.mkDerivation {
|
beaker = pkgs.stdenv.mkDerivation {
|
||||||
pname = "beaker";
|
pname = "beaker";
|
||||||
version = "git";
|
version = "git";
|
||||||
src = beaker-src;
|
src = beaker-src;
|
||||||
makeFlags = [
|
makeFlags = [
|
||||||
"INSTALL_PREFIX=$(out)/"
|
"INSTALL_PREFIX=$(out)/"
|
||||||
"LDCONFIG=true"
|
"LDCONFIG=true"
|
||||||
];
|
];
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
default = pkgs.stdenv.mkDerivation {
|
||||||
|
pname = "omnisearch";
|
||||||
|
version = "git";
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
buildInputs = [
|
||||||
|
pkgs.libxml2.dev
|
||||||
|
pkgs.curl.dev
|
||||||
|
pkgs.openssl
|
||||||
|
beaker
|
||||||
|
];
|
||||||
|
|
||||||
|
preBuild = ''
|
||||||
|
makeFlagsArray+=(
|
||||||
|
"PREFIX=$out"
|
||||||
|
"CFLAGS=-Wall -Wextra -O2 -Isrc -I${pkgs.libxml2.dev}/include/libxml2"
|
||||||
|
"LIBS=-lbeaker -lcurl -lxml2 -lpthread -lm -lssl -lcrypto"
|
||||||
|
)
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/bin $out/share/omnisearch
|
||||||
|
install -Dm755 bin/omnisearch $out/bin/omnisearch
|
||||||
|
cp -r templates static locales -t $out/share/omnisearch/
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
description = "Lightweight metasearch engine in C";
|
||||||
|
platforms = pkgs.lib.platforms.linux;
|
||||||
};
|
};
|
||||||
in
|
};
|
||||||
{
|
}
|
||||||
default = pkgs.stdenv.mkDerivation {
|
);
|
||||||
pname = "omnisearch";
|
nixosModules.default = import ./module.nix self;
|
||||||
version = "git";
|
};
|
||||||
src = ./.;
|
|
||||||
|
|
||||||
buildInputs = [
|
|
||||||
pkgs.libxml2.dev
|
|
||||||
pkgs.curl.dev
|
|
||||||
pkgs.openssl
|
|
||||||
beaker
|
|
||||||
];
|
|
||||||
|
|
||||||
preBuild = ''
|
|
||||||
makeFlagsArray+=(
|
|
||||||
"PREFIX=$out"
|
|
||||||
"CFLAGS=-Wall -Wextra -O2 -Isrc -I${pkgs.libxml2.dev}/include/libxml2"
|
|
||||||
"LIBS=-lbeaker -lcurl -lxml2 -lpthread -lm -lssl -lcrypto"
|
|
||||||
)
|
|
||||||
'';
|
|
||||||
|
|
||||||
installPhase = ''
|
|
||||||
mkdir -p $out/bin $out/share/omnisearch
|
|
||||||
install -Dm755 bin/omnisearch $out/bin/omnisearch
|
|
||||||
cp -r templates static locales -t $out/share/omnisearch/
|
|
||||||
'';
|
|
||||||
|
|
||||||
meta = {
|
|
||||||
description = "Lightweight metasearch engine in C";
|
|
||||||
platforms = pkgs.lib.platforms.linux;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
nixosModules.default = import ./module.nix self;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,3 +7,4 @@ logfile-uid = omnisearch
|
|||||||
logfile-gid = omnisearch
|
logfile-gid = omnisearch
|
||||||
restart = yes
|
restart = yes
|
||||||
restart-delay = 5
|
restart-delay = 5
|
||||||
|
waits-for = login.target
|
||||||
34
locales/de_de.ini
Normal file
34
locales/de_de.ini
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[Meta]
|
||||||
|
Id = "de_de"
|
||||||
|
Name = "Deutsch (DE)"
|
||||||
|
Direction = "ltr"
|
||||||
|
|
||||||
|
[Keys]
|
||||||
|
search_placeholder = "Suche das Internet..."
|
||||||
|
search_button = "Suchen"
|
||||||
|
surprise_me_button = "Überrasche mich"
|
||||||
|
all_tab = "Alle"
|
||||||
|
images_tab = "Bilder"
|
||||||
|
settings_tab = "Einstellungen"
|
||||||
|
settings_title = "Einstellungen"
|
||||||
|
theme_label = "Aussehen"
|
||||||
|
theme_desc = "Wähle ein Erscheinungsbild."
|
||||||
|
theme_system = "System"
|
||||||
|
theme_light = "Hell"
|
||||||
|
theme_dark = "Dunkel"
|
||||||
|
language_label = "Sprache"
|
||||||
|
display_language_label = "Anzeigesprache"
|
||||||
|
language_desc = "Wähle deine Sprache."
|
||||||
|
engines_label = "Suchmaschinen"
|
||||||
|
engines_desc = "Wähle die Suchmachinen die verwendet werden sollen. Nur Suchmachinen, die am Server aktiviert sind, werden gezeigt."
|
||||||
|
save_settings_button = "Einstellungen speichern"
|
||||||
|
no_results = "Keine Ergebnisse gefunden"
|
||||||
|
error_images = "Error beim Holen von Bildern"
|
||||||
|
rate_limit = "Langsam! Es kommen zu viele Anfragen von dir!"
|
||||||
|
warning_fetch_error = "Anfrage fehlgeschlagen bevor Omnisearch Suchergebnisse lesen konnte."
|
||||||
|
warning_parse_mismatch = "Bekam Suchergebnisse die von Omnisearch nicht geparst werden konnte."
|
||||||
|
warning_blocked = "Bekam ein Captcha oder Blocking-Seite statt Suchergebnisse"
|
||||||
|
read_more = "Mehr lesen"
|
||||||
|
view_cached = "Zwischengespeichert"
|
||||||
|
view_image = "Bild"
|
||||||
|
visit_site = "Seite"
|
||||||
@@ -21,6 +21,8 @@ display_language_label = "Display Language"
|
|||||||
language_desc = "Choose your preferred language."
|
language_desc = "Choose your preferred language."
|
||||||
engines_label = "Search Engines"
|
engines_label = "Search Engines"
|
||||||
engines_desc = "Choose which search engines to use. Only engines enabled on the server are shown."
|
engines_desc = "Choose which search engines to use. Only engines enabled on the server are shown."
|
||||||
|
default_engine_label = "Default Search Engine"
|
||||||
|
all_engines_option = "All enabled engines"
|
||||||
save_settings_button = "Save Settings"
|
save_settings_button = "Save Settings"
|
||||||
no_results = "No results found"
|
no_results = "No results found"
|
||||||
error_images = "Error fetching images"
|
error_images = "Error fetching images"
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ display_language_label = "Display Language"
|
|||||||
language_desc = "Choose your preferred language."
|
language_desc = "Choose your preferred language."
|
||||||
engines_label = "Search Engines"
|
engines_label = "Search Engines"
|
||||||
engines_desc = "Choose which search engines to use. Only engines enabled on the server are shown."
|
engines_desc = "Choose which search engines to use. Only engines enabled on the server are shown."
|
||||||
|
default_engine_label = "Default Search Engine"
|
||||||
|
all_engines_option = "All enabled engines"
|
||||||
save_settings_button = "Save Settings"
|
save_settings_button = "Save Settings"
|
||||||
no_results = "No results found"
|
no_results = "No results found"
|
||||||
error_images = "Error fetching images"
|
error_images = "Error fetching images"
|
||||||
|
|||||||
34
locales/es_es.ini
Normal file
34
locales/es_es.ini
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[Meta]
|
||||||
|
Id = "es_es"
|
||||||
|
Name = "Español (España)"
|
||||||
|
Direction = "ltr"
|
||||||
|
|
||||||
|
[Keys]
|
||||||
|
search_placeholder = "Buscar en internet..."
|
||||||
|
search_button = "Buscar"
|
||||||
|
surprise_me_button = "Sorpréndeme"
|
||||||
|
all_tab = "Todo"
|
||||||
|
images_tab = "Imágenes"
|
||||||
|
settings_tab = "Configuración"
|
||||||
|
settings_title = "Configuración"
|
||||||
|
theme_label = "Apariencia"
|
||||||
|
theme_desc = "Elige tu paleta de color preferida."
|
||||||
|
theme_system = "Sistema"
|
||||||
|
theme_light = "Claro"
|
||||||
|
theme_dark = "Oscuro"
|
||||||
|
language_label = "Idioma"
|
||||||
|
display_language_label = "Idioma de la interfaz"
|
||||||
|
language_desc = "Elige tu idioma preferido."
|
||||||
|
engines_label = "Motores de búsqueda"
|
||||||
|
engines_desc = "Elige qué motores de búsqueda usar. Solo se muestran los motores habilitados en el servidor."
|
||||||
|
save_settings_button = "Guardar configuración"
|
||||||
|
no_results = "No se encontraron resultados"
|
||||||
|
error_images = "Error al obtener imágenes"
|
||||||
|
rate_limit = "¡Más despacio! ¡Demasiadas búsquedas tuyas!"
|
||||||
|
warning_fetch_error = "la petición falló antes de que OmniSearch pudiése leer los resultados de búsqueda."
|
||||||
|
warning_parse_mismatch = "devolvió resultados de búsqueda en un formato que OmniSearch no pudo leer."
|
||||||
|
warning_blocked = "devolvió un captcha u otra página de bloqueo en lugar de resultados de búsqueda."
|
||||||
|
read_more = "Leer más"
|
||||||
|
view_cached = "En caché"
|
||||||
|
view_image = "Imagen"
|
||||||
|
visit_site = "Página web"
|
||||||
36
locales/fi_fi.ini
Normal file
36
locales/fi_fi.ini
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
[Meta]
|
||||||
|
Id = "fi_fi"
|
||||||
|
Name = "Suomi"
|
||||||
|
Direction = "ltr"
|
||||||
|
|
||||||
|
[Keys]
|
||||||
|
search_placeholder = "Hae netistä..."
|
||||||
|
search_button = "Hae"
|
||||||
|
surprise_me_button = "Kokeilen onneani"
|
||||||
|
all_tab = "Kaikki"
|
||||||
|
images_tab = "Kuvat"
|
||||||
|
settings_tab = "Asetukset"
|
||||||
|
settings_title = "Asetukset"
|
||||||
|
theme_label = "Ulkonäkö"
|
||||||
|
theme_desc = "Valitse haluamasi väriteema."
|
||||||
|
theme_system = "Järjestelmä"
|
||||||
|
theme_light = "Vaalea"
|
||||||
|
theme_dark = "Tumma"
|
||||||
|
language_label = "Kieli"
|
||||||
|
display_language_label = "Näyttökieli"
|
||||||
|
language_desc = "Valitse haluamasi kieli."
|
||||||
|
engines_label = "Hakukoneet"
|
||||||
|
engines_desc = "Valitse mitä hakukoneita käytetään. Vain palvelimella käyttöön otetut hakukoneet näytetään."
|
||||||
|
default_engine_label = "Oletushakukone"
|
||||||
|
all_engines_option = "Kaikki valitut hakukoneet"
|
||||||
|
save_settings_button = "Tallenna asetukset"
|
||||||
|
no_results = "Ei tuloksia"
|
||||||
|
error_images = "Virhe kuvien haussa"
|
||||||
|
rate_limit = "Hidasta hieman! Sinulta on tullut liian monta hakupyyntöä!"
|
||||||
|
warning_fetch_error = "pyyntö epäonnistui ennen kuin OmniSearch ehti lukea hakutuloksia."
|
||||||
|
warning_parse_mismatch = "palautti hakutulokset muodossa jota OmniSearch ei osaa jäsentää."
|
||||||
|
warning_blocked = "palautti captchan tai muun estosivun hakutulosten sijaan."
|
||||||
|
read_more = "Lue Lisää"
|
||||||
|
view_cached = "Välimuistissa"
|
||||||
|
view_image = "Kuva"
|
||||||
|
visit_site = "Sivu"
|
||||||
34
locales/it_it.ini
Normal file
34
locales/it_it.ini
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[Meta]
|
||||||
|
Id = "it_it"
|
||||||
|
Name = "Italiano (Italia)"
|
||||||
|
Direction = "ltr"
|
||||||
|
|
||||||
|
[Keys]
|
||||||
|
search_placeholder = "Ricerca sul web..."
|
||||||
|
search_button = "Cerca"
|
||||||
|
surprise_me_button = "Sorprendimi"
|
||||||
|
all_tab = "Tutti"
|
||||||
|
images_tab = "Immagini"
|
||||||
|
settings_tab = "Impostazioni"
|
||||||
|
settings_title = "Impostazioni"
|
||||||
|
theme_label = "Aspetto"
|
||||||
|
theme_desc = "Scegli la tua combinazione di colori desiderata."
|
||||||
|
theme_system = "Sistema"
|
||||||
|
theme_light = "Chiaro"
|
||||||
|
theme_dark = "Scuro"
|
||||||
|
language_label = "Lingua"
|
||||||
|
display_language_label = "Lingua di visualizzazione"
|
||||||
|
language_desc = "Scegli la tua lingua desiderata."
|
||||||
|
engines_label = "Motori di ricerca"
|
||||||
|
engines_desc = "Scegli quali motori di ricerca usare. Solo i motori di ricerca abilitati verranno mostrati."
|
||||||
|
save_settings_button = "Salva Impostazioni"
|
||||||
|
no_results = "Nessun risultato trovato"
|
||||||
|
error_images = "Errore nel riportare le immagini"
|
||||||
|
rate_limit = "Rallenta! Troppe ricerche da parte tua!"
|
||||||
|
warning_fetch_error = "richiesta fallita prima che OmniSearch potesse leggere i risultati."
|
||||||
|
warning_parse_mismatch = "I risultati della ricerca restituiti sono in un formato che OmniSearch non è riuscito ad analizzare."
|
||||||
|
warning_blocked = "È stato restituito un captcha o un'altra pagina di blocco invece dei risultati della ricerca."
|
||||||
|
read_more = "Leggi di più"
|
||||||
|
view_cached = "Nella Cache"
|
||||||
|
view_image = "Immagine"
|
||||||
|
visit_site = "Sito"
|
||||||
142
module.nix
142
module.nix
@@ -1,142 +0,0 @@
|
|||||||
self:
|
|
||||||
|
|
||||||
{
|
|
||||||
config,
|
|
||||||
lib,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
|
|
||||||
let
|
|
||||||
cfg = config.services.omnisearch;
|
|
||||||
pkg = cfg.package;
|
|
||||||
|
|
||||||
finalConfigFile =
|
|
||||||
if cfg.configFile != null then
|
|
||||||
cfg.configFile
|
|
||||||
else
|
|
||||||
pkgs.writeText "omnisearch.ini" ''
|
|
||||||
[server]
|
|
||||||
host = ${cfg.settings.server.host}
|
|
||||||
port = ${toString cfg.settings.server.port}
|
|
||||||
domain = ${cfg.settings.server.domain}
|
|
||||||
${lib.optionalString (cfg.settings.server.locale != null) "locale = ${cfg.settings.server.locale}"}
|
|
||||||
|
|
||||||
[proxy]
|
|
||||||
${lib.optionalString (cfg.settings.proxy.proxy != null) "proxy = \"${cfg.settings.proxy.proxy}\""}
|
|
||||||
${lib.optionalString (
|
|
||||||
cfg.settings.proxy.list_file != null
|
|
||||||
) "list_file = ${cfg.settings.proxy.list_file}"}
|
|
||||||
max_retries = ${toString cfg.settings.proxy.max_retries}
|
|
||||||
randomize_username = ${lib.boolToString cfg.settings.proxy.randomize_username}
|
|
||||||
randomize_password = ${lib.boolToString cfg.settings.proxy.randomize_password}
|
|
||||||
|
|
||||||
[cache]
|
|
||||||
dir = ${cfg.settings.cache.dir}
|
|
||||||
ttl_search = ${toString cfg.settings.cache.ttl_search}
|
|
||||||
ttl_infobox = ${toString cfg.settings.cache.ttl_infobox}
|
|
||||||
'';
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options.services.omnisearch = {
|
|
||||||
enable = lib.mkEnableOption "OmniSearch metasearch engine";
|
|
||||||
|
|
||||||
package = lib.mkOption {
|
|
||||||
type = lib.types.package;
|
|
||||||
default = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
|
||||||
description = "The omnisearch package to use.";
|
|
||||||
};
|
|
||||||
|
|
||||||
configFile = lib.mkOption {
|
|
||||||
type = lib.types.nullOr lib.types.path;
|
|
||||||
default = null;
|
|
||||||
description = "Path to a custom config.ini. Overrides 'settings'.";
|
|
||||||
};
|
|
||||||
|
|
||||||
settings = {
|
|
||||||
server = {
|
|
||||||
host = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "0.0.0.0";
|
|
||||||
};
|
|
||||||
port = lib.mkOption {
|
|
||||||
type = lib.types.port;
|
|
||||||
default = 8087;
|
|
||||||
};
|
|
||||||
domain = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "http://localhost:${toString cfg.settings.server.port}";
|
|
||||||
};
|
|
||||||
locale = lib.mkOption {
|
|
||||||
type = lib.types.nullOr lib.types.str;
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
proxy = {
|
|
||||||
proxy = lib.mkOption {
|
|
||||||
type = lib.types.nullOr lib.types.str;
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
list_file = lib.mkOption {
|
|
||||||
type = lib.types.nullOr lib.types.str;
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
max_retries = lib.mkOption {
|
|
||||||
type = lib.types.int;
|
|
||||||
default = 3;
|
|
||||||
};
|
|
||||||
randomize_username = lib.mkOption {
|
|
||||||
type = lib.types.bool;
|
|
||||||
default = true;
|
|
||||||
};
|
|
||||||
randomize_password = lib.mkOption {
|
|
||||||
type = lib.types.bool;
|
|
||||||
default = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
cache = {
|
|
||||||
dir = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "/var/cache/omnisearch";
|
|
||||||
};
|
|
||||||
ttl_search = lib.mkOption {
|
|
||||||
type = lib.types.int;
|
|
||||||
default = 3600;
|
|
||||||
};
|
|
||||||
ttl_infobox = lib.mkOption {
|
|
||||||
type = lib.types.int;
|
|
||||||
default = 86400;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
|
||||||
systemd.services.omnisearch = {
|
|
||||||
description = "OmniSearch Service";
|
|
||||||
after = [ "network.target" ];
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
|
||||||
|
|
||||||
serviceConfig = {
|
|
||||||
ExecStart = "${pkg}/bin/omnisearch";
|
|
||||||
|
|
||||||
WorkingDirectory = "/var/lib/omnisearch";
|
|
||||||
StateDirectory = "omnisearch";
|
|
||||||
CacheDirectory = "omnisearch";
|
|
||||||
|
|
||||||
BindReadOnlyPaths = [
|
|
||||||
"${pkg}/share/omnisearch/templates:/var/lib/omnisearch/templates"
|
|
||||||
"${pkg}/share/omnisearch/static:/var/lib/omnisearch/static"
|
|
||||||
"${pkg}/share/omnisearch/locales:/var/lib/omnisearch/locales"
|
|
||||||
"${finalConfigFile}:/var/lib/omnisearch/config.ini"
|
|
||||||
];
|
|
||||||
|
|
||||||
DynamicUser = true;
|
|
||||||
ProtectSystem = "strict";
|
|
||||||
ProtectHome = true;
|
|
||||||
PrivateTmp = true;
|
|
||||||
Restart = "always";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -36,7 +36,7 @@ static void md5_hash(const char *str, char *output) {
|
|||||||
EVP_DigestFinal_ex(ctx, hash, &hash_len);
|
EVP_DigestFinal_ex(ctx, hash, &hash_len);
|
||||||
EVP_MD_CTX_free(ctx);
|
EVP_MD_CTX_free(ctx);
|
||||||
for (unsigned int i = 0; i < hash_len; i++) {
|
for (unsigned int i = 0; i < hash_len; i++) {
|
||||||
sprintf(output + (i * 2), "%02x", hash[i]);
|
snprintf(output + (i * 2), 3, "%02x", hash[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,11 +50,9 @@ static time_t get_file_mtime(const char *filepath) {
|
|||||||
|
|
||||||
int cache_init(const char *dir) {
|
int cache_init(const char *dir) {
|
||||||
if (!dir || strlen(dir) == 0) {
|
if (!dir || strlen(dir) == 0) {
|
||||||
strncpy(cache_dir, DEFAULT_CACHE_DIR, sizeof(cache_dir) - 1);
|
snprintf(cache_dir, sizeof(cache_dir), "%s", DEFAULT_CACHE_DIR);
|
||||||
cache_dir[sizeof(cache_dir) - 1] = '\0';
|
|
||||||
} else {
|
} else {
|
||||||
strncpy(cache_dir, dir, sizeof(cache_dir) - 1);
|
snprintf(cache_dir, sizeof(cache_dir), "%s", dir);
|
||||||
cache_dir[sizeof(cache_dir) - 1] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|||||||
251
src/Config.c
251
src/Config.c
@@ -1,120 +1,189 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CONFIG_STRING,
|
||||||
|
CONFIG_INTEGER,
|
||||||
|
CONFIG_BOOLEAN,
|
||||||
|
} ConfigValueType;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char *section;
|
||||||
|
const char *key;
|
||||||
|
ConfigValueType type;
|
||||||
|
size_t offset;
|
||||||
|
size_t size;
|
||||||
|
} ConfigOption;
|
||||||
|
|
||||||
|
#define STRING_OPTION(section_name, key_name, field) \
|
||||||
|
{section_name, key_name, CONFIG_STRING, offsetof(Config, field), \
|
||||||
|
sizeof(((Config *)0)->field)}
|
||||||
|
#define INTEGER_OPTION(section_name, key_name, field) \
|
||||||
|
{section_name, key_name, CONFIG_INTEGER, offsetof(Config, field), 0}
|
||||||
|
#define BOOLEAN_OPTION(section_name, key_name, field) \
|
||||||
|
{section_name, key_name, CONFIG_BOOLEAN, offsetof(Config, field), 0}
|
||||||
|
|
||||||
|
static const ConfigOption CONFIG_OPTIONS[] = {
|
||||||
|
STRING_OPTION("server", "host", host),
|
||||||
|
INTEGER_OPTION("server", "port", port),
|
||||||
|
STRING_OPTION("server", "locale", default_locale),
|
||||||
|
STRING_OPTION("proxy", "proxy", proxy),
|
||||||
|
STRING_OPTION("proxy", "list_file", proxy_list_file),
|
||||||
|
INTEGER_OPTION("proxy", "max_retries", max_proxy_retries),
|
||||||
|
BOOLEAN_OPTION("proxy", "randomize_username", randomize_username),
|
||||||
|
BOOLEAN_OPTION("proxy", "randomize_password", randomize_password),
|
||||||
|
STRING_OPTION("cache", "dir", cache_dir),
|
||||||
|
INTEGER_OPTION("cache", "ttl_search", cache_ttl_search),
|
||||||
|
INTEGER_OPTION("cache", "ttl_infobox", cache_ttl_infobox),
|
||||||
|
INTEGER_OPTION("cache", "ttl_image", cache_ttl_image),
|
||||||
|
STRING_OPTION("engines", "engines", engines),
|
||||||
|
STRING_OPTION("engines", "yacy_instance", yacy_instance),
|
||||||
|
INTEGER_OPTION("rate_limit", "search_requests", rate_limit_search_requests),
|
||||||
|
INTEGER_OPTION("rate_limit", "search_interval", rate_limit_search_interval),
|
||||||
|
INTEGER_OPTION("rate_limit", "images_requests", rate_limit_images_requests),
|
||||||
|
INTEGER_OPTION("rate_limit", "images_interval", rate_limit_images_interval),
|
||||||
|
};
|
||||||
|
|
||||||
|
void config_set_defaults(Config *config) {
|
||||||
|
if (!config) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*config = (Config){
|
||||||
|
.host = DEFAULT_HOST,
|
||||||
|
.port = DEFAULT_PORT,
|
||||||
|
.default_locale = "en_gb",
|
||||||
|
.max_proxy_retries = DEFAULT_MAX_PROXY_RETRIES,
|
||||||
|
.cache_dir = DEFAULT_CACHE_DIR,
|
||||||
|
.cache_ttl_search = DEFAULT_CACHE_TTL_SEARCH,
|
||||||
|
.cache_ttl_infobox = DEFAULT_CACHE_TTL_INFOBOX,
|
||||||
|
.cache_ttl_image = DEFAULT_CACHE_TTL_IMAGE,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *trim(char *value) {
|
||||||
|
while (*value == ' ' || *value == '\t') {
|
||||||
|
value++;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *end = value + strlen(value);
|
||||||
|
while (end > value && (end[-1] == ' ' || end[-1] == '\t')) {
|
||||||
|
end--;
|
||||||
|
}
|
||||||
|
*end = '\0';
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *unquote(char *value) {
|
||||||
|
size_t length = strlen(value);
|
||||||
|
if (length >= 2 && (value[0] == '"' || value[0] == '\'') &&
|
||||||
|
value[length - 1] == value[0]) {
|
||||||
|
value[length - 1] = '\0';
|
||||||
|
return value + 1;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int parse_integer(const char *value, int *result) {
|
||||||
|
char *end;
|
||||||
|
errno = 0;
|
||||||
|
long parsed = strtol(value, &end, 10);
|
||||||
|
|
||||||
|
if (value == end || *end != '\0' || errno == ERANGE || parsed < INT_MIN ||
|
||||||
|
parsed > INT_MAX) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*result = (int)parsed;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int parse_boolean(const char *value, int *result) {
|
||||||
|
if (strcmp(value, "1") == 0 || strcasecmp(value, "true") == 0 ||
|
||||||
|
strcasecmp(value, "yes") == 0 || strcasecmp(value, "on") == 0) {
|
||||||
|
*result = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (strcmp(value, "0") == 0 || strcasecmp(value, "false") == 0 ||
|
||||||
|
strcasecmp(value, "no") == 0 || strcasecmp(value, "off") == 0) {
|
||||||
|
*result = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_option(Config *config, const char *section, const char *key,
|
||||||
|
const char *value) {
|
||||||
|
size_t option_count = sizeof(CONFIG_OPTIONS) / sizeof(CONFIG_OPTIONS[0]);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < option_count; i++) {
|
||||||
|
const ConfigOption *option = &CONFIG_OPTIONS[i];
|
||||||
|
if (strcmp(section, option->section) != 0 ||
|
||||||
|
strcmp(key, option->key) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *destination = (char *)config + option->offset;
|
||||||
|
if (option->type == CONFIG_STRING) {
|
||||||
|
snprintf(destination, option->size, "%s", value);
|
||||||
|
} else if (option->type == CONFIG_INTEGER) {
|
||||||
|
parse_integer(value, destination);
|
||||||
|
} else {
|
||||||
|
parse_boolean(value, destination);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int load_config(const char *filename, Config *config) {
|
int load_config(const char *filename, Config *config) {
|
||||||
|
if (!filename || !config) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
FILE *file = fopen(filename, "r");
|
FILE *file = fopen(filename, "r");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char line[512];
|
char line[1024];
|
||||||
char section[64] = "";
|
char section[64] = "";
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), file)) {
|
while (fgets(line, sizeof(line), file)) {
|
||||||
line[strcspn(line, "\r\n")] = 0;
|
line[strcspn(line, "\r\n")] = '\0';
|
||||||
|
char *content = trim(line);
|
||||||
|
|
||||||
if (line[0] == '\0' || line[0] == '#' || line[0] == ';') {
|
if (*content == '\0' || *content == '#' || *content == ';') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line[0] == '[') {
|
if (*content == '[') {
|
||||||
char *end = strchr(line, ']');
|
char *end = strchr(content + 1, ']');
|
||||||
if (end) {
|
if (end) {
|
||||||
*end = '\0';
|
*end = '\0';
|
||||||
snprintf(section, sizeof(section), "%.*s", (int)(sizeof(section) - 1),
|
snprintf(section, sizeof(section), "%s", trim(content + 1));
|
||||||
line + 1);
|
|
||||||
section[sizeof(section) - 1] = '\0';
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *delimiter = strchr(line, '=');
|
char *delimiter = strchr(content, '=');
|
||||||
if (delimiter) {
|
if (!delimiter) {
|
||||||
*delimiter = '\0';
|
continue;
|
||||||
char *key = line;
|
|
||||||
char *value = delimiter + 1;
|
|
||||||
|
|
||||||
while (*key == ' ' || *key == '\t')
|
|
||||||
key++;
|
|
||||||
while (*value == ' ' || *value == '\t')
|
|
||||||
value++;
|
|
||||||
|
|
||||||
char *key_end = key + strlen(key) - 1;
|
|
||||||
while (key_end > key && (*key_end == ' ' || *key_end == '\t')) {
|
|
||||||
*key_end = '\0';
|
|
||||||
key_end--;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *value_end = value + strlen(value) - 1;
|
|
||||||
while (value_end > value && (*value_end == ' ' || *value_end == '\t' ||
|
|
||||||
*value_end == '"' || *value_end == '\'')) {
|
|
||||||
*value_end = '\0';
|
|
||||||
value_end--;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (*value == ' ' || *value == '\t')
|
|
||||||
value++;
|
|
||||||
while (*value == '"' || *value == '\'')
|
|
||||||
value++;
|
|
||||||
|
|
||||||
if (strcmp(section, "server") == 0) {
|
|
||||||
if (strcmp(key, "host") == 0) {
|
|
||||||
strncpy(config->host, value, sizeof(config->host) - 1);
|
|
||||||
config->host[sizeof(config->host) - 1] = '\0';
|
|
||||||
} else if (strcmp(key, "port") == 0) {
|
|
||||||
config->port = atoi(value);
|
|
||||||
} else if (strcmp(key, "locale") == 0) {
|
|
||||||
strncpy(config->default_locale, value,
|
|
||||||
sizeof(config->default_locale) - 1);
|
|
||||||
config->default_locale[sizeof(config->default_locale) - 1] = '\0';
|
|
||||||
}
|
|
||||||
} else if (strcmp(section, "proxy") == 0) {
|
|
||||||
if (strcmp(key, "proxy") == 0) {
|
|
||||||
strncpy(config->proxy, value, sizeof(config->proxy) - 1);
|
|
||||||
config->proxy[sizeof(config->proxy) - 1] = '\0';
|
|
||||||
} else if (strcmp(key, "list_file") == 0) {
|
|
||||||
strncpy(config->proxy_list_file, value,
|
|
||||||
sizeof(config->proxy_list_file) - 1);
|
|
||||||
config->proxy_list_file[sizeof(config->proxy_list_file) - 1] = '\0';
|
|
||||||
} else if (strcmp(key, "max_retries") == 0) {
|
|
||||||
config->max_proxy_retries = atoi(value);
|
|
||||||
} else if (strcmp(key, "randomize_username") == 0) {
|
|
||||||
config->randomize_username = atoi(value);
|
|
||||||
} else if (strcmp(key, "randomize_password") == 0) {
|
|
||||||
config->randomize_password = atoi(value);
|
|
||||||
}
|
|
||||||
} else if (strcmp(section, "cache") == 0) {
|
|
||||||
if (strcmp(key, "dir") == 0) {
|
|
||||||
strncpy(config->cache_dir, value, sizeof(config->cache_dir) - 1);
|
|
||||||
config->cache_dir[sizeof(config->cache_dir) - 1] = '\0';
|
|
||||||
} else if (strcmp(key, "ttl_search") == 0) {
|
|
||||||
config->cache_ttl_search = atoi(value);
|
|
||||||
} else if (strcmp(key, "ttl_infobox") == 0) {
|
|
||||||
config->cache_ttl_infobox = atoi(value);
|
|
||||||
} else if (strcmp(key, "ttl_image") == 0) {
|
|
||||||
config->cache_ttl_image = atoi(value);
|
|
||||||
}
|
|
||||||
} else if (strcmp(section, "engines") == 0) {
|
|
||||||
if (strcmp(key, "engines") == 0) {
|
|
||||||
strncpy(config->engines, value, sizeof(config->engines) - 1);
|
|
||||||
config->engines[sizeof(config->engines) - 1] = '\0';
|
|
||||||
}
|
|
||||||
} else if (strcmp(section, "rate_limit") == 0) {
|
|
||||||
if (strcmp(key, "search_requests") == 0) {
|
|
||||||
config->rate_limit_search_requests = atoi(value);
|
|
||||||
} else if (strcmp(key, "search_interval") == 0) {
|
|
||||||
config->rate_limit_search_interval = atoi(value);
|
|
||||||
} else if (strcmp(key, "images_requests") == 0) {
|
|
||||||
config->rate_limit_images_requests = atoi(value);
|
|
||||||
} else if (strcmp(key, "images_interval") == 0) {
|
|
||||||
config->rate_limit_images_interval = atoi(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*delimiter = '\0';
|
||||||
|
char *key = trim(content);
|
||||||
|
char *value = unquote(trim(delimiter + 1));
|
||||||
|
set_option(config, section, key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int result = ferror(file) ? -1 : 0;
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return 0;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#define DEFAULT_CACHE_TTL_INFOBOX 86400
|
#define DEFAULT_CACHE_TTL_INFOBOX 86400
|
||||||
#define DEFAULT_CACHE_TTL_IMAGE 604800
|
#define DEFAULT_CACHE_TTL_IMAGE 604800
|
||||||
#define DEFAULT_MAX_PROXY_RETRIES 3
|
#define DEFAULT_MAX_PROXY_RETRIES 3
|
||||||
|
#define DEFAULT_YACY_INSTANCE "http://127.0.0.1:8090"
|
||||||
|
|
||||||
#define BUFFER_SIZE_SMALL 256
|
#define BUFFER_SIZE_SMALL 256
|
||||||
#define BUFFER_SIZE_MEDIUM 512
|
#define BUFFER_SIZE_MEDIUM 512
|
||||||
@@ -46,12 +47,14 @@ typedef struct {
|
|||||||
int cache_ttl_infobox;
|
int cache_ttl_infobox;
|
||||||
int cache_ttl_image;
|
int cache_ttl_image;
|
||||||
char engines[512];
|
char engines[512];
|
||||||
|
char yacy_instance[512];
|
||||||
int rate_limit_search_requests;
|
int rate_limit_search_requests;
|
||||||
int rate_limit_search_interval;
|
int rate_limit_search_interval;
|
||||||
int rate_limit_images_requests;
|
int rate_limit_images_requests;
|
||||||
int rate_limit_images_interval;
|
int rate_limit_images_interval;
|
||||||
} Config;
|
} Config;
|
||||||
|
|
||||||
|
void config_set_defaults(Config *config);
|
||||||
int load_config(const char *filename, Config *config);
|
int load_config(const char *filename, Config *config);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -38,14 +38,31 @@ static double parse_factor(Parser *p) {
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static double parse_term(Parser *p) {
|
static double parse_exponent(Parser *p) {
|
||||||
double left = parse_factor(p);
|
double left = parse_factor(p);
|
||||||
|
skip_ws(p);
|
||||||
|
if (p->buffer[p->pos] == '^') {
|
||||||
|
p->pos++;
|
||||||
|
double right = parse_exponent(p);
|
||||||
|
double old = left;
|
||||||
|
left = pow(old, right);
|
||||||
|
|
||||||
|
char step[256];
|
||||||
|
snprintf(step, sizeof(step), "<div>%g ^ %g = <b>%g</b></div>", old, right,
|
||||||
|
left);
|
||||||
|
strncat(logic_log, step, sizeof(logic_log) - strlen(logic_log) - 1);
|
||||||
|
}
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double parse_term(Parser *p) {
|
||||||
|
double left = parse_exponent(p);
|
||||||
while (1) {
|
while (1) {
|
||||||
skip_ws(p);
|
skip_ws(p);
|
||||||
char op = p->buffer[p->pos];
|
char op = p->buffer[p->pos];
|
||||||
if (op == '*' || op == '/') {
|
if (op == '*' || op == '/') {
|
||||||
p->pos++;
|
p->pos++;
|
||||||
double right = parse_factor(p);
|
double right = parse_exponent(p);
|
||||||
double old = left;
|
double old = left;
|
||||||
left = (op == '*') ? left * right : left / right;
|
left = (op == '*') ? left * right : left / right;
|
||||||
|
|
||||||
|
|||||||
@@ -207,8 +207,7 @@ char *construct_dictionary_url(const char *query) {
|
|||||||
const char *base = "https://dictionary.cambridge.org/dictionary/english/";
|
const char *base = "https://dictionary.cambridge.org/dictionary/english/";
|
||||||
char *url = malloc(strlen(base) + strlen(escaped) + 1);
|
char *url = malloc(strlen(base) + strlen(escaped) + 1);
|
||||||
if (url) {
|
if (url) {
|
||||||
strcpy(url, base);
|
snprintf(url, strlen(base) + strlen(escaped) + 1, "%s%s", base, escaped);
|
||||||
strcat(url, escaped);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_free(escaped);
|
curl_free(escaped);
|
||||||
|
|||||||
@@ -360,7 +360,7 @@ static int parse_conversion_query(const char *query, double *value,
|
|||||||
while (try_len > 0) {
|
while (try_len > 0) {
|
||||||
*to_unit = find_unit(try_buf);
|
*to_unit = find_unit(try_buf);
|
||||||
if (*to_unit) {
|
if (*to_unit) {
|
||||||
strcpy(to_part, try_buf);
|
snprintf(to_part, sizeof(to_part), "%s", try_buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
char *last_space = strrchr(try_buf, ' ');
|
char *last_space = strrchr(try_buf, ' ');
|
||||||
@@ -443,34 +443,34 @@ static const char *pluralize(const char *unit, double value, char *buf,
|
|||||||
if (len == 0 || bufsize == 0)
|
if (len == 0 || bufsize == 0)
|
||||||
return unit;
|
return unit;
|
||||||
|
|
||||||
strncpy(buf, unit, bufsize - 1);
|
snprintf(buf, bufsize, "%s", unit);
|
||||||
buf[bufsize - 1] = '\0';
|
|
||||||
|
|
||||||
if (strcmp(unit, "foot") == 0 || strcmp(unit, "square foot") == 0) {
|
if (strcmp(unit, "foot") == 0 || strcmp(unit, "square foot") == 0) {
|
||||||
if (is_one)
|
if (is_one)
|
||||||
strcpy(buf, unit);
|
snprintf(buf, bufsize, "%s", unit);
|
||||||
else
|
else
|
||||||
strcpy(buf, strcmp(unit, "square foot") == 0 ? "square feet" : "feet");
|
snprintf(buf, bufsize, "%s",
|
||||||
|
strcmp(unit, "square foot") == 0 ? "square feet" : "feet");
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
if (strcmp(unit, "inch") == 0 || strcmp(unit, "square inch") == 0) {
|
if (strcmp(unit, "inch") == 0 || strcmp(unit, "square inch") == 0) {
|
||||||
if (is_one)
|
if (is_one)
|
||||||
strcpy(buf, unit);
|
snprintf(buf, bufsize, "%s", unit);
|
||||||
else
|
else
|
||||||
strcpy(buf,
|
snprintf(buf, bufsize, "%s",
|
||||||
strcmp(unit, "square inch") == 0 ? "square inches" : "inches");
|
strcmp(unit, "square inch") == 0 ? "square inches" : "inches");
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
if (strcmp(unit, "stone") == 0) {
|
if (strcmp(unit, "stone") == 0) {
|
||||||
if (is_one)
|
if (is_one)
|
||||||
strcpy(buf, "stone");
|
snprintf(buf, bufsize, "%s", "stone");
|
||||||
else
|
else
|
||||||
strcpy(buf, "stones");
|
snprintf(buf, bufsize, "%s", "stones");
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
if (strcmp(unit, "celsius") == 0 || strcmp(unit, "fahrenheit") == 0 ||
|
if (strcmp(unit, "celsius") == 0 || strcmp(unit, "fahrenheit") == 0 ||
|
||||||
strcmp(unit, "kelvin") == 0) {
|
strcmp(unit, "kelvin") == 0) {
|
||||||
strcpy(buf, unit);
|
snprintf(buf, bufsize, "%s", unit);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ static void shorten_summary(char **extract_ptr, int max_chars) {
|
|||||||
if (new_text) {
|
if (new_text) {
|
||||||
strncpy(new_text, text, end_pos);
|
strncpy(new_text, text, end_pos);
|
||||||
new_text[end_pos] = '\0';
|
new_text[end_pos] = '\0';
|
||||||
strcat(new_text, "...");
|
strncat(new_text, "...", 3);
|
||||||
free(*extract_ptr);
|
free(*extract_ptr);
|
||||||
*extract_ptr = new_text;
|
*extract_ptr = new_text;
|
||||||
}
|
}
|
||||||
@@ -65,8 +65,8 @@ static void extract_wiki_info(xmlNode *node, InfoBox *info) {
|
|||||||
info->url =
|
info->url =
|
||||||
malloc(strlen(base_article_url) + strlen(formatted_title) + 1);
|
malloc(strlen(base_article_url) + strlen(formatted_title) + 1);
|
||||||
if (info->url) {
|
if (info->url) {
|
||||||
strcpy(info->url, base_article_url);
|
snprintf(info->url, strlen(base_article_url) + strlen(formatted_title) + 1,
|
||||||
strcat(info->url, formatted_title);
|
"%s%s", base_article_url, formatted_title);
|
||||||
}
|
}
|
||||||
free(formatted_title);
|
free(formatted_title);
|
||||||
xmlFree(title);
|
xmlFree(title);
|
||||||
@@ -177,9 +177,9 @@ static char *get_first_search_result(const char *search_term) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(search_url, search_base);
|
snprintf(search_url, strlen(search_base) + strlen(escaped_term) +
|
||||||
strcat(search_url, escaped_term);
|
strlen(search_suffix) + 1, "%s%s%s", search_base,
|
||||||
strcat(search_url, search_suffix);
|
escaped_term, search_suffix);
|
||||||
|
|
||||||
curl_free(escaped_term);
|
curl_free(escaped_term);
|
||||||
|
|
||||||
@@ -226,8 +226,8 @@ char *construct_wiki_url(const char *search_term) {
|
|||||||
|
|
||||||
char *full_url = malloc(strlen(base) + strlen(escaped_title) + 1);
|
char *full_url = malloc(strlen(base) + strlen(escaped_title) + 1);
|
||||||
if (full_url) {
|
if (full_url) {
|
||||||
strcpy(full_url, base);
|
snprintf(full_url, strlen(base) + strlen(escaped_title) + 1, "%s%s", base,
|
||||||
strcat(full_url, escaped_title);
|
escaped_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_free(escaped_title);
|
curl_free(escaped_title);
|
||||||
|
|||||||
38
src/Main.c
38
src/Main.c
@@ -12,6 +12,7 @@
|
|||||||
#include "Routes/Home.h"
|
#include "Routes/Home.h"
|
||||||
#include "Routes/ImageProxy.h"
|
#include "Routes/ImageProxy.h"
|
||||||
#include "Routes/Images.h"
|
#include "Routes/Images.h"
|
||||||
|
#include "Routes/Info.h"
|
||||||
#include "Routes/Search.h"
|
#include "Routes/Search.h"
|
||||||
#include "Routes/Settings.h"
|
#include "Routes/Settings.h"
|
||||||
#include "Routes/SettingsSave.h"
|
#include "Routes/SettingsSave.h"
|
||||||
@@ -65,23 +66,8 @@ int main() {
|
|||||||
|
|
||||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||||
|
|
||||||
Config cfg = {.host = DEFAULT_HOST,
|
Config cfg;
|
||||||
.port = DEFAULT_PORT,
|
config_set_defaults(&cfg);
|
||||||
.default_locale = "en_gb",
|
|
||||||
.proxy = "",
|
|
||||||
.proxy_list_file = "",
|
|
||||||
.max_proxy_retries = DEFAULT_MAX_PROXY_RETRIES,
|
|
||||||
.randomize_username = 0,
|
|
||||||
.randomize_password = 0,
|
|
||||||
.cache_dir = DEFAULT_CACHE_DIR,
|
|
||||||
.cache_ttl_search = DEFAULT_CACHE_TTL_SEARCH,
|
|
||||||
.cache_ttl_infobox = DEFAULT_CACHE_TTL_INFOBOX,
|
|
||||||
.cache_ttl_image = DEFAULT_CACHE_TTL_IMAGE,
|
|
||||||
.engines = "",
|
|
||||||
.rate_limit_search_requests = 0,
|
|
||||||
.rate_limit_search_interval = 0,
|
|
||||||
.rate_limit_images_requests = 0,
|
|
||||||
.rate_limit_images_interval = 0};
|
|
||||||
|
|
||||||
if (load_config("config.ini", &cfg) != 0) {
|
if (load_config("config.ini", &cfg) != 0) {
|
||||||
fprintf(stderr, "[WARN] Could not load config file, using defaults\n");
|
fprintf(stderr, "[WARN] Could not load config file, using defaults\n");
|
||||||
@@ -101,6 +87,23 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
apply_engines_config(cfg.engines);
|
apply_engines_config(cfg.engines);
|
||||||
|
configure_yacy_engine(cfg.yacy_instance);
|
||||||
|
|
||||||
|
if (cfg.yacy_instance[0] != '\0') {
|
||||||
|
int yacy_enabled = 0;
|
||||||
|
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||||
|
if (strcmp(ENGINE_REGISTRY[i].id, "yacy") == 0) {
|
||||||
|
yacy_enabled = ENGINE_REGISTRY[i].enabled;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!yacy_enabled) {
|
||||||
|
fprintf(
|
||||||
|
stderr,
|
||||||
|
"[INFO] YaCy instance configured but the yacy engine is not "
|
||||||
|
"enabled (add it to the engines list, e.g. engines=\"*,yacy\")\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (cache_init(cfg.cache_dir) != 0) {
|
if (cache_init(cfg.cache_dir) != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@@ -136,6 +139,7 @@ int main() {
|
|||||||
set_handler("/search", results_handler);
|
set_handler("/search", results_handler);
|
||||||
set_handler("/images", images_handler);
|
set_handler("/images", images_handler);
|
||||||
set_handler("/proxy", image_proxy_handler);
|
set_handler("/proxy", image_proxy_handler);
|
||||||
|
set_handler("/info", info_handler);
|
||||||
set_handler("/settings", settings_handler);
|
set_handler("/settings", settings_handler);
|
||||||
set_handler("/save_settings", settings_save_handler);
|
set_handler("/save_settings", settings_save_handler);
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ static void generate_random_string(char *buf, size_t len) {
|
|||||||
|
|
||||||
void set_proxy_config(const char *proxy_str, int rand_user, int rand_pass) {
|
void set_proxy_config(const char *proxy_str, int rand_user, int rand_pass) {
|
||||||
if (proxy_str && proxy_str[0]) {
|
if (proxy_str && proxy_str[0]) {
|
||||||
strncpy(proxy_url, proxy_str, sizeof(proxy_url) - 1);
|
snprintf(proxy_url, sizeof(proxy_url), "%s", proxy_str);
|
||||||
proxy_url[sizeof(proxy_url) - 1] = '\0';
|
|
||||||
}
|
}
|
||||||
randomize_username = rand_user;
|
randomize_username = rand_user;
|
||||||
randomize_password = rand_pass;
|
randomize_password = rand_pass;
|
||||||
@@ -144,7 +143,8 @@ int load_proxy_list(const char *filename) {
|
|||||||
|
|
||||||
if (temp_count >= temp_capacity) {
|
if (temp_count >= temp_capacity) {
|
||||||
temp_capacity *= 2;
|
temp_capacity *= 2;
|
||||||
Proxy *new_list = (Proxy *)realloc(temp_list, temp_capacity * sizeof(Proxy));
|
Proxy *new_list =
|
||||||
|
(Proxy *)realloc(temp_list, temp_capacity * sizeof(Proxy));
|
||||||
if (!new_list) {
|
if (!new_list) {
|
||||||
free(temp_list);
|
free(temp_list);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
typedef struct DnsCacheEntry {
|
typedef struct DnsCacheEntry {
|
||||||
char hostname[256];
|
char hostname[256];
|
||||||
char ip_str[INET_ADDRSTRLEN];
|
char ip_str[INET6_ADDRSTRLEN];
|
||||||
time_t resolved_at;
|
time_t resolved_at;
|
||||||
struct DnsCacheEntry *next;
|
struct DnsCacheEntry *next;
|
||||||
} DnsCacheEntry;
|
} DnsCacheEntry;
|
||||||
@@ -39,7 +39,7 @@ static int dns_cache_lookup(const char *hostname, char *out_ip) {
|
|||||||
for (DnsCacheEntry *e = dns_cache; e; e = e->next) {
|
for (DnsCacheEntry *e = dns_cache; e; e = e->next) {
|
||||||
if (strcmp(e->hostname, hostname) == 0) {
|
if (strcmp(e->hostname, hostname) == 0) {
|
||||||
if ((now - e->resolved_at) < DNS_CACHE_TTL) {
|
if ((now - e->resolved_at) < DNS_CACHE_TTL) {
|
||||||
strcpy(out_ip, e->ip_str);
|
snprintf(out_ip, INET6_ADDRSTRLEN, "%s", e->ip_str);
|
||||||
pthread_mutex_unlock(&dns_cache_mutex);
|
pthread_mutex_unlock(&dns_cache_mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ static void dns_cache_insert(const char *hostname, const char *ip_str) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(entry->hostname, hostname) == 0) {
|
if (strcmp(entry->hostname, hostname) == 0) {
|
||||||
strcpy(entry->ip_str, ip_str);
|
snprintf(entry->ip_str, sizeof(entry->ip_str), "%s", ip_str);
|
||||||
entry->resolved_at = now;
|
entry->resolved_at = now;
|
||||||
pthread_mutex_unlock(&dns_cache_mutex);
|
pthread_mutex_unlock(&dns_cache_mutex);
|
||||||
return;
|
return;
|
||||||
@@ -73,9 +73,8 @@ static void dns_cache_insert(const char *hostname, const char *ip_str) {
|
|||||||
|
|
||||||
DnsCacheEntry *new_entry = malloc(sizeof(DnsCacheEntry));
|
DnsCacheEntry *new_entry = malloc(sizeof(DnsCacheEntry));
|
||||||
if (new_entry) {
|
if (new_entry) {
|
||||||
strncpy(new_entry->hostname, hostname, sizeof(new_entry->hostname) - 1);
|
snprintf(new_entry->hostname, sizeof(new_entry->hostname), "%s", hostname);
|
||||||
new_entry->hostname[sizeof(new_entry->hostname) - 1] = '\0';
|
snprintf(new_entry->ip_str, sizeof(new_entry->ip_str), "%s", ip_str);
|
||||||
strcpy(new_entry->ip_str, ip_str);
|
|
||||||
new_entry->resolved_at = now;
|
new_entry->resolved_at = now;
|
||||||
new_entry->next = dns_cache;
|
new_entry->next = dns_cache;
|
||||||
dns_cache = new_entry;
|
dns_cache = new_entry;
|
||||||
@@ -150,7 +149,7 @@ static const char *is_private_hostname(const char *hostname, char *out_ip) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
strcpy(out_ip, ip_str);
|
snprintf(out_ip, INET6_ADDRSTRLEN, "%s", ip_str);
|
||||||
dns_cache_insert(hostname, ip_str);
|
dns_cache_insert(hostname, ip_str);
|
||||||
return out_ip;
|
return out_ip;
|
||||||
}
|
}
|
||||||
@@ -172,7 +171,8 @@ static int is_allowed_domain(const char *url, char *resolved_ip) {
|
|||||||
curl_url_get(h, CURLUPART_SCHEME, &scheme, 0);
|
curl_url_get(h, CURLUPART_SCHEME, &scheme, 0);
|
||||||
|
|
||||||
int valid_scheme = 0;
|
int valid_scheme = 0;
|
||||||
if (scheme && (strcasecmp(scheme, "http") == 0 || strcasecmp(scheme, "https") == 0)) {
|
if (scheme &&
|
||||||
|
(strcasecmp(scheme, "http") == 0 || strcasecmp(scheme, "https") == 0)) {
|
||||||
valid_scheme = 1;
|
valid_scheme = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +258,7 @@ static char *url_encode_key(const char *url) {
|
|||||||
EVP_MD_CTX_free(ctx);
|
EVP_MD_CTX_free(ctx);
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
sprintf(hash + (i * 2), "%02x", md5hash[i]);
|
snprintf(hash + (i * 2), 3, "%02x", md5hash[i]);
|
||||||
}
|
}
|
||||||
hash[32] = '\0';
|
hash[32] = '\0';
|
||||||
|
|
||||||
@@ -279,7 +279,7 @@ int image_proxy_handler(UrlParams *params) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char resolved_ip[INET_ADDRSTRLEN] = {0};
|
char resolved_ip[INET6_ADDRSTRLEN] = {0};
|
||||||
int domain_check = is_allowed_domain(url, resolved_ip);
|
int domain_check = is_allowed_domain(url, resolved_ip);
|
||||||
if (domain_check == -1) {
|
if (domain_check == -1) {
|
||||||
send_response("Invalid URL scheme");
|
send_response("Invalid URL scheme");
|
||||||
@@ -420,8 +420,7 @@ int image_proxy_handler(UrlParams *params) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(content_type) == 0 ||
|
if (strlen(content_type) == 0 || strncmp(content_type, "image/", 6) != 0) {
|
||||||
strncmp(content_type, "image/", 6) != 0) {
|
|
||||||
free(buf.data);
|
free(buf.data);
|
||||||
free(cache_key);
|
free(cache_key);
|
||||||
send_response("Invalid content type");
|
send_response("Invalid content type");
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ static char *build_images_href(const char *query, int page) {
|
|||||||
if (!href)
|
if (!href)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
snprintf(href, needed, "/images?q=%s", safe_query);
|
|
||||||
if (page > 1) {
|
if (page > 1) {
|
||||||
char page_buf[16];
|
char page_buf[16];
|
||||||
snprintf(page_buf, sizeof(page_buf), "%d", page);
|
snprintf(page_buf, sizeof(page_buf), "%d", page);
|
||||||
strcat(href, "&p=");
|
snprintf(href, needed, "/images?q=%s&p=%s", safe_query, page_buf);
|
||||||
strcat(href, page_buf);
|
} else {
|
||||||
|
snprintf(href, needed, "/images?q=%s", safe_query);
|
||||||
}
|
}
|
||||||
return href;
|
return href;
|
||||||
}
|
}
|
||||||
@@ -76,14 +76,12 @@ int images_handler(UrlParams *params) {
|
|||||||
if (!error_images_msg)
|
if (!error_images_msg)
|
||||||
error_images_msg = "Error fetching images";
|
error_images_msg = "Error fetching images";
|
||||||
|
|
||||||
char ***pager_matrix = NULL;
|
StringMatrix pagination;
|
||||||
int *pager_inner_counts = NULL;
|
string_matrix_build_pagination(page, images_href_builder, (void *)raw_query,
|
||||||
int pager_count =
|
&pagination);
|
||||||
build_pagination(page, images_href_builder, (void *)raw_query,
|
if (pagination.count > 0) {
|
||||||
&pager_matrix, &pager_inner_counts);
|
context_set_array_of_arrays(&ctx, "pagination_links", pagination.rows,
|
||||||
if (pager_count > 0) {
|
pagination.count, pagination.field_counts);
|
||||||
context_set_array_of_arrays(&ctx, "pagination_links", pager_matrix,
|
|
||||||
pager_count, pager_inner_counts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *display_query = url_decode_query(raw_query);
|
char *display_query = url_decode_query(raw_query);
|
||||||
@@ -91,8 +89,9 @@ int images_handler(UrlParams *params) {
|
|||||||
|
|
||||||
if (!raw_query || strlen(raw_query) == 0) {
|
if (!raw_query || strlen(raw_query) == 0) {
|
||||||
send_redirect("/");
|
send_redirect("/");
|
||||||
if (display_query)
|
string_matrix_free(&pagination);
|
||||||
free(display_query);
|
free(display_query);
|
||||||
|
free(locale);
|
||||||
free_context(&ctx);
|
free_context(&ctx);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -128,7 +127,9 @@ int images_handler(UrlParams *params) {
|
|||||||
snprintf(response, sizeof(response), "<h1>%s</h1>", rate_limit_msg);
|
snprintf(response, sizeof(response), "<h1>%s</h1>", rate_limit_msg);
|
||||||
send_response(response);
|
send_response(response);
|
||||||
free(request_cache_key);
|
free(request_cache_key);
|
||||||
|
string_matrix_free(&pagination);
|
||||||
free(display_query);
|
free(display_query);
|
||||||
|
free(locale);
|
||||||
free_context(&ctx);
|
free_context(&ctx);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -147,37 +148,37 @@ int images_handler(UrlParams *params) {
|
|||||||
snprintf(error_html, sizeof(error_html), "<h1>%s</h1>", error_images_msg);
|
snprintf(error_html, sizeof(error_html), "<h1>%s</h1>", error_images_msg);
|
||||||
send_response(error_html);
|
send_response(error_html);
|
||||||
free(request_cache_key);
|
free(request_cache_key);
|
||||||
|
string_matrix_free(&pagination);
|
||||||
free(display_query);
|
free(display_query);
|
||||||
|
free(locale);
|
||||||
free_context(&ctx);
|
free_context(&ctx);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char ***image_matrix = malloc(sizeof(char **) * result_count);
|
StringMatrix images;
|
||||||
int *inner_counts = malloc(sizeof(int) * result_count);
|
string_matrix_init(&images);
|
||||||
|
|
||||||
if (!image_matrix || !inner_counts) {
|
|
||||||
if (image_matrix)
|
|
||||||
free(image_matrix);
|
|
||||||
if (inner_counts)
|
|
||||||
free(inner_counts);
|
|
||||||
free_image_results(results, result_count);
|
|
||||||
free(request_cache_key);
|
|
||||||
free(display_query);
|
|
||||||
free_context(&ctx);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < result_count; i++) {
|
for (int i = 0; i < result_count; i++) {
|
||||||
image_matrix[i] = malloc(sizeof(char *) * IMAGE_RESULT_FIELDS);
|
const char *values[IMAGE_RESULT_FIELDS] = {
|
||||||
image_matrix[i][0] = strdup(results[i].thumbnail_url);
|
results[i].thumbnail_url,
|
||||||
image_matrix[i][1] = strdup(results[i].title);
|
results[i].title,
|
||||||
image_matrix[i][2] = strdup(results[i].page_url);
|
results[i].page_url,
|
||||||
image_matrix[i][3] = strdup(results[i].full_url);
|
results[i].full_url,
|
||||||
inner_counts[i] = IMAGE_RESULT_FIELDS;
|
};
|
||||||
|
if (string_matrix_append(&images, values, IMAGE_RESULT_FIELDS) != 0) {
|
||||||
|
string_matrix_free(&images);
|
||||||
|
string_matrix_free(&pagination);
|
||||||
|
free_image_results(results, result_count);
|
||||||
|
free(request_cache_key);
|
||||||
|
free(display_query);
|
||||||
|
free(locale);
|
||||||
|
free_context(&ctx);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context_set_array_of_arrays(&ctx, "images", image_matrix, result_count,
|
context_set_array_of_arrays(&ctx, "images", images.rows, images.count,
|
||||||
inner_counts);
|
images.field_counts);
|
||||||
|
|
||||||
char *rendered = render_template("images.html", &ctx);
|
char *rendered = render_template("images.html", &ctx);
|
||||||
if (rendered) {
|
if (rendered) {
|
||||||
@@ -187,27 +188,13 @@ int images_handler(UrlParams *params) {
|
|||||||
send_response("<h1>Error rendering image results</h1>");
|
send_response("<h1>Error rendering image results</h1>");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < result_count; i++) {
|
string_matrix_free(&images);
|
||||||
for (int j = 0; j < IMAGE_RESULT_FIELDS; j++)
|
string_matrix_free(&pagination);
|
||||||
free(image_matrix[i][j]);
|
|
||||||
free(image_matrix[i]);
|
|
||||||
}
|
|
||||||
free(image_matrix);
|
|
||||||
free(inner_counts);
|
|
||||||
|
|
||||||
if (pager_count > 0) {
|
|
||||||
for (int i = 0; i < pager_count; i++) {
|
|
||||||
for (int j = 0; j < LINK_FIELD_COUNT; j++)
|
|
||||||
free(pager_matrix[i][j]);
|
|
||||||
free(pager_matrix[i]);
|
|
||||||
}
|
|
||||||
free(pager_matrix);
|
|
||||||
free(pager_inner_counts);
|
|
||||||
}
|
|
||||||
|
|
||||||
free_image_results(results, result_count);
|
free_image_results(results, result_count);
|
||||||
free(request_cache_key);
|
free(request_cache_key);
|
||||||
free(display_query);
|
free(display_query);
|
||||||
|
free(locale);
|
||||||
free_context(&ctx);
|
free_context(&ctx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
69
src/Routes/Info.c
Normal file
69
src/Routes/Info.c
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#include "Info.h"
|
||||||
|
#include "../Config.h"
|
||||||
|
#include "../Scraping/Scraping.h"
|
||||||
|
#include "../Utility/Utility.h"
|
||||||
|
#include <beaker.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static int append_json(char *buf, size_t size, size_t *used, const char *format,
|
||||||
|
...) {
|
||||||
|
if (*used >= size) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
int written = vsnprintf(buf + *used, size - *used, format, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
if (written < 0 || (size_t)written >= size - *used) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*used += (size_t)written;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int info_handler(UrlParams *params) {
|
||||||
|
(void)params;
|
||||||
|
extern Config global_config;
|
||||||
|
|
||||||
|
char json[INITIAL_BUFFER_SIZE];
|
||||||
|
size_t used = 0;
|
||||||
|
|
||||||
|
if (append_json(json, sizeof(json), &used, "{\"version\":\"%s\",", VERSION) !=
|
||||||
|
0 ||
|
||||||
|
append_json(json, sizeof(json), &used, "\"git_remote\":\"%s\",",
|
||||||
|
GIT_REMOTE) != 0 ||
|
||||||
|
append_json(json, sizeof(json), &used, "\"locale\":\"%s\",",
|
||||||
|
global_config.default_locale) != 0 ||
|
||||||
|
append_json(json, sizeof(json), &used, "\"engines\":[") != 0) {
|
||||||
|
send_response("Failed to build instance info");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int first = 1;
|
||||||
|
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||||
|
if (!ENGINE_REGISTRY[i].enabled) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (append_json(json, sizeof(json), &used,
|
||||||
|
"%s{\"id\":\"%s\",\"name\":\"%s\"}", first ? "" : ",",
|
||||||
|
ENGINE_REGISTRY[i].id, ENGINE_REGISTRY[i].name) != 0) {
|
||||||
|
send_response("Failed to build instance info");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
first = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (append_json(json, sizeof(json), &used, "]}") != 0) {
|
||||||
|
send_response("Failed to build instance info");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
serve_data(json, used, "application/json");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
8
src/Routes/Info.h
Normal file
8
src/Routes/Info.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef INFO_H
|
||||||
|
#define INFO_H
|
||||||
|
|
||||||
|
#include <beaker.h>
|
||||||
|
|
||||||
|
int info_handler(UrlParams *params);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -140,29 +140,31 @@ static InfoBox fetch_currency_wrapper(char *query) {
|
|||||||
return fetch_currency_data(query);
|
return fetch_currency_data(query);
|
||||||
}
|
}
|
||||||
char *get_base_url(const char *input) {
|
char *get_base_url(const char *input) {
|
||||||
if (!input) return NULL;
|
if (!input)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
const char *start = input;
|
const char *start = input;
|
||||||
|
|
||||||
const char *protocol_pos = strstr(input, "://");
|
const char *protocol_pos = strstr(input, "://");
|
||||||
if (protocol_pos) {
|
if (protocol_pos) {
|
||||||
start = protocol_pos + 3;
|
start = protocol_pos + 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *end = start;
|
const char *end = start;
|
||||||
while (*end && *end != '/' && *end != '?' && *end != '#') {
|
while (*end && *end != '/' && *end != '?' && *end != '#') {
|
||||||
end++;
|
end++;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t len = end - start;
|
size_t len = end - start;
|
||||||
|
|
||||||
char *domain = (char *)malloc(len + 1);
|
char *domain = (char *)malloc(len + 1);
|
||||||
if (!domain) return NULL;
|
if (!domain)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
strncpy(domain, start, len);
|
strncpy(domain, start, len);
|
||||||
domain[len] = '\0';
|
domain[len] = '\0';
|
||||||
|
|
||||||
return domain;
|
return domain;
|
||||||
}
|
}
|
||||||
static int is_calculator_query(const char *query) {
|
static int is_calculator_query(const char *query) {
|
||||||
if (!query)
|
if (!query)
|
||||||
@@ -249,88 +251,65 @@ static void *infobox_thread_func(void *arg) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_infobox_to_collection(InfoBox *infobox, char ****collection,
|
static int add_infobox_to_collection(InfoBox *infobox,
|
||||||
int **inner_counts, int current_count) {
|
StringMatrix *collection) {
|
||||||
*collection =
|
const char *values[INFOBOX_FIELD_COUNT] = {
|
||||||
(char ***)realloc(*collection, sizeof(char **) * (current_count + 1));
|
infobox->title, infobox->thumbnail_url, infobox->extract,
|
||||||
*inner_counts =
|
infobox->url, infobox->url,
|
||||||
(int *)realloc(*inner_counts, sizeof(int) * (current_count + 1));
|
};
|
||||||
|
return string_matrix_append(collection, values, INFOBOX_FIELD_COUNT);
|
||||||
(*collection)[current_count] =
|
|
||||||
(char **)malloc(sizeof(char *) * INFOBOX_FIELD_COUNT);
|
|
||||||
(*collection)[current_count][0] =
|
|
||||||
infobox->title ? strdup(infobox->title) : NULL;
|
|
||||||
(*collection)[current_count][1] =
|
|
||||||
infobox->thumbnail_url ? strdup(infobox->thumbnail_url) : NULL;
|
|
||||||
(*collection)[current_count][2] =
|
|
||||||
infobox->extract ? strdup(infobox->extract) : NULL;
|
|
||||||
(*collection)[current_count][3] = infobox->url ? strdup(infobox->url) : NULL;
|
|
||||||
(*collection)[current_count][4] = infobox->url ? strdup(infobox->url) : NULL;
|
|
||||||
(*inner_counts)[current_count] = INFOBOX_FIELD_COUNT;
|
|
||||||
|
|
||||||
return current_count + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_warning_to_collection(const char *engine_name,
|
static int add_warning_to_collection(const char *engine_name,
|
||||||
const char *warning_message,
|
const char *warning_message,
|
||||||
char ****collection, int **inner_counts,
|
StringMatrix *collection) {
|
||||||
int current_count) {
|
const char *values[] = {engine_name, warning_message};
|
||||||
char ***new_collection =
|
return string_matrix_append(collection, values, 2);
|
||||||
(char ***)malloc(sizeof(char **) * (current_count + 1));
|
|
||||||
int *new_inner_counts =
|
|
||||||
(int *)malloc(sizeof(int) * (current_count + 1));
|
|
||||||
|
|
||||||
if (!new_collection || !new_inner_counts) {
|
|
||||||
free(new_collection);
|
|
||||||
free(new_inner_counts);
|
|
||||||
return current_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*collection && current_count > 0) {
|
|
||||||
memcpy(new_collection, *collection, sizeof(char **) * current_count);
|
|
||||||
}
|
|
||||||
if (*inner_counts && current_count > 0) {
|
|
||||||
memcpy(new_inner_counts, *inner_counts, sizeof(int) * current_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(*collection);
|
|
||||||
free(*inner_counts);
|
|
||||||
|
|
||||||
*collection = new_collection;
|
|
||||||
*inner_counts = new_inner_counts;
|
|
||||||
|
|
||||||
(*collection)[current_count] = (char **)malloc(sizeof(char *) * 2);
|
|
||||||
if (!(*collection)[current_count])
|
|
||||||
return current_count;
|
|
||||||
|
|
||||||
(*collection)[current_count][0] = strdup(engine_name ? engine_name : "");
|
|
||||||
(*collection)[current_count][1] =
|
|
||||||
strdup(warning_message ? warning_message : "");
|
|
||||||
|
|
||||||
if (!(*collection)[current_count][0] || !(*collection)[current_count][1]) {
|
|
||||||
free((*collection)[current_count][0]);
|
|
||||||
free((*collection)[current_count][1]);
|
|
||||||
free((*collection)[current_count]);
|
|
||||||
return current_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*inner_counts)[current_count] = 2;
|
|
||||||
return current_count + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *warning_message_for_job(const ScrapeJob *job, const char *locale) {
|
static void free_user_engine_list(char **user_engines, int user_engine_count) {
|
||||||
|
for (int i = 0; i < user_engine_count; i++)
|
||||||
|
free(user_engines[i]);
|
||||||
|
free(user_engines);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void free_search_results(SearchResult **all_results, ScrapeJob *jobs,
|
||||||
|
int job_count) {
|
||||||
|
for (int i = 0; i < job_count; i++) {
|
||||||
|
for (int j = 0; all_results[i] && j < jobs[i].results_count; j++) {
|
||||||
|
free(all_results[i][j].url);
|
||||||
|
free(all_results[i][j].title);
|
||||||
|
free(all_results[i][j].snippet);
|
||||||
|
}
|
||||||
|
free(all_results[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void free_infobox_results(InfoBoxThreadData *data) {
|
||||||
|
for (int i = 0; i < HANDLER_COUNT; i++) {
|
||||||
|
free_infobox(&data[i].result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *warning_message_for_job(const ScrapeJob *job,
|
||||||
|
const char *locale) {
|
||||||
switch (job->status) {
|
switch (job->status) {
|
||||||
case SCRAPE_STATUS_FETCH_ERROR: {
|
case SCRAPE_STATUS_FETCH_ERROR: {
|
||||||
const char *msg = beaker_get_locale_value(locale, "warning_fetch_error");
|
const char *msg = beaker_get_locale_value(locale, "warning_fetch_error");
|
||||||
return msg ? msg : "request failed before OmniSearch could read search results.";
|
return msg ? msg
|
||||||
|
: "request failed before OmniSearch could read search results.";
|
||||||
}
|
}
|
||||||
case SCRAPE_STATUS_PARSE_MISMATCH: {
|
case SCRAPE_STATUS_PARSE_MISMATCH: {
|
||||||
const char *msg = beaker_get_locale_value(locale, "warning_parse_mismatch");
|
const char *msg = beaker_get_locale_value(locale, "warning_parse_mismatch");
|
||||||
return msg ? msg : "returned search results in a format OmniSearch could not parse.";
|
return msg ? msg
|
||||||
|
: "returned search results in a format OmniSearch could not "
|
||||||
|
"parse.";
|
||||||
}
|
}
|
||||||
case SCRAPE_STATUS_BLOCKED: {
|
case SCRAPE_STATUS_BLOCKED: {
|
||||||
const char *msg = beaker_get_locale_value(locale, "warning_blocked");
|
const char *msg = beaker_get_locale_value(locale, "warning_blocked");
|
||||||
return msg ? msg : "returned a captcha or another blocking page instead of search results.";
|
return msg ? msg
|
||||||
|
: "returned a captcha or another blocking page instead of "
|
||||||
|
"search results.";
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -384,8 +363,8 @@ static int engine_allowed_for_user(const SearchEngine *eng, char **user_ids,
|
|||||||
static char *build_search_href(const char *query, const char *engine_id,
|
static char *build_search_href(const char *query, const char *engine_id,
|
||||||
int page) {
|
int page) {
|
||||||
const char *safe_query = query ? query : "";
|
const char *safe_query = query ? query : "";
|
||||||
int use_engine = engine_id && engine_id[0] != '\0' &&
|
int use_engine =
|
||||||
!engine_id_matches(engine_id, "all");
|
engine_id && engine_id[0] != '\0' && !engine_id_matches(engine_id, "all");
|
||||||
size_t needed = strlen("/search?q=") + strlen(safe_query) + 1;
|
size_t needed = strlen("/search?q=") + strlen(safe_query) + 1;
|
||||||
|
|
||||||
if (use_engine)
|
if (use_engine)
|
||||||
@@ -397,18 +376,19 @@ static char *build_search_href(const char *query, const char *engine_id,
|
|||||||
if (!href)
|
if (!href)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
snprintf(href, needed, "/search?q=%s", safe_query);
|
if (use_engine && page > 1) {
|
||||||
|
|
||||||
if (use_engine) {
|
|
||||||
strcat(href, "&engine=");
|
|
||||||
strcat(href, engine_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (page > 1) {
|
|
||||||
char page_buf[16];
|
char page_buf[16];
|
||||||
snprintf(page_buf, sizeof(page_buf), "%d", page);
|
snprintf(page_buf, sizeof(page_buf), "%d", page);
|
||||||
strcat(href, "&p=");
|
snprintf(href, needed, "/search?q=%s&engine=%s&p=%s", safe_query, engine_id,
|
||||||
strcat(href, page_buf);
|
page_buf);
|
||||||
|
} else if (use_engine) {
|
||||||
|
snprintf(href, needed, "/search?q=%s&engine=%s", safe_query, engine_id);
|
||||||
|
} else if (page > 1) {
|
||||||
|
char page_buf[16];
|
||||||
|
snprintf(page_buf, sizeof(page_buf), "%d", page);
|
||||||
|
snprintf(href, needed, "/search?q=%s&p=%s", safe_query, page_buf);
|
||||||
|
} else {
|
||||||
|
snprintf(href, needed, "/search?q=%s", safe_query);
|
||||||
}
|
}
|
||||||
|
|
||||||
return href;
|
return href;
|
||||||
@@ -437,13 +417,18 @@ int results_handler(UrlParams *params) {
|
|||||||
extern Config global_config;
|
extern Config global_config;
|
||||||
TemplateContext ctx = new_context();
|
TemplateContext ctx = new_context();
|
||||||
char *raw_query = "";
|
char *raw_query = "";
|
||||||
const char *selected_engine_id = "all";
|
char selected_engine_id[32];
|
||||||
|
char *default_engine = get_default_search_engine();
|
||||||
|
snprintf(selected_engine_id, sizeof(selected_engine_id), "%s",
|
||||||
|
default_engine);
|
||||||
|
free(default_engine);
|
||||||
int page = 1;
|
int page = 1;
|
||||||
int btnI = 0;
|
int btnI = 0;
|
||||||
|
|
||||||
char **user_engines = NULL;
|
char **user_engines = NULL;
|
||||||
int user_engine_count = 0;
|
int user_engine_count = 0;
|
||||||
int has_user_pref = (get_user_engines(&user_engines, &user_engine_count) == 0);
|
int has_user_pref =
|
||||||
|
(get_user_engines(&user_engines, &user_engine_count) == 0);
|
||||||
|
|
||||||
if (params) {
|
if (params) {
|
||||||
for (int i = 0; i < params->count; i++) {
|
for (int i = 0; i < params->count; i++) {
|
||||||
@@ -454,7 +439,8 @@ int results_handler(UrlParams *params) {
|
|||||||
if (parsed > 1)
|
if (parsed > 1)
|
||||||
page = parsed;
|
page = parsed;
|
||||||
} else if (strcmp(params->params[i].key, "engine") == 0) {
|
} else if (strcmp(params->params[i].key, "engine") == 0) {
|
||||||
selected_engine_id = params->params[i].value;
|
snprintf(selected_engine_id, sizeof(selected_engine_id), "%s",
|
||||||
|
params->params[i].value);
|
||||||
} else if (strcmp(params->params[i].key, "btnI") == 0) {
|
} else if (strcmp(params->params[i].key, "btnI") == 0) {
|
||||||
btnI = atoi(params->params[i].value);
|
btnI = atoi(params->params[i].value);
|
||||||
}
|
}
|
||||||
@@ -471,9 +457,11 @@ int results_handler(UrlParams *params) {
|
|||||||
beaker_set_locale(&ctx, locale);
|
beaker_set_locale(&ctx, locale);
|
||||||
|
|
||||||
const char *rate_limit_msg = beaker_get_locale_value(locale, "rate_limit");
|
const char *rate_limit_msg = beaker_get_locale_value(locale, "rate_limit");
|
||||||
if (!rate_limit_msg) rate_limit_msg = "Slow down! Too many searches from you!";
|
if (!rate_limit_msg)
|
||||||
|
rate_limit_msg = "Slow down! Too many searches from you!";
|
||||||
const char *no_results_msg = beaker_get_locale_value(locale, "no_results");
|
const char *no_results_msg = beaker_get_locale_value(locale, "no_results");
|
||||||
if (!no_results_msg) no_results_msg = "No results found";
|
if (!no_results_msg)
|
||||||
|
no_results_msg = "No results found";
|
||||||
|
|
||||||
char page_str[16];
|
char page_str[16];
|
||||||
snprintf(page_str, sizeof(page_str), "%d", page);
|
snprintf(page_str, sizeof(page_str), "%d", page);
|
||||||
@@ -491,18 +479,24 @@ int results_handler(UrlParams *params) {
|
|||||||
|
|
||||||
if (!raw_query || strlen(raw_query) == 0) {
|
if (!raw_query || strlen(raw_query) == 0) {
|
||||||
send_redirect("/");
|
send_redirect("/");
|
||||||
if (has_user_pref) {
|
free(locale);
|
||||||
for (int i = 0; i < user_engine_count; i++)
|
free_user_engine_list(user_engines, user_engine_count);
|
||||||
free(user_engines[i]);
|
|
||||||
free(user_engines);
|
|
||||||
}
|
|
||||||
free_context(&ctx);
|
free_context(&ctx);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SearchEngine *selected_engine = find_enabled_engine(selected_engine_id);
|
const SearchEngine *selected_engine = find_enabled_engine(selected_engine_id);
|
||||||
if (!selected_engine)
|
if (selected_engine &&
|
||||||
selected_engine_id = "all";
|
!engine_allowed_for_user(selected_engine, user_engines, user_engine_count,
|
||||||
|
has_user_pref)) {
|
||||||
|
selected_engine = NULL;
|
||||||
|
}
|
||||||
|
if (selected_engine) {
|
||||||
|
snprintf(selected_engine_id, sizeof(selected_engine_id), "%s",
|
||||||
|
selected_engine->id);
|
||||||
|
} else {
|
||||||
|
snprintf(selected_engine_id, sizeof(selected_engine_id), "all");
|
||||||
|
}
|
||||||
|
|
||||||
context_set(&ctx, "selected_engine", selected_engine_id);
|
context_set(&ctx, "selected_engine", selected_engine_id);
|
||||||
char *search_href = build_search_href(raw_query, selected_engine_id, 1);
|
char *search_href = build_search_href(raw_query, selected_engine_id, 1);
|
||||||
@@ -528,13 +522,6 @@ int results_handler(UrlParams *params) {
|
|||||||
infobox_data[i].result = (InfoBox){NULL};
|
infobox_data[i].result = (InfoBox){NULL};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page == 1) {
|
|
||||||
for (int i = 0; i < HANDLER_COUNT; i++) {
|
|
||||||
pthread_create(&infobox_threads[i], NULL, infobox_thread_func,
|
|
||||||
&infobox_data[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ScrapeJob jobs[ENGINE_COUNT];
|
ScrapeJob jobs[ENGINE_COUNT];
|
||||||
SearchResult *all_results[ENGINE_COUNT];
|
SearchResult *all_results[ENGINE_COUNT];
|
||||||
|
|
||||||
@@ -592,11 +579,8 @@ int results_handler(UrlParams *params) {
|
|||||||
snprintf(response, sizeof(response), "<h1>%s</h1>", rate_limit_msg);
|
snprintf(response, sizeof(response), "<h1>%s</h1>", rate_limit_msg);
|
||||||
send_response(response);
|
send_response(response);
|
||||||
free(request_cache_key);
|
free(request_cache_key);
|
||||||
if (has_user_pref) {
|
free(locale);
|
||||||
for (int i = 0; i < user_engine_count; i++)
|
free_user_engine_list(user_engines, user_engine_count);
|
||||||
free(user_engines[i]);
|
|
||||||
free(user_engines);
|
|
||||||
}
|
|
||||||
free_context(&ctx);
|
free_context(&ctx);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -615,15 +599,14 @@ int results_handler(UrlParams *params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (filter_engine_count > 1) {
|
if (filter_engine_count > 1) {
|
||||||
char ***filter_matrix = NULL;
|
StringMatrix filter_matrix;
|
||||||
int *filter_inner_counts = NULL;
|
string_matrix_init(&filter_matrix);
|
||||||
int filter_count = 0;
|
|
||||||
char *all_href = build_search_href(raw_query, "all", 1);
|
char *all_href = build_search_href(raw_query, "all", 1);
|
||||||
|
const char *all_values[LINK_FIELD_COUNT] = {
|
||||||
filter_count = add_link_to_collection(
|
|
||||||
all_href, "All",
|
all_href, "All",
|
||||||
selected_engine ? "engine-filter" : "engine-filter active",
|
selected_engine ? "engine-filter" : "engine-filter active"};
|
||||||
&filter_matrix, &filter_inner_counts, filter_count);
|
|
||||||
|
string_matrix_append(&filter_matrix, all_values, LINK_FIELD_COUNT);
|
||||||
free(all_href);
|
free(all_href);
|
||||||
|
|
||||||
for (int i = 0; i < ENGINE_COUNT; i++) {
|
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||||
@@ -639,22 +622,24 @@ int results_handler(UrlParams *params) {
|
|||||||
? "engine-filter active"
|
? "engine-filter active"
|
||||||
: "engine-filter";
|
: "engine-filter";
|
||||||
|
|
||||||
filter_count = add_link_to_collection(filter_href, ENGINE_REGISTRY[i].name,
|
const char *filter_values[LINK_FIELD_COUNT] = {
|
||||||
filter_class, &filter_matrix,
|
filter_href, ENGINE_REGISTRY[i].name, filter_class};
|
||||||
&filter_inner_counts, filter_count);
|
string_matrix_append(&filter_matrix, filter_values, LINK_FIELD_COUNT);
|
||||||
free(filter_href);
|
free(filter_href);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter_count > 0) {
|
if (filter_matrix.count > 0) {
|
||||||
context_set_array_of_arrays(&ctx, "engine_filters", filter_matrix,
|
context_set_array_of_arrays(&ctx, "engine_filters", filter_matrix.rows,
|
||||||
filter_count, filter_inner_counts);
|
filter_matrix.count,
|
||||||
for (int i = 0; i < filter_count; i++) {
|
filter_matrix.field_counts);
|
||||||
for (int j = 0; j < LINK_FIELD_COUNT; j++)
|
}
|
||||||
free(filter_matrix[i][j]);
|
string_matrix_free(&filter_matrix);
|
||||||
free(filter_matrix[i]);
|
}
|
||||||
}
|
|
||||||
free(filter_matrix);
|
if (page == 1) {
|
||||||
free(filter_inner_counts);
|
for (int i = 0; i < HANDLER_COUNT; i++) {
|
||||||
|
pthread_create(&infobox_threads[i], NULL, infobox_thread_func,
|
||||||
|
&infobox_data[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,27 +657,12 @@ int results_handler(UrlParams *params) {
|
|||||||
for (int i = 0; i < engine_idx; i++) {
|
for (int i = 0; i < engine_idx; i++) {
|
||||||
if (jobs[i].results_count > 0 && all_results[i][0].url) {
|
if (jobs[i].results_count > 0 && all_results[i][0].url) {
|
||||||
char *redirect_url = strdup(all_results[i][0].url);
|
char *redirect_url = strdup(all_results[i][0].url);
|
||||||
for (int j = 0; j < enabled_engine_count; j++) {
|
free_search_results(all_results, jobs, engine_idx);
|
||||||
for (int k = 0; k < jobs[j].results_count; k++) {
|
if (page == 1)
|
||||||
free(all_results[j][k].url);
|
free_infobox_results(infobox_data);
|
||||||
free(all_results[j][k].title);
|
|
||||||
free(all_results[j][k].snippet);
|
|
||||||
}
|
|
||||||
free(all_results[j]);
|
|
||||||
}
|
|
||||||
if (page == 1) {
|
|
||||||
for (int j = 0; j < HANDLER_COUNT; j++) {
|
|
||||||
if (infobox_data[j].success) {
|
|
||||||
free_infobox(&infobox_data[j].result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(request_cache_key);
|
free(request_cache_key);
|
||||||
if (has_user_pref) {
|
free(locale);
|
||||||
for (int i = 0; i < user_engine_count; i++)
|
free_user_engine_list(user_engines, user_engine_count);
|
||||||
free(user_engines[i]);
|
|
||||||
free(user_engines);
|
|
||||||
}
|
|
||||||
free_context(&ctx);
|
free_context(&ctx);
|
||||||
if (redirect_url) {
|
if (redirect_url) {
|
||||||
send_redirect(redirect_url);
|
send_redirect(redirect_url);
|
||||||
@@ -701,54 +671,37 @@ int results_handler(UrlParams *params) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < enabled_engine_count; i++) {
|
free_search_results(all_results, jobs, engine_idx);
|
||||||
free(all_results[i]);
|
if (page == 1)
|
||||||
}
|
free_infobox_results(infobox_data);
|
||||||
if (page == 1) {
|
|
||||||
for (int i = 0; i < HANDLER_COUNT; i++) {
|
|
||||||
if (infobox_data[i].success) {
|
|
||||||
free_infobox(&infobox_data[i].result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(request_cache_key);
|
free(request_cache_key);
|
||||||
if (has_user_pref) {
|
free(locale);
|
||||||
for (int i = 0; i < user_engine_count; i++)
|
free_user_engine_list(user_engines, user_engine_count);
|
||||||
free(user_engines[i]);
|
|
||||||
free(user_engines);
|
|
||||||
}
|
|
||||||
free_context(&ctx);
|
free_context(&ctx);
|
||||||
char no_results_html[128];
|
char no_results_html[128];
|
||||||
snprintf(no_results_html, sizeof(no_results_html), "<h1>%s</h1>", no_results_msg);
|
snprintf(no_results_html, sizeof(no_results_html), "<h1>%s</h1>",
|
||||||
|
no_results_msg);
|
||||||
send_response(no_results_html);
|
send_response(no_results_html);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char ***infobox_matrix = NULL;
|
StringMatrix infobox_matrix;
|
||||||
int *infobox_inner_counts = NULL;
|
string_matrix_init(&infobox_matrix);
|
||||||
int infobox_count = 0;
|
|
||||||
|
|
||||||
if (page == 1) {
|
if (page == 1) {
|
||||||
for (int i = 0; i < HANDLER_COUNT; i++) {
|
for (int i = 0; i < HANDLER_COUNT; i++) {
|
||||||
if (infobox_data[i].success) {
|
if (infobox_data[i].success) {
|
||||||
infobox_count =
|
add_infobox_to_collection(&infobox_data[i].result, &infobox_matrix);
|
||||||
add_infobox_to_collection(&infobox_data[i].result, &infobox_matrix,
|
|
||||||
&infobox_inner_counts, infobox_count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (infobox_count > 0) {
|
if (infobox_matrix.count > 0) {
|
||||||
context_set_array_of_arrays(&ctx, "infoboxes", infobox_matrix,
|
context_set_array_of_arrays(&ctx, "infoboxes", infobox_matrix.rows,
|
||||||
infobox_count, infobox_inner_counts);
|
infobox_matrix.count,
|
||||||
for (int i = 0; i < infobox_count; i++) {
|
infobox_matrix.field_counts);
|
||||||
for (int j = 0; j < INFOBOX_FIELD_COUNT; j++)
|
|
||||||
free(infobox_matrix[i][j]);
|
|
||||||
free(infobox_matrix[i]);
|
|
||||||
}
|
|
||||||
free(infobox_matrix);
|
|
||||||
free(infobox_inner_counts);
|
|
||||||
}
|
}
|
||||||
|
string_matrix_free(&infobox_matrix);
|
||||||
|
|
||||||
int warning_count = 0;
|
int warning_count = 0;
|
||||||
for (int i = 0; i < enabled_engine_count; i++) {
|
for (int i = 0; i < enabled_engine_count; i++) {
|
||||||
@@ -757,35 +710,33 @@ int results_handler(UrlParams *params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (warning_count > 0) {
|
if (warning_count > 0) {
|
||||||
char ***warning_matrix = NULL;
|
StringMatrix warning_matrix;
|
||||||
int *warning_inner_counts = NULL;
|
string_matrix_init(&warning_matrix);
|
||||||
int warning_index = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < enabled_engine_count; i++) {
|
for (int i = 0; i < enabled_engine_count; i++) {
|
||||||
const char *warning_message = warning_message_for_job(&jobs[i], locale);
|
const char *warning_message = warning_message_for_job(&jobs[i], locale);
|
||||||
if (!warning_message)
|
if (!warning_message)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
warning_index = add_warning_to_collection(
|
if (jobs[i].http_status >= 400) {
|
||||||
jobs[i].engine->name, warning_message, &warning_matrix,
|
char warning_with_status[BUFFER_SIZE_LARGE];
|
||||||
&warning_inner_counts, warning_index);
|
snprintf(warning_with_status, sizeof(warning_with_status),
|
||||||
}
|
"%s (HTTP %ld)", warning_message, jobs[i].http_status);
|
||||||
|
add_warning_to_collection(jobs[i].engine->name, warning_with_status,
|
||||||
if (warning_index > 0) {
|
&warning_matrix);
|
||||||
context_set_array_of_arrays(&ctx, "engine_warnings", warning_matrix,
|
} else {
|
||||||
warning_index, warning_inner_counts);
|
add_warning_to_collection(jobs[i].engine->name, warning_message,
|
||||||
}
|
&warning_matrix);
|
||||||
|
|
||||||
if (warning_matrix) {
|
|
||||||
for (int i = 0; i < warning_index; i++) {
|
|
||||||
free(warning_matrix[i][0]);
|
|
||||||
free(warning_matrix[i][1]);
|
|
||||||
free(warning_matrix[i]);
|
|
||||||
}
|
}
|
||||||
free(warning_matrix);
|
|
||||||
}
|
}
|
||||||
if (warning_inner_counts)
|
|
||||||
free(warning_inner_counts);
|
if (warning_matrix.count > 0) {
|
||||||
|
context_set_array_of_arrays(&ctx, "engine_warnings", warning_matrix.rows,
|
||||||
|
warning_matrix.count,
|
||||||
|
warning_matrix.field_counts);
|
||||||
|
}
|
||||||
|
|
||||||
|
string_matrix_free(&warning_matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
int total_results = 0;
|
int total_results = 0;
|
||||||
@@ -794,33 +745,8 @@ int results_handler(UrlParams *params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (total_results > 0) {
|
if (total_results > 0) {
|
||||||
char ***results_matrix = (char ***)malloc(sizeof(char **) * total_results);
|
StringMatrix results_matrix;
|
||||||
int *results_inner_counts = (int *)malloc(sizeof(int) * total_results);
|
string_matrix_init(&results_matrix);
|
||||||
if (!results_matrix || !results_inner_counts) {
|
|
||||||
char *html = render_template("results.html", &ctx);
|
|
||||||
if (html) {
|
|
||||||
send_response(html);
|
|
||||||
free(html);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < enabled_engine_count; i++)
|
|
||||||
free(all_results[i]);
|
|
||||||
if (page == 1) {
|
|
||||||
for (int i = 0; i < HANDLER_COUNT; i++) {
|
|
||||||
if (infobox_data[i].success) {
|
|
||||||
free_infobox(&infobox_data[i].result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(request_cache_key);
|
|
||||||
if (has_user_pref) {
|
|
||||||
for (int i = 0; i < user_engine_count; i++)
|
|
||||||
free(user_engines[i]);
|
|
||||||
free(user_engines);
|
|
||||||
}
|
|
||||||
free_context(&ctx);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int unique_count = 0;
|
|
||||||
UrlHashTable url_table;
|
UrlHashTable url_table;
|
||||||
url_hash_init(&url_table);
|
url_hash_init(&url_table);
|
||||||
|
|
||||||
@@ -837,61 +763,45 @@ int results_handler(UrlParams *params) {
|
|||||||
|
|
||||||
url_hash_insert(&url_table, display_url);
|
url_hash_insert(&url_table, display_url);
|
||||||
|
|
||||||
results_matrix[unique_count] =
|
|
||||||
(char **)malloc(sizeof(char *) * RESULT_FIELD_COUNT);
|
|
||||||
if (!results_matrix[unique_count]) {
|
|
||||||
free(all_results[i][j].url);
|
|
||||||
free(all_results[i][j].title);
|
|
||||||
free(all_results[i][j].snippet);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
char *pretty_url = pretty_display_url(display_url);
|
char *pretty_url = pretty_display_url(display_url);
|
||||||
char *base_url = get_base_url(display_url);
|
char *base_url = get_base_url(display_url);
|
||||||
|
const char *values[RESULT_FIELD_COUNT] = {
|
||||||
results_matrix[unique_count][0] = strdup(display_url);
|
display_url,
|
||||||
results_matrix[unique_count][1] = strdup(pretty_url);
|
pretty_url,
|
||||||
results_matrix[unique_count][2] = all_results[i][j].title
|
all_results[i][j].title ? all_results[i][j].title : "Untitled",
|
||||||
? strdup(all_results[i][j].title)
|
all_results[i][j].snippet ? all_results[i][j].snippet : "",
|
||||||
: strdup("Untitled");
|
base_url,
|
||||||
results_matrix[unique_count][3] =
|
"",
|
||||||
all_results[i][j].snippet ? strdup(all_results[i][j].snippet)
|
};
|
||||||
: strdup("");
|
int append_result =
|
||||||
results_matrix[unique_count][4] = strdup(base_url ? base_url : "");
|
string_matrix_append(&results_matrix, values, RESULT_FIELD_COUNT);
|
||||||
results_matrix[unique_count][5] = strdup("");
|
|
||||||
|
|
||||||
results_inner_counts[unique_count] = RESULT_FIELD_COUNT;
|
|
||||||
|
|
||||||
free(pretty_url);
|
free(pretty_url);
|
||||||
free(base_url);
|
free(base_url);
|
||||||
free(all_results[i][j].url);
|
free(all_results[i][j].url);
|
||||||
free(all_results[i][j].title);
|
free(all_results[i][j].title);
|
||||||
free(all_results[i][j].snippet);
|
free(all_results[i][j].snippet);
|
||||||
|
if (append_result != 0) {
|
||||||
unique_count++;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free(all_results[i]);
|
free(all_results[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
context_set_array_of_arrays(&ctx, "results", results_matrix, unique_count,
|
context_set_array_of_arrays(&ctx, "results", results_matrix.rows,
|
||||||
results_inner_counts);
|
results_matrix.count,
|
||||||
|
results_matrix.field_counts);
|
||||||
|
|
||||||
char ***pager_matrix = NULL;
|
StringMatrix pager_matrix;
|
||||||
int *pager_inner_counts = NULL;
|
SearchHrefData href_data = {.query = raw_query,
|
||||||
SearchHrefData href_data = { .query = raw_query, .engine_id = selected_engine_id };
|
.engine_id = selected_engine_id};
|
||||||
int pager_count = build_pagination(page, search_href_builder,
|
int pagination_result = string_matrix_build_pagination(
|
||||||
&href_data, &pager_matrix,
|
page, search_href_builder, &href_data, &pager_matrix);
|
||||||
&pager_inner_counts);
|
|
||||||
|
|
||||||
if (pager_count > 0) {
|
if (pagination_result == 0 && pager_matrix.count > 0) {
|
||||||
context_set_array_of_arrays(&ctx, "pagination_links", pager_matrix,
|
context_set_array_of_arrays(&ctx, "pagination_links", pager_matrix.rows,
|
||||||
pager_count, pager_inner_counts);
|
pager_matrix.count,
|
||||||
for (int i = 0; i < pager_count; i++) {
|
pager_matrix.field_counts);
|
||||||
for (int j = 0; j < LINK_FIELD_COUNT; j++)
|
|
||||||
free(pager_matrix[i][j]);
|
|
||||||
free(pager_matrix[i]);
|
|
||||||
}
|
|
||||||
free(pager_matrix);
|
|
||||||
free(pager_inner_counts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *html = render_template("results.html", &ctx);
|
char *html = render_template("results.html", &ctx);
|
||||||
@@ -900,13 +810,8 @@ int results_handler(UrlParams *params) {
|
|||||||
free(html);
|
free(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < unique_count; i++) {
|
string_matrix_free(&pager_matrix);
|
||||||
for (int j = 0; j < RESULT_FIELD_COUNT; j++)
|
string_matrix_free(&results_matrix);
|
||||||
free(results_matrix[i][j]);
|
|
||||||
free(results_matrix[i]);
|
|
||||||
}
|
|
||||||
free(results_matrix);
|
|
||||||
free(results_inner_counts);
|
|
||||||
url_hash_free(&url_table);
|
url_hash_free(&url_table);
|
||||||
} else {
|
} else {
|
||||||
char *html = render_template("results.html", &ctx);
|
char *html = render_template("results.html", &ctx);
|
||||||
@@ -915,26 +820,15 @@ int results_handler(UrlParams *params) {
|
|||||||
free(html);
|
free(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < enabled_engine_count; i++) {
|
free_search_results(all_results, jobs, engine_idx);
|
||||||
free(all_results[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(request_cache_key);
|
free(request_cache_key);
|
||||||
|
|
||||||
if (page == 1) {
|
if (page == 1)
|
||||||
for (int i = 0; i < HANDLER_COUNT; i++) {
|
free_infobox_results(infobox_data);
|
||||||
if (infobox_data[i].success) {
|
|
||||||
free_infobox(&infobox_data[i].result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(locale);
|
free(locale);
|
||||||
if (has_user_pref) {
|
free_user_engine_list(user_engines, user_engine_count);
|
||||||
for (int i = 0; i < user_engine_count; i++)
|
|
||||||
free(user_engines[i]);
|
|
||||||
free(user_engines);
|
|
||||||
}
|
|
||||||
free_context(&ctx);
|
free_context(&ctx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -5,6 +5,27 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
static char *format_theme_name(const char *theme) {
|
||||||
|
char *label = strdup(theme ? theme : "");
|
||||||
|
if (!label)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
int capitalise_next = 1;
|
||||||
|
for (size_t i = 0; label[i] != '\0'; i++) {
|
||||||
|
if (label[i] == '-') {
|
||||||
|
label[i] = ' ';
|
||||||
|
capitalise_next = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (capitalise_next) {
|
||||||
|
if (label[i] >= 'a' && label[i] <= 'z')
|
||||||
|
label[i] = label[i] - 'a' + 'A';
|
||||||
|
capitalise_next = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
int settings_handler(UrlParams *params) {
|
int settings_handler(UrlParams *params) {
|
||||||
const char *query = "";
|
const char *query = "";
|
||||||
if (params) {
|
if (params) {
|
||||||
@@ -34,6 +55,14 @@ int settings_handler(UrlParams *params) {
|
|||||||
int user_engine_count = 0;
|
int user_engine_count = 0;
|
||||||
int has_user_pref =
|
int has_user_pref =
|
||||||
(get_user_engines(&user_engines, &user_engine_count) == 0);
|
(get_user_engines(&user_engines, &user_engine_count) == 0);
|
||||||
|
char *default_engine = get_default_search_engine();
|
||||||
|
|
||||||
|
if (strcmp(default_engine, "all") != 0 && has_user_pref &&
|
||||||
|
!user_engines_contains(default_engine, user_engines,
|
||||||
|
user_engine_count)) {
|
||||||
|
free(default_engine);
|
||||||
|
default_engine = strdup("all");
|
||||||
|
}
|
||||||
|
|
||||||
int enabled_count = 0;
|
int enabled_count = 0;
|
||||||
for (int i = 0; i < ENGINE_COUNT; i++) {
|
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||||
@@ -63,11 +92,13 @@ int settings_handler(UrlParams *params) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
engine_data[idx] = malloc(sizeof(char *) * 3);
|
engine_data[idx] = malloc(sizeof(char *) * 4);
|
||||||
engine_data[idx][0] = (char *)ENGINE_REGISTRY[i].id;
|
engine_data[idx][0] = (char *)ENGINE_REGISTRY[i].id;
|
||||||
engine_data[idx][1] = (char *)ENGINE_REGISTRY[i].name;
|
engine_data[idx][1] = (char *)ENGINE_REGISTRY[i].name;
|
||||||
engine_data[idx][2] = is_selected ? "checked" : "";
|
engine_data[idx][2] = is_selected ? "checked" : "";
|
||||||
engine_inner[idx] = 3;
|
engine_data[idx][3] =
|
||||||
|
strcmp(default_engine, ENGINE_REGISTRY[i].id) == 0 ? "selected" : "";
|
||||||
|
engine_inner[idx] = 4;
|
||||||
|
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
@@ -78,6 +109,7 @@ int settings_handler(UrlParams *params) {
|
|||||||
context_set(&ctx, "query", query);
|
context_set(&ctx, "query", query);
|
||||||
context_set(&ctx, "theme", theme);
|
context_set(&ctx, "theme", theme);
|
||||||
context_set(&ctx, "locale", locale);
|
context_set(&ctx, "locale", locale);
|
||||||
|
context_set(&ctx, "default_engine", default_engine);
|
||||||
context_set_array_of_arrays(&ctx, "locales", locale_data, locale_count,
|
context_set_array_of_arrays(&ctx, "locales", locale_data, locale_count,
|
||||||
inner_counts);
|
inner_counts);
|
||||||
|
|
||||||
@@ -91,10 +123,7 @@ int settings_handler(UrlParams *params) {
|
|||||||
for (int i = 0; i < themes_count; i++) {
|
for (int i = 0; i < themes_count; i++) {
|
||||||
theme_ptrs[i] = malloc(sizeof(char *) * 2);
|
theme_ptrs[i] = malloc(sizeof(char *) * 2);
|
||||||
theme_ptrs[i][0] = themes[i];
|
theme_ptrs[i][0] = themes[i];
|
||||||
theme_ptrs[i][1] = strdup(themes[i]);
|
theme_ptrs[i][1] = format_theme_name(themes[i]);
|
||||||
if (theme_ptrs[i][1][0] >= 'a' && theme_ptrs[i][1][0] <= 'z') {
|
|
||||||
theme_ptrs[i][1][0] = theme_ptrs[i][1][0] - 'a' + 'A';
|
|
||||||
}
|
|
||||||
theme_inner[i] = 2;
|
theme_inner[i] = 2;
|
||||||
}
|
}
|
||||||
context_set_array_of_arrays(&ctx, "themes", theme_ptrs, themes_count,
|
context_set_array_of_arrays(&ctx, "themes", theme_ptrs, themes_count,
|
||||||
@@ -132,6 +161,7 @@ int settings_handler(UrlParams *params) {
|
|||||||
send_response(rendered_html);
|
send_response(rendered_html);
|
||||||
|
|
||||||
free(rendered_html);
|
free(rendered_html);
|
||||||
|
free(default_engine);
|
||||||
free(theme);
|
free(theme);
|
||||||
free(locale);
|
free(locale);
|
||||||
free_context(&ctx);
|
free_context(&ctx);
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ int settings_save_handler(UrlParams *params) {
|
|||||||
const char *theme = "";
|
const char *theme = "";
|
||||||
const char *locale = "";
|
const char *locale = "";
|
||||||
const char *query = "";
|
const char *query = "";
|
||||||
|
const char *default_engine = "all";
|
||||||
|
int default_engine_present = 0;
|
||||||
int engines_present = 0;
|
int engines_present = 0;
|
||||||
char selected_ids[ENGINE_COUNT][32];
|
char selected_ids[ENGINE_COUNT][32];
|
||||||
int selected_count = 0;
|
int selected_count = 0;
|
||||||
@@ -22,6 +24,9 @@ int settings_save_handler(UrlParams *params) {
|
|||||||
locale = params->params[i].value;
|
locale = params->params[i].value;
|
||||||
} else if (strcmp(params->params[i].key, "q") == 0) {
|
} else if (strcmp(params->params[i].key, "q") == 0) {
|
||||||
query = params->params[i].value;
|
query = params->params[i].value;
|
||||||
|
} else if (strcmp(params->params[i].key, "default_engine") == 0) {
|
||||||
|
default_engine = params->params[i].value;
|
||||||
|
default_engine_present = 1;
|
||||||
} else if (strcmp(params->params[i].key, "engines_present") == 0) {
|
} else if (strcmp(params->params[i].key, "engines_present") == 0) {
|
||||||
engines_present = 1;
|
engines_present = 1;
|
||||||
} else if (strncmp(params->params[i].key, "engine_", 7) == 0 &&
|
} else if (strncmp(params->params[i].key, "engine_", 7) == 0 &&
|
||||||
@@ -31,8 +36,8 @@ int settings_save_handler(UrlParams *params) {
|
|||||||
selected_count < ENGINE_COUNT) {
|
selected_count < ENGINE_COUNT) {
|
||||||
strncpy(selected_ids[selected_count], engine_id,
|
strncpy(selected_ids[selected_count], engine_id,
|
||||||
sizeof(selected_ids[selected_count]) - 1);
|
sizeof(selected_ids[selected_count]) - 1);
|
||||||
selected_ids[selected_count][sizeof(selected_ids[selected_count]) - 1] =
|
selected_ids[selected_count]
|
||||||
'\0';
|
[sizeof(selected_ids[selected_count]) - 1] = '\0';
|
||||||
selected_count++;
|
selected_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,24 +45,67 @@ int settings_save_handler(UrlParams *params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(theme) > 0) {
|
if (strlen(theme) > 0) {
|
||||||
set_cookie("theme", theme, "Fri, 31 Dec 2038 23:59:59 GMT", "/", false, false);
|
set_cookie("theme", theme, "Fri, 31 Dec 2038 23:59:59 GMT", "/", false,
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
if (strlen(locale) > 0) {
|
if (strlen(locale) > 0) {
|
||||||
set_cookie("locale", locale, "Fri, 31 Dec 2038 23:59:59 GMT", "/", false, false);
|
set_cookie("locale", locale, "Fri, 31 Dec 2038 23:59:59 GMT", "/", false,
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (engines_present) {
|
if (engines_present) {
|
||||||
char cookie_value[512];
|
char cookie_value[512];
|
||||||
cookie_value[0] = '\0';
|
cookie_value[0] = '\0';
|
||||||
|
size_t used = 0;
|
||||||
|
cookie_value[0] = '\0';
|
||||||
for (int i = 0; i < selected_count; i++) {
|
for (int i = 0; i < selected_count; i++) {
|
||||||
if (i > 0)
|
const char *id = selected_ids[i];
|
||||||
strcat(cookie_value, ",");
|
size_t idlen = strlen(id);
|
||||||
strcat(cookie_value, selected_ids[i]);
|
if (i > 0) {
|
||||||
|
if (used + 1 < sizeof(cookie_value)) {
|
||||||
|
cookie_value[used++] = '+';
|
||||||
|
cookie_value[used] = '\0';
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (used + idlen < sizeof(cookie_value)) {
|
||||||
|
memcpy(cookie_value + used, id, idlen);
|
||||||
|
used += idlen;
|
||||||
|
cookie_value[used] = '\0';
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
set_cookie("engines", cookie_value, "Fri, 31 Dec 2038 23:59:59 GMT", "/",
|
set_cookie("engines", cookie_value, "Fri, 31 Dec 2038 23:59:59 GMT", "/",
|
||||||
false, false);
|
false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (default_engine_present) {
|
||||||
|
const char *validated_default = "all";
|
||||||
|
|
||||||
|
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||||
|
if (!ENGINE_REGISTRY[i].enabled ||
|
||||||
|
strcmp(default_engine, ENGINE_REGISTRY[i].id) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int selected = !engines_present;
|
||||||
|
for (int j = 0; j < selected_count; j++) {
|
||||||
|
if (strcmp(selected_ids[j], ENGINE_REGISTRY[i].id) == 0) {
|
||||||
|
selected = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selected)
|
||||||
|
validated_default = ENGINE_REGISTRY[i].id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_cookie("default_engine", validated_default,
|
||||||
|
"Fri, 31 Dec 2038 23:59:59 GMT", "/", false, false);
|
||||||
|
}
|
||||||
|
|
||||||
char redirect_url[512];
|
char redirect_url[512];
|
||||||
snprintf(redirect_url, sizeof(redirect_url), "/settings?q=%s", query);
|
snprintf(redirect_url, sizeof(redirect_url), "/settings?q=%s", query);
|
||||||
send_redirect(redirect_url);
|
send_redirect(redirect_url);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "ImageScraping.h"
|
#include "ImageScraping.h"
|
||||||
#include "../Utility/HttpClient.h"
|
#include "../Utility/HttpClient.h"
|
||||||
|
#include "../Utility/Unescape.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include <libxml/HTMLparser.h>
|
#include <libxml/HTMLparser.h>
|
||||||
#include <libxml/xpath.h>
|
#include <libxml/xpath.h>
|
||||||
@@ -29,51 +30,30 @@ static char *build_proxy_url(const char *image_url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char *extract_json_string(const char *json, const char *key) {
|
static char *extract_json_string(const char *json, const char *key) {
|
||||||
if (!json || !key)
|
if (!json || !key) return NULL;
|
||||||
return NULL;
|
|
||||||
|
|
||||||
char search_key[64];
|
char search_key[64];
|
||||||
snprintf(search_key, sizeof(search_key), "\"%s\"", key);
|
snprintf(search_key, sizeof(search_key), "\"%s\"", key);
|
||||||
|
|
||||||
const char *key_pos = strstr(json, search_key);
|
const char *key_pos = strstr(json, search_key);
|
||||||
if (!key_pos)
|
if (!key_pos) return NULL;
|
||||||
return NULL;
|
|
||||||
|
|
||||||
const char *colon = strchr(key_pos + strlen(search_key), ':');
|
const char *colon = strchr(key_pos + strlen(search_key), ':');
|
||||||
if (!colon)
|
if (!colon) return NULL;
|
||||||
return NULL;
|
|
||||||
|
|
||||||
colon++;
|
colon++;
|
||||||
while (*colon == ' ' || *colon == '\t' || *colon == '\n' || *colon == '\r')
|
while (*colon == ' ' || *colon == '\t' || *colon == '\n' || *colon == '\r') colon++;
|
||||||
colon++;
|
if (*colon != '"') return NULL;
|
||||||
|
|
||||||
if (*colon != '"')
|
|
||||||
return NULL;
|
|
||||||
colon++;
|
colon++;
|
||||||
|
|
||||||
size_t len = 0;
|
const char *end = colon;
|
||||||
const char *start = colon;
|
while (*end && *end != '"') {
|
||||||
while (*colon && *colon != '"') {
|
if (*end == '\\' && end[1]) end += 2;
|
||||||
if (*colon == '\\' && *(colon + 1))
|
else end += 1;
|
||||||
colon++;
|
|
||||||
colon++;
|
|
||||||
len++;
|
|
||||||
}
|
}
|
||||||
|
if (*end != '"') return NULL;
|
||||||
|
|
||||||
char *result = malloc(len + 1);
|
return json_string_unescape(colon, end);
|
||||||
if (!result)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
colon = start;
|
|
||||||
size_t i = 0;
|
|
||||||
while (*colon && *colon != '"') {
|
|
||||||
if (*colon == '\\' && *(colon + 1))
|
|
||||||
colon++;
|
|
||||||
result[i++] = *colon++;
|
|
||||||
}
|
|
||||||
result[i] = '\0';
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_iusc_node(xmlNodePtr node, ImageResult *result) {
|
static int parse_iusc_node(xmlNodePtr node, ImageResult *result) {
|
||||||
@@ -140,7 +120,7 @@ int scrape_images(const char *query, int page, ImageResult **out_results,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
htmlDocPtr doc = htmlReadMemory(resp.memory, resp.size, NULL, NULL,
|
htmlDocPtr doc = htmlReadMemory(resp.memory, resp.size, NULL, "UTF-8",
|
||||||
HTML_PARSE_RECOVER | HTML_PARSE_NOERROR);
|
HTML_PARSE_RECOVER | HTML_PARSE_NOERROR);
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
http_response_free(&resp);
|
http_response_free(&resp);
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
#include "Scraping.h"
|
#include "Scraping.h"
|
||||||
#include "../Cache/Cache.h"
|
#include "../Cache/Cache.h"
|
||||||
#include "../Proxy/Proxy.h"
|
#include "../Proxy/Proxy.h"
|
||||||
|
#include "../Utility/XmlHelper.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <libxml/HTMLparser.h>
|
#include <libxml/HTMLparser.h>
|
||||||
|
#include <libxml/parser.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -13,6 +15,79 @@ static int response_contains(const char *response, const char *needle) {
|
|||||||
return response && needle && strstr(response, needle) != NULL;
|
return response && needle && strstr(response, needle) != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int is_ddg_job(const ScrapeJob *job) {
|
||||||
|
return job && job->engine && job->engine->id &&
|
||||||
|
strcmp(job->engine->id, "ddg") == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *job_cache_key(const ScrapeJob *job, int page) {
|
||||||
|
const char *scope = is_ddg_job(job) ? "ddg_pagination_v2" : job->engine->name;
|
||||||
|
return cache_compute_key(job->query, page, scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *ddg_request_data(ScrapeJob *job, const char *encoded_query) {
|
||||||
|
job->current_page = 1;
|
||||||
|
if (job->page > 1 && get_cache_ttl_search() > 0) {
|
||||||
|
char *key = job_cache_key(job, job->page - 1);
|
||||||
|
char *cached = NULL;
|
||||||
|
size_t size = 0;
|
||||||
|
char *data = NULL;
|
||||||
|
if (key && cache_get(key, get_cache_ttl_search(), &cached, &size) == 0)
|
||||||
|
data = build_ddg_next_page_data(cached, size);
|
||||||
|
free(cached);
|
||||||
|
free(key);
|
||||||
|
if (data) {
|
||||||
|
job->current_page = job->page;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size = strlen(encoded_query) + sizeof("q=&b=");
|
||||||
|
char *data = malloc(size);
|
||||||
|
if (data)
|
||||||
|
snprintf(data, size, "q=%s&b=", encoded_query);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int configure_ddg_request(ScrapeJob *job, char *url,
|
||||||
|
const char *encoded_query) {
|
||||||
|
char *data = ddg_request_data(job, encoded_query);
|
||||||
|
if (!data)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
char *query_start = strchr(url, '?');
|
||||||
|
if (query_start)
|
||||||
|
*query_start = '\0';
|
||||||
|
|
||||||
|
curl_easy_setopt(job->handle, CURLOPT_URL, url);
|
||||||
|
curl_easy_setopt(job->handle, CURLOPT_USERAGENT, get_first_user_agent());
|
||||||
|
CURLcode code = curl_easy_setopt(job->handle, CURLOPT_COPYPOSTFIELDS, data);
|
||||||
|
free(data);
|
||||||
|
return code == CURLE_OK ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int configure_job_request(ScrapeJob *job, char *url,
|
||||||
|
const char *encoded_query) {
|
||||||
|
job->handle = curl_easy_init();
|
||||||
|
if (!job->handle)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
job->response.memory = (char *)malloc(INITIAL_BUFFER_SIZE);
|
||||||
|
job->response.size = 0;
|
||||||
|
job->response.capacity = INITIAL_BUFFER_SIZE;
|
||||||
|
if (!job->response.memory)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
struct curl_slist *headers =
|
||||||
|
build_request_headers(job->engine->host_header, job->engine->referer);
|
||||||
|
|
||||||
|
configure_curl_handle(job->handle, url, &job->response, headers);
|
||||||
|
curl_easy_setopt(job->handle, CURLOPT_PRIVATE, headers);
|
||||||
|
if (is_ddg_job(job))
|
||||||
|
return configure_ddg_request(job, url, encoded_query);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int is_startpage_job(const ScrapeJob *job) {
|
static int is_startpage_job(const ScrapeJob *job) {
|
||||||
return job && job->engine && strcmp(job->engine->name, "Startpage") == 0;
|
return job && job->engine && strcmp(job->engine->name, "Startpage") == 0;
|
||||||
}
|
}
|
||||||
@@ -24,7 +99,8 @@ static int response_is_startpage_captcha(const ScrapeJob *job,
|
|||||||
|
|
||||||
return response_contains(response, "<title>Startpage Captcha</title>") ||
|
return response_contains(response, "<title>Startpage Captcha</title>") ||
|
||||||
response_contains(response, "Startpage Captcha") ||
|
response_contains(response, "Startpage Captcha") ||
|
||||||
response_contains(response, "/static-pages-assets/page-data/captcha/") ||
|
response_contains(response,
|
||||||
|
"/static-pages-assets/page-data/captcha/") ||
|
||||||
response_contains(response, ">Startpage Blocked</title>");
|
response_contains(response, ">Startpage Blocked</title>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +115,8 @@ static int response_looks_like_results_page(const ScrapeJob *job,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(job->engine->name, "Startpage") == 0) {
|
if (strcmp(job->engine->name, "Startpage") == 0) {
|
||||||
return response_contains(response, "<title>Startpage Search Results</title>") ||
|
return response_contains(response,
|
||||||
|
"<title>Startpage Search Results</title>") ||
|
||||||
response_contains(response, "class=\"w-gl") ||
|
response_contains(response, "class=\"w-gl") ||
|
||||||
response_contains(response, "data-testid=\"gl-title-link\"");
|
response_contains(response, "data-testid=\"gl-title-link\"");
|
||||||
}
|
}
|
||||||
@@ -55,6 +132,11 @@ static int response_looks_like_results_page(const ScrapeJob *job,
|
|||||||
response_contains(response, "Mojeek Search");
|
response_contains(response, "Mojeek Search");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strcmp(job->engine->name, "YaCy") == 0) {
|
||||||
|
return response_contains(response, "<item") ||
|
||||||
|
response_contains(response, "<rss");
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,23 +149,30 @@ static void classify_job_response(ScrapeJob *job, const char *response,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response_is_startpage_captcha(job, response)) {
|
if (response_is_startpage_captcha(job, response) ||
|
||||||
|
(is_ddg_job(job) && response_contains(response, "id=\"challenge-form\""))) {
|
||||||
job->status = SCRAPE_STATUS_BLOCKED;
|
job->status = SCRAPE_STATUS_BLOCKED;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlDocPtr doc = htmlReadMemory(response, response_size, NULL, NULL,
|
xmlDocPtr doc;
|
||||||
HTML_PARSE_RECOVER | HTML_PARSE_NOERROR |
|
if (job->engine->is_xml) {
|
||||||
HTML_PARSE_NOWARNING);
|
doc = xmlReadMemory(response, response_size, NULL, NULL,
|
||||||
|
XML_PARSE_RECOVER | XML_PARSE_NOERROR |
|
||||||
|
XML_PARSE_NOWARNING);
|
||||||
|
} else {
|
||||||
|
doc = htmlReadMemory(response, response_size, NULL, NULL,
|
||||||
|
HTML_PARSE_RECOVER | HTML_PARSE_NOERROR |
|
||||||
|
HTML_PARSE_NOWARNING);
|
||||||
|
}
|
||||||
|
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
job->status = SCRAPE_STATUS_FETCH_ERROR;
|
job->status = SCRAPE_STATUS_FETCH_ERROR;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
job->results_count =
|
job->results_count = job->engine->parser(job->engine->name, doc,
|
||||||
job->engine->parser(job->engine->name, doc, job->out_results,
|
job->out_results, job->max_results);
|
||||||
job->max_results);
|
|
||||||
xmlFreeDoc(doc);
|
xmlFreeDoc(doc);
|
||||||
|
|
||||||
if (job->results_count > 0) {
|
if (job->results_count > 0) {
|
||||||
@@ -108,7 +197,7 @@ int check_cache_for_job(ScrapeJob *job) {
|
|||||||
if (get_cache_ttl_search() <= 0)
|
if (get_cache_ttl_search() <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
char *key = cache_compute_key(job->query, job->page, job->engine->name);
|
char *key = job_cache_key(job, job->page);
|
||||||
if (!key)
|
if (!key)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -149,50 +238,86 @@ void parse_and_cache_response(ScrapeJob *job) {
|
|||||||
classify_job_response(job, job->response.memory, job->response.size);
|
classify_job_response(job, job->response.memory, job->response.size);
|
||||||
|
|
||||||
if (job->status == SCRAPE_STATUS_OK || job->status == SCRAPE_STATUS_EMPTY) {
|
if (job->status == SCRAPE_STATUS_OK || job->status == SCRAPE_STATUS_EMPTY) {
|
||||||
char *key = cache_compute_key(job->query, job->page, job->engine->name);
|
char *key = job_cache_key(job, job->current_page);
|
||||||
if (key && get_cache_ttl_search() > 0)
|
if (key && get_cache_ttl_search() > 0)
|
||||||
cache_set(key, job->response.memory, job->response.size);
|
cache_set(key, job->response.memory, job->response.size);
|
||||||
free(key);
|
free(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanup_job_handle(ScrapeJob *job, CURL *handle) {
|
static void cleanup_job_results(ScrapeJob *job) {
|
||||||
|
if (!job || !job->out_results)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xml_result_free(*job->out_results, job->results_count);
|
||||||
|
*job->out_results = NULL;
|
||||||
|
job->results_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cleanup_job_handle(ScrapeJob *job, CURL *handle) {
|
||||||
struct curl_slist *headers = NULL;
|
struct curl_slist *headers = NULL;
|
||||||
curl_easy_getinfo(handle, CURLINFO_PRIVATE, &headers);
|
if (handle)
|
||||||
|
curl_easy_getinfo(handle, CURLINFO_PRIVATE, &headers);
|
||||||
if (headers)
|
if (headers)
|
||||||
curl_slist_free_all(headers);
|
curl_slist_free_all(headers);
|
||||||
|
|
||||||
free(job->response.memory);
|
free(job->response.memory);
|
||||||
job->response.memory = NULL;
|
job->response.memory = NULL;
|
||||||
|
job->response.size = 0;
|
||||||
|
job->response.capacity = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_response(ScrapeJob *job, CURL *handle, CURLMsg *msg) {
|
static int process_response(ScrapeJob *job, CURL *handle, CURLcode result) {
|
||||||
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &job->http_status);
|
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &job->http_status);
|
||||||
|
|
||||||
if (msg->data.result == CURLE_OK)
|
if (result == CURLE_OK)
|
||||||
parse_and_cache_response(job);
|
parse_and_cache_response(job);
|
||||||
else {
|
else {
|
||||||
job->results_count = 0;
|
job->results_count = 0;
|
||||||
job->status = SCRAPE_STATUS_FETCH_ERROR;
|
job->status = SCRAPE_STATUS_FETCH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_ddg_job(job) && job->current_page < job->page &&
|
||||||
|
(job->status == SCRAPE_STATUS_OK || job->status == SCRAPE_STATUS_EMPTY)) {
|
||||||
|
char *data = build_ddg_next_page_data(job->response.memory,
|
||||||
|
job->response.size);
|
||||||
|
cleanup_job_results(job);
|
||||||
|
if (data) {
|
||||||
|
CURLcode code = curl_easy_setopt(handle, CURLOPT_COPYPOSTFIELDS, data);
|
||||||
|
free(data);
|
||||||
|
if (code == CURLE_OK) {
|
||||||
|
job->current_page++;
|
||||||
|
job->response.size = 0;
|
||||||
|
job->response.memory[0] = '\0';
|
||||||
|
job->http_status = 0;
|
||||||
|
job->status = SCRAPE_STATUS_PENDING;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
job->status = SCRAPE_STATUS_FETCH_ERROR;
|
||||||
|
} else {
|
||||||
|
job->status = SCRAPE_STATUS_EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cleanup_job_handle(job, handle);
|
cleanup_job_handle(job, handle);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int setup_job(ScrapeJob *job, CURLM *multi_handle) {
|
int setup_job(ScrapeJob *job, CURLM *multi_handle) {
|
||||||
|
cleanup_job_handle(job, job->handle);
|
||||||
if (job->handle)
|
if (job->handle)
|
||||||
curl_easy_cleanup(job->handle);
|
curl_easy_cleanup(job->handle);
|
||||||
if (job->response.memory)
|
job->handle = NULL;
|
||||||
free(job->response.memory);
|
|
||||||
|
|
||||||
job->results_count = 0;
|
cleanup_job_results(job);
|
||||||
job->http_status = 0;
|
job->http_status = 0;
|
||||||
job->status = SCRAPE_STATUS_PENDING;
|
job->status = SCRAPE_STATUS_PENDING;
|
||||||
|
job->current_page = job->page;
|
||||||
|
|
||||||
if (check_cache_for_job(job)) {
|
if (check_cache_for_job(job))
|
||||||
job->results_count = job->results_count > 0 ? job->results_count : 0;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
cleanup_job_results(job);
|
||||||
|
|
||||||
char *encoded_query = curl_easy_escape(NULL, job->query, 0);
|
char *encoded_query = curl_easy_escape(NULL, job->query, 0);
|
||||||
if (!encoded_query) {
|
if (!encoded_query) {
|
||||||
@@ -200,44 +325,52 @@ int setup_job(ScrapeJob *job, CURLM *multi_handle) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (char *p = encoded_query + strlen(encoded_query) - 3; p >= encoded_query; p--) {
|
char *read = encoded_query;
|
||||||
if (p[0] == '%' && p[1] == '2' && p[2] == '0') {
|
char *write = encoded_query;
|
||||||
*p = '+';
|
while (*read) {
|
||||||
memmove(p + 1, p + 3, strlen(p + 3) + 1);
|
if (read[0] == '%' && read[1] == '2' && read[2] == '0') {
|
||||||
|
*write++ = '+';
|
||||||
|
read += 3;
|
||||||
|
} else {
|
||||||
|
*write++ = *read++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*write = '\0';
|
||||||
|
|
||||||
char *full_url =
|
char *full_url =
|
||||||
build_search_url(job->engine->base_url, job->engine->page_param,
|
build_search_url(job->engine->base_url, job->engine->page_param,
|
||||||
job->engine->page_multiplier, job->engine->page_base,
|
job->engine->page_multiplier, job->engine->page_base,
|
||||||
encoded_query, job->page);
|
encoded_query, job->page);
|
||||||
free(encoded_query);
|
int ready = full_url &&
|
||||||
|
configure_job_request(job, full_url, encoded_query) == 0;
|
||||||
if (!full_url) {
|
|
||||||
job->status = SCRAPE_STATUS_FETCH_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
job->handle = curl_easy_init();
|
|
||||||
if (!job->handle) {
|
|
||||||
free(full_url);
|
|
||||||
job->status = SCRAPE_STATUS_FETCH_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
job->response.memory = (char *)malloc(INITIAL_BUFFER_SIZE);
|
|
||||||
job->response.size = 0;
|
|
||||||
job->response.capacity = INITIAL_BUFFER_SIZE;
|
|
||||||
|
|
||||||
struct curl_slist *headers =
|
|
||||||
build_request_headers(job->engine->host_header, job->engine->referer);
|
|
||||||
|
|
||||||
configure_curl_handle(job->handle, full_url, &job->response, headers);
|
|
||||||
curl_easy_setopt(job->handle, CURLOPT_PRIVATE, headers);
|
|
||||||
|
|
||||||
free(full_url);
|
free(full_url);
|
||||||
curl_multi_add_handle(multi_handle, job->handle);
|
curl_free(encoded_query);
|
||||||
return 0;
|
if (ready && curl_multi_add_handle(multi_handle, job->handle) == CURLM_OK)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
cleanup_job_handle(job, job->handle);
|
||||||
|
if (job->handle)
|
||||||
|
curl_easy_cleanup(job->handle);
|
||||||
|
job->handle = NULL;
|
||||||
|
job->status = SCRAPE_STATUS_FETCH_ERROR;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cleanup_unfinished_jobs(CURLM *multi_handle, ScrapeJob *jobs,
|
||||||
|
int num_jobs) {
|
||||||
|
for (int i = 0; i < num_jobs; i++) {
|
||||||
|
if (!jobs[i].handle)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
curl_multi_remove_handle(multi_handle, jobs[i].handle);
|
||||||
|
cleanup_job_handle(&jobs[i], jobs[i].handle);
|
||||||
|
curl_easy_cleanup(jobs[i].handle);
|
||||||
|
jobs[i].handle = NULL;
|
||||||
|
|
||||||
|
if (jobs[i].status == SCRAPE_STATUS_PENDING)
|
||||||
|
jobs[i].status = SCRAPE_STATUS_FETCH_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int handle_responses(CURLM *multi_handle, ScrapeJob *jobs, int num_jobs) {
|
int handle_responses(CURLM *multi_handle, ScrapeJob *jobs, int num_jobs) {
|
||||||
@@ -252,8 +385,14 @@ int handle_responses(CURLM *multi_handle, ScrapeJob *jobs, int num_jobs) {
|
|||||||
|
|
||||||
for (int i = 0; i < num_jobs; i++) {
|
for (int i = 0; i < num_jobs; i++) {
|
||||||
if (jobs[i].handle && jobs[i].handle == handle) {
|
if (jobs[i].handle && jobs[i].handle == handle) {
|
||||||
process_response(&jobs[i], handle, msg);
|
CURLcode result = msg->data.result;
|
||||||
curl_multi_remove_handle(multi_handle, handle);
|
curl_multi_remove_handle(multi_handle, handle);
|
||||||
|
if (process_response(&jobs[i], handle, result)) {
|
||||||
|
if (curl_multi_add_handle(multi_handle, handle) == CURLM_OK)
|
||||||
|
break;
|
||||||
|
jobs[i].status = SCRAPE_STATUS_FETCH_ERROR;
|
||||||
|
cleanup_job_handle(&jobs[i], handle);
|
||||||
|
}
|
||||||
curl_easy_cleanup(handle);
|
curl_easy_cleanup(handle);
|
||||||
jobs[i].handle = NULL;
|
jobs[i].handle = NULL;
|
||||||
break;
|
break;
|
||||||
@@ -279,34 +418,37 @@ int should_retry(ScrapeJob *jobs, int num_jobs) {
|
|||||||
int scrape_engines_parallel(ScrapeJob *jobs, int num_jobs) {
|
int scrape_engines_parallel(ScrapeJob *jobs, int num_jobs) {
|
||||||
int retries = 0;
|
int retries = 0;
|
||||||
|
|
||||||
retry:
|
retry:;
|
||||||
;
|
|
||||||
CURLM *multi_handle = curl_multi_init();
|
CURLM *multi_handle = curl_multi_init();
|
||||||
if (!multi_handle)
|
if (!multi_handle)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (int i = 0; i < num_jobs; i++) {
|
for (int i = 0; i < num_jobs; i++) {
|
||||||
if (setup_job(&jobs[i], multi_handle) != 0 && jobs[i].handle) {
|
setup_job(&jobs[i], multi_handle);
|
||||||
curl_multi_remove_handle(multi_handle, jobs[i].handle);
|
|
||||||
curl_easy_cleanup(jobs[i].handle);
|
|
||||||
jobs[i].handle = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
http_delay();
|
http_delay();
|
||||||
|
|
||||||
int still_running = 0;
|
while (1) {
|
||||||
curl_multi_perform(multi_handle, &still_running);
|
int still_running = 0;
|
||||||
|
CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
|
||||||
do {
|
handle_responses(multi_handle, jobs, num_jobs);
|
||||||
int numfds = 0;
|
|
||||||
CURLMcode mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
|
|
||||||
if (mc != CURLM_OK)
|
if (mc != CURLM_OK)
|
||||||
break;
|
break;
|
||||||
curl_multi_perform(multi_handle, &still_running);
|
|
||||||
} while (still_running);
|
|
||||||
|
|
||||||
handle_responses(multi_handle, jobs, num_jobs);
|
int active = 0;
|
||||||
|
for (int i = 0; i < num_jobs; i++)
|
||||||
|
active += jobs[i].handle != NULL;
|
||||||
|
if (!active)
|
||||||
|
break;
|
||||||
|
|
||||||
|
int numfds = 0;
|
||||||
|
mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
|
||||||
|
if (mc != CURLM_OK)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup_unfinished_jobs(multi_handle, jobs, num_jobs);
|
||||||
curl_multi_cleanup(multi_handle);
|
curl_multi_cleanup(multi_handle);
|
||||||
|
|
||||||
if (retries < max_proxy_retries && should_retry(jobs, num_jobs)) {
|
if (retries < max_proxy_retries && should_retry(jobs, num_jobs)) {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ typedef struct {
|
|||||||
int page_base;
|
int page_base;
|
||||||
ParserFunc parser;
|
ParserFunc parser;
|
||||||
int enabled;
|
int enabled;
|
||||||
|
int is_xml;
|
||||||
} SearchEngine;
|
} SearchEngine;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -49,6 +50,7 @@ typedef struct {
|
|||||||
SearchResult **out_results;
|
SearchResult **out_results;
|
||||||
int max_results;
|
int max_results;
|
||||||
int page;
|
int page;
|
||||||
|
int current_page;
|
||||||
CURL *handle;
|
CURL *handle;
|
||||||
MemoryBuffer response;
|
MemoryBuffer response;
|
||||||
int results_count;
|
int results_count;
|
||||||
@@ -59,15 +61,18 @@ typedef struct {
|
|||||||
extern SearchEngine ENGINE_REGISTRY[];
|
extern SearchEngine ENGINE_REGISTRY[];
|
||||||
extern const int ENGINE_COUNT;
|
extern const int ENGINE_COUNT;
|
||||||
void apply_engines_config(const char *engines_str);
|
void apply_engines_config(const char *engines_str);
|
||||||
|
void configure_yacy_engine(const char *instance);
|
||||||
|
|
||||||
size_t write_memory_callback(void *contents, size_t size, size_t nmemb,
|
size_t write_memory_callback(void *contents, size_t size, size_t nmemb,
|
||||||
void *userp);
|
void *userp);
|
||||||
const char *get_random_user_agent(void);
|
const char *get_random_user_agent(void);
|
||||||
|
const char *get_first_user_agent(void);
|
||||||
void configure_curl_handle(CURL *curl, const char *full_url,
|
void configure_curl_handle(CURL *curl, const char *full_url,
|
||||||
MemoryBuffer *chunk, struct curl_slist *headers);
|
MemoryBuffer *chunk, struct curl_slist *headers);
|
||||||
char *build_search_url(const char *base_url, const char *page_param,
|
char *build_search_url(const char *base_url, const char *page_param,
|
||||||
int page_multiplier, int page_base,
|
int page_multiplier, int page_base,
|
||||||
const char *encoded_query, int page);
|
const char *encoded_query, int page);
|
||||||
|
char *build_ddg_next_page_data(const char *html, size_t size);
|
||||||
struct curl_slist *build_request_headers(const char *host_header,
|
struct curl_slist *build_request_headers(const char *host_header,
|
||||||
const char *referer);
|
const char *referer);
|
||||||
void http_delay(void);
|
void http_delay(void);
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ const char *get_random_user_agent(void) {
|
|||||||
return USER_AGENTS[rand() % USER_AGENT_COUNT];
|
return USER_AGENTS[rand() % USER_AGENT_COUNT];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *get_first_user_agent(void) { return USER_AGENTS[0]; }
|
||||||
|
|
||||||
void configure_curl_handle(CURL *curl, const char *full_url,
|
void configure_curl_handle(CURL *curl, const char *full_url,
|
||||||
MemoryBuffer *chunk, struct curl_slist *headers) {
|
MemoryBuffer *chunk, struct curl_slist *headers) {
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, full_url);
|
curl_easy_setopt(curl, CURLOPT_URL, full_url);
|
||||||
@@ -75,25 +77,92 @@ void configure_curl_handle(CURL *curl, const char *full_url,
|
|||||||
char *build_search_url(const char *base_url, const char *page_param,
|
char *build_search_url(const char *base_url, const char *page_param,
|
||||||
int page_multiplier, int page_base,
|
int page_multiplier, int page_base,
|
||||||
const char *encoded_query, int page) {
|
const char *encoded_query, int page) {
|
||||||
int page_value = (page < 1 ? 1 : page - 1) * page_multiplier + page_base;
|
long long page_value =
|
||||||
|
(long long)(page > 1 ? page - 1 : 0) * page_multiplier + page_base;
|
||||||
char *url = malloc(BUFFER_SIZE_LARGE);
|
char *url = malloc(BUFFER_SIZE_LARGE);
|
||||||
if (!url)
|
if (!url)
|
||||||
return NULL;
|
return NULL;
|
||||||
snprintf(url, BUFFER_SIZE_LARGE, "%s%s&%s=%d", base_url, encoded_query,
|
snprintf(url, BUFFER_SIZE_LARGE, "%s%s&%s=%lld", base_url, encoded_query,
|
||||||
page_param, page_value);
|
page_param, page_value);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *build_ddg_next_page_data(const char *html, size_t size) {
|
||||||
|
htmlDocPtr doc = htmlReadMemory(html, size, NULL, NULL,
|
||||||
|
HTML_PARSE_RECOVER | HTML_PARSE_NOERROR |
|
||||||
|
HTML_PARSE_NOWARNING);
|
||||||
|
if (!doc)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
xmlXPathContextPtr ctx = create_xpath_context(doc);
|
||||||
|
if (!ctx) {
|
||||||
|
xmlFreeDoc(doc);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlXPathObjectPtr inputs = xmlXPathEvalExpression(
|
||||||
|
(const xmlChar *)"(//form[.//input[@name='s'] and "
|
||||||
|
".//input[@name='vqd' and string-length(@value)>0] and "
|
||||||
|
"(.//input[@type='submit' and contains(@value, 'Next')] or "
|
||||||
|
".//button[contains(., 'Next')])])[1]"
|
||||||
|
"//input[@name and not(@disabled) and "
|
||||||
|
"(not(@type) or @type='hidden')]",
|
||||||
|
ctx);
|
||||||
|
|
||||||
|
if (!inputs || !inputs->nodesetval) {
|
||||||
|
free_xpath_objects(ctx, inputs);
|
||||||
|
xmlFreeDoc(doc);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *data = NULL;
|
||||||
|
size_t length = 0;
|
||||||
|
int failed = 0;
|
||||||
|
for (int i = 0; i < inputs->nodesetval->nodeNr; i++) {
|
||||||
|
xmlNodePtr node = inputs->nodesetval->nodeTab[i];
|
||||||
|
xmlChar *name = xmlGetProp(node, (const xmlChar *)"name");
|
||||||
|
xmlChar *value = xmlGetProp(node, (const xmlChar *)"value");
|
||||||
|
char *key = curl_easy_escape(NULL, (const char *)name, 0);
|
||||||
|
char *val = curl_easy_escape(NULL, value ? (const char *)value : "", 0);
|
||||||
|
size_t needed = key && val ? strlen(key) + strlen(val) + 2 : 0;
|
||||||
|
char *expanded = needed ? realloc(data, length + needed + 1) : NULL;
|
||||||
|
if (expanded) {
|
||||||
|
data = expanded;
|
||||||
|
length += snprintf(data + length, needed + 1, "%s%s=%s",
|
||||||
|
length ? "&" : "", key, val);
|
||||||
|
} else {
|
||||||
|
failed = 1;
|
||||||
|
}
|
||||||
|
curl_free(key);
|
||||||
|
curl_free(val);
|
||||||
|
xmlFree(name);
|
||||||
|
xmlFree(value);
|
||||||
|
if (failed)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failed) {
|
||||||
|
free(data);
|
||||||
|
data = NULL;
|
||||||
|
}
|
||||||
|
free_xpath_objects(ctx, inputs);
|
||||||
|
xmlFreeDoc(doc);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
struct curl_slist *build_request_headers(const char *host_header,
|
struct curl_slist *build_request_headers(const char *host_header,
|
||||||
const char *referer) {
|
const char *referer) {
|
||||||
struct curl_slist *headers = NULL;
|
struct curl_slist *headers = NULL;
|
||||||
char host_buf[BUFFER_SIZE_MEDIUM], ref_buf[BUFFER_SIZE_MEDIUM];
|
char host_buf[BUFFER_SIZE_MEDIUM], ref_buf[BUFFER_SIZE_MEDIUM];
|
||||||
|
|
||||||
snprintf(host_buf, sizeof(host_buf), "Host: %s", host_header);
|
if (host_header && host_header[0] != '\0') {
|
||||||
snprintf(ref_buf, sizeof(ref_buf), "Referer: %s", referer);
|
snprintf(host_buf, sizeof(host_buf), "Host: %s", host_header);
|
||||||
|
headers = curl_slist_append(headers, host_buf);
|
||||||
headers = curl_slist_append(headers, host_buf);
|
}
|
||||||
headers = curl_slist_append(headers, ref_buf);
|
if (referer && referer[0] != '\0') {
|
||||||
|
snprintf(ref_buf, sizeof(ref_buf), "Referer: %s", referer);
|
||||||
|
headers = curl_slist_append(headers, ref_buf);
|
||||||
|
}
|
||||||
headers = curl_slist_append(
|
headers = curl_slist_append(
|
||||||
headers,
|
headers,
|
||||||
"Accept: "
|
"Accept: "
|
||||||
|
|||||||
@@ -249,8 +249,8 @@ static int parse_mojeek(const char *engine_name, xmlDocPtr doc,
|
|||||||
if (!ctx)
|
if (!ctx)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
xmlXPathObjectPtr obj =
|
xmlXPathObjectPtr obj = xml_xpath_eval(
|
||||||
xml_xpath_eval(ctx, "//ul[@class='results-standard']/li[starts-with(@class, 'r')]");
|
ctx, "//ul[@class='results-standard']/li[starts-with(@class, 'r')]");
|
||||||
|
|
||||||
if (!obj || !obj->nodesetval || obj->nodesetval->nodeNr == 0) {
|
if (!obj || !obj->nodesetval || obj->nodesetval->nodeNr == 0) {
|
||||||
free_xpath_objects(ctx, obj);
|
free_xpath_objects(ctx, obj);
|
||||||
@@ -268,18 +268,17 @@ static int parse_mojeek(const char *engine_name, xmlDocPtr doc,
|
|||||||
xmlNodePtr result_node = obj->nodesetval->nodeTab[i];
|
xmlNodePtr result_node = obj->nodesetval->nodeTab[i];
|
||||||
ctx->node = result_node;
|
ctx->node = result_node;
|
||||||
|
|
||||||
xmlXPathObjectPtr link_obj =
|
xmlXPathObjectPtr link_obj = xml_xpath_eval(ctx, ".//a[@class='title']");
|
||||||
xml_xpath_eval(ctx, ".//a[@class='title']");
|
|
||||||
char *url =
|
char *url =
|
||||||
(link_obj && link_obj->nodesetval && link_obj->nodesetval->nodeNr > 0)
|
(link_obj && link_obj->nodesetval && link_obj->nodesetval->nodeNr > 0)
|
||||||
? (char *)xmlGetProp(link_obj->nodesetval->nodeTab[0],
|
? (char *)xmlGetProp(link_obj->nodesetval->nodeTab[0],
|
||||||
(xmlChar *)"href")
|
(xmlChar *)"href")
|
||||||
: NULL;
|
: NULL;
|
||||||
|
|
||||||
char *title = (link_obj && link_obj->nodesetval &&
|
char *title =
|
||||||
link_obj->nodesetval->nodeNr > 0)
|
(link_obj && link_obj->nodesetval && link_obj->nodesetval->nodeNr > 0)
|
||||||
? xml_node_content(link_obj->nodesetval->nodeTab[0])
|
? xml_node_content(link_obj->nodesetval->nodeTab[0])
|
||||||
: NULL;
|
: NULL;
|
||||||
|
|
||||||
xmlXPathObjectPtr snippet_obj = xml_xpath_eval(ctx, ".//p[@class='s']");
|
xmlXPathObjectPtr snippet_obj = xml_xpath_eval(ctx, ".//p[@class='s']");
|
||||||
char *snippet_text =
|
char *snippet_text =
|
||||||
@@ -310,6 +309,90 @@ static int parse_yahoo(const char *engine_name, xmlDocPtr doc,
|
|||||||
static int parse_mojeek(const char *engine_name, xmlDocPtr doc,
|
static int parse_mojeek(const char *engine_name, xmlDocPtr doc,
|
||||||
SearchResult **out_results, int max_results);
|
SearchResult **out_results, int max_results);
|
||||||
|
|
||||||
|
static int parse_yacy(const char *engine_name, xmlDocPtr doc,
|
||||||
|
SearchResult **out_results, int max_results) {
|
||||||
|
(void)engine_name;
|
||||||
|
int found_count = 0;
|
||||||
|
|
||||||
|
xmlXPathContextPtr ctx = create_xpath_context(doc);
|
||||||
|
if (!ctx)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
xmlXPathObjectPtr obj = xml_xpath_eval(ctx, "//item");
|
||||||
|
|
||||||
|
if (!obj || !obj->nodesetval || obj->nodesetval->nodeNr == 0) {
|
||||||
|
free_xpath_objects(ctx, obj);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int num_items = obj->nodesetval->nodeNr;
|
||||||
|
*out_results = alloc_results_array(num_items, max_results);
|
||||||
|
if (!*out_results) {
|
||||||
|
free_xpath_objects(ctx, obj);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < num_items && found_count < max_results; i++) {
|
||||||
|
xmlNodePtr item_node = obj->nodesetval->nodeTab[i];
|
||||||
|
ctx->node = item_node;
|
||||||
|
|
||||||
|
xmlXPathObjectPtr title_obj = xml_xpath_eval(ctx, "./title");
|
||||||
|
char *title = (title_obj && title_obj->nodesetval &&
|
||||||
|
title_obj->nodesetval->nodeNr > 0)
|
||||||
|
? xml_node_content(title_obj->nodesetval->nodeTab[0])
|
||||||
|
: NULL;
|
||||||
|
|
||||||
|
xmlXPathObjectPtr link_obj = xml_xpath_eval(ctx, "./link");
|
||||||
|
char *url =
|
||||||
|
(link_obj && link_obj->nodesetval && link_obj->nodesetval->nodeNr > 0)
|
||||||
|
? xml_node_content(link_obj->nodesetval->nodeTab[0])
|
||||||
|
: NULL;
|
||||||
|
|
||||||
|
xmlXPathObjectPtr desc_obj = xml_xpath_eval(ctx, "./description");
|
||||||
|
char *snippet_text =
|
||||||
|
(desc_obj && desc_obj->nodesetval && desc_obj->nodesetval->nodeNr > 0)
|
||||||
|
? xml_node_content(desc_obj->nodesetval->nodeTab[0])
|
||||||
|
: NULL;
|
||||||
|
|
||||||
|
if (url && title) {
|
||||||
|
assign_result(&(*out_results)[found_count], url, title, snippet_text, 0);
|
||||||
|
found_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
free_xml_node_list(title, url, snippet_text);
|
||||||
|
if (title_obj)
|
||||||
|
xmlXPathFreeObject(title_obj);
|
||||||
|
if (link_obj)
|
||||||
|
xmlXPathFreeObject(link_obj);
|
||||||
|
if (desc_obj)
|
||||||
|
xmlXPathFreeObject(desc_obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->node = NULL;
|
||||||
|
free_xpath_objects(ctx, obj);
|
||||||
|
return found_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char yacy_base_url[BUFFER_SIZE_LARGE];
|
||||||
|
|
||||||
|
void configure_yacy_engine(const char *instance) {
|
||||||
|
if (!instance || instance[0] == '\0')
|
||||||
|
instance = DEFAULT_YACY_INSTANCE;
|
||||||
|
|
||||||
|
snprintf(yacy_base_url, sizeof(yacy_base_url),
|
||||||
|
"%s/"
|
||||||
|
"yacysearch.rss?resource=global&urlmaskfilter=.*&prefermaskfilter=&"
|
||||||
|
"nav=all&maximumRecords=%d&query=",
|
||||||
|
instance, MAX_RESULTS_PER_ENGINE);
|
||||||
|
|
||||||
|
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||||
|
if (strcmp(ENGINE_REGISTRY[i].id, "yacy") == 0) {
|
||||||
|
ENGINE_REGISTRY[i].base_url = yacy_base_url;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SearchEngine ENGINE_REGISTRY[] = {
|
SearchEngine ENGINE_REGISTRY[] = {
|
||||||
{.id = "ddg",
|
{.id = "ddg",
|
||||||
.name = "DuckDuckGo Lite",
|
.name = "DuckDuckGo Lite",
|
||||||
@@ -350,7 +433,18 @@ SearchEngine ENGINE_REGISTRY[] = {
|
|||||||
.page_multiplier = 10,
|
.page_multiplier = 10,
|
||||||
.page_base = 1,
|
.page_base = 1,
|
||||||
.parser = parse_mojeek,
|
.parser = parse_mojeek,
|
||||||
.enabled = 1}};
|
.enabled = 1},
|
||||||
|
{.id = "yacy",
|
||||||
|
.name = "YaCy",
|
||||||
|
.base_url = "",
|
||||||
|
.host_header = NULL,
|
||||||
|
.referer = NULL,
|
||||||
|
.page_param = "startRecord",
|
||||||
|
.page_multiplier = 10,
|
||||||
|
.page_base = 0,
|
||||||
|
.parser = parse_yacy,
|
||||||
|
.enabled = 0,
|
||||||
|
.is_xml = 1}};
|
||||||
|
|
||||||
const int ENGINE_COUNT = sizeof(ENGINE_REGISTRY) / sizeof(SearchEngine);
|
const int ENGINE_COUNT = sizeof(ENGINE_REGISTRY) / sizeof(SearchEngine);
|
||||||
|
|
||||||
@@ -373,6 +467,8 @@ static int engine_id_compare(const char *engine_id, const char *config_id) {
|
|||||||
void apply_engines_config(const char *engines_str) {
|
void apply_engines_config(const char *engines_str) {
|
||||||
if (!engines_str || engines_str[0] == '\0') {
|
if (!engines_str || engines_str[0] == '\0') {
|
||||||
for (int i = 0; i < ENGINE_COUNT; i++) {
|
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||||
|
if (engine_id_compare(ENGINE_REGISTRY[i].id, "yacy"))
|
||||||
|
continue;
|
||||||
ENGINE_REGISTRY[i].enabled = 1;
|
ENGINE_REGISTRY[i].enabled = 1;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -395,6 +491,8 @@ void apply_engines_config(const char *engines_str) {
|
|||||||
|
|
||||||
if (strcmp(token, "*") == 0) {
|
if (strcmp(token, "*") == 0) {
|
||||||
for (int i = 0; i < ENGINE_COUNT; i++) {
|
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||||
|
if (engine_id_compare(ENGINE_REGISTRY[i].id, "yacy"))
|
||||||
|
continue;
|
||||||
ENGINE_REGISTRY[i].enabled = 1;
|
ENGINE_REGISTRY[i].enabled = 1;
|
||||||
}
|
}
|
||||||
} else if (token[0] == '-' && token[1] != '\0') {
|
} else if (token[0] == '-' && token[1] != '\0') {
|
||||||
|
|||||||
@@ -3,6 +3,143 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
static unsigned int hexval(char c) {
|
||||||
|
if (c >= '0' && c <= '9')
|
||||||
|
return c - '0';
|
||||||
|
if (c >= 'a' && c <= 'f')
|
||||||
|
return c - 'a' + 10;
|
||||||
|
if (c >= 'A' && c <= 'F')
|
||||||
|
return c - 'A' + 10;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned int hex4(const char *s) {
|
||||||
|
return (hexval(s[0]) << 12) | (hexval(s[1]) << 8) | (hexval(s[2]) << 4) |
|
||||||
|
hexval(s[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t utf8_len(unsigned int cp) {
|
||||||
|
if (cp < 0x80)
|
||||||
|
return 1;
|
||||||
|
if (cp < 0x800)
|
||||||
|
return 2;
|
||||||
|
if (cp < 0x10000)
|
||||||
|
return 3;
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void utf8_write(char *buf, size_t *i, unsigned int cp) {
|
||||||
|
if (cp < 0x80) {
|
||||||
|
buf[(*i)++] = (char)cp;
|
||||||
|
} else if (cp < 0x800) {
|
||||||
|
buf[(*i)++] = (char)(0xC0 | (cp >> 6));
|
||||||
|
buf[(*i)++] = (char)(0x80 | (cp & 0x3F));
|
||||||
|
} else if (cp < 0x10000) {
|
||||||
|
buf[(*i)++] = (char)(0xE0 | (cp >> 12));
|
||||||
|
buf[(*i)++] = (char)(0x80 | ((cp >> 6) & 0x3F));
|
||||||
|
buf[(*i)++] = (char)(0x80 | (cp & 0x3F));
|
||||||
|
} else {
|
||||||
|
buf[(*i)++] = (char)(0xF0 | (cp >> 18));
|
||||||
|
buf[(*i)++] = (char)(0x80 | ((cp >> 12) & 0x3F));
|
||||||
|
buf[(*i)++] = (char)(0x80 | ((cp >> 6) & 0x3F));
|
||||||
|
buf[(*i)++] = (char)(0x80 | (cp & 0x3F));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *json_string_unescape(const char *s, const char *end) {
|
||||||
|
if (!s || !end || end < s)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
size_t len = 0;
|
||||||
|
const char *p = s;
|
||||||
|
while (p < end) {
|
||||||
|
if (*p == '\\' && p + 1 < end) {
|
||||||
|
if (p[1] == 'u' && p + 5 < end) {
|
||||||
|
unsigned int cp = hex4(p + 2);
|
||||||
|
if (cp >= 0xD800 && cp <= 0xDBFF && p + 11 < end && p[6] == '\\' &&
|
||||||
|
p[7] == 'u') {
|
||||||
|
unsigned int cp2 = hex4(p + 8);
|
||||||
|
if (cp2 >= 0xDC00 && cp2 <= 0xDFFF) {
|
||||||
|
len += 4;
|
||||||
|
p += 12;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
len += utf8_len(cp);
|
||||||
|
p += 6;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
len += 1;
|
||||||
|
p += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
len += 1;
|
||||||
|
p += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *out = malloc(len + 1);
|
||||||
|
if (!out)
|
||||||
|
return NULL;
|
||||||
|
size_t i = 0;
|
||||||
|
p = s;
|
||||||
|
while (p < end) {
|
||||||
|
if (*p == '\\' && p + 1 < end) {
|
||||||
|
if (p[1] == 'u' && p + 5 < end) {
|
||||||
|
unsigned int cp = hex4(p + 2);
|
||||||
|
if (cp >= 0xD800 && cp <= 0xDBFF && p + 11 < end && p[6] == '\\' &&
|
||||||
|
p[7] == 'u') {
|
||||||
|
unsigned int cp2 = hex4(p + 8);
|
||||||
|
if (cp2 >= 0xDC00 && cp2 <= 0xDFFF) {
|
||||||
|
utf8_write(out, &i,
|
||||||
|
0x10000 + ((cp - 0xD800) << 10) + (cp2 - 0xDC00));
|
||||||
|
p += 12;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cp < 0xD800 || cp > 0xDFFF)
|
||||||
|
utf8_write(out, &i, cp);
|
||||||
|
p += 6;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (p[1] == 'n') {
|
||||||
|
out[i++] = '\n';
|
||||||
|
p += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (p[1] == 'r') {
|
||||||
|
out[i++] = '\r';
|
||||||
|
p += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (p[1] == 't') {
|
||||||
|
out[i++] = '\t';
|
||||||
|
p += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (p[1] == 'b') {
|
||||||
|
out[i++] = '\b';
|
||||||
|
p += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (p[1] == 'f') {
|
||||||
|
out[i++] = '\f';
|
||||||
|
p += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (p[1] == '"' || p[1] == '\\' || p[1] == '/') {
|
||||||
|
out[i++] = p[1];
|
||||||
|
p += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
p += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
out[i++] = *p++;
|
||||||
|
}
|
||||||
|
out[i] = '\0';
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
char *unescape_search_url(const char *input) {
|
char *unescape_search_url(const char *input) {
|
||||||
if (!input)
|
if (!input)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -5,5 +5,6 @@
|
|||||||
|
|
||||||
char *unescape_search_url(const char *input);
|
char *unescape_search_url(const char *input);
|
||||||
char *url_decode_query(const char *src);
|
char *url_decode_query(const char *src);
|
||||||
|
char *json_string_unescape(const char *s, const char *end);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ static int themes_initialized = 0;
|
|||||||
void init_themes(const char *static_path) {
|
void init_themes(const char *static_path) {
|
||||||
if (themes_initialized)
|
if (themes_initialized)
|
||||||
return;
|
return;
|
||||||
themes_initialized = 1;
|
|
||||||
|
|
||||||
char themes_dir[512];
|
char themes_dir[512];
|
||||||
snprintf(themes_dir, sizeof(themes_dir), "%s/themes", static_path);
|
snprintf(themes_dir, sizeof(themes_dir), "%s/themes", static_path);
|
||||||
@@ -26,20 +25,32 @@ void init_themes(const char *static_path) {
|
|||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
int capacity = 4;
|
int capacity = 4;
|
||||||
themes_list = malloc(sizeof(char *) * capacity);
|
themes_list = malloc(sizeof(char *) * capacity);
|
||||||
|
if (!themes_list) {
|
||||||
|
closedir(dir);
|
||||||
|
return;
|
||||||
|
}
|
||||||
themes_count = 0;
|
themes_count = 0;
|
||||||
|
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
size_t len = strlen(entry->d_name);
|
size_t len = strlen(entry->d_name);
|
||||||
if (len > 4 && strcmp(entry->d_name + len - 4, ".css") == 0) {
|
if (len > 4 && strcmp(entry->d_name + len - 4, ".css") == 0) {
|
||||||
if (themes_count >= capacity) {
|
if (themes_count >= capacity) {
|
||||||
capacity *= 2;
|
int new_capacity = capacity * 2;
|
||||||
themes_list = realloc(themes_list, sizeof(char *) * capacity);
|
char **new_list = realloc(themes_list, sizeof(char *) * new_capacity);
|
||||||
|
if (!new_list)
|
||||||
|
break;
|
||||||
|
themes_list = new_list;
|
||||||
|
capacity = new_capacity;
|
||||||
}
|
}
|
||||||
themes_list[themes_count] = strndup(entry->d_name, len - 4);
|
char *theme = strndup(entry->d_name, len - 4);
|
||||||
|
if (!theme)
|
||||||
|
break;
|
||||||
|
themes_list[themes_count] = theme;
|
||||||
themes_count++;
|
themes_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
themes_initialized = 1;
|
||||||
|
|
||||||
for (int i = 0; i < themes_count; i++) {
|
for (int i = 0; i < themes_count; i++) {
|
||||||
for (int j = i + 1; j < themes_count; j++) {
|
for (int j = i + 1; j < themes_count; j++) {
|
||||||
@@ -78,8 +89,8 @@ void get_available_themes(char ***out_themes, int *out_count) {
|
|||||||
|
|
||||||
void set_default_locale(const char *locale) {
|
void set_default_locale(const char *locale) {
|
||||||
if (locale && strlen(locale) > 0) {
|
if (locale && strlen(locale) > 0) {
|
||||||
strncpy(global_default_locale, locale, sizeof(global_default_locale) - 1);
|
snprintf(global_default_locale, sizeof(global_default_locale), "%s",
|
||||||
global_default_locale[sizeof(global_default_locale) - 1] = '\0';
|
locale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +177,7 @@ int get_user_engines(char ***out_ids, int *out_count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *saveptr;
|
char *saveptr;
|
||||||
char *token = strtok_r(copy, ",", &saveptr);
|
char *token = strtok_r(copy, "+", &saveptr);
|
||||||
while (token) {
|
while (token) {
|
||||||
while (*token == ' ' || *token == '\t')
|
while (*token == ' ' || *token == '\t')
|
||||||
token++;
|
token++;
|
||||||
@@ -180,9 +191,30 @@ int get_user_engines(char ***out_ids, int *out_count) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
token = strtok_r(NULL, ",", &saveptr);
|
token = strtok_r(NULL, "+", &saveptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count == 0) {
|
||||||
|
char *copy2 = strdup(cookie);
|
||||||
|
if (copy2) {
|
||||||
|
char *saveptr2 = NULL;
|
||||||
|
char *token2 = strtok_r(copy2, ",", &saveptr2);
|
||||||
|
while (token2) {
|
||||||
|
while (*token2 == ' ' || *token2 == '\t')
|
||||||
|
token2++;
|
||||||
|
if (token2[0] != '\0' && is_engine_id_enabled(token2)) {
|
||||||
|
char **new_ids = realloc(ids, sizeof(char *) * (count + 1));
|
||||||
|
if (new_ids) {
|
||||||
|
ids = new_ids;
|
||||||
|
ids[count] = strdup(token2);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
token2 = strtok_r(NULL, ",", &saveptr2);
|
||||||
|
}
|
||||||
|
free(copy2);
|
||||||
|
}
|
||||||
|
}
|
||||||
free(copy);
|
free(copy);
|
||||||
free(cookie);
|
free(cookie);
|
||||||
|
|
||||||
@@ -206,98 +238,130 @@ int user_engines_contains(const char *engine_id, char **ids, int count) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int add_link_to_collection(const char *href, const char *label,
|
char *get_default_search_engine(void) {
|
||||||
const char *class_name, char ****collection,
|
char *cookie = get_cookie("default_engine");
|
||||||
int **inner_counts, int current_count) {
|
if (cookie && (strcmp(cookie, "all") == 0 || is_engine_id_enabled(cookie)))
|
||||||
char ***old_collection = *collection;
|
return cookie;
|
||||||
int *old_inner_counts = *inner_counts;
|
|
||||||
char ***new_collection =
|
|
||||||
(char ***)malloc(sizeof(char **) * (current_count + 1));
|
|
||||||
int *new_inner_counts = (int *)malloc(sizeof(int) * (current_count + 1));
|
|
||||||
|
|
||||||
if (!new_collection || !new_inner_counts) {
|
free(cookie);
|
||||||
free(new_collection);
|
return strdup("all");
|
||||||
free(new_inner_counts);
|
|
||||||
return current_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*collection && current_count > 0) {
|
|
||||||
memcpy(new_collection, *collection, sizeof(char **) * current_count);
|
|
||||||
}
|
|
||||||
if (*inner_counts && current_count > 0) {
|
|
||||||
memcpy(new_inner_counts, *inner_counts, sizeof(int) * current_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
*collection = new_collection;
|
|
||||||
*inner_counts = new_inner_counts;
|
|
||||||
|
|
||||||
(*collection)[current_count] =
|
|
||||||
(char **)malloc(sizeof(char *) * LINK_FIELD_COUNT);
|
|
||||||
if (!(*collection)[current_count]) {
|
|
||||||
*collection = old_collection;
|
|
||||||
*inner_counts = old_inner_counts;
|
|
||||||
free(new_collection);
|
|
||||||
free(new_inner_counts);
|
|
||||||
return current_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*collection)[current_count][0] = strdup(href ? href : "");
|
|
||||||
(*collection)[current_count][1] = strdup(label ? label : "");
|
|
||||||
(*collection)[current_count][2] = strdup(class_name ? class_name : "");
|
|
||||||
|
|
||||||
if (!(*collection)[current_count][0] || !(*collection)[current_count][1] ||
|
|
||||||
!(*collection)[current_count][2]) {
|
|
||||||
free((*collection)[current_count][0]);
|
|
||||||
free((*collection)[current_count][1]);
|
|
||||||
free((*collection)[current_count][2]);
|
|
||||||
free((*collection)[current_count]);
|
|
||||||
*collection = old_collection;
|
|
||||||
*inner_counts = old_inner_counts;
|
|
||||||
free(new_collection);
|
|
||||||
free(new_inner_counts);
|
|
||||||
return current_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*inner_counts)[current_count] = LINK_FIELD_COUNT;
|
|
||||||
|
|
||||||
free(old_collection);
|
|
||||||
free(old_inner_counts);
|
|
||||||
return current_count + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int build_pagination(int page, char *(*href_builder)(int page, void *data),
|
void free_string_matrix(char ***matrix, int *inner_counts, int row_count) {
|
||||||
void *data, char ****out_matrix, int **out_inner_counts) {
|
if (matrix) {
|
||||||
|
for (int i = 0; i < row_count; i++) {
|
||||||
|
int field_count = inner_counts ? inner_counts[i] : 0;
|
||||||
|
for (int j = 0; j < field_count; j++)
|
||||||
|
free(matrix[i][j]);
|
||||||
|
free(matrix[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(matrix);
|
||||||
|
free(inner_counts);
|
||||||
|
}
|
||||||
|
|
||||||
|
void string_matrix_init(StringMatrix *matrix) {
|
||||||
|
if (matrix)
|
||||||
|
*matrix = (StringMatrix){0};
|
||||||
|
}
|
||||||
|
|
||||||
|
int string_matrix_append(StringMatrix *matrix, const char *const *values,
|
||||||
|
int field_count) {
|
||||||
|
if (!matrix || !values || field_count <= 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
char **row = calloc((size_t)field_count, sizeof(*row));
|
||||||
|
if (!row)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (int i = 0; i < field_count; i++) {
|
||||||
|
row[i] = strdup(values[i] ? values[i] : "");
|
||||||
|
if (!row[i]) {
|
||||||
|
for (int j = 0; j < i; j++)
|
||||||
|
free(row[j]);
|
||||||
|
free(row);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matrix->count == matrix->capacity) {
|
||||||
|
int new_capacity = matrix->capacity ? matrix->capacity * 2 : 8;
|
||||||
|
char ***new_rows = malloc(sizeof(*new_rows) * (size_t)new_capacity);
|
||||||
|
int *new_counts = malloc(sizeof(*new_counts) * (size_t)new_capacity);
|
||||||
|
if (!new_rows || !new_counts) {
|
||||||
|
free(new_rows);
|
||||||
|
free(new_counts);
|
||||||
|
for (int i = 0; i < field_count; i++)
|
||||||
|
free(row[i]);
|
||||||
|
free(row);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (matrix->count > 0) {
|
||||||
|
memcpy(new_rows, matrix->rows, sizeof(*new_rows) * matrix->count);
|
||||||
|
memcpy(new_counts, matrix->field_counts,
|
||||||
|
sizeof(*new_counts) * matrix->count);
|
||||||
|
}
|
||||||
|
free(matrix->rows);
|
||||||
|
free(matrix->field_counts);
|
||||||
|
matrix->rows = new_rows;
|
||||||
|
matrix->field_counts = new_counts;
|
||||||
|
matrix->capacity = new_capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix->rows[matrix->count] = row;
|
||||||
|
matrix->field_counts[matrix->count] = field_count;
|
||||||
|
matrix->count++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void string_matrix_free(StringMatrix *matrix) {
|
||||||
|
if (!matrix)
|
||||||
|
return;
|
||||||
|
free_string_matrix(matrix->rows, matrix->field_counts, matrix->count);
|
||||||
|
*matrix = (StringMatrix){0};
|
||||||
|
}
|
||||||
|
|
||||||
|
int string_matrix_build_pagination(int page,
|
||||||
|
char *(*href_builder)(int page, void *data),
|
||||||
|
void *data, StringMatrix *out_matrix) {
|
||||||
enum { PAGER_WINDOW_SIZE = 5 };
|
enum { PAGER_WINDOW_SIZE = 5 };
|
||||||
|
if (!out_matrix || !href_builder)
|
||||||
|
return -1;
|
||||||
|
|
||||||
*out_matrix = NULL;
|
string_matrix_init(out_matrix);
|
||||||
*out_inner_counts = NULL;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
int pager_start = page <= 3 ? 1 : page - 2;
|
int pager_start = page <= 3 ? 1 : page - 2;
|
||||||
int pager_end = pager_start + PAGER_WINDOW_SIZE - 1;
|
int pager_end = pager_start + PAGER_WINDOW_SIZE - 1;
|
||||||
|
|
||||||
if (page > 1) {
|
for (int i = page > 1 ? pager_start - 1 : pager_start; i <= pager_end + 1;
|
||||||
char *href = href_builder(page - 1, data);
|
i++) {
|
||||||
count = add_link_to_collection(href, "←", "pagination-btn prev", out_matrix,
|
const char *label = NULL;
|
||||||
out_inner_counts, count);
|
const char *class_name = "pagination-btn";
|
||||||
|
char page_label[16];
|
||||||
|
int target_page = i;
|
||||||
|
|
||||||
|
if (page > 1 && i == pager_start - 1) {
|
||||||
|
label = "←";
|
||||||
|
class_name = "pagination-btn prev";
|
||||||
|
target_page = page - 1;
|
||||||
|
} else if (i == pager_end + 1) {
|
||||||
|
label = "→";
|
||||||
|
class_name = "pagination-btn next";
|
||||||
|
target_page = page + 1;
|
||||||
|
} else {
|
||||||
|
snprintf(page_label, sizeof(page_label), "%d", i);
|
||||||
|
label = page_label;
|
||||||
|
if (i == page)
|
||||||
|
class_name = "pagination-btn pagination-current";
|
||||||
|
}
|
||||||
|
|
||||||
|
char *href = href_builder(target_page, data);
|
||||||
|
const char *values[LINK_FIELD_COUNT] = {href, label, class_name};
|
||||||
|
int result = string_matrix_append(out_matrix, values, LINK_FIELD_COUNT);
|
||||||
free(href);
|
free(href);
|
||||||
|
if (result != 0) {
|
||||||
|
string_matrix_free(out_matrix);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
for (int i = pager_start; i <= pager_end; i++) {
|
|
||||||
char label[16];
|
|
||||||
snprintf(label, sizeof(label), "%d", i);
|
|
||||||
char *href = href_builder(i, data);
|
|
||||||
count = add_link_to_collection(
|
|
||||||
href, label,
|
|
||||||
i == page ? "pagination-btn pagination-current" : "pagination-btn",
|
|
||||||
out_matrix, out_inner_counts, count);
|
|
||||||
free(href);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *href = href_builder(page + 1, data);
|
|
||||||
count = add_link_to_collection(href, "→", "pagination-btn next", out_matrix,
|
|
||||||
out_inner_counts, count);
|
|
||||||
free(href);
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,18 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef GIT_REMOTE
|
#ifndef GIT_REMOTE
|
||||||
#define GIT_REMOTE "https://git.bwaaa.monster/omnisearch"
|
#define GIT_REMOTE "https://git.bwaaa.space/omnisearch"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define LINK_FIELD_COUNT 3
|
#define LINK_FIELD_COUNT 3
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char ***rows;
|
||||||
|
int *field_counts;
|
||||||
|
int count;
|
||||||
|
int capacity;
|
||||||
|
} StringMatrix;
|
||||||
|
|
||||||
int hex_to_int(char c);
|
int hex_to_int(char c);
|
||||||
char *get_theme(const char *default_theme);
|
char *get_theme(const char *default_theme);
|
||||||
void init_themes(const char *static_path);
|
void init_themes(const char *static_path);
|
||||||
@@ -23,12 +30,17 @@ char *get_locale(const char *default_locale);
|
|||||||
int is_engine_id_enabled(const char *engine_id);
|
int is_engine_id_enabled(const char *engine_id);
|
||||||
int get_user_engines(char ***out_ids, int *out_count);
|
int get_user_engines(char ***out_ids, int *out_count);
|
||||||
int user_engines_contains(const char *engine_id, char **ids, int count);
|
int user_engines_contains(const char *engine_id, char **ids, int count);
|
||||||
|
char *get_default_search_engine(void);
|
||||||
|
|
||||||
int add_link_to_collection(const char *href, const char *label,
|
void free_string_matrix(char ***matrix, int *inner_counts, int row_count);
|
||||||
const char *class_name, char ****collection,
|
|
||||||
int **inner_counts, int current_count);
|
|
||||||
|
|
||||||
int build_pagination(int page, char *(*href_builder)(int page, void *data),
|
void string_matrix_init(StringMatrix *matrix);
|
||||||
void *data, char ****out_matrix, int **out_inner_counts);
|
int string_matrix_append(StringMatrix *matrix, const char *const *values,
|
||||||
|
int field_count);
|
||||||
|
void string_matrix_free(StringMatrix *matrix);
|
||||||
|
|
||||||
|
int string_matrix_build_pagination(int page,
|
||||||
|
char *(*href_builder)(int page, void *data),
|
||||||
|
void *data, StringMatrix *out_matrix);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
106
static/main.css
106
static/main.css
@@ -841,10 +841,42 @@ header .logo-link:hover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.settings-checkbox {
|
.settings-checkbox {
|
||||||
width: 18px;
|
width:18px;
|
||||||
height: 18px;
|
height:18px;
|
||||||
accent-color: var(--accent);
|
accent-color:var(--accent);
|
||||||
cursor: pointer;
|
cursor:pointer;
|
||||||
|
flex-shrink:0;
|
||||||
|
margin:0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-engine-list {
|
||||||
|
margin:0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-engine-options {
|
||||||
|
display:grid;
|
||||||
|
gap:8px;
|
||||||
|
margin-inline:-3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-engine-option {
|
||||||
|
display:flex;
|
||||||
|
align-items:center;
|
||||||
|
justify-content:space-between;
|
||||||
|
gap:16px;
|
||||||
|
padding:12px 14px;
|
||||||
|
border:1px solid var(--border);
|
||||||
|
border-radius:8px;
|
||||||
|
background:var(--bg-main);
|
||||||
|
color:var(--text-primary);
|
||||||
|
font-size:0.95rem;
|
||||||
|
cursor:pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-default-engine-field {
|
||||||
|
margin-top:12px;
|
||||||
|
padding-top:12px;
|
||||||
|
border-top:1px solid var(--border);
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings-actions {
|
.settings-actions {
|
||||||
@@ -887,38 +919,44 @@ header .logo-link:hover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.settings-actions .btn-secondary:hover {
|
.settings-actions .btn-secondary:hover {
|
||||||
background: var(--border);
|
background:var(--border);
|
||||||
border-color: var(--text-secondary);
|
border-color:var(--text-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width:768px) {
|
||||||
.settings-layout {
|
.settings-layout {
|
||||||
padding: 12px;
|
padding:12px;
|
||||||
display: block;
|
display:block;
|
||||||
}
|
}
|
||||||
.settings-container {
|
.settings-container {
|
||||||
max-width: 100%;
|
max-width:100%;
|
||||||
}
|
}
|
||||||
.settings-title {
|
.settings-title {
|
||||||
font-size: 1.4rem;
|
font-size:1.4rem;
|
||||||
margin-bottom: 24px;
|
margin-bottom:24px;
|
||||||
}
|
}
|
||||||
.settings-section {
|
.settings-section {
|
||||||
padding: 16px;
|
padding:16px;
|
||||||
}
|
}
|
||||||
.settings-field {
|
.settings-field {
|
||||||
flex-direction: column;
|
flex-direction:column;
|
||||||
align-items: stretch;
|
align-items:stretch;
|
||||||
gap: 8px;
|
gap:8px;
|
||||||
}
|
}
|
||||||
.settings-actions {
|
.settings-engine-options {
|
||||||
flex-direction: column;
|
margin-inline:0;
|
||||||
}
|
}
|
||||||
.settings-actions .btn-primary,
|
.settings-engine-option {
|
||||||
.settings-actions .btn-secondary {
|
padding-inline:7px;
|
||||||
width: 100%;
|
}
|
||||||
text-align: center;
|
.settings-actions {
|
||||||
}
|
flex-direction:column;
|
||||||
|
}
|
||||||
|
.settings-actions .btn-primary,
|
||||||
|
.settings-actions .btn-secondary {
|
||||||
|
width:100%;
|
||||||
|
text-align:center;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[dir="rtl"] {
|
[dir="rtl"] {
|
||||||
|
|||||||
10
static/themes/catppuccin-frappe.css
Normal file
10
static/themes/catppuccin-frappe.css
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
:root {
|
||||||
|
--bg-main: #292c2c;
|
||||||
|
--bg-card: #303446;
|
||||||
|
--border: #414559;
|
||||||
|
--text-primary: #c6d0f5;
|
||||||
|
--text-secondary: #a5adce;
|
||||||
|
--text-muted: #737994;
|
||||||
|
--accent: #ca9ee6;
|
||||||
|
--accent-glow: rgba(255,255,255,0.1);
|
||||||
|
}
|
||||||
10
static/themes/catppuccin-latte.css
Normal file
10
static/themes/catppuccin-latte.css
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
:root {
|
||||||
|
--bg-main: #e6e9ef;
|
||||||
|
--bg-card: #eff1f5;
|
||||||
|
--border: #cdd0da;
|
||||||
|
--text-primary: #4c4f69;
|
||||||
|
--text-secondary: #6c6f85;
|
||||||
|
--text-muted: #9ca0b0;
|
||||||
|
--accent: #8839ef;
|
||||||
|
--accent-glow: rgba(255,255,255,0.1);
|
||||||
|
}
|
||||||
10
static/themes/catppuccin-macchiato.css
Normal file
10
static/themes/catppuccin-macchiato.css
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
:root {
|
||||||
|
--bg-main: #1e2030;
|
||||||
|
--bg-card: #24273a;
|
||||||
|
--border: #363a4f;
|
||||||
|
--text-primary: #cad3f5;
|
||||||
|
--text-secondary: #a5adcb;
|
||||||
|
--text-muted: #6e738d;
|
||||||
|
--accent: #c6a0f6;
|
||||||
|
--accent-glow: rgba(255,255,255,0.1);
|
||||||
|
}
|
||||||
@@ -7,5 +7,5 @@
|
|||||||
<Url type="text/html" method="get" template="{{scheme}}://{{domain}}/search?q={searchTerms}"/>
|
<Url type="text/html" method="get" template="{{scheme}}://{{domain}}/search?q={searchTerms}"/>
|
||||||
<InputEncoding>UTF-8</InputEncoding>
|
<InputEncoding>UTF-8</InputEncoding>
|
||||||
<OutputEncoding>UTF-8</OutputEncoding>
|
<OutputEncoding>UTF-8</OutputEncoding>
|
||||||
<moz:SearchForm>{{domain}}/</moz:SearchForm>
|
<moz:SearchForm>{{scheme}}://{{domain}}/</moz:SearchForm>
|
||||||
</OpenSearchDescription>
|
</OpenSearchDescription>
|
||||||
|
|||||||
@@ -76,16 +76,33 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
{{if has_enabled_engines}}
|
{{if has_enabled_engines}}
|
||||||
<section class="settings-section">
|
<section class="settings-section settings-engines-section">
|
||||||
<h3 class="settings-section-title">{{l("engines_label")}}</h3>
|
<h3 class="settings-section-title">{{l("engines_label")}}</h3>
|
||||||
<p class="settings-section-desc">{{l("engines_desc")}}</p>
|
<p class="settings-section-desc">{{l("engines_desc")}}</p>
|
||||||
<input type="hidden" name="engines_present" value="1">
|
<input type="hidden" name="engines_present" value="1">
|
||||||
{{for eng in enabled_engines}}
|
|
||||||
<div class="settings-field">
|
<div class="settings-engine-list">
|
||||||
<label class="settings-label" for="engine_{{eng[0]}}">{{eng[1]}}</label>
|
<div class="settings-engine-options">
|
||||||
<input type="checkbox" id="engine_{{eng[0]}}" name="engine_{{eng[0]}}" value="1" class="settings-checkbox" {{eng[2]}}>
|
{{for eng in enabled_engines}}
|
||||||
|
<label class="settings-engine-option" for="engine_{{eng[0]}}">
|
||||||
|
<span>{{eng[1]}}</span>
|
||||||
|
<input type="checkbox" id="engine_{{eng[0]}}" name="engine_{{eng[0]}}" value="1" class="settings-checkbox" {{eng[2]}}>
|
||||||
|
</label>
|
||||||
|
{{endfor}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="settings-field settings-default-engine-field">
|
||||||
|
<label class="settings-label" for="default_engine">{{l("default_engine_label")}}</label>
|
||||||
|
<select id="default_engine" name="default_engine" class="settings-select">
|
||||||
|
<option value="all" {{if default_engine == "all"}}selected{{endif}}>{{l("all_engines_option")}}</option>
|
||||||
|
{{for eng in enabled_engines}}
|
||||||
|
{{if eng[2] != ""}}
|
||||||
|
<option value="{{eng[0]}}" {{eng[3]}}>{{eng[1]}}</option>
|
||||||
|
{{endif}}
|
||||||
|
{{endfor}}
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
{{endfor}}
|
|
||||||
</section>
|
</section>
|
||||||
{{endif}}
|
{{endif}}
|
||||||
<div class="settings-actions">
|
<div class="settings-actions">
|
||||||
@@ -96,4 +113,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user