Review: Merge branch mmu_man/netsurf-gopher-support

2011-05-04 Thread François Revol

Precis:

Gopher browsing is now mostly functional.

Due to having to wait for the full content before converting to html, large 
pages like search results might take some seconds to load, but otherwise it 
works not too bad.

Supported item-types:
- 0 (plain text)
- 1 (gopher dir) converted to html for display
- 3 (error, when first item should behave as an HTTP 404, not much tested)
- 7 (search) converted to html for display
- 8 generates a link to a telnet: URI
- g (GIF) adds a link (or optionally inlines the image as img)
- h (html) selectors begining with URL: are automatically converted to direct 
links to the specified URL, which then is not limited to http: either.
- i displays a text line
- I (image) links to the item but tries to display as text.
- 9 (binary) links to the item but tries to display as text.
- d (PDF, unofficial)
- p (seems to be PNG, unofficial)
- all other unknown types are just linked as is, and will probably work when 
the mime type is correctly sniffed.

Unsupported item-types:
- 2 (CSO search) I failed to find a sample link, it requires a complex and 
separate protocol.
- T (TN3270) Failed to find a sample link, it's an antique competitor to telnet.

Missing stuff, which will be considered in a second iteration:
- document the feature.
- document requirements for ports (like, OSX requires libcurl from MacPort to 
have the fetcher working).
- better error handling on non-existing files (will require an heuristic since 
gopher doesn't have out-of-band signaling).
- make the parser more robust.
- fix url escaping in generated html code, gopher selectors can include any 
character except tab, though no tested servers ever tried using reserved html 
chars yet.
- merge custom generated CSS with internal.css.
- improve the used CSS (reuse the blueish dirlist one ?).
- add text/dir/search icons like other usual clients (optional ?).
- links to ambiguous items (like type 'I' which can be JPEG or PNG or another 
image type, and binary types like '9') will attempt to load the target as a 
text file. Handling them correctly probably requires implementing 
LLCACHE_RETRIEVE_SNIFF_TYPE. Archive types could probably get a fake 
Content-disposition header forcing a download though.
- make gopher: URI scheme handling explicit to OS front-ends (done for BeOS).
- fix search field sending an extra = in the url (add a GOPHER form method 
maybe ?), though all tested search engines just skip it.
- maybe Gopher+ support but it seems most clients just ignore it.



Added files


Index: render/gopher.c
===
--- /dev/null   2011-05-04 14:01:53.0 +0200
+++ render/gopher.c 2011-05-04 12:18:42.0 +0200
@@ -0,0 +1,662 @@
+/*
+ * Copyright 2006 James Bursa bu...@users.sourceforge.net
+ * Copyright 2006 Adrian Lees adri...@users.sourceforge.net
+ * Copyright 2011 François Revol mmu_...@users.sourceforge.net
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see http://www.gnu.org/licenses/.
+ */
+
+/** \file
+ * Content for text/x-gopher-directory (implementation).
+ */
+
+#include errno.h
+#include stddef.h
+#include string.h
+#include strings.h
+#include math.h
+
+#include content/content_protected.h
+#include desktop/gui.h
+#include desktop/options.h
+#include render/gopher.h
+#include utils/http.h
+#include utils/log.h
+#include utils/messages.h
+#include utils/utils.h
+
+static char *gen_nice_title(const char *path);
+static bool gopher_generate_top(char *buffer, int buffer_length);
+static bool gopher_generate_title(const char *title, char *buffer, int 
buffer_length);
+static bool gopher_generate_row(const char **data, size_t *size,
+   char *buffer, int buffer_length);
+static bool gopher_generate_bottom(char *buffer, int buffer_length);
+
+
+static struct {
+   char type;
+   const char *mime;
+} gopher_type_map[] = {
+   /* these come from http://tools.ietf.org/html/rfc1436 */
+   { '0', text/plain },
+   { '1', text/x-gopher-directory;charset=UTF-8 },   /* gopher 
directory */
+   /* 2CSO search */
+   /* 3error message */
+   /* 4binhex encoded text */
+   /* 5binary archive file */
+   /* 6uuencoded text */
+   { '7', text/x-gopher-directory;charset=UTF-8 },   /* search query 
*/
+   /* 8telnet: */
+   /* 9binary */
+   { 'g', image/gif 

Re: Review: Content factory

2011-05-04 Thread Vincent Sanders
On Wed, May 04, 2011 at 10:33:08PM +0100, John-Mark Bell wrote:
 
 Precis:
 
 This changeset introduces a content factory with which content handlers may 
 be dynamically registered.
 Additionally, it inverts the inheritance model of contents such that each 
 content handler becomes self-contained.

schweeet!

as usual my review will be inline and I shall elide any bits I have no
comment on


 Index: render/html_internal.h
 ===
 --- /dev/null 2009-04-16 19:17:07.0 +0100
 +++ render/html_internal.h2011-05-04 22:29:08.0 +0100
 @@ -0,0 +1,103 @@
 +/*
 + * Copyright 2004 James Bursa bu...@users.sourceforge.net

really? I think its 2011 and you added this file ;-) maybe its a move tho?

 +
 +/** Data specific to CONTENT_HTML. */
 +typedef struct html_content {
 + struct content base;
 +
 + void *parser_binding;
 + xmlDoc *document;
 + binding_quirks_mode quirks; /** Quirkyness of document */
 +
 + char *encoding; /** Encoding of source, 0 if unknown. */
 + binding_encoding_source encoding_source;
 + /** Source of encoding information. */
 +
 + char *base_url; /** Base URL (may be a copy of content-url). */
 + char *base_target;  /** Base target */
 +
 + struct box *layout;  /** Box tree, or 0. */
 + colour background_colour;  /** Document background colour. */
 + const struct font_functions *font_func;
 +
 + /** Number of entries in stylesheet_content. */
 + unsigned int stylesheet_count;
 + /** Stylesheets. Each may be 0. */
 + struct html_stylesheet *stylesheets;
 + /** Style selection context */
 + css_select_ctx *select_ctx;
 +
 + /** Number of entries in object_list. */
 + unsigned int num_objects;
 + /** List of objects. */
 + struct content_html_object *object_list;
 + /** Forms, in reverse order to document. */
 + struct form *forms;
 + /** Hash table of imagemaps. */
 + struct imagemap **imagemaps;
 +
 + /** Browser window containing this document, or 0 if not open. */
 + struct browser_window *bw;
 +
 + /** Frameset information */
 + struct content_html_frames *frameset;
 +
 + /** Inline frame information */
 + struct content_html_iframe *iframe;
 +
 + /** Content of type CONTENT_HTML containing this, or 0 if not an object
 +  * within a page. */
 + struct html_content *page;
 + /** Box containing this, or 0 if not an object. */
 + struct box *box;
 +} html_content;

gah make a decision on before or after doccomments within one struct
;-) and are we saying 0 or NULL for empty ponters?


 +
 +
 +bool html_fetch_object(html_content *c, const char *url, struct box *box,
 + content_type permitted_types,
 + int available_width, int available_height,
 + bool background);
 +
 +void html_set_status(html_content *c, const char *extra);
 +
 +/* in render/html_redraw.c */
 +bool html_redraw(struct content *c, int x, int y,
 + int width, int height, const struct rect *clip,
 + float scale, colour background_colour);
 +
 +/* in render/html_interaction.c */
 +void html_mouse_track(struct content *c, struct browser_window *bw,
 + browser_mouse_state mouse, int x, int y);
 +void html_mouse_action(struct content *c, struct browser_window *bw,
 + browser_mouse_state mouse, int x, int y);
 +void html_overflow_scroll_callback(void *client_data,
 + struct scroll_msg_data *scroll_data);
 +
 +#endif

no doccomments?

 Index: image/image.c
 ===
 --- /dev/null 2009-04-16 19:17:07.0 +0100
 +++ image/image.c 2011-05-04 22:29:39.0 +0100


 +
 +nserror image_init(void)
 +{

comment? or at least a ref to the header?

 +
 +void image_fini(void)

ditto


 Index: content/content_factory.c
 ===
 --- /dev/null 2009-04-16 19:17:07.0 +0100
 +++ content/content_factory.c 2011-05-04 22:30:17.0 +0100

file comment?

 +
 +typedef struct content_handler_entry {


 + struct content_handler_entry *next;
 +
 + lwc_string *mime_type;
 + const content_handler *handler;
 +} content_handler_entry;


whassat for then? comment teh struct a bit? tbh i shall shut up about
comments now, its boring

 +
 +static content_handler_entry *content_handlers;
 +
 +nserror content_factory_register_handler(lwc_string *mime_type,
 + const content_handler *handler)
 +{
 + content_handler_entry *e;

e? really? perhaps entry might have been a little less brief?

 +
 +content_type content_factory_type_from_mime_type(const char *mime_type)
 +{
 + const content_handler *handler;
 + lwc_string *imime_type;
 + lwc_error lerror;
 + content_type type;
 +
 + lerror = lwc_intern_string(mime_type,