Remove I/O layer

This commit is contained in:
Julien BLACHE 2009-05-03 12:10:17 +02:00
parent 07fb43ca8c
commit ed7c848702
5 changed files with 0 additions and 2983 deletions

View File

@ -29,7 +29,6 @@ mt_daapd_SOURCES = main.c daapd.h \
scan-wma.c \ scan-wma.c \
smart-parser.c smart-parser.h \ smart-parser.c smart-parser.h \
db-sql-updates.c \ db-sql-updates.c \
io.h io.c io-errors.h io-plugin.h \
db-sql.c db-sql.h db-sql-sqlite3.c db-sql-sqlite3.h\ db-sql.c db-sql.h db-sql-sqlite3.c db-sql-sqlite3.h\
$(FLACSRC) $(MUSEPACKSRC) $(FLACSRC) $(MUSEPACKSRC)

View File

@ -1,47 +0,0 @@
/*
* Created by Ron Pedde on 2007-07-01.
* Copyright (C) 2007 Firefly Media Services. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _IO_ERRORS_H_
#define _IO_ERRORS_H_
#define IO_E_OTHER 0x00000000 /**< Native error */
#define IO_E_BADPROTO 0x01000001 /**< Bad protocol type, unhandled URI */
#define IO_E_NOTINIT 0x01000002 /**< io object not initialized with new */
#define IO_E_BADFN 0x01000003 /**< uniplemented io function */
#define IO_E_INTERNAL 0x01000004 /**< something fatal internally */
#define IO_E_FILE_OTHER 0x00000000 /**< Native error */
#define IO_E_FILE_NOTOPEN 0x02000001 /**< operation on closed file */
#define IO_E_FILE_UNKNOWN 0x02000002 /**< other inernal error */
#define IO_E_SOCKET_OTHER 0x00000000 /**< Native error */
#define IO_E_SOCKET_NOTOPEN 0x03000001 /**< operation on closed socket */
#define IO_E_SOCKET_UNKNOWN 0x03000002 /**< other internal error */
#define IO_E_SOCKET_BADHOST 0x03000003 /**< can't resolve address */
#define IO_E_SOCKET_NOTINIT 0x03000004 /**< socket not initialized with new */
#define IO_E_SOCKET_BADFN 0x03000005 /**< unimplemented io function */
#define IO_E_SOCKET_NOMCAST 0x03000006 /**< can't set up multicast */
#define IO_E_SOCKET_INVALID 0x03000007 /**< ? */
#define IO_E_SOCKET_INUSE 0x03000008 /**< EADDRINUSE */
#endif /* _IO_ERRORS_H_ */

View File

@ -1,66 +0,0 @@
/*
* Private interface for io objects to provide plug-in io objects
*/
#ifndef _IO_PLUGIN_H_
#define _IO_PLUGIN_H_
typedef struct tag_io_privhandle IO_PRIVHANDLE;
typedef struct tag_io_fnptr IO_FNPTR;
typedef struct tag_io_optionlist IO_OPTIONLIST;
#define IO_LOG_FATAL 0
#define IO_LOG_LOG 1
#define IO_LOG_WARN 3
#define IO_LOG_INFO 5
#define IO_LOG_DEBUG 9
#define IO_LOG_SPAM 10
#define WAITABLE_T int
#define SOCKET_T int
#define FILE_T int
#define ERR_T int
struct tag_io_fnptr {
int(*fn_open)(IO_PRIVHANDLE *, char *);
int(*fn_close)(IO_PRIVHANDLE *);
int(*fn_read)(IO_PRIVHANDLE *, unsigned char *, uint32_t *);
int(*fn_write)(IO_PRIVHANDLE *, unsigned char *, uint32_t *);
int(*fn_size)(IO_PRIVHANDLE *, uint64_t *);
int(*fn_setpos)(IO_PRIVHANDLE *, uint64_t, int);
int(*fn_getpos)(IO_PRIVHANDLE *, uint64_t *);
char*(*fn_geterrmsg)(IO_PRIVHANDLE *, ERR_T *, int *);
int(*fn_getwaitable)(IO_PRIVHANDLE *, int, WAITABLE_T *);
int(*fn_getfd)(IO_PRIVHANDLE *, FILE_T *);
int(*fn_getsocket)(IO_PRIVHANDLE *, SOCKET_T *);
};
struct tag_io_privhandle {
int open; /**< Whether file is open - don't touch */
ERR_T err; /**< Current error code - don't touch */
int is_local;
char *err_str; /**< Current error string - don't touch */
IO_FNPTR *fnptr; /**< Set on io_open by checking proto table */
IO_OPTIONLIST *pol; /**< List of passed options */
char *proto; /**< proto of file */
int buffering; /**< are we in linebuffer mode? */
uint32_t buffer_offset; /**< current offset pointer */
uint32_t buffer_len; /**< total size of buffer */
unsigned char *buffer; /**< linebuffer */
/**
* the following parameters should be set by the provider in
* the open function (or as soon as is practicable)
*/
void *private; /**< Private struct for implementation */
};
extern int io_register_handler(char *proto, IO_FNPTR *fnptr);
extern char* io_option_get(IO_PRIVHANDLE *phandle,char *option,char *dflt);
#ifndef TRUE
# define TRUE 1
# define FALSE 0
#endif
#endif /* _IO_PLUGIN_H_ */

