fixed GTKHTML detection
[k8lowj.git] / src / network-libxml.c
bloba1309e7319cfcf7feb8c2302c567fd76661938ce
1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2004 Evan Martin <martine@danga.com>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
5 */
6 #if 0
8 #include "glib-all.h"
10 #include <libxml/nanohttp.h>
12 #include "conf.h"
13 #include "network.h"
14 #include "network-internal.h"
16 GString*
17 net_post_blocking(const char *url, GSList *headers, GString *post,
18 NetStatusCallback cb, gpointer data,
19 GError **err) {
20 void *ctx = NULL;
21 char buf[2048];
22 char *headerstr = NULL;
23 GString *response = NULL;
24 gboolean success = FALSE;
25 int len;
26 NetStatusProgress progress;
28 if (conf.options.netdump && post)
29 fprintf(stderr, _("Request: [%s]\n"), post->str);
31 xmlNanoHTTPInit();
33 if (conf.options.useproxy) {
34 if (conf.proxyuser) {
35 g_set_error(err, NET_ERROR, NET_ERROR_GENERIC,
36 _("LogJam was built with libxml's NanoHTTP support, "
37 "which does not support proxy authentication."));
38 goto out;
40 xmlNanoHTTPScanProxy(conf.proxy);
41 } else {
42 /* reset any potentially lingering proxy information. */
43 xmlNanoHTTPScanProxy(NULL);
46 if (headers) {
47 GString *hs = g_string_new(NULL);
48 GSList *l;
49 for (l = headers; l; l = l->next) {
50 g_string_append(hs, l->data);
51 g_string_append(hs, "\r\n");
53 headerstr = hs->str;
54 g_string_free(hs, FALSE);
56 if (post)
57 ctx = xmlNanoHTTPMethod(url, "POST",
58 post->str, NULL, headerstr, post->len);
59 else
60 ctx = xmlNanoHTTPMethod(url, "GET", NULL, NULL, headerstr, 0);
62 if (!ctx) {
63 g_set_error(err, NET_ERROR, NET_ERROR_GENERIC,
64 _("xmlNanoHTTPMethod error."));
65 goto out;
68 switch (xmlNanoHTTPReturnCode(ctx)) {
69 case 404:
70 /* HTTP 404 message: file not found. */
71 g_set_error(err, NET_ERROR, NET_ERROR_PROTOCOL,
72 _("File not found."));
73 goto out;
74 default:
75 ; /* supress warning */
78 response = g_string_new(NULL);
79 for (;;) {
80 len = xmlNanoHTTPRead(ctx, buf, sizeof(buf));
81 if (len < 0) {
82 g_set_error(err, NET_ERROR, NET_ERROR_GENERIC,
83 _("xmlNanoHTTPRead error."));
84 goto out;
85 } else if (len == 0) {
86 break;
87 } else {
88 g_string_append_len(response, buf, len);
91 if (cb) {
92 progress.current = response->len;
93 progress.total = 0;/* XXX (int)contentlength; */
95 cb(NET_STATUS_PROGRESS, &progress, data);
99 success = TRUE;
101 if (conf.options.netdump)
102 fprintf(stderr, _("Response: [%s]\n"), response->str);
104 out:
105 g_free(headerstr);
106 if (ctx)
107 xmlNanoHTTPClose(ctx);
108 if (!success && response) {
109 g_string_free(response, TRUE);
110 response = NULL;
112 return response;
115 #endif