* Some fixes in the rap protocol

This commit is contained in:
earada 2011-04-17 20:58:32 +02:00
parent 8069e1f509
commit 450764d0c6
4 changed files with 19 additions and 12 deletions

View File

@ -479,12 +479,14 @@ R_API int r_core_serve(RCore *core, RIODesc *file) {
int i, pipefd;
ut64 x;
RSocket *c, *fd;
RIORap *rior;
fd = (RSocket *)file->data;
if (fd == NULL) {
rior = (RIORap *)file->data;
if (rior == NULL|| rior->fd == NULL) {
eprintf ("rap: cannot listen.\n");
return -1;
}
fd = rior->fd;
eprintf ("RAP Server started (rap.loop=%s)\n", r_config_get (core->config, "rap.loop"));
#if __UNIX__
@ -502,7 +504,7 @@ reaccept:
}
eprintf ("rap: client connected\n");
r_io_accept (core->io, c->fd);
//r_io_accept (core->io, c->fd); //FIXME: Useless ??
for (;;) {
i = r_socket_read (c, &cmd, 1);
if (i==0) {
@ -537,6 +539,7 @@ reaccept:
} else {
pipefd = -1;
eprintf ("Cannot open file (%s)\n", ptr);
return NULL; //XXX: Close conection and goto accept
}
}
buf[0] = RMT_OPEN | RMT_REPLY;

View File

@ -230,7 +230,7 @@ R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int mode, ut64 loa
if (fd == NULL)
return NULL;
if (r_io_is_listener (r->io)) {
r_core_serve (r, r->io->fd);
r_core_serve (r, fd);
return NULL;
}

View File

@ -3,6 +3,7 @@
#include <r_types.h>
#include <r_util.h>
#include <r_socket.h>
#include <list.h>
#define R_IO_READ 4
@ -48,6 +49,12 @@ typedef struct r_io_desc_t {
struct r_io_plugin_t *plugin;
} RIODesc;
typedef struct {
RSocket *fd;
RSocket *client;
int listener;
} RIORap;
// enum?
#define R_IO_DESC_TYPE_OPENED 1
#define R_IO_DESC_TYPE_CLOSED 0

View File

@ -10,11 +10,6 @@
// XXX: if in listener mode we need to use fd or fdlistener to listen or accept
// go fruit yourself
#define ENDIAN (0)
typedef struct {
RSocket *fd;
RSocket *client;
int listener;
} RIORap;
#define RIORAP_FD(x) ((x->data)?(((RIORap*)(x->data))->client):NULL)
#define RIORAP_IS_LISTEN(x) (((RIORap*)(x->data))->listener)
#define RIORAP_IS_VALID(x) ((x) && (x->data) && (x->plugin == &r_io_plugin_rap))
@ -25,7 +20,7 @@ static int rap__write(struct r_io_t *io, RIODesc *fd, const ut8 *buf, int count)
ut8 *tmp;
if (count>RMT_MAX)
count = RMT_MAX;
if ((tmp = (ut8 *)malloc (count+5))) {
if ((tmp = (ut8 *)malloc (count+5))) {
eprintf ("rap__write: malloc failed\n");
return -1;
}
@ -157,6 +152,8 @@ static RIODesc *rap__open(struct r_io_t *io, const char *pathname, int rw, int m
rior = R_NEW (RIORap);
rior->listener = R_TRUE;
rior->client = rior->fd = r_socket_listen (port, R_FALSE, NULL);
if (rior->fd == NULL)
return NULL;
// TODO: listen mode is broken.. here must go the root loop!!
#warning TODO: implement rap:/:9999 listen mode
return r_io_desc_new (&r_io_plugin_rap, rior->fd->fd, pathname, rw, mode, rior);
@ -185,7 +182,7 @@ static RIODesc *rap__open(struct r_io_t *io, const char *pathname, int rw, int m
}
r_mem_copyendian ((ut8 *)&i, (ut8*)buf+1, 4, ENDIAN);
if (i>0) eprintf ("ok\n");
}
} else return NULL;
return r_io_desc_new (&r_io_plugin_rap, rior->fd->fd, pathname, rw, mode, rior);
}