annotate src/web.cc @ 2102:e1973d1962c5

rm comment warning about (left|right)-tab
author corvid <corvid@lavabit.com>
date Tue, 21 Jun 2011 00:15:55 +0000
parents 16cdda1f8379
children
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 * File: web.cc
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3 *
35
d9e7b35430de Updated copyright lines
jcid
parents: 19
diff changeset
4 * Copyright 2005-2007 Jorge Arellano Cid <jcid@dillo.org>
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 * (at your option) any later version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12 #include "msg.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13 #include "nav.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
15 #include "uicmd.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
16
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17 #include "IO/IO.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 #include "IO/mime.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20 #include "dw/core.hh"
982
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 930
diff changeset
21 #include "styleengine.hh"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 #include "web.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23
360
1354085ccbfe - Removed the remaining DEBUG_MSG in src/
jcid
parents: 327
diff changeset
24 // Platform independent part
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25 using namespace dw::core;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29 * Local data
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31 static Dlist *ValidWebs; /* Active web structures list; it holds
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32 * pointers to DilloWeb structures. */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
34 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
35 * Initialize local data
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
36 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
37 void a_Web_init(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
38 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
39 ValidWebs = dList_new(32);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
40 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
41
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
42 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
43 * Given the MIME content type, and a fd to read it from,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
44 * this function connects the proper MIME viewer to it.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
45 * Return value:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
46 * 1 on success (and Call and Data properly set).
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 * -1 for unhandled MIME types (and Call and Data untouched).
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49 int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50 CA_Callback_t *Call, void **Data)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52 Widget *dw = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53
360
1354085ccbfe - Removed the remaining DEBUG_MSG in src/
jcid
parents: 327
diff changeset
54 _MSG("a_Web_dispatch_by_type\n");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
56 dReturn_val_if_fail(Web->bw != NULL, -1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
57
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
58 // get the Layout object from the bw structure.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
59 Layout *layout = (Layout*)Web->bw->render_layout;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
60
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
61 if (Web->flags & WEB_RootUrl) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
62 /* We have RootUrl! */
982
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 930
diff changeset
63
1730
2c90a2e90866 call layout->setBgColor() from web.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1644
diff changeset
64 style::Color *bgColor = style::Color::create (layout, prefs.bg_color);
2c90a2e90866 call layout->setBgColor() from web.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1644
diff changeset
65 Web->bgColor = bgColor->getColor ();
2c90a2e90866 call layout->setBgColor() from web.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1644
diff changeset
66 layout->setBgColor (bgColor);
2c90a2e90866 call layout->setBgColor() from web.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1644
diff changeset
67
982
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 930
diff changeset
68 /* Set a style for the widget */
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 930
diff changeset
69 StyleEngine styleEngine (layout);
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 930
diff changeset
70 styleEngine.startElement ("body");
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 930
diff changeset
71
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
72 dw = (Widget*) a_Mime_set_viewer(Type, Web, Call, Data);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
73 if (dw == NULL)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74 return -1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
75
982
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 930
diff changeset
76 dw->setStyle (styleEngine.style ());
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
77
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
78 /* This method frees the old dw if any */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
79 layout->setWidget(dw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80
2093
16cdda1f8379 Made tab and window titles more informative (WRT length)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1743
diff changeset
81 /* Set the page title with the bare filename (e.g. for images),
16cdda1f8379 Made tab and window titles more informative (WRT length)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1743
diff changeset
82 * HTML pages with a <TITLE> tag will overwrite it later */
16cdda1f8379 Made tab and window titles more informative (WRT length)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1743
diff changeset
83 const char *p = strrchr(URL_STR(Web->url), '/');
16cdda1f8379 Made tab and window titles more informative (WRT length)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1743
diff changeset
84 a_UIcmd_set_page_title(Web->bw, p ? p+1 : "");
16cdda1f8379 Made tab and window titles more informative (WRT length)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1743
diff changeset
85
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86 a_UIcmd_set_location_text(Web->bw, URL_STR(Web->url));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87 /* Reset both progress bars */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
88 a_UIcmd_set_page_prog(Web->bw, 0, 2);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
89 a_UIcmd_set_img_prog(Web->bw, 0, 0, 2);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
90 /* Reset the bug meter */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
91 a_UIcmd_set_bug_prog(Web->bw, 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
92
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
93 /* Let the Nav module know... */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
94 a_Nav_expect_done(Web->bw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
95
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
96 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
97 /* A non-RootUrl. At this moment we only handle image-children */
1721
8a4b1d7c0b0d clearer msg when can't display something as image
corvid <corvid@lavabit.com>
parents: 1644
diff changeset
98 if (!dStrncasecmp(Type, "image/", 6)) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
99 dw = (Widget*) a_Mime_set_viewer(Type, Web, Call, Data);
1721
8a4b1d7c0b0d clearer msg when can't display something as image
corvid <corvid@lavabit.com>
parents: 1644
diff changeset
100 } else {
8a4b1d7c0b0d clearer msg when can't display something as image
corvid <corvid@lavabit.com>
parents: 1644
diff changeset
101 MSG_HTTP("'%s' cannot be displayed as image; has media type '%s'\n",
8a4b1d7c0b0d clearer msg when can't display something as image
corvid <corvid@lavabit.com>
parents: 1644
diff changeset
102 URL_STR(Web->url), Type);
8a4b1d7c0b0d clearer msg when can't display something as image
corvid <corvid@lavabit.com>
parents: 1644
diff changeset
103 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
104 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
105 return (dw ? 1 : -1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
106 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
107
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
108
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
109 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
110 * Allocate and set safe values for a DilloWeb structure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
111 */
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1267
diff changeset
112 DilloWeb* a_Web_new(const DilloUrl *url, const DilloUrl *requester)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
113 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
114 DilloWeb *web= dNew(DilloWeb, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
115
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
116 _MSG(" a_Web_new: ValidWebs ==> %d\n", dList_length(ValidWebs));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
117 web->url = a_Url_dup(url);
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1267
diff changeset
118 web->requester = a_Url_dup(requester);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
119 web->bw = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
120 web->flags = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
121 web->Image = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
122 web->filename = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
123 web->stream = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
124 web->SavedBytes = 0;
982
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 930
diff changeset
125 web->bgColor = 0x000000; /* Dummy value will be overwritten
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 930
diff changeset
126 * in a_Web_dispatch_by_type. */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
127 dList_append(ValidWebs, (void *)web);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
128 return web;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
129 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
130
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
131 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
132 * Validate a DilloWeb pointer
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
133 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
134 int a_Web_valid(DilloWeb *web)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
135 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
136 return (dList_find(ValidWebs, web) != NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
137 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
138
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
139 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
140 * Deallocate a DilloWeb structure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
141 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
142 void a_Web_free(DilloWeb *web)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
143 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
144 if (!web) return;
1067
73aba13ddaed Removed redundant caller NULL checks already in the API
Jeremy Henty <onepoint@starurchin.org>
parents: 1039
diff changeset
145 a_Url_free(web->url);
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1267
diff changeset
146 a_Url_free(web->requester);
1067
73aba13ddaed Removed redundant caller NULL checks already in the API
Jeremy Henty <onepoint@starurchin.org>
parents: 1039
diff changeset
147 a_Image_unref(web->Image);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
148 dFree(web->filename);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
149 dList_remove(ValidWebs, (void *)web);
1267
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1186
diff changeset
150 _MSG("a_Web_free: ValidWebs=%d\n", dList_length(ValidWebs));
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
151 dFree(web);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
152 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
153