about summary refs log tree commit diff stats
path: root/src/config/preferences.c
Commit message (Expand)AuthorAgeFilesLines
* add `/strophe` command to modify libstrophe-specific settingsSteffen Jaeckel2023-01-181-3/+16
* Update copyright yearMichael Vetter2023-01-101-1/+1
* Add vCard supportMarouane L2022-10-181-0/+10
* Display a help message upon first start of ProfanityMichael Vetter2022-07-051-1/+0
* Display mood preferencesMichael Vetter2022-06-221-1/+1
* Make mood display optionalMichael Vetter2022-06-221-0/+4
* Update copyright yearMichael Vetter2022-05-091-1/+1
* Log encrypted messages by default to chatlogMichael Vetter2022-05-091-4/+4
* ox: Add /ox log commandMichael Vetter2022-05-051-0/+6
* Restore default behaviour for stampsMichael Vetter2022-05-031-1/+1
* Merge branch 'master' into add_stamp_settingsMichael Vetter2022-04-281-3/+7
|\
| * Add support for offline MUC notificationsStefan Ott2022-04-231-0/+3
| * Dont show presence status changes by defaultMichael Vetter2022-04-071-2/+2
| * run `make format`Steffen Jaeckel2022-03-301-1/+2
* | Rename stamp preference variableMichael Vetter2022-04-281-6/+6
* | add /stamp commandArtjom Vejsel2022-04-021-0/+10
|/
* Use EDITOR environment variablePaul Fertser2022-03-271-2/+4
* auto-formatSteffen Jaeckel2021-10-271-1/+0
* Allow utf8 in occupants header charMichael Vetter2021-10-221-16/+8
* Allow utf8 in occupants charMichael Vetter2021-10-221-15/+8
* Allow utf8 in roster room private charMichael Vetter2021-10-221-16/+8
* Allow utf8 in roster rooms charMichael Vetter2021-10-221-16/+8
* Allow utf8 in roster private charMichael Vetter2021-10-221-16/+8
* Allow utf8 in roster resource charMichael Vetter2021-10-221-16/+8
* Allow utf8 in roster contact charMichael Vetter2021-10-221-16/+8
* Allow utf8 in roster header charMichael Vetter2021-10-211-13/+11
* Clean sourcepath from profrcMichael Vetter2021-09-291-0/+5
* Remove `/python sourcepath`Michael Vetter2021-09-291-4/+0
* Enable whole word only notifications by defaultMichael Vetter2021-09-081-0/+1
* Add option to only allow messages from jids in rosterMichael Vetter2021-07-011-0/+3
* Disable notifications by defaultMichael Vetter2021-06-281-9/+0
* external editor: don't use absolute paths and allow path searchJörg Thalheim2021-05-301-1/+1
* Have intype on by defaultMichael Vetter2021-05-081-0/+2
* Have separate settings for intypeMichael Vetter2021-05-081-0/+3
* OMEMO - trust mode (#1506)Stefan2021-04-171-0/+5
* Editor: Using preferences compose.editorStefan2021-04-161-0/+5
* MUC: Show offline members in sidebarThorben Günther2021-03-081-0/+3
* Update copyrightMichael Vetter2021-01-081-1/+1
* Add `/executable (urlsave|urlopen)` migrationsWilliam Wennerström2020-12-181-3/+29
* Fix various typosMichael Vetter2020-12-101-1/+1
* Purge omemo sendfile from configMichael Vetter2020-12-091-0/+5
* Remove scheme and filetype matching for url (save|open)William Wennerström2020-12-081-2/+2
* Move unique_filename_from_url functions to commonWilliam Wennerström2020-12-041-1/+0
* Refactor for threaded external executable for built-in download methodsWilliam Wennerström2020-12-031-45/+4
* Use fallback method when /executable urlsave is unsetWilliam Wennerström2020-11-161-2/+0
* Run make format on rebaseWilliam Wennerström2020-11-161-389/+387
* Remove /omemo sendfileWilliam Wennerström2020-11-161-390/+389
* Declare counter var inside loopMichael Vetter2020-11-091-24/+15
* Apply coding styleMichael Vetter2020-07-071-713/+709
* Revert "Apply coding style"Michael Vetter2020-07-071-712/+716
und-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
import std/options

import js/regex
import types/url

#TODO add denyhost/s for blocklists
type URLFilter* = object
  scheme: Option[string]
  allowschemes: seq[string]
  allowhost*: Option[string]
  allowhosts: seq[Regex]
  default: bool

proc newURLFilter*(scheme = none(string), allowschemes: seq[string] = @[],
    allowhost = none(string), allowhosts: seq[Regex] = @[],
    default = false): URLFilter =
  doAssert scheme.isSome or allowschemes.len == 0,
    "allowschemes without scheme is not supported"
  return URLFilter(
    scheme: scheme,
    allowschemes: allowschemes,
    allowhost: allowhost,
    allowhosts: allowhosts,
    default: default
  )

# Filters as follows:
# If scheme/s are given, only URLs with the same scheme are matched.
# Then, allowhost and allowhosts are checked; if none of these match the host,
# the function returns the value of `default'.
proc match*(filter: URLFilter, url: URL): bool =
  block check_scheme:
    if filter.scheme.isSome and filter.scheme.get != url.scheme:
      for scheme in filter.allowschemes:
        if scheme == url.scheme:
          break check_scheme
      return false
  let host = url.host
  if filter.allowhost.isSome and filter.allowhost.get == host:
    return true
  for regex in filter.allowhosts:
    if regex.match(host):
      return true
  return filter.default