~ubuntu-branches/ubuntu/hardy/evolution-data-server/hardy-updates

« back to all changes in this revision

Viewing changes to servers/exchange/lib/e2k-encoding-utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-11-13 10:59:20 UTC
  • mfrom: (1.1.38 upstream)
  • Revision ID: james.westby@ubuntu.com-20071113105920-nb6w14udvgx0ghi3
Tags: 2.21.2-0ubuntu1
* New upstream version:
  Bug Fixes:
  - #318842: Task lists should be sorted (LP: #23912)
  - #345135: Disable SSLv2 compatible HELLO on SSL stream when 
    SSLv2 is disabled
  - #359267: Not all memos are showed in calendar view
  - #430420: Returned size <= 0 is an error
  - #460649: Meeting UI Needs To Show Color Of Selected Calendar Source
  - #487229: Use GKeyFile instead of gnome-config to access stored passwords
  - #488156: Minimize use of the WITH_GNOME_KEYRING macro
  - #492130: ESourceSelector uses pointers to ESource
  - #494304: Fix leak
  Updated Translations
  New in 2.21.1:
  - Support for Google Calendar
  Bug Fixes:
  - #203480: (Novell Bugzilla) Compiler warning fix 
    for usage ofunintialized variable
  - #231178: New symbol 'set-label' defined and added corresponding callback
  - #271777: Keep character's case as user types
  - #417999: Don't use deprecated GTK+ symbols
  - #420167: e-d-s now exits with gnome-session
  - #469657: Better use of GHashTable
  - #474000: Use GLib's Base64 API instead of Camel's
  - #475487: When creating the default contact, print errors to the console
  - #475493: Use G_DEFINE_TYPE
  - #475494: Use G_LOCK instead of a static mutex for clearer code
  - #478404: Reset the id to zero
  - #483301: Remove an unused variable
  - #487270: Fix typo in documentation
  - #488173: Remove __FUNCTION__, which is a gcc-ism
  - #488351: Fix an addressbook error on a fresh install
  Other Contributors:
  - Protect against a NULL subject string. 
* debian/*.preinst:
  - On upgrades from Gutsy, remove the symlinks introduced in Gutsy. They
    break upgrades all over, and current cdbs just symlinks individual files.
* Sync with Debian
* debian/control:
  - evolution-data-server Breaks evolution (<< 2.9), 
    evolution-exchange (<= 2.8.1-0ubuntu1),
    evolution-jescs (<= 2.8.2-0ubuntu3), 
    evolution-scalix (<= 10.0.0.357-0ubuntu6)
  - updated maintainer to desktop team
* debian/rules:
  - don't specify the paths for nspr and nss since the package is built 
    with firefox
  - don't build documentation, it's distributed in the upstream tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
 
3
 
/* Copyright (C) 2001-2004 Novell, Inc.
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or
6
 
 * modify it under the terms of version 2 of the GNU Lesser General Public
7
 
 * License as published by the Free Software Foundation.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
 * General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU Lesser General Public
15
 
 * License along with this program; if not, write to the
16
 
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 
 * Boston, MA 02110-1301, USA.
18
 
 */
19
 
 
20
 
#ifdef HAVE_CONFIG_H
21
 
#include "config.h"
22
 
#endif
23
 
 
24
 
#include "e2k-encoding-utils.h"
25
 
 
26
 
#include <string.h>
27
 
 
28
 
static const char *b64_alphabet =
29
 
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
30
 
 
31
 
/**
32
 
 * e2k_base64_encode:
33
 
 * @data: binary data
34
 
 * @len: the length of @data
35
 
 *
36
 
 * Base64-encodes @len bytes of data at @data.
37
 
 *
38
 
 * Return value: the base64-encoded representation of @data, which
39
 
 * the caller must free.
40
 
 **/
41
 
char *
42
 
e2k_base64_encode (const guint8 *data, int len)
43
 
