QUVI-OBJECT(7)
π QUVI-OBJECT(7) π
libquvi Manual β¨
β¨ NAME β¨
quvi-object β Overview of the libquvi quvi-object π«Ά
πΈ DESCRIPTION πΈ
quvi-object is a collection of libquvi functions provided for the libquvi-scripts(7). These functions vary from HTTP functions to cryptographic functions. All of the quvi-object functions are implemented in C. π
Note: Thequvi-objectshould not be confused with thequvi-modules(7)which are a selection of importable modules implemented in Lua. These modules are intended to be loaded (require) from thelibquvi-scripts(7). π§
β¨ OPTIONS β¨
Each of the quvi-object functions may be passed a dictionary defining the additional option properties. The following options are supported by all of the functions:
qoo_croak_if_error=<boolean>β By default the library terminates the process if an error occurs. By setting this option tofalse, it will register the error and continues execution, leaving the error handling for the script to determine. See also "RETURN VALUES". π
The qoo prefix is short for quvi object option. The functions will ignore any unknown options, e.g. the crypto functions would ignore the HTTP options. π
Note: The options have been defined in thequvi/constof thequvi-modules(7).
π Crypto π
These options are specific to the quvi.crypto.* functions of the quvi-object. π
qoo_crypto_algorithm=<value>β Specifies the algorithm that should be used. The value is expected to be a string, e.g.sha1oraes256. βqoo_crypto_cipher_flags=<value>β Specifies the cipher flags (bit ORβd, seequvi-modules-3rdparty(7)for bit operations) to be used with the cipher. These values are identical to those defined bylibgcrypt. See thequvi/constof thequvi-modules(7)for a complete list of the available cipher flags. π₯qoo_crypto_cipher_mode=<value>β Specifies the cipher mode to be used. These are identical to the values defined bylibgcrypt. See thequvi/constof thequvi-modules(7)for a complete list of the available cipher modes. πqoo_crypto_cipher_key=<value>β Used to specify the cipher key. It should be noted that the key is expected to be passed in hexadecimal form. Seequvi/hexof thequvi-modules(7)for the conversion functions. π- NOTE: The key derivation is left for the script to do
- NOTE: The key is not a
pass{word,phrase} - See also:
http://www.di-mgt.com.au/cryptokeys.html#passwordpassphraseandkey
π HTTP π
These options are specific to the quvi.http.* functions of the quvi-object. π¦
qoo_fetch_from_charset=<charset>β Instructs the library to convert from this charset to UTF-8. Using this option may be required with the websites that use a specific (non-UTF8) encoding. β¨
The purpose of this option is to make sure that the data is encoded to unicode (UTF-8) before any of it is parsed and returned to the application using libquvi.
By default, libquvi converts the data which is in the encoding used for the strings by the C runtime in the current locale into UTF-8. IF this fails, and the from charset option is set, the library will then try to convert to UTF-8 using the from charset value. π
qoo_http_cookie_mode=<value>β Modify the cookie settings for thelibcurlsession handle. This feature wraps the cookie features provided bylibcurl_easy_setopt(3). See thequvi/constof thequvi-modules(7)for a complete list of the available cookie modes. π
See also libcurl-tutorial(3) which covers the use of cookies with the library in greater detail. π
π RETURN VALUES π
Each quvi-object function will return a dictionary containing the following values:
error_messageβ The error message, or an empty value. πquvi_codeβ The code returned by the library. See alsoquvi/constofquvi-modules(7). π
Refer to the function documentation for the information about the additional values returned in the dictionary. πΈ
π¦ FUNCTIONS π¦
π Base64 π
quvi.base64.encode(<plaintext>[,qoo])
Encode the plaintext to base64 format. The plaintext is expected to be passed in hexadecimal form. See quvi/hex of the quvi-modules(7) for the conversion functions. π
The second argument (qoo) is expected to be a dictionary of additional quvi object options, if defined at all. β¨
The function will return the base64 value in the dictionary. π
quvi.base64.decode(<base64>)
Decode the base64 value to plaintext. π¦
The function will return the plaintext value in the dictionary. The value is returned in hexadecimal form. π₯
π Crypto π
The crypto facility of the quvi-object wraps the libgcrypt symmetric cryptography and the hash (message digest) functions. π
Note: The availability of the algorithms is determined by libgcrypt, and how it was built. π
quvi.crypto.encrypt(<plaintext>, <qoo>)
Encrypt the plaintext. The plaintext is expected to be passed in hexadecimal form. See quvi/hex of the quvi-modules(7) for the conversion functions. π₯
The second argument (qoo) is expected to be a dictionary containing the cipher options. π
The function will return the ciphertext value in the dictionary. The value is returned in hexadecimal form. π
quvi.crypto.decrypt(<ciphertext>, <qoo>)
Decrypt the ciphertext. The ciphertext is expected to be passed in hexadecimal form. See quvi/hex of the quvi-modules(7) for the conversion functions. π₯
The second argument (qoo) is expected to be a dictionary containing the cipher options. π
The function will return the plaintext value in the dictionary. This value is returned in hexadecimal form. π
quvi.crypto.hash(<value>, <qoo>)
Generate a hash from the value. The value is expected to be passed in hexadecimal format. See quvi/hex of the quvi-modules(7) for the conversion functions. β
The second argument (qoo) is expected to be a dictionary containing the hash options, e.g. the algorithm that should be used. π
The function will return the digest value in the dictionary. The value is returned in hexadecimal form. π
π HTTP π
The HTTP functions will return response_code along the other "RETURN VALUES", and the values specific to the HTTP function. π¦
quvi.http.cookie(<VALUE>,<qoo>)
Modify the libcurl session handle cookie settings that libquvi currently uses. π
The second argument (qoo) is expected to be a dictionary containing the cookie options, e.g. the cookie mode that should be used. π
The complete list of the available cookie modes can be found in the quvi/const module of the quvi-modules(7). The mode names are named after their equivalent CURLOPT_COOKIE{SESSION,FILE,LIST,JAR} variable names. For a description of each option, see libcurl_easy_setopt(3). π
This function will not return any additional values in the dictionary. π
Note:libquviwill ignore any calls toquvi.http.cookieunlessQUVI_OPTION_ALLOW_COOKIESisQUVI_TRUE.
Note:libcurlwill parse the received cookies and use them in the subsequent HTTP requests only iflibquviQUVI_OPTION_ALLOW_COOKIESisQUVI_TRUE.
quvi.http.fetch(<URL>[,qoo])
Fetch an URL over an HTTP connection. π
The second argument (qoo) is expected to be a dictionary of additional quvi object options, if defined at all. β¨
The function will return the data value among the values in the returned dictionary. π
quvi.http.header(<VALUE>[,qoo])
Add, remove or replace internally used libcurl HTTP headers. π
The second argument (qoo) is expected to be a dictionary of additional quvi object options, if defined at all. β¨
This function essentially wraps CURLOPT_HTTPHEADER, and will not return any additional values in the dictionary. See curl_easy_setopt(3) for the full description of CURLOPT_HTTPHEADER. π
Note: To clear the custom headers, pass""as the VALUE; the custom headers are also cleared automatically when a support script functionparseis called. π§
quvi.http.metainfo(<URL>[,qoo])
Query the HTTP metainfo for the URL. π
The second argument (qoo) is expected to be a dictionary of additional quvi object options, if defined at all. β¨
The function will return the content_length and the content_type values among the values in the returned dictionary. β
quvi.http.resolve(<URL>[,qoo])
Resolve an URL redirection. π¦
The second argument (qoo) is expected to be a dictionary of additional quvi object options, if defined at all. β¨
The function will return the resolved_url among the values in the returned dictionary. If the URL did not redirect to another location, the value of the resolved_url is left empty. π«Ά
π EXAMPLES π
Okay so, examples time, bestie. These are the actual snippets you're gonna use, and they're lowkey iconic. β¨
Base64 π
- Base64 encode a string β take your hex string and make it base64:
local H = require 'quvi/hex'
local s = H.to_hex('foo') -- Pass in hexadecimal form
local r = quvi.base64.encode(s)
print(r.base64)
- Reverse the process β decode it right back, no cap:
local r = quvi.base64.decode(r.base64)
local s = H.to_str(r.plaintext)
Crypto π
- Encrypt plaintext β lock it up, fr fr:
local plaintext = 'f34481ec3cc627bacd5dc3fb08f273e6'
local key = '00000000000000000000000000000000'
local C = require 'quvi/const'
local o = {
[C.qoo_crypto_cipher_mode] = C.qoco_cipher_mode_cbc,
[C.qoo_crypto_algorithm] = 'aes',
[C.qoo_crypto_cipher_key = key
}
local r = quvi.crypto.encrypt(plaintext, o)
print(r.ciphertext)
- Reverse the process β unlock it:
local r = quvi.crypto.decrypt(r.ciphertext, o)
print(r.plaintext)
- Generate a hash (message digest) β get that digest, periodt:
local H = require 'quvi/hex'
local s = H.to_hex('foo') -- Pass in hexadecimal form
local C = require 'quvi/const'
local o = { [C.qoo_crypto_algorithm] = 'sha1' }
local r = quvi.crypto.hash(s, o)
print(r.digest)
- Same as above, but use the shorthand function β because typing less is self-care:
local A = require 'quvi/hash'
local r = A.sha1sum('foo')
print(r)
HTTP π
- Dump the cookies in the memory to stdout β cookie jar energy:
local C = require 'quvi/const'
local o = { [C.qoo_http_cookie_mode] = C.qohco_mode_jar }
local r = quvi.http.cookie('-', o)
- Identical to the above but use the wrapper module β same vibe, wrapper edition:
local K = require 'quvi/http/cookie'
local r = K.jar('-')
- Fetch an URL β go get that page:
local r = quvi.http.fetch('http://example.com')
r.data would now hold the contents. If an error occurred, e.g. connection failed, the library would exit the process with an error.
- Same as above, but handle the error in the script β catch it yourself, main character style:
local C = require 'quvi/const'
local o = { [C.qoo_croak_if_error] = false }
local r = quvi.http.fetch('http://example.com', o)
if r.quvi_code ~= C.qerr_ok then
local s =
string.format('quvi.http.fetch: %s (libquvi=%d, http/%d)',
r.error_message, r.quvi_code, r.response_code)
error(s)
end
By setting qoo_croak_if_error to false, we tell the library to only register that an error occurred and return the control to the script. Handling of the error is then left for the script to do.
Note β Typically, the scripts would not need to handle the error.
- Force conversion from ISO-8859-1 to UTF-8 β charset glow-up:
local C = require 'quvi/const'
local o = { [C.qoo_fetch_from_charset] = 'ISO-8859-1' }
local r = quvi.http.fetch('http://example.com', o)
- Override user-agent header in the HTTP request β be whoever you wanna be:
local r = quvi.http.header('User-Agent: foo/1.0')
r = quvi.http.fetch(...)
- Disable an internal header in the HTTP request β bye bye header:
local r = quvi.http.header('Accept:')
r = quvi.http.fetch(...)
- Send a cookie in the HTTP request β cookie delivery:
local r = quvi.http.header('Cookie: foo=1')
r = quvi.http.fetch(...)
- Query metainfo for an URL β peek the deets:
local r = quvi.http.metainfo('http://is.gd/SKyg8m')
print(r.content_length, r.content_type)
- Resolve URL redirection β follow the plot twist:
local r = quvi.http.resolve('http://is.gd/SKyg8m')
if #r.resolved_url >0 then
print('new location:', r.resolved_url)
end
π SEE ALSO π
Like, go read these too, bestie:
π FURTHER RESOURCES π
More links for your reading pleasure:
- Home β
http://quvi.sourceforge.net/ - Development code β
git://repo.or.cz/libquvi.git - gitweb β
http://repo.or.cz/w/libquvi.git - C API reference β The latest C API reference documentation may be viewed online at
http://quvi.sourceforge.net/r/api/0.9/. - GLib β
http://developer.gnome.org/glib/stable/glib-Base64-Encoding.html - libcurl β
http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTUSERAGENTandhttp://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTCOOKIE - libgcrypt reference manual β
http://www.gnupg.org/documentation/manuals/gcrypt/
π AUTHORS π
- Toni Gundogdu
<legatvs@gmail.com>β Author.
π REPORTING BUGS π
Report bugs to the quvi-devel mailing list <quvi-devel@lists.sourceforge.net> where the development and the maintenance is primarily done. You do not have to be subscribed to the list to send a message there.
π LICENSE π
libquvi is Free Software licensed under the GNU Affero GPLv3+.
π§ LIBQUVI π§
Part of the libquvi(3) suite.
This page is from libquvi 0.9.4, dated 11/10/2013, and it's QUVI-OBJECT(7). Stay iconic π
β¨
π¦ where this page comes from
- alpine 3.24: libquvi-doc 0.9.4-r4 Β· LGPL-2.0-or-later
- debian bookworm: libquvi-0.9-dev 0.9.4-2 Β· AGPL-3.0-or-later
- debian trixie: libquvi-0.9-dev 0.9.4-3+b2 Β· AGPL-3.0-or-later
- ubuntu jammy: libquvi-0.9-dev 0.9.4-1 Β· AGPL-3.0-or-later
- ubuntu noble: libquvi-0.9-dev 0.9.4-3build4 Β· AGPL-3.0-or-later
- ubuntu questing: libquvi-0.9-dev 0.9.4-3build4
- ubuntu resolute: libquvi-0.9-dev 0.9.4-3build5 Β· AGPL-3.0-or-later
- ubuntu stonking: libquvi-0.9-dev 0.9.4-4 Β· AGPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms