2010-11-11 02:00:10 +01:00
|
|
|
/* radare - LGPL - Copyright 2008-2010 pancake<nopcode.org> */
|
2009-02-05 22:08:46 +01:00
|
|
|
|
|
|
|
/* TODO: write li->fds setter/getter helpers */
|
2010-11-11 02:00:10 +01:00
|
|
|
// TODO: return true/false everywhere,, not -1 or 0
|
2009-02-05 22:08:46 +01:00
|
|
|
|
|
|
|
#include "r_io.h"
|
2009-08-22 03:11:33 +00:00
|
|
|
#include "../config.h"
|
2009-02-05 22:08:46 +01:00
|
|
|
#include "list.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2010-05-26 01:42:22 +02:00
|
|
|
static struct r_io_plugin_t *io_static_plugins[] =
|
2009-08-22 03:11:33 +00:00
|
|
|
{ R_IO_STATIC_PLUGINS };
|
|
|
|
|
2010-05-26 18:25:35 +02:00
|
|
|
R_API int r_io_plugin_add(struct r_io_t *io, struct r_io_plugin_t *plugin) {
|
2009-02-05 22:08:46 +01:00
|
|
|
struct r_io_list_t *li;
|
2009-08-22 03:11:33 +00:00
|
|
|
if (plugin == NULL)
|
|
|
|
return R_FALSE;
|
2010-03-12 13:35:10 +01:00
|
|
|
li = R_NEW(struct r_io_list_t);
|
2009-02-05 22:08:46 +01:00
|
|
|
if (li == NULL)
|
2009-08-22 03:11:33 +00:00
|
|
|
return R_FALSE;
|
2009-02-05 22:08:46 +01:00
|
|
|
li->plugin = plugin;
|
|
|
|
list_add_tail(&(li->list), &(io->io_list));
|
2009-08-22 03:11:33 +00:00
|
|
|
return R_TRUE;
|
2009-02-05 22:08:46 +01:00
|
|
|
}
|
|
|
|
|
2010-05-26 18:25:35 +02:00
|
|
|
R_API int r_io_plugin_init(struct r_io_t *io) {
|
2010-05-28 02:44:51 +02:00
|
|
|
RIOPlugin *static_plugin;
|
2009-08-22 05:29:58 +00:00
|
|
|
int i;
|
2010-05-28 02:44:51 +02:00
|
|
|
|
2009-08-22 05:29:58 +00:00
|
|
|
INIT_LIST_HEAD(&io->io_list);
|
2010-05-28 02:44:51 +02:00
|
|
|
for (i=0;io_static_plugins[i];i++) {
|
|
|
|
static_plugin = R_NEW (RIOPlugin);
|
|
|
|
memcpy (static_plugin, io_static_plugins[i], sizeof (RIOPlugin));
|
|
|
|
r_io_plugin_add (io, static_plugin);
|
|
|
|
}
|
2009-08-22 05:29:58 +00:00
|
|
|
return R_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-05-26 18:25:35 +02:00
|
|
|
R_API struct r_io_plugin_t *r_io_plugin_resolve(struct r_io_t *io, const char *filename) {
|
2009-02-05 22:08:46 +01:00
|
|
|
struct list_head *pos;
|
|
|
|
list_for_each_prev(pos, &io->io_list) {
|
|
|
|
struct r_io_list_t *il = list_entry(pos, struct r_io_list_t, list);
|
2009-08-22 04:54:41 +00:00
|
|
|
if (il->plugin == NULL)
|
|
|
|
continue;
|
2010-05-27 00:57:25 +02:00
|
|
|
if (il->plugin->plugin_open == NULL)
|
2009-08-22 04:54:41 +00:00
|
|
|
continue;
|
2010-05-27 00:57:25 +02:00
|
|
|
if (il->plugin->plugin_open(io, filename))
|
2009-02-05 22:08:46 +01:00
|
|
|
return il->plugin;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-20 22:52:16 +01:00
|
|
|
/*
|
|
|
|
DEPRECATED
|
2010-05-26 18:25:35 +02:00
|
|
|
R_API struct r_io_plugin_t *r_io_plugin_resolve_fd(struct r_io_t *io, int fd) {
|
2009-02-05 22:08:46 +01:00
|
|
|
int i;
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-01-20 22:52:16 +01:00
|
|
|
*/
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2010-05-26 18:25:35 +02:00
|
|
|
R_API int r_io_plugin_open(struct r_io_t *io, int fd, struct r_io_plugin_t *plugin) {
|
2011-01-20 22:52:16 +01:00
|
|
|
#if 0
|
2009-02-05 22:08:46 +01:00
|
|
|
int i=0;
|
|
|
|
struct list_head *pos;
|
|
|
|
list_for_each_prev(pos, &io->io_list) {
|
|
|
|
struct r_io_list_t *il = list_entry(pos, struct r_io_list_t, list);
|
|
|
|
if (plugin == il->plugin) {
|
|
|
|
for(i=0;i<R_IO_NFDS;i++) {
|
|
|
|
if (il->plugin->fds[i] == -1) {
|
|
|
|
il->plugin->fds[i] = fd;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
2011-01-20 22:52:16 +01:00
|
|
|
#endif
|
|
|
|
return 0;
|
2009-02-05 22:08:46 +01:00
|
|
|
}
|
|
|
|
|
2010-05-26 18:25:35 +02:00
|
|
|
R_API int r_io_plugin_close(struct r_io_t *io, int fd, struct r_io_plugin_t *plugin) {
|
2011-01-20 22:52:16 +01:00
|
|
|
return 0;
|
2009-02-05 22:08:46 +01:00
|
|
|
}
|
|
|
|
|
2009-09-02 00:10:51 +00:00
|
|
|
// TODO: must return an r_iter ator
|
2010-05-26 18:25:35 +02:00
|
|
|
R_API int r_io_plugin_list(struct r_io_t *io) {
|
2009-02-05 22:08:46 +01:00
|
|
|
int n = 0;
|
|
|
|
struct list_head *pos;
|
2010-05-27 00:57:25 +02:00
|
|
|
io->printf ("IO plugins:\n");
|
2009-02-05 22:08:46 +01:00
|
|
|
list_for_each_prev(pos, &io->io_list) {
|
|
|
|
struct r_io_list_t *il = list_entry(pos, struct r_io_list_t, list);
|
2009-08-22 04:54:41 +00:00
|
|
|
io->printf(" - %s\n", il->plugin->name);
|
2009-02-05 22:08:46 +01:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
2010-03-19 14:01:37 +01:00
|
|
|
|
2010-05-26 18:25:35 +02:00
|
|
|
R_API int r_io_plugin_generate(struct r_io_t *io) {
|
2010-03-19 14:01:37 +01:00
|
|
|
//TODO
|
|
|
|
return -1;
|
|
|
|
}
|