commit dfd057b9b6e0b022f73c1bdb4b845230f29fae3a
parent ae588bb3c84708b17d75d3ab2ccaf5e972c28fde
Author: Christian Grothoff <christian@grothoff.org>
Date: Wed, 6 Aug 2008 16:32:11 +0000
fixing 1399
Diffstat:
3 files changed, 115 insertions(+), 0 deletions(-)
diff --git a/doc/microhttpd.texi b/doc/microhttpd.texi
@@ -695,6 +695,36 @@ and returns the number of headers.
@end deftypefun
+@deftypefun int MHD_set_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char * key, const char * value)
+This function can be used to add an entry to
+the HTTP headers of a connection (so that the
+MHD_get_connection_values function will return
+them -- and the MHD PostProcessor will also
+see them). This maybe required in certain
+situations (see Mantis #1399) where (broken)
+HTTP implementations fail to supply values needed
+by the post processor (or other parts of the
+application).
+
+This function MUST only be called from within
+the MHD_AccessHandlerCallback (otherwise, access
+maybe improperly synchronized). Furthermore,
+the client must guarantee that the key and
+value arguments are 0-terminated strings that
+are NOT freed until the connection is closed.
+(The easiest way to do this is by passing only
+arguments to permanently allocated strings.).
+
+@var{connection} is the connection for which
+the entry for @var{key} of the given @var{kind}
+should be set to the given @var{value}.
+
+The function returns @code{MHD_NO} if the operation
+could not be performed due to insufficient memory
+and @code{MHD_YES} on success.
+@end deftypefun
+
+
@deftypefun {const char *} MHD_lookup_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key)
Get a particular header value. If multiple values match the @var{kind},
return one of them (the ``first'', whatever that means). @var{key} must
diff --git a/src/daemon/connection.c b/src/daemon/connection.c
@@ -148,6 +148,56 @@ MHD_get_connection_values (struct MHD_Connection *connection,
}
/**
+ * This function can be used to add an entry to
+ * the HTTP headers of a connection (so that the
+ * MHD_get_connection_values function will return
+ * them -- and the MHD PostProcessor will also
+ * see them). This maybe required in certain
+ * situations (see Mantis #1399) where (broken)
+ * HTTP implementations fail to supply values needed
+ * by the post processor (or other parts of the
+ * application).
+ * <p>
+ * This function MUST only be called from within
+ * the MHD_AccessHandlerCallback (otherwise, access
+ * maybe improperly synchronized). Furthermore,
+ * the client must guarantee that the key and
+ * value arguments are 0-terminated strings that
+ * are NOT freed until the connection is closed.
+ * (The easiest way to do this is by passing only
+ * arguments to permanently allocated strings.).
+ *
+ * @param connection the connection for which a
+ * value should be set
+ * @param kind kind of the value
+ * @param key key for the value
+ * @param value the value itself
+ * @return MHD_NO if the operation could not be
+ * performed due to insufficient memory;
+ * MHD_YES on success
+ */
+int
+MHD_set_connection_value (struct MHD_Connection *connection,
+ enum MHD_ValueKind kind,
+ const char *key,
+ const char *value)
+{
+ struct MHD_HTTP_Header * pos;
+
+ pos = MHD_pool_allocate(connection->pool,
+ sizeof(struct MHD_HTTP_Header),
+ MHD_NO);
+ if (pos == NULL)
+ return MHD_NO;
+ pos->header = (char*) key;
+ pos->value = (char*) value;
+ pos->kind = kind;
+ pos->next = connection->headers_received;
+ connection->headers_received = pos;
+ return MHD_YES;
+}
+
+/**
* Get a particular header value. If multiple
* values match the kind, return any one of them.
*
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
@@ -791,6 +791,41 @@ MHD_get_connection_values (struct MHD_Connection *connection,
MHD_KeyValueIterator iterator, void *iterator_cls);
/**
+ * This function can be used to add an entry to
+ * the HTTP headers of a connection (so that the
+ * MHD_get_connection_values function will return
+ * them -- and the MHD PostProcessor will also
+ * see them). This maybe required in certain
+ * situations (see Mantis #1399) where (broken)
+ * HTTP implementations fail to supply values needed
+ * by the post processor (or other parts of the
+ * application).
+ * <p>
+ * This function MUST only be called from within
+ * the MHD_AccessHandlerCallback (otherwise, access
+ * maybe improperly synchronized). Furthermore,
+ * the client must guarantee that the key and
+ * value arguments are 0-terminated strings that
+ * are NOT freed until the connection is closed.
+ * (The easiest way to do this is by passing only
+ * arguments to permanently allocated strings.).
+ *
+ * @param connection the connection for which a
+ * value should be set
+ * @param kind kind of the value
+ * @param key key for the value
+ * @param value the value itself
+ * @return MHD_NO if the operation could not be
+ * performed due to insufficient memory;
+ * MHD_YES on success
+ */
+int
+MHD_set_connection_value (struct MHD_Connection *connection,
+ enum MHD_ValueKind kind,
+ const char *key,
+ const char *value);
+
+/**
* Get a particular header value. If multiple
* values match the kind, return any one of them.
*