diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-03-13 20:37:38 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-03-13 20:37:38 -0700 |
commit | bd9f8ad7f84208f087e3209c35a5263f45879ce9 (patch) | |
tree | 48b42b2655b4bc88f95dfccb70a73eaefd77f89c /webservice.c | |
parent | 3e1098bd038a8568fd3a216b59b753dac59f45fa (diff) | |
download | subsurface-bd9f8ad7f84208f087e3209c35a5263f45879ce9.tar.gz |
First simplistic implementation of a divelogs.de upload
This has no user interface and hardcodes a testing username / password.
But it can successfully create a DLD file (thanks to Miika and Lubomir)
and then uses libsoup to upload that to the server.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'webservice.c')
-rw-r--r-- | webservice.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/webservice.c b/webservice.c index 9cdd75ced..615405fc5 100644 --- a/webservice.c +++ b/webservice.c @@ -6,6 +6,7 @@ #include "dive.h" #include "divelist.h" #include "display-gtk.h" +#include "file.h" struct dive_table gps_location_table; static gboolean merge_locations_into_dives(void); @@ -306,3 +307,41 @@ void webservice_download_dialog(void) if (has_previous_uid) free((void *)current_uid); } + +int divelogde_upload(char *fn) +{ + SoupMessage *msg; + SoupMultipart *multipart; + SoupSession *session; + SoupBuffer *sbuf; + gboolean ret = FALSE; + gchar url[256] = "http://divelogs.de/DivelogsDirectImport.php"; + struct memblock mem; + + if (readfile(fn, &mem) < 0) + return ret; + + sbuf = soup_buffer_new(SOUP_MEMORY_STATIC, mem.buffer, mem.size); + session = soup_session_async_new(); + multipart = soup_multipart_new(SOUP_FORM_MIME_TYPE_MULTIPART); + + /* this needs to come from a dialog box and be stored in the user config */ + soup_multipart_append_form_string(multipart, "user", "subsurfacetest"); + soup_multipart_append_form_string(multipart, "pass", "geheim"); + + soup_multipart_append_form_file(multipart, "userfile", fn, NULL, sbuf); + msg = soup_form_request_new_from_multipart(url, multipart); + soup_message_headers_append(msg->request_headers, "Accept", "text/xml"); + soup_session_send_message(session, msg); + if (SOUP_STATUS_IS_SUCCESSFUL(msg->status_code)) { + /* we should really check if the XML returned indicates that + * the profiles were successfully uploaded... + */ + fprintf(stderr, "%s\n", (gchar *)msg->response_body->data); + ret = TRUE; + } + soup_session_abort(session); + g_object_unref(G_OBJECT(msg)); + g_object_unref(G_OBJECT(session)); + return ret; +} |