YaST2 Developers Documentation: yast2

yast2

modules/URL.ycp
Manipulate and Parse URLs
  • Michal Svec
  • Anas Nashif

This module has an unstable interface.

Imports

  • Hostname
  • IP
  • String
  • URLRecode

Global Variables

Global Functions

Info:

TODO: - read URI(3) - esp. compare the regex mentioned in the URI(3) with ours: my($scheme, $authority, $path, $query, $fragment) = $uri =~ m|^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;

global transform_map_passwd -> map<string, string>

Transform map used for (un)escaping characters in username/password part of an URL. It doesn't contain '%' because this character must be used in a particular order (the first or the last) during processing

global transform_map_filename -> map<string, string>

Transform map used for (un)escaping characters in file location part of an URL. It doesn't contain '%' because this character must be used in a particular order (the first or the last) during processing

global transform_map_query -> map<string, string>

Transform map used for (un)escaping characters in query part of a URL. It doesn't contain '%' because this character must be used in a particular order (the first or the last) during processing

global UnEscapeString (string in, map<string,string> transform) -> string

Escape reserved characters in string used as a part of URL (e.g. '%25' => '%', '%40' => '@'...)

Parameters:
in input string to escape
transform
Return value:
unescaped string
Example

	URL::UnEscapeString ("http%3a%2f%2fsome.nice.url%2f%3awith%3a%2f%24p#ci%26l%2fch%40rs%2f", URL::transform_map_passwd)
		-> http://some.nice.url/:with:/$p#ci&l/ch@rs/
global EscapeString (string in, map<string,string> transform) -> string

Escape reserved characters in string used as a part of URL (e.g. '%' => '%25', '@' => '%40'...)

Parameters:
in input string to escape
transform
Return value:
escaped string
Example

	URL::EscapeString ("http://some.nice.url/:with:/$p#ci&l/ch@rs/", URL::transform_map_passwd)
		-> http%3a%2f%2fsome.nice.url%2f%3awith%3a%2f%24p#ci%26l%2fch%40rs%2f
global Parse (string url) -> map

Tokenize URL

Parameters:
url URL to be parsed
Return value:
URL split to tokens
Example
 Parse("http://name:pass@www.suse.cz:80/path/index.html?question#part") ->
     $[
         "scheme"  : "http",
         "host"    : "www.suse.cz"
         "port"    : "80",
         "path"    : /path/index.html",
         "user"    : "name",
         "pass"    : "pass",
         "query"   : "question",
         "fragment": "part"
     ]
global Check (string url) -> boolean

Check URL

Parameters:
url URL to be checked
Return value:
true if correct
See
RFC 2396 (updated by RFC 2732) also perl-URI: URI(3)
global Build (map tokens) -> string

Build URL from tokens as parsed with Parse

Parameters:
tokens
Return value:
url, empty string if invalid data is used to build the url.
See
RFC 2396 (updated by RFC 2732) also perl-URI: URI(3)
global FormatURL (map tokens, integer len) -> string

Format URL - truncate the middle part of the directory to fit to the requested lenght.

Elements in the middle of the path specification are replaced by ellipsis (...). The result migth be longer that requested size if other URL parts are longer than the requested size. If the requested size is greater than size of the full URL then full URL is returned. Only path element of the URL is changed the other parts are not modified (e.g. protocol name)

Parameters:
tokens parsed URL
len requested maximum lenght of the output string
Return value:
Truncated URL
Example
 FormatURL("http://download.opensuse.org/very/log/path/which/will/be/truncated/target_file", 45)
    -> "http://download.opensuse.org/.../target_file"
 FormatURL("http://download.opensuse.org/very/log/path/which/will/be/truncated/target_file", 60)
    -> "http://download.opensuse.org/very/.../be/truncated/target_file"
See
Parse should be used to convert URL string to a map (tokens parameter)
global MakeMapFromParams (string params) -> map <string, string>

Reads list of HTTP params and returns them as map. (Useful also for cd:/, dvd:/, nfs:/ ... params) Neither keys nor values are HTML-unescaped, see UnEscapeString().

Parameters:
params
Return value:
params
Example

      MakeMapFromParams ("device=sda3&login=aaa&password=bbb") -> $[
              "device"   : "sda3",
              "login"    : "aaa",
              "password" : "bbb"
      ]
global MakeParamsFromMap (map <string, string> params_map) -> string

Returns string made of HTTP params. It's a reverse function to MakeMapFromParams(). Neither keys nor values are HTML-escaped, use EscapeString() if needed.

Parameters:
params_map
Example

   MakeMapFromParams ($[
     "param1" : "a",
     "param2" : "b",
     "param3" : "c",
   ]) -> "param1=a¶m2=b¶m3=c"
See
MakeMapFromParams
global HidePassword (string url) -> string

Hide password in an URL - replaces the password in the URL by 'PASSWORD' string. If there is no password in the URL the original URL is returned. It should be used when an URL is logged to y2log or when it is displayed to user.

Parameters:
url original URL
Return value:
new URL with 'PASSWORD' password or unmodified URL if there is no password
global HidePasswordToken (map tokens) -> map

Hide password token in parsed URL (by URL::Parse()) - the password is replaced by 'PASSWORD' string. Similar to HidePassword() but uses a parsed URL as the input.

Parameters:
tokens input
Return value:
map with replaced password