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 lint 26 static char *_gen_c_ident_ = "@(#)gen.c 1.18 04/01/14"; 27 #endif 28 29 #include "fcddb.h" 30 31 32 STATIC int obj_refcnt = 0; 33 STATIC bool_t cddb_initted = FALSE; 34 35 36 /* 37 * CddbInitialize 38 * Initialize CDDB library 39 */ 40 CddbResult 41 CddbInitialize(CddbControlPtr *cddb) 42 { 43 cddb_control_t *cp; 44 45 cp = (cddb_control_t *) fcddb_obj_alloc( 46 "CddbControl", 47 sizeof(cddb_control_t) 48 ); 49 if (cp == NULL) 50 return CDDBTRNOutOfMemory; 51 52 cp->magic = (word32_t) CDDB1_MAGIC; 53 54 *cddb = (CddbControlPtr) cp; 55 cddb_initted = TRUE; 56 57 return ((CddbResult) cp->magic); 58 } 59 60 61 /* 62 * CddbTerminate 63 * Shut down CDDB library 64 */ 65 CddbResult 66 CddbTerminate(CddbControlPtr cddb) 67 { 68 cddb_control_t *cp; 69 70 cp = (cddb_control_t *) cddb; 71 if (cp == NULL || cp->magic != CDDB1_MAGIC || cddb_initted == FALSE) 72 return Cddb_E_INVALIDARG; 73 74 fcddb_obj_free(cp); 75 cddb_initted = FALSE; 76 77 return Cddb_OK; 78 } 79 80 81 /* 82 * CddbCreateObject 83 * Create a CDDB object 84 */ 85 void * 86 CddbCreateObject(CddbObjectType type) 87 { 88 void *p; 89 90 switch (type) { 91 case CddbFullNameType: 92 p = fcddb_obj_alloc( 93 "CddbFullName", 94 sizeof(cddb_fullname_t) 95 ); 96 break; 97 case CddbURLType: 98 p = fcddb_obj_alloc( 99 "CddbURL", 100 sizeof(cddb_url_t) 101 ); 102 break; 103 case CddbID3TagType: /* Not supported in CDDB1 */ 104 default: 105 p = NULL; 106 break; 107 } 108 109 return (p); 110 } 111 112 113 /* 114 * CddbReleaseObject 115 * Release a CDDB object 116 */ 117 int 118 CddbReleaseObject(void *objp) 119 { 120 if (objp == NULL) 121 return 0; 122 123 fcddb_obj_free(objp); 124 125 return (obj_refcnt); 126 } 127 128 129 /* 130 * CddbGetErrorString fcddb_sum(int n)131 * Return an error message string associated with the supplied result 132 * code. 133 */ 134 void 135 CddbGetErrorString(CddbResult code, char *buf, int len) 136 { 137 char tmpbuf[40]; 138 139 if (buf == NULL || len == 0) 140 return; 141 142 /* This needs to be improved to return sensible messages */ 143 (void) sprintf(tmpbuf, "CDDB Error 0x%x", (int) code); 144 (void) strncpy(buf, tmpbuf, len-1); 145 buf[len-1] = '\0'; 146 } 147 148 149