~ubuntu-branches/ubuntu/utopic/dovecot/utopic

« back to all changes in this revision

Viewing changes to src/lib/unichar.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2005-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "array.h"
37
37
 
38
38
int uni_utf8_get_char_n(const void *_input, size_t max_len, unichar_t *chr_r)
39
39
{
 
40
        static unichar_t lowest_valid_chr_table[] =
 
41
                { 0, 0, 0x80, 0x800, 0x10000, 0x200000, 0x4000000 };
40
42
        const unsigned char *input = _input;
41
 
        unichar_t chr;
 
43
        unichar_t chr, lowest_valid_chr;
42
44
        unsigned int i, len;
43
45
        int ret;
44
46
 
75
77
                return -1;
76
78
        }
77
79
 
78
 
        if (len <= max_len)
 
80
        if (len <= max_len) {
 
81
                lowest_valid_chr = lowest_valid_chr_table[len];
79
82
                ret = 1;
80
 
        else {
 
83
        } else {
81
84
                /* check first if the input is invalid before returning 0 */
 
85
                lowest_valid_chr = 0;
82
86
                ret = 0;
83
87
                len = max_len;
84
88
        }
91
95
                chr <<= 6;
92
96
                chr |= input[i] & 0x3f;
93
97
        }
 
98
        if (chr < lowest_valid_chr) {
 
99
                /* overlong encoding */
 
100
                return -1;
 
101
        }
94
102
 
95
103
        *chr_r = chr;
96
104
        return ret;
279
287
 
280
288
static bool uni_ucs4_decompose_multi_utf8(unichar_t chr, buffer_t *output)
281
289
{
282
 
        const uint16_t *value;
 
290
        const uint32_t *value;
283
291
        unsigned int idx;
284
292
 
285
293
        if (chr < multidecomp_keys[0] || chr > 0xffff)
307
315
        buffer_append(output, utf8_replacement_char, UTF8_REPLACEMENT_CHAR_LEN);
308
316
}
309
317
 
310
 
int uni_utf8_to_decomposed_titlecase(const void *_input, size_t max_len,
 
318
int uni_utf8_to_decomposed_titlecase(const void *_input, size_t size,
311
319
                                     buffer_t *output)
312
320
{
313
321
        const unsigned char *input = _input;
315
323
        unichar_t chr;
316
324
        int ret = 0;
317
325
 
318
 
        while (max_len > 0 && *input != '\0') {
319
 
                if (uni_utf8_get_char_n(input, max_len, &chr) <= 0) {
 
326
        while (size > 0) {
 
327
                if (uni_utf8_get_char_n(input, size, &chr) <= 0) {
320
328
                        /* invalid input. try the next byte. */
321
329
                        ret = -1;
322
 
                        input++; max_len--;
 
330
                        input++; size--;
323
331
                        output_add_replacement_char(output);
324
332
                        continue;
325
333
                }
326
334
                bytes = uni_utf8_char_bytes(*input);
327
335
                input += bytes;
328
 
                max_len -= bytes;
 
336
                size -= bytes;
329
337
 
330
338
                chr = uni_ucs4_to_titlecase(chr);
331
339
                if (chr >= HANGUL_FIRST && chr <= HANGUL_LAST)
340
348
static inline unsigned int
341
349
is_valid_utf8_seq(const unsigned char *input, unsigned int size)
342
350
{
343
 
        unsigned int i, len;
 
351
        unichar_t chr;
344
352
 
345
 
        len = uni_utf8_char_bytes(input[0]);
346
 
        if (unlikely(len > size || len == 1))
 
353
        if (uni_utf8_get_char_n(input, size, &chr) <= 0)
347
354
                return 0;
348
 
 
349
 
        /* the rest of the chars should be in 0x80..0xbf range.
350
 
           anything else is start of a sequence or invalid */
351
 
        for (i = 1; i < len; i++) {
352
 
                if (unlikely(input[i] < 0x80 || input[i] > 0xbf))
353
 
                        return 0;
354
 
        }
355
 
        return len;
 
355
        return uni_utf8_char_bytes(input[0]);
356
356
}
357
357
 
358
358
static int uni_utf8_find_invalid_pos(const unsigned char *input, size_t size,