Author: jmb
Date: Wed Oct 14 10:14:30 2009
New Revision: 9633
URL:
http://source.netsurf-browser.org?rev=9633&view=rev
Log:
Clone POST data
Modified:
branches/jmb/new-cache/content/llcache.c
branches/jmb/new-cache/content/llcache.h
branches/jmb/new-cache/render/form.c
branches/jmb/new-cache/render/form.h
Modified: branches/jmb/new-cache/content/llcache.c
URL:
http://source.netsurf-browser.org/branches/jmb/new-cache/content/llcache....
==============================================================================
--- branches/jmb/new-cache/content/llcache.c (original)
+++ branches/jmb/new-cache/content/llcache.c Wed Oct 14 10:14:30 2009
@@ -29,6 +29,7 @@
#include "content/fetch.h"
#include "content/llcache.h"
+#include "render/form.h"
#include "utils/messages.h"
#include "utils/url.h"
#include "utils/utils.h"
@@ -162,6 +163,9 @@
static nserror llcache_object_notify_users(llcache_object *object);
static nserror llcache_clean(void);
+
+static nserror llcache_post_data_clone(const llcache_post_data *orig,
+ llcache_post_data **clone);
static nserror llcache_query_handle_response(bool proceed, void *cbpw);
@@ -650,6 +654,7 @@
nserror llcache_object_fetch(llcache_object *object, uint32_t flags,
const char *referer, const llcache_post_data *post)
{
+ nserror error;
char *referer_clone;
llcache_post_data *post_clone;
@@ -657,8 +662,11 @@
if (referer_clone == NULL)
return NSERROR_NOMEM;
- /** \todo clone post */
- post_clone = (llcache_post_data *) post;
+ error = llcache_post_data_clone(post, &post_clone);
+ if (error != NSERROR_OK) {
+ free(referer_clone);
+ return error;
+ }
object->fetch.flags = flags;
object->fetch.referer = referer_clone;
@@ -747,7 +755,17 @@
}
free(object->fetch.referer);
- /** \todo Destroy POST data */
+
+ if (object->fetch.post != NULL) {
+ if (object->fetch.post->type == LLCACHE_POST_URL_ENCODED) {
+ free(object->fetch.post->data.urlenc);
+ } else {
+ form_free_successful(
+ object->fetch.post->data.multipart);
+ }
+
+ free(object->fetch.post);
+ }
free(object->cache.etag);
@@ -992,6 +1010,47 @@
}
/**
+ * Clone a POST data object
+ *
+ * \param orig Object to clone
+ * \param clone Pointer to location to receive clone
+ * \return NSERROR_OK on success, appropriate error otherwise
+ */
+nserror llcache_post_data_clone(const llcache_post_data *orig,
+ llcache_post_data **clone)
+{
+ llcache_post_data *post_clone;
+
+ post_clone = calloc(1, sizeof(llcache_post_data));
+ if (post_clone == NULL)
+ return NSERROR_NOMEM;
+
+ post_clone->type = orig->type;
+
+ /* Deep-copy the type-specific data */
+ if (orig->type == LLCACHE_POST_URL_ENCODED) {
+ post_clone->data.urlenc = strdup(orig->data.urlenc);
+ if (post_clone->data.urlenc == NULL) {
+ free(post_clone);
+
+ return NSERROR_NOMEM;
+ }
+ } else {
+ post_clone->data.multipart =
+ form_clone_successful(orig->data.multipart);
+ if (post_clone->data.multipart == NULL) {
+ free(post_clone);
+
+ return NSERROR_NOMEM;
+ }
+ }
+
+ *clone = post_clone;
+
+ return NSERROR_OK;
+}
+
+/**
* Handle a query response
*
* \param proceed Whether to proceed with fetch
Modified: branches/jmb/new-cache/content/llcache.h
URL:
http://source.netsurf-browser.org/branches/jmb/new-cache/content/llcache....
==============================================================================
--- branches/jmb/new-cache/content/llcache.h (original)
+++ branches/jmb/new-cache/content/llcache.h Wed Oct 14 10:14:30 2009
@@ -45,7 +45,7 @@
LLCACHE_POST_MULTIPART
} type; /**< Type of POST data */
union {
- const char *urlenc; /**< URL encoded data */
+ char *urlenc; /**< URL encoded data */
/** \todo Need to abstract this away from HTML forms. */
struct form_successful_control *multipart; /**< Multipart data */
} data; /**< POST data content */
Modified: branches/jmb/new-cache/render/form.c
URL:
http://source.netsurf-browser.org/branches/jmb/new-cache/render/form.c?re...
==============================================================================
--- branches/jmb/new-cache/render/form.c (original)
+++ branches/jmb/new-cache/render/form.c Wed Oct 14 10:14:30 2009
@@ -713,6 +713,60 @@
return s;
}
+/**
+ * Clone a linked list of form_successful control.
+ *
+ * \param list List to clone
+ * \return Pointer to head of cloned list, or NULL on failure
+ */
+struct form_successful_control *form_clone_successful(
+ const struct form_successful_control *list)
+{
+ struct form_successful_control *clone, *last = NULL;
+ struct form_successful_control *result = NULL;
+
+ for (; list != NULL; list = list->next) {
+ clone = malloc(sizeof(struct form_successful_control));
+ if (clone == NULL) {
+ if (result != NULL)
+ form_free_successful(result);
+
+ return NULL;
+ }
+
+ clone->file = list->file;
+
+ clone->name = strdup(list->name);
+ if (clone->name == NULL) {
+ free(clone);
+ if (result != NULL)
+ form_free_successful(result);
+
+ return NULL;
+ }
+
+ clone->value = strdup(list->value);
+ if (clone->value == NULL) {
+ free(clone->name);
+ free(clone);
+ if (result != NULL)
+ form_free_successful(result);
+
+ return NULL;
+ }
+
+ clone->next = NULL;
+
+ if (result == NULL)
+ result = clone;
+ else
+ last->next = clone;
+
+ last = clone;
+ }
+
+ return result;
+}
/**
* Free a linked list of form_successful_control.
Modified: branches/jmb/new-cache/render/form.h
URL:
http://source.netsurf-browser.org/branches/jmb/new-cache/render/form.h?re...
==============================================================================
--- branches/jmb/new-cache/render/form.h (original)
+++ branches/jmb/new-cache/render/form.h Wed Oct 14 10:14:30 2009
@@ -160,6 +160,8 @@
struct form_successful_control **successful_controls);
char *form_url_encode(struct form *form,
struct form_successful_control *control);
+struct form_successful_control *form_clone_successful(
+ const struct form_successful_control *list);
void form_free_successful(struct form_successful_control *control);
bool form_open_select_menu(void *client_data,