[PATCH] DLD upload

Lubomir I. Ivanov neolit123 at gmail.com
Wed Mar 13 12:14:30 PDT 2013


On 13 March 2013 16:51, Lubomir I. Ivanov <neolit123 at gmail.com> wrote:
>
> on the other hand, the libsoup re-write should be quite trivial, also
> if i'm no mistaken we get easy SSL support, but that has to be
> confirmed.
>

here is a (untested) libsoup variant for reference. as you can see
it's more code even without the error checks, which seems typical for
the gnome folks, even if the library capabilities are overall smaller
in comparison to libcurl (as they say). but i really think we should
move both the zip packaging code and the upload code to a new pair
e.g. upload.c/upload.h. we then can use the same file to write a
dialog and the same dialog to upload to different website platforms.
but please, don't put this in divelist.c :-).

-----------------------------------------------------------

/* input parameters */
guint file_len = ...;
gchar *file_name = ...;
gchar *file_buffer = ...;
gchar *user = ...;
gchar *pass = ...;

/* async session, so that we don't freeze the UI */
SoupSession *session = soup_session_async_new();
if (!session)
	return;
/* create a message object */
SoupMessage *message = soup_message_new ("POST",
"http://divelogs.de/DivelogsDirectImport.php");
if (!message)
	return;
/* create a HTTP multipart */
SoupMultipart *multipart = soup_multipart_new("multipart/form-data");
if (!multipart)
	return;
/* this is needed unfortunately; too many buffer stages. */
SoupBuffer *buffer = soup_buffer_new(SOUP_MEMORY_STATIC, file_buffer, file_len);
if (!buffer)
	return;
/* add the user details and file */
soup_multipart_append_form_string(multipart, "user", user);
soup_multipart_append_form_string(multipart, "pass", pass);
soup_multipart_append_form_file(multipart, "userfile", file_name,
"application/octet-stream", buffer);
/* serialize everything into the message and send it */
message = soup_multipart_to_message(multipart,
message->request_headers, message->request_body);
soup_session_send_message(session, message);

/* result */
if SOUP_STATUS_IS_SUCCESSFUL(message->status_code) {
	/* ok */
} else {
	/* message->status contains the protocol error */
}

/* release memory */
soup_session_abort(session);
g_object_unref(G_OBJECT(session));
g_object_unref(G_OBJECT(message));
soup_multipart_free(multipart);
soup_buffer_free(buffer);

-----------------------------------------------------------


lubomir
--


More information about the subsurface mailing list