{
44
 
        char *buf, *p;
45
 
 
46
 
        p = buf = g_malloc (((len + 2) / 3) * 4 + 1);
47
 
        while (len >= 3) {
48
 
                p[0] = b64_alphabet[ (data[0] >> 2) & 0x3f];
49
 
                p[1] = b64_alphabet[((data[0] << 4) & 0x30) +
50
 
                                    ((data[1] >> 4) & 0x0f)];
51
 
                p[2] = b64_alphabet[((data[1] << 2) & 0x3c) +
52
 
                                    ((data[2] >> 6) & 0x03)];
53
 
                p[3] = b64_alphabet[  data[2]       & 0x3f];
54
 
 
55
 
                data += 3;
56
 
                p += 4;
57
 
                len -= 3;
58
 
        }
59
 
 
60
 
        switch (len) {
61
 
        case 2:
62
 
                p[0] = b64_alphabet[ (data[0] >> 2) & 0x3f];
63
 
                p[1] = b64_alphabet[((data[0] << 4) & 0x30) +
64
 
                                    ((data[1] >> 4) & 0xf)];
65
 
                p[2] = b64_alphabet[ (data[1] << 2) & 0x3c];
66
 
                p[3] = '=';
67
 
                p += 4;
68
 
                break;
69
 
        case 1:
70
 
                p[0] = b64_alphabet[ (data[0] >> 2) & 0x3f];
71
 
                p[1] = b64_alphabet[ (data[0] << 4) & 0x30];
72
 
                p[2] = '=';
73
 
                p[3] = '=';
74
 
                p += 4;
75
 
                break;
76
 
        }
77
 
 
78
 
        *p = '\0';
79
 
        return buf;
80
 
}
81
 
 
82
 
static guint8 base64_unphabet[] = {
83
 
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -2, -1, -1,
84
 
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
85
 
        -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
86
 
        52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
87
 
        -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
88
 
        15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
89
 
        -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
90
 
        41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
91
 
};
92
 
#define E2K_B64_SPACE ((guint8)-2)
93
 
#define E2K_B64_BAD   ((guint8)-1)
94
 
 
95
 
/**
96
 
 * e2k_base64_decode:
97
 
 * @string: base64-encoded data
98
 
 *
99
 
 * Decodes the base64-encoded data in @string.
100
 
 *
101
 
 * Return value: the binary data encoded in @string
102
 
 **/
103
 
GByteArray *
104
 
e2k_base64_decode (const char *string)
105
 
{
106
 
        GByteArray *rc;
107
 
        int bits, length, qw = 0;
108
 
        guint8 *data;
109
 
 
110
 
        rc = g_byte_array_new ();
111
 
 
112
 
        length = strlen (string);
113
 
        if (length == 0)
114
 
                return rc;
115
 
 
116
 
        g_byte_array_set_size (rc, ((length / 4) + 1) * 3);
117
 
 
118
 
        data = rc->data;
119
 
        for (; *string; string++) {
120
 
                if ((unsigned char)*string > 127)
121
 
                        break;
122
 
                bits = base64_unphabet[(unsigned char)*string];
123
 
                if (bits == E2K_B64_BAD)
124
 
                        break;
125
 
                else if (bits == E2K_B64_SPACE)
126
 
                        continue;
127
 
 
128
 
                switch (qw++) {
129
 
                case 0:
130
 
                        data[0]  = (bits << 2) & 0xfc;
131
 
                        break;
132
 
                case 1:
133
 
                        data[0] |= (bits >> 4) & 0x03;
134
 
                        data[1]  = (bits << 4) & 0xf0;
135
 
                        break;
136
 
                case 2:
137
 
                        data[1] |= (bits >> 2) & 0x0f;
138
 
                        data[2]  = (bits << 6) & 0xc0;
139
 
                        break;
140
 
                case 3:
141
 
                        data[2] |=  bits       & 0x3f;
142
 
                        data += 3;
143
 
                        qw = 0;
144
 
                        break;
145
 
                }
146
 
        }
147
 
 
148
 
        rc->len = data - rc->data;
149
 
        if (qw > 1)
150
 
                rc->len += qw - 1;
151
 
        return rc;
152
 
}