Rizin
unix-like reverse engineering framework and cli tools
io_http.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2008-2021 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_io.h>
5 #include <rz_lib.h>
6 #include <rz_socket.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "../io_memory.h"
10 
11 static bool __check(RzIO *io, const char *pathname, bool many) {
12  return (!strncmp(pathname, "http://", 7));
13 }
14 
15 static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) {
16  if (__check(io, pathname, 0)) {
17  int rlen, code;
19  if (!mal) {
20  return NULL;
21  }
22  mal->offset = 0;
23  mal->buf = (ut8 *)rz_socket_http_get(pathname, &code, &rlen);
24  if (mal->buf && rlen > 0) {
25  mal->size = rlen;
27  }
28  eprintf("No HTTP response\n");
29  free(mal);
30  }
31  return NULL;
32 }
33 
35  .name = "http",
36  .desc = "Make http get requests",
37  .uris = "http://",
38  .license = "LGPL3",
39  .open = __open,
40  .close = io_memory_close,
41  .read = io_memory_read,
42  .check = __check,
43  .lseek = io_memory_lseek,
44  .write = io_memory_write,
45 };
46 
47 #ifndef RZ_PLUGIN_INCORE
50  .data = &rz_io_plugin_http,
52 };
53 #endif
#define RZ_API
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static bool __check(RzIO *io, const char *pathname, bool many)
Definition: io_http.c:11
static RzIODesc * __open(RzIO *io, const char *pathname, int rw, int mode)
Definition: io_http.c:15
RzIOPlugin rz_io_plugin_http
Definition: io_http.c:34
RZ_API RzLibStruct rizin_plugin
Definition: io_http.c:48
int io_memory_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count)
Definition: io_memory.c:97
int io_memory_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
Definition: io_memory.c:56
ut64 io_memory_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence)
Definition: io_memory.c:125
int io_memory_close(RzIODesc *fd)
Definition: io_memory.c:114
const char int mode
Definition: ioapi.h:137
uint8_t ut8
Definition: lh5801.h:11
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char pathname
Definition: sflib.h:66
const char * code
Definition: pal.c:98
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API RzIODesc * rz_io_desc_new(RzIO *io, RzIOPlugin *plugin, const char *uri, int flags, int mode, void *data)
Definition: io_desc.c:11
RzIOPlugin rz_io_plugin_malloc
Definition: io_malloc.c:50
@ RZ_LIB_TYPE_IO
Definition: rz_lib.h:69
RZ_API char * rz_socket_http_get(const char *url, int *code, int *rlen)
Definition: socket_http.c:287
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_PERM_RW
Definition: rz_types.h:96
#define RZ_VERSION
Definition: rz_version.h:8
Definition: inftree9.h:24
const char * name
Definition: rz_io.h:115
const char * version
Definition: rz_io.h:117
Definition: rz_io.h:59
static struct @626 mal