SharingHTTP

SharingHTTP — Class for making simple GET and POST HTTP requests to web services.

Synopsis


#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);

Description

SharingHTTP is class for making simple HTTP GET and POST requests to web services. It's designed to be used for uploading media content to services like Share on 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); 

Details

SharingHTTPProgressCallback ()

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

enum SharingHTTPRunResponse

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()

SHARING_HTTP_RUNRES_SUCCESS Run was a success.
SHARING_HTTP_RUNRES_UNKNOWN_FAILURE Unknown failure.
SHARING_HTTP_RUNRES_INVALID_PARAMETERS Invalid parameters given.
SHARING_HTTP_RUNRES_CONNECTION_PROBLEM Couldn't get connection to URL.
SHARING_HTTP_RUNRES_CANCELLED Run was cancelled by callback.
SHARING_HTTP_RUNRES_ALREADY_RUNNING There is already active process ongoing.

sharing_http_new ()

SharingHTTP*        sharing_http_new                    ();

Create new SharingHTTP

Returns : New SharingHTTP with one reference. Unref with sharing_http_unref().

sharing_http_ref ()

gint                sharing_http_ref                    (SharingHTTP *self);

Add reference to SharingHTTP

self : Pointer to SharingHTTP object
Returns : New reference count.

sharing_http_unref ()

gint                sharing_http_unref                  (SharingHTTP *self);

Remove reference to SharingHTTP

self : Pointer to SharingHTTP object
Returns : New reference count. If under 1 then SharingHTTP was freed.

sharing_http_set_connection ()

void                sharing_http_set_connection         (SharingHTTP *self,
                                                         ConIcConnection *connection);

Changes the connection used when send

self : Pointer to SharingHTTP object
connection : New connection used

sharing_http_get_connection ()

ConIcConnection*    sharing_http_get_connection         (SharingHTTP *self);

Get connection mark to be used when connected

self : Pointer to SharingHTTP object
Returns : Connection mark to be used or NULL if not defined.

sharing_http_set_timeouts ()

void                sharing_http_set_timeouts           (SharingHTTP *self,
                                                         glong connecting_timeout,
                                                         glong connection_timeout);

Change timeout values of SharingHTTP

self : Pointer to SharingHTTP object
connecting_timeout : Who long we wait connecting in seconds
connection_timeout : Who long the connection can last in seconds

sharing_http_set_progress_callback ()

void                sharing_http_set_progress_callback  (SharingHTTP *self,
                                                         SharingHTTPProgressCallback callback,
                                                         gpointer user_data);

sharing_http_run ()

SharingHTTPRunResponse sharing_http_run                 (SharingHTTP *self,
                                                         const gchar *url);

Run request and get responses

self : Pointer to SharingHTTP object
url : URL where request is send
Returns : Result of run

sharing_http_cancel ()

void                sharing_http_cancel                 (SharingHTTP *self);

Cancel current running process

self : Pointer to SharingHTTP object

sharing_http_add_req_header ()

gboolean            sharing_http_add_req_header         (SharingHTTP *self,
                                                         const gchar *name,
                                                         const gchar *value);

Add new header to request

self : Pointer to SharingHTTP object
name : Name of header added
value : Value of header added
Returns : TRUE if header was added successfully

sharing_http_add_req_header_line ()

gboolean            sharing_http_add_req_header_line    (SharingHTTP *self,
                                                         const gchar *line);

Add new header line to out going request

self : Pointer to SharingHTTP object
line : Header line added
Returns : TRUE if line was added successfully

sharing_http_remove_req_headers ()

void                sharing_http_remove_req_headers     (SharingHTTP *self);

sharing_http_add_req_multipart_file ()

gboolean            sharing_http_add_req_multipart_file (SharingHTTP *self,
                                                         const gchar *name,
                                                         const gchar *filepath,
                                                         const gchar *type);

Add file as a multipart to request with option to replace filename value.

self : Pointer to SharingHTTP object
name : Name for part
filepath : Path to file added
type : Type of part
filename : Replace real filename with this. If NULL then original filename is used.
Returns : TRUE if file was added successfully

sharing_http_add_req_multipart_file_with_filename ()

gboolean            sharing_http_add_req_multipart_file_with_filename
                                                        (SharingHTTP *self,
                                                         const gchar *name,
                                                         const gchar *filepath,
                                                         const gchar *type,
                                                         const gchar *filename);

sharing_http_add_req_multipart_data ()

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 request

self : Pointer to SharingHTTP object
name : Name for part
data : Path to file added
data_len : Length of data or -1 if data is NULL terminated.
type : Type of data
Returns : TRUE if data was added successfully

sharing_http_clear_multiparts ()

void                sharing_http_clear_multiparts       (SharingHTTP *self);

Clear all multipart data from request.

self : Pointer to SharingHTTP object

sharing_http_set_res_buffer_size_limit ()

void                sharing_http_set_res_buffer_size_limit
                                                        (SharingHTTP *self,
                                                         gsize limit);

Change size limit of response buffer in bytes

self : Pointer to SharingHTTP object
limit : New size limit in bytes

sharing_http_get_res_buffer_size_limit ()

gsize               sharing_http_get_res_buffer_size_limit
                                                        (SharingHTTP *self);

Get response buffer size limit

self : Pointer to SharingHTTP object
Returns : Size limit of response buffer in bytes or 0 if not defined.

sharing_http_get_res_code ()

gint                sharing_http_get_res_code           (SharingHTTP *self);

Get response HTTP code

self : Pointer to SharingHTTP object
Returns : Response HTTP code or -1 if not defined.

sharing_http_get_res_content ()

const gchar*        sharing_http_get_res_content        (SharingHTTP *self,
                                                         gsize *len);

Get full content of response

self : Pointer to SharingHTTP object
len : Length of content is defined here. Needed if content isn't NULL terminated.
Returns : Pointer to reponse content or NULL if not available.

sharing_http_get_res_body ()

const gchar*        sharing_http_get_res_body           (SharingHTTP *self,
                                                         gsize *len);

Get body of response

self : Pointer to SharingHTTP object
len : Length of body is defined here. Needed if body isn't NULL terminated.
Returns : Pointer to reponse body or NULL if not available.

sharing_http_set_user_agent_name ()

void                sharing_http_set_user_agent_name    (SharingHTTP *self,
                                                         const gchar *name);

Change user agent name sent when using SharingHTTP

self : Pointer to SharingHTTP object
name : User agent name or NULL if none