1 /* 2 $Id: cddb_ni.h,v 1.32 2009/03/01 03:28:07 jcaratzas Exp $ 3 4 Copyright (C) 2003, 2004, 2005 Kris Verbeeck <airborne@advalvas.be> 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Library General Public 8 License as published by the Free Software Foundation; either 9 version 2 of the License, or (at your option) any later version. 10 11 This library is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Library General Public License for more details. 15 16 You should have received a copy of the GNU Library General Public 17 License along with this library; if not, write to the 18 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 Boston, MA 02111-1307, USA. 20 */ 21 22 #ifndef CDDB_NI_H 23 #define CDDB_NI_H 1 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 30 #if HAVE_CONFIG_H 31 # include <config.h> 32 #endif 33 34 #ifdef HAVE_ICONV_H 35 # include <iconv.h> 36 #else 37 typedef void *iconv_t; /* for code uniformity */ 38 #endif 39 40 #ifdef HAVE_WINDOWS_H 41 #include <windows.h> 42 #endif 43 44 #ifdef HAVE_WINSOCK2_H 45 #include <winsock2.h> 46 #ifndef ETIMEDOUT 47 #define ETIMEDOUT WSAETIMEDOUT 48 #endif 49 #ifndef EWOULDBLOCK 50 #define EWOULDBLOCK WSAEWOULDBLOCK 51 #endif 52 #ifndef EINPROGRESS 53 #define EINPROGRESS WSAEINPROGRESS 54 #endif 55 #endif 56 57 #include "cddb/cddb_regex.h" 58 #include "cddb/cddb.h" 59 #include "cddb/cddb_conn_ni.h" 60 #include "cddb/cddb_net.h" 61 #include "cddb/cddb_cmd_ni.h" 62 #include "cddb/cddb_log_ni.h" 63 64 65 #define FALSE 0 66 #define TRUE 1 67 68 #define CHR_CR '\r' 69 #define CHR_LF '\n' 70 #define CHR_EOS '\0' 71 #define CHR_SPACE ' ' 72 #define CHR_DOT '.' 73 74 #define DEFAULT_BUF_SIZE 1024 75 76 #define CLIENT_NAME PACKAGE 77 #define CLIENT_VERSION VERSION 78 79 #define DEFAULT_USER "anonymous" 80 #define DEFAULT_HOST "localhost" 81 #define DEFAULT_SERVER "freedb.org" 82 #define DEFAULT_PORT 888 83 #define DEFAULT_TIMEOUT 10 84 #define DEFAULT_PATH_QUERY "/~cddb/cddb.cgi" 85 #define DEFAULT_PATH_SUBMIT "/~cddb/submit.cgi" 86 #define DEFAULT_CACHE ".cddbslave" 87 #define DEFAULT_PROXY_PORT 8080 88 89 #define DEFAULT_PROTOCOL_VERSION 6 90 #define SERVER_CHARSET "UTF8" 91 92 93 #define FREE_NOT_NULL(p) if (p) { free(p); p = NULL; } 94 #define CONNECTION_OK(c) (c->socket != -1) 95 #define STR_OR_NULL(s) ((s) ? s : "NULL") 96 #define STR_OR_EMPTY(s) ((s) ? s : "") 97 98 #define RETURN_STR_OR_EMPTY(s) \ 99 return (!s && (libcddb_flags() & CDDB_F_EMPTY_STR)) ? "" : s 100 101 #define ASSERT(cond, error) \ 102 if (!(cond)) { return error; } 103 #define ASSERT_NOT_NULL(ptr) \ 104 ASSERT(ptr!=NULL, CDDB_ERR_INVALID) 105 #define ASSERT_RANGE(num,lo,hi) \ 106 ASSERT((num>=lo)&&(num<=hi), CDDB_ERR_INVALID) 107 108 109 /* --- type definitions */ 110 111 112 /** Actual definition of track structure. */ 113 struct cddb_track_s 114 { 115 int num; /**< track number on the disc */ 116 int frame_offset; /**< frame offset of the track on the disc */ 117 int length; /**< track length in seconds */ 118 char *title; /**< track title */ 119 char *artist; /**< (optional) track artist */ 120 char *ext_data; /**< (optional) extended disc data */ 121 struct cddb_track_s *prev; /**< pointer to previous track, or NULL */ 122 struct cddb_track_s *next; /**< pointer to next track, or NULL */ 123 struct cddb_disc_s *disc; /**< disc of which this is a track */ 124 }; 125 126 /** Actual definition of disc structure. */ 127 struct cddb_disc_s 128 { 129 unsigned int revision; /**< revision number */ 130 unsigned int discid; /**< four byte disc ID */ 131 cddb_cat_t category; /**< CDDB category */ 132 char *genre; /**< disc genre */ 133 char *title; /**< disc title */ 134 char *artist; /**< disc artist */ 135 unsigned int length; /**< disc length in seconds */ 136 unsigned int year; /**< (optional) disc year YYYY */ 137 char *ext_data; /**< (optional) extended disc data */ 138 int track_cnt; /**< number of tracks on the disc */ 139 cddb_track_t *tracks; /**< pointer to the first track */ 140 cddb_track_t *iterator; /**< track iterator */ 141 }; 142 143 144 /* --- global variables */ 145 146 147 /** Server connection used especially for text searches. */ 148 extern cddb_conn_t *cddb_search_conn; 149 150 151 /* --- non-exported function prototypes */ 152 153 154 unsigned int libcddb_flags(void); 155 156 /** 157 * Convert a string to a new character encoding according to the given 158 * conversion descriptor. 159 */ 160 int cddb_str_iconv(iconv_t cd, ICONV_CONST char *in, char **out); 161 162 /** 163 * Converts all disc and track strings to user character encoding. 164 */ 165 int cddb_disc_iconv(iconv_t cd, cddb_disc_t *disc); 166 167 /** 168 * Converts all track strings to user character encoding. 169 */ 170 int cddb_track_iconv(iconv_t cd, cddb_track_t *track); 171 172 /** 173 * Converts all site strings to user character encoding. 174 */ 175 int cddb_site_iconv(iconv_t cd, cddb_site_t *site); 176 177 /** 178 * Base64 encode the source string and write it to the destination 179 * buffer. The destination buffer should be large enough (= 4/3 of 180 * src string length). 181 */ 182 void cddb_b64_encode(char *dst, const char *src); 183 184 185 #ifdef __cplusplus 186 } 187 #endif 188 189 #endif /* CDDB_NI_H */ 190