2763
src/io.c

File diff suppressed because it is too large Load Diff

106
src/io.h
View File

@ -1,106 +0,0 @@
/*
* Generic IO abstraction for files, sockets, http streams, etc
*/
#ifndef _IO_H_
#define _IO_H_
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdint.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include "io-errors.h"
typedef void* IOHANDLE;
typedef void* IO_WAITHANDLE;
#define INVALID_HANDLE NULL
#define SOCKET_T int
#define FILE_T int
/*
* Valid protocol options:
*
* udplisten:
* multicast=0/1 (default 0)
* mcast_group=multicast ip (required if multicast=1)
* mcast_ttl=<n> (defaults to 4)
*
* Example URI for UPnP:
* udplisten://1900?multicast=1&mcast_group=239.255.255.250&mcast_ttl=4
*
* listen:
* backlog=<n> (default to 5)
* reuse=0/1 (defaults to 1) - SO_REUSEADDR
*/
extern int io_init(void);
extern int io_deinit(void);
extern void io_set_errhandler(void(*err_handler)(int, char *));
extern void io_set_lockhandler(void(*lock_handler)(int));
extern IOHANDLE io_new(void);
extern int io_open(IOHANDLE io, char *fmt, ...);
extern int io_close(IOHANDLE io);
extern int io_read(IOHANDLE io, unsigned char *buf, uint32_t *len);
extern int io_read_timeout(IOHANDLE io, unsigned char *buf, uint32_t *len,
uint32_t *ms);
extern int io_write(IOHANDLE io, unsigned char *buf, uint32_t *len);
extern int io_printf(IOHANDLE io, char *fmt, ...);
extern int io_size(IOHANDLE io, uint64_t *size);
extern int io_setpos(IOHANDLE io, uint64_t offset, int whence);
extern int io_getpos(IOHANDLE io, uint64_t *pos);
extern int io_buffer(IOHANDLE io); /* unimplemented */
extern int io_readline(IOHANDLE io, unsigned char *buf, uint32_t *len);
extern int io_readline_timeout(IOHANDLE io, unsigned char *buf, uint32_t *len,
uint32_t *ms);
extern char* io_errstr(IOHANDLE io);
extern int io_errcode(IOHANDLE io);
extern void io_dispose(IOHANDLE io);
/* Given a listen:// socket, accept and return the child socket.
* the child IOHANDLE should have already been allocated with io_new, and
* even on error must be io_dispose'd */
extern int io_listen_accept(IOHANDLE io, IOHANDLE child, struct in_addr *host);
/* Given an iohandle that has already been io_new'ed, attach an exising
* socket or file handle to the iohandle */
extern int io_file_attach(IOHANDLE io, FILE_T fd);
extern int io_socket_attach(IOHANDLE io, SOCKET_T fd);
/* udp equivalents to recvfrom/sendto */
extern int io_udp_recvfrom(IOHANDLE io, unsigned char *buf, uint32_t *len,
struct sockaddr_in *si_remote, socklen_t *si_len);
extern int io_udp_sendto(IOHANDLE io, unsigned char *buf, uint32_t *len,
struct sockaddr_in *si_remote, socklen_t si_len);
extern int io_isproto(IOHANDLE io, char *proto);
/* Some wrappers to level os-specific file handling */
extern int io_stat(unsigned char *file);
extern int io_find(unsigned char *file, unsigned char *current, unsigned char **returned, int len);
#define IO_WAIT_READ 1
#define IO_WAIT_WRITE 2
#define IO_WAIT_ERROR 4
extern IO_WAITHANDLE io_wait_new(void);
extern int io_wait_add(IO_WAITHANDLE wh, IOHANDLE io, int type);
extern int io_wait(IO_WAITHANDLE wh, uint32_t *ms);
extern int io_wait_status(IO_WAITHANDLE wh, IOHANDLE io);
extern int io_wait_dispose(IO_WAITHANDLE wh);
#ifndef TRUE
# define TRUE 1
# define FALSE 0
#endif
char *io_urlencode(char *str);
#endif /* _IO_H_ */