~diwic/ubuntu/lucid/pulseaudio/bugfixes

« back to all changes in this revision

Viewing changes to src/pulsecore/protocol-http.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2008-11-04 15:46:00 UTC
  • mfrom: (1.2.1 upstream) (1.1.6 lenny)
  • Revision ID: james.westby@ubuntu.com-20081104154600-hlzknpcazaam0nxm
Tags: 0.9.13-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Don't build against, and create jack package. Jack is not in main.
  - Remove --disable-per-user-esound-socket from configure flags, as we still
    want per user esound sockets.
  - Remove stop links from rc0 and rc6.
  - Change default resample algorithm and bubffer size.
  - Add alsa configuration files to route alsa applications via pulseaudio.
  - Move libasound2-plugins from Recommends to Depends.
* debian/pulseaudio.preinst: When upgrading from intrepid, remove
  /etc/X11/Xsession.d/70pulseaudio, as this was used to minimize a race
  condition when starting GNOME in intrepid. This race should not exist in
  jaunty once libcanberra is built to use pulseaudio as a backend.
* Do not spawn a pulseaudio server if clients fail to find a running server.
* Remove explicit version dependency for libspeex-dev to allow the package
  to be built for now.
* Regenerate autotools files to work with Ubuntu's newer libtool/libltdl.
* debian/control: libpulsecore5 -> libpulsecore8 to match the library
  soname.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: protocol-http.c 1971 2007-10-28 19:13:50Z lennart $ */
2
 
 
3
1
/***
4
2
  This file is part of PulseAudio.
5
3
 
37
35
#include <pulsecore/log.h>
38
36
#include <pulsecore/namereg.h>
39
37
#include <pulsecore/cli-text.h>
 
38
#include <pulsecore/shared.h>
40
39
 
41
40
#include "protocol-http.h"
42
41
 
50
49
#define URL_STATUS "/status"
51
50
 
52
51
struct connection {
53
 
    pa_protocol_http *protocol;
 
52
    pa_http_protocol *protocol;
54
53
    pa_ioline *line;
55
 
    enum { REQUEST_LINE, MIME_HEADER, DATA } state;
 
54
    enum {
 
55
        REQUEST_LINE,
 
56
        MIME_HEADER,
 
57
        DATA
 
58
    } state;
56
59
    char *url;
57
 
};
58
 
 
59
 
struct pa_protocol_http {
60
60
    pa_module *module;
 
61
};
 
62
 
 
63
struct pa_http_protocol {
 
64
    PA_REFCNT_DECLARE;
 
65
 
61
66
    pa_core *core;
62
 
    pa_socket_server*server;
63
67
    pa_idxset *connections;
64
68
};
65
69
 
103
107
}
104
108
 
105
109
 
106
 
static void connection_free(struct connection *c, int del) {
 
110
static void connection_unlink(struct connection *c) {
107
111
    pa_assert(c);
108
112
 
109
113
    if (c->url)
110
114
        pa_xfree(c->url);
111
115
 
112
 
    if (del)
113
 
        pa_idxset_remove_by_data(c->protocol->connections, c, NULL);
 
116
    pa_idxset_remove_by_data(c->protocol->connections, c, NULL);
114
117
 
115
118
    pa_ioline_unref(c->line);
116
119
    pa_xfree(c);
123
126
 
124
127
    if (!s) {
125
128
        /* EOF */
126
 
        connection_free(c, 1);
 
129
        connection_unlink(c);
127
130
        return;
128
131
    }
129
132
 
168
171
#define PRINTF_FIELD(a,b) pa_ioline_printf(c->line, "<tr><td><b>%s</b></td><td>%s</td></tr>\n",(a),(b))
169
172
 
170
173
                PRINTF_FIELD("User Name:", pa_get_user_name(txt, sizeof(txt)));
171
 
                PRINTF_FIELD("Fully Qualified Domain Name:", pa_get_fqdn(txt, sizeof(txt)));
 
174
                PRINTF_FIELD("Host name:", pa_get_host_name(txt, sizeof(txt)));
172
175
                PRINTF_FIELD("Default Sample Specification:", pa_sample_spec_snprint(txt, sizeof(txt), &c->protocol->core->default_sample_spec));
173
176
                PRINTF_FIELD("Default Sink:", pa_namereg_get_default_sink_name(c->protocol->core));
174
177
                PRINTF_FIELD("Default Source:", pa_namereg_get_default_source_name(c->protocol->core));
222
225
    internal_server_error(c);
223
226
}
224
227
 
225
 
