1 /*
2  *   libcddb - CDDB Interface Library for xmcd/cda
3  *
4  *	This library implements an interface to access the "classic"
5  *	CDDB1 services.
6  *
7  *   Copyright (C) 1993-2004  Ti Kan
8  *   E-mail: xmcd@amb.org
9  *
10  *   This program is free software; you can redistribute it and/or modify
11  *   it under the terms of the GNU General Public License as published by
12  *   the Free Software Foundation; either version 2 of the License, or
13  *   (at your option) any later version.
14  *
15  *   This program is distributed in the hope that it will be useful,
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *   GNU General Public License for more details.
19  *
20  *   You should have received a copy of the GNU General Public License
21  *   along with this program; if not, write to the Free Software
22  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  *
24  */
25 #ifndef _FCDDB_H_
26 #define _FCDDB_H_
27 
28 #ifndef lint
29 static char     *_fcddb_h_ident_ = "@(#)fcddb.h	1.42 04/03/11";
30 #endif
31 
32 #define XMCD_CDDB		/* Enable correct includes in CDDB2API.h */
33 
34 #include "common_d/appenv.h"
35 #include "common_d/util.h"
36 #include "cddb_d/CDDB2API.h"
37 
38 /* Debug output macro */
39 #define FCDDBDBG		if (fcddb_debug) (void) fprintf
40 
41 /* Magic value to indicate that this is a CDDB1 implementation */
42 #define CDDB1_MAGIC		0x000cddb1
43 
44 /* HTTP port number */
45 #define HTTP_PORT		80
46 
47 /* CDDB1 server host and CGI path */
48 #define CDDB_SERVER_HOST	"cddb.cddb.com"
49 #define CDDB_CGI_PATH		"/~cddb/cddb.cgi"
50 #define CDDB_SUBMIT_HOST	"submit.cddb.com"
51 #define CDDB_SUBMIT_CGI_PATH	"/~cddb/submit.cgi"
52 
53 /* Web browser invocation script name */
54 #define CDDB_GOBROWSER		"gobrowser"
55 
56 #ifdef NOREMOTE
57 #undef SOCKS			/* NOREMOTE implies no SOCKS support */
58 #endif
59 
60 /* SOCKS support */
61 #ifdef SOCKS
62 #define SOCKSINIT(x)		SOCKSinit(x)
63 #define SOCKET			socket
64 #define CONNECT			Rconnect
65 #else
66 #define SOCKSINIT(x)
67 #define SOCKET			socket
68 #define CONNECT			connect
69 #endif  /* SOCKS */
70 
71 
72 /*
73  * Internal data structures
74  */
75 
76 /* Disc ID list structure */
77 typedef struct fcddb_idlist {
78 	word32_t		discid;		/* Disc ID */
79 	struct fcddb_idlist	*next;		/* Ptr to next elem */
80 } fcddb_idlist_t;
81 
82 /* Bits for the flags field in fcddb_gmap_t */
83 #define CDDB_GMAP_DYN		0x1		/* Dynamically allocated */
84 #define CDDB_GMAP_DUP		0x2		/* Duplicate mapping */
85 
86 /* CDDB1 -> CDDB2 genre mapping structure */
87 typedef struct fcddb_gmap {
88 	char			*cddb1name;	/* CDDB1 Category name */
89 	struct {
90 		char		*id;		/* CDDB2 meta-genre ID */
91 		char		*name;		/* CDDB2 meta-genre name */
92 	} meta;
93 	struct {
94 		char		*id;		/* CDDB2 sub-genre ID */
95 		char		*name;		/* CDDB2 sub-genre name */
96 	} sub;
97 	unsigned int		flags;		/* Flags */
98 	struct fcddb_gmap	*next;		/* Pointer to next element */
99 } fcddb_gmap_t;
100 
101 
102 /*
103  * Internal Object structures
104  */
105 
106 /* CddbGenre structure */
107 typedef struct cddb_genre {
108 	char			objtype[STR_BUF_SZ];	/* Object type */
109 	CddbStr			id;			/* Genre id */
110 	CddbStr			name;			/* Genre name */
111 	struct cddb_genre	*nextmeta;		/* Ptr to next meta */
112 	struct cddb_genre	*next;			/* Ptr to next elem */
113 } cddb_genre_t;
114 
115 /* CddbGenreList structure */
116 typedef struct cddb_genrelist {
117 	char			objtype[STR_BUF_SZ];	/* Object type */
118 	cddb_genre_t		*genres;		/* Genre list */
119 } cddb_genrelist_t;
120 
121 /* CddbGenreTree structure */
122 typedef struct cddb_genretree {
123 	char			objtype[STR_BUF_SZ];	/* Object type */
124 	cddb_genre_t		*genres;		/* Genre list */
125 	long			count;			/* Number of elems */
126 } cddb_genretree_t;
127 
128 /* CddbRole structure */
129 typedef struct cddb_role {
130 	char			objtype[STR_BUF_SZ];	/* Object type */
131 	char			*roletype;		/* Role type */
132 	CddbStr			id;			/* Role ID */
133 	CddbStr			name;			/* Role name */
134 	struct cddb_role	*next;			/* Ptr to next elem */
135 } cddb_role_t;
136 
137 /* CddbRoleList structure */
138 typedef struct cddb_rolelist {
139 	char			objtype[STR_BUF_SZ];	/* Object type */
140 	cddb_role_t		*metarole;		/* Meta role */
141 	cddb_role_t		*subroles;		/* Role list */
142 	long			count;			/* Number of elems */
143 	struct cddb_rolelist	*next;			/* Ptr to next elem */
144 } cddb_rolelist_t;
145 
146 /* CddbRoleTree structure */
147 typedef struct cddb_roletree {
148 	char			objtype[STR_BUF_SZ];	/* Object type */
149 	cddb_rolelist_t		*rolelists;		/* Role list */
150 	long			count;			/* Number of elems */
151 } cddb_roletree_t;
152 
153 /* CddbLanguage structure */
154 typedef struct cddb_language {
155 	char			objtype[STR_BUF_SZ];	/* Object type */
156 	CddbStr			id;			/* Language ID */
157 	CddbStr			name;			/* Language name */
158 	struct cddb_language	*next;			/* Ptr to next elem */
159 } cddb_language_t;
160 
161 /* CddbLanguages structure */
162 typedef struct cddb_languages {
163 	char			objtype[STR_BUF_SZ];	/* Object type */
164 	cddb_language_t		*languages;		/* Language list */
165 	long			count;			/* Number of elems */
166 } cddb_languages_t;
167 
168 /* CddbLanguageList structure */
169 typedef struct cddb_languagelist {
170 	char			objtype[STR_BUF_SZ];	/* Object type */
171 	cddb_language_t		*languages;		/* Language list */
172 	long			count;			/* Number of elems */
173 } cddb_languagelist_t;
174 
175 /* CddbRegion structure */
176 typedef struct cddb_region {
177 	char			objtype[STR_BUF_SZ];	/* Object type */
178 	CddbStr			id;			/* Region ID */
179 	CddbStr			name;			/* Region name */
180 	struct cddb_region	*next;			/* Ptr to next elem */
181 } cddb_region_t;
182 
183 /* CddbRegionList structure */
184 typedef struct cddb_regionlist {
185 	char			objtype[STR_BUF_SZ];	/* Object type */
186 	cddb_region_t		*regions;		/* Region list */
187 	long			count;			/* Number of elems */
188 } cddb_regionlist_t;
189 
190 /* CddbURL structure */
191 typedef struct cddb_url {
192 	char			objtype[STR_BUF_SZ];	/* Object type */
193 	CddbStr			type;			/* Type */
194 	CddbStr			href;			/* HREF */
195 	CddbStr			displaylink;		/* Display link */
196 	CddbStr			displaytext;		/* Display text */
197 	CddbStr			category;		/* Category */
198 	CddbStr			description;		/* Description */
199 	struct cddb_url		*next;			/* Ptr to next elem */
200 } cddb_url_t;
201 
202 /* CddbURLList structure */
203 typedef struct cddb_urllist {
204 	char			objtype[STR_BUF_SZ];	/* Object type */
205 	cddb_url_t		*urls;			/* URL list */
206 	long			count;			/* Number of elems */
207 } cddb_urllist_t;
208 
209 /* CddbURLTree structure */
210 typedef struct cddb_urltree {
211 	char			objtype[STR_BUF_SZ];	/* Object type */
212 	cddb_url_t		*urls;			/* URL list */
213 } cddb_urltree_t;
214 
215 /* CddbURLManager structure */
216 typedef struct cddb_urlmanager {
217 	char			objtype[STR_BUF_SZ];	/* Object type */
218 	cddb_urllist_t		urllist;		/* URL list */
219 	void			*control;		/* Ptr back to ctrl */
220 } cddb_urlmanager_t;
221 
222 /* CddbFullName structure */
223 typedef struct cddb_fullname {
224 	char			objtype[STR_BUF_SZ];	/* Object type */
225 	CddbStr			name;			/* Name */
226 	CddbStr			lastname;		/* Last name */
227 	CddbStr			firstname;		/* First name */
228 	CddbStr			the;			/* The */
229 } cddb_fullname_t;
230 
231 /* CddbCredit structure */
232 typedef struct cddb_credit {
233 	char			objtype[STR_BUF_SZ];	/* Object type */
234 	cddb_role_t		*role;			/* Role */
235 	cddb_fullname_t		fullname;		/* Name */
236 	CddbStr			notes;			/* Notes */
237 	struct cddb_credit	*next;			/* Ptr to next elem */
238 } cddb_credit_t;
239 
240 /* CddbCredits structure */
241 typedef struct cddb_credits {
242 	char			objtype[STR_BUF_SZ];	/* Object type */
243 	cddb_credit_t		*credits;		/* Credit list */
244 	long			count;			/* Number of elems */
245 } cddb_credits_t;
246 
247 /* CddbSegment structure */
248 typedef struct cddb_segment {
249 	char			objtype[STR_BUF_SZ];	/* Object type */
250 	CddbStr			name;			/* Segment name */
251 	CddbStr			notes;			/* Segment notes */
252 	CddbStr			starttrack;		/* Start track */
253 	CddbStr			startframe;		/* Start frame */
254 	CddbStr			endtrack;		/* End track */
255 	CddbStr			endframe;		/* End frame */
256 	cddb_credits_t		credits;		/* Credits */
257 	void			*control;		/* Ptr back to ctrl */
258 	struct cddb_segment	*next;			/* Ptr to next elem */
259 } cddb_segment_t;
260 
261 /* CddbSegments structure */
262 typedef struct cddb_segments {
263 	char			objtype[STR_BUF_SZ];	/* Object type */
264 	cddb_segment_t		*segments;		/* Segment list */
265 	long			count;			/* Number of elems */
266 } cddb_segments_t;
267 
268 /* CddbUserInfo structure */
269 typedef struct cddb_userinfo {
270 	char			objtype[STR_BUF_SZ];	/* Object type */
271 	CddbStr			userhandle;		/* user handle */
272 	CddbStr			password;		/* password */
273 	CddbStr			passwordhint;		/* password hint */
274 	CddbStr			emailaddress;		/* email address */
275 	CddbStr			regionid;		/* Region ID */
276 	CddbStr			postalcode;		/* Postal code */
277 	CddbStr			age;			/* Age */
278 	CddbStr			sex;			/* Sex */
279 	CddbBoolean		allowemail;		/* Allow email */
280 	CddbBoolean		allowstats;		/* Allow stats */
281 } cddb_userinfo_t;
282 
283 /* CddbOptions structure */
284 typedef struct cddb_options {
285 	char			objtype[STR_BUF_SZ];	/* Object type */
286 	CddbStr			proxyserver;		/* Proxy server */
287 	long			proxyport;		/* Proxy port */
288 	CddbStr			proxyusername;		/* Proxy user name */
289 	CddbStr			proxypassword;		/* Proxy password */
290 	long			servertimeout;		/* Server timeout */
291 	CddbBoolean		testsubmitmode;		/* Test submit mode */
292 	CddbStr			localcachepath;		/* Cache path */
293 	long			localcachetimeout;	/* Cache timeout */
294 	long			localcacheflags;	/* Cache flags */
295 } cddb_options_t;
296 
297 /* CddbTrack structure */
298 typedef struct cddb_track {
299 	char			objtype[STR_BUF_SZ];	/* Object type */
300 	CddbStr			title;			/* Title */
301 	CddbStr			notes;			/* Notes */
302 	cddb_fullname_t		fullname;		/* Artist full name */
303 	cddb_credits_t		credits;		/* Credits */
304 	void			*control;		/* Ptr back to ctrl */
305 } cddb_track_t;
306 
307 /* CddbTracks structure */
308 typedef struct cddb_tracks {
309 	char			objtype[STR_BUF_SZ];	/* Object type */
310 	cddb_track_t		track[MAXTRACK];	/* Tracks */
311 	long			count;			/* Track count */
312 } cddb_tracks_t;
313 
314 /* CddbDisc structure */
315 typedef struct cddb_disc {
316 	char			objtype[STR_BUF_SZ];	/* Object type */
317 	char			*category;		/* CDDB1 category */
318 	char			*discid;		/* Disc ID */
319 	CddbStr			toc;			/* TOC string */
320 	CddbStr			title;			/* Title */
321 	CddbStr			notes;			/* Notes */
322 	char			*revision;		/* Revision */
323 	char			*submitter;		/* Submitter */
324 	cddb_fullname_t		fullname;		/* Artist full name */
325 	cddb_tracks_t		tracks;			/* Tracks */
326 	cddb_credits_t		credits;		/* Credits */
327 	cddb_segments_t		segments;		/* Segments */
328 	cddb_genre_t		*genre;			/* Genre */
329 	cddb_urllist_t		urllist;		/* URL list */
330 	void			*control;		/* Ptr back to ctrl */
331 	fcddb_idlist_t		*idlist;		/* ID list */
332 	struct cddb_disc	*next;			/* Ptr to next elem */
333 } cddb_disc_t;
334 
335 /* CddbDiscs structure */
336 typedef struct cddb_discs {
337 	char			objtype[STR_BUF_SZ];	/* Object type */
338 	cddb_disc_t		*discs;			/* Disc list */
339 	long			count;			/* Number of elems */
340 } cddb_discs_t;
341 
342 /* CddbControl structure */
343 typedef struct cddb_control {
344 	char			objtype[STR_BUF_SZ];	/* Object type */
345 	word32_t		magic;			/* Magic number */
346 	char			*clientname;		/* Client name */
347 	char			*clientid;		/* Client ID */
348 	char			*clientver;		/* Client version */
349 	char			*hostname;		/* Hostname */
350 	cddb_options_t		options;		/* Options */
351 	cddb_userinfo_t		userinfo;		/* Userinfo */
352 	cddb_regionlist_t	regionlist;		/* Region list */
353 	cddb_languagelist_t	languagelist;		/* Language list */
354 	cddb_genretree_t 	genretree;		/* Genre tree */
355 	cddb_roletree_t 	roletree;		/* Role tree */
356 	cddb_urllist_t		urllist;		/* URL list */
357 	cddb_discs_t		discs;			/* Discs */
358 	cddb_disc_t		disc;			/* Disc */
359 } cddb_control_t;
360 
361 
362 /*
363  * Support functions
364  */
365 extern void		fcddb_onsig(int);
366 extern void		(*fcddb_signal(int , void (*)(int)))(int);
367 extern CddbResult	fcddb_init(cddb_control_t *);
368 extern CddbResult	fcddb_halt(cddb_control_t *);
369 extern void		*fcddb_obj_alloc(char *, size_t);
370 extern void		fcddb_obj_free(void *);
371 extern int		fcddb_runcmd(char *);
372 extern CddbResult	fcddb_set_auth(char *, char *);
373 extern char		*fcddb_strdup(char *);
374 extern char		*fcddb_basename(char *);
375 extern char		*fcddb_dirname(char *);
376 extern CddbResult	fcddb_mkdir(char *, mode_t);
377 extern char		*fcddb_username(void);
378 extern char		*fcddb_homedir(void);
379 extern char		*fcddb_hostname(void);
380 extern char		*fcddb_genre_id2categ(char *);
381 extern cddb_genre_t	*fcddb_genre_id2gp(cddb_control_t *, char *);
382 extern char		*fcddb_genre_categ2id(char *);
383 extern cddb_genre_t	*fcddb_genre_categ2gp(cddb_control_t *, char *);
384 extern int		fcddb_parse_toc(char *, unsigned int *);
385 extern char		*fcddb_discid(int, unsigned int *);
386 extern CddbResult	fcddb_read_cddb(cddb_control_t *, char *,
387 					char *, char *, char *,
388 					unsigned short, bool_t);
389 extern CddbResult	fcddb_lookup_cddb(cddb_control_t *, char *,
390 					unsigned int *, char *, char *,
391 					unsigned short, bool_t, int *);
392 extern CddbResult	fcddb_submit_cddb(cddb_control_t *, cddb_disc_t *,
393 					char *, unsigned short, bool_t);
394 extern CddbResult	fcddb_flush_cddb(cddb_control_t *, CDDBFlushFlags);
395 
396 #endif	/* _FCDDB_H_ */
397 
398