1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2004 Evan Martin <martine@danga.com>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
6 #if !defined(HAVE_CURL) && !defined(HAVE_LIBSOUP)
10 #include <libxml/nanohttp.h>
14 #include "network-internal.h"
17 GString
*net_post_blocking (const char *url
, GSList
*headers
, GString
*post
, NetStatusCallback cb
, gpointer data
, GError
**err
) {
20 char *headerstr
= NULL
;
21 GString
*response
= NULL
;
22 gboolean success
= FALSE
;
24 NetStatusProgress progress
;
26 if (conf
.options
.netdump
&& post
) fprintf(stderr
, _("Request: [%s]\n"), post
->str
);
30 if (conf
.options
.useproxy
) {
32 g_set_error(err
, NET_ERROR
, NET_ERROR_GENERIC
, "%s", _("LogJam was built with libxml's NanoHTTP support, " "which does not support proxy authentication."));
35 xmlNanoHTTPScanProxy(conf
.proxy
);
37 /* reset any potentially lingering proxy information. */
38 xmlNanoHTTPScanProxy(NULL
);
42 GString
*hs
= g_string_new(NULL
);
44 for (l
= headers
; l
; l
= l
->next
) {
45 g_string_append(hs
, l
->data
);
46 g_string_append(hs
, "\r\n");
49 g_string_free(hs
, FALSE
);
52 ctx
= xmlNanoHTTPMethod(url
, "POST", post
->str
, NULL
, headerstr
, post
->len
);
54 ctx
= xmlNanoHTTPMethod(url
, "GET", NULL
, NULL
, headerstr
, 0);
58 g_set_error(err
, NET_ERROR
, NET_ERROR_GENERIC
, "%s", _("xmlNanoHTTPMethod error."));
62 switch (xmlNanoHTTPReturnCode(ctx
)) {
63 case 404: /* HTTP 404 message: file not found. */
64 g_set_error(err
, NET_ERROR
, NET_ERROR_PROTOCOL
, "%s", _("File not found."));
66 default: ; /* supress warning */
69 response
= g_string_new(NULL
);
71 len
= xmlNanoHTTPRead(ctx
, buf
, sizeof(buf
));
73 g_set_error(err
, NET_ERROR
, NET_ERROR_GENERIC
, "%s", _("xmlNanoHTTPRead error."));
75 } else if (len
== 0) {
78 g_string_append_len(response
, buf
, len
);
81 progress
.current
= response
->len
;
82 progress
.total
= 0; /* XXX (int)contentlength; */
83 cb(NET_STATUS_PROGRESS
, &progress
, data
);
89 if (conf
.options
.netdump
) fprintf(stderr
, _("Response: [%s]\n"), response
->str
);
93 if (ctx
) xmlNanoHTTPClose(ctx
);
94 if (!success
&& response
) {
95 g_string_free(response
, TRUE
);