1 /* 2 $Id: cddb_conn_ni.h,v 1.14 2005/08/03 18:27:19 airborne 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_CONN_NI_H 23 #define CDDB_CONN_NI_H 1 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 30 #include "cddb_ni.h" 31 #include "ll.h" 32 33 34 /* --- type definitions */ 35 36 37 /** Actual definition of iconv structure. */ 38 struct cddb_iconv_s 39 { 40 iconv_t cd_to_freedb; /**< character set conversion descriptor for 41 converting from user to FreeDB format */ 42 iconv_t cd_from_freedb; /**< character set conversion descriptor for 43 converting from FreeDB to user format */ 44 }; 45 46 /** Actual definition of serach parameters structure. */ 47 typedef struct cddb_search_params_s 48 { 49 unsigned int fields; /**< fields to search (cddb_search_t 50 bit string) */ 51 unsigned int cats; /**< categories to search (cddb_cat_t 52 bit string) */ 53 } cddb_search_params_t; 54 55 /** Actual definition of connection structure. */ 56 struct cddb_conn_s 57 { 58 unsigned int buf_size; /**< maximum line/buffer size, defaults to 1024 59 (see DEFAULT_BUF_SIZE) */ 60 char *line; /**< last line read */ 61 62 int is_connected; /**< are we already connected to the server? */ 63 struct sockaddr_in sa; /**< the socket address structure for 64 connecting to the CDDB server */ 65 int socket; /**< the socket file descriptor */ 66 char *server_name; /**< host name of the CDDB server, defaults 67 to 'freedb.org' (see DEFAULT_SERVER) */ 68 int server_port; /**< port of the CDDB server, defaults to 888 69 (see DEFAULT_PORT) */ 70 int timeout; /**< time out interval (in seconds) used during 71 network operations, defaults to 10 seconds 72 (see DEFAULT_TIMEOUT) */ 73 74 char *http_path_query; /**< URL for querying the server through HTTP, 75 defaults to /~cddb/cddb.cgi' 76 (see DEFAULT_PATH_QUERY) */ 77 char *http_path_submit; /**< URL for submitting to the server through HTTP, 78 defaults to /~cddb/submit.cgi' 79 (see DEFAULT_PATH_SUBMIT) */ 80 int is_http_enabled; /**< use HTTP, disabled by default */ 81 82 int is_http_proxy_enabled; /**< use HTTP through a proxy server, 83 disabled by default */ 84 char *http_proxy_server; /**< host name of the HTTP proxy server */ 85 int http_proxy_server_port; /**< port of the HTTP proxy server, 86 defaults to 8080 (see DEFAULT_PROXY_PORT) */ 87 char *http_proxy_username; /**< HTTP proxy user name */ 88 char *http_proxy_password; /**< HTTP proxy password */ 89 char *http_proxy_auth; /**< Base64 encoded username:password */ 90 91 FILE *cache_fp; /**< a file pointer to a cached CDDB entry or 92 NULL if no cached version is available */ 93 cddb_cache_mode_t use_cache;/**< field to specify local CDDB cache behaviour, 94 enabled by default (CACHE_ON) */ 95 char *cache_dir; /**< CDDB slave cache, defaults to 96 '~/.cddbslave' (see DEFAULT_CACHE) */ 97 int cache_read; /**< read data from cached file instead of 98 from the network */ 99 100 char *cname; /**< name of the client program, 'libcddb' by 101 default */ 102 char *cversion; /**< version of the client program, current 103 libcddb version by default */ 104 char *user; /**< user name supplied to CDDB server, defaults 105 to the value of the 'USER' environment 106 variable or 'anonymous' if undefined */ 107 char *hostname; /**< host name of the local machine, defaults 108 to the value of the 'HOSTNAME' environment 109 variable or 'localhost' if undefined */ 110 111 cddb_error_t errnum; /**< error number of last CDDB command */ 112 113 list_t *query_data; /**< list to keep CDDB query results */ 114 list_t *sites_data; /**< list to keep FreeDB mirror sites */ 115 cddb_search_params_t srch; /**< parameters for text search */ 116 117 cddb_iconv_t charset; /**< character set conversion settings */ 118 }; 119 120 121 /* --- getters & setters --- */ 122 123 124 #define cddb_cache_file(c) (c)->cache_fp 125 126 127 /* --- connecting / disconnecting --- */ 128 129 130 int cddb_connect(cddb_conn_t *c); 131 132 void cddb_disconnect(cddb_conn_t *c); 133 134 135 /* --- miscellaneous --- */ 136 137 138 /** 139 * Clone proxy settings from source connection to destinaton 140 * connection. 141 */ 142 void cddb_clone_proxy(cddb_conn_t *dst, cddb_conn_t *src); 143 144 145 /* --- error handling --- */ 146 147 148 /** 149 * Set the error number for the last libcddb command. 150 * 151 * @param c The CDDB connection structure. 152 * @param n The error number 153 */ 154 #define cddb_errno_set(c, n) (c)->errnum = n 155 156 /** 157 * Set the error number for the last libcddb command. If this number 158 * is different from CDDB_ERR_OK, a message is also logged with the 159 * level specified. 160 * 161 * @param c The CDDB connection structure. 162 * @param n The error number 163 * @param l The log level 164 */ 165 #define cddb_errno_log(c, n, l) cddb_errno_set(c, n); cddb_log(l, cddb_error_str(n)) 166 167 #define cddb_errno_log_debug(c, n) cddb_errno_log(c, n, CDDB_LOG_DEBUG) 168 #define cddb_errno_log_info(c, n) cddb_errno_log(c, n, CDDB_LOG_INFO) 169 #define cddb_errno_log_warn(c, n) cddb_errno_log(c, n, CDDB_LOG_WARN) 170 #define cddb_errno_log_error(c, n) cddb_errno_log(c, n, CDDB_LOG_ERROR) 171 #define cddb_errno_log_crit(c, n) cddb_errno_log(c, n, CDDB_LOG_CRITICAL) 172 173 174 #ifdef __cplusplus 175 } 176 #endif 177 178 #endif /* CDDB_CONN_NI_H */ 179