Mercurial > audlegacy-plugins
changeset 1374:e17e009b3d9b
Finally removed the old cdaudio plugin
author | Calin Crisan ccrisan@gmail.com |
---|---|
date | Thu, 26 Jul 2007 12:13:04 +0300 |
parents | 85ffec632924 |
children | ef07ff837063 |
files | src/cdaudio/Makefile src/cdaudio/cdaudio.c src/cdaudio/cdaudio.h src/cdaudio/cddb.c src/cdaudio/cddb.h src/cdaudio/cdinfo.c src/cdaudio/cdinfo.h src/cdaudio/configure.c src/cdaudio/http.c src/cdaudio/http.h |
diffstat | 10 files changed, 0 insertions(+), 3775 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cdaudio/Makefile Wed Jul 25 16:48:53 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -include ../../mk/rules.mk -include ../../mk/init.mk - -OBJECTIVE_LIBS = libcdaudio$(SHARED_SUFFIX) - -LIBADD = $(GTK_LIBS) $(GLIB_LIBS) $(PANGO_LIBS) -LIBDIR = $(plugindir)/$(INPUT_PLUGIN_DIR) - -SOURCES = cdaudio.c cddb.c cdinfo.c configure.c http.c - -OBJECTS = ${SOURCES:.c=.o} - -CFLAGS += $(PICFLAGS) $(GTK_CFLAGS) $(GLIB_CFLAGS) $(PANGO_CFLAGS) -I../../intl -I../.. -I../.. - -include ../../mk/objective.mk
--- a/src/cdaudio/cdaudio.c Wed Jul 25 16:48:53 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1342 +0,0 @@ -/* XMMS - Cross-platform multimedia player - * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas, - * Thomas Nilsson and 4Front Technologies - * Copyright (C) 1999-2003 Haavard Kvaalen <havardk@xmms.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "cdaudio.h" - -#include <glib.h> -#include <audacious/i18n.h> -#include <glib/gprintf.h> -#include <string.h> -#include <stdlib.h> - -#include <unistd.h> -#include <errno.h> -#include <fcntl.h> -#include <sys/ioctl.h> -#include <sys/stat.h> - -#include <audacious/configdb.h> -#include <audacious/util.h> -#include <audacious/titlestring.h> -#include "audacious/output.h" - -#ifdef CDROMSTOP -# define XMMS_STOP CDROMSTOP -#elif defined CDIOCSTOP -# define XMMS_STOP CDIOCSTOP -#else -# error "No stop ioctl" -#endif - -#ifdef CDIOCPAUSE -# define XMMS_PAUSE CDIOCPAUSE -#elif defined CDROMPAUSE -# define XMMS_PAUSE CDROMPAUSE -#else -# error "No pause ioctl" -#endif - -#ifdef CDIOCRESUME -# define XMMS_RESUME CDIOCRESUME -#elif defined CDROMRESUME -# define XMMS_RESUME CDROMRESUME -#else -# error "No resume ioctl" -#endif - -/* - * Distributions should not patch this, but instead use the - * --with-cdda-device=path and --with-cdda-dir=path configure options. - */ - -#ifndef CDDA_DEVICE -# ifdef HAVE_SYS_CDIO_H -# if defined(__FreeBSD__) && !defined(CDIOCREADAUDIO) -# define CDDA_DEVICE "/dev/acd0c" -# elif defined __FreeBSD__ -# define CDDA_DEVICE "/dev/acd0" -# elif defined __OpenBSD__ || defined __NetBSD__ -# define CDDA_DEVICE "/dev/cd0c" -# else -# define CDDA_DEVICE "/vol/dev/aliases/cdrom0" -# endif -# else -# define CDDA_DEVICE "/dev/cdrom" -# endif -#endif - -#ifndef CDDA_DIRECTORY -# ifdef HAVE_SYS_CDIO_H -# ifdef __FreeBSD__ -# define CDDA_DIRECTORY "/cdrom" -# elif defined __OpenBSD__ || defined __NetBSD__ -# define CDDA_DIRECTORY "/cdrom" -# else -# define CDDA_DIRECTORY "/cdrom/cdrom0" -# endif -# else -# define CDDA_DIRECTORY "/mnt/cdrom" -# endif -#endif - - - - -static TitleInput *cdda_get_tuple(cdda_disc_toc_t * toc, int track); -static gchar *get_song_title(TitleInput *tuple); -static gboolean stop_timeout(gpointer data); - -static void cdda_init(void); -static int is_our_file(char *filename); -static GList *scan_dir(char *dir); -static void play_file(InputPlayback *playback); -static void stop(InputPlayback *playback); -static void cdda_pause(InputPlayback *playback, short p); -static void seek(InputPlayback *playback, int time); -static int get_time(InputPlayback *playback); -static void get_song_info(char *filename, char **title, int *length); -static TitleInput *get_song_tuple(char *filename); -static gint get_volume(int *l, int *r); -static gint set_volume(int l, int r); -static void cleanup(void); -void cdda_fileinfo(char *filename); - -InputPlugin cdda_ip = { - NULL, - NULL, - "CD Audio Plugin", /* Description */ - cdda_init, - NULL, /* about */ - cdda_configure, - is_our_file, - scan_dir, - play_file, - stop, - cdda_pause, - seek, - NULL, /* set_eq */ - get_time, - get_volume, - set_volume, - cleanup, - NULL, /* obsolete */ - NULL, /* add_vis_pcm */ - NULL, /* set_info, filled in by xmms */ - NULL, /* set_info_text, filled in by xmms */ - get_song_info, - NULL, /* cdda_fileinfo, *//* file_info_box */ - NULL, /* output plugin handle */ - get_song_tuple -}; - -InputPlugin *cdda_iplist[] = { &cdda_ip, NULL }; - -DECLARE_PLUGIN(cdda, NULL, NULL, cdda_iplist, NULL, NULL, NULL, NULL); - -CDDAConfig cdda_cfg; - -static struct { - struct driveinfo drive; - cdda_disc_toc_t cd_toc; - int track; - int fd; - gboolean playing; -} cdda_playing; - -static struct { - GThread *thread; - gboolean audio_error, eof; - int seek; - -} dae_data; - -static gboolean is_paused; -static int pause_time; - -struct timeout { - int id; - char *device; -}; - -static GList *timeout_list; - -/* Time to delay stop command in 1/10 second */ -#define STOP_DELAY 20 - -#ifdef BEEP_CDROM_SOLARIS -/* - * Lowlevel cdrom access, Solaris style (Solaris, Linux) - */ - -static void -play_ioctl(struct cdda_msf *start, struct cdda_msf *end) -{ - struct cdrom_msf msf; - - msf.cdmsf_min0 = start->minute; - msf.cdmsf_sec0 = start->second; - msf.cdmsf_frame0 = start->frame; - msf.cdmsf_min1 = end->minute; - msf.cdmsf_sec1 = end->second; - msf.cdmsf_frame1 = end->frame; - ioctl(cdda_playing.fd, CDROMPLAYMSF, &msf); -} - -static int -get_current_frame(void) -{ - struct cdrom_subchnl subchnl; - - subchnl.cdsc_format = CDROM_MSF; - if (ioctl(cdda_playing.fd, CDROMSUBCHNL, &subchnl) < 0) - return -1; - - switch (subchnl.cdsc_audiostatus) { - case CDROM_AUDIO_COMPLETED: - case CDROM_AUDIO_ERROR: - return -1; - } - - return (LBA(subchnl.cdsc_absaddr.msf)); -} - -#if !defined(CDROMVOLREAD) -static int volume_left = 100, volume_right = 100; -#endif - -static void -drive_get_volume(int *l, int *r) -{ -#if defined(CDROMVOLREAD) - struct cdrom_volctrl vol; - - if (cdda_playing.fd != -1 && !ioctl(cdda_playing.fd, CDROMVOLREAD, &vol)) { - *l = (100 * vol.channel0) / 255; - *r = (100 * vol.channel1) / 255; - } -#if 0 - else if (cdda_playing.fd != -1) - g_message("CDROMVOLREAD failed"); -#endif -#else - *l = volume_left; - *r = volume_right; -#endif -} - -static void -drive_set_volume(int l, int r) -{ - struct cdrom_volctrl vol; - - if (cdda_playing.fd != -1) { - vol.channel0 = vol.channel2 = (l * 255) / 100; - vol.channel1 = vol.channel3 = (r * 255) / 100; - ioctl(cdda_playing.fd, CDROMVOLCTRL, &vol); - } -#if !defined(CDROMVOLREAD) - volume_left = l; - volume_right = r; -#endif -} - -#ifdef CDROMREADAUDIO -int -read_audio_data(int fd, int pos, int num, void *buf) -{ - struct cdrom_read_audio cdra; - -#if 1 - cdra.addr.lba = pos - CDDA_MSF_OFFSET; - cdra.addr_format = CDROM_LBA; -#else - cdra.addr.msf.minute = pos / (60 * 75); - cdra.addr.msf.second = (pos / 75) % 60; - cdra.addr.msf.frame = pos % 75; - cdra.addr_format = CDROM_MSF; -#endif - - cdra.nframes = num; - cdra.buf = buf; - - if (ioctl(fd, CDROMREADAUDIO, &cdra) < 0) - return -errno; - - return cdra.nframes; -} -#endif /* CDROMREADAUDIO */ - -#if defined(CDROMCDDA) -int -read_audio_data(int fd, int pos, int num, void *buf) -{ - struct cdrom_cdda cdra; - - cdra.cdda_addr = pos - CDDA_MSF_OFFSET; - cdra.cdda_length = num; - cdra.cdda_data = buf; - cdra.cdda_subcode = CDROM_DA_NO_SUBCODE; - if (ioctl(fd, CDROMCDDA, &cdra) < 0) - return -errno; - - return cdra.cdda_length; -} -#endif - -static gboolean -cdda_get_toc_lowlevel(int fd, cdda_disc_toc_t * info) -{ - struct cdrom_tochdr tochdr; - struct cdrom_tocentry tocentry; - int i; - - - - if (ioctl(fd, CDROMREADTOCHDR, &tochdr)) - return FALSE; - - for (i = tochdr.cdth_trk0; i <= tochdr.cdth_trk1; i++) { - tocentry.cdte_format = CDROM_MSF; - tocentry.cdte_track = i; - if (ioctl(fd, CDROMREADTOCENTRY, &tocentry)) - return FALSE; - info->track[i].minute = tocentry.cdte_addr.msf.minute; - info->track[i].second = tocentry.cdte_addr.msf.second; - info->track[i].frame = tocentry.cdte_addr.msf.frame; - info->track[i].flags.data_track = - tocentry.cdte_ctrl == CDROM_DATA_TRACK; - - } - - /* Get the leadout track */ - tocentry.cdte_track = CDROM_LEADOUT; - tocentry.cdte_format = CDROM_MSF; - - if (ioctl(fd, CDROMREADTOCENTRY, &tocentry)) - return FALSE; - info->leadout.minute = tocentry.cdte_addr.msf.minute; - info->leadout.second = tocentry.cdte_addr.msf.second; - info->leadout.frame = tocentry.cdte_addr.msf.frame; - - info->first_track = tochdr.cdth_trk0; - info->last_track = tochdr.cdth_trk1; - - return TRUE; -} - -#endif - -#ifdef BEEP_CDROM_BSD -/* - * Lowlevel cdrom access, BSD style (FreeBSD, OpenBSD, NetBSD, Darwin) - */ - -static void -play_ioctl(struct cdda_msf *start, struct cdda_msf *end) -{ - struct ioc_play_msf msf; - - msf.start_m = start->minute; - msf.start_s = start->second; - msf.start_f = start->frame; - msf.end_m = end->minute; - msf.end_s = end->second; - msf.end_f = end->frame; - ioctl(cdda_playing.fd, CDIOCPLAYMSF, &msf); -} - -static int -get_current_frame(void) -{ - struct ioc_read_subchannel subchnl; - struct cd_sub_channel_info subinfo; - subchnl.address_format = CD_MSF_FORMAT; - subchnl.data_format = CD_CURRENT_POSITION; - subchnl.track = 0; - subchnl.data_len = sizeof(subinfo); - subchnl.data = &subinfo; - if (ioctl(cdda_playing.fd, CDIOCREADSUBCHANNEL, &subchnl) < 0) - return -1; - -#ifdef BEEP_CDROM_BSD_DARWIN - return ((subchnl.data->what.position.absaddr[1] * 60 - subchnl.data->what.position.absaddr[2]) * 75 + - subchnl.data->what.position.absaddr[3]); -#else - return (LBA(subchnl.data->what.position.absaddr.msf)); -#endif -} - -static void -drive_get_volume(int *l, int *r) -{ - struct ioc_vol vol; - - if (cdda_playing.fd != -1) { - ioctl(cdda_playing.fd, CDIOCGETVOL, &vol); - *l = (100 * vol.vol[0]) / 255; - *r = (100 * vol.vol[1]) / 255; - } -} - -static void -drive_set_volume(int l, int r) -{ - struct ioc_vol vol; - - if (cdda_playing.fd != -1) { - vol.vol[0] = vol.vol[2] = (l * 255) / 100; - vol.vol[1] = vol.vol[3] = (r * 255) / 100; - ioctl(cdda_playing.fd, CDIOCSETVOL, &vol); - } -} - -#if defined(__FreeBSD__) && !defined(CDIOCREADAUDIO) -int -read_audio_data(int fd, int pos, int num, void *buf) -{ - int bs = CD_FRAMESIZE_RAW; - - if (ioctl(fd, CDRIOCSETBLOCKSIZE, &bs) == -1) - return -1; - if (pread(fd, buf, num * bs, (pos - 150) * bs) != num * bs) - return -1; - - return num; -} -#endif - -#if defined(CDIOCREADAUDIO) -int -read_audio_data(int fd, int pos, int num, void *buf) -{ - struct ioc_read_audio cdra; - - cdra.address.lba = pos - CDDA_MSF_OFFSET; - cdra.address_format = CD_LBA_FORMAT; - cdra.nframes = num; - cdra.buffer = buf; - - if (ioctl(fd, CDIOCREADAUDIO, &cdra) < 0) - return -errno; - - return cdra.nframes; -} -#endif /* CDIOCREADAUDIO */ - -#ifdef BEEP_CDROM_BSD_NETBSD /* NetBSD, OpenBSD */ - -static gboolean -cdda_get_toc_lowlevel(int fd, cdda_disc_toc_t * info) -{ - struct ioc_toc_header tochdr; - struct ioc_read_toc_entry tocentry; - struct cd_toc_entry tocentrydata; - int i; - - if (ioctl(fd, CDIOREADTOCHEADER, &tochdr)) - return FALSE; - - for (i = tochdr.starting_track; i <= tochdr.ending_track; i++) { - tocentry.address_format = CD_MSF_FORMAT; - - tocentry.starting_track = i; - tocentry.data = &tocentrydata; - tocentry.data_len = sizeof(tocentrydata); - if (ioctl(fd, CDIOREADTOCENTRYS, &tocentry)) - return FALSE; - info->track[i].minute = tocentry.data->addr.msf.minute; - info->track[i].second = tocentry.data->addr.msf.second; - info->track[i].frame = tocentry.data->addr.msf.frame; - info->track[i].flags.data_track = (tocentry.data->control & 4) == 4; - } - - /* Get the leadout track */ - tocentry.address_format = CD_MSF_FORMAT; - - tocentry.starting_track = 0xAA; - tocentry.data = &tocentrydata; - tocentry.data_len = sizeof(tocentrydata); - if (ioctl(fd, CDIOREADTOCENTRYS, &tocentry)) - return FALSE; - info->leadout.minute = tocentry.data->addr.msf.minute; - info->leadout.second = tocentry.data->addr.msf.second; - info->leadout.frame = tocentry.data->addr.msf.frame; - - info->first_track = tochdr.starting_track; - info->last_track = tochdr.ending_track; - - return TRUE; -} - -#elif defined(BEEP_CDROM_BSD_DARWIN) - -static gboolean -cdda_get_toc_lowlevel(int fd, cdda_disc_toc_t * info) -{ - struct ioc_toc_header tochdr; - struct ioc_read_toc_entry tocentry; - int i; - - if (ioctl(fd, CDIOREADTOCHEADER, &tochdr)) - return FALSE; - - for (i = tochdr.starting_track; i <= tochdr.ending_track; i++) { - tocentry.address_format = CD_MSF_FORMAT; - - tocentry.starting_track = i; - if (ioctl(fd, CDIOREADTOCENTRYS, &tocentry)) - return FALSE; - info->track[i].minute = tocentry.data->addr[1]; - info->track[i].second = tocentry.data->addr[2]; - info->track[i].frame = tocentry.data->addr[3]; - info->track[i].flags.data_track = (tocentry.data->control & 4) == 4; - } - - /* Get the leadout track */ - tocentry.address_format = CD_MSF_FORMAT; - - tocentry.starting_track = 0xAA; - if (ioctl(fd, CDIOREADTOCENTRYS, &tocentry)) - return FALSE; - info->leadout.minute = tocentry.data->addr[1]; - info->leadout.second = tocentry.data->addr[2]; - info->leadout.frame = tocentry.data->addr[3]; - - return TRUE; -} - -#else /* FreeBSD */ - -static gboolean -cdda_get_toc_lowlevel(int fd, cdda_disc_toc_t * info) -{ - struct ioc_toc_header tochdr; - struct ioc_read_toc_single_entry tocentry; - int i; - - if (ioctl(fd, CDIOREADTOCHEADER, &tochdr)) - return FALSE; - - for (i = tochdr.starting_track; i <= tochdr.ending_track; i++) { - tocentry.address_format = CD_MSF_FORMAT; - - tocentry.track = i; - if (ioctl(fd, CDIOREADTOCENTRY, &tocentry)) - return FALSE; - info->track[i].minute = tocentry.entry.addr.msf.minute; - info->track[i].second = tocentry.entry.addr.msf.second; - info->track[i].frame = tocentry.entry.addr.msf.frame; - info->track[i].flags.data_track = (tocentry.entry.control & 4) == 4; - } - - /* Get the leadout track */ - tocentry.address_format = CD_MSF_FORMAT; - - tocentry.track = 0xAA; - if (ioctl(fd, CDIOREADTOCENTRY, &tocentry)) - return FALSE; - info->leadout.minute = tocentry.entry.addr.msf.minute; - info->leadout.second = tocentry.entry.addr.msf.second; - info->leadout.frame = tocentry.entry.addr.msf.frame; - - info->first_track = tochdr.starting_track; - info->last_track = tochdr.ending_track; - - return TRUE; -} -#endif - -#endif - - - - - - - - - - - -extern gboolean -is_mounted(const char *device_name) -{ -#if defined(HAVE_MNTENT_H) || defined(HAVE_GETMNTINFO) - char devname[256]; - struct stat st; -#if defined(HAVE_MNTENT_H) - FILE *mounts; - struct mntent *mnt; -#elif defined(HAVE_GETMNTINFO) -#if defined __NetBSD__ && HAVE_STATVFS - struct statvfs *fsp; -#else - struct statfs *fsp; -#endif - int entries; -#endif - - if (lstat(device_name, &st) < 0) - return -1; - - if (S_ISLNK(st.st_mode)) - readlink(device_name, devname, 256); - else - strncpy(devname, device_name, 256); - -#if defined(HAVE_MNTENT_H) - if ((mounts = setmntent(MOUNTED, "r")) == NULL) - return TRUE; - - while ((mnt = getmntent(mounts)) != NULL) { - if (strcmp(mnt->mnt_fsname, devname) == 0) { - endmntent(mounts); - return TRUE; - } - } - endmntent(mounts); -#elif defined(HAVE_GETMNTINFO) - entries = getmntinfo(&fsp, MNT_NOWAIT); - if (entries < 0) - return FALSE; - - while (entries-- > 0) { - if (!strcmp(fsp->f_mntfromname, devname)) - return TRUE; - fsp++; - } -#endif -#endif - return FALSE; -} - - -gboolean -cdda_get_toc(cdda_disc_toc_t * info, const char *device) -{ - gboolean retv = FALSE; - int fd; - - if (is_mounted(device)) - return FALSE; - - if ((fd = open(device, CDOPENFLAGS)) == -1) - return FALSE; - - memset(info, 0, sizeof(cdda_disc_toc_t)); - - retv = cdda_get_toc_lowlevel(fd, info); - close(fd); - - return retv; -} - -static void -cdda_init(void) -{ - ConfigDb *db; - struct driveinfo *drive = g_malloc0(sizeof(struct driveinfo)); - int ndrives = 1, i; - - cdda_playing.fd = -1; - memset(&cdda_cfg, 0, sizeof(CDDAConfig)); - -#ifdef HAVE_OSS - drive->mixer = CDDA_MIXER_OSS; - drive->oss_mixer = SOUND_MIXER_CD; -#endif - - db = bmp_cfg_db_open(); - - /* These names are used for backwards compatibility */ - bmp_cfg_db_get_string(db, "CDDA", "device", &drive->device); - bmp_cfg_db_get_string(db, "CDDA", "directory", &drive->directory); - bmp_cfg_db_get_int(db, "CDDA", "mixer", &drive->mixer); - if (bmp_cfg_db_get_int(db, "CDDA", "readmode", &drive->dae)==FALSE) - drive->dae = 1; /* default to digital */ - - if (!drive->device) - drive->device = g_strdup(CDDA_DEVICE); - if (!drive->directory) - drive->directory = g_strdup(CDDA_DIRECTORY); - - cdda_cfg.drives = g_list_append(cdda_cfg.drives, drive); - - bmp_cfg_db_get_int(db, "CDDA", "num_drives", &ndrives); - for (i = 1; i < ndrives; i++) { - char label[20]; - drive = g_malloc0(sizeof(struct driveinfo)); - - sprintf(label, "device%d", i); - bmp_cfg_db_get_string(db, "CDDA", label, &drive->device); - - sprintf(label, "directory%d", i); - bmp_cfg_db_get_string(db, "CDDA", label, &drive->directory); - - sprintf(label, "mixer%d", i); - bmp_cfg_db_get_int(db, "CDDA", label, &drive->mixer); - - sprintf(label, "readmode%d", i); - bmp_cfg_db_get_int(db, "CDDA", label, &drive->dae); - - cdda_cfg.drives = g_list_append(cdda_cfg.drives, drive); - } - bmp_cfg_db_get_bool(db, "CDDA", "title_override", - &cdda_cfg.title_override); - bmp_cfg_db_get_string(db, "CDDA", "name_format", &cdda_cfg.name_format); - bmp_cfg_db_get_bool(db, "CDDA", "use_cddb", &cdda_cfg.use_cddb); - bmp_cfg_db_get_string(db, "CDDA", "cddb_server", &cdda_cfg.cddb_server); - bmp_cfg_db_close(db); - - if (!cdda_cfg.cddb_server) - cdda_cfg.cddb_server = g_strdup(CDDB_DEFAULT_SERVER); - if (!cdda_cfg.name_format) - cdda_cfg.name_format = g_strdup("%p - %t"); -} - -struct driveinfo * -cdda_find_drive(char *filename) -{ - GList *node; - - // FIXME: Will always return the first drive - - for (node = cdda_cfg.drives; node; node = node->next) { - struct driveinfo *d = node->data; - if (!strncmp(d->directory, filename, strlen(d->directory))) - return d; - } - - return NULL; - -} - -static void -timeout_destroy(struct timeout *entry) -{ - g_free(entry->device); - g_free(entry); - timeout_list = g_list_remove(timeout_list, entry); -} - -static void -timeout_remove_for_device(char *device) -{ - GList *node; - - for (node = timeout_list; node; node = node->next) { - struct timeout *t = node->data; - - if (!strcmp(t->device, device)) { - gtk_timeout_remove(t->id); - timeout_destroy(t); - return; - } - } - -} - -static void -cleanup(void) -{ - GList *node; - struct driveinfo *drive; - - if (cdda_cfg.drives) { - for (node = g_list_first(cdda_cfg.drives); node; node = node->next) { - drive = (struct driveinfo *)node->data; - if (!drive) - continue; - - if (drive->device) - free(drive->device); - - if (drive->directory) - free(drive->directory); - - free(drive); - } - - g_list_free(cdda_cfg.drives); - cdda_cfg.drives = NULL; - } - - if (cdda_cfg.name_format) { - free(cdda_cfg.name_format); - cdda_cfg.name_format = NULL; - } - - if (cdda_cfg.cddb_server) { - free(cdda_cfg.cddb_server); - cdda_cfg.cddb_server = NULL; - } - - while (timeout_list) { - struct timeout *t = timeout_list->data; - gtk_timeout_remove(t->id); - stop_timeout(t); - timeout_destroy(t); - } - cddb_quit(); -} - -static int -is_our_file(char *filename) -{ - char *ext = ".cda"; - - if (cdda_find_drive(filename) == NULL) { - return FALSE; - } - - if (g_str_has_suffix(filename, ext)) { - return TRUE; - } - return FALSE; -} - - -static GList * -scan_dir(char *dir) -{ - GList *list = NULL; - int i; - cdda_disc_toc_t toc; - struct driveinfo *drive; - - if ((drive = cdda_find_drive(dir)) == NULL) - return NULL; - - if (!cdda_get_toc(&toc, drive->device)) - return NULL; - - for (i = toc.last_track; i >= toc.first_track; i--) - if (!toc.track[i].flags.data_track) { - list = g_list_prepend(list, g_strdup_printf("Track %02d.cda", i)); - } - return list; -} - -guint -cdda_calculate_track_length(cdda_disc_toc_t * toc, int track) -{ - if (track == toc->last_track) - return (LBA(toc->leadout) - LBA(toc->track[track])); - else - return (LBA(toc->track[track + 1]) - LBA(toc->track[track])); -} - -static void * -dae_play_loop(void *data) -{ - InputPlayback *playback = data; - char *buffer = g_malloc(CD_FRAMESIZE_RAW * CDDA_DAE_FRAMES); - int pos = LBA(cdda_playing.cd_toc.track[cdda_playing.track]); - int end, frames; - - if (cdda_playing.track == cdda_playing.cd_toc.last_track) - end = LBA(cdda_playing.cd_toc.leadout); - else - end = LBA(cdda_playing.cd_toc.track[cdda_playing.track + 1]); - - while (cdda_playing.playing) { - int left; - char *data; - - if (dae_data.seek != -1) { - playback->output->flush(dae_data.seek * 1000); - pos = LBA(cdda_playing.cd_toc.track[cdda_playing.track]) - + dae_data.seek * 75; - dae_data.seek = -1; - dae_data.eof = FALSE; - } - frames = MIN(CDDA_DAE_FRAMES, end - pos); - if (frames == 0) - dae_data.eof = TRUE; - - if (dae_data.eof) { - xmms_usleep(30000); - continue; - } - - frames = read_audio_data(cdda_playing.fd, pos, frames, buffer); - if (frames <= 0) { - int err = -frames; - if (err == EOPNOTSUPP) - dae_data.eof = TRUE; - else { - /* - * If the read failed, skip ahead to - * avoid getting stuck on scratches - * and such. - */ - g_message("read_audio_data() failed: %s (%d)", - strerror(err), err); - pos += MIN(CDDA_DAE_FRAMES, end - pos); - } - continue; - } - left = frames * CD_FRAMESIZE_RAW; - data = buffer; - while (cdda_playing.playing && left > 0 && dae_data.seek == -1) { - int cur = MIN(512 * 2 * 2, left); - cdda_ip.add_vis_pcm(playback->output->written_time(), - FMT_S16_LE, 2, cur, data); - while (playback->output->buffer_free() < cur && - cdda_playing.playing && dae_data.seek == -1) - xmms_usleep(30000); - if (cdda_playing.playing && dae_data.seek == -1) - produce_audio(playback->output->written_time(), FMT_S16_LE, 2, cur, data, &cdda_playing.playing); - left -= cur; - data += cur; - } - pos += frames; - } - - playback->output->buffer_free(); - playback->output->buffer_free(); - g_free(buffer); - - g_thread_exit(NULL); - return NULL; -} - -static void -dae_play(InputPlayback *playback) -{ - if (playback->output->open_audio(FMT_S16_LE, 44100, 2) == 0) { - dae_data.audio_error = TRUE; - cdda_playing.playing = FALSE; - return; - } - dae_data.seek = -1; - dae_data.eof = FALSE; - dae_data.audio_error = FALSE; - dae_data.thread = g_thread_create(dae_play_loop, playback, TRUE, NULL); -} - -static void -play_file(InputPlayback *playback) -{ - char *filename = playback->filename; - char *tmp; - struct driveinfo *drive; - int track; - int track_len; - -// g_message(g_strdup_printf("** CD_AUDIO: trying to play file %s",filename)); - - if ((drive = cdda_find_drive(filename)) == NULL) { -// g_message("** CD_AUDIO: find drive check failed"); - return; - } - if (is_mounted(drive->device)) { -// g_message("** CD_AUDIO: drive is mounted"); - return; - } - tmp = strrchr(filename, '/'); - if (tmp) - tmp++; - else - tmp = filename; - - if (!sscanf(tmp, "Track %d.cda", &track)) { -// g_message("** CD_AUDIO: filename check failed"); - return; - } - - if (!cdda_get_toc(&cdda_playing.cd_toc, drive->device) || - cdda_playing.cd_toc.track[track].flags.data_track || - track < cdda_playing.cd_toc.first_track || - track > cdda_playing.cd_toc.last_track) { -// g_message("** CD_AUDIO: toc check failed"); - return; - } - - if ((cdda_playing.fd = open(drive->device, CDOPENFLAGS)) == -1) { -// g_message("** CD_AUDIO: device open failed"); - return; - } - track_len = cdda_calculate_track_length(&cdda_playing.cd_toc, track); - cdda_ip.set_info(get_song_title(cdda_get_tuple(&cdda_playing.cd_toc, track)), - (track_len * 1000) / 75, 44100 * 2 * 2 * 8, 44100, 2); - - memcpy(&cdda_playing.drive, drive, sizeof(struct driveinfo)); -#ifndef CDDA_HAS_READAUDIO - cdda_playing.drive.dae = FALSE; -#endif - - cdda_playing.track = track; - - is_paused = FALSE; - timeout_remove_for_device(drive->device); - - cdda_playing.playing = TRUE; - if (drive->dae) - dae_play(playback); - else - seek(playback, 0); - return; -} - -static TitleInput * -cdda_get_tuple(cdda_disc_toc_t * toc, int track) -{ - G_LOCK_DEFINE_STATIC(tuple); - - static guint32 cached_id; - static cdinfo_t cdinfo; - static gchar *performer, *album_name, *track_name; - TitleInput *tuple = NULL; - guint32 disc_id; - - disc_id = cdda_cddb_compute_discid(toc); - - /* - * We want to avoid looking up a album from two threads simultaneously. - * This can happen since we are called both from the main-thread and - * from the playlist-thread. - */ - - G_LOCK(tuple); - if (!(disc_id == cached_id && cdinfo.is_valid)) { - /* - * We try to look up the disc again if the info is not - * valid. The user might have configured a new server - * in the meantime. - */ - cdda_cdinfo_flush(&cdinfo); - cached_id = disc_id; - - if (!cdda_cdinfo_read_file(disc_id, &cdinfo)) { - if (cdda_cfg.use_cddb) - cdda_cddb_get_info(toc, &cdinfo); - if (cdinfo.is_valid) - cdda_cdinfo_write_file(disc_id, &cdinfo); - } - } - - tuple = bmp_title_input_new(); - cdda_cdinfo_get(&cdinfo, track, &performer, &album_name, &track_name); - G_UNLOCK(tuple); - - tuple->performer = g_strdup(performer); - tuple->album_name = g_strdup(album_name); - tuple->track_name = g_strdup(track_name); - tuple->track_number = (track); - tuple->file_name = g_strdup(tuple->file_path); - tuple->file_path = g_strdup_printf(_("CD Audio Track %02u"), track); - tuple->file_ext = "cda"; - tuple->length = ((cdda_calculate_track_length(toc, track) * 1000) / 75); - - if (!tuple->track_name) - tuple->track_name = g_strdup_printf(_("CD Audio Track %02u"), track); - - tuple->genre = g_strdup(cdinfo.genre); - tuple->year = cdinfo.year; - - return tuple; -} - -static gchar * -get_song_title(TitleInput *tuple) -{ - return xmms_get_titlestring(cdda_cfg.title_override ? - cdda_cfg.name_format : - xmms_get_gentitle_format(), tuple); -} - -static gboolean -stop_timeout(gpointer data) -{ - int fd; - struct timeout *to = data; - - fd = open(to->device, CDOPENFLAGS); - if (fd != -1) { - ioctl(fd, XMMS_STOP, 0); - close(fd); - } - timeout_destroy(to); - return FALSE; -} - -static void -stop(InputPlayback * playback) -{ - struct timeout *to_info; - if (cdda_playing.fd < 0) - return; - - cdda_playing.playing = FALSE; - - if (cdda_playing.drive.dae) { - g_thread_join(dae_data.thread); - playback->output->close_audio(); - } - else - ioctl(cdda_playing.fd, XMMS_PAUSE, 0); - - close(cdda_playing.fd); - cdda_playing.fd = -1; - - if (!cdda_playing.drive.dae) { - to_info = g_malloc(sizeof(*to_info)); - to_info->device = g_strdup(cdda_playing.drive.device); - to_info->id = gtk_timeout_add(STOP_DELAY * 100, stop_timeout, - to_info); - timeout_list = g_list_prepend(timeout_list, to_info); - } -} - -static void -cdda_pause(InputPlayback *playback, short p) -{ - if (cdda_playing.drive.dae) { - playback->output->pause(p); - return; - } - if (p) { - pause_time = get_time(playback); - ioctl(cdda_playing.fd, XMMS_PAUSE, 0); - } - else { - ioctl(cdda_playing.fd, XMMS_RESUME, 0); - pause_time = -1; - } - is_paused = p; -} - - - -static void -seek(InputPlayback *data, int time) -{ - struct cdda_msf *end, start; - int track = cdda_playing.track; - -// g_message("** CD_AUDIO: seeking..."); - if (cdda_playing.drive.dae) { - dae_data.seek = time; - while (dae_data.seek != -1) - xmms_usleep(20000); - return; - } - - start.minute = (cdda_playing.cd_toc.track[track].minute * 60 + - cdda_playing.cd_toc.track[track].second + time) / 60; - start.second = (cdda_playing.cd_toc.track[track].second + time) % 60; - start.frame = cdda_playing.cd_toc.track[track].frame; - if (track == cdda_playing.cd_toc.last_track) - end = &cdda_playing.cd_toc.leadout; - else - end = &cdda_playing.cd_toc.track[track + 1]; - - play_ioctl(&start, end); - - if (is_paused) { - cdda_pause(data, TRUE); - pause_time = time * 1000; - } -} - -static int -get_time_analog(void) -{ - int frame, start_frame, length; - int track = cdda_playing.track; - - if (is_paused && pause_time != -1) - return pause_time; - - frame = get_current_frame(); - - if (frame == -1) - return -1; - - start_frame = LBA(cdda_playing.cd_toc.track[track]); - length = cdda_calculate_track_length(&cdda_playing.cd_toc, track); - - if (frame - start_frame >= length - 20) /* 20 seems to work better */ - return -1; - - return ((frame - start_frame) * 1000) / 75; -} - -static int -get_time_dae(InputPlayback *playback) -{ - if (dae_data.audio_error) - return -2; - if (!cdda_playing.playing || - (dae_data.eof && !playback->output->buffer_playing())) - return -1; - return playback->output->output_time(); -} - -static int -get_time(InputPlayback *playback) -{ - if (cdda_playing.fd == -1) - return -1; - - if (cdda_playing.drive.dae) - return get_time_dae(playback); - else - return get_time_analog(); -} - -static void -get_song_info(char *filename, char **title, int *len) -{ - cdda_disc_toc_t toc; - int t; - char *tmp; - struct driveinfo *drive; - TitleInput *tuple; - - *title = NULL; - *len = -1; - -// g_message("** CD_AUDIO: getting song info"); - - if ((drive = cdda_find_drive(filename)) == NULL) - return; - - tmp = strrchr(filename, '/'); - if (tmp) - tmp++; - else - tmp = filename; - - if (!sscanf(tmp, "Track %d.cda", &t)) - return; - if (!cdda_get_toc(&toc, drive->device)) - return; - if (t < toc.first_track || t > toc.last_track - || toc.track[t].flags.data_track) - return; - - if ((tuple = cdda_get_tuple(&toc, t)) != NULL) { - *len = tuple->length; - *title = get_song_title(tuple); - } - bmp_title_input_free(tuple); -} - -static TitleInput * -get_song_tuple(char *filename) -{ - cdda_disc_toc_t toc; - int t; - char *tmp; - struct driveinfo *drive; - TitleInput *tuple = NULL; - -// g_message("** CD_AUDIO: getting song info"); - - if ((drive = cdda_find_drive(filename)) == NULL) - return tuple; - - tmp = strrchr(filename, '/'); - if (tmp) - tmp++; - else - tmp = filename; - - if (!sscanf(tmp, "Track %d.cda", &t)) - return tuple; - if (!cdda_get_toc(&toc, drive->device)) - return tuple; - if (t < toc.first_track || t > toc.last_track - || toc.track[t].flags.data_track) - return tuple; - - tuple = cdda_get_tuple(&toc, t); - return tuple; -} - -#ifdef HAVE_OSS -static void -oss_get_volume(int *l, int *r, int mixer_line) -{ - int fd, v; - - fd = open(DEV_MIXER, O_RDONLY); - if (fd != -1) { - ioctl(fd, MIXER_READ(mixer_line), &v); - *r = (v & 0xFF00) >> 8; - *l = (v & 0x00FF); - close(fd); - } -} - -static void -oss_set_volume(int l, int r, int mixer_line) -{ - int fd, v; - - fd = open(DEV_MIXER, O_RDONLY); - if (fd != -1) { - v = (r << 8) | l; - ioctl(fd, MIXER_WRITE(mixer_line), &v); - close(fd); - } -} -#else -static void -oss_get_volume(int *l, int *r, int mixer_line) -{ -} -static void -oss_set_volume(int l, int r, int mixer_line) -{ -} -#endif - - -static gint -get_volume(int *l, int *r) -{ - if (cdda_playing.drive.dae) - return 0; - else if (cdda_playing.drive.mixer == CDDA_MIXER_OSS) - oss_get_volume(l, r, cdda_playing.drive.oss_mixer); - else if (cdda_playing.drive.mixer == CDDA_MIXER_DRIVE) - drive_get_volume(l, r); - return 1; -} - -static gint -set_volume(int l, int r) -{ - if (cdda_playing.drive.dae) - return 0; - else if (cdda_playing.drive.mixer == CDDA_MIXER_OSS) - oss_set_volume(l, r, cdda_playing.drive.oss_mixer); - else if (cdda_playing.drive.mixer == CDDA_MIXER_DRIVE) - drive_set_volume(l, r); - return 1; -}
--- a/src/cdaudio/cdaudio.h Wed Jul 25 16:48:53 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,161 +0,0 @@ -/* XMMS - Cross-platform multimedia player - * Copyright (C) 1998-2002 Peter Alm, Mikael Alm, Olle Hallnas, - * Thomas Nilsson and 4Front Technologies - * Copyright (C) 1999-2002 Haavard Kvaalen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#ifndef CDAUDIO_H -#define CDAUDIO_H - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include <glib.h> -#include <gtk/gtk.h> -#include "audacious/plugin.h" - -#include "cdinfo.h" - -#ifdef HAVE_OSS -#ifdef HAVE_SYS_SOUNDCARD_H -#include <sys/soundcard.h> -#else -#include <soundcard.h> -#endif -#endif - -#ifdef HAVE_MNTENT_H -#include <mntent.h> -#endif - -#ifdef HAVE_GETMNTINFO -#include <sys/param.h> -#include <sys/ucred.h> -#include <sys/mount.h> -#endif - -#ifndef CD_FRAMES -#define CD_FRAMES 75 -#endif - -#include <sys/types.h> - -#ifdef HAVE_LINUX_CDROM_H -#include <linux/cdrom.h> -#elif defined HAVE_SYS_CDIO_H -#include <sys/cdio.h> -#ifdef HAVE_SYS_CDRIO_H -#include <sys/cdrio.h> -#endif -#endif - -#if defined(CDROMREADAUDIO) || defined(CDIOCREADAUDIO) || defined(CDROMCDDA) || defined(CDRIOCSETBLOCKSIZE) -# define CDDA_HAS_READAUDIO -#endif - -#ifndef CD_FRAMESIZE_RAW -# define CD_FRAMESIZE_RAW 2352 -#endif - -/* Number of frames that are read at once in dae mode */ -#define CDDA_DAE_FRAMES 8 - -#ifndef CDDA_HAS_READAUDIO -#warning "Digital audio extraction has not been ported to this platform" -#define read_audio_data(fd, pos, num, buf) -1 -#else -int read_audio_data(int fd, int pos, int num, void *buf); -#endif - - -#ifdef __FreeBSD__ -/* - * FreeBSD won't be able to detect media changes if using O_NONBLOCK - */ -#define CDOPENFLAGS O_RDONLY -#else -#define CDOPENFLAGS (O_RDONLY | O_NONBLOCK) -#endif - - -#define CDDB_DEFAULT_SERVER "freedb.freedb.org" - -struct driveinfo { - gchar *device, *directory; - gint mixer, oss_mixer; - gboolean valid; - gint dae; -}; - -typedef struct { - GList *drives; - - gchar *cddb_server; - gint cddb_protocol_level; - gboolean use_cddb; - - gboolean title_override; - char *name_format; -} CDDAConfig; - -struct cdda_msf { - guint8 minute; - guint8 second; - guint8 frame; - struct { - guint data_track:1; - } flags; -}; - -/* - * Note: This macro will convert to a LBA representation of the MSF - * address, not to a true LBA address, as we don't subtract the offset - */ -#define LBA(msf) ((msf.minute * 60 + msf.second) * 75 + msf.frame) - -#define CDDA_MSF_OFFSET 150 - -typedef struct { - guint8 first_track, last_track; - struct cdda_msf leadout; - struct cdda_msf track[100]; -} cdda_disc_toc_t; - -extern CDDAConfig cdda_cfg; - -enum { - CDDA_MIXER_NONE, - CDDA_MIXER_DRIVE, - CDDA_MIXER_OSS, -}; - -enum { - CDDA_READ_ANALOG, - CDDA_READ_DAE, -}; - -void cdda_configure(void); -gboolean cdda_get_toc(cdda_disc_toc_t * info, const gchar *device); -guint32 cdda_cddb_compute_discid(cdda_disc_toc_t * info); -void cdda_cddb_get_info(cdda_disc_toc_t * toc, cdinfo_t * info); -struct driveinfo *cdda_find_drive(gchar *filename); - -void cdda_cddb_show_server_dialog(GtkWidget * w, gpointer data); -void cdda_cddb_set_server(const gchar *new_server); -void cddb_quit(void); - -#endif
--- a/src/cdaudio/cddb.c Wed Jul 25 16:48:53 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,956 +0,0 @@ -/* - * cddb.c Copyright 1999-2001 Håvard Kvålen <havardk@xmms.org> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -#include "cddb.h" - -#include <glib.h> -#include <glib/gprintf.h> -#include <gtk/gtk.h> -#include <stdarg.h> - -#include <audacious/util.h> - -#include "http.h" -#include "cdaudio.h" -#include "cdinfo.h" - - -static guint32 cached_id = 0; -static GtkWidget *server_dialog, *server_clist; -static GtkWidget *debug_window, *debug_clist; -static GList *debug_messages = NULL; -static GList *temp_messages = NULL; -static guint cddb_timeout_id; - -G_LOCK_DEFINE_STATIC(list); - -void configure_set_cddb_server(gchar * server); - -static void -cddb_log(gchar * str, ...) -{ - static GList *end_ptr = NULL; - static gint message_num = 0; - va_list args; - gchar *text; - - va_start(args, str); - text = g_strdup_vprintf(str, args); - va_end(args); - - message_num++; - debug_messages = g_list_prepend(debug_messages, text); - if (!end_ptr) - end_ptr = debug_messages; - if (message_num > CDDB_LOG_MAX) { - GList *temp; - - temp = g_list_previous(end_ptr); - temp->next = NULL; - g_free(end_ptr->data); - g_list_free_1(end_ptr); - end_ptr = temp; - message_num--; - } - if (debug_window) { - G_LOCK(list); - temp_messages = g_list_append(temp_messages, g_strdup(text)); - G_UNLOCK(list); - } -} - -static gint -cddb_sum(gint in) -{ - gint retval = 0; - - while (in > 0) { - retval += in % 10; - in /= 10; - } - return retval; -} - -guint32 -cdda_cddb_compute_discid(cdda_disc_toc_t * info) -{ - gint i; - guint high = 0, low; - - for (i = info->first_track; i <= info->last_track; i++) - high += cddb_sum(info->track[i].minute * 60 + info->track[i].second); - - low = (info->leadout.minute * 60 + info->leadout.second) - - (info->track[info->first_track].minute * 60 + - info->track[info->first_track].second); - - return ((high % 0xff) << 24 | low << 8 | (info->last_track - - info->first_track + 1)); -} - -static gchar * -cddb_generate_offset_string(cdda_disc_toc_t * info) -{ - gchar *buffer; - gchar offset[8]; - int i; - - buffer = g_malloc(info->last_track * 7 + 1); - - sprintf(buffer, "%d", LBA(info->track[info->first_track])); - - for (i = info->first_track + 1; i <= info->last_track; i++) { - sprintf(offset, "+%d", LBA(info->track[i])); - strcat(buffer, offset); - } - - return buffer; -} - -static gchar * -cddb_generate_hello_string(void) -{ - static gchar *buffer; - - if (buffer == NULL) { - gchar *env, *client = NULL, *version = NULL, **strs = NULL; - - env = getenv("XMMS_CDDB_CLIENT_NAME"); - if (env) { - strs = g_strsplit(env, " ", 2); - if (strs && strs[0] && strs[1]) { - client = strs[0]; - version = strs[1]; - } - } - - if (!client || !version) { - client = PACKAGE_NAME; - version = PACKAGE_VERSION; - } - - buffer = g_strdup_printf("&hello=nobody+localhost+%s+%s", - client, version); - if (strs) - g_strfreev(strs); - } - return buffer; -} - -static gint -cddb_http_open_connection(const gchar * server, gint port) -{ - gint sock; - gchar *status; - - if ((sock = http_open_connection(server, 80)) == 0) - status = "Failed"; - else - status = "Ok"; - - cddb_log("Connecting to CDDB-server %s: %s", server, status); - return sock; -} - - -static gboolean -cddb_query(gchar * server, cdda_disc_toc_t * info, - cddb_disc_header_t * cddb_info) -{ - /* - * Query the cddb-server for the cd. - * Returns the *real* discid and category. - */ - - gint sock; - gchar *offsets, *getstr; - gchar buffer[256]; - gchar **response; - gint i; - gint ret; - - if ((sock = cddb_http_open_connection(server, 80)) == 0) - return FALSE; - - offsets = cddb_generate_offset_string(info); - - cddb_log("Sending query-command. Disc ID: %08x", - cdda_cddb_compute_discid(info)); - - getstr = - g_strdup_printf - ("GET /~cddb/cddb.cgi?cmd=cddb+query+%08x+%d+%s+%d%s&proto=%d HTTP/1.0\r\n\r\n", - cdda_cddb_compute_discid(info), - info->last_track - info->first_track + 1, offsets, - (info->leadout.minute * 60 + info->leadout.second), - cddb_generate_hello_string(), cdda_cfg.cddb_protocol_level); - cddb_log(getstr); - - g_free(offsets); - ret = write(sock, getstr, strlen(getstr)); - - if(ret != strlen(getstr)){ - g_free(getstr); - http_close_connection(sock); - return FALSE; - } - - g_free(getstr); - - if (http_read_first_line(sock, buffer, 256) < 0) { - http_close_connection(sock); - return FALSE; - } - - response = g_strsplit(buffer, " ", 4); - - cddb_log("Query response: %s", buffer); - - switch (strtol(response[0], NULL, 10)) { - case 200: - /* One exact match */ - for (i = 0; i < 4; i++) { - if (response[i] == NULL) { - g_strfreev(response); - return FALSE; - } - } - cddb_info->category = g_strdup(response[1]); - cddb_info->discid = strtoul(response[2], NULL, 16); - break; - case 210: - case 211: - /* multiple matches - use first match */ - g_strfreev(response); - if (http_read_first_line(sock, buffer, 256) < 0) { - http_close_connection(sock); - return FALSE; - } - response = g_strsplit(buffer, " ", 4); - for (i = 0; i < 4; i++) { - if (response[i] == NULL) { - g_strfreev(response); - return FALSE; - } - } - cddb_info->category = g_strdup(response[0]); - cddb_info->discid = strtoul(response[1], NULL, 16); - break; - default: /* FIXME: Handle other 2xx */ - g_strfreev(response); - return FALSE; - } - http_close_connection(sock); - - g_strfreev(response); - return TRUE; -} - -static gint -cddb_check_protocol_level(const gchar * server) -{ - gint level = 0, sock, n, ret; - gchar *str, buffer[256]; - - if ((sock = cddb_http_open_connection(server, 80)) == 0) - return 0; - - str = - g_strdup_printf - ("GET /~cddb/cddb.cgi?cmd=stat%s&proto=1 HTTP/1.0\r\n\r\n", - cddb_generate_hello_string()); - - ret = write(sock, str, strlen(str)); - if(ret != strlen(str)){ - g_free(str); - http_close_connection(sock); - return 0; - } - - - g_free(str); - - if ((n = http_read_first_line(sock, buffer, 256)) < 0 || - atoi(buffer) != 210) { - if (n > 0) - cddb_log("Getting cddb protocol level failed: %s", buffer); - else - cddb_log("Getting cddb protocol level failed."); - - http_close_connection(sock); - return 0; - } - - while (http_read_line(sock, buffer, 256) >= 0) { - g_strstrip(buffer); - if (!strncmp(buffer, "max proto:", 10)) - level = atoi(buffer + 10); - if (!strcmp(buffer, ".")) - break; - } - http_close_connection(sock); - cddb_log("Getting cddb protocol level. Got level %d", level); - return (MIN(level, CDDB_MAX_PROTOCOL_LEVEL)); -} - -#define BUF2SIZE (80*3) - -static gboolean -cddb_read(gchar * server, cddb_disc_header_t * cddb_info, cdinfo_t * cdinfo) -{ - gint sock; - gchar *readstr; - gchar buffer[256]; /* http line buffer */ - gchar *discid = NULL, *dartist = NULL, *dtitle = NULL, - *dyear = NULL, *dgenre = NULL, *ttitle = NULL; - gchar *realstr, *temp; - gint len, command; - gint num, oldnum; - gint ret; - - if ((sock = cddb_http_open_connection(server, 80)) == 0) - return FALSE; - - cddb_log("Sending read-command. Disc ID: %08x. Category: %s", - cddb_info->discid, cddb_info->category); - - readstr = - g_strdup_printf - ("GET /~cddb/cddb.cgi?cmd=cddb+read+%s+%08x%s&proto=%d HTTP/1.0\r\n\r\n", - cddb_info->category, cddb_info->discid, - cddb_generate_hello_string(), cdda_cfg.cddb_protocol_level); - cddb_log(readstr); - - ret = write(sock, readstr, strlen(readstr)); - if(ret != strlen(readstr)){ - g_free(readstr); - http_close_connection(sock); - return FALSE; - } - - g_free(readstr); - - if (http_read_first_line(sock, buffer, 256) < 0) { - http_close_connection(sock); - return FALSE; - } - - cddb_log("Read response: %s", buffer); - - command = 1; - oldnum = -1; - do { - realstr = strchr(buffer, '='); - if (buffer[0] == '#' || !realstr) - continue; - - realstr++; - len = strlen(realstr); - - switch (command) { - case 1: - if (!strncmp(buffer, "DISCID", 6)) { - discid = g_strdup(realstr); - break; - } - command++; - case 2: - if (!strncmp(buffer, "DTITLE", 6)) { - if((temp = strstr(buffer, " / ")) != NULL) { - dtitle = g_strdup(temp+3); - dartist = g_strndup(realstr, temp - realstr); - } - else { - dtitle = g_strdup(realstr); - } - break; - } - command++; - case 3: - if (!strncmp(buffer, "DYEAR", 5)) { - dyear = g_strdup(realstr); - break; - } - command++; - case 4: - if (!strncmp(buffer, "DGENRE", 6)) { - dgenre = g_strdup(realstr); - break; - } - - // we have obtained all necessary data to set discinfo - cdda_cdinfo_cd_set(cdinfo, dtitle, dartist, discid, dgenre, dyear); - - command++; - case 5: - if (!strncmp(buffer, "TTITLE", 6)) { - num = atoi(buffer + 6); - if (oldnum < 0 || num == oldnum) { - ttitle = g_strdup(realstr); - } - else { - cdda_cdinfo_track_set(cdinfo, oldnum + 1, NULL, ttitle); - ttitle = g_strdup(realstr); - } - oldnum = num; - break; - } - if (oldnum >= 0) - cdda_cdinfo_track_set(cdinfo, oldnum + 1, NULL, ttitle); - - oldnum = -1; - command++; - case 6: - if (!strncmp(buffer, "EXTD", 4)) { - break; - } - command++; - case 7: - if (!strncmp(buffer, "EXTT", 4)) { - break; - } - command++; - case 8: - if (!strncmp(buffer, "PLAYORDER", 9)) { - break; - } - command++; - default: - g_log(NULL, G_LOG_LEVEL_WARNING, "%s: illegal cddb-data: %s", - PACKAGE_NAME, buffer); - break; - } - - } while (http_read_line(sock, buffer, 256) >= 0); - - if (oldnum >= 0) - cdda_cdinfo_track_set(cdinfo, oldnum + 1, NULL, ttitle); - - http_close_connection(sock); - return TRUE; -} - -static gint -cddb_get_protocol_level(void) -{ - if (cdda_cfg.cddb_protocol_level < 1) - cdda_cfg.cddb_protocol_level = - cddb_check_protocol_level(cdda_cfg.cddb_server); - - return cdda_cfg.cddb_protocol_level; -} - -static GList * -cddb_get_server_list(const gchar * server, gint protocol_level) -{ - gint sock; - gchar *getstr; - gchar buffer[256]; - gchar **message; - GList *list = NULL; - gint ret; - - if ((sock = cddb_http_open_connection(server, 80)) == 0) - return NULL; - - cddb_log("Sending sites-command"); - - getstr = - g_strdup_printf - ("GET /~cddb/cddb.cgi?cmd=sites%s&proto=%d HTTP/1.0\r\n\r\n", - cddb_generate_hello_string(), protocol_level); - cddb_log(getstr); - - ret = write(sock, getstr, strlen(getstr)); - if(ret != strlen(getstr)){ - g_free(getstr); - http_close_connection(sock); - return NULL; - } - g_free(getstr); - - if (http_read_first_line(sock, buffer, 256) < 0) { - http_close_connection(sock); - return NULL; - } - - cddb_log("Sites response: %s", buffer); - - switch (atoi(buffer)) { - case 210: - while ((http_read_line(sock, buffer, 256)) > 1) { - message = g_strsplit(buffer, " ", 6); - if (message && message[0] && message[1] && - !strcasecmp(message[1], "http")) { - list = g_list_prepend(list, message); - } - else { - /* Ignore non-http servers */ - g_strfreev(message); - } - } - list = g_list_reverse(list); - break; - case 401: - /* No site information available */ - break; - default: - break; - } - http_close_connection(sock); - return list; -} - -gint -search_for_discid(gchar * abs_filename, gchar ** cddb_file, guint32 disc_id) -{ - GDir *dir; - const gchar *dir_entry; - gchar tmp_id[10]; - - if (!(dir = g_dir_open(abs_filename, 0, NULL))) - return (0); - - memset(tmp_id, 0, 10); - - snprintf(tmp_id, sizeof(tmp_id), "%08x", disc_id); - while ((dir_entry = g_dir_read_name(dir))) { - if (!strncmp(tmp_id, dir_entry, 8)) { - cddb_file[0] = g_build_filename(abs_filename, dir_entry, NULL); - g_dir_close(dir); - return (1); - } - } - g_dir_close(dir); - - return (0); -} - -gint -scan_cddb_dir(gchar * server, gchar ** cddb_file, guint32 disc_id) -{ - - GDir *dir; - const gchar *dir_entry; - gchar abs_filename[FILENAME_MAX]; - - if (!(dir = g_dir_open(&server[7], 0, NULL))) { - return 0; - } - - while ((dir_entry = g_dir_read_name(dir))) { - strcpy(abs_filename, &server[7]); - if (abs_filename[strlen(abs_filename) - 1] != '/') { - strcat(abs_filename, "/"); - } - strcat(abs_filename, dir_entry); - - if (dir_entry[0] != '.' && - g_file_test(abs_filename, G_FILE_TEST_IS_DIR) && - search_for_discid(abs_filename, cddb_file, disc_id)) { - break; - } - } - - g_dir_close(dir); - return (cddb_file[0] != NULL); -} - -gint -cddb_read_file(gchar * file, cddb_disc_header_t * cddb_info, - cdinfo_t * cdinfo) -{ - FILE *fd; - gchar buffer[256]; - gchar *realstr, *temp; - gchar *discid = NULL, *dartist = NULL, *dtitle = NULL, - *dyear = NULL, *dgenre = NULL, *ttitle = NULL; - gint len, command; - gint num, oldnum; - - if ((fd = fopen(file, "r")) == NULL) - return 0; - - command = 1; - oldnum = -1; - while (fgets(buffer, 256, fd) != NULL) { - realstr = strchr(buffer, '='); - if (buffer[0] == '#' || !realstr) - continue; - - realstr++; - len = strlen(realstr); - if (realstr[len - 1] == '\n') - realstr[--len] = '\0'; /* remove newline */ - - switch (command) { - case 1: - if (!strncmp(buffer, "DISCID", 6)) { - discid = g_strdup(realstr); - break; - } - command++; - case 2: - if (!strncmp(buffer, "DTITLE", 6)) { - if((temp = strstr(buffer, " / ")) != NULL) { - dtitle = g_strdup(temp+3); - dartist = g_strndup(realstr, temp - realstr); - } - else { - dtitle = g_strdup(realstr); - } - break; - } - command++; - case 3: - if (!strncmp(buffer, "DYEAR", 5)) { - dyear = g_strdup(realstr); - break; - } - command++; - case 4: - if (!strncmp(buffer, "DGENRE", 6)) { - dgenre = g_strdup(realstr); - break; - } - - // we have obtained all necessary data to set discinfo - cdda_cdinfo_cd_set(cdinfo, dtitle, dartist, discid, dgenre, dyear); - - command++; - case 5: - if (!strncmp(buffer, "TTITLE", 6)) { - num = atoi(buffer + 6); - if (oldnum < 0 || num == oldnum) { - ttitle = g_strdup(realstr); - } - else { - cdda_cdinfo_track_set(cdinfo, oldnum + 1, NULL, ttitle); - ttitle = g_strdup(realstr); - } - oldnum = num; - break; - } - if (oldnum >= 0) - cdda_cdinfo_track_set(cdinfo, oldnum + 1, NULL, ttitle); - - oldnum = -1; - command++; - case 6: - if (!strncmp(buffer, "EXTD", 4)) { - break; - } - command++; - case 7: - if (!strncmp(buffer, "EXTT", 4)) { - break; - } - command++; - case 8: - if (!strncmp(buffer, "PLAYORDER", 9)) { - break; - } - command++; - default: - g_log(NULL, G_LOG_LEVEL_WARNING, "%s: illegal cddb-data: %s", - PACKAGE_NAME, buffer); - break; - } - - } - - if (oldnum >= 0) - cdda_cdinfo_track_set(cdinfo, oldnum + 1, NULL, ttitle); - - fclose(fd); - return (1); -} - - -void -cdda_cddb_get_info(cdda_disc_toc_t * toc, cdinfo_t * cdinfo) -{ - guint32 disc_id; - cddb_disc_header_t cddb_disc_info; - gchar *cddb_file[1]; - disc_id = cdda_cddb_compute_discid(toc); - cddb_file[0] = NULL; - - if ((cached_id != disc_id) - && (strncmp(cdda_cfg.cddb_server, "file://", 7) != 0)) { - if (cddb_get_protocol_level() == 0) - return; - - cached_id = disc_id; - if (!cddb_query(cdda_cfg.cddb_server, toc, &cddb_disc_info)) - return; - if (!cddb_read(cdda_cfg.cddb_server, &cddb_disc_info, cdinfo)) - return; - cdinfo->is_valid = TRUE; - - } - else if ((cached_id != disc_id) - && (strncmp(cdda_cfg.cddb_server, "file://", 7) == 0)) { - cached_id = disc_id; - if (!scan_cddb_dir(cdda_cfg.cddb_server, cddb_file, disc_id)) - return; - if (!cddb_read_file(cddb_file[0], &cddb_disc_info, cdinfo)) { - g_free(cddb_file[0]); - return; - } - cdinfo->is_valid = TRUE; - g_free(cddb_file[0]); - } -} - -void -cdda_cddb_set_server(const gchar * new_server) -{ - if (strcmp(cdda_cfg.cddb_server, new_server)) { - g_free(cdda_cfg.cddb_server); - cdda_cfg.cddb_server = g_strdup(new_server); - cdda_cfg.cddb_protocol_level = 0; - cached_id = 0; - } -} - - -static gchar * -cddb_position_string(gchar * input) -{ - gchar deg[4], min[3]; - if (input == NULL || strlen(input) < 7) - return g_strdup(""); - strncpy(deg, input + 1, 3); - deg[3] = '\0'; - strncpy(min, input + 5, 2); - min[2] = '\0'; - return g_strdup_printf("%2d°%s'%c", atoi(deg), min, input[0]); -} - -static void -cddb_server_dialog_ok_cb(GtkWidget * w, gpointer data) -{ - gchar *text; - gint pos; - GtkEntry *entry = GTK_ENTRY(data); - - if (!GTK_CLIST(server_clist)->selection) - return; - pos = GPOINTER_TO_INT(GTK_CLIST(server_clist)->selection->data); - gtk_clist_get_text(GTK_CLIST(server_clist), pos, 0, &text); - cdda_cddb_set_server(text); - gtk_entry_set_text(entry, text); - gtk_widget_destroy(server_dialog); -} - -static void -cddb_server_dialog_select(GtkWidget * w, gint row, gint column, - GdkEvent * event, gpointer data) -{ - if (event->type == GDK_2BUTTON_PRESS) - cddb_server_dialog_ok_cb(NULL, NULL); -} - -void -cdda_cddb_show_server_dialog(GtkWidget * w, gpointer data) -{ - GtkWidget *vbox, *bbox, *okbutton, *cancelbutton; - GtkEntry *server_entry = GTK_ENTRY(data); - gchar *titles[] = { "Server", "Latitude", "Longitude", "Description" }; - GList *servers; - const gchar *server; - gint level; - - if (server_dialog) - return; - - server = gtk_entry_get_text(server_entry); - - if ((level = cddb_check_protocol_level(server)) < 3) { - if (!level) - xmms_show_message("CDDB", - "Unable to connect to CDDB-server", - "Ok", FALSE, NULL, NULL); - else - /* CDDB level < 3 has the "sites" command, - but the format is different. Not supported yet */ - xmms_show_message("CDDB", - "Can't get server list from the current CDDB-server\n" - "Unsupported CDDB protocol level", - "Ok", FALSE, NULL, NULL); - return; - } - - if ((servers = cddb_get_server_list(server, level)) == NULL) { - xmms_show_message("CDDB", - "No site information available", - "Ok", FALSE, NULL, NULL); - return; - } - - server_dialog = gtk_dialog_new(); - g_signal_connect(G_OBJECT(server_dialog), "destroy", - G_CALLBACK(gtk_widget_destroyed), &server_dialog); - gtk_window_set_title(GTK_WINDOW(server_dialog), "CDDB servers"); - gtk_window_set_modal(GTK_WINDOW(server_dialog), TRUE); - - vbox = gtk_vbox_new(FALSE, 0); - gtk_container_set_border_width(GTK_CONTAINER(vbox), 15); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(server_dialog)->vbox), vbox, - TRUE, TRUE, 0); - - server_clist = gtk_clist_new_with_titles(4, titles); - g_signal_connect(G_OBJECT(server_clist), "select-row", - G_CALLBACK(cddb_server_dialog_select), NULL); - gtk_box_pack_start(GTK_BOX(vbox), server_clist, TRUE, TRUE, 0); - - bbox = gtk_hbutton_box_new(); - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); - gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(server_dialog)->action_area), - bbox, TRUE, TRUE, 0); - - okbutton = gtk_button_new_with_label("Ok"); - g_signal_connect(G_OBJECT(okbutton), "clicked", - G_CALLBACK(cddb_server_dialog_ok_cb), data); - gtk_box_pack_start(GTK_BOX(bbox), okbutton, TRUE, TRUE, 0); - cancelbutton = gtk_button_new_with_label("Cancel"); - g_signal_connect_swapped(G_OBJECT(cancelbutton), "clicked", - G_CALLBACK(gtk_widget_destroy), - GTK_OBJECT(server_dialog)); - gtk_box_pack_start(GTK_BOX(bbox), cancelbutton, TRUE, TRUE, 0); - GTK_WIDGET_SET_FLAGS(okbutton, GTK_CAN_DEFAULT); - GTK_WIDGET_SET_FLAGS(cancelbutton, GTK_CAN_DEFAULT); - gtk_widget_grab_default(okbutton); - - while (servers) { - gchar *row[4]; - gint i; - - row[0] = g_strdup(((gchar **) servers->data)[0]); - row[1] = cddb_position_string(((gchar **) servers->data)[4]); - row[2] = cddb_position_string(((gchar **) servers->data)[5]); - row[3] = g_strdup(((gchar **) servers->data)[6]); - gtk_clist_append(GTK_CLIST(server_clist), row); - for (i = 0; i < 4; i++) - g_free(row[i]); - g_strfreev(servers->data); - servers = g_list_next(servers); - } - g_list_free(servers); - gtk_clist_columns_autosize(GTK_CLIST(server_clist)); - gtk_widget_show_all(server_dialog); -} - -static gboolean -cddb_update_log_window(gpointer data) -{ - if (!debug_window) { - cddb_timeout_id = 0; - return FALSE; - } - - G_LOCK(list); - if (temp_messages != NULL) { - GList *temp; - GDK_THREADS_ENTER(); - gtk_clist_freeze(GTK_CLIST(debug_clist)); - for (temp = temp_messages; temp; temp = temp->next) { - gchar *text = temp->data; - gtk_clist_append(GTK_CLIST(debug_clist), &text); - g_free(text); - } - gtk_clist_columns_autosize(GTK_CLIST(debug_clist)); - gtk_clist_thaw(GTK_CLIST(debug_clist)); - gtk_clist_moveto(GTK_CLIST(debug_clist), - GTK_CLIST(debug_clist)->rows - 1, -1, 0.5, 0); - GDK_THREADS_LEAVE(); - g_list_free(temp_messages); - temp_messages = NULL; - } - G_UNLOCK(list); - return TRUE; -} - - -void -cdda_cddb_show_network_window(GtkWidget * w, gpointer data) -{ - GtkWidget *vbox, *bbox, *close, *scroll_win; - GList *temp; - - if (debug_window) - return; - - debug_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - g_signal_connect(G_OBJECT(debug_window), "destroy", - G_CALLBACK(gtk_widget_destroyed), &debug_window); - gtk_window_set_title(GTK_WINDOW(debug_window), "CDDB networkdebug"); - gtk_window_set_resizable(GTK_WINDOW(debug_window), TRUE); - gtk_window_set_default_size(GTK_WINDOW(debug_window), 400, 150); - gtk_container_border_width(GTK_CONTAINER(debug_window), 10); - - vbox = gtk_vbox_new(FALSE, 10); - gtk_container_add(GTK_CONTAINER(debug_window), vbox); - - scroll_win = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_win), - GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); - debug_clist = gtk_clist_new(1); - gtk_container_add(GTK_CONTAINER(scroll_win), debug_clist); - gtk_box_pack_start(GTK_BOX(vbox), scroll_win, TRUE, TRUE, 0); - - temp = debug_messages; - while (temp) { - gtk_clist_prepend(GTK_CLIST(debug_clist), (gchar **) & temp->data); - temp = g_list_next(temp); - } - - bbox = gtk_hbutton_box_new(); - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_SPREAD); - gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); - gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); - - close = gtk_button_new_with_label("Close"); - g_signal_connect_swapped(G_OBJECT(close), "clicked", - G_CALLBACK(gtk_widget_destroy), - GTK_OBJECT(debug_window)); - GTK_WIDGET_SET_FLAGS(close, GTK_CAN_DEFAULT); - gtk_box_pack_start(GTK_BOX(bbox), close, TRUE, TRUE, 0); - gtk_widget_grab_default(close); - - gtk_clist_columns_autosize(GTK_CLIST(debug_clist)); - gtk_clist_set_button_actions(GTK_CLIST(debug_clist), 0, - GTK_BUTTON_IGNORED); - gtk_clist_moveto(GTK_CLIST(debug_clist), - GTK_CLIST(debug_clist)->rows - 1, -1, 0, 0); - - cddb_timeout_id = gtk_timeout_add(500, cddb_update_log_window, NULL); - gtk_widget_show_all(debug_window); -} - -void -cddb_quit(void) -{ - if (cddb_timeout_id) - gtk_timeout_remove(cddb_timeout_id); - cddb_timeout_id = 0; -}
--- a/src/cdaudio/cddb.h Wed Jul 25 16:48:53 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - * cddb.h Copyright 1999 Håvard Kvålen <havardk@sol.no> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -#ifndef CDDB_H -#define CDDB_H - -#include <glib.h> - -typedef struct { - gchar *category; - guint32 discid; -} cddb_disc_header_t; - -#define CDDB_MAX_PROTOCOL_LEVEL 6 -#define CDDB_HOSTNAME_LEN 100 -#define CDDB_LOG_MAX 100 - -#endif
--- a/src/cdaudio/cdinfo.c Wed Jul 25 16:48:53 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,286 +0,0 @@ -/* - * cdinfo.c Copyright 1999 Espen Skoglund <esk@ira.uka.de> - * Copyright 1999 Håvard Kvålen <havardk@sol.no> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "cdinfo.h" -#include "cdaudio.h" - -#include <glib.h> -#include <audacious/i18n.h> -#include <audacious/rcfile.h> - -#include <stdlib.h> - - -/* - * Function cdda_cdinfo_flush (cdinfo) - * - * Free all information stored about the CD. - * - */ -void -cdda_cdinfo_flush(cdinfo_t * cdinfo) -{ - trackinfo_t *t; - gint i; - - if (cdinfo->albname) - g_free(cdinfo->albname); - if (cdinfo->artname) - g_free(cdinfo->artname); - - cdinfo->albname = cdinfo->artname = NULL; - - for (t = cdinfo->tracks, i = 0; i < 100; i++, t++) { - if (t->artist) - g_free(t->artist); - if (t->title) - g_free(t->title); - - t->artist = t->title = NULL; - t->num = -1; - } - cdinfo->is_valid = FALSE; -} - - -/* - * Function cdda_cdinfo_delete (cdinfo) - * - * Free the indicated `cdinfo' structure. - * - */ -void -cdda_cdinfo_delete(cdinfo_t * cdinfo) -{ - cdda_cdinfo_flush(cdinfo); - g_free(cdinfo); -} - - -/* - * Function cdda_cdinfo_new () - * - * Allocate a new `cdinfo' structure and return it. - * - */ -cdinfo_t * -cdda_cdinfo_new(void) -{ - cdinfo_t *ret; - ret = g_malloc0(sizeof(cdinfo_t)); - cdda_cdinfo_flush(ret); - - return ret; -} - - -/* - * Function cdda_cdinfo_track_set (cdinfo, num, artist, title) - * - * Set `artist', and `title' for a track `num'. If the CD is a - * singleartist disc, the `artist' on each track should be set to - * NULL. - * - */ -void -cdda_cdinfo_track_set(cdinfo_t * cdinfo, gint num, gchar * artist, - gchar * title) -{ - trackinfo_t *track = cdinfo->tracks + num; - - /* Check bounds */ - if (num < 1 || num >= 100) - return; - - track->artist = artist; - track->title = title; - track->num = num; - cdinfo->is_valid = TRUE; -} - - -/* - * Function cdda_cdinfo_cd_set (cdinfo, cdname, cdartist, discid, - * genre, year) - * - * Set name, artist, discid, genre and year for a cd. If CD is a - * multiartist disc, the `artist' should be set to NULL. - * - */ -void -cdda_cdinfo_cd_set(cdinfo_t * cdinfo, gchar * cdname, gchar * cdartist, - gchar * discid, gchar * genre, gchar *year) -{ - cdinfo->is_valid = TRUE; - cdinfo->albname = cdname; - cdinfo->artname = cdartist; - cdinfo->discid = discid ? atoi(discid) : 0; - cdinfo->genre = genre; - cdinfo->year = year ? atoi(year) : 0; -} - - -/* - * Function cdda_cdinfo_get (cdinfo, num, artist, album, title) - * - * Get artist, album, and title of the indicated track (i.e. store - * them in the specified pointers). Return 0 upon success, or -1 - * of track did not exist. The returned name must be subsequently - * freed using g_free(). - * - */ -gint -cdda_cdinfo_get(cdinfo_t * cdinfo, gint num, gchar ** artist, - gchar ** album, gchar ** title) -{ - trackinfo_t *track = cdinfo->tracks + num; - - /* Check validity */ - if (!cdinfo->is_valid || num < 1 || num >= 100) - return -1; - - *artist = track->artist ? track->artist : - cdinfo->artname ? cdinfo->artname : _("(unknown)"); - *album = cdinfo->albname ? cdinfo->albname : _("(unknown)"); - *title = track->title ? track->title : _("(unknown)"); - - return track->num == -1 ? -1 : 0; -} - - -/* - * Function cdda_cdinfo_write_file - * - * Writes the cdinfo_t structure to disk. - */ - - -void -cdda_cdinfo_write_file(guint32 cddb_discid, cdinfo_t * cdinfo) -{ - gchar *filename; - RcFile *rcfile; - gchar sectionname[10], trackstr[16]; - gint i, numtracks = cddb_discid & 0xff; - - sprintf(sectionname, "%08x", cddb_discid); - - filename = - g_strconcat(g_get_home_dir(), "/", BMP_RCPATH, "/cdinfo", NULL); - if ((rcfile = bmp_rcfile_open(filename)) == NULL) - rcfile = bmp_rcfile_new(); - - if (cdinfo->albname) - bmp_rcfile_write_string(rcfile, sectionname, "Albumname", - cdinfo->albname); - else - bmp_rcfile_write_string(rcfile, sectionname, "Albumname", ""); - - if (cdinfo->artname) - bmp_rcfile_write_string(rcfile, sectionname, "Artistname", - cdinfo->artname); - if (cdinfo->year) { - gchar *yearstr = g_strdup_printf("%4d", cdinfo->year); - bmp_rcfile_write_string(rcfile, sectionname, "Year", yearstr); - g_free(yearstr); - } - - if (cdinfo->genre) - bmp_rcfile_write_string(rcfile, sectionname, "Genre", cdinfo->genre); - - - for (i = 1; i <= numtracks; i++) { - if (cdinfo->tracks[i].artist) { - sprintf(trackstr, "track_artist%d", i); - bmp_rcfile_write_string(rcfile, sectionname, trackstr, - cdinfo->tracks[i].artist); - } - if (cdinfo->tracks[i].title) { - sprintf(trackstr, "track_title%d", i); - bmp_rcfile_write_string(rcfile, sectionname, trackstr, - cdinfo->tracks[i].title); - } - } - bmp_rcfile_write(rcfile, filename); - bmp_rcfile_free(rcfile); - g_free(filename); -} - -/* - * Function cdda_cdinfo_read_file - * - * Tries to find and read a album from the disk-cache. - * - * Returns true if the album is found. - */ - -gboolean -cdda_cdinfo_read_file(guint32 cddb_discid, cdinfo_t * cdinfo) -{ - gchar *filename; - RcFile *rcfile; - gchar sectionname[10], trackstr[16]; - gint i, numtracks = cddb_discid & 0xff; - gboolean track_found; - gchar *yearstr = NULL; - - sprintf(sectionname, "%08x", cddb_discid); - - filename = - g_strconcat(g_get_home_dir(), "/", BMP_RCPATH, "/cdinfo", NULL); - if ((rcfile = bmp_rcfile_open(filename)) == NULL) { - g_free(filename); - return FALSE; - } - g_free(filename); - - if (!bmp_rcfile_read_string - (rcfile, sectionname, "Albumname", &cdinfo->albname)) - return FALSE; - - bmp_rcfile_read_string(rcfile, sectionname, "Artistname", - &cdinfo->artname); - - bmp_rcfile_read_string(rcfile, sectionname, "Year", &yearstr); - if (yearstr) { - cdinfo->year = atoi(yearstr); - g_free(yearstr); - yearstr = NULL; - } - - bmp_rcfile_read_string(rcfile, sectionname, "Genre", &cdinfo->genre); - - for (i = 1; i <= numtracks; i++) { - track_found = FALSE; - sprintf(trackstr, "track_artist%d", i); - if (bmp_rcfile_read_string - (rcfile, sectionname, trackstr, &cdinfo->tracks[i].artist)) - track_found = TRUE; - sprintf(trackstr, "track_title%d", i); - if (bmp_rcfile_read_string - (rcfile, sectionname, trackstr, &cdinfo->tracks[i].title)) - track_found = TRUE; - if (track_found) - cdinfo->tracks[i].num = i; - } - cdinfo->is_valid = TRUE; - bmp_rcfile_free(rcfile); - return TRUE; -}
--- a/src/cdaudio/cdinfo.h Wed Jul 25 16:48:53 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/* - * cdinfo.h Copyright 1999 Espen Skoglund <esk@ira.uka.de> - * Copyright 1999 Håvard Kvålen <havardk@sol.no> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#ifndef CDINFO_H -#define CDINFO_H - -#include <glib.h> - -/* - * For holding info on a single CD track. - */ -typedef struct { - gchar *artist; - gchar *title; - gint num; -} trackinfo_t; - -/* - * For holding info on a complete CD. - */ -typedef struct { - gboolean is_valid; - gint discid; - gchar *albname; - gchar *artname; - gchar *genre; - gint year; - trackinfo_t tracks[100]; -} cdinfo_t; - -void cdda_cdinfo_flush(cdinfo_t * cdinfo); -cdinfo_t *cdda_cdinfo_new(void); -void cdda_cdinfo_delete(cdinfo_t * info); -void cdda_cdinfo_track_set(cdinfo_t * cdinfo, gint, gchar *, gchar *); -void cdda_cdinfo_cd_set(cdinfo_t * cdinfo, gchar *, gchar *, gchar *, gchar *, gchar *); -gint cdda_cdinfo_get(cdinfo_t * cdinfo, gint num, gchar **, gchar **, gchar **); -gboolean cdda_cdinfo_read_file(guint32 cddb_discid, cdinfo_t * cdinfo); -void cdda_cdinfo_write_file(guint32 cddb_discid, cdinfo_t * cdinfo); - - -#endif
--- a/src/cdaudio/configure.c Wed Jul 25 16:48:53 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,658 +0,0 @@ -/* BMP - Cross-platform multimedia player - * Copyright (C) 2003-2004 BMP development team. - * - * Based on XMMS: - * Copyright (C) 1998-2003 XMMS development team. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "cdaudio.h" - -#include <glib.h> -#include <audacious/i18n.h> -#include <glib/gprintf.h> -#include <string.h> - -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <sys/stat.h> - -#include <audacious/configdb.h> -#include <audacious/titlestring.h> - - -#define GET_TB(b) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b)) -#define SET_TB(b) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b), TRUE) - -struct driveconfig { - GtkWidget *device, *directory; - GtkWidget *mixer_oss, *mixer_drive; - GtkWidget *remove_button; - GtkWidget *dae; -}; - -static GList *drives; - -static GtkWidget *cdda_configure_win; -static GtkWidget *cdi_name, *cdi_name_override; -static GtkWidget *cdi_use_cddb, *cdi_cddb_server; - -void cdda_cddb_show_server_dialog(GtkWidget * w, gpointer data); -void cdda_cddb_show_network_window(GtkWidget * w, gpointer data); -void cdda_cddb_set_server(const char *new_server); - -static GtkWidget *configurewin_add_drive(struct driveinfo *drive, - gpointer nb); - -static void -cdda_configurewin_ok_cb(GtkWidget * w, gpointer data) -{ - ConfigDb *db; - struct driveinfo *drive; - GList *node; - gint olddrives, ndrives, i; - - olddrives = g_list_length(cdda_cfg.drives); - for (node = cdda_cfg.drives; node; node = node->next) { - drive = node->data; - g_free(drive->device); - g_free(drive->directory); - g_free(drive); - } - g_list_free(cdda_cfg.drives); - cdda_cfg.drives = NULL; - - for (node = drives; node; node = node->next) { - struct driveconfig *config = node->data; - const gchar *tmp; - - drive = g_new0(struct driveinfo, 1); - drive->device = - g_strdup(gtk_entry_get_text(GTK_ENTRY(config->device))); - - tmp = gtk_entry_get_text(GTK_ENTRY(config->directory)); -// if (strlen(tmp) < 2 || tmp[strlen(tmp) - 1] == '/') - drive->directory = g_strdup(tmp); -// else -// drive->directory = g_strconcat(tmp, "/", NULL); - -// drive->directory = "CD_AUDIO"; - - if (GET_TB(config->mixer_oss)) - drive->mixer = CDDA_MIXER_OSS; - else if (GET_TB(config->mixer_drive)) - drive->mixer = CDDA_MIXER_DRIVE; - else - drive->mixer = CDDA_MIXER_NONE; - if (GET_TB(config->dae)) - drive->dae = CDDA_READ_DAE; - else - drive->dae = CDDA_READ_ANALOG; - - cdda_cfg.drives = g_list_append(cdda_cfg.drives, drive); - } - - cdda_cfg.title_override = GET_TB(cdi_name_override); - g_free(cdda_cfg.name_format); - cdda_cfg.name_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(cdi_name))); - - cdda_cfg.use_cddb = GET_TB(cdi_use_cddb); - cdda_cddb_set_server(gtk_entry_get_text(GTK_ENTRY(cdi_cddb_server))); - - db = bmp_cfg_db_open(); - - drive = cdda_cfg.drives->data; - bmp_cfg_db_set_string(db, "CDDA", "device", drive->device); - bmp_cfg_db_set_string(db, "CDDA", "directory", drive->directory); - bmp_cfg_db_set_int(db, "CDDA", "mixer", drive->mixer); - bmp_cfg_db_set_int(db, "CDDA", "readmode", drive->dae); - -/* bmp_cfg_db_set_bool(db, "CDDA", "use_oss_mixer", cdda_cfg.use_oss_mixer); */ - - for (node = cdda_cfg.drives->next, i = 1; node; node = node->next, i++) { - char label[20]; - drive = node->data; - - sprintf(label, "device%d", i); - bmp_cfg_db_set_string(db, "CDDA", label, drive->device); - - sprintf(label, "directory%d", i); - bmp_cfg_db_set_string(db, "CDDA", label, drive->directory); - - sprintf(label, "mixer%d", i); - bmp_cfg_db_set_int(db, "CDDA", label, drive->mixer); - - sprintf(label, "readmode%d", i); - bmp_cfg_db_set_int(db, "CDDA", label, drive->dae); - } - - ndrives = g_list_length(cdda_cfg.drives); - - for (i = ndrives; i < olddrives; i++) - /* FIXME: Clear old entries */ ; - - bmp_cfg_db_set_int(db, "CDDA", "num_drives", ndrives); - - bmp_cfg_db_set_bool(db, "CDDA", "title_override", - cdda_cfg.title_override); - bmp_cfg_db_set_string(db, "CDDA", "name_format", cdda_cfg.name_format); - bmp_cfg_db_set_bool(db, "CDDA", "use_cddb", cdda_cfg.use_cddb); - bmp_cfg_db_set_string(db, "CDDA", "cddb_server", cdda_cfg.cddb_server); - bmp_cfg_db_set_int(db, "CDDA", "cddb_protocol_level", - cdda_cfg.cddb_protocol_level); - bmp_cfg_db_close(db); -} - -static void -configurewin_close(GtkButton * w, gpointer data) -{ - GList *node; - - for (node = drives; node; node = node->next) - g_free(node->data); - g_list_free(drives); - drives = NULL; - - gtk_widget_destroy(cdda_configure_win); -} - -static void -toggle_set_sensitive_cb(GtkToggleButton * w, gpointer data) -{ - gboolean set = gtk_toggle_button_get_active(w); - gtk_widget_set_sensitive(GTK_WIDGET(data), set); -} - -static void -configurewin_add_page(GtkButton * w, gpointer data) -{ - GtkNotebook *nb = GTK_NOTEBOOK(data); - GtkWidget *box = configurewin_add_drive(NULL, nb); - gchar *label = g_strdup_printf(_("Drive %d"), g_list_length(drives)); - - gtk_widget_show_all(box); - gtk_notebook_append_page(GTK_NOTEBOOK(nb), box, gtk_label_new(label)); - g_free(label); -} - -static void -redo_nb_labels(GtkNotebook * nb) -{ - gint i; - GtkWidget *child; - - for (i = 0; (child = gtk_notebook_get_nth_page(nb, i)) != NULL; i++) { - gchar *label = g_strdup_printf(_("Drive %d"), i + 1); - - gtk_notebook_set_tab_label_text(nb, child, label); - g_free(label); - } -} - - -static void -configurewin_remove_page(GtkButton * w, gpointer data) -{ - GList *node; - GtkNotebook *nb = GTK_NOTEBOOK(data); - gtk_notebook_remove_page(nb, gtk_notebook_get_current_page(nb)); - for (node = drives; node; node = node->next) { - struct driveconfig *drive = node->data; - - if (GTK_WIDGET(w) == drive->remove_button) { - if (node->next) - redo_nb_labels(nb); - drives = g_list_remove(drives, drive); - g_free(drive); - break; - } - } - if (g_list_length(drives) == 1) { - struct driveconfig *drive = drives->data; - gtk_widget_set_sensitive(drive->remove_button, FALSE); - } -} - - -static void -configurewin_check_drive(GtkButton * w, gpointer data) -{ - struct driveconfig *drive = data; - GtkWidget *window, *vbox, *label, *bbox, *closeb; - const gchar *device, *directory; - gint fd, dae_track = -1; - GString *str = g_string_new(""); - struct stat stbuf; - - device = gtk_entry_get_text(GTK_ENTRY(drive->device)); - directory = gtk_entry_get_text(GTK_ENTRY(drive->directory)); - - if ((fd = open(device, CDOPENFLAGS) < 0)) - g_string_sprintfa(str, _("Failed to open device %s\n" - "Error: %s\n\n"), device, strerror(errno)); - else { - cdda_disc_toc_t toc; - close(fd); - if (!cdda_get_toc(&toc, device)) - g_string_append(str, - _("Failed to read \"Table of Contents\"" - "\nMaybe no disc in the drive?\n\n")); - else { - gint i, data = 0; - g_string_sprintfa(str, _("Device %s OK.\n" - "Disc has %d tracks"), device, - toc.last_track - toc.first_track + 1); - for (i = toc.first_track; i <= toc.last_track; i++) - if (toc.track[i].flags.data_track) - data++; - else if (dae_track < 0) - dae_track = i; - if (data > 0) - g_string_sprintfa(str, _(" (%d data tracks)"), data); - g_string_sprintfa(str, _("\nTotal length: %d:%d\n"), - toc.leadout.minute, toc.leadout.second); -#ifdef CDDA_HAS_READAUDIO - if (dae_track == -1) - g_string_sprintfa(str, - _("Digital audio extraction " - "not tested as the disc has " - "no audio tracks\n")); - else { - gint fd = open(device, CDOPENFLAGS); - gint start, end, fr; - gchar buffer[CD_FRAMESIZE_RAW]; - start = LBA(toc.track[dae_track]); - - if (dae_track == toc.last_track) - end = LBA(toc.leadout); - else - end = LBA(toc.track[dae_track + 1]); - fr = read_audio_data(fd, start + (end - start) / 2, - 1, buffer); - if (fr > 0) - g_string_sprintfa(str, - _("Digital audio extraction " - "test: OK\n\n")); - else - g_string_sprintfa(str, - _("Digital audio extraction " - "test failed: %s\n\n"), - strerror(-fr)); - } -#else - g_string_sprintfa(str, "\n"); -#endif - } - } - if (stat(directory, &stbuf) < 0) { - g_string_sprintfa(str, _("Failed to check directory %s\n" - "Error: %s"), directory, strerror(errno)); - } - else { - if (!S_ISDIR(stbuf.st_mode)) - g_string_sprintfa(str, - _("Error: %s exist, but is not a directory"), - directory); - else - g_string_sprintfa(str, _("Directory %s OK."), directory); - } - - - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_transient_for(GTK_WINDOW(window), - GTK_WINDOW(cdda_configure_win)); - gtk_container_set_border_width(GTK_CONTAINER(window), 10); - vbox = gtk_vbox_new(FALSE, 10); - gtk_container_add(GTK_CONTAINER(window), vbox); - label = gtk_label_new(str->str); - gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); - gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); - - bbox = gtk_hbutton_box_new(); - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_SPREAD); - gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); - gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); - - closeb = gtk_button_new_from_stock(GTK_STOCK_CLOSE); - GTK_WIDGET_SET_FLAGS(closeb, GTK_CAN_DEFAULT); - g_signal_connect_swapped(G_OBJECT(closeb), "clicked", - G_CALLBACK(gtk_widget_destroy), - GTK_OBJECT(window)); - gtk_box_pack_start(GTK_BOX(bbox), closeb, TRUE, TRUE, 0); - gtk_widget_grab_default(closeb); - - g_string_free(str, TRUE); - - gtk_widget_show_all(window); -} - -static GtkWidget * -configurewin_add_drive(struct driveinfo *drive, gpointer nb) -{ - GtkWidget *vbox, *bbox, *dev_frame, *dev_table, *dev_label; - GtkWidget *dev_dir_label, *check_btn; - GtkWidget *volume_frame, *volume_box, *volume_none; - GtkWidget *readmode_frame, *readmode_box, *readmode_analog; - struct driveconfig *d = g_new0(struct driveconfig, 1); - - vbox = gtk_vbox_new(FALSE, 5); - gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); - - dev_frame = gtk_frame_new(_("Device:")); - gtk_box_pack_start(GTK_BOX(vbox), dev_frame, FALSE, FALSE, 0); - dev_table = gtk_table_new(2, 2, FALSE); - gtk_container_set_border_width(GTK_CONTAINER(dev_table), 5); - gtk_container_add(GTK_CONTAINER(dev_frame), dev_table); - gtk_table_set_row_spacings(GTK_TABLE(dev_table), 5); - gtk_table_set_col_spacings(GTK_TABLE(dev_table), 5); - - dev_label = gtk_label_new_with_mnemonic(_("_Device:")); - gtk_misc_set_alignment(GTK_MISC(dev_label), 1.0, 0.5); - gtk_table_attach(GTK_TABLE(dev_table), dev_label, 0, 1, 0, 1, - GTK_FILL, 0, 0, 0); - - d->device = gtk_entry_new(); - gtk_label_set_mnemonic_widget(GTK_LABEL(dev_label), d->device); - gtk_table_attach(GTK_TABLE(dev_table), d->device, 1, 2, 0, 1, - GTK_FILL | GTK_EXPAND, 0, 0, 0); - - dev_dir_label = gtk_label_new_with_mnemonic(_("Dir_ectory:")); - gtk_misc_set_alignment(GTK_MISC(dev_dir_label), 1.0, 0.5); - gtk_table_attach(GTK_TABLE(dev_table), dev_dir_label, 0, 1, 1, 2, - GTK_FILL, 0, 0, 0); - - - d->directory = gtk_entry_new(); - gtk_label_set_mnemonic_widget(GTK_LABEL(dev_dir_label), d->directory); - gtk_table_attach(GTK_TABLE(dev_table), d->directory, 1, 2, 1, 2, - GTK_FILL | GTK_EXPAND, 0, 0, 0); - - - readmode_frame = gtk_frame_new(_("Play mode:")); - gtk_box_pack_start(GTK_BOX(vbox), readmode_frame, FALSE, FALSE, 0); - - readmode_box = gtk_vbox_new(5, FALSE); - gtk_container_add(GTK_CONTAINER(readmode_frame), readmode_box); - - readmode_analog = gtk_radio_button_new_with_label(NULL, _("Analog")); - gtk_box_pack_start(GTK_BOX(readmode_box), readmode_analog, FALSE, - FALSE, 0); - - d->dae = - gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON - (readmode_analog), - _ - ("Digital audio extraction")); - gtk_box_pack_start(GTK_BOX(readmode_box), d->dae, FALSE, FALSE, 0); -#ifndef CDDA_HAS_READAUDIO - gtk_widget_set_sensitive(readmode_frame, FALSE); -#endif - - /* - * Volume config - */ - - volume_frame = gtk_frame_new(_("Volume control:")); - gtk_box_pack_start(GTK_BOX(vbox), volume_frame, FALSE, FALSE, 0); - - volume_box = gtk_vbox_new(5, FALSE); - gtk_container_add(GTK_CONTAINER(volume_frame), volume_box); - - volume_none = gtk_radio_button_new_with_label(NULL, _("No mixer")); - gtk_box_pack_start(GTK_BOX(volume_box), volume_none, FALSE, FALSE, 0); - - d->mixer_drive = - gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON - (volume_none), - _("CDROM drive")); - gtk_box_pack_start(GTK_BOX(volume_box), d->mixer_drive, FALSE, FALSE, 0); - - d->mixer_oss = - gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON - (volume_none), - _("OSS mixer")); - gtk_box_pack_start(GTK_BOX(volume_box), d->mixer_oss, FALSE, FALSE, 0); - - g_signal_connect(G_OBJECT(readmode_analog), "toggled", - G_CALLBACK(toggle_set_sensitive_cb), volume_frame); -#ifndef HAVE_OSS - gtk_widget_set_sensitive(d->mixer_oss, FALSE); -#endif - if (drive) { - gtk_entry_set_text(GTK_ENTRY(d->device), drive->device); - gtk_entry_set_text(GTK_ENTRY(d->directory), drive->directory); - if (drive->mixer == CDDA_MIXER_DRIVE) - SET_TB(d->mixer_drive); - else if (drive->mixer == CDDA_MIXER_OSS) - SET_TB(d->mixer_oss); - if (drive->dae == CDDA_READ_DAE) - SET_TB(d->dae); - } - - bbox = gtk_hbutton_box_new(); - gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_SPREAD); - - check_btn = gtk_button_new_with_label(_("Check drive...")); - GTK_WIDGET_SET_FLAGS(check_btn, GTK_CAN_DEFAULT); - gtk_box_pack_start_defaults(GTK_BOX(bbox), check_btn); - g_signal_connect(G_OBJECT(check_btn), "clicked", - G_CALLBACK(configurewin_check_drive), d); - - d->remove_button = gtk_button_new_with_label(_("Remove drive")); - GTK_WIDGET_SET_FLAGS(d->remove_button, GTK_CAN_DEFAULT); - gtk_box_pack_start_defaults(GTK_BOX(bbox), d->remove_button); - g_signal_connect(G_OBJECT(d->remove_button), "clicked", - G_CALLBACK(configurewin_remove_page), nb); - - - if (drives == NULL) - gtk_widget_set_sensitive(d->remove_button, FALSE); - else { - struct driveconfig *tmp = drives->data; - gtk_widget_set_sensitive(tmp->remove_button, TRUE); - } - - drives = g_list_append(drives, d); - - return vbox; -} - -void -cdda_configure(void) -{ - GtkWidget *vbox, *notebook; - GtkWidget *dev_vbox, *dev_notebook, *add_drive, *add_bbox; - GtkWidget *cdi_vbox; - GtkWidget *cdi_cddb_frame, *cdi_cddb_vbox, *cdi_cddb_hbox; - GtkWidget *cdi_cddb_server_hbox, *cdi_cddb_server_label; - GtkWidget *cdi_cddb_server_list, *cdi_cddb_debug_win; - GtkWidget *cdi_name_frame, *cdi_name_vbox, *cdi_name_hbox; - GtkWidget *cdi_name_label, *cdi_desc; - GtkWidget *cdi_name_enable_vbox; - GtkWidget *bbox, *ok, *cancel; - - GList *node; - gint i = 1; - - if (cdda_configure_win) - return; - - cdda_configure_win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - g_signal_connect(G_OBJECT(cdda_configure_win), "destroy", - G_CALLBACK(gtk_widget_destroyed), &cdda_configure_win); - gtk_window_set_title(GTK_WINDOW(cdda_configure_win), - _("CD Audio Player Configuration")); - gtk_window_set_type_hint(GTK_WINDOW(cdda_configure_win), - GDK_WINDOW_TYPE_HINT_DIALOG); - gtk_window_set_resizable(GTK_WINDOW(cdda_configure_win), FALSE); - gtk_window_set_position(GTK_WINDOW(cdda_configure_win), - GTK_WIN_POS_MOUSE); - gtk_container_border_width(GTK_CONTAINER(cdda_configure_win), 10); - - vbox = gtk_vbox_new(FALSE, 10); - gtk_container_add(GTK_CONTAINER(cdda_configure_win), vbox); - - notebook = gtk_notebook_new(); - gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0); - - /* - * Device config - */ - dev_vbox = gtk_vbox_new(FALSE, 5); - gtk_container_set_border_width(GTK_CONTAINER(dev_vbox), 5); - - dev_notebook = gtk_notebook_new(); - gtk_notebook_set_scrollable(GTK_NOTEBOOK(dev_notebook), TRUE); - gtk_box_pack_start(GTK_BOX(dev_vbox), dev_notebook, FALSE, FALSE, 0); - - for (node = cdda_cfg.drives; node; node = node->next) { - struct driveinfo *drive = node->data; - gchar *label = g_strdup_printf(_("Drive %d"), i++); - GtkWidget *w; - - w = configurewin_add_drive(drive, dev_notebook); - gtk_notebook_append_page(GTK_NOTEBOOK(dev_notebook), w, - gtk_label_new(label)); - g_free(label); - - } - - add_bbox = gtk_hbutton_box_new(); - gtk_box_pack_start(GTK_BOX(dev_vbox), add_bbox, FALSE, FALSE, 0); - add_drive = gtk_button_new_with_label(_("Add drive")); - g_signal_connect(G_OBJECT(add_drive), "clicked", - G_CALLBACK(configurewin_add_page), dev_notebook); - GTK_WIDGET_SET_FLAGS(add_drive, GTK_CAN_DEFAULT); - gtk_box_pack_start(GTK_BOX(add_bbox), add_drive, FALSE, FALSE, 0); - - - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dev_vbox, - gtk_label_new(_("Device"))); - - /* - * CD Info config - */ - cdi_vbox = gtk_vbox_new(FALSE, 5); - gtk_container_set_border_width(GTK_CONTAINER(cdi_vbox), 5); - - - /* CDDB */ - cdi_cddb_frame = gtk_frame_new(_("CDDB:")); - gtk_box_pack_start(GTK_BOX(cdi_vbox), cdi_cddb_frame, FALSE, FALSE, 0); - - cdi_cddb_vbox = gtk_vbox_new(FALSE, 10); - gtk_container_border_width(GTK_CONTAINER(cdi_cddb_vbox), 5); - gtk_container_add(GTK_CONTAINER(cdi_cddb_frame), cdi_cddb_vbox); - - cdi_cddb_hbox = gtk_hbox_new(FALSE, 10); - gtk_container_border_width(GTK_CONTAINER(cdi_cddb_hbox), 0); - gtk_box_pack_start(GTK_BOX(cdi_cddb_vbox), - cdi_cddb_hbox, FALSE, FALSE, 0); - cdi_use_cddb = gtk_check_button_new_with_label(_("Use CDDB")); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cdi_use_cddb), - cdda_cfg.use_cddb); - gtk_box_pack_start(GTK_BOX(cdi_cddb_hbox), cdi_use_cddb, FALSE, FALSE, 0); - cdi_cddb_server_list = gtk_button_new_with_label(_("Get server list")); - gtk_box_pack_end(GTK_BOX(cdi_cddb_hbox), cdi_cddb_server_list, FALSE, - FALSE, 0); - cdi_cddb_debug_win = gtk_button_new_with_label(_("Show network window")); - g_signal_connect(G_OBJECT(cdi_cddb_debug_win), "clicked", - G_CALLBACK(cdda_cddb_show_network_window), NULL); - gtk_box_pack_end(GTK_BOX(cdi_cddb_hbox), cdi_cddb_debug_win, FALSE, - FALSE, 0); - - cdi_cddb_server_hbox = gtk_hbox_new(FALSE, 5); - gtk_box_pack_start(GTK_BOX(cdi_cddb_vbox), - cdi_cddb_server_hbox, FALSE, FALSE, 0); - - cdi_cddb_server_label = gtk_label_new(_("CDDB server:")); - gtk_box_pack_start(GTK_BOX(cdi_cddb_server_hbox), - cdi_cddb_server_label, FALSE, FALSE, 0); - - cdi_cddb_server = gtk_entry_new(); - gtk_entry_set_text(GTK_ENTRY(cdi_cddb_server), cdda_cfg.cddb_server); - gtk_box_pack_start(GTK_BOX(cdi_cddb_server_hbox), cdi_cddb_server, - TRUE, TRUE, 0); - g_signal_connect(G_OBJECT(cdi_cddb_server_list), "clicked", - G_CALLBACK(cdda_cddb_show_server_dialog), - cdi_cddb_server); - - /* - * Track names - */ - cdi_name_frame = gtk_frame_new(_("Track names:")); - gtk_box_pack_start(GTK_BOX(cdi_vbox), cdi_name_frame, FALSE, FALSE, 0); - - cdi_name_vbox = gtk_vbox_new(FALSE, 10); - gtk_container_add(GTK_CONTAINER(cdi_name_frame), cdi_name_vbox); - gtk_container_border_width(GTK_CONTAINER(cdi_name_vbox), 5); - cdi_name_override = - gtk_check_button_new_with_label(_("Override generic titles")); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cdi_name_override), - cdda_cfg.title_override); - gtk_box_pack_start(GTK_BOX(cdi_name_vbox), cdi_name_override, FALSE, - FALSE, 0); - - cdi_name_enable_vbox = gtk_vbox_new(FALSE, 10); - gtk_container_add(GTK_CONTAINER(cdi_name_vbox), cdi_name_enable_vbox); - gtk_widget_set_sensitive(cdi_name_enable_vbox, cdda_cfg.title_override); - g_signal_connect(G_OBJECT(cdi_name_override), "toggled", - G_CALLBACK(toggle_set_sensitive_cb), - cdi_name_enable_vbox); - - cdi_name_hbox = gtk_hbox_new(FALSE, 5); - gtk_box_pack_start(GTK_BOX(cdi_name_enable_vbox), cdi_name_hbox, FALSE, - FALSE, 0); - cdi_name_label = gtk_label_new(_("Name format:")); - gtk_box_pack_start(GTK_BOX(cdi_name_hbox), cdi_name_label, FALSE, - FALSE, 0); - cdi_name = gtk_entry_new(); - gtk_entry_set_text(GTK_ENTRY(cdi_name), cdda_cfg.name_format); - gtk_box_pack_start(GTK_BOX(cdi_name_hbox), cdi_name, TRUE, TRUE, 0); - - cdi_desc = xmms_titlestring_descriptions("patn", 2); - gtk_box_pack_start(GTK_BOX(cdi_name_enable_vbox), cdi_desc, FALSE, - FALSE, 0); - - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), cdi_vbox, - gtk_label_new(_("CD Info"))); - - bbox = gtk_hbutton_box_new(); - gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); - gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); - gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); - - - cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); - g_signal_connect(G_OBJECT(cancel), "clicked", - G_CALLBACK(configurewin_close), NULL); - GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT); - gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 0); - - ok = gtk_button_new_from_stock(GTK_STOCK_OK); - g_signal_connect(G_OBJECT(ok), "clicked", - G_CALLBACK(cdda_configurewin_ok_cb), NULL); - g_signal_connect(G_OBJECT(ok), "clicked", - G_CALLBACK(configurewin_close), NULL); - GTK_WIDGET_SET_FLAGS(ok, GTK_CAN_DEFAULT); - gtk_box_pack_start(GTK_BOX(bbox), ok, TRUE, TRUE, 0); - gtk_widget_grab_default(ok); - - - gtk_widget_show_all(cdda_configure_win); -}
--- a/src/cdaudio/http.c Wed Jul 25 16:48:53 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,223 +0,0 @@ -/* - * http.c - * Some simple routines for connecting to a remote tcp socket - * Copyright 1999 Håvard Kvålen <havardk@sol.no> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -/* FIXME: We need to have *one* place in xmms where you configure proxies */ - -#include "http.h" - -gint -http_open_connection(const gchar * server, gint port) -{ - gint sock; -#ifdef USE_IPV6 - struct addrinfo hints, *res, *res0; - char service[6]; -#else - struct hostent *host; - struct sockaddr_in address; -#endif - -#ifdef USE_IPV6 - snprintf(service, 6, "%d", port); - memset(&hints, 0, sizeof(hints)); - hints.ai_socktype = SOCK_STREAM; - - if (getaddrinfo(server, service, &hints, &res0)) - return 0; - - for (res = res0; res; res = res->ai_next) { - sock = socket (res->ai_family, res->ai_socktype, res->ai_protocol); - if (sock < 0) { - if (res->ai_next) - continue; - else { - freeaddrinfo(res0); - return 0; - } - } - if (connect(sock, res->ai_addr, res->ai_addrlen) < 0) { - if (res->ai_next) { - close(sock); - continue; - } else { - freeaddrinfo(res0); - return 0; - } - } - freeaddrinfo(res0); - return sock; - } -#else - sock = socket(AF_INET, SOCK_STREAM, 0); - address.sin_family = AF_INET; - - if (!(host = gethostbyname(server))) - return 0; - - memcpy(&address.sin_addr.s_addr, *(host->h_addr_list), - sizeof(address.sin_addr.s_addr)); - address.sin_port = g_htons(port); - - if (connect - (sock, (struct sockaddr *) &address, - sizeof(struct sockaddr_in)) == -1) - return 0; -#endif - - return sock; -} - -void -http_close_connection(gint sock) -{ - shutdown(sock, 2); - close(sock); -} - -gint -http_read_line(gint sock, gchar * buf, gint size) -{ - gint i = 0; - - while (i < size - 1) { - if (read(sock, buf + i, 1) <= 0) { - if (i == 0) - return -1; - else - break; - } - if (buf[i] == '\n') - break; - if (buf[i] != '\r') - i++; - } - buf[i] = '\0'; - return i; -} - -gint -http_read_first_line(gint sock, gchar * buf, gint size) -{ - /* Skips the HTTP-header, if there is one, and reads the first line into buf. - Returns number of bytes read. */ - - gint i; - /* Skip the HTTP-header */ - if ((i = http_read_line(sock, buf, size)) < 0) - return -1; - if (!strncmp(buf, "HTTP", 4)) { /* Check to make sure its not HTTP/0.9 */ - while (http_read_line(sock, buf, size) > 0) - /* nothing */ ; - if ((i = http_read_line(sock, buf, size)) < 0) - return -1; - } - - return i; -} - -gchar * -http_get(gchar * url) -{ - gchar *server, *getstr, *buf = NULL, *bptr; - gchar *gs, *gc, *turl = url; - gint sock, n, bsize, port = 0; - - /* Skip past ``http://'' part of URL */ - if (!strncmp(turl, "http:", 5)) { - turl += 5; - if (!strncmp(turl, "//", 2)) - turl += 2; - } - - /* If path starts with a '/', we are referring to localhost */ - if (turl[0] == '/') - server = "localhost"; - else - server = turl; - - /* Check if URL contains port specification */ - gc = strchr(turl, ':'); - gs = strchr(turl, '/'); - - if (gc != NULL && gc < gs) { - port = atoi(gc + 1); - *gc = '\0'; - } - if (port == 0) - port = 80; - - /* Make sure that server string is null terminated. */ - if (gs) - *gs = '\0'; - - - /* - * Now, open connection to server. - */ - sock = http_open_connection(server, port); - - /* Repair the URL string that we broke earlier on */ - if (gs) - *gs = '/'; - if (gc && gc == '\0') - *gc = ':'; - - if (sock == 0) - return NULL; - - /* - * Send query to socket. - */ - getstr = g_strdup_printf("GET %s HTTP/1.0\r\n\r\n", gs ? gs : "/"); -/* getstr = g_strdup_printf("GET %s HTTP/1.0\r\n\r\n", url ? url : "/"); */ - - if (write(sock, getstr, strlen(getstr)) == -1) { - http_close_connection(sock); - return NULL; - } - - /* - * Start receiving result. - */ - bsize = 4096; - bptr = buf = g_malloc(bsize); - - if ((n = http_read_first_line(sock, bptr, bsize)) == -1) { - g_free(buf); - buf = NULL; - goto Done; - } - - bsize -= n; - bptr += n; - - while (bsize > 0 && (n = http_read_line(sock, bptr, bsize)) != -1) { - bptr += n; - bsize -= n; - } - - Done: - http_close_connection(sock); - - /* - * Return result buffer to caller. - */ - return buf; -}
--- a/src/cdaudio/http.h Wed Jul 25 16:48:53 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * Copyright 1999 Håvard Kvålen <havardk@sol.no> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef XMMS_HTTP_H -#define XMMS_HTTP_H - -#include "config.h" -#include <glib.h> - -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif - -#include <sys/socket.h> -#include <netinet/in.h> -#include <string.h> -#include <netdb.h> -#include <stdlib.h> - - -gint http_open_connection(const gchar * server, gint port); -void http_close_connection(gint sock); -gint http_read_line(gint sock, gchar * buf, gint size); -gint http_read_first_line(gint sock, gchar * buf, gint size); -gchar *http_get(gchar * url); - -#endif