summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Graveley <alex@ximian.com>2001-10-27 22:32:09 +0000
committerAlex Graveley <orph@src.gnome.org>2001-10-27 22:32:09 +0000
commitb80b325030d751949aebf4fd6580864a33fa25a6 (patch)
tree945c442b05677c655aab2eefacb2e8b65fec2641
parent9e163241a62fb9df1559543c66d3e31c69c67d59 (diff)
downloadlibsoup-b80b325030d751949aebf4fd6580864a33fa25a6.tar.gz
Include soup-error.h
2001-10-27 Alex Graveley <alex@ximian.com> * src/libsoup/soup-dav.c: Include soup-error.h * src/libsoup/soup-queue.c (soup_debug_print_headers): Use soup_message_foreach_header. * src/libsoup/soup-message.c (soup_message_new): Default to GET if method not supplied. (soup_message_add_header): Remove code to delete header if no value is supplied. (soup_message_foreach_remove_header): Impl. (soup_message_remove_header): Impl.
-rw-r--r--ChangeLog14
-rw-r--r--libsoup/soup-context.h4
-rw-r--r--libsoup/soup-message.c110
-rw-r--r--libsoup/soup-message.h8
-rw-r--r--libsoup/soup-queue.c21
5 files changed, 123 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog
index aa618629..0c2ae1a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2001-10-27 Alex Graveley <alex@ximian.com>
+
+ * src/libsoup/soup-dav.c: Include soup-error.h
+
+ * src/libsoup/soup-queue.c (soup_debug_print_headers): Use
+ soup_message_foreach_header.
+
+ * src/libsoup/soup-message.c (soup_message_new): Default to GET if
+ method not supplied.
+ (soup_message_add_header): Remove code to delete header if no
+ value is supplied.
+ (soup_message_foreach_remove_header): Impl.
+ (soup_message_remove_header): Impl.
+
2001-10-26 Alex Graveley <alex@ximian.com>
* src/libsoup/soup-socket-unix.c (soup_address_new): Use WUNTRACED,
diff --git a/libsoup/soup-context.h b/libsoup/soup-context.h
index 6e6501a7..c10fe217 100644
--- a/libsoup/soup-context.h
+++ b/libsoup/soup-context.h
@@ -43,10 +43,10 @@ SoupConnectId soup_context_get_connection (SoupContext *ctx,
SoupConnectCallbackFn cb,
gpointer user_data);
-const SoupUri *soup_context_get_uri (SoupContext *ctx);
-
void soup_context_cancel_connect (SoupConnectId tag);
+const SoupUri *soup_context_get_uri (SoupContext *ctx);
+
GIOChannel *soup_connection_get_iochannel (SoupConnection *conn);
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index d79ff03a..856089a4 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -21,10 +21,12 @@
* soup_message_new:
* @context: a %SoupContext for the destination endpoint.
* @method: a string which will be used as the HTTP method for the created
- * request.
+ * request, if NULL a GET request will be made.
*
* Creates a new empty %SoupMessage, which will connect to the URL represented
- * by @context. The new message has a status of @SOUP_STATUS_IDLE.
+ * by @context. A reference will be added to @context.
+ *
+ * The new message has a status of @SOUP_STATUS_IDLE.
*
* Return value: the new %SoupMessage.
*/
@@ -39,7 +41,7 @@ soup_message_new (SoupContext *context, const gchar *method)
ret->priv = g_new0 (SoupMessagePrivate, 1);
ret->status = SOUP_STATUS_IDLE;
ret->context = context;
- ret->method = method ? method : SOUP_METHOD_POST;
+ ret->method = method ? method : SOUP_METHOD_GET;
ret->request_headers = g_hash_table_new (soup_str_case_hash,
soup_str_case_equal);
@@ -58,16 +60,18 @@ soup_message_new (SoupContext *context, const gchar *method)
* soup_message_new_full:
* @context: a %SoupContext for the destination endpoint.
* @method: a string which will be used as the HTTP method for the created
- * request.
+ * request, if NULL a GET request will be made..
* @req_owner: the %SoupOwnership of the passed data buffer.
* @req_body: a data buffer containing the body of the message request.
* @req_length: the byte length of @req_body.
*
* Creates a new %SoupMessage, which will connect to the URL represented by
- * @context. The new message has a status of @SOUP_STATUS_IDLE. The request data
+ * @context. A reference is added to @context. The request data
* buffer will be filled from @req_owner, @req_body, and @req_length
* respectively.
*
+ * The new message has a status of @SOUP_STATUS_IDLE.
+ *
* Return value: the new %SoupMessage.
*/
SoupMessage *
@@ -90,8 +94,9 @@ soup_message_new_full (SoupContext *context,
* soup_message_cleanup:
* @req: a %SoupMessage.
*
- * Frees any temporary resources created in the processing of @req. Request and
- * response data buffers are left intact.
+ * Frees any temporary resources created in the processing of @req. Also
+ * releases the active connection, if one exists. Request and response data
+ * buffers are left intact.
*/
void
soup_message_cleanup (SoupMessage *req)
@@ -232,34 +237,44 @@ soup_message_clear_headers (GHashTable *hash)
}
void
+soup_message_remove_header (GHashTable *hash,
+ const gchar *name)
+{
+ gchar *stored_key;
+ GSList *vals;
+
+ g_return_if_fail (hash != NULL);
+ g_return_if_fail (name != NULL || name [0] != '\0');
+
+ if (g_hash_table_lookup_extended (hash,
+ name,
+ (gpointer *) &stored_key,
+ (gpointer *) &vals)) {
+ g_hash_table_remove (hash, name);
+ foreach_free_header_list (stored_key, vals, NULL);
+ }
+}
+
+void
soup_message_add_header (GHashTable *hash,
const gchar *name,
const gchar *value)
{
- gboolean exists = FALSE;
- gpointer old_name;
GSList *old_value;
g_return_if_fail (hash != NULL);
- g_return_if_fail (name != NULL || name [0] != '\0');
+ g_return_if_fail (name != NULL || name [0] != '\0');
+ g_return_if_fail (value != NULL);
- exists = g_hash_table_lookup_extended (hash,
- name,
- &old_name,
- (gpointer *) &old_value);
+ old_value = g_hash_table_lookup (hash, name);
- if (value && exists)
- old_value = g_slist_append (old_value,
- g_strdup (value));
- else if (value && !exists)
+ if (old_value)
+ g_slist_append (old_value, g_strdup (value));
+ else
g_hash_table_insert (hash,
g_strdup (name),
g_slist_append (NULL,
g_strdup (value)));
- else if (!value && exists) {
- g_hash_table_remove (hash, name);
- foreach_free_header_list (old_name, old_value, NULL);
- }
}
/**
@@ -337,6 +352,57 @@ soup_message_foreach_header (GHashTable *hash,
g_hash_table_foreach (hash, (GHFunc) foreach_value_in_list, &data);
}
+typedef struct {
+ GHRFunc func;
+ gpointer user_data;
+} ForeachRemoveData;
+
+static gboolean
+foreach_remove_value_in_list (gchar *name,
+ GSList *vals,
+ ForeachRemoveData *data)
+{
+ GSList *iter = vals;
+
+ while (iter) {
+ gchar *v = iter->data;
+ gboolean ret = FALSE;
+
+ ret = (*data->func) (name, v, data->user_data);
+ if (ret) {
+ GSList *next = iter->next;
+
+ vals = g_slist_remove (vals, v);
+ g_free (v);
+
+ iter = next;
+ } else
+ iter = iter->next;
+ }
+
+ if (!vals) {
+ g_free (name);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void
+soup_message_foreach_remove_header (GHashTable *hash,
+ GHRFunc func,
+ gpointer user_data)
+{
+ ForeachRemoveData data = { func, user_data };
+
+ g_return_if_fail (hash != NULL);
+ g_return_if_fail (func != NULL);
+
+ g_hash_table_foreach_remove (hash,
+ (GHRFunc) foreach_remove_value_in_list,
+ &data);
+}
+
/**
* soup_message_set_request_header:
* @req: a %SoupMessage.
diff --git a/libsoup/soup-message.h b/libsoup/soup-message.h
index fe197ac0..6ddfa052 100644
--- a/libsoup/soup-message.h
+++ b/libsoup/soup-message.h
@@ -116,6 +116,14 @@ void soup_message_foreach_header (GHashTable *hash,
GHFunc func,
gpointer user_data);
+void soup_message_foreach_remove_header (
+ GHashTable *hash,
+ GHRFunc func,
+ gpointer user_data);
+
+void soup_message_remove_header (GHashTable *hash,
+ const gchar *name);
+
void soup_message_clear_headers (GHashTable *hash);
typedef enum {
diff --git a/libsoup/soup-queue.c b/libsoup/soup-queue.c
index 0a3bf250..f3cd3097 100644
--- a/libsoup/soup-queue.c
+++ b/libsoup/soup-queue.c
@@ -34,22 +34,23 @@ GSList *soup_active_requests = NULL;
static guint soup_queue_idle_tag = 0;
static void
-soup_debug_print_a_header (gchar *key, GSList *vals, gpointer not_used)
+soup_debug_print_a_header (gchar *key, gchar *val, gpointer not_used)
{
- while (vals) {
- g_print ("\tKEY: \"%s\", VALUE: \"%s\"\n",
- key,
- (gchar *) vals->data);
- vals = vals->next;
- }
+ g_print ("\tKEY: \"%s\", VALUE: \"%s\"\n", key, val);
}
void
soup_debug_print_headers (SoupMessage *req)
{
- g_hash_table_foreach (req->response_headers,
- (GHFunc) soup_debug_print_a_header,
- NULL);
+ g_print ("Request Headers:\n");
+ soup_message_foreach_header (req->request_headers,
+ (GHFunc) soup_debug_print_a_header,
+ NULL);
+
+ g_print ("Response Headers:\n");
+ soup_message_foreach_header (req->response_headers,
+ (GHFunc) soup_debug_print_a_header,
+ NULL);
}
static void