Cross-platform C SDK logo

Cross-platform C SDK

URL

❮ Back
Next ❯
This page has been automatically translated using the Google Translate API services. We are working on improving texts. Thank you for your understanding and patience.

Functions

Url*url_parse (...)
voidurl_destroy (...)
const char_t*url_scheme (...)
const char_t*url_user (...)
const char_t*url_pass (...)
const char_t*url_host (...)
const char_t*url_path (...)
const char_t*url_params (...)
const char_t*url_query (...)
const char_t*url_fragment (...)
String*url_resource (...)
uint16_turl_port (...)

URL is the acronym for Uniform Resource Locator that identifies a unique resource on the Internet. The most common use is found when making requests to a Web server. For example https://www.google.com is a widely recognized and used URL. Being somewhat more specific, we can say that it is a string of characters with a specific format composed of a series of fields that allow unambiguously locating a unique global resource (Listing 1) (Figure 1).

Listing 1: Parsing a URL string.
1
2
3
4
5
Url *url = url_parse("https://frang@www.nappgui.com/services/demo/userlist.php?id=peter&city=Alicante");
const char_t *scheme = url_scheme(url); // https
const char_t *host = url_host(url);     // www.nappgui.com
const char_t *path = url_path(url);     // /services/demo/userlist.php
const char_t *query = url_query(url);   // id=peter&city=Alicante
A complete URL where all its fields are indicated.
Figure 1: The different fields that make up a URL.
  • Scheme: Communication protocol used. http, https, ftp, smtp, mailto, etc.
  • Authority: Access string to the server composed of several fields, where only the host name is required. The rest are optional.
    • Host: Server name or IP address.
    • User: User name. Optional, only if the service requires it.
    • Password: Password. Optional, only if the service requires it.
    • Port: Access port. Each protocol has a default port, which will be the one used if none is specified. 80 = http, 413 = https.
  • Resource: Path within the server where the resource we are looking for is located. The pathname is the only one required.
    • Pathname: Directory and name of the file or resource.
    • Parameters: List of name = value arguments that the service may need. Not normally used. If there are multiple values, they are separated by the character '&'.
    • Queries: List of name = value arguments that the service may need. These are the ones normally used by Web services. That is, in the URL you must use the '?' separator instead of ';' after the pathname. If there are multiple values, they are separated by the character '&'.
  • Fragment: It is an anchor to a specific part of the document that we request from the server. Normally used to access a specific point in an HTML page.
❮ Back
Next ❯

url_parse ()

Create a URL object from a text string.

Url*
url_parse(const char_t *url);
url

Null-terminated UTF8 C text string '\0'.

Return

Result URL object after parsing the string.


url_destroy ()

Destroy the URL object.

void
url_destroy(Url **url);
url

URL object. Will be set to NULL after destruction.


url_scheme ()

Gets the scheme (protocol) of the URL.

const char_t*
url_scheme(const Url *url);
url

URL object.

Return

Protocol (http, https, ftp, etc).


url_user ()

Gets the user.

const char_t*
url_user(const Url *url);
url

URL object.

Return

User or "" if not specified.


url_pass ()

Get the password.

const char_t*
url_pass(const Url *url);
url

URL object.

Return

Password or "" if not specified.


url_host ()

Gets the name of the server.

const char_t*
url_host(const Url *url);
url

URL object.

Return

Host (Pe. www.google.com).


url_path ()

Gets the path (directories + name) of the requested file or resource.

const char_t*
url_path(const Url *url);
url

URL object.

Return

Pathname (Pe. /dir1/dir2/file.html).


url_params ()

Gets the parameters (from ';') of the URL.

const char_t*
url_params(const Url *url);
url

URL object.

Return

Parameters or "" if not specified.


url_query ()

Gets the parameters (from '?') of the URL.

const char_t*
url_query(const Url *url);
url

URL object.

Return

Parameters or "" if not specified.


url_fragment ()

Gets the fragment (position or anchor of the document) of the URL.

const char_t*
url_fragment(const Url *url);
url

URL object.

Return

Fragment or "" if not specified.


url_resource ()

Get the full address of a resource within the server.

String*
url_resource(const Url *url);
url

URL object.

Return

Resource. path + ";" + params + "?" + query + "#" + fragment.


url_port ()

Gets the access port to the server.

uint16_t
url_port(const Url *url);
url

URL object.

Return

Port. UINT16_MAX if not specified.

❮ Back
Next ❯