Re: Default charset patch (bug 0000068)

Rune Saetre <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hi again

Here is the modified patch. It now only sets charset to "ISO-8859-1" if
content type is a subtype of "text".

Regards
Rune

---
Rune Sætre <[email protected]>
NetCom as, Infrastruktur
Telefon (mob): 934 34 285
..

On Mon, 6 Dec 2004, Rune Saetre wrote:

> Hi
>
> Good point.
>
> I looked this up in RFC 2616. Snipped from section 3.7.1:
>
>    The "charset" parameter is used with some media types to define the
>    character set (section 3.4) of the data. When no explicit charset
>    parameter is provided by the sender, media subtypes of the "text"
>    type are defined to have a default charset value of "ISO-8859-1" when
>    received via HTTP. Data in character sets other than "ISO-8859-1" or
>    its subsets MUST be labeled with an appropriate charset value. See
>    section 3.4.1 for compatibility problems.
>
> So assuming ISO-8859-1 for the "text" type if nothing else is declared
> seems to be what the RFC specifies.
>
> I will make a patch that checks for type "text" as soon as I have some
> time.
>
> Regards
> Rune
>
> ---
> Rune Sætre <[email protected]>
> NetCom as, Infrastruktur
> Telefon (mob): 934 34 285
> ..
>
> On Mon, 6 Dec 2004, Guillaume Cottenceau wrote:
>
> > Rune Saetre <rune.saetre 'at' netcom-gsm.no> writes:
> >
> > > Hi
> > >
> > > Here is a patch for setting a default charset if none is indicated in the
> > > http reply. Id is fixed as indicated in bug report 0000068.
> > >
> > >   http://bugs.kannel.org/view_bug_advanced_page.php?f_id=0000068
> > >
> > > It seems to be required to see pages using international characters
> > > where the charset is not indicated by the server.
> > > There are a lot of these here in Norway.
> > >
> > > This works for me, and I have not found any ill effects (yet).
> >
> > As far as I know, this may violate the RFC.
> >
> > Do you have any pointer indicating that not specified charsets
> > must be considered ISO-8859-1?
> >
> > As far as I can see, 3.7.1 specifies that subtypes of "text" must
> > be assumed ISO-8859-1 when no charset is specified, e.g. not all
> > types.
> >
> > I think your patch should at least verify we are receiving a
> > subtype of "text".
> >
> > --
> > Guillaume Cottenceau
> >
>
kannel140_charset.patch (text/plain, 1.4 KB)
diff -uprN clean/gateway-1.4.0/gwlib/http.c fixed/gateway-1.4.0/gwlib/http.c
--- clean/gateway-1.4.0/gwlib/http.c	2004-08-11 18:41:29.000000000 +0200
+++ fixed/gateway-1.4.0/gwlib/http.c	2005-01-04 01:48:29.000000000 +0100
@@ -2928,15 +2928,21 @@ void http_header_get_content_type(List *
         semicolon = octstr_search_char(h, ';', 0);
         if (semicolon == -1) {
             *type = h;
-            *charset = octstr_create("");
+            if (octstr_ncompare(h, octstr_imm("text"), strlen("text")) == 0)
+                *charset = octstr_create("ISO-8859-1");
+            else
+                *charset = octstr_create("");
         } else {
             *charset = octstr_duplicate(h);
             octstr_delete(*charset, 0, semicolon + 1);
             octstr_strip_blanks(*charset);
             equals = octstr_search_char(*charset, '=', 0);
-            if (equals == -1)
-                octstr_truncate(*charset, 0);
-            else {
+            if (equals == -1) {
+                octstr_destroy(*charset);
+                if (octstr_ncompare(h, octstr_imm("text"), 
+                                    strlen("text")) == 0)
+                    *charset = octstr_create("ISO-8859-1");
+            } else {
                 octstr_delete(*charset, 0, equals + 1);
                 if (octstr_get_char(*charset, 0) == '"')
                     octstr_delete(*charset, 0, 1);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.