2014-03-27 15:34:17 +00:00
|
|
|
#ifndef R2_SOCKET_H
|
|
|
|
#define R2_SOCKET_H
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2011-03-27 15:44:27 +00:00
|
|
|
#include "r_types.h"
|
2013-06-18 10:09:23 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-06-14 00:51:33 +00:00
|
|
|
R_LIB_VERSION_HEADER(r_socket);
|
2011-03-27 15:44:27 +00:00
|
|
|
|
2014-06-25 10:22:27 +00:00
|
|
|
#if __UNIX__ || __CYGWIN__
|
2011-05-05 01:41:57 +00:00
|
|
|
#include <netinet/in.h>
|
2014-04-21 10:55:34 +00:00
|
|
|
#include <sys/un.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <sys/socket.h>
|
2011-05-05 01:41:57 +00:00
|
|
|
#endif
|
2014-04-21 10:55:34 +00:00
|
|
|
|
2011-04-15 07:22:34 +00:00
|
|
|
#if HAVE_LIB_SSL
|
2011-03-21 00:47:17 +00:00
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#include <openssl/err.h>
|
2011-03-27 15:44:27 +00:00
|
|
|
#endif
|
2009-07-24 13:38:53 +00:00
|
|
|
|
2014-08-08 15:39:50 +00:00
|
|
|
#if defined(__WINDOWS__) && !defined(__CYGWIN__) && !defined(MINGW32)
|
2014-04-21 10:55:34 +00:00
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#endif
|
|
|
|
|
2011-03-21 00:47:17 +00:00
|
|
|
typedef struct r_socket_t {
|
|
|
|
int fd;
|
|
|
|
int is_ssl;
|
2012-09-06 01:12:54 +00:00
|
|
|
int local; // TODO: merge ssl with local -> flags/options
|
2013-10-04 11:57:49 +00:00
|
|
|
int port;
|
2013-02-25 00:47:55 +00:00
|
|
|
struct sockaddr_in sa;
|
2011-04-15 07:22:34 +00:00
|
|
|
#if HAVE_LIB_SSL
|
2011-03-21 00:47:17 +00:00
|
|
|
SSL_CTX *ctx;
|
|
|
|
SSL *sfd;
|
2011-03-27 15:44:27 +00:00
|
|
|
BIO *bio;
|
|
|
|
#endif
|
2011-03-21 00:47:17 +00:00
|
|
|
} RSocket;
|
2009-10-12 15:41:52 +00:00
|
|
|
|
2011-05-05 15:32:56 +00:00
|
|
|
#define R_SOCKET_PROTO_TCP IPPROTO_TCP
|
|
|
|
#define R_SOCKET_PROTO_UDP IPPROTO_UDP
|
|
|
|
#define R_SOCKET_PROTO_UNIX 0x1337
|
|
|
|
|
2010-01-26 00:28:33 +00:00
|
|
|
#ifdef R_API
|
2011-04-06 07:29:25 +00:00
|
|
|
R_API RSocket *r_socket_new_from_fd (int fd);
|
2011-05-05 01:41:57 +00:00
|
|
|
R_API RSocket *r_socket_new (int is_ssl);
|
2012-10-25 19:40:11 +00:00
|
|
|
R_API int r_socket_connect (RSocket *s, const char *host, const char *port, int proto, int timeout);
|
|
|
|
#define r_socket_connect_tcp(a,b,c,d) r_socket_connect(a,b,c,R_SOCKET_PROTO_TCP,d)
|
|
|
|
#define r_socket_connect_udp(a,b,c,d) r_socket_connect(a,b,c,R_SOCKET_PROTO_UDP,d)
|
2009-10-12 15:41:52 +00:00
|
|
|
#if __UNIX__
|
2011-05-05 15:32:56 +00:00
|
|
|
#define r_socket_connect_unix(a,b) r_socket_connect(a,b,NULL,R_SOCKET_PROTO_UNIX)
|
|
|
|
R_API int r_socket_unix_listen (RSocket *s, const char *file);
|
2009-10-12 15:41:52 +00:00
|
|
|
#endif
|
2013-10-04 11:57:49 +00:00
|
|
|
R_API int r_socket_port_by_name(const char *name);
|
2011-05-05 15:32:56 +00:00
|
|
|
R_API int r_socket_close (RSocket *s);
|
|
|
|
R_API int r_socket_free (RSocket *s);
|
2011-05-05 01:41:57 +00:00
|
|
|
R_API int r_socket_listen (RSocket *s, const char *port, const char *certfile);
|
2011-03-21 00:47:17 +00:00
|
|
|
R_API RSocket *r_socket_accept (RSocket *s);
|
2011-05-05 01:41:57 +00:00
|
|
|
R_API int r_socket_block_time (RSocket *s, int block, int sec);
|
2011-03-21 00:47:17 +00:00
|
|
|
R_API int r_socket_flush (RSocket *s);
|
|
|
|
R_API int r_socket_ready (RSocket *s, int secs, int usecs);
|
|
|
|
R_API char *r_socket_to_string (RSocket *s);
|
|
|
|
R_API int r_socket_write (RSocket *s, void *buf, int len);
|
|
|
|
R_API int r_socket_puts (RSocket *s, char *buf);
|
|
|
|
R_API void r_socket_printf (RSocket *s, const char *fmt, ...);
|
2011-04-06 07:29:25 +00:00
|
|
|
R_API int r_socket_read (RSocket *s, ut8 *read, int len);
|
2011-03-21 00:47:17 +00:00
|
|
|
R_API int r_socket_read_block (RSocket *s, unsigned char *buf, int len);
|
|
|
|
R_API int r_socket_gets (RSocket *s, char *buf, int size);
|
2013-07-24 06:58:10 +00:00
|
|
|
R_API int r_socket_is_connected (RSocket *);
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2010-01-26 00:28:33 +00:00
|
|
|
/* process */
|
2010-03-30 15:37:15 +00:00
|
|
|
typedef struct r_socket_proc_t {
|
2010-01-26 00:28:33 +00:00
|
|
|
int fd0[2];
|
|
|
|
int fd1[2];
|
|
|
|
int pid;
|
2010-03-30 15:37:15 +00:00
|
|
|
} RSocketProc;
|
2010-01-26 00:28:33 +00:00
|
|
|
|
2014-05-08 21:20:42 +00:00
|
|
|
R_API RSocketProc *r_socket_proc_open(char* const argv[]);
|
2010-03-30 15:37:15 +00:00
|
|
|
R_API int r_socket_proc_close(RSocketProc *sp);
|
2011-03-21 00:47:17 +00:00
|
|
|
R_API int r_socket_proc_read (RSocketProc *sp, unsigned char *buf, int len);
|
|
|
|
R_API int r_socket_proc_gets (RSocketProc *sp, char *buf, int size);
|
|
|
|
R_API int r_socket_proc_write (RSocketProc *sp, void *buf, int len);
|
|
|
|
R_API void r_socket_proc_printf (RSocketProc *sp, const char *fmt, ...);
|
|
|
|
R_API int r_socket_proc_ready (RSocketProc *sp, int secs, int usecs);
|
2010-01-26 00:28:33 +00:00
|
|
|
|
2011-10-06 23:16:45 +00:00
|
|
|
/* HTTP */
|
|
|
|
R_API char *r_socket_http_get (const char *url, int *code, int *rlen);
|
|
|
|
R_API char *r_socket_http_post (const char *url, const char *data, int *code, int *rlen);
|
2012-09-06 01:12:54 +00:00
|
|
|
|
|
|
|
typedef struct r_socket_http_request {
|
|
|
|
RSocket *s;
|
|
|
|
char *path;
|
|
|
|
char *host;
|
|
|
|
char *agent;
|
|
|
|
char *method;
|
|
|
|
ut8 *data;
|
|
|
|
int data_length;
|
|
|
|
} RSocketHTTPRequest;
|
|
|
|
|
2012-12-03 03:01:55 +00:00
|
|
|
R_API RSocketHTTPRequest *r_socket_http_accept (RSocket *s, int timeout);
|
2012-10-03 10:10:18 +00:00
|
|
|
R_API void r_socket_http_response (RSocketHTTPRequest *rs, int code, const char *out, int x, const char *headers);
|
2012-09-06 01:12:54 +00:00
|
|
|
R_API void r_socket_http_close (RSocketHTTPRequest *rs);
|
2013-01-03 00:43:23 +00:00
|
|
|
R_API ut8 *r_socket_http_handle_upload(const ut8 *str, int len, int *olen);
|
2014-05-05 10:32:10 +00:00
|
|
|
|
2014-05-05 12:38:47 +00:00
|
|
|
typedef int (*rap_server_open)(void *user, const char *file, int flg, int mode);
|
2014-05-05 10:32:10 +00:00
|
|
|
typedef int (*rap_server_seek)(void *user, ut64 offset, int whence);
|
|
|
|
typedef int (*rap_server_read)(void *user, ut8 *buf, int len);
|
|
|
|
typedef int (*rap_server_write)(void *user, ut8 *buf, int len);
|
2014-05-05 22:25:29 +00:00
|
|
|
typedef char *(*rap_server_cmd)(void *user, const char *command);
|
2014-05-05 10:32:10 +00:00
|
|
|
typedef int (*rap_server_close)(void *user, int fd);
|
|
|
|
|
|
|
|
enum {
|
|
|
|
RAP_RMT_OPEN = 0x01,
|
|
|
|
RAP_RMT_READ,
|
|
|
|
RAP_RMT_WRITE,
|
|
|
|
RAP_RMT_SEEK,
|
|
|
|
RAP_RMT_CLOSE,
|
|
|
|
RAP_RMT_SYSTEM,
|
|
|
|
RAP_RMT_CMD,
|
|
|
|
RAP_RMT_REPLY = 0x80,
|
|
|
|
RAP_RMT_MAX = 4096
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct r_socket_rap_server_t {
|
|
|
|
RSocket *fd;
|
|
|
|
char port[5];
|
|
|
|
ut8 buf[4101]; //This should be used as a static buffer for everything done by the server
|
|
|
|
rap_server_open open;
|
|
|
|
rap_server_seek seek;
|
|
|
|
rap_server_read read;
|
|
|
|
rap_server_write write;
|
|
|
|
rap_server_cmd system;
|
|
|
|
rap_server_cmd cmd;
|
|
|
|
rap_server_close close;
|
2014-12-05 23:31:28 +00:00
|
|
|
void *user; //Always first arg for callbacks
|
2014-05-05 10:32:10 +00:00
|
|
|
} RSocketRapServer;
|
|
|
|
|
|
|
|
R_API RSocketRapServer *r_socket_rap_server_new (int is_ssl, const char *port);
|
2014-05-05 12:38:47 +00:00
|
|
|
R_API RSocketRapServer *r_socket_rap_server_create (const char *pathname);
|
2014-05-05 10:32:10 +00:00
|
|
|
R_API void r_socket_rap_server_free (RSocketRapServer *rap_s);
|
2014-05-05 12:38:47 +00:00
|
|
|
R_API int r_socket_rap_server_listen (RSocketRapServer *rap_s, const char *certfile);
|
2014-06-04 20:33:56 +00:00
|
|
|
R_API RSocket* r_socket_rap_server_accept (RSocketRapServer *rap_s);
|
2014-05-05 10:32:10 +00:00
|
|
|
R_API int r_socket_rap_server_continue (RSocketRapServer *rap_s);
|
|
|
|
|
2014-07-09 00:24:31 +00:00
|
|
|
/* run.c */
|
|
|
|
#define R_RUN_PROFILE_NARGS 512
|
|
|
|
typedef struct r_run_profile_t {
|
|
|
|
char *_args[R_RUN_PROFILE_NARGS];
|
|
|
|
char *_system;
|
|
|
|
char *_program;
|
|
|
|
char *_stdin;
|
|
|
|
char *_stdout;
|
|
|
|
char *_stderr;
|
|
|
|
char *_chgdir;
|
|
|
|
char *_chroot;
|
|
|
|
char *_libpath;
|
|
|
|
char *_preload;
|
|
|
|
int _bits;
|
2014-11-22 02:00:31 +00:00
|
|
|
int _pid;
|
2014-07-09 00:24:31 +00:00
|
|
|
int _r2preload;
|
|
|
|
int _docore;
|
|
|
|
int _aslr;
|
|
|
|
int _maxstack;
|
|
|
|
int _maxproc;
|
|
|
|
int _maxfd;
|
|
|
|
int _r2sleep;
|
|
|
|
char *_setuid;
|
|
|
|
char *_seteuid;
|
|
|
|
char *_setgid;
|
|
|
|
char *_setegid;
|
|
|
|
char *_input;
|
|
|
|
char *_connect;
|
|
|
|
char *_listen;
|
|
|
|
int _timeout;
|
|
|
|
} RRunProfile;
|
|
|
|
|
|
|
|
R_API RRunProfile *r_run_new(const char *str);
|
|
|
|
R_API int r_run_parseline (RRunProfile *p, char *b);
|
|
|
|
R_API int r_run_parse(RRunProfile *pf, const char *profile);
|
|
|
|
R_API void r_run_free (RRunProfile *r);
|
|
|
|
R_API int r_run_parseline (RRunProfile *p, char *b);
|
2015-01-13 02:40:01 +00:00
|
|
|
R_API const char *r_run_help(void);
|
2014-07-09 00:24:31 +00:00
|
|
|
R_API int r_run_start(RRunProfile *p);
|
2014-07-09 01:48:47 +00:00
|
|
|
R_API void r_run_reset(RRunProfile *p);
|
2014-07-09 03:05:22 +00:00
|
|
|
R_API int r_run_parsefile (RRunProfile *p, const char *b);
|
2014-07-09 00:24:31 +00:00
|
|
|
|
2010-01-26 00:28:33 +00:00
|
|
|
#endif
|
2013-06-18 10:09:23 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-05 21:08:46 +00:00
|
|
|
#endif
|