File: html_common.c

package info (click to toggle)
prayer 1.3.4-dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,416 kB
  • sloc: ansic: 43,089; makefile: 812; sh: 451; perl: 166
file content (105 lines) | stat: -rw-r--r-- 3,281 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* $Cambridge: hermes/src/prayer/shared/html_common.c,v 1.4 2008/09/16 09:59:58 dpc22 Exp $ */
/************************************************
 *    Prayer - a Webmail Interface              *
 ************************************************/

/* Copyright (c) University of Cambridge 2000 - 2008 */
/* See the file NOTICE for conditions of use and distribution. */

#include "shared.h"

/* Set of routines for generating chunks of HTML markup. */

/* html_common_start() ***************************************************
 *
 * HTML header
 ************************************************************************/

void
html_common_start(struct config *config, struct buffer *b, char *title)
{
    struct config_theme *theme = config->theme_main;

    bputs(b, ("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\""
              " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"CRLF));
    bputs(b, ("<html xmlns=\"http://www.w3.org/1999/xhtml\""
              " lang=\"en\" xml:lang=\"en\">"CRLF));
    bputs(b, "<head>"CRLF);
    bprintf(b, "<title>Webmail service: %s</title>" CRLF, title);
    bputs(b, "<meta name=\"robots\" content=\"none\" />" CRLF);
    bputs(b, ("<meta http-equiv=\"Content-Type\" "
              "content=\"text/html; charset=UTF-8\" />" CRLF));
    bprintf(b, ("<link rel=\"stylesheet\""
                " href=\"/static/%s.css\""
                " type=\"text/css\" />"CRLF), theme->name);
    bputs(b, "</head>" CRLF);
    bputs(b, "<body>"CRLF);
}

/* html_common_end() *****************************************************
 *
 * End of HTML body
 ************************************************************************/

void html_common_end(struct buffer *b)
{
    bprintf(b, "</body></html>" CRLF);
}

/* ====================================================================== */

/* html_common_quote_char() *********************************************
 *
 * Print character replacing significant HTML characters with eqivalent
 * escape sequences.
 * translation stuff.
 *     b: Buffer
 *     c: Character to print
 ***********************************************************************/

static void html_common_quote_char(struct buffer *b, unsigned char c)
{
    if (c > 127) {
        bprintf(b, "&#%lu;", (unsigned long) c);
    } else
        switch (c) {
        case ' ':
            bputs(b, "&nbsp;");
            break;
        case '"':
            bputs(b, "&quot;");
            break;
        case '&':
            bputs(b, "&amp;");
            break;
        case '<':
            bputs(b, "&lt;");
            break;
        case '>':
            bputs(b, "&gt;");
            break;
        default:
            bputc(b, c);
        }
}

/* html_common_quote() ***************************************************
 *
 * Print string replacing significant HTML characters with eqivalent
 * escape sequences.
 * translation stuff.
 *     b: Buffer
 *     t: String to print
 ***********************************************************************/

void html_common_quote_string(struct buffer *b, char *t)
{
    unsigned char *s = (unsigned char *) t;
    unsigned char c;

    if (!s)
        bputs(b, "(nil)");
    else
        while ((c = *s++))
            html_common_quote_char(b, c);
}