Skip to content

Commit

Permalink
lef
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Jun 20, 2024
1 parent f85e320 commit 2b1589c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
23 changes: 21 additions & 2 deletions libr/core/cmd_cmp.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static RCoreHelpMessage help_msg_cu = {
"cu8", " $$+1 > p", "compare qwords from current seek and +1",
"cud", " $$+1 > p", "compare disasm current seek and +1",
"wu", " p", "apply unified hex patch (see output of cu)",
"curl", " [http-url]", "",
"curl", " ([-D data]) [http-url]", "",
NULL
};

Expand Down Expand Up @@ -1079,12 +1079,31 @@ static void cmd_curl(RCore *core, const char *arg) {
if (r_sys_getenv_asbool ("R2_CURL")) {
r_sys_cmdf ("curl %s", arg);
} else {
char *postdata = NULL;
arg = r_str_trim_head_ro (arg);
if (r_str_startswith (arg, "-D")) {
if (arg[2] == ' ') {
arg = r_str_trim_head_ro (arg + 2);
const char *space = strchr (arg, ' ');
if (space) {
postdata = r_str_ndup (arg, space - arg);
arg = space + 1;
}
}
if (!postdata) {
r_core_cmd_help_match (core, help_msg_cu, "curl");
return;
}
}
if (r_str_startswith (arg, "http://") || r_str_startswith (arg, "https://")) {
int len;
char *s = r_socket_http_get (arg, NULL, &len);
char *s = postdata
? r_socket_http_post (arg, postdata, NULL, &len)
: r_socket_http_get (arg, NULL, &len);
if (s) {
r_cons_write (s, len);
free (s);
r_cons_newline ();
}
} else {
r_core_cmd_help_match (core, help_msg_cu, "curl");
Expand Down
39 changes: 11 additions & 28 deletions libr/socket/socket_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,16 @@ static char *socket_http_answer(RSocket *s, int *code, int *rlen, ut32 redirecti
} else {
len = olen - (dn - buf);
}
if (len == 0 || 1) {
char *res = calloc (olen, 1);
int total = 0;
do {
r_socket_block_time (s, true, 0, 0);
ret = r_socket_read (s, (ut8*) res + total, olen - total);
if (ret == -1) {
R_LOG_ERROR ("-1");
break;
}
if (ret == 0) {
continue;
}
total += ret;
} while (total < olen);
eprintf ("%d\n", total);
return res;
if (len == 0) {
eprintf ("LEN = 0\n");
}
eprintf ("LEN I%d\n", len);
if (len > 0) {
eprintf ("READING %d\n", len);
if (len > olen) {
res = malloc (len + 2);
if (!res) {
goto exit;
}
olen -= dn - buf;
olen -= (dn - buf);
memcpy (res, dn + delta, olen);
do {
ret = r_socket_read_block (s, (ut8*) res + olen, len - olen);
Expand Down Expand Up @@ -322,16 +305,16 @@ R_API char *r_socket_http_post(const char *url, const char *data, int *code, int
}
host += 3;
char *port = strchr (host, ':');
if (!port) {
port = (ssl)? "443": "80";
} else {
*port++ = 0;
}
char *path = strchr (host, '/');
if (!path) {
path = "";
if (port && (!path || (path && port < path))) {
*port++ = 0;
} else {
port = ssl? "443": "80";
}
if (path) {
*path++ = 0;
} else {
path = "";
}
s = r_socket_new (ssl);
if (!s) {
Expand All @@ -353,7 +336,7 @@ R_API char *r_socket_http_post(const char *url, const char *data, int *code, int
"Host: %s:%d\r\n"
"Content-Length: %i\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"\r\n", path, host, atoi(port), (int)strlen (data));
"\r\n", path, host, atoi (port), (int)strlen (data));
free (uri);
r_socket_write (s, (void *)data, strlen (data));
return socket_http_answer (s, code, rlen, 0);
Expand Down

0 comments on commit 2b1589c

Please sign in to comment.