static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata) {
226
 
    pa_protocol_http *p = userdata;
 
228
void pa_http_protocol_connect(pa_http_protocol *p, pa_iochannel *io, pa_module *m) {
227
229
    struct connection *c;
228
230
 
229
 
    pa_assert(s);
 
231
    pa_assert(p);
230
232
    pa_assert(io);
231
 
    pa_assert(p);
 
233
    pa_assert(m);
232
234
 
233
235
    if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) {
234
 
        pa_log_warn("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS);
 
236
        pa_log("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS);
235
237
        pa_iochannel_free(io);
236
238
        return;
237
239
    }
241
243
    c->line = pa_ioline_new(io);
242
244
    c->state = REQUEST_LINE;
243
245
    c->url = NULL;
 
246
    c->module = m;
244
247
 
245
248
    pa_ioline_set_callback(c->line, line_callback, c);
 
249
 
246
250
    pa_idxset_put(p->connections, c, NULL);
247
251
}
248
252
 
249
 
pa_protocol_http* pa_protocol_http_new(pa_core *core, pa_socket_server *server, pa_module *m, PA_GCC_UNUSED pa_modargs *ma) {
250
 
    pa_protocol_http* p;
251
 
 
252
 
    pa_core_assert_ref(core);
253
 
    pa_assert(server);
254
 
 
255
 
    p = pa_xnew(pa_protocol_http, 1);
256
 
    p->module = m;
257
 
    p->core = core;
258
 
    p->server = server;
 
253
void pa_http_protocol_disconnect(pa_http_protocol *p, pa_module *m) {
 
254
    struct connection *c;
 
255
    void *state = NULL;
 
256
 
 
257
    pa_assert(p);
 
258
    pa_assert(m);
 
259
 
 
260
    while ((c = pa_idxset_iterate(p->connections, &state, NULL)))
 
261
        if (c->module == m)
 
262
            connection_unlink(c);
 
263
}
 
264
 
 
265
static pa_http_protocol* http_protocol_new(pa_core *c) {
 
266
    pa_http_protocol *p;
 
267
 
 
268
    pa_assert(c);
 
269
 
 
270
    p = pa_xnew(pa_http_protocol, 1);
 
271
    PA_REFCNT_INIT(p);
 
272
    p->core = c;
259
273
    p->connections = pa_idxset_new(NULL, NULL);
260
274
 
261
 
    pa_socket_server_set_callback(p->server, on_connection, p);
262
 
 
263
 
    return p;
264
 
}
265
 
 
266
 
static void free_connection(void *p, PA_GCC_UNUSED void *userdata) {
267
 
    pa_assert(p);
268
 
    connection_free(p, 0);
269
 
}
270
 
 
271
 
void pa_protocol_http_free(pa_protocol_http *p) {
272
 
    pa_assert(p);
273
 
 
274
 
    pa_idxset_free(p->connections, free_connection, NULL);
275
 
    pa_socket_server_unref(p->server);
 
275
    pa_assert_se(pa_shared_set(c, "http-protocol", p) >= 0);
 
276
 
 
277
    return p;
 
278
}
 
279
 
 
280
pa_http_protocol* pa_http_protocol_get(pa_core *c) {
 
281
    pa_http_protocol *p;
 
282
 
 
283
    if ((p = pa_shared_get(c, "http-protocol")))
 
284
        return pa_http_protocol_ref(p);
 
285
 
 
286
    return http_protocol_new(c);
 
287
}
 
288
 
 
289
pa_http_protocol* pa_http_protocol_ref(pa_http_protocol *p) {
 
290
    pa_assert(p);
 
291
    pa_assert(PA_REFCNT_VALUE(p) >= 1);
 
292
 
 
293
    PA_REFCNT_INC(p);
 
294
 
 
295
    return p;
 
296
}
 
297
 
 
298
void pa_http_protocol_unref(pa_http_protocol *p) {
 
299
    struct connection *c;
 
300
 
 
301
    pa_assert(p);
 
302
    pa_assert(PA_REFCNT_VALUE(p) >= 1);
 
303
 
 
304
    if (PA_REFCNT_DEC(p) > 0)
 
305
        return;
 
306
 
 
307
    while ((c = pa_idxset_first(p->connections, NULL)))
 
308
        connection_unlink(c);
 
309
 
 
310
    pa_idxset_free(p->connections, NULL, NULL);
 
311
 
 
312
    pa_assert_se(pa_shared_remove(p->core, "http-protocol") >= 0);
 
313
 
276
314
    pa_xfree(p);
277
315
}