annotate stream/stream_cddb.c @ 30707:4d15378da04a

Mark vf_opts/vf_opts_fields structures as const.
author diego
date Fri, 26 Feb 2010 17:21:06 +0000
parents 9be8d71ca9a5
children 7092b8fc23f4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
1 /*
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
2 * CDDB HTTP protocol
30426
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
3 *
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
4 * Copyright (C) 2002 Bertrand Baudet <bertrand_baudet@yahoo.com>
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
5 *
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
6 * Implementation follow the freedb.howto1.06.txt specification
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
7 * from http://freedb.freedb.org
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
8 *
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
9 * discid computation by Jeremy D. Zawodny
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
10 * Copyright (c) 1998-2000 Jeremy D. Zawodny <Jeremy@Zawodny.com>
30426
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
11 *
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
12 * This file is part of MPlayer.
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
13 *
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
14 * MPlayer is free software; you can redistribute it and/or modify
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
15 * it under the terms of the GNU General Public License as published by
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
16 * the Free Software Foundation; either version 2 of the License, or
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
17 * (at your option) any later version.
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
18 *
30426
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
19 * MPlayer is distributed in the hope that it will be useful,
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
22 * GNU General Public License for more details.
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
23 *
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
24 * You should have received a copy of the GNU General Public License along
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
25 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29263
diff changeset
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
27 */
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
28
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
29 #include "config.h"
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
30
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
31 #include <stdio.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
32 #include <stdlib.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
33 #include <fcntl.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
34 #include <stdarg.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
35 #include <errno.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
36 #include <unistd.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
37 #include <string.h>
25792
0bf5384fb82c Fix compilation failue:
ulion
parents: 25780
diff changeset
38 #include <limits.h>
27727
48c1ae64255b Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents: 27461
diff changeset
39 #if defined(__MINGW32__) || defined(__CYGWIN__)
16935
60bd6aeed405 make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents: 16524
diff changeset
40 #ifdef __MINGW32__
60bd6aeed405 make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents: 16524
diff changeset
41 #define mkdir(a,b) mkdir(a)
60bd6aeed405 make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents: 16524
diff changeset
42 #endif
60bd6aeed405 make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents: 16524
diff changeset
43 #include <windows.h>
28402
c884d17bd005 Convert HAVE_WINSOCK2_H into a 0/1 definition.
diego
parents: 27727
diff changeset
44 #if HAVE_WINSOCK2_H
16935
60bd6aeed405 make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents: 16524
diff changeset
45 #include <winsock2.h>
17446
9604131f9196 Cygwin compilation fix
diego
parents: 17044
diff changeset
46 #endif
16935
60bd6aeed405 make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents: 16524
diff changeset
47 #else
60bd6aeed405 make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents: 16524
diff changeset
48 #include <netdb.h>
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
49 #include <sys/ioctl.h>
16935
60bd6aeed405 make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents: 16524
diff changeset
50 #endif
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
51 #include <sys/types.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
52 #include <sys/stat.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
53
16967
32e2c59c8e86 [TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents: 16935
diff changeset
54 #include "mp_msg.h"
32e2c59c8e86 [TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents: 16935
diff changeset
55 #include "help_mp.h"
32e2c59c8e86 [TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents: 16935
diff changeset
56
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
57 #if defined(__linux__)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
58 #include <linux/cdrom.h>
21848
3ff1eade91f9 GNU/kFreeBSD support, closes Bugzilla #704.
diego
parents: 20587
diff changeset
59 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
60 #include <sys/cdio.h>
27727
48c1ae64255b Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents: 27461
diff changeset
61 #elif defined(__MINGW32__) || defined(__CYGWIN__)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
62 #include <ddk/ntddcdrm.h>
30613
e04602bd557a Add missing 'defined' for __bsdi__.
komh
parents: 30426
diff changeset
63 #elif defined(__bsdi__)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
64 #include <dvd.h>
25393
454ab8a40f1c Support cddb on darwin.
ulion
parents: 23734
diff changeset
65 #elif defined(__APPLE__) || defined(__DARWIN__)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
66 #include <IOKit/storage/IOCDTypes.h>
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
67 #include <IOKit/storage/IOCDMediaBSDClient.h>
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
68 #include "mpbswap.h"
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
69 #endif
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
70
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
71 #include "cdd.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16967
diff changeset
72 #include "version.h"
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
73 #include "stream.h"
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
74 #include "network.h"
25948
e8945e43a36f #include just libavutil/common.h, not all of libavutil/intreadwrite.h.
diego
parents: 25796
diff changeset
75 #include "libavutil/common.h"
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
76
30685
7e2f58933cc1 Define O_BINARY if it is undefined.
komh
parents: 30629
diff changeset
77 #ifndef O_BINARY
7e2f58933cc1 Define O_BINARY if it is undefined.
komh
parents: 30629
diff changeset
78 #define O_BINARY 0
7e2f58933cc1 Define O_BINARY if it is undefined.
komh
parents: 30629
diff changeset
79 #endif
7e2f58933cc1 Define O_BINARY if it is undefined.
komh
parents: 30629
diff changeset
80
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
81 #define DEFAULT_FREEDB_SERVER "freedb.freedb.org"
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
82 #define DEFAULT_CACHE_DIR "/.cddb/"
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
83
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
84 static cd_toc_t cdtoc[100];
16524
83d101e1bedb Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents: 15566
diff changeset
85 static int cdtoc_last_track;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
86
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
87 static int read_toc(const char *dev)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
88 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
89 int first = 0, last = -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
90 int i;
27727
48c1ae64255b Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents: 27461
diff changeset
91 #if defined(__MINGW32__) || defined(__CYGWIN__)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
92 HANDLE drive;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
93 DWORD r;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
94 CDROM_TOC toc;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
95 char device[10];
20586
d9558d78179d cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents: 20583
diff changeset
96
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
97 sprintf(device, "\\\\.\\%s", dev);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
98 drive = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
99 OPEN_EXISTING, 0, 0);
20586
d9558d78179d cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents: 20583
diff changeset
100
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
101 if (!DeviceIoControl(drive, IOCTL_CDROM_READ_TOC, NULL, 0, &toc,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
102 sizeof(CDROM_TOC), &r, 0)) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
103 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToReadTOC);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
104 return 0;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
105 }
20586
d9558d78179d cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents: 20583
diff changeset
106
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
107 first = toc.FirstTrack - 1; last = toc.LastTrack;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
108 for (i = first; i <= last; i++) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
109 cdtoc[i].min = toc.TrackData[i].Address[1];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
110 cdtoc[i].sec = toc.TrackData[i].Address[2];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
111 cdtoc[i].frame = toc.TrackData[i].Address[3];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
112 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
113 CloseHandle(drive);
20586
d9558d78179d cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents: 20583
diff changeset
114
d9558d78179d cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents: 20583
diff changeset
115 #else
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
116 int drive;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
117 drive = open(dev, O_RDONLY | O_NONBLOCK);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
118 if (drive < 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
119 return drive;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
120 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
121
20587
128b2dc39f57 More code shuffling
reimar
parents: 20586
diff changeset
122 #if defined(__linux__) || defined(__bsdi__)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
123 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
124 struct cdrom_tochdr tochdr;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
125 ioctl(drive, CDROMREADTOCHDR, &tochdr);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
126 first = tochdr.cdth_trk0 - 1; last = tochdr.cdth_trk1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
127 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
128 for (i = first; i <= last; i++) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
129 struct cdrom_tocentry tocentry;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
130 tocentry.cdte_track = (i == last) ? 0xAA : i + 1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
131 tocentry.cdte_format = CDROM_MSF;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
132 ioctl(drive, CDROMREADTOCENTRY, &tocentry);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
133 cdtoc[i].min = tocentry.cdte_addr.msf.minute;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
134 cdtoc[i].sec = tocentry.cdte_addr.msf.second;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
135 cdtoc[i].frame = tocentry.cdte_addr.msf.frame;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
136 }
21848
3ff1eade91f9 GNU/kFreeBSD support, closes Bugzilla #704.
diego
parents: 20587
diff changeset
137 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
138 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
139 struct ioc_toc_header tochdr;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
140 ioctl(drive, CDIOREADTOCHEADER, &tochdr);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
141 first = tochdr.starting_track - 1; last = tochdr.ending_track;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
142 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
143 for (i = first; i <= last; i++) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
144 struct ioc_read_toc_single_entry tocentry;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
145 tocentry.track = (i == last) ? 0xAA : i + 1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
146 tocentry.address_format = CD_MSF_FORMAT;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
147 ioctl(drive, CDIOREADTOCENTRY, &tocentry);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
148 cdtoc[i].min = tocentry.entry.addr.msf.minute;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
149 cdtoc[i].sec = tocentry.entry.addr.msf.second;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
150 cdtoc[i].frame = tocentry.entry.addr.msf.frame;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
151 }
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
152 #elif defined(__NetBSD__) || defined(__OpenBSD__)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
153 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
154 struct ioc_toc_header tochdr;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
155 ioctl(drive, CDIOREADTOCHEADER, &tochdr);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
156 first = tochdr.starting_track - 1; last = tochdr.ending_track;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
157 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
158 for (i = first; i <= last; i++) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
159 struct ioc_read_toc_entry tocentry;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
160 struct cd_toc_entry toc_buffer;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
161 tocentry.starting_track = (i == last) ? 0xAA : i + 1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
162 tocentry.address_format = CD_MSF_FORMAT;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
163 tocentry.data = &toc_buffer;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
164 tocentry.data_len = sizeof(toc_buffer);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
165 ioctl(drive, CDIOREADTOCENTRYS, &tocentry);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
166 cdtoc[i].min = toc_buffer.addr.msf.minute;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
167 cdtoc[i].sec = toc_buffer.addr.msf.second;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
168 cdtoc[i].frame = toc_buffer.addr.msf.frame;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
169 }
25393
454ab8a40f1c Support cddb on darwin.
ulion
parents: 23734
diff changeset
170 #elif defined(__APPLE__) || defined(__DARWIN__)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
171 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
172 dk_cd_read_toc_t tochdr;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
173 uint8_t buf[4];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
174 uint8_t buf2[100 * sizeof(CDTOCDescriptor) + sizeof(CDTOC)];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
175 memset(&tochdr, 0, sizeof(tochdr));
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
176 tochdr.bufferLength = sizeof(buf);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
177 tochdr.buffer = &buf;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
178 if (!ioctl(drive, DKIOCCDREADTOC, &tochdr)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
179 && tochdr.bufferLength == sizeof(buf)) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
180 first = buf[2] - 1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
181 last = buf[3];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
182 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
183 if (last >= 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
184 memset(&tochdr, 0, sizeof(tochdr));
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
185 tochdr.bufferLength = sizeof(buf2);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
186 tochdr.buffer = &buf2;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
187 tochdr.format = kCDTOCFormatTOC;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
188 if (ioctl(drive, DKIOCCDREADTOC, &tochdr)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
189 || tochdr.bufferLength < sizeof(CDTOC))
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
190 last = -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
191 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
192 if (last >= 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
193 CDTOC *cdToc = (CDTOC *)buf2;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
194 CDTrackInfo lastTrack;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
195 dk_cd_read_track_info_t trackInfoParams;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
196 for (i = first; i < last; ++i) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
197 CDMSF msf = CDConvertTrackNumberToMSF(i + 1, cdToc);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
198 cdtoc[i].min = msf.minute;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
199 cdtoc[i].sec = msf.second;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
200 cdtoc[i].frame = msf.frame;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
201 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
202 memset(&trackInfoParams, 0, sizeof(trackInfoParams));
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
203 trackInfoParams.addressType = kCDTrackInfoAddressTypeTrackNumber;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
204 trackInfoParams.bufferLength = sizeof(lastTrack);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
205 trackInfoParams.address = last;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
206 trackInfoParams.buffer = &lastTrack;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
207 if (!ioctl(drive, DKIOCCDREADTRACKINFO, &trackInfoParams)) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
208 CDMSF msf = CDConvertLBAToMSF(be2me_32(lastTrack.trackStartAddress)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
209 + be2me_32(lastTrack.trackSize));
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
210 cdtoc[last].min = msf.minute;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
211 cdtoc[last].sec = msf.second;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
212 cdtoc[last].frame = msf.frame;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
213 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
214 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
215 }
20587
128b2dc39f57 More code shuffling
reimar
parents: 20586
diff changeset
216 #endif
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
217 close(drive);
20581
bfcc98ad59ba Factor out common code in stream_cddb read_toc function.
reimar
parents: 20579
diff changeset
218 #endif
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
219 for (i = first; i <= last; i++)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
220 cdtoc[i].frame += (cdtoc[i].min * 60 + cdtoc[i].sec) * 75;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
221 return last;
7269
a5f1baaf7714 Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents: 6697
diff changeset
222 }
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
223
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
224 /**
16524
83d101e1bedb Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents: 15566
diff changeset
225 \brief Reads TOC from CD in the given device and prints the number of tracks
83d101e1bedb Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents: 15566
diff changeset
226 and the length of each track in minute:second:frame format.
83d101e1bedb Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents: 15566
diff changeset
227 \param *dev the device to analyse
83d101e1bedb Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents: 15566
diff changeset
228 \return if the command line -identify is given, returns the last track of
83d101e1bedb Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents: 15566
diff changeset
229 the TOC or -1 if the TOC can't be read,
83d101e1bedb Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents: 15566
diff changeset
230 otherwise just returns 0 and let cddb_resolve the TOC
83d101e1bedb Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents: 15566
diff changeset
231 */
83d101e1bedb Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents: 15566
diff changeset
232 int cdd_identify(const char *dev)
83d101e1bedb Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents: 15566
diff changeset
233 {
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
234 cdtoc_last_track = 0;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
235 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO)) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
236 int i, min, sec, frame;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
237 cdtoc_last_track = read_toc(dev);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
238 if (cdtoc_last_track < 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
239 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToOpenDevice,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
240 dev);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
241 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
242 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
243 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_CDDA_TRACKS=%d\n", cdtoc_last_track);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
244 for (i = 1; i <= cdtoc_last_track; i++) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
245 frame = cdtoc[i].frame - cdtoc[i-1].frame;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
246 sec = frame / 75;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
247 frame -= sec * 75;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
248 min = sec / 60;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
249 sec -= min * 60;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
250 mp_msg(MSGT_IDENTIFY, MSGL_INFO,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
251 "ID_CDDA_TRACK_%d_MSF=%02d:%02d:%02d\n", i, min, sec, frame);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
252 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
253 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
254 return cdtoc_last_track;
16524
83d101e1bedb Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents: 15566
diff changeset
255 }
83d101e1bedb Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents: 15566
diff changeset
256
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
257 static unsigned int cddb_sum(int n)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
258 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
259 unsigned int ret;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
260
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
261 ret = 0;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
262 while (n > 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
263 ret += (n % 10);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
264 n /= 10;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
265 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
266 return ret;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
267 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
268
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
269 static unsigned long cddb_discid(int tot_trks)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
270 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
271 unsigned int i, t = 0, n = 0;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
272
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
273 i = 0;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
274 while (i < (unsigned int)tot_trks) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
275 n = n + cddb_sum((cdtoc[i].min * 60) + cdtoc[i].sec);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
276 i++;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
277 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
278 t = ((cdtoc[tot_trks].min * 60) + cdtoc[tot_trks].sec) -
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
279 ((cdtoc[0].min * 60) + cdtoc[0].sec);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
280 return (n % 0xff) << 24 | t << 8 | tot_trks;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
281 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
282
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
283
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
284
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
285 static int cddb_http_request(char *command,
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
286 int (*reply_parser)(HTTP_header_t*, cddb_data_t*),
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
287 cddb_data_t *cddb_data)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
288 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
289 char request[4096];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
290 int fd, ret = 0;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
291 URL_t *url;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
292 HTTP_header_t *http_hdr;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
293
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
294 if (reply_parser == NULL || command == NULL || cddb_data == NULL)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
295 return -1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
296
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
297 sprintf(request, "http://%s/~cddb/cddb.cgi?cmd=%s%s&proto=%d",
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
298 cddb_data->freedb_server, command, cddb_data->cddb_hello,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
299 cddb_data->freedb_proto_level);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
300 mp_msg(MSGT_OPEN, MSGL_INFO,"Request[%s]\n", request);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
301
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
302 url = url_new(request);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
303 if (url == NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
304 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_NotAValidURL);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
305 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
306 }
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
307
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
308 fd = http_send_request(url,0);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
309 if (fd < 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
310 mp_msg(MSGT_DEMUX, MSGL_ERR,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
311 MSGTR_MPDEMUX_CDDB_FailedToSendHTTPRequest);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
312 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
313 }
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
314
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
315 http_hdr = http_read_response(fd);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
316 if (http_hdr == NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
317 mp_msg(MSGT_DEMUX, MSGL_ERR,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
318 MSGTR_MPDEMUX_CDDB_FailedToReadHTTPResponse);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
319 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
320 }
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
321
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
322 http_debug_hdr(http_hdr);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
323 mp_msg(MSGT_OPEN, MSGL_INFO,"body=[%s]\n", http_hdr->body);
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
324
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
325 switch (http_hdr->status_code) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
326 case 200:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
327 ret = reply_parser(http_hdr, cddb_data);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
328 break;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
329 case 400:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
330 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_HTTPErrorNOTFOUND);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
331 break;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
332 default:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
333 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_HTTPErrorUnknown);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
334 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
335
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
336 http_free(http_hdr);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
337 url_free(url);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
338
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
339 return ret;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
340 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
341
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
342 static int cddb_read_cache(cddb_data_t *cddb_data)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
343 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
344 char file_name[100];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
345 struct stat stats;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
346 int file_fd, ret;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
347 size_t file_size;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
348
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
349 if (cddb_data == NULL || cddb_data->cache_dir == NULL)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
350 return -1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
351
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
352 sprintf(file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
353
30685
7e2f58933cc1 Define O_BINARY if it is undefined.
komh
parents: 30629
diff changeset
354 file_fd = open(file_name, O_RDONLY | O_BINARY);
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
355 if (file_fd < 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
356 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_NoCacheFound);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
357 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
358 }
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
359
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
360 ret = fstat(file_fd, &stats);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
361 if (ret < 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
362 perror("fstat");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
363 file_size = 4096;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
364 } else {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
365 file_size = stats.st_size < UINT_MAX ? stats.st_size : UINT_MAX - 1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
366 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
367
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
368 cddb_data->xmcd_file = malloc(file_size + 1);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
369 if (cddb_data->xmcd_file == NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
370 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
371 close(file_fd);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
372 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
373 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
374 cddb_data->xmcd_file_size = read(file_fd, cddb_data->xmcd_file, file_size);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
375 if (cddb_data->xmcd_file_size != file_size) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
376 mp_msg(MSGT_DEMUX, MSGL_WARN,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
377 MSGTR_MPDEMUX_CDDB_NotAllXMCDFileHasBeenRead);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
378 close(file_fd);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
379 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
380 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
381 cddb_data->xmcd_file[cddb_data->xmcd_file_size] = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
382
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
383 close(file_fd);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
384
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
385 return 0;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
386 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
387
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
388 static int cddb_write_cache(cddb_data_t *cddb_data)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
389 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
390 // We have the file, save it for cache.
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
391 struct stat file_stat;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
392 char file_name[100];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
393 int file_fd, ret;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
394 int wrote = 0;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
395
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
396 if (cddb_data == NULL || cddb_data->cache_dir == NULL)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
397 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
398
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
399 // Check if the CDDB cache dir exist
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
400 ret = stat(cddb_data->cache_dir, &file_stat);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
401 if (ret < 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
402 // Directory not present, create it.
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
403 ret = mkdir(cddb_data->cache_dir, 0755);
16935
60bd6aeed405 make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents: 16524
diff changeset
404 #ifdef __MINGW32__
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
405 if (ret < 0 && errno != EEXIST) {
16935
60bd6aeed405 make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents: 16524
diff changeset
406 #else
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
407 if (ret < 0) {
16935
60bd6aeed405 make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents: 16524
diff changeset
408 #endif
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
409 perror("mkdir");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
410 mp_msg(MSGT_DEMUX, MSGL_ERR,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
411 MSGTR_MPDEMUX_CDDB_FailedToCreateDirectory,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
412 cddb_data->cache_dir);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
413 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
414 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
415 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
416
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
417 sprintf(file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
418
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
419 file_fd = creat(file_name, S_IRUSR | S_IWUSR);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
420 if (file_fd < 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
421 perror("create");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
422 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
423 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
424
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
425 wrote = write(file_fd, cddb_data->xmcd_file, cddb_data->xmcd_file_size);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
426 if (wrote < 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
427 perror("write");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
428 close(file_fd);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
429 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
430 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
431 if ((unsigned int) wrote != cddb_data->xmcd_file_size) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
432 mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_CDDB_NotAllXMCDFileHasBeenWritten);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
433 close(file_fd);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
434 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
435 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
436
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
437 close(file_fd);
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
438
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
439 return 0;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
440 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
441
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
442 static int cddb_read_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
443 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
444 unsigned long disc_id;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
445 char category[100];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
446 char *ptr = NULL, *ptr2 = NULL;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
447 int ret, status;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
448
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
449 if (http_hdr == NULL || cddb_data == NULL)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
450 return -1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
451
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
452 ret = sscanf(http_hdr->body, "%d ", &status);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
453 if (ret != 1) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
454 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
455 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
456 }
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
457
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
458 switch (status) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
459 case 210:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
460 ret = sscanf(http_hdr->body, "%d %99s %08lx", &status,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
461 category, &disc_id);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
462 if (ret != 3) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
463 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
464 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
465 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
466 // Check if it's a xmcd database file
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
467 ptr = strstr(http_hdr->body, "# xmcd");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
468 if (ptr == NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
469 mp_msg(MSGT_DEMUX, MSGL_ERR,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
470 MSGTR_MPDEMUX_CDDB_InvalidXMCDDatabaseReturned);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
471 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
472 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
473 ptr = strdup(ptr);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
474 // Ok found the beginning of the file
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
475 // look for the end
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
476 ptr2 = strstr(ptr, "\n.\r\n");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
477 if (!ptr2)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
478 ptr2 = strstr(ptr, "\n.\n");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
479 if (ptr2) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
480 ptr2++;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
481 } else {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
482 mp_msg(MSGT_DEMUX, MSGL_FIXME, "Unable to find '.'\n");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
483 ptr2 = ptr + strlen(ptr); //return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
484 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
485 // Ok found the end
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
486 // do a sanity check
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
487 if (http_hdr->body_size < (unsigned int)(ptr2 - ptr)) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
488 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_UnexpectedFIXME);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
489 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
490 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
491 cddb_data->xmcd_file = ptr;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
492 cddb_data->xmcd_file_size = ptr2 - ptr;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
493 cddb_data->xmcd_file[cddb_data->xmcd_file_size] = '\0';
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
494 return cddb_write_cache(cddb_data);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
495 default:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
496 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
497 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
498 return 0;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
499 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
500
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
501 static int cddb_request_titles(cddb_data_t *cddb_data)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
502 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
503 char command[1024];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
504 sprintf(command, "cddb+read+%s+%08lx",
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
505 cddb_data->category, cddb_data->disc_id);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
506 return cddb_http_request(command, cddb_read_parse, cddb_data);
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
507 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
508
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
509 static int cddb_parse_matches_list(HTTP_header_t *http_hdr, cddb_data_t *cddb_data)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
510 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
511 char album_title[100];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
512 char *ptr = NULL;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
513 int ret;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
514
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
515 ptr = strstr(http_hdr->body, "\n");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
516 if (ptr == NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
517 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_UnableToFindEOL);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
518 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
519 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
520 ptr++;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
521 // We have a list of exact/inexact matches, so which one do we use?
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
522 // So let's take the first one.
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
523 ret = sscanf(ptr, "%99s %08lx %99s", cddb_data->category,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
524 &(cddb_data->disc_id), album_title);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
525 if (ret != 3) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
526 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
527 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
528 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
529 ptr = strstr(http_hdr->body, album_title);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
530 if (ptr != NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
531 char *ptr2;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
532 int len;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
533 ptr2 = strstr(ptr, "\n");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
534 if (ptr2 == NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
535 len = (http_hdr->body_size)-(ptr-(http_hdr->body));
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
536 } else {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
537 len = ptr2-ptr+1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
538 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
539 len = FFMIN(sizeof(album_title) - 1, len);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
540 strncpy(album_title, ptr, len);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
541 album_title[len]='\0';
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
542 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
543 mp_msg(MSGT_DEMUX, MSGL_STATUS, MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
544 album_title);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
545 return 0;
8746
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
546 }
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
547
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
548 static int cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
549 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
550 char album_title[100];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
551 char *ptr = NULL;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
552 int ret, status;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
553
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
554 ret = sscanf(http_hdr->body, "%d ", &status);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
555 if (ret != 1) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
556 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
557 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
558 }
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
559
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
560 switch (status) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
561 case 200:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
562 // Found exact match
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
563 ret = sscanf(http_hdr->body, "%d %99s %08lx %99s", &status,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
564 cddb_data->category, &(cddb_data->disc_id), album_title);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
565 if (ret != 4) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
566 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
567 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
568 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
569 ptr = strstr(http_hdr->body, album_title);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
570 if (ptr != NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
571 char *ptr2;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
572 int len;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
573 ptr2 = strstr(ptr, "\n");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
574 if (ptr2 == NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
575 len = (http_hdr->body_size)-(ptr-(http_hdr->body));
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
576 } else {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
577 len = ptr2-ptr+1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
578 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
579 len = FFMIN(sizeof(album_title) - 1, len);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
580 strncpy(album_title, ptr, len);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
581 album_title[len]='\0';
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
582 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
583 mp_msg(MSGT_DEMUX, MSGL_STATUS,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
584 MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle, album_title);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
585 return cddb_request_titles(cddb_data);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
586 case 202:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
587 // No match found
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
588 mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_CDDB_AlbumNotFound);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
589 break;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
590 case 210:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
591 // Found exact matches, list follows
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
592 cddb_parse_matches_list(http_hdr, cddb_data);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
593 return cddb_request_titles(cddb_data);
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
594 /*
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
595 body=[210 Found exact matches, list follows (until terminating `.')
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
596 misc c711930d Santana / Supernatural
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
597 rock c711930d Santana / Supernatural
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
598 blues c711930d Santana / Supernatural
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
599 .]
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
600 */
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
601 case 211:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
602 // Found inexact matches, list follows
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
603 cddb_parse_matches_list(http_hdr, cddb_data);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
604 return cddb_request_titles(cddb_data);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
605 case 500:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
606 mp_msg(MSGT_DEMUX, MSGL_FIXME,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
607 MSGTR_MPDEMUX_CDDB_ServerReturnsCommandSyntaxErr);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
608 break;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
609 default:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
610 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
611 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
612 return -1;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
613 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
614
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
615 static int cddb_proto_level_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
616 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
617 int max;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
618 int ret, status;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
619 char *ptr;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
620
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
621 ret = sscanf(http_hdr->body, "%d ", &status);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
622 if (ret != 1) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
623 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
624 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
625 }
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
626
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
627 switch (status) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
628 case 210:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
629 ptr = strstr(http_hdr->body, "max proto:");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
630 if (ptr == NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
631 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
632 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
633 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
634 ret = sscanf(ptr, "max proto: %d", &max);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
635 if (ret != 1) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
636 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
637 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
638 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
639 cddb_data->freedb_proto_level = max;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
640 return 0;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
641 default:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
642 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
643 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
644 return -1;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
645 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
646
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
647 static int cddb_get_proto_level(cddb_data_t *cddb_data)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
648 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
649 return cddb_http_request("stat", cddb_proto_level_parse, cddb_data);
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
650 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
651
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
652 static int cddb_freedb_sites_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
653 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
654 int ret, status;
7746
15ce89ba92cf Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents: 7721
diff changeset
655
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
656 ret = sscanf(http_hdr->body, "%d ", &status);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
657 if (ret != 1) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
658 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
659 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
660 }
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
661
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
662 switch (status) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
663 case 210:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
664 // TODO: Parse the sites
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
665 ret = cddb_data->anonymous; // For gcc complaining about unused parameter.
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
666 return 0;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
667 case 401:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
668 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_NoSitesInfoAvailable);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
669 break;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
670 default:
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
671 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
672 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
673 return -1;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
674 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
675
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
676 static int cddb_get_freedb_sites(cddb_data_t *cddb_data)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
677 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
678 return cddb_http_request("sites", cddb_freedb_sites_parse, cddb_data);
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
679 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
680
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
681 static void cddb_create_hello(cddb_data_t *cddb_data)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
682 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
683 char host_name[51];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
684 char *user_name;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
685
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
686 if (cddb_data->anonymous) { // Default is anonymous
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
687 /* Note from Eduardo Pérez Ureta <eperez@it.uc3m.es> :
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
688 * We don't send current user/host name in hello to prevent spam.
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
689 * Software that sends this is considered spyware
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
690 * that most people don't like.
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
691 */
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
692 user_name = "anonymous";
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
693 strcpy(host_name, "localhost");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
694 } else {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
695 if (gethostname(host_name, 50) < 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
696 strcpy(host_name, "localhost");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
697 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
698 user_name = getenv("LOGNAME");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
699 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
700 sprintf(cddb_data->cddb_hello, "&hello=%s+%s+%s+%s",
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
701 user_name, host_name, "MPlayer", VERSION);
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
702 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
703
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
704 static int cddb_retrieve(cddb_data_t *cddb_data)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
705 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
706 char offsets[1024], command[1024];
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
707 char *ptr;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
708 unsigned int i, time_len;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
709 int ret;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
710
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
711 ptr = offsets;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
712 for (i = 0; i < cddb_data->tracks ; i++) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
713 ptr += sprintf(ptr, "%d+", cdtoc[i].frame);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
714 if (ptr-offsets > sizeof offsets - 40) break;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
715 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
716 ptr[0] = 0;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
717 time_len = (cdtoc[cddb_data->tracks].frame)/75;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
718
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
719 cddb_data->freedb_server = DEFAULT_FREEDB_SERVER;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
720 cddb_data->freedb_proto_level = 1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
721 cddb_data->xmcd_file = NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
722
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
723 cddb_create_hello(cddb_data);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
724 if (cddb_get_proto_level(cddb_data) < 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
725 mp_msg(MSGT_DEMUX, MSGL_ERR,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
726 MSGTR_MPDEMUX_CDDB_FailedToGetProtocolLevel);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
727 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
728 }
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
729
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
730 //cddb_get_freedb_sites(&cddb_data);
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
731
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
732 sprintf(command, "cddb+query+%08lx+%d+%s%d", cddb_data->disc_id,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
733 cddb_data->tracks, offsets, time_len);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
734 ret = cddb_http_request(command, cddb_query_parse, cddb_data);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
735 if (ret < 0)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
736 return -1;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
737
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
738 if (cddb_data->cache_dir != NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
739 free(cddb_data->cache_dir);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
740 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
741 return 0;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
742 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
743
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
744 int cddb_resolve(const char *dev, char **xmcd_file)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
745 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
746 char cddb_cache_dir[] = DEFAULT_CACHE_DIR;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
747 char *home_dir = NULL;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
748 cddb_data_t cddb_data;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
749
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
750 if (cdtoc_last_track <= 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
751 cdtoc_last_track = read_toc(dev);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
752 if (cdtoc_last_track < 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
753 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToOpenDevice,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
754 dev);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
755 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
756 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
757 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
758 cddb_data.tracks = cdtoc_last_track;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
759 cddb_data.disc_id = cddb_discid(cddb_data.tracks);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
760 cddb_data.anonymous = 1; // Don't send user info by default
7746
15ce89ba92cf Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents: 7721
diff changeset
761
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
762 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_DISCID=%08lx\n",
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
763 cddb_data.disc_id);
27174
ee63b09aedc9 Add disc ID to -identify output.
diego
parents: 26756
diff changeset
764
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
765 // Check if there is a CD in the drive
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
766 // FIXME: That's not really a good way to check
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
767 if (cddb_data.disc_id == 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
768 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_NoCDInDrive);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
769 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
770 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
771
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
772 home_dir = getenv("HOME");
16935
60bd6aeed405 make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents: 16524
diff changeset
773 #ifdef __MINGW32__
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
774 if (home_dir == NULL)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
775 home_dir = getenv("USERPROFILE");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
776 if (home_dir == NULL)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
777 home_dir = getenv("HOMEPATH");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
778 // Last resort, store the cddb cache in the mplayer directory
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
779 if (home_dir == NULL)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
780 home_dir = (char *)get_path("");
16935
60bd6aeed405 make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents: 16524
diff changeset
781 #endif
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
782 if (home_dir == NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
783 cddb_data.cache_dir = NULL;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
784 } else {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
785 cddb_data.cache_dir = malloc(strlen(home_dir)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
786 + strlen(cddb_cache_dir) + 1);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
787 if (cddb_data.cache_dir == NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
788 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
789 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
790 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
791 sprintf(cddb_data.cache_dir, "%s%s", home_dir, cddb_cache_dir);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
792 }
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
793
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
794 // Check for a cached file
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
795 if (cddb_read_cache(&cddb_data) < 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
796 // No Cache found
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
797 if (cddb_retrieve(&cddb_data) < 0) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
798 return -1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
799 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
800 }
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
801
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
802 if (cddb_data.xmcd_file != NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
803 // printf("%s\n", cddb_data.xmcd_file);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
804 *xmcd_file = cddb_data.xmcd_file;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
805 return 0;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
806 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
807
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
808 return -1;
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
809 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
810
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
811 /***************
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
812 * xmcd parser *
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
813 ***************/
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
814 static char *xmcd_parse_dtitle(cd_info_t *cd_info, char *line)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
815 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
816 char *ptr, *album;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
817 ptr = strstr(line, "DTITLE=");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
818 if (ptr != NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
819 ptr += 7;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
820 album = strstr(ptr, "/");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
821 if (album == NULL)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
822 return NULL;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
823 cd_info->album = malloc(strlen(album + 2) + 1);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
824 if (cd_info->album == NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
825 return NULL;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
826 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
827 strcpy(cd_info->album, album + 2);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
828 album--;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
829 album[0] = '\0';
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
830 cd_info->artist = malloc(strlen(ptr) + 1);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
831 if (cd_info->artist == NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
832 return NULL;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
833 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
834 strcpy(cd_info->artist, ptr);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
835 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
836 return ptr;
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
837 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
838
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
839 static char *xmcd_parse_dgenre(cd_info_t *cd_info, char *line)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
840 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
841 char *ptr;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
842 ptr = strstr(line, "DGENRE=");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
843 if (ptr != NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
844 ptr += 7;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
845 cd_info->genre = malloc(strlen(ptr)+1);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
846 if (cd_info->genre == NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
847 return NULL;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
848 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
849 strcpy(cd_info->genre, ptr);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
850 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
851 return ptr;
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
852 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
853
30693
ce392deeb0a6 Make local-only cddb functions static.
reimar
parents: 30685
diff changeset
854 static char *xmcd_parse_ttitle(cd_info_t *cd_info, char *line)
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
855 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
856 unsigned int track_nb;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
857 unsigned long sec, off;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
858 char *ptr;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
859 ptr = strstr(line, "TTITLE");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
860 if (ptr != NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
861 ptr += 6;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
862 // Here we point to the track number
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
863 track_nb = atoi(ptr);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
864 ptr = strstr(ptr, "=");
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
865 if (ptr == NULL)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
866 return NULL;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
867 ptr++;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
868
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
869 sec = cdtoc[track_nb].frame;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
870 off = cdtoc[track_nb + 1].frame - sec + 1;
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
871
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
872 cd_info_add_track(cd_info, ptr, track_nb + 1,
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
873 (unsigned int) (off / (60 * 75)),
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
874 (unsigned int) ((off / 75) % 60),
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
875 (unsigned int) (off % 75),
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
876 sec, off);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
877 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
878 return ptr;
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
879 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
880
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
881 cd_info_t *cddb_parse_xmcd(char *xmcd_file)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
882 {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
883 cd_info_t *cd_info = NULL;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
884 int length, pos = 0;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
885 char *ptr, *ptr2;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
886 unsigned int audiolen;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
887 if (xmcd_file == NULL)
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
888 return NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
889
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
890 cd_info = cd_info_new();
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
891 if (cd_info == NULL) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
892 return NULL;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
893 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
894
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
895 length = strlen(xmcd_file);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
896 ptr = xmcd_file;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
897 while (ptr != NULL && pos < length) {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
898 // Read a line
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
899 ptr2 = ptr;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
900 while(ptr2[0] != '\0' && ptr2[0] != '\r' && ptr2[0] != '\n')
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
901 ptr2++;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
902 if (ptr2[0] == '\0') {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
903 break;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
904 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
905 ptr2[0] = '\0';
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
906 // Ignore comments
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
907 if (ptr[0] != '#') {
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
908 // Search for the album title
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
909 if (xmcd_parse_dtitle(cd_info, ptr))
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
910 ;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
911 // Search for the genre
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
912 else if (xmcd_parse_dgenre(cd_info, ptr))
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
913 ;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
914 // Search for a track title
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
915 else if (xmcd_parse_ttitle(cd_info, ptr))
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
916 audiolen++; // <-- audiolen++ to shut up gcc warning
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
917 }
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
918 if (ptr2[1] == '\n')
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
919 ptr2++;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
920 pos = (ptr2 + 1) - ptr;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
921 ptr = ptr2 + 1;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
922 }
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
923
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
924 audiolen = cdtoc[cd_info->nb_tracks].frame-cdtoc[0].frame;
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
925 cd_info->min = (unsigned int) (audiolen / (60 * 75));
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
926 cd_info->sec = (unsigned int) ((audiolen / 75) % 60);
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
927 cd_info->msec = (unsigned int) (audiolen % 75);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28402
diff changeset
928
30629
16d7ef2f04e5 cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents: 30613
diff changeset
929 return cd_info;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
930 }