Hi Dominique,
Actually, it looks like this bug is caused by alsaplayer not reading a
long enough string for the welcome string, which messes up the parsing
later on.
Attached is a patch that fixes this, along with a few other
improvements in cddb reading (getting rid of some fixed-size buffers).
The patch is against alsaplayer 0.99.79, so you'll have to update it
a bit to apply against what you have in svn. I can now use port 888
on freedb.freedb.org again.
(But I'm looking forward to the gtk2 interface. ;) )
--
Hubert Chan <[EMAIL PROTECTED]> -- Jabber: [EMAIL PROTECTED]
PGP/GnuPG key: 1024D/124B61FA http://www.uhoreg.ca/
Fingerprint: 96C5 012F 5F74 A5F7 1FF7 5291 AF29 C719 124B 61FA
<cdda.patch>
--- alsaplayer-0.99.79/input/cdda/cdda_engine.c 2007-04-15 16:20:57.424360259 -0400
+++ alsaplayer-0.99.79/input/cdda/cdda_engine.c 2007-06-05 16:34:32.430846932 -0400
@@ -309,45 +309,58 @@
char * send_to_server (int server_fd, char *message)
{
ssize_t total, i;
- int len = BUFFER_SIZE * 8;
- char *response, temp[len];
+ int len = BUFFER_SIZE;
+ char *response, *temp;
+
+ temp = (char *) malloc(BUFFER_SIZE);
/* write 'message' to the server */
if (send (server_fd, message, strlen (message), MSG_DONTWAIT) < 0)
{
alsaplayer_error("%s: %s\n", message, strerror (errno));
+ free (temp);
return (NULL);
}
-#ifdef DEBUG
+ if (global_verbose) {
/* print the message sent to the server */
alsaplayer_error("-> %s", message);
-#endif
+ }
/* read the response from the server */
total = 0;
do
{
- i = read (server_fd, temp + total, len - total);
+ i = read (server_fd, temp + total, BUFFER_SIZE);
if (i < 0)
{
alsaplayer_error("%s\n", strerror (errno));
+ free (temp);
return (NULL);
}
total += i;
+ if (total + BUFFER_SIZE > len)
+ {
+ temp = (char *) realloc(temp, len + BUFFER_SIZE);
+ len += BUFFER_SIZE;
+ }
}
while (total > 2 && temp[total - 2] != '\r' && i != 0);
if (total < 2)
+ {
+ free (temp);
return (NULL);
+ }
temp[total-2] = '\0'; /* temp[total-1] == \r; temp[total] == \n */
response = strdup (temp); /* duplicate the response from the server */
+ free(temp);
-#ifdef DEBUG
+ if (global_verbose) {
/* print the message sent to the server */
alsaplayer_error("<- %s", response);
-#endif
+ }
return (response);
}
@@ -551,11 +564,11 @@
char * cddb_lookup (char *address, char *char_port, int discID, struct cd_trk_list *tl)
{
int port = atoi (char_port);
- int server_fd, i, j, n;
+ int server_fd, i, j;
int total_secs = 0, counter = 0;
char *answer = NULL, *username, *filename, categ[20], newID[9];
char msg[BUFFER_SIZE], offsets[BUFFER_SIZE], tmpbuf[BUFFER_SIZE];
- char hostname[MAXHOSTNAMELEN], server[80];
+ char hostname[MAXHOSTNAMELEN];
/* try to create a socket to the server */
if (global_verbose)
@@ -570,17 +583,14 @@
printf ("OK\n");
/* get the initial message from the server */
- n = read (server_fd, server, 80);
- if (n >= 0)
- server[n] = '\0';
- if (n >= 2)
- server[n-2] = '\0';
+ answer = send_to_server (server_fd, "");
if (global_verbose) {
- printf ("\n<- %s\n", server);
printf ("Saying HELLO to CDDB server ...\n");
}
+ free (answer);
+
/* set some settings before saying HELLO to the CDDB server */
username = getlogin ();
if ((gethostname (hostname, sizeof (hostname))) < 0)