summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsandmann <sandmann>2007-01-14 01:55:58 +0000
committersandmann <sandmann>2007-01-14 01:55:58 +0000
commite3411fa8e046e3ba92c9b9c626ce5a63337b95e5 (patch)
tree2c87c7eeb340c8eab7bca2aba5254e8c20fd2e3b
parent18f11ea5b877e0dadc0f755684031e3a4efc8283 (diff)
Use LacByteQueue for http request content
-rw-r--r--src/lac.h4
-rw-r--r--src/lacbytequeue.c10
-rw-r--r--src/lacconnection.c2
-rw-r--r--src/lachttp.c38
4 files changed, 27 insertions, 27 deletions
diff --git a/src/lac.h b/src/lac.h
index 71dc7a7..8a773a0 100644
--- a/src/lac.h
+++ b/src/lac.h
@@ -190,9 +190,9 @@ LacByteQueue *lac_byte_queue_new (void);
gchar *lac_byte_queue_free (LacByteQueue *queue,
gboolean free_data);
gsize lac_byte_queue_get_length (LacByteQueue *queue);
-const gchar *lac_byte_queue_peek_data (LacByteQueue *queue,
+const gchar *lac_byte_queue_peek (LacByteQueue *queue,
gsize *n_bytes);
-gchar *lac_byte_queue_steal_data (LacByteQueue *queue,
+gchar *lac_byte_queue_steal (LacByteQueue *queue,
gsize *n_bytes);
gchar *lac_byte_queue_alloc_tail (LacByteQueue *queue,
gsize size);
diff --git a/src/lacbytequeue.c b/src/lacbytequeue.c
index 74df2fc..a3c4adb 100644
--- a/src/lacbytequeue.c
+++ b/src/lacbytequeue.c
@@ -50,7 +50,7 @@ lac_byte_queue_free (LacByteQueue *queue,
}
else
{
- result = lac_byte_queue_steal_data (queue, NULL);
+ result = lac_byte_queue_steal (queue, NULL);
}
g_free (queue);
@@ -62,8 +62,8 @@ lac_byte_queue_free (LacByteQueue *queue,
* as soon as any method is called on the queue.
*/
const gchar *
-lac_byte_queue_peek_data (LacByteQueue *queue,
- gsize *n_bytes)
+lac_byte_queue_peek (LacByteQueue *queue,
+ gsize *n_bytes)
{
if (n_bytes)
*n_bytes = queue->end - queue->start;
@@ -225,8 +225,8 @@ lac_byte_queue_append_printf (LacByteQueue *queue,
}
gchar *
-lac_byte_queue_steal_data (LacByteQueue *queue,
- gsize *n_bytes)
+lac_byte_queue_steal (LacByteQueue *queue,
+ gsize *n_bytes)
{
gchar *result;
diff --git a/src/lacconnection.c b/src/lacconnection.c
index cc8df99..e0106db 100644
--- a/src/lacconnection.c
+++ b/src/lacconnection.c
@@ -262,7 +262,7 @@ lac_connection_do_writes (LacConnection *connection)
const guint8 *unwritten;
gsize len, sent;
- unwritten = lac_byte_queue_peek_data (connection->unwritten, &len);
+ unwritten = lac_byte_queue_peek (connection->unwritten, &len);
sent = socket_send (connection->socket, unwritten, len, &err);
diff --git a/src/lachttp.c b/src/lachttp.c
index 303ed72..aa2b120 100644
--- a/src/lachttp.c
+++ b/src/lachttp.c
@@ -114,7 +114,7 @@ struct _LacHttpRequest {
GList * headers;
- GString * content;
+ LacByteQueue * content;
HttpHost * host;
gboolean canceled;
@@ -305,7 +305,7 @@ request_alloc (const LacUri *uri, LacHttpFunc func, gpointer data)
request->headers = NULL;
- request->content = g_string_new ("");
+ request->content = lac_byte_queue_new ();
request->host = NULL;
request->canceled = FALSE;
@@ -382,7 +382,7 @@ request_destroy (LacHttpRequest *request)
}
g_list_free (request->headers);
- g_string_free (request->content, TRUE);
+ lac_byte_queue_free (request->content, TRUE);
lac_byte_queue_free (request->unparsed, TRUE);
while ((event = g_queue_pop_head (request->pending_events)))
@@ -434,6 +434,9 @@ request_serialize (LacHttpRequest *request, const gchar *connection)
const gchar *method = "";
GList *list;
+
+ const gchar *content;
+ gsize content_len;
result = g_string_new ("");
@@ -493,6 +496,10 @@ request_serialize (LacHttpRequest *request, const gchar *connection)
}
g_string_append_printf (result, CRLF);
+
+ content = lac_byte_queue_peek (request->content, &content_len);
+
+ g_string_append_len (result, content, content_len);
return g_string_free (result, FALSE);
}
@@ -503,7 +510,7 @@ request_get_line (LacHttpRequest *request, gchar **result)
gchar *lf_pos;
gsize line_len;
gsize n_bytes;
- const gchar *unparsed = lac_byte_queue_peek_data (request->unparsed, &n_bytes);
+ const gchar *unparsed = lac_byte_queue_peek (request->unparsed, &n_bytes);
#if 0
g_print ("unparsed: %s\n", request->unparsed->str);
@@ -665,9 +672,7 @@ request_parse_status_line (LacHttpRequest *request)
gchar *status_line;
ParseResult result;
gsize n_bytes;
- const gchar *unparsed;
-
- unparsed = lac_byte_queue_peek_data (request->unparsed, &n_bytes);
+ const gchar *unparsed = lac_byte_queue_peek (request->unparsed, &n_bytes);
if (n_bytes < 4)
return NEED_MORE_DATA;
@@ -688,8 +693,8 @@ request_parse_status_line (LacHttpRequest *request)
if (result == ERROR)
{
- gchar *s;
#if 0
+ gchar *s;
g_print ("error in status line for %s\n",
lac_uri_string (request->uri));
@@ -761,8 +766,6 @@ real_parse_header (LacHttpRequest *request, const gchar *input)
colon = strchr (input, ':');
if (!colon)
{
- int i;
-
#if 0
g_print ("Header line without colon: \n");
@@ -900,8 +903,7 @@ static ParseResult
request_parse_chunk_data (LacHttpRequest *request)
{
gsize n_bytes;
- const gchar *unparsed = lac_byte_queue_peek_data (
- request->unparsed, &n_bytes);
+ const gchar *unparsed = lac_byte_queue_peek (request->unparsed, &n_bytes);
g_assert (request->current_chunk_size > 0);
@@ -979,8 +981,7 @@ static ParseResult
request_parse_length_delimited_body (LacHttpRequest *request)
{
gsize emit_size, n_bytes;
- const gchar *unparsed =
- lac_byte_queue_peek_data (request->unparsed, &n_bytes);
+ const gchar *unparsed = lac_byte_queue_peek (request->unparsed, &n_bytes);
g_assert (request->content_length > request->n_content_bytes);
@@ -1014,8 +1015,7 @@ static ParseResult
request_parse_close_delimited_body (LacHttpRequest *request)
{
gsize n_bytes;
- const gchar *unparsed =
- lac_byte_queue_peek_data (request->unparsed, &n_bytes);
+ const gchar *unparsed = lac_byte_queue_peek (request->unparsed, &n_bytes);
request_emit_content (request, n_bytes, unparsed);
lac_byte_queue_delete_head (request->unparsed, n_bytes);
@@ -1145,7 +1145,7 @@ request_parse_end_of_file (LacHttpRequest *request)
{
gsize n_bytes;
const gchar *unparsed =
- lac_byte_queue_peek_data (request->unparsed, &n_bytes);
+ lac_byte_queue_peek (request->unparsed, &n_bytes);
if (n_bytes > 0)
{
@@ -1644,7 +1644,7 @@ lac_http_request_add_content (LacHttpRequest *request,
request->type == PUT_REQUEST);
g_return_if_fail (data != NULL);
- g_string_append_len (request->content, data, len);
+ lac_byte_queue_append (request->content, data, len);
}
void
@@ -2509,7 +2509,7 @@ transport_dump_spam (HttpTransport *transport)
{
gsize n_bytes;
const gchar *unparsed =
- lac_byte_queue_peek_data (transport->current->unparsed, &n_bytes);
+ lac_byte_queue_peek (transport->current->unparsed, &n_bytes);
int i;
g_print ("**** transport info: \n");
g_print (" transport->current->unparsed: %d\n", n_bytes);