LibSharing Manual | ||||
---|---|---|---|---|
#include <sharing-http.h> gboolean (*SharingHTTPProgressCallback) (SharingHTTP *http, guint64 bytes_sent, gpointer user_data); enum SharingHTTPRunResponse; SharingHTTP* sharing_http_new (); gint sharing_http_ref (SharingHTTP *self); gint sharing_http_unref (SharingHTTP *self); void sharing_http_set_connection (SharingHTTP *self, ConIcConnection *connection); ConIcConnection* sharing_http_get_connection (SharingHTTP *self); void sharing_http_set_timeouts (SharingHTTP *self, glong connecting_timeout, glong connection_timeout); void sharing_http_set_progress_callback (SharingHTTP *self, SharingHTTPProgressCallback callback, gpointer user_data); SharingHTTPRunResponse sharing_http_run (SharingHTTP *self, const gchar *url); void sharing_http_cancel (SharingHTTP *self); gboolean sharing_http_add_req_header (SharingHTTP *self, const gchar *name, const gchar *value); gboolean sharing_http_add_req_header_line (SharingHTTP *self, const gchar *line); void sharing_http_remove_req_headers (SharingHTTP *self); gboolean sharing_http_add_req_multipart_file (SharingHTTP *self, const gchar *name, const gchar *filepath, const gchar *type); gboolean sharing_http_add_req_multipart_file_with_filename (SharingHTTP *self, const gchar *name, const gchar *filepath, const gchar *type, const gchar *filename); gboolean sharing_http_add_req_multipart_data (SharingHTTP *self, const gchar *name, const gchar *data, gint data_len, const gchar *type); void sharing_http_clear_multiparts (SharingHTTP *self); void sharing_http_set_res_buffer_size_limit (SharingHTTP *self, gsize limit); gsize sharing_http_get_res_buffer_size_limit (SharingHTTP *self); gint sharing_http_get_res_code (SharingHTTP *self); const gchar* sharing_http_get_res_content (SharingHTTP *self, gsize *len); const gchar* sharing_http_get_res_body (SharingHTTP *self, gsize *len); void sharing_http_set_user_agent_name (SharingHTTP *self, const gchar *name);
SharingHTTP makes simple HTTP GET and POST requests to web services. It is designed to be used for uploading media content to services like Flickr and OVI.
SharingHTTP * http = sharing_http_new (); SharingHTTPRunResponse res; res = sharing_http_run (http, "http://example.com/post"); if (res == SHARING_HTTP_RUNRES_SUCCESS) { g_print ("Got response (%d): %s\n", sharing_http_get_res_code (http), sharing_http_get_res_body (http, NULL)); } else { g_printerr ("Couldn't get stuff from service\n"); } sharing_http_unref (http);
gboolean (*SharingHTTPProgressCallback) (SharingHTTP *http, guint64 bytes_sent, gpointer user_data);
Progress callback function prototype for SharingHTTP
http : |
Pointer to SharingHTTP object calling |
bytes_sent : |
How many bytes is sent |
user_data : |
User data pointer |
Returns : | TRUE to continue, FALSE to cancel transfer
|
typedef enum { SHARING_HTTP_RUNRES_SUCCESS, SHARING_HTTP_RUNRES_UNKNOWN_FAILURE, SHARING_HTTP_RUNRES_INVALID_PARAMETERS, SHARING_HTTP_RUNRES_CONNECTION_PROBLEM, SHARING_HTTP_RUNRES_CANCELLED, SHARING_HTTP_RUNRES_ALREADY_RUNNING } SharingHTTPRunResponse;
Response codes for sharing_http_run()
SharingHTTP* sharing_http_new ();
Create a new SharingHTTP object.
Returns : | a newly-allocated SharingHTTP with a reference count of 1.
Decrease ther reference count with sharing_http_unref() .
|
gint sharing_http_ref (SharingHTTP *self);
Increase the reference count of a SharingHTTP object.
self : |
Pointer to SharingHTTP object |
Returns : | the new reference count |
gint sharing_http_unref (SharingHTTP *self);
Decrease the reference count of a SharingHTTP object.
self : |
a SharingHTTP object |
Returns : | the new reference count. If the reference count is less than 1, the SharingHTTP object was freed |
void sharing_http_set_connection (SharingHTTP *self, ConIcConnection *connection);
Set the network connection used for HTTP requests.
self : |
a SharingHTTP object |
connection : |
the Internet connection to use |
ConIcConnection* sharing_http_get_connection (SharingHTTP *self);
Get the network connection used for HTTP requests.
self : |
a SharingHTTP object |
Returns : | the connection that will be used, or NULL if no connection is
specified
|
void sharing_http_set_timeouts (SharingHTTP *self, glong connecting_timeout, glong connection_timeout);
Change the timeout values of a SharingHTTP request.
self : |
a SharingHTTP object |
connecting_timeout : |
how long we wait connecting in seconds |
connection_timeout : |
how long the connection can last in seconds |
void sharing_http_set_progress_callback (SharingHTTP *self, SharingHTTPProgressCallback callback, gpointer user_data);
Change the callback called while a transfer is in progress.
self : |
a SharingHTTP object |
callback : |
the callback called while the transfer is in progress, or NULL
to unset
|
user_data : |
the data pointer passed to the callback function |
SharingHTTPRunResponse sharing_http_run (SharingHTTP *self, const gchar *url);
Run a SharingHTTP request and get a response.
self : |
a SharingHTTP object |
url : |
the URL where the request is sent |
Returns : | the result of the SharingHTTP request |
void sharing_http_cancel (SharingHTTP *self);
Cancel the current request of a SharingHTTP object.
self : |
a SharingHTTP object |
gboolean sharing_http_add_req_header (SharingHTTP *self, const gchar *name, const gchar *value);
Add a new header to an HTTP request, by combining the name and value into a single header line.
self : |
a SharingHTTP object |
name : |
name of the header to add |
value : |
value of the header to add |
see_also : |
sharing_http_add_req_header_line()
|
Returns : | TRUE if the header was added successfully, FALSE otherwise
|
gboolean sharing_http_add_req_header_line (SharingHTTP *self, const gchar *line);
Add a new header line to an HTTP request.
self : |
a SharingHTTP object |
line : |
a header line to add |
Returns : | TRUE if the header line was added successfully, FALSE otherwise
|
gboolean sharing_http_add_req_multipart_file (SharingHTTP *self, const gchar *name, const gchar *filepath, const gchar *type);
Add a file to a SharingHTTP request as a multipart, and substitue the on-disk file name for a specified alternative.
self : |
a SharingHTTP object |
name : |
the name of the part |
filepath : |
the path to the file |
type : |
the type of the part |
filename : |
a filename to use in the request, rather than the the on-disk
filename, or NULL to use the on-disk filename
|
Returns : | TRUE if the file was added successfully, FALSE otherwise
|
gboolean sharing_http_add_req_multipart_file_with_filename (SharingHTTP *self, const gchar *name, const gchar *filepath, const gchar *type, const gchar *filename);
gboolean sharing_http_add_req_multipart_data (SharingHTTP *self, const gchar *name, const gchar *data, gint data_len, const gchar *type);
Add data as a multipart to a SharingHTTP request.
self : |
a SharingHTTP object |
name : |
the name of the part |
data : |
the data to add to the request |
data_len : |
the length of the data, or -1 if the data is NULL -terminated
|
type : |
the content type of the data |
Returns : | TRUE if the data was added successfully, FALSE
|
void sharing_http_clear_multiparts (SharingHTTP *self);
Clear all multipart data from a SharingHTTP request.
self : |
a SharingHTTP object |
void sharing_http_set_res_buffer_size_limit (SharingHTTP *self, gsize limit);
Set the size limit of the response buffer of a SharingHTTP request.
self : |
a SharingHTTP object |
limit : |
the new size limit in bytes |
gsize sharing_http_get_res_buffer_size_limit (SharingHTTP *self);
Get the size limit of the response buffer of a SharingHTTP request.
self : |
a SharingHTTP object |
Returns : | the size limit of the response buffer in bytes, or 0 if no size limit is specified |
gint sharing_http_get_res_code (SharingHTTP *self);
Get the HTTP response code of a SharingHTTP request.
self : |
a SharingHTTP object |
Returns : | an HTTP response code, or -1 if no response code is specified |
const gchar* sharing_http_get_res_content (SharingHTTP *self, gsize *len);
Get the full content (both the header and body) of a SharingHTTP response.
self : |
a SharingHTTP object |
len : |
an output parameter for the length of the response content, which is
required if the content is not NULL -terminated
|
Returns : | the response content on success, or NULL otherwise
|
const gchar* sharing_http_get_res_body (SharingHTTP *self, gsize *len);
Get the body of a SharingHTTP response.
self : |
a SharingHTTP object |
len : |
an output parameter for the length of the response body, which is
required if the response is not NULL -terminated
|
Returns : | the response body on success, or NULL otherwise
|