summaryrefslogtreecommitdiff
path: root/include/cddb/cddb_ni.h
blob: d32fdc1324fbc174c140d47baf2e12fc9ba49900 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
    $Id: cddb_ni.h,v 1.32 2009/03/01 03:28:07 jcaratzas Exp $

    Copyright (C) 2003, 2004, 2005 Kris Verbeeck <airborne@advalvas.be>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA  02111-1307, USA.
*/

#ifndef CDDB_NI_H
#define CDDB_NI_H 1

#ifdef __cplusplus
    extern "C" {
#endif


#if HAVE_CONFIG_H
#  include <config.h>
#endif

#ifdef HAVE_ICONV_H
#  include <iconv.h>
#else
   typedef void *iconv_t;       /* for code uniformity */
#endif

#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif

#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#ifndef ETIMEDOUT
#define ETIMEDOUT   WSAETIMEDOUT
#endif
#ifndef EWOULDBLOCK
#define EWOULDBLOCK WSAEWOULDBLOCK
#endif
#ifndef EINPROGRESS
#define EINPROGRESS WSAEINPROGRESS
#endif
#endif

#include "cddb/cddb_regex.h"
#include "cddb/cddb.h"
#include "cddb/cddb_conn_ni.h"
#include "cddb/cddb_net.h"
#include "cddb/cddb_cmd_ni.h"
#include "cddb/cddb_log_ni.h"


#define FALSE          0
#define TRUE           1

#define CHR_CR         '\r'
#define CHR_LF         '\n'
#define CHR_EOS        '\0'
#define CHR_SPACE      ' '
#define CHR_DOT        '.'

#define DEFAULT_BUF_SIZE 1024

#define CLIENT_NAME    PACKAGE
#define CLIENT_VERSION VERSION

#define DEFAULT_USER        "anonymous"
#define DEFAULT_HOST        "localhost"
#define DEFAULT_SERVER      "freedb.org"
#define DEFAULT_PORT        888
#define DEFAULT_TIMEOUT     10
#define DEFAULT_PATH_QUERY  "/~cddb/cddb.cgi"
#define DEFAULT_PATH_SUBMIT "/~cddb/submit.cgi"
#define DEFAULT_CACHE       ".cddbslave"
#define DEFAULT_PROXY_PORT  8080

#define DEFAULT_PROTOCOL_VERSION 6
#define SERVER_CHARSET           "UTF8"


#define FREE_NOT_NULL(p) if (p) { free(p); p = NULL; }
#define CONNECTION_OK(c) (c->socket != -1)
#define STR_OR_NULL(s) ((s) ? s : "NULL")
#define STR_OR_EMPTY(s) ((s) ? s : "")

#define RETURN_STR_OR_EMPTY(s) \
            return (!s && (libcddb_flags() & CDDB_F_EMPTY_STR)) ? "" : s

#define ASSERT(cond, error) \
            if (!(cond)) { return error; }
#define ASSERT_NOT_NULL(ptr) \
            ASSERT(ptr!=NULL, CDDB_ERR_INVALID)
#define ASSERT_RANGE(num,lo,hi) \
            ASSERT((num>=lo)&&(num<=hi), CDDB_ERR_INVALID)


/* --- type definitions */


/** Actual definition of track structure. */
struct cddb_track_s
{
    int num;                    /**< track number on the disc */
    int frame_offset;           /**< frame offset of the track on the disc */
    int length;                 /**< track length in seconds */
    char *title;                /**< track title */
    char *artist;               /**< (optional) track artist */
    char *ext_data;             /**< (optional) extended disc data */
    struct cddb_track_s *prev;  /**< pointer to previous track, or NULL */
    struct cddb_track_s *next;  /**< pointer to next track, or NULL */
    struct cddb_disc_s *disc;   /**< disc of which this is a track */
};

/** Actual definition of disc structure. */
struct cddb_disc_s
{
    unsigned int revision;      /**< revision number */
    unsigned int discid;        /**< four byte disc ID */
    cddb_cat_t category;        /**< CDDB category */
    char *genre;                /**< disc genre */
    char *title;                /**< disc title */
    char *artist;               /**< disc artist */
    unsigned int length;        /**< disc length in seconds */
    unsigned int year;          /**< (optional) disc year YYYY */
    char *ext_data;             /**< (optional) extended disc data  */
    int track_cnt;              /**< number of tracks on the disc */
    cddb_track_t *tracks;       /**< pointer to the first track */
    cddb_track_t *iterator;     /**< track iterator */
};


/* --- global variables */


/** Server connection used especially for text searches. */
extern cddb_conn_t *cddb_search_conn;


/* --- non-exported function prototypes */


unsigned int libcddb_flags(void);

/**
 * Convert a string to a new character encoding according to the given
 * conversion descriptor.
 */
int cddb_str_iconv(iconv_t cd, ICONV_CONST char *in, char **out);

/**
 * Converts all disc and track strings to user character encoding.
 */
int cddb_disc_iconv(iconv_t cd, cddb_disc_t *disc);

/**
 * Converts all track strings to user character encoding.
 */
int cddb_track_iconv(iconv_t cd, cddb_track_t *track);

/**
 * Converts all site strings to user character encoding.
 */
int cddb_site_iconv(iconv_t cd, cddb_site_t *site);

/**
 * Base64 encode the source string and write it to the destination
 * buffer.  The destination buffer should be large enough (= 4/3 of
 * src string length).
 */
void cddb_b64_encode(char *dst, const char *src);


#ifdef __cplusplus
    }
#endif

#endif /* CDDB_NI_H */