GSK Reference Manual | ||||
---|---|---|---|---|
GskHttpAuthorization; GskHttpAuthenticate; GskHttpCharSet; GskHttpCookie; GskHttpLanguageSet; GskHttpMediaTypeSet; GskHttpContentEncodingSet; GskHttpTransferEncodingSet; GskHttpRangeSet; enum GskHttpStatus; enum GskHttpVerb; enum GskHttpRange; enum GskHttpContentEncoding; enum GskHttpTransferEncoding; enum GskHttpConnection; GskHttpMediaTypeSet* gsk_http_media_type_set_new (const char *type, const char *subtype, gfloat quality); void gsk_http_media_type_set_free (GskHttpMediaTypeSet *set); GskHttpCharSet* gsk_http_char_set_new (const char *charset_name, gfloat quality); void gsk_http_char_set_free (GskHttpCharSet *char_set); GskHttpContentEncodingSet* gsk_http_content_encoding_set_new (GskHttpContentEncoding encoding, gfloat quality); void gsk_http_content_encoding_set_free (GskHttpContentEncodingSet *encoding_set); GskHttpTransferEncodingSet* gsk_http_transfer_encoding_set_new (GskHttpTransferEncoding encoding, gfloat quality); void gsk_http_transfer_encoding_set_free (GskHttpTransferEncodingSet *encoding_set); GskHttpRangeSet* gsk_http_range_set_new (GskHttpRange range_type); void gsk_http_range_set_free (GskHttpRangeSet *set); GskHttpLanguageSet* gsk_http_language_set_new (const char *language, gfloat quality); void gsk_http_language_set_free (GskHttpLanguageSet *set); GskHttpAuthenticate* gsk_http_authenticate_new_basic (const char *realm); GskHttpAuthenticate* gsk_http_authenticate_new_digest (const char *realm, const char *domain, const char *nonce, const char *opaque, const char *algorithm); GskHttpAuthenticate* gsk_http_authenticate_new_unknown (const char *auth_scheme_name, const char *realm, const char *options); GskHttpAuthorization* gsk_http_authorization_new_basic (const char *realm, const char *user, const char *password); GskHttpAuthorization* gsk_http_authorization_new_respond_post (const GskHttpAuthenticate *, const char *user, const char *password, guint post_data_len, gconstpointer post_data, GError **error); GskHttpAuthorization* gsk_http_authorization_new_unknown (const char *auth_scheme_name, const char *response); const char* gsk_http_authorization_peek_response_digest (GskHttpAuthorization *); GskHttpAuthorization* gsk_http_authorization_copy (const GskHttpAuthorization *); void gsk_http_authorization_free (GskHttpAuthorization *); GskHttpAuthorization* gsk_http_authorization_new_digest (const char *realm, const char *domain, const char *nonce, const char *opaque, const char *algorithm, const char *user, const char *password, const char *response_digest, const char *entity_digest); GskHttpAuthorization* gsk_http_authorization_new_respond (const GskHttpAuthenticate *, const char *user, const char *password, GError **error); void gsk_http_authorization_set_nonce (GskHttpAuthorization *, const char *nonce); GskHttpCookie* gsk_http_cookie_new (const char *key, const char *value, const char *path, const char *domain, const char *expire_date, const char *comment, int max_age); GskHttpCookie* gsk_http_cookie_copy (const GskHttpCookie *orig); void gsk_http_cookie_free (GskHttpCookie *orig); GskHttpHeaderClass; GskHttpHeader; enum GskHttpParseFlags; GskHttpConnection gsk_http_header_get_connection (GskHttpHeader *header); GskHttpHeader* gsk_http_header_from_buffer (GskBuffer *input, gboolean is_request, GskHttpParseFlags flags, GError **error); void gsk_http_header_to_buffer (GskHttpHeader *header, GskBuffer *output); void gsk_http_header_set_content_encoding (GskHttpHeader *header, const char *encoding); #define gsk_http_header_get_content_encoding(header) #define gsk_http_header_set_date (header, date) #define gsk_http_header_get_date (header) void gsk_http_header_add_misc (GskHttpHeader *header, const char *key, const char *value); const char* gsk_http_header_lookup_misc (GskHttpHeader *header, const char *key); void gsk_http_header_remove_misc (GskHttpHeader *header, const char *key); GskHttpHeaderLineParser; gboolean (*GskHttpHeaderLineParserFunc) (GskHttpHeader *header, const char *text, gpointer data); GHashTable* gsk_http_header_get_parser_table (gboolean is_request); void (*GskHttpHeaderPrintFunc) (const char *text, gpointer data); void gsk_http_header_print (GskHttpHeader *http_header, GskHttpHeaderPrintFunc print_func, gpointer print_data); #define gsk_http_header_set_connection_type(header, connection_type) #define gsk_http_header_get_connection_type(header) #define gsk_http_header_set_transfer_encoding(header, enc) #define gsk_http_header_get_transfer_encoding(header) #define gsk_http_header_get_content_type(header) #define gsk_http_header_set_content_type(header, content_type) #define gsk_http_header_get_content_subtype(header) #define gsk_http_header_set_content_subtype(header, content_type) #define gsk_http_header_set_content_length(header, len) #define gsk_http_header_get_content_length(header) #define gsk_http_header_get_content_charset(header) void gsk_http_header_add_accepted_range (GskHttpHeader *header, GskHttpRange range); void gsk_http_header_add_pragma (GskHttpHeader *header, const char *pragma); #define gsk_http_header_set_content_charset(header, content_type) #define gsk_http_header_set_range (header, start, end) #define gsk_http_header_get_range_start (header) #define gsk_http_header_get_range_end (header) void gsk_http_header_set_string (gpointer http_header, char **p_str, const char *str); void gsk_http_header_set_string_val (gpointer http_header, char **p_str, const GValue *value); char* gsk_http_header_cut_string (gpointer http_header, const char *start, const char *end); void gsk_http_header_free_string (gpointer http_header, char *str); void gsk_http_header_set_connection_string (GskHttpHeader *header, const char *str); void gsk_http_header_set_content_encoding_string (GskHttpHeader *header, const char *str); void gsk_http_header_set_transfer_encoding_string (GskHttpHeader *header, const char *str); void gsk_http_header_set_version (GskHttpHeader *header, gint major, gint minor);
"connection" GskHttpConnection : Read / Write "connection-string" gchararray : Read / Write "content-charset" gchararray : Read / Write "content-encoding" GskHttpContentEncoding : Read / Write "content-encoding-string" gchararray : Read / Write "content-length" gint : Read / Write "content-subtype" gchararray : Read / Write "content-type" gchararray : Read / Write "date" gint : Read / Write "major-version" guint : Read / Write "minor-version" guint : Read / Write "range-end" gint : Read / Write "range-start" gint : Read / Write "transfer-encoding" GskHttpTransferEncoding : Read / Write "transfer-encoding-string" gchararray : Read / Write
The class provides methods and structure to parse and examime HTTP requests and responses.
typedef struct { GskHttpAuthMode mode; char *auth_scheme_name; union { struct { char *response; } unknown; struct { char *realm; char *user; char *password; } basic; struct { char *realm; char *domain; char *nonce; char *opaque; char *algorithm; char *user; char *password; char *response_digest; char *entity_digest; } digest; } info; } GskHttpAuthorization;
A response to a Authenticate: challenge. This string may provide a cryptographic proof that the client-side has access to a secret key.
From RFC 2616, Section 14.8: If a request is authenticated and a realm specified, the same credentials SHOULD be valid for all other requests within this realm (assuming that the authentication scheme itself does not require otherwise, such as credentials that vary according to a challenge value or using synchronized clocks).
The details of authentification are in a sister RFC, namely RFC 2617, "HTTP Authentication: Basic and Digest Access Authentication", by J Franks, et al.
typedef struct { GskHttpAuthMode mode; char *auth_scheme_name; char *realm; union { struct { char *options; } unknown; struct { } basic; struct { char *realm; char *domain; char *nonce; char *opaque; gboolean is_stale; char *algorithm; } digest; } info; } GskHttpAuthenticate;
XXX: should be a list of possible authenification strategies.
The WWW-Authenticate response-header field MUST be included in 401 (Unauthorized) response messages. The field value consists of at least one challenge that indicates the authentication scheme(s) and parameters applicable to the Request-URI.
typedef struct { /*< public: read-only >*/ char *charset_name; gfloat quality; /* -1 if not present */ } GskHttpCharSet;
A character set, along with optional quality factor.
The default quality is 1.0. See also gsk_http_request_add_charsets()
and gsk_http_response_set_charset()
. The HTTP standard does not concretely
define the Character Set strings that are mentioned in RFC 2616, Section 3.4.
But it recommends the documents
RFC 2279 "UTF-8, a transformation format of Unicode and ISO-10646"; and
RFC 2277 "IETF Policy on Character Sets and Languages".
...
char *charset_name ; |
the name of the character set, as recommended by IETF policy. |
gfloat quality ; |
ranking of the character set, on a range from 0 to 1. |
typedef struct { /*< public: read-only >*/ char *key; char *value; char *domain; char *path; char *expire_date; char *comment; int max_age; gboolean secure; /* default is FALSE */ guint version; /* default is 0, unspecified */ } GskHttpCookie;
See RFC 2964 "Use of HTTP State Management" and RFC 2965 "HTTP State Management Mechanism".
typedef struct { /*< public: read-only >*/ /* these give a language (with optional dialect specifier) */ char *language; gfloat quality; /* -1 if not present */ } GskHttpLanguageSet;
A list of natural languages that may be acceptable to the client. Examples: en, en-US, en-cockney, i-cherokee, x-pig-latin.
This is intended for human languages - computer languages are specifically prohibited.
Any two-letter primary tag ('en') must be an ISO-639 language abbreviation. Any two-letter subtag ('US') must be an ISO-3166 country abbreviation.
char *language ; |
the ASCII text of the language name. |
gfloat quality ; |
quality from 0 to 1, or -1 for unspecified. |
typedef struct { /*< public: read-only >*/ char *type; char *subtype; gfloat quality; /* -1 if not present */ } GskHttpMediaTypeSet;
A list of media types that the client can handle, and some quality factors to break ties.
char *type ; |
standard types like "image" or "text", or "x-"-prefixed types which are not well standardized. May be "*" to mean any major type. |
char *subtype ; |
specific format of data: "html" or "jpeg". May be "*" to mean any subtype. |
gfloat quality ; |
quality from 0 to 1, or -1 for unspecified. |
typedef struct { /*< public: read-only >*/ GskHttpContentEncoding encoding; gfloat quality; /* -1 if not present */ } GskHttpContentEncodingSet;
A node in a list of content-encodings allowed by the server. Each element may have an associated quality. If the quality is -1, then it is implicit, but for comparison purposes it should be treated at +1.
GskHttpContentEncoding encoding ; |
the encoding being rated. |
gfloat quality ; |
quality from 0 to 1, or -1 for unspecified. |
typedef struct { /*< public: read-only >*/ GskHttpTransferEncoding encoding; gfloat quality; /* -1 if not present */ } GskHttpTransferEncodingSet;
A node in a list of transfer-encodings allowed by the server. Each element may have an associated quality. If the quality is -1, then it is implicit, but for comparison purposes it should be treated at +1.
GskHttpTransferEncoding encoding ; |
the encoding being rated. |
gfloat quality ; |
quality from 0 to 1, or -1 for unspecified. |
typedef struct { /*< public: read-only >*/ GskHttpRange range_type; } GskHttpRangeSet;
A node in a list of range-specifiers allowed by the server. Each element may have an associated quality. If the quality is -1, then it is implicit, but for comparison purposes it should be treated at +1.
This mechanism is rather pointless, as there is only one valid unit allowed, 'bytes'.
GskHttpRange range_type ; |
the units permitted for partial content requests. |
typedef enum { GSK_HTTP_STATUS_CONTINUE = 100, GSK_HTTP_STATUS_SWITCHING_PROTOCOLS = 101, GSK_HTTP_STATUS_OK = 200, GSK_HTTP_STATUS_CREATED = 201, GSK_HTTP_STATUS_ACCEPTED = 202, GSK_HTTP_STATUS_NONAUTHORITATIVE_INFO = 203, GSK_HTTP_STATUS_NO_CONTENT = 204, GSK_HTTP_STATUS_RESET_CONTENT = 205, GSK_HTTP_STATUS_PARTIAL_CONTENT = 206, GSK_HTTP_STATUS_MULTIPLE_CHOICES = 300, GSK_HTTP_STATUS_MOVED_PERMANENTLY = 301, GSK_HTTP_STATUS_FOUND = 302, GSK_HTTP_STATUS_SEE_OTHER = 303, GSK_HTTP_STATUS_NOT_MODIFIED = 304, GSK_HTTP_STATUS_USE_PROXY = 305, GSK_HTTP_STATUS_TEMPORARY_REDIRECT = 306, GSK_HTTP_STATUS_BAD_REQUEST = 400, GSK_HTTP_STATUS_UNAUTHORIZED = 401, GSK_HTTP_STATUS_PAYMENT_REQUIRED = 402, GSK_HTTP_STATUS_FORBIDDEN = 403, GSK_HTTP_STATUS_NOT_FOUND = 404, GSK_HTTP_STATUS_METHOD_NOT_ALLOWED = 405, GSK_HTTP_STATUS_NOT_ACCEPTABLE = 406, GSK_HTTP_STATUS_PROXY_AUTH_REQUIRED = 407, GSK_HTTP_STATUS_REQUEST_TIMEOUT = 408, GSK_HTTP_STATUS_CONFLICT = 409, GSK_HTTP_STATUS_GONE = 410, GSK_HTTP_STATUS_LENGTH_REQUIRED = 411, GSK_HTTP_STATUS_PRECONDITION_FAILED = 412, GSK_HTTP_STATUS_ENTITY_TOO_LARGE = 413, GSK_HTTP_STATUS_URI_TOO_LARGE = 414, GSK_HTTP_STATUS_UNSUPPORTED_MEDIA = 415, GSK_HTTP_STATUS_BAD_RANGE = 416, GSK_HTTP_STATUS_EXPECTATION_FAILED = 417, GSK_HTTP_STATUS_INTERNAL_SERVER_ERROR = 500, GSK_HTTP_STATUS_NOT_IMPLEMENTED = 501, GSK_HTTP_STATUS_BAD_GATEWAY = 502, GSK_HTTP_STATUS_SERVICE_UNAVAILABLE = 503, GSK_HTTP_STATUS_GATEWAY_TIMEOUT = 504, GSK_HTTP_STATUS_UNSUPPORTED_VERSION = 505 } GskHttpStatus;
Status code corresponding to the number on the first line of an HTTP response. This enum takes on the same numerical value.
typedef enum { GSK_HTTP_VERB_GET, GSK_HTTP_VERB_POST, GSK_HTTP_VERB_PUT, GSK_HTTP_VERB_HEAD, GSK_HTTP_VERB_OPTIONS, GSK_HTTP_VERB_DELETE, GSK_HTTP_VERB_TRACE, GSK_HTTP_VERB_CONNECT } GskHttpVerb;
The type of action requested by the User or User-Agent. It is common practice that GET and HEAD requests are "safe"-- they are intended for information retrieval are should never have harmful side-effects.
Some additional methods are idempotent, meaning that running the command more than once SHOULD have no effect. In particular, PUT, DELETE, OPTIONS, and TRACE have this property, as well as the safe methods GET and HEAD.
typedef enum { GSK_HTTP_RANGE_BYTES } GskHttpRange;
This gives units, or allowed units, for the Content-Range. This is used when you want to retreive part of a document. (Not all servers support that, of course.)
Currently, only bytes are allowed.
typedef enum { GSK_HTTP_CONTENT_ENCODING_IDENTITY, GSK_HTTP_CONTENT_ENCODING_GZIP, GSK_HTTP_CONTENT_ENCODING_COMPRESS, GSK_HTTP_CONTENT_ENCODING_UNRECOGNIZED = 0x100 } GskHttpContentEncoding;
This gives ways in which content can be encoded. The default encoding is "identity", which means that the data is not re-encoded as all: it is sent as itself.
Currently, all non-identity encodings are compression schemes.
XXX: the spec says that multiple content-encodings are allowed, and that they are applied left-to-right. But we won't even parse such a line, due to the limited types of content-encoding we are aware of.
typedef enum { GSK_HTTP_TRANSFER_ENCODING_NONE = 0, GSK_HTTP_TRANSFER_ENCODING_CHUNKED = 1, GSK_HTTP_TRANSFER_ENCODING_UNRECOGNIZED = 0x100 } GskHttpTransferEncoding;
[RFC 2616, Section 3.6] Transfer-coding values are used to indicate an encoding transformation that has been, can be, or may need to be applied to an entity-body in order to ensure "safe transport" through the network.
typedef enum { GSK_HTTP_CONNECTION_NONE = 0, GSK_HTTP_CONNECTION_CLOSE = 1, GSK_HTTP_CONNECTION_KEEPALIVE = 2, } GskHttpConnection;
Specify what should happen once the transaction is done.
This is used to support persistent connections, which can be more efficient than making a new connection for each transaction.
GskHttpMediaTypeSet* gsk_http_media_type_set_new (const char *type, const char *subtype, gfloat quality);
Allocate a new node in a GskHttpMediaTypeSet list.
type : |
major type of the media to allow, like "text" or "image". An asterisk can be used to allow any major type. |
subtype : |
format of the media to allow, like "html", "plain" or "jpeg". An asterisk can be used to allow any format. |
quality : |
relative preference for this encoding. -1 means "not specified", which has a default of 1. |
Returns : | the newly allocated node. |
void gsk_http_media_type_set_free (GskHttpMediaTypeSet *set);
Free the memory associated with the media-type-set node.
set : |
the media type set to deallocate. |
GskHttpCharSet* gsk_http_char_set_new (const char *charset_name, gfloat quality);
Allocate a single GskHttpCharSet preference. You may wish to build a list of these.
charset_name : |
name of the character set. |
quality : |
quality from 0 to 1, or -1 if no quality flag was given. |
Returns : | the new character-set. |
void gsk_http_char_set_free (GskHttpCharSet *char_set);
Deallocate a GskHttpCharSet.
char_set : |
character set to free. |
GskHttpContentEncodingSet* gsk_http_content_encoding_set_new (GskHttpContentEncoding encoding, gfloat quality);
Allocate a new node in a GskHttpContentEncodingSet list.
encoding : |
the encoding to list a preference for. |
quality : |
relative preference for this encoding. A value of -1 means that the quality was omitted, which means it should be treated as 1. |
Returns : | the new encoding node. |
void gsk_http_content_encoding_set_free (GskHttpContentEncodingSet *encoding_set);
Deallocate the encoding.
encoding_set : |
the encoding set to deallocate. |
GskHttpTransferEncodingSet* gsk_http_transfer_encoding_set_new (GskHttpTransferEncoding encoding, gfloat quality);
Allocate a new node in a GskHttpTransferEncodingSet list.
encoding : |
the encoding to list a preference for. |
quality : |
relative preference for this encoding. A value of -1 means that the quality was omitted, which means it should be treated as 1. |
Returns : | the new encoding node. |
void gsk_http_transfer_encoding_set_free (GskHttpTransferEncodingSet *encoding_set);
Deallocate the encoding (a single node in the list).
encoding_set : |
the encoding set to deallocate. |
GskHttpRangeSet* gsk_http_range_set_new (GskHttpRange range_type);
Allocate a node telling what units are available for specifying partial content.
range_type : |
allocate a new node in a allowable range units list. |
Returns : | the newly allocated node. |
void gsk_http_range_set_free (GskHttpRangeSet *set);
Free the memory associated with the node in the range-set.
set : |
range-unit node to deallocate. |
GskHttpLanguageSet* gsk_http_language_set_new (const char *language, gfloat quality);
Allocate a new node in a GskHttpLanguageSet list. Though any ASCII string is basically allowed, a two letter language code (en, de, pl, it, etc) is the usual start of the language name; a two letter country code (US, UK, DE, etc) is the second more optional part, like "en-US".
language : |
the human language code to list a preference for. |
quality : |
relative preference for this encoding. A value of -1 means that the quality was omitted, which means it should be treated as 1. |
Returns : | the new language node. |
void gsk_http_language_set_free (GskHttpLanguageSet *set);
Deallocate the node in the language-set.
set : |
the language set node to deallocate. |
GskHttpAuthenticate* gsk_http_authenticate_new_basic (const char *realm);
Create an GskHttpAuthenticate for basic authentication. Basic authentication is very insecure: the password is merely transmitted base64 encoded.
realm : |
the area on the site to authenticate for. This is the name used by the RFC. |
Returns : | the new challenge. |
GskHttpAuthenticate* gsk_http_authenticate_new_digest (const char *realm, const char *domain, const char *nonce, const char *opaque, const char *algorithm);
Create an GskHttpAuthenticate for Digest authentication. Digest authentication improves Basic authentication by using a hash of the password.
realm : |
the area on the site to authenticate for. |
domain : |
|
nonce : |
value hashed into the digest to keep it secure against replay attacks. |
opaque : |
value which must be sent back to the server, which the client does not interpret. |
algorithm : |
digest algorithm. Only MD5 is supported for now, and is equivalent to specifying NULL. |
Returns : | the new challenge. |
GskHttpAuthenticate* gsk_http_authenticate_new_unknown (const char *auth_scheme_name, const char *realm, const char *options);
Handling your special purpose authenticator. Note that Basic and Digest authenticator parsers are built-in to GSK, this is only for other types.
It is given from the server to the client. The client must response (in another message) with an authorization.
The purpose of a challenge in cryptographic systems is to randomize the transaction so that an attacker cannot use the same Authorization lines to get access to a machine.
Of course, if you use an insecure transport layer, it is MUCH harder to make things secure -- using SSL is recommended.
Some WWW-Authenticate header is required in a GSK_HTTP_STATUS_UNAUTHORIZED response message.
auth_scheme_name : |
|
realm : |
|
options : |
|
Returns : | the new challenge. |
GskHttpAuthorization* gsk_http_authorization_new_basic (const char *realm, const char *user, const char *password);
Basic HTTP authentication response. Not very secure because your password is provided plain-text.
realm : |
the area on the site to authenticate for. |
user : |
name of the account to authenticate for. |
password : |
password of the account to authenticate for. |
Returns : | the response to the authentication request. |
GskHttpAuthorization* gsk_http_authorization_new_respond_post (const GskHttpAuthenticate *, const char *user, const char *password, guint post_data_len, gconstpointer post_data, GError **error);
Param1 : |
|
user : |
|
password : |
|
post_data_len : |
|
post_data : |
|
error : |
|
Returns : |
GskHttpAuthorization* gsk_http_authorization_new_unknown (const char *auth_scheme_name, const char *response);
Arbitrary authorization response.
We recommend you use gsk_http_authorization_new_digest()
instead, or gsk_http_authorization_new_basic()
if that's all
the server can do.
auth_scheme_name : |
name of the authentification scheme. |
response : |
|
Returns : | the response to the authentication request. |
const char* gsk_http_authorization_peek_response_digest (GskHttpAuthorization *);
Param1 : |
|
Returns : |
GskHttpAuthorization* gsk_http_authorization_copy (const GskHttpAuthorization *);
Param1 : |
|
Returns : |
GskHttpAuthorization* gsk_http_authorization_new_digest (const char *realm, const char *domain, const char *nonce, const char *opaque, const char *algorithm, const char *user, const char *password, const char *response_digest, const char *entity_digest);
Create a new Digest-based authentication response. Many of the parameters must match the Authenticate header.
The response_digest is a value computed from nonce, user, and password. The security of Digest authentication derives from the difficulty of computing the password from the digest, since the password itself is not transmitted cleartext.
realm : |
the area on the site to authenticate for. |
domain : |
|
nonce : |
value hashed into the digest to keep it secure against replay attacks. |
opaque : |
value which must be sent back to the server, which the client does not interpret. |
algorithm : |
digest algorithm. Only MD5 is supported for now, and is equivalent to specifying NULL. |
user : |
name of the account to authenticate for. |
password : |
password of the account to authenticate for. [unnecessary if you have the response digest] This value is NOT transmitted to the remote host. |
response_digest : |
the securely-hashed response. If NULL, Gsk will compute the response. |
entity_digest : |
the securely-hashed information about your POST content. |
Returns : | the response to the authentication request. |
GskHttpAuthorization* gsk_http_authorization_new_respond (const GskHttpAuthenticate *, const char *user, const char *password, GError **error);
Attempt to use the given user/password pair as authentication information for the given request.
Param1 : |
|
user : |
the username of the account (or whatever) to use. |
password : |
password of the account to authenticate for. |
error : |
optional place to put the error if something goes wrong. |
Returns : | the new response, or NULL if something goes wrong. |
void gsk_http_authorization_set_nonce (GskHttpAuthorization *, const char *nonce);
Param1 : |
|
nonce : |
GskHttpCookie* gsk_http_cookie_new (const char *key, const char *value, const char *path, const char *domain, const char *expire_date, const char *comment, int max_age);
Allocate a cookie. Once allocated, it cannot be changed.
Cookies are a mechanism for tracking users. The remote host sends a Set-Cookie directive which, should be client choose to accept it, may be sent with subsequent relevant requests.
NOTE: GSK does not automatically handle cookies. That is up to the application.
TODO: GSK should have a cookie database mechanism.
See RFC 2964 and 2965.
key : |
token used to identify the cookie. |
value : |
information associated with the cookie. |
path : |
applicable area in server directory structure for this cookie. |
domain : |
domain names this cookie applies to. |
expire_date : |
when this cookie should be discarded. |
comment : |
miscellaneous information about this cookie. |
max_age : |
maximum number of seconds that this cookie should be retained. |
Returns : | the newly allocated cookie. |
GskHttpCookie* gsk_http_cookie_copy (const GskHttpCookie *orig);
Copy a cookie.
orig : |
the cookie to copy. |
Returns : | the new cookie. |
void gsk_http_cookie_free (GskHttpCookie *orig);
Free the memory associated with the cookie.
orig : |
the cookie to deallocate. |
typedef struct { GObjectClass base_class; } GskHttpHeaderClass;
Virtual functions of HTTP headers (none, for now).
GObjectClass base_class ; |
object system. |
typedef struct { guint16 http_major_version; /* always 1 */ guint16 http_minor_version; GskHttpConnection connection_type; GskHttpTransferEncoding transfer_encoding_type; GskHttpContentEncoding content_encoding_type; GskHttpRangeSet *accepted_range_units; /* Accept-Ranges */ char *unrecognized_transfer_encoding; char *unrecognized_content_encoding; char *content_encoding; /* Content-Encoding */ unsigned has_content_type : 1; char *content_type; /* Content-Type */ char *content_subtype; char *content_charset; GSList *content_additional; /* NULL-terminated array of language tags from the Content-Language * header, or NULL if header not present. */ char **content_languages; /* Bytes ranges. Both with be == -1 if there is no Range tag. */ int range_start; int range_end; /* may be set to ((time_t) -1) to omit them. */ glong date; /* From the Content-Length header. */ gssize content_length; /* Key/value searchable header lines. */ GHashTable *header_lines; /* Error messages. */ GSList *errors; /* list of char* Error: directives */ /* General headers. */ GSList *pragmas; /* and actual accumulated parse error (a bit of a hack) */ GError *g_error; } GskHttpHeader;
Base class for all HTTP headers.
guint16 http_major_version ; |
The major version of the HTTP protocol, according to the header. This must always by '1'. |
guint16 http_minor_version ; |
The minor version of the HTTP protocol, according to the header. This must always by '0' or '1'. |
GskHttpConnection connection_type ; |
Whether to close or keep alive the connection at the end of the current transaction. |
GskHttpTransferEncoding transfer_encoding_type ; |
Type of encoding used to package the header for transmission across the transport. |
GskHttpContentEncoding content_encoding_type ; |
Type of encoding used encode the content. This is mostly used to support compressed transactions. |
GskHttpRangeSet *accepted_range_units ; |
|
char *unrecognized_transfer_encoding ; |
A string, if the header has an unknown transfer encoding. |
char *unrecognized_content_encoding ; |
A string, if the header has an unknown content encoding. |
char *content_encoding ; |
|
char *content_type ; |
major type of the content. Typical examples are 'text' or 'image'. Types beginning with 'x-' are for unstandardized extensions. |
char *content_subtype ; |
minor type of the content. Typical examples depend on the major type. For 'text', one encounters 'plain' and 'html'. For 'image', one encounters 'jpeg', 'png', 'gif' etc. |
char *content_charset ; |
|
GSList *content_additional ; |
|
char **content_languages ; |
|
int range_start ; |
First byte to transmit, or -1 if not using partial ranges. |
int range_end ; |
Immediately after the last byte to transport, or -1 if no end range given. |
glong date ; |
The date of the transaction, in UNIX time, or -1 if not specified. |
gssize content_length ; |
The length of the content associated with this side of this transaction. |
GHashTable *header_lines ; |
Hash-table of key->value mappings, for headers which are not handled directly by this implementation. |
GSList *errors ; |
|
GSList *pragmas ; |
A list of strings from Pragma: header lines. |
GError *g_error ; |
A GError that indicates what last went wrong with this header. Usually NULL. |
typedef enum { GSK_HTTP_PARSE_STRICT = (1 << 0), /* instead of giving up on unknown headers, just * add them as misc-headers */ GSK_HTTP_PARSE_SAVE_ERRORS = (1 << 1) } GskHttpParseFlags;
Flags which affect how headers are parsed.
GskHttpConnection gsk_http_header_get_connection (GskHttpHeader *header);
Returns the connection semantics. Note that this will never return GSK_HTTP_CONNECTION_NONE; it will figure out if the default is keep-alive or close.
Use gsk_http_header_get_connection_type()
to get the
actual connection-type that will be transmitted over the
wire (with NONE meaning that there is no Connection: header).
Note that the client can make Connection: requests, but the server is allowed to ignore keep-alive directives. So calling this on the request gets the client's suggestions, and calling this on the response gets the server's intentions.
header : |
the HTTP header to query. |
Returns : | the connection semantics. |
GskHttpHeader* gsk_http_header_from_buffer (GskBuffer *input, gboolean is_request, GskHttpParseFlags flags, GError **error);
Parse the HTTP header from the buffer.
input : |
the buffer from which to parse the request. |
is_request : |
whether this is a request; otherwise, it is a response. |
flags : |
preferences for parsing. |
error : |
|
Returns : | a new reference to the header. |
void gsk_http_header_to_buffer (GskHttpHeader *header, GskBuffer *output);
Appends an HTTP header into a buffer.
header : |
the HTTP header to write into the buffer. |
output : |
the buffer to store the header in, as text. |
void gsk_http_header_set_content_encoding (GskHttpHeader *header, const char *encoding);
Set encoding method for the content. The actual encoding is done transparently by GskHttpClient and GskHttpServer usually. Encoding is only used for POST and PUT requests and any response that has a body (most do). The default is the identity encoding.
header : |
the header to affect. |
encoding : |
the new content encoding method. |
#define gsk_http_header_get_content_encoding(header)
Get encoding method for the content. (The actual encoding is done transparently by GskHttpClient and GskHttpServer usually.)
header : |
the header to query. |
#define gsk_http_header_set_date(header, date)
The date of the request. Defines as the same as "orig-date in RFC 822". Basically, clients should only send dates with POST or PUT data, and even then it is optional. Servers should usually send dates, but if there is no content then the date is optional. The precise rules are set out in [RFC 2616, Section 14.18].
header : |
The HTTP header to affect. |
date : |
The date, as a unix time number. |
#define gsk_http_header_get_date(header)
Get the Date on the request, or -1 if not set.
header : |
The HTTP header to query. |
void gsk_http_header_add_misc (GskHttpHeader *header, const char *key, const char *value);
Add a raw header line to the header, with an associated value.
header : |
the header to affect. |
key : |
a case-insensitive ASCII string for the key for this foreign header. This key should not be a standard HTTP tag. |
value : |
a case-sensitive value for that key. |
const char* gsk_http_header_lookup_misc (GskHttpHeader *header, const char *key);
Lookup a miscellaneous HTTP header. All headers that begin with X- are stored in here.
header : |
the header to query. |
key : |
a case-insensitive ASCII string for the key for this foreign header. This key should not be a standard HTTP tag. returns: value of the key. |
Returns : |
void gsk_http_header_remove_misc (GskHttpHeader *header, const char *key);
Remove a raw header line from the header.
header : |
the header to affect. |
key : |
a case-insensitive ASCII string for the key for this foreign header. This key should not be a standard HTTP tag. |
typedef struct { const char *name; GskHttpHeaderLineParserFunc func; gpointer data; } GskHttpHeaderLineParser;
A structure giving a HTTP header line field-name, and a function to parse the value of that kind of field.
const char *name ; |
the name of the field in lowercase, i.e. "date" or "content-length". |
GskHttpHeaderLineParserFunc func ; |
function to call to parse the value of that field. So if a "Date: Thu Jun 5 06:27:39 PDT 2003" line comes in, then this function will be called with "Thu Jun 5 06:27:39 PDT 2003", and a header to add that information to. |
gpointer data ; |
data to pass to function. |
gboolean (*GskHttpHeaderLineParserFunc) (GskHttpHeader *header, const char *text, gpointer data);
A function to be invoked with the value of a specific type of header-line.
This will add information to header
frequently.
If it encounters a parse error, it can indicate that by returning FALSE.
header : |
header to affect by this line. |
text : |
value of the header line. That is, everything that follows
the initial colon and space(s). So for the header line "Content-Length: 42",
the text should merely be "42".
|
data : |
pointer from the GskHttpHeaderLineParser to give auxilliary info. |
Returns : | whether it was able to process the value. |
GHashTable* gsk_http_header_get_parser_table (gboolean is_request);
Obtain a hash-table which maps lowercased HTTP header keys to GskHttpHeaderLineParser's. There are different maps for requests and responses.
is_request : |
whether to get the parse table for request (versus for responses). |
Returns : | the hash-table mapping, which is global and should not be freed. |
void (*GskHttpHeaderPrintFunc) (const char *text, gpointer data);
Function to print a line of HTTP header data.
text : |
NUL-terminated line of HTTP header. |
data : |
print_data argument of gsk_http_header_print() .
|
void gsk_http_header_print (GskHttpHeader *http_header, GskHttpHeaderPrintFunc print_func, gpointer print_data);
Print the HTTP header line-by-line, through a generic printing function. This could conceivable save memory and allow better streaming.
http_header : |
the header to output, line-by-line. |
print_func : |
a function to call on each line of output. |
print_data : |
data to pass to print_func .
|
#define gsk_http_header_set_connection_type(header, connection_type)
Change the Connection type reflected in this header.
[From RFC 2616, Section 14.10] The Connection general-header field allows the sender to specify options that are desired for that particular connection and MUST NOT be communicated by proxies over further connections.
header : |
the header to affect. |
connection_type : |
the new Connection type. |
#define gsk_http_header_get_connection_type(header)
Get the Connection type reflected in this header.
header : |
the header to query. |
#define gsk_http_header_set_transfer_encoding(header, enc)
[From RFC 2616, Section 14.41] The Transfer-Encoding general-header field indicates what (if any) type of transformation has been applied to the message body in order to safely transfer it between the sender and the recipient. This differs from the content-coding in that the transfer-coding is a property of the message, not of the entity.
If multiple encodings have been applied to an entity, the transfer- codings MUST be listed in the order in which they were applied. Additional information about the encoding parameters MAY be provided by other entity-header fields not defined by this specification.
header : |
the header to affect. |
enc : |
the new encoding. |
#define gsk_http_header_get_transfer_encoding(header)
Get the transfer encoding of this message.
header : |
the header to query. |
#define gsk_http_header_get_content_type(header)
Get the major type of the content. Any header which has content SHOULD have a content-type. Typical examples are 'text' and 'image'.
XXX: need a reference to a list of content types!!!!
header : |
the header to query. |
#define gsk_http_header_set_content_type(header, content_type)
Set the major type of the content. Any header which has content SHOULD have a content-type. Typical examples are 'text' and 'image'.
XXX: need a reference to a list of content types!!!!
header : |
the header to affect. |
content_type : |
the new major type of the header. |
#define gsk_http_header_get_content_subtype(header)
Get the minor subtype of the content. Any header which has content SHOULD have a content-subtype.
XXX: need a reference to a list of content types!!!!
header : |
the header to query. |
#define gsk_http_header_set_content_subtype(header, content_type)
Set the minor type of the content. Any header which has content SHOULD have a content-subtype.
XXX: need a reference to a list of content types!!!!
header : |
the header to affect. |
content_type : |
the new content subtype. |
#define gsk_http_header_set_content_length(header, len)
Set the indicated length of the content. This may be used for POST and PUT requests as well as most responses.
header : |
the header to affect. |
len : |
the exact length of the content, in bytes, or -1 if the length cannot be predetermined. |
#define gsk_http_header_get_content_length(header)
Get the indicated length of the content. This may be used in POST and PUT requests as well as most responses. If the content has no specified length, or no length is allowed, then -1 is returned.
header : |
the header to query. |
void gsk_http_header_add_accepted_range (GskHttpHeader *header, GskHttpRange range);
header : |
|
range : |
void gsk_http_header_add_pragma (GskHttpHeader *header, const char *pragma);
header : |
|
pragma : |
#define gsk_http_header_set_content_charset(header, content_type)
header : |
|
content_type : |
#define gsk_http_header_set_range(header, start, end)
If retrieving partial content, set the range in bytes of that content.
header : |
the header to affect. |
start : |
start of the range in bytes. |
end : |
end of the range in bytes. |
#define gsk_http_header_get_range_start(header)
If retrieving partial content, get the offset of the first byte to receive.
header : |
the header to query. |
#define gsk_http_header_get_range_end(header)
If retrieving partial content, get the offset of the last byte to receive.
header : |
the header to query. |
void gsk_http_header_set_string (gpointer http_header, char **p_str, const char *str);
Private function to set a string in a HTTP header. (Currently this uses strdup, but we may eventually switch allocation strategies).
http_header : |
HTTP header which owns the string. |
p_str : |
pointer to the string's location. |
str : |
string to copy and assign to *p_str .
(May be NULL)
|
void gsk_http_header_set_string_val (gpointer http_header, char **p_str, const GValue *value);
Private function to set a string in a HTTP header from a value. This is used from the set_property methods in the various HTTP header class implementations.
http_header : |
HTTP header which owns the string. |
p_str : |
pointer to the string's location. |
value : |
a value which holds a string. |
char* gsk_http_header_cut_string (gpointer http_header, const char *start, const char *end);
private. Copy a substring assuming that http_header is responsible for it.
http_header : |
HTTP header which owns the string. |
start : |
the start of the string |
end : |
immediately past the input string. |
Returns : | the NUL-terminated copy of the string between start
and end .
|
void gsk_http_header_free_string (gpointer http_header, char *str);
Deallocate a string allocated with
gsk_http_header_set_string()
,
gsk_http_header_set_string_val()
,
gsk_http_header_cut_string()
.
http_header : |
HTTP header which owns the string. |
str : |
the string to free. |
void gsk_http_header_set_connection_string (GskHttpHeader *header, const char *str);
Change the Connection type reflected in this header.
[From RFC 2616, Section 14.10] The Connection general-header field allows the sender to specify options that are desired for that particular connection and MUST NOT be communicated by proxies over further connections.
header : |
the HTTP header to affect. |
str : |
connection type, as a string. (The string is exactly the same as that which is found literally in the header.) |
void gsk_http_header_set_content_encoding_string (GskHttpHeader *header, const char *str);
Change the Content-Encoding type reflected in this header.
The actual encoding is done transparently by GskHttpClient and GskHttpServer usually. Encoding is only used for POST and PUT requests and any response that has a body (most do). The default is the identity encoding.
header : |
the HTTP header to affect. |
str : |
content-encoding type, as a string. (The string is exactly the same as that which is found literally in the header.) |
void gsk_http_header_set_transfer_encoding_string (GskHttpHeader *header, const char *str);
Set the Transfer-Encoding type, as a string.
[From RFC 2616, Section 14.41] The Transfer-Encoding general-header field indicates what (if any) type of transformation has been applied to the message body in order to safely transfer it between the sender and the recipient. This differs from the content-coding in that the transfer-coding is a property of the message, not of the entity.
header : |
the HTTP header to affect. |
str : |
transfer-encoding type, as a string. (The string is exactly the same as that which is found literally in the header.) |
void gsk_http_header_set_version (GskHttpHeader *header, gint major, gint minor);
Set the major and minor versions;
for example, to use HTTP 1.0, one would set major
to 1,
and minor
to 0.
In addition to setting the version numbers, this function suppresses features not available in the respective http implementations.
Only HTTP 1.0 and 1.1 are supported.
header : |
the HTTP header to affect. |
major : |
the major HTTP version number. |
minor : |
the minor HTTP version number. |
connection
" property"connection" GskHttpConnection : Read / Write
The type of connection. See gsk_http_header_set_connection_type()
for more documentation.
Default value: GSK_HTTP_CONNECTION_NONE
connection-string
" property"connection-string" gchararray : Read / Write
The type of connection as a string.
Default value: "close"
content-charset
" property"content-charset" gchararray : Read / Write
The character set used for text content.
Default value: NULL
content-encoding
" property"content-encoding" GskHttpContentEncoding : Read / Write
The way the content is encoded, see GskHttpConnection for more documentation.
Default value: GSK_HTTP_CONTENT_ENCODING_IDENTITY
content-encoding-string
" property"content-encoding-string" gchararray : Read / Write
The way the content is encoded, as a string. Typical values are "identity", "gzip" and "compress".
Default value: "identity"
content-length
" property"content-length" gint : Read / Write
Length of content associated with this header.
Allowed values: >= -1
Default value: -1
content-subtype
" property"content-subtype" gchararray : Read / Write
The minor type of content.
Default value: NULL
content-type
" property"content-type" gchararray : Read / Write
The major type of content.
Default value: NULL
date
" property"date" gint : Read / Write
the date of the content of this response.
Allowed values: >= -1
Default value: -1
major-version
" property"major-version" guint : Read / Write
major version number of the HTTP protocol. Always 1.
Allowed values: <= 2
Default value: 1
minor-version
" property"minor-version" guint : Read / Write
minor version number of the HTTP protocol. Always 0 or 1, usually 1, indicating HTTP/1.1.
Allowed values: <= 10
Default value: 1
range-end
" property"range-end" gint : Read / Write
end of the data.
Allowed values: >= -1
Default value: -1
range-start
" property"range-start" gint : Read / Write
beginning of the data.
Allowed values: >= -1
Default value: -1
transfer-encoding
" property"transfer-encoding" GskHttpTransferEncoding : Read / Write
type of transfer encoding.
Default value: GSK_HTTP_TRANSFER_ENCODING_NONE