~diwic/ubuntu/lucid/pulseaudio/bugfixes

« back to all changes in this revision

Viewing changes to src/modules/raop/base64.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2009-05-05 14:18:20 UTC
  • mfrom: (1.2.4 upstream) (1.1.8 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090505141820-rrr2mtdd1jkllvr8
Tags: 1:0.9.15-1ubuntu1
* Merge from unreleased Debian pulseaudio git, remaining changes:
  - epoch (my stupid fault :S)
  - Don't build against, and create jack package. Jack is not in main
  - use linear resampler to work better with lack of PREEMPT in jaunty's
    -generic kernel config, also change buffer size
  - Add alsa configuration files to route alsa applications via pulseaudio
  - Move libasound2-plugins from Recommends to Depends
  - Add pm-utils sleep hook to suspend (and resume) users' pulseaudio
    daemons
  - patch to fix source/sink and suspend-on-idle race
  - Make initscript more informative in the default case of per-user
    sessions
  - create /var/run/pulse, and make restart more robust
  - add status check for system wide pulseaudio instance
  - LSB {Required-*,Should-*} should specify hal instead of dbus,
    since hal is required (and already requires dbus)
  - indicate that the system pulseaudio instance is being started from the init
    script
  - Install more upstream man pages
  - Link to pacat for parec man page
  - check whether pulseaudio is running before preloading the padsp library
  - Add DEB_OPT_FLAG = -O3 as per recommendation from
    pulseaudio-discuss/2007-December/001017.html
  - cache /usr/share/sounds/ubuntu/stereo/ wav files on pulseaudio load
  - disable glitch free (use tsched=0)
  - Generate a PO template on build
  - add special case to disable pulseaudio loading if accessibility/speech
    is being used
  - the sd wrapper script should not load pulseaudio if pulseaudio is being
    used as a system service
  - add a pulseaudio apport hook
  - fix some typos in README.Debian
  - demote paprefs to suggests
  - drop padevchooser(Recommends) and pavucontrol (Suggests)
  - drop libasyncns-dev build dependency, its in universe
* add libudev-dev as a build-dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***
 
2
  This file is part of PulseAudio.
 
3
 
 
4
  Copyright 2008 Colin Guthrie
 
5
 
 
6
  PulseAudio is free software; you can redistribute it and/or modify
 
7
  it under the terms of the GNU Lesser General Public License as published
 
8
  by the Free Software Foundation; either version 2.1 of the License,
 
9
  or (at your option) any later version.
 
10
 
 
11
  PulseAudio is distributed in the hope that it will be useful, but
 
12
  WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
14
  General Public License for more details.
 
15
 
 
16
  You should have received a copy of the GNU Lesser General Public License
 
17
  along with PulseAudio; if not, write to the Free Software
 
18
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
19
  USA.
 
20
***/
 
21
 
 
22
/*
 
23
  This file was originally inspired by a file developed by
 
24
    Kungliga Tekniska H�gskolan
 
25
*/
 
26
 
 
27
#ifdef HAVE_CONFIG_H
 
28
#include <config.h>
 
29
#endif
 
30
 
 
31
#include <stdlib.h>
 
32
#include <string.h>
 
33
 
 
34
#include <pulse/xmalloc.h>
 
35
 
 
36
#include "base64.h"
 
37
 
 
38
static const char base64_chars[] =
 
39
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
40
 
 
41
static int pos(char c)
 
42
{
 
43
    if (c >= 'A' && c <= 'Z') return c - 'A' + 0;
 
44
    if (c >= 'a' && c <= 'z') return c - 'a' + 26;
 
45
    if (c >= '0' && c <= '9') return c - '0' + 52;
 
46
    if (c == '+') return 62;
 
47
    if (c == '/') return 63;
 
48
    return -1;
 
49
}
 
50
 
 
51
int pa_base64_encode(const void *data, int size, char **str)
 
52
{
 
53
    char *s, *p;
 
54
    int i;
 
55
    int c;
 
56
    const unsigned char *q;
 
57
 
 
58
    p = s = pa_xnew(char, size * 4 / 3 + 4);
 
59
    q = (const unsigned char *) data;
 
60
    i = 0;
 
61
    for (i = 0; i < size;) {
 
62
        c = q[i++];
 
63
        c *= 256;
 
64
        if (i < size)
 
65
            c += q[i];
 
66
        i++;
 
67
        c *= 256;
 
68
        if (i < size)
 
69
            c += q[i];
 
70
        i++;
 
71
        p[0] = base64_chars[(c & 0x00fc0000) >> 18];
 
72
        p[1] = base64_chars[(c & 0x0003f000) >> 12];
 
73
        p[2] = base64_chars[(c & 0x00000fc0) >> 6];
 
74
        p[3] = base64_chars[(c & 0x0000003f) >> 0];
 
75
        if (i > size)
 
76
            p[3] = '=';
 
77
        if (i > size + 1)
 
78
            p[2] = '=';
 
79
        p += 4;
 
80
    }
 
81
    *p = 0;
 
82
    *str = s;
 
83
    return strlen(s);
 
84
}
 
85
 
 
86
#define DECODE_ERROR 0xffffffff
 
87
 
 
88
static unsigned int token_decode(const char *token)
 
89
{
 
90
    int i;
 
91
    unsigned int val = 0;
 
92
    int marker = 0;
 
93
    if (strlen(token) < 4)
 
94
        return DECODE_ERROR;
 
95
    for (i = 0; i < 4; i++) {
 
96
        val *= 64;
 
97
        if (token[i] == '=')
 
98
            marker++;
 
99
        else if (marker > 0)
 
100
            return DECODE_ERROR;
 
101
        else {
 
102
            int lpos = pos(token[i]);
 
103
            if (lpos < 0)
 
104
                return DECODE_ERROR;
 
105
            val += lpos;
 
106
        }
 
107
    }
 
108
    if (marker > 2)
 
109
        return DECODE_ERROR;
 
110
    return (marker << 24) | val;
 
111
}
 
112
 
 
113
int pa_base64_decode(const char *str, void *data)
 
114
{
 
115
    const char *p;
 
116
    unsigned char *q;
 
117
 
 
118
    q = data;
 
119
    for (p = str; *p && (*p == '=' || strchr(base64_chars, *p)); p += 4) {
 
120
        unsigned int val = token_decode(p);
 
121
        unsigned int marker = (val >> 24) & 0xff;
 
122
        if (val == DECODE_ERROR)
 
123
            return -1;
 
124
        *q++ = (val >> 16) & 0xff;
 
125
        if (marker < 2)
 
126
            *q++ = (val >> 8) & 0xff;
 
127
        if (marker < 1)
 
128
            *q++ = val & 0xff;
 
129
    }
 
130
    return q - (unsigned char *) data;
 
131
}