File: | content/fetchers/about/websearch.c |
Warning: | line 66, column 7 Value stored to 'kvlen' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Copyright 2020 Vincent Sanders <vince@netsurf-browser.org> |
3 | * |
4 | * This file is part of NetSurf. |
5 | * |
6 | * NetSurf is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; version 2 of the License. |
9 | * |
10 | * NetSurf is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | */ |
18 | |
19 | /** |
20 | * \file |
21 | * content generator for the about scheme web search |
22 | */ |
23 | |
24 | #include <stdbool.h> |
25 | #include <stdint.h> |
26 | #include <sys/types.h> |
27 | #include <stdlib.h> |
28 | #include <string.h> |
29 | |
30 | #include "utils/errors.h" |
31 | #include "utils/nsurl.h" |
32 | #include "utils/url.h" |
33 | |
34 | #include "content/fetch.h" |
35 | #include "desktop/searchweb.h" |
36 | |
37 | #include "private.h" |
38 | #include "websearch.h" |
39 | |
40 | static nserror |
41 | process_query_section(const char *str, size_t len, char **term) |
42 | { |
43 | if (len < 3) { |
44 | return NSERROR_BAD_PARAMETER; |
45 | } |
46 | if (str[0] != 'q' || str[1] != '=') { |
47 | return NSERROR_BAD_PARAMETER; |
48 | } |
49 | return url_unescape(str + 2, len - 2, NULL((void*)0), term); |
50 | } |
51 | |
52 | static nserror |
53 | searchterm_from_query(struct nsurl *url, char **term) |
54 | { |
55 | nserror res; |
56 | char *querystr; |
57 | size_t querylen; |
58 | size_t kvstart;/* key value start */ |
59 | size_t kvlen; /* key value end */ |
60 | |
61 | res = nsurl_get(url, NSURL_QUERY, &querystr, &querylen); |
62 | if (res != NSERROR_OK) { |
63 | return res; |
64 | } |
65 | |
66 | for (kvlen = 0, kvstart = 0; kvstart < querylen; kvstart += kvlen) { |
Value stored to 'kvlen' is never read | |
67 | /* get query section length */ |
68 | kvlen = 0; |
69 | while (((kvstart + kvlen) < querylen) && |
70 | (querystr[kvstart + kvlen] != '&')) { |
71 | kvlen++; |
72 | } |
73 | |
74 | res = process_query_section(querystr + kvstart, kvlen, term); |
75 | if (res == NSERROR_OK) { |
76 | break; |
77 | } |
78 | kvlen++; /* account for & separator */ |
79 | } |
80 | free(querystr); |
81 | |
82 | return res; |
83 | } |
84 | |
85 | bool_Bool fetch_about_websearch_handler(struct fetch_about_context *ctx) |
86 | { |
87 | nserror res; |
88 | nsurl *url; |
89 | char *term; |
90 | |
91 | res = searchterm_from_query(fetch_about_get_url(ctx), &term); |
92 | if (res != NSERROR_OK) { |
93 | return false0; |
94 | } |
95 | |
96 | res = search_web_omni(term, SEARCH_WEB_OMNI_SEARCHONLY, &url); |
97 | free(term); |
98 | if (res != NSERROR_OK) { |
99 | return false0; |
100 | } |
101 | |
102 | fetch_about_redirect(ctx, nsurl_access(url)); |
103 | nsurl_unref(url); |
104 | |
105 | return true1; |
106 | } |