#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <cdaudio.h>

#include "cddb.h"


int 
bebo_cddb_conf (void)
{
	FILE *conf;
	struct stat cst;
	char *buff;

	if ( NULL == getenv ("HOME")) {
		return -1;
	}

	if ( NULL == (buff = malloc(250))) {
		return -1;
	}

	snprintf (buff, 249, "%s/.cdserverrc", getenv ("HOME"));
	if ( !stat(buff, &cst) ) {
		/* We have ~/.cdserverrc, so skiping... */
		free (buff);
		return 0;
	}

	if ( NULL == (conf = fopen(buff, "w")) ) {
		free (buff);
		return -1;
	}

	fprintf (conf, "# CD server conf file generated for libcdaudio by beboCD.\n");
	fprintf (conf, "# Please edit this file to fit your options.\n\n");
	fprintf (conf, "ACCESS=REMOTE\n");
	fprintf (conf, "SERVER=http://www.freedb.org:80/cgi-bin/cddb.cgi CDDB\n");

	fclose (conf);
	free (buff);

	return 1;
}
