1 /* radare - LGPL - Copyright 2008-2021 - pancake */
2
3 #include "r_io.h"
4 #include "r_lib.h"
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include "../io_memory.h"
8
__check(RIO * io,const char * pathname,bool many)9 static bool __check(RIO *io, const char *pathname, bool many) {
10 return (!strncmp (pathname, "http://", 7));
11 }
12
__open(RIO * io,const char * pathname,int rw,int mode)13 static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
14 if (__check (io, pathname, 0)) {
15 int rlen, code;
16 RIOMalloc *mal = R_NEW0 (RIOMalloc);
17 if (!mal) {
18 return NULL;
19 }
20 mal->offset = 0;
21 mal->buf = (ut8*)r_socket_http_get (pathname, &code, &rlen);
22 if (mal->buf && rlen > 0) {
23 mal->size = rlen;
24 return r_io_desc_new (io, &r_io_plugin_malloc, pathname, R_PERM_RW | rw, mode, mal);
25 }
26 eprintf ("No HTTP response\n");
27 free (mal);
28 }
29 return NULL;
30 }
31
32 RIOPlugin r_io_plugin_http = {
33 .name = "http",
34 .desc = "Make http get requests",
35 .uris = "http://",
36 .license = "LGPL3",
37 .open = __open,
38 .close = io_memory_close,
39 .read = io_memory_read,
40 .check = __check,
41 .lseek = io_memory_lseek,
42 .write = io_memory_write,
43 };
44
45 #ifndef R2_PLUGIN_INCORE
46 R_API RLibStruct radare_plugin = {
47 .type = R_LIB_TYPE_IO,
48 .data = &r_io_plugin_http,
49 .version = R2_VERSION
50 };
51 #endif
52