Blame doc/man7/quvi-object.7

Packit 3ff1e7
'\" t
Packit 3ff1e7
.\"     Title: quvi-object
Packit 3ff1e7
.\"    Author: [see the "Authors" section]
Packit 3ff1e7
.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
Packit 3ff1e7
.\"      Date: 11/10/2013
Packit 3ff1e7
.\"    Manual: libquvi Manual
Packit 3ff1e7
.\"    Source: libquvi 0.9.4
Packit 3ff1e7
.\"  Language: English
Packit 3ff1e7
.\"
Packit 3ff1e7
.TH "QUVI\-OBJECT" "7" "11/10/2013" "libquvi 0\&.9\&.4" "libquvi Manual"
Packit 3ff1e7
.\" -----------------------------------------------------------------
Packit 3ff1e7
.\" * Define some portability stuff
Packit 3ff1e7
.\" -----------------------------------------------------------------
Packit 3ff1e7
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Packit 3ff1e7
.\" http://bugs.debian.org/507673
Packit 3ff1e7
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
Packit 3ff1e7
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Packit 3ff1e7
.ie \n(.g .ds Aq \(aq
Packit 3ff1e7
.el       .ds Aq '
Packit 3ff1e7
.\" -----------------------------------------------------------------
Packit 3ff1e7
.\" * set default formatting
Packit 3ff1e7
.\" -----------------------------------------------------------------
Packit 3ff1e7
.\" disable hyphenation
Packit 3ff1e7
.nh
Packit 3ff1e7
.\" disable justification (adjust text to left margin only)
Packit 3ff1e7
.ad l
Packit 3ff1e7
.\" -----------------------------------------------------------------
Packit 3ff1e7
.\" * MAIN CONTENT STARTS HERE *
Packit 3ff1e7
.\" -----------------------------------------------------------------
Packit 3ff1e7
.SH "NAME"
Packit 3ff1e7
quvi-object \- Overview of the libquvi quvi\-object
Packit 3ff1e7
.SH "DESCRIPTION"
Packit 3ff1e7
.sp
Packit 3ff1e7
\fIquvi\-object\fR is a collection of libquvi functions provided for the \fBlibquvi-scripts\fR(7)\&. These functions vary from HTTP functions to cryptographic functions\&. All of the \fIquvi\-object\fR functions are implemented in C\&.
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.sp
Packit 3ff1e7
.\}
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.it 1 an-trap
Packit 3ff1e7
.nr an-no-space-flag 1
Packit 3ff1e7
.nr an-break-flag 1
Packit 3ff1e7
.br
Packit 3ff1e7
.ps +1
Packit 3ff1e7
\fBNote\fR
Packit 3ff1e7
.ps -1
Packit 3ff1e7
.br
Packit 3ff1e7
.sp
Packit 3ff1e7
The \fIquvi\-object\fR should not be confused with the \fBquvi-modules\fR(7) which are a selection of importable modules implemented in Lua\&. These modules are intended to be loaded (\fIrequire\fR) from the \fBlibquvi-scripts\fR(7)\&.
Packit 3ff1e7
.sp .5v
Packit 3ff1e7
.RE
Packit 3ff1e7
.SH "OPTIONS"
Packit 3ff1e7
.sp
Packit 3ff1e7
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:
Packit 3ff1e7
.PP
Packit 3ff1e7
qoo_croak_if_error=<boolean>
Packit 3ff1e7
.RS 4
Packit 3ff1e7
By default the library terminates the process if an error occurs\&. By setting this option to
Packit 3ff1e7
\fIfalse\fR, it will register the error and continues execution, leaving the error handling for the script to determine\&. See also "RETURN VALUES"\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
The \fIqoo\fR prefix is short for \fIquvi object option\fR\&. The functions will ignore any unknown options, e\&.g\&. the crypto functions would ignore the HTTP options\&.
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.sp
Packit 3ff1e7
.\}
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.it 1 an-trap
Packit 3ff1e7
.nr an-no-space-flag 1
Packit 3ff1e7
.nr an-break-flag 1
Packit 3ff1e7
.br
Packit 3ff1e7
.ps +1
Packit 3ff1e7
\fBNote\fR
Packit 3ff1e7
.ps -1
Packit 3ff1e7
.br
Packit 3ff1e7
.sp
Packit 3ff1e7
The options have been defined in the \fIquvi/const\fR of the \fBquvi-modules\fR(7)
Packit 3ff1e7
.sp .5v
Packit 3ff1e7
.RE
Packit 3ff1e7
.SS "Crypto"
Packit 3ff1e7
.sp
Packit 3ff1e7
These options are specific to the quvi\&.crypto\&.* functions of the quvi\-object\&.
Packit 3ff1e7
.PP
Packit 3ff1e7
qoo_crypto_algorithm=<value>
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Specifies the algorithm that should be used\&. The
Packit 3ff1e7
\fIvalue\fR
Packit 3ff1e7
is expected to be a string, e\&.g\&.
Packit 3ff1e7
\fIsha1\fR
Packit 3ff1e7
or
Packit 3ff1e7
\fIaes256\fR\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
qoo_crypto_cipher_flags=<value>
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Specifies the cipher flags (bit OR\(cqd, see
Packit 3ff1e7
\fBquvi-modules-3rdparty\fR(7)
Packit 3ff1e7
for
Packit 3ff1e7
\fIbit operations\fR) to be used with the cipher\&. These values are identical to those defined by libgcrypt\&. See the
Packit 3ff1e7
\fIquvi/const\fR
Packit 3ff1e7
of the
Packit 3ff1e7
\fBquvi-modules\fR(7)
Packit 3ff1e7
for a complete list of the available cipher flags\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
qoo_crypto_cipher_mode=<value>
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Specifies the cipher mode to be used\&. These are identical to the values defined by libgcrypt\&. See the
Packit 3ff1e7
\fIquvi/const\fR
Packit 3ff1e7
of the
Packit 3ff1e7
\fBquvi-modules\fR(7)
Packit 3ff1e7
for a complete list of the available cipher modes\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
qoo_crypto_cipher_key=<value>
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Used to specify the cipher key\&. It should be noted that the
Packit 3ff1e7
\fIkey\fR
Packit 3ff1e7
is expected to be passed in hexadecimal form\&. See
Packit 3ff1e7
\fIquvi/hex\fR
Packit 3ff1e7
of the
Packit 3ff1e7
\fBquvi-modules\fR(7)
Packit 3ff1e7
for the conversion functions\&.
Packit 3ff1e7
Packit 3ff1e7
NOTE: The key derivation is left for the script to do
Packit 3ff1e7
Packit 3ff1e7
NOTE: The key is not a pass{word,phrase}
Packit 3ff1e7
Packit 3ff1e7
See also:
Packit 3ff1e7
http://www\&.di\-mgt\&.com\&.au/cryptokeys\&.html#passwordpassphraseandkey
Packit 3ff1e7
.RE
Packit 3ff1e7
.SS "HTTP"
Packit 3ff1e7
.sp
Packit 3ff1e7
These options are specific to the quvi\&.http\&.* functions of the quvi\-object\&.
Packit 3ff1e7
.PP
Packit 3ff1e7
qoo_fetch_from_charset=<charset>
Packit 3ff1e7
.RS 4
Packit 3ff1e7
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\&.
Packit 3ff1e7
Packit 3ff1e7
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\&.
Packit 3ff1e7
Packit 3ff1e7
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
Packit 3ff1e7
\fIfrom charset\fR
Packit 3ff1e7
option is set, the library will then try to convert to UTF\-8 using the
Packit 3ff1e7
\fIfrom charset\fR
Packit 3ff1e7
value\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
qoo_http_cookie_mode=<value>
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Modify the cookie settings for the libcurl session handle\&. This feature wraps the cookie features provided by
Packit 3ff1e7
\fBlibcurl_easy_setopt\fR(3)\&. See the
Packit 3ff1e7
\fIquvi/const\fR
Packit 3ff1e7
of the
Packit 3ff1e7
\fBquvi-modules\fR(7)
Packit 3ff1e7
for a complete list of the available cookie modes\&.
Packit 3ff1e7
Packit 3ff1e7
See also
Packit 3ff1e7
\fBlibcurl-tutorial\fR(3)
Packit 3ff1e7
which covers the use of cookies with the library in greater detail\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.SH "RETURN VALUES"
Packit 3ff1e7
.sp
Packit 3ff1e7
Each quvi\-object function will return a dictionary containing the following values:
Packit 3ff1e7
.PP
Packit 3ff1e7
error_message
Packit 3ff1e7
.RS 4
Packit 3ff1e7
The error message, or an empty value\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
quvi_code
Packit 3ff1e7
.RS 4
Packit 3ff1e7
The code returned by the library\&. See also
Packit 3ff1e7
\fIquvi/const\fR
Packit 3ff1e7
of
Packit 3ff1e7
\fBquvi-modules\fR(7)\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
Refer to the function documentation for the information about the additional values returned in the dictionary\&.
Packit 3ff1e7
.SH "FUNCTIONS"
Packit 3ff1e7
.SS "Base64"
Packit 3ff1e7
.PP
Packit 3ff1e7
quvi\&.base64\&.encode(<plaintext>[,qoo])
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Encode the
Packit 3ff1e7
\fIplaintext\fR
Packit 3ff1e7
to base64 format\&. The
Packit 3ff1e7
\fIplaintext\fR
Packit 3ff1e7
is expected to be passed in hexadecimal form\&. See
Packit 3ff1e7
\fIquvi/hex\fR
Packit 3ff1e7
of the
Packit 3ff1e7
\fBquvi-modules\fR(7)
Packit 3ff1e7
for the conversion functions\&.
Packit 3ff1e7
Packit 3ff1e7
The second argument (\fIqoo\fR) is expected to be a dictionary of additional
Packit 3ff1e7
\fIquvi object options\fR, if defined at all\&.
Packit 3ff1e7
Packit 3ff1e7
The function will return the
Packit 3ff1e7
\fIbase64\fR
Packit 3ff1e7
value in the dictionary\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
quvi\&.base64\&.decode(<base64>)
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Decode the
Packit 3ff1e7
\fIbase64\fR
Packit 3ff1e7
value to plaintext\&.
Packit 3ff1e7
Packit 3ff1e7
The function will return the
Packit 3ff1e7
\fIplaintext\fR
Packit 3ff1e7
value in the dictionary\&. The value is returned in hexadecimal form\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.SS "Crypto"
Packit 3ff1e7
.sp
Packit 3ff1e7
The crypto facility of the quvi\-object wraps the libgcrypt symmetric cryptography and the hash (message digest) functions\&.
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.sp
Packit 3ff1e7
.\}
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.it 1 an-trap
Packit 3ff1e7
.nr an-no-space-flag 1
Packit 3ff1e7
.nr an-break-flag 1
Packit 3ff1e7
.br
Packit 3ff1e7
.ps +1
Packit 3ff1e7
\fBNote\fR
Packit 3ff1e7
.ps -1
Packit 3ff1e7
.br
Packit 3ff1e7
.sp
Packit 3ff1e7
The availability of the algorithms is determined by libgcrypt, and how it was built
Packit 3ff1e7
.sp .5v
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
quvi\&.crypto\&.encrypt(<plaintext>, <qoo>)
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Encrypt the
Packit 3ff1e7
\fIplaintext\fR\&. The
Packit 3ff1e7
\fIplaintext\fR
Packit 3ff1e7
is expected to be passed in hexadecimal form\&. See
Packit 3ff1e7
\fIquvi/hex\fR
Packit 3ff1e7
of the
Packit 3ff1e7
\fBquvi-modules\fR(7)
Packit 3ff1e7
for the conversion functions\&.
Packit 3ff1e7
Packit 3ff1e7
The second argument (\fIqoo\fR) is expected to be a dictionary containing the cipher options\&.
Packit 3ff1e7
Packit 3ff1e7
The function will return the
Packit 3ff1e7
\fIciphertext\fR
Packit 3ff1e7
value in the dictionary\&. The value is returned in hexadecimal form\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
quvi\&.crypto\&.decrypt(<ciphertext>, <qoo>)
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Decrypt the
Packit 3ff1e7
\fIciphertext\fR\&. The
Packit 3ff1e7
\fIciphertext\fR
Packit 3ff1e7
is expected to be passed in hexadecimal form\&. See
Packit 3ff1e7
\fIquvi/hex\fR
Packit 3ff1e7
of the
Packit 3ff1e7
\fBquvi-modules\fR(7)
Packit 3ff1e7
for the conversion functions\&.
Packit 3ff1e7
Packit 3ff1e7
The second argument (\fIqoo\fR) is expected to be a dictionary containing the cipher options\&.
Packit 3ff1e7
Packit 3ff1e7
The function will return the
Packit 3ff1e7
\fIplaintext\fR
Packit 3ff1e7
value in the dictionary\&. This value is returned in hexadecimal form\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
quvi\&.crypto\&.hash(<value>, <qoo>)
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Generate a hash from the
Packit 3ff1e7
\fIvalue\fR\&. The
Packit 3ff1e7
\fIvalue\fR
Packit 3ff1e7
is expected to be passed in hexadecimal format\&. See
Packit 3ff1e7
\fIquvi/hex\fR
Packit 3ff1e7
of the
Packit 3ff1e7
\fBquvi-modules\fR(7)
Packit 3ff1e7
for the conversion functions\&.
Packit 3ff1e7
Packit 3ff1e7
The second argument (\fIqoo\fR) is expected to be a dictionary containing the hash options, e\&.g\&. the algorithm that should be used\&.
Packit 3ff1e7
Packit 3ff1e7
The function will return the
Packit 3ff1e7
\fIdigest\fR
Packit 3ff1e7
value in the dictionary\&. The value is returned in hexadecimal form\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.SS "HTTP"
Packit 3ff1e7
.sp
Packit 3ff1e7
The HTTP functions will return \fIresponse_code\fR along the other "RETURN VALUES", and the values specific to the HTTP function\&.
Packit 3ff1e7
.PP
Packit 3ff1e7
quvi\&.http\&.cookie(<VALUE>,<qoo>)
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Modify the libcurl session handle cookie settings that libquvi currently uses\&.
Packit 3ff1e7
Packit 3ff1e7
The second argument (\fIqoo\fR) is expected to be a dictionary containing the cookie options, e\&.g\&. the cookie mode that should be used\&.
Packit 3ff1e7
Packit 3ff1e7
The complete list of the available cookie modes can be found in the
Packit 3ff1e7
\fIquvi/const\fR
Packit 3ff1e7
module of the
Packit 3ff1e7
\fBquvi-modules\fR(7)\&. The mode names are named after their equivalent CURLOPT_COOKIE{SESSION,FILE,LIST,JAR} variable names\&. For a description of each option, see
Packit 3ff1e7
\fBlibcurl_easy_setopt\fR(3)\&.
Packit 3ff1e7
Packit 3ff1e7
This function will not return any additional values in the dictionary\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.sp
Packit 3ff1e7
.\}
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.it 1 an-trap
Packit 3ff1e7
.nr an-no-space-flag 1
Packit 3ff1e7
.nr an-break-flag 1
Packit 3ff1e7
.br
Packit 3ff1e7
.ps +1
Packit 3ff1e7
\fBNote\fR
Packit 3ff1e7
.ps -1
Packit 3ff1e7
.br
Packit 3ff1e7
.sp
Packit 3ff1e7
libquvi will ignore any calls to quvi\&.http\&.cookie unless QUVI_OPTION_ALLOW_COOKIES is QUVI_TRUE
Packit 3ff1e7
.sp .5v
Packit 3ff1e7
.RE
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.sp
Packit 3ff1e7
.\}
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.it 1 an-trap
Packit 3ff1e7
.nr an-no-space-flag 1
Packit 3ff1e7
.nr an-break-flag 1
Packit 3ff1e7
.br
Packit 3ff1e7
.ps +1
Packit 3ff1e7
\fBNote\fR
Packit 3ff1e7
.ps -1
Packit 3ff1e7
.br
Packit 3ff1e7
.sp
Packit 3ff1e7
libcurl will parse the received cookies and use them in the subsequent HTTP requests only if libquvi QUVI_OPTION_ALLOW_COOKIES is QUVI_TRUE
Packit 3ff1e7
.sp .5v
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
quvi\&.http\&.fetch(<URL>[,qoo])
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Fetch an URL over an HTTP connection\&.
Packit 3ff1e7
Packit 3ff1e7
The second argument (\fIqoo\fR) is expected to be a dictionary of additional
Packit 3ff1e7
\fIquvi object options\fR, if defined at all\&.
Packit 3ff1e7
Packit 3ff1e7
The function will return the
Packit 3ff1e7
\fIdata\fR
Packit 3ff1e7
value among the values in the returned dictionary\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
quvi\&.http\&.header(<VALUE>[,qoo])
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Add, remove or replace internally used libcurl HTTP headers\&.
Packit 3ff1e7
Packit 3ff1e7
The second argument (\fIqoo\fR) is expected to be a dictionary of additional
Packit 3ff1e7
\fIquvi object options\fR, if defined at all\&.
Packit 3ff1e7
Packit 3ff1e7
This function essentially wraps CURLOPT_HTTPHEADER, and will not return any additional values in the dictionary\&. See
Packit 3ff1e7
\fBcurl_easy_setopt\fR(3)
Packit 3ff1e7
for the full description of CURLOPT_HTTPHEADER\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.sp
Packit 3ff1e7
.\}
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.it 1 an-trap
Packit 3ff1e7
.nr an-no-space-flag 1
Packit 3ff1e7
.nr an-break-flag 1
Packit 3ff1e7
.br
Packit 3ff1e7
.ps +1
Packit 3ff1e7
\fBNote\fR
Packit 3ff1e7
.ps -1
Packit 3ff1e7
.br
Packit 3ff1e7
.sp
Packit 3ff1e7
To clear the custom headers, pass "" as the VALUE; the custom headers are also cleared automatically when a support script function \fIparse\fR is called
Packit 3ff1e7
.sp .5v
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
quvi\&.http\&.metainfo(<URL>[,qoo])
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Query the HTTP metainfo for the URL\&.
Packit 3ff1e7
Packit 3ff1e7
The second argument (\fIqoo\fR) is expected to be a dictionary of additional
Packit 3ff1e7
\fIquvi object options\fR, if defined at all\&.
Packit 3ff1e7
Packit 3ff1e7
The function will return the
Packit 3ff1e7
\fIcontent_length\fR
Packit 3ff1e7
and the
Packit 3ff1e7
\fIcontent_type\fR
Packit 3ff1e7
values among the values in the returned dictionary\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
quvi\&.http\&.resolve(<URL>[,qoo])
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Resolve an URL redirection\&.
Packit 3ff1e7
Packit 3ff1e7
The second argument (\fIqoo\fR) is expected to be a dictionary of additional
Packit 3ff1e7
\fIquvi object options\fR, if defined at all\&.
Packit 3ff1e7
Packit 3ff1e7
The function will return the
Packit 3ff1e7
\fIresolved_url\fR
Packit 3ff1e7
among the values in the returned dictionary\&. If the URL did not redirect to another location, the value of the
Packit 3ff1e7
\fIresolved_url\fR
Packit 3ff1e7
is left empty\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.SH "EXAMPLES"
Packit 3ff1e7
.SS "Base64"
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Base64 encode a string:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local H = require \*(Aqquvi/hex\*(Aq
Packit 3ff1e7
local s = H\&.to_hex(\*(Aqfoo\*(Aq) \-\- Pass in hexadecimal form
Packit 3ff1e7
Packit 3ff1e7
local r = quvi\&.base64\&.encode(s)
Packit 3ff1e7
print(r\&.base64)
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Reverse the process:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local r = quvi\&.base64\&.decode(r\&.base64)
Packit 3ff1e7
local s = H\&.to_str(r\&.plaintext)
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.RE
Packit 3ff1e7
.SS "Crypto"
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Encrypt plaintext:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local plaintext = \*(Aqf34481ec3cc627bacd5dc3fb08f273e6\*(Aq
Packit 3ff1e7
local key = \*(Aq00000000000000000000000000000000\*(Aq
Packit 3ff1e7
Packit 3ff1e7
local C = require \*(Aqquvi/const\*(Aq
Packit 3ff1e7
local o = {
Packit 3ff1e7
  [C\&.qoo_crypto_cipher_mode] = C\&.qoco_cipher_mode_cbc,
Packit 3ff1e7
  [C\&.qoo_crypto_algorithm] = \*(Aqaes\*(Aq,
Packit 3ff1e7
  [C\&.qoo_crypto_cipher_key = key
Packit 3ff1e7
}
Packit 3ff1e7
Packit 3ff1e7
local r = quvi\&.crypto\&.encrypt(plaintext, o)
Packit 3ff1e7
print(r\&.ciphertext)
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Reverse the process:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local r = quvi\&.crypto\&.decrypt(r\&.ciphertext, o)
Packit 3ff1e7
print(r\&.plaintext)
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Generate a hash (message digest):
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local H = require \*(Aqquvi/hex\*(Aq
Packit 3ff1e7
local s = H\&.to_hex(\*(Aqfoo\*(Aq) \-\- Pass in hexadecimal form
Packit 3ff1e7
Packit 3ff1e7
local C = require \*(Aqquvi/const\*(Aq
Packit 3ff1e7
local o = { [C\&.qoo_crypto_algorithm] = \*(Aqsha1\*(Aq }
Packit 3ff1e7
Packit 3ff1e7
local r = quvi\&.crypto\&.hash(s, o)
Packit 3ff1e7
print(r\&.digest)
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Same as above, but use the shorthand function:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local A = require \*(Aqquvi/hash\*(Aq
Packit 3ff1e7
local r = A\&.sha1sum(\*(Aqfoo\*(Aq)
Packit 3ff1e7
print(r)
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.RE
Packit 3ff1e7
.SS "HTTP"
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Dump the cookies in the memory to stdout:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local C = require \*(Aqquvi/const\*(Aq
Packit 3ff1e7
local o = { [C\&.qoo_http_cookie_mode] = C\&.qohco_mode_jar }
Packit 3ff1e7
local r = quvi\&.http\&.cookie(\*(Aq\-\*(Aq, o)
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Identical to the above but use the wrapper module:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local K = require \*(Aqquvi/http/cookie\*(Aq
Packit 3ff1e7
local r = K\&.jar(\*(Aq\-\*(Aq)
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Fetch an URL:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local r = quvi\&.http\&.fetch(\*(Aqhttp://example\&.com\*(Aq)
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.sp
Packit 3ff1e7
r\&.data would now hold the contents\&. If an error occurred, e\&.g\&. connection failed, the library would exit the process with an error\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Same as above, but handle the error in the script:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local C = require \*(Aqquvi/const\*(Aq
Packit 3ff1e7
local o = { [C\&.qoo_croak_if_error] = false }
Packit 3ff1e7
Packit 3ff1e7
local r = quvi\&.http\&.fetch(\*(Aqhttp://example\&.com\*(Aq, o)
Packit 3ff1e7
if r\&.quvi_code ~= C\&.qerr_ok then
Packit 3ff1e7
  local s =
Packit 3ff1e7
    string\&.format(\*(Aqquvi\&.http\&.fetch: %s (libquvi=%d, http/%d)\*(Aq,
Packit 3ff1e7
                  r\&.error_message, r\&.quvi_code, r\&.response_code)
Packit 3ff1e7
  error(s)
Packit 3ff1e7
end
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.sp
Packit 3ff1e7
By setting qoo_croak_if_error to
Packit 3ff1e7
\fIfalse\fR, 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\&.
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.sp
Packit 3ff1e7
.\}
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.it 1 an-trap
Packit 3ff1e7
.nr an-no-space-flag 1
Packit 3ff1e7
.nr an-break-flag 1
Packit 3ff1e7
.br
Packit 3ff1e7
.ps +1
Packit 3ff1e7
\fBNote\fR
Packit 3ff1e7
.ps -1
Packit 3ff1e7
.br
Packit 3ff1e7
Typically, the scripts would not need to handle the error
Packit 3ff1e7
.sp .5v
Packit 3ff1e7
.RE
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Force conversion from ISO\-8859\-1 to UTF\-8:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local C = require \*(Aqquvi/const\*(Aq
Packit 3ff1e7
local o = { [C\&.qoo_fetch_from_charset] = \*(AqISO\-8859\-1\*(Aq }
Packit 3ff1e7
local r = quvi\&.http\&.fetch(\*(Aqhttp://example\&.com\*(Aq, o)
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Override user\-agent header in the HTTP request:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local r = quvi\&.http\&.header(\*(AqUser\-Agent: foo/1\&.0\*(Aq)
Packit 3ff1e7
r = quvi\&.http\&.fetch(\&.\&.\&.)
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Disable an internal header in the HTTP request:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local r = quvi\&.http\&.header(\*(AqAccept:\*(Aq)
Packit 3ff1e7
r = quvi\&.http\&.fetch(\&.\&.\&.)
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Send a cookie in the HTTP request:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local r = quvi\&.http\&.header(\*(AqCookie: foo=1\*(Aq)
Packit 3ff1e7
r = quvi\&.http\&.fetch(\&.\&.\&.)
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Query metainfo for an URL:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local r = quvi\&.http\&.metainfo(\*(Aqhttp://is\&.gd/SKyg8m\*(Aq)
Packit 3ff1e7
print(r\&.content_length, r\&.content_type)
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.RE
Packit 3ff1e7
.sp
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.ie n \{\
Packit 3ff1e7
\h'-04'\(bu\h'+03'\c
Packit 3ff1e7
.\}
Packit 3ff1e7
.el \{\
Packit 3ff1e7
.sp -1
Packit 3ff1e7
.IP \(bu 2.3
Packit 3ff1e7
.\}
Packit 3ff1e7
Resolve URL redirection:
Packit 3ff1e7
.sp
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RS 4
Packit 3ff1e7
.\}
Packit 3ff1e7
.nf
Packit 3ff1e7
local r = quvi\&.http\&.resolve(\*(Aqhttp://is\&.gd/SKyg8m\*(Aq)
Packit 3ff1e7
if #r\&.resolved_url >0 then
Packit 3ff1e7
  print(\*(Aqnew location:\*(Aq, r\&.resolved_url)
Packit 3ff1e7
end
Packit 3ff1e7
.fi
Packit 3ff1e7
.if n \{\
Packit 3ff1e7
.RE
Packit 3ff1e7
.\}
Packit 3ff1e7
.RE
Packit 3ff1e7
.SH "SEE ALSO"
Packit 3ff1e7
.sp
Packit 3ff1e7
\fBlibquvi-scripts\fR(7), \fBlibquvi\fR(3), \fBquvi-modules\fR(7), \fBquvi-modules-3rdparty\fR(7)
Packit 3ff1e7
.SH "FURTHER RESOURCES"
Packit 3ff1e7
.PP
Packit 3ff1e7
Home
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Packit 3ff1e7
http://quvi\&.sourceforge\&.net/
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
Development code
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Packit 3ff1e7
git://repo\&.or\&.cz/libquvi\&.git
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
gitweb
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Packit 3ff1e7
http://repo\&.or\&.cz/w/libquvi\&.git
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
C API reference
Packit 3ff1e7
.RS 4
Packit 3ff1e7
The latest C API reference documentation may be viewed online at
Packit 3ff1e7
http://quvi\&.sourceforge\&.net/r/api/0\&.9/\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
GLib
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Packit 3ff1e7
http://developer\&.gnome\&.org/glib/stable/glib\-Base64\-Encoding\&.html
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
libcurl
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Packit 3ff1e7
http://curl\&.haxx\&.se/libcurl/c/curl_easy_setopt\&.html#CURLOPTUSERAGENT
Packit 3ff1e7
http://curl\&.haxx\&.se/libcurl/c/curl_easy_setopt\&.html#CURLOPTCOOKIE
Packit 3ff1e7
.RE
Packit 3ff1e7
.PP
Packit 3ff1e7
libgcrypt reference manual
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Packit 3ff1e7
http://www\&.gnupg\&.org/documentation/manuals/gcrypt/
Packit 3ff1e7
.RE
Packit 3ff1e7
.SH "AUTHORS"
Packit 3ff1e7
.PP
Packit 3ff1e7
Toni Gundogdu <legatvs@gmail\&.com>
Packit 3ff1e7
.RS 4
Packit 3ff1e7
Author\&.
Packit 3ff1e7
.RE
Packit 3ff1e7
.SH "REPORTING BUGS"
Packit 3ff1e7
.sp
Packit 3ff1e7
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\&.
Packit 3ff1e7
.SH "LICENSE"
Packit 3ff1e7
.sp
Packit 3ff1e7
libquvi is Free Software licensed under the GNU Affero GPLv3+
Packit 3ff1e7
.SH "LIBQUVI"
Packit 3ff1e7
.sp
Packit 3ff1e7
Part of the \fBlibquvi\fR(3) suite