about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/iq.c31
-rw-r--r--src/xmpp/stanza.c31
-rw-r--r--src/xmpp/stanza.h9
3 files changed, 35 insertions, 36 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 8556d63d..b866128b 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -2424,18 +2424,31 @@ _http_upload_response_id_handler(xmpp_stanza_t* const stanza, void* const userda
         xmpp_stanza_t* get = xmpp_stanza_get_child_by_name(slot, STANZA_NAME_GET);
 
         if (put && get) {
-            char* put_url = xmpp_stanza_get_text(put);
-            char* get_url = xmpp_stanza_get_text(get);
-
+            const char* put_url = xmpp_stanza_get_attribute(put, "url");
             upload->put_url = strdup(put_url);
+            const char* get_url = xmpp_stanza_get_attribute(get, "url");
             upload->get_url = strdup(get_url);
 
-            xmpp_conn_t* conn = connection_get_conn();
-            xmpp_ctx_t* ctx = xmpp_conn_get_context(conn);
-            if (put_url)
-                xmpp_free(ctx, put_url);
-            if (get_url)
-                xmpp_free(ctx, get_url);
+            // Optional "authorization", "cookie", "expires" headers
+            upload->authorization = upload->cookie = upload->expires = NULL;
+            xmpp_stanza_t* header = xmpp_stanza_get_children(put);
+            for (; header; header = xmpp_stanza_get_next(header)) {
+                if (g_strcmp0(xmpp_stanza_get_name(header), STANZA_NAME_HEADER) == 0) {
+                    const char* header_name = xmpp_stanza_get_attribute(header, STANZA_ATTR_NAME);
+                    if (g_strcmp0(header_name, STANZA_HEADER_AUTHORIZATION) == 0) {
+                        upload->authorization = xmpp_stanza_get_text(header);
+                    }
+                    else if (g_strcmp0(header_name, STANZA_HEADER_COOKIE) == 0) {
+                        upload->cookie = xmpp_stanza_get_text(header);
+                    }
+                    else if (g_strcmp0(header_name, STANZA_HEADER_EXPIRES) == 0) {
+                        upload->expires = xmpp_stanza_get_text(header);
+                    }
+                    else {
+                        log_warning("[HTTP upload] unknown header: %s", header_name);
+                    }
+                }
+            }
 
             pthread_create(&(upload->worker), NULL, &http_file_put, upload);
             http_upload_add_upload(upload);
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index f13d784b..86bd0d91 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -232,9 +232,6 @@ stanza_create_http_upload_request(xmpp_ctx_t* ctx, const char* const id,
     xmpp_stanza_set_name(request, STANZA_NAME_REQUEST);
     xmpp_stanza_set_ns(request, STANZA_NS_HTTP_UPLOAD);
 
-    xmpp_stanza_t* filename = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(filename, STANZA_NAME_FILENAME);
-    xmpp_stanza_t* filename_txt = xmpp_stanza_new(ctx);
     char* filename_cpy = strdup(upload->filename);
     // strip spaces from filename (servers don't spaces)
     for (int i = 0; i < strlen(filename_cpy); i++) {
@@ -242,34 +239,16 @@ stanza_create_http_upload_request(xmpp_ctx_t* ctx, const char* const id,
             filename_cpy[i] = '_';
         }
     }
-    xmpp_stanza_set_text(filename_txt, basename(filename_cpy));
+    xmpp_stanza_set_attribute(request, STANZA_ATTR_FILENAME, basename(filename_cpy));
     free(filename_cpy);
-    xmpp_stanza_add_child(filename, filename_txt);
-    xmpp_stanza_add_child(request, filename);
-    xmpp_stanza_release(filename_txt);
-    xmpp_stanza_release(filename);
-
-    xmpp_stanza_t* size = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(size, STANZA_NAME_SIZE);
-    xmpp_stanza_t* size_txt = xmpp_stanza_new(ctx);
+
     char* filesize = NULL;
     if (asprintf(&filesize, "%jd", (intmax_t)(upload->filesize)) != -1) {
-        xmpp_stanza_set_text(size_txt, filesize);
+        xmpp_stanza_set_attribute(request, STANZA_ATTR_SIZE, filesize);
         free(filesize);
     }
-    xmpp_stanza_add_child(size, size_txt);
-    xmpp_stanza_add_child(request, size);
-    xmpp_stanza_release(size_txt);
-    xmpp_stanza_release(size);
-
-    xmpp_stanza_t* content_type = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(content_type, STANZA_NAME_CONTENT_TYPE);
-    xmpp_stanza_t* content_type_txt = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_text(content_type_txt, upload->mime_type);
-    xmpp_stanza_add_child(content_type, content_type_txt);
-    xmpp_stanza_add_child(request, content_type);
-    xmpp_stanza_release(content_type_txt);
-    xmpp_stanza_release(content_type);
+
+    xmpp_stanza_set_attribute(request, STANZA_ATTR_CONTENTTYPE, upload->mime_type);
 
     xmpp_stanza_add_child(iq, request);
     xmpp_stanza_release(request);
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index 0634f1ad..35f38055 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -106,6 +106,10 @@
 #define STANZA_NAME_SLOT             "slot"
 #define STANZA_NAME_PUT              "put"
 #define STANZA_NAME_GET              "get"
+#define STANZA_NAME_HEADER           "header"
+#define STANZA_HEADER_AUTHORIZATION  "Authorization"
+#define STANZA_HEADER_COOKIE         "Cookie"
+#define STANZA_HEADER_EXPIRES        "Expires"
 #define STANZA_NAME_URL              "url"
 #define STANZA_NAME_COMMAND          "command"
 #define STANZA_NAME_CONFIGURE        "configure"
@@ -179,6 +183,9 @@
 #define STANZA_ATTR_STATUS         "status"
 #define STANZA_ATTR_DATE           "date"
 #define STANZA_ATTR_V4_FINGERPRINT "v4-fingerprint"
+#define STANZA_ATTR_FILENAME       "filename"
+#define STANZA_ATTR_SIZE           "size"
+#define STANZA_ATTR_CONTENTTYPE    "content-type"
 
 #define STANZA_TEXT_AWAY   "away"
 #define STANZA_TEXT_DND    "dnd"
@@ -211,7 +218,7 @@
 // XEP-0373: OpenPGP for XMPP
 #define STANZA_NS_OPENPGP_0               "urn:xmpp:openpgp:0"
 #define STANZA_NS_OPENPGP_0_PUBLIC_KEYS   "urn:xmpp:openpgp:0:public-keys"
-#define STANZA_NS_HTTP_UPLOAD             "urn:xmpp:http:upload"
+#define STANZA_NS_HTTP_UPLOAD             "urn:xmpp:http:upload:0"
 #define STANZA_NS_X_OOB                   "jabber:x:oob"
 #define STANZA_NS_BLOCKING                "urn:xmpp:blocking"
 #define STANZA_NS_COMMAND                 "http://jabber.org/protocol/commands"