2014-07-03 00:01:46 +02:00
|
|
|
/* radare - LGPL - Copyright 2008-2014 - pancake */
|
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
|
2012-02-08 00:45:06 +01:00
|
|
|
// TODO: use RList here
|
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>
|
|
|
|
|
2014-04-29 11:10:35 -05:00
|
|
|
volatile static RIOPlugin *DEFAULT = NULL;
|
2014-05-06 01:23:06 +04:00
|
|
|
static RIOPlugin *io_static_plugins[] =
|
2009-08-22 03:11:33 +00:00
|
|
|
{ R_IO_STATIC_PLUGINS };
|
|
|
|
|
2014-04-29 11:10:35 -05:00
|
|
|
|
2012-03-07 10:43:02 +01:00
|
|
|
R_API int r_io_plugin_add(RIO *io, RIOPlugin *plugin) {
|
2009-02-05 22:08:46 +01:00
|
|
|
struct r_io_list_t *li;
|
2011-10-08 12:10:30 +02:00
|
|
|
if (!plugin || !plugin->name)
|
2009-08-22 03:11:33 +00:00
|
|
|
return R_FALSE;
|
2011-10-08 12:10:30 +02: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;
|
2011-10-08 12:10:30 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-10-08 12:10:30 +02:00
|
|
|
R_API int r_io_plugin_init(RIO *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
|
|
|
|
2011-10-08 12:10:30 +02:00
|
|
|
INIT_LIST_HEAD (&io->io_list);
|
|
|
|
for (i=0; io_static_plugins[i]; i++) {
|
2011-10-08 23:39:06 +02:00
|
|
|
if (!io_static_plugins[i]->name)
|
|
|
|
continue;
|
2010-05-28 02:44:51 +02:00
|
|
|
static_plugin = R_NEW (RIOPlugin);
|
2012-09-26 10:01:43 +02:00
|
|
|
// memory leak here: static_plugin never freed
|
2010-05-28 02:44:51 +02:00
|
|
|
memcpy (static_plugin, io_static_plugins[i], sizeof (RIOPlugin));
|
2014-04-29 11:10:35 -05:00
|
|
|
if (!strncmp (static_plugin->name, "default", 7)) {
|
2014-05-08 23:20:42 +02:00
|
|
|
if (DEFAULT) free ((void*)DEFAULT);
|
2014-04-29 11:10:35 -05:00
|
|
|
DEFAULT = static_plugin;
|
|
|
|
continue;
|
|
|
|
}
|
2010-05-28 02:44:51 +02:00
|
|
|
r_io_plugin_add (io, static_plugin);
|
|
|
|
}
|
2009-08-22 05:29:58 +00:00
|
|
|
return R_TRUE;
|
|
|
|
}
|
|
|
|
|
2014-04-29 11:10:35 -05:00
|
|
|
R_API RIOPlugin *r_io_plugin_get_default(RIO *io, const char *filename, ut8 many) {
|
|
|
|
if (!DEFAULT ||
|
|
|
|
!DEFAULT->plugin_open ||
|
|
|
|
!DEFAULT->plugin_open (io, filename, many) ) return NULL;
|
2014-06-04 22:33:56 +02:00
|
|
|
return (RIOPlugin*) DEFAULT;
|
2014-04-29 11:10:35 -05:00
|
|
|
}
|
|
|
|
|
2014-01-23 21:05:35 -06:00
|
|
|
R_API RIOPlugin *r_io_plugin_resolve(RIO *io, const char *filename, ut8 many) {
|
|
|
|
struct list_head *pos = NULL;
|
2012-09-23 21:42:10 +02: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
|
|
|
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;
|
2014-01-23 21:05:35 -06:00
|
|
|
if (il->plugin->plugin_open (io, filename, many))
|
2009-02-05 22:08:46 +01:00
|
|
|
return il->plugin;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-07 10:43:02 +01:00
|
|
|
R_API int r_io_plugin_open(RIO *io, int fd, RIOPlugin *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
|
2012-10-25 12:55:28 +02:00
|
|
|
return R_FALSE;
|
2009-02-05 22:08:46 +01:00
|
|
|
}
|
|
|
|
|
2012-03-07 10:43:02 +01:00
|
|
|
R_API int r_io_plugin_close(RIO *io, int fd, RIOPlugin *plugin) {
|
2012-10-25 12:55:28 +02:00
|
|
|
return R_FALSE;
|
2009-02-05 22:08:46 +01:00
|
|
|
}
|
|
|
|
|
2009-09-02 00:10:51 +00:00
|
|
|
// TODO: must return an r_iter ator
|
2011-10-08 12:10:30 +02:00
|
|
|
R_API int r_io_plugin_list(RIO *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");
|
2011-10-08 12:10:30 +02:00
|
|
|
list_for_each_prev (pos, &io->io_list) {
|
|
|
|
struct r_io_list_t *il = list_entry (pos, struct r_io_list_t, list);
|
|
|
|
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
|
|
|
|
2011-10-08 12:10:30 +02:00
|
|
|
R_API int r_io_plugin_generate(RIO *io) {
|
2010-03-19 14:01:37 +01:00
|
|
|
//TODO
|
|
|
|
return -1;
|
|
|
|
}
|