2017-07-21 03:40:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-09-13 10:02:59 +00:00
|
|
|
#include <pthread.h>
|
2017-09-20 12:40:28 +00:00
|
|
|
#include "ipfs/core/ipfs_node.h"
|
2017-09-13 10:02:59 +00:00
|
|
|
|
2017-07-21 03:40:43 +00:00
|
|
|
#ifdef __x86_64__
|
|
|
|
#define INT_TYPE uint64_t
|
|
|
|
#else
|
|
|
|
#define INT_TYPE uint32_t
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MAX_READ (32*1024) // 32k
|
|
|
|
|
2017-09-25 13:55:42 +00:00
|
|
|
struct ApiContext {
|
2017-07-21 03:40:43 +00:00
|
|
|
int socket;
|
|
|
|
uint32_t ipv4;
|
|
|
|
uint16_t port;
|
|
|
|
int max_conns;
|
|
|
|
int timeout;
|
|
|
|
struct s_conns {
|
|
|
|
int socket;
|
|
|
|
uint32_t ipv4;
|
|
|
|
uint16_t port;
|
|
|
|
pthread_t pthread;
|
|
|
|
} **conns;
|
2017-09-25 13:55:42 +00:00
|
|
|
pthread_mutex_t conns_lock;
|
|
|
|
int conns_count;
|
|
|
|
pthread_t api_thread;
|
2017-07-21 03:40:43 +00:00
|
|
|
};
|
|
|
|
|
2017-07-24 01:24:14 +00:00
|
|
|
struct s_request {
|
|
|
|
char *buf;
|
|
|
|
size_t size;
|
|
|
|
|
2017-07-28 03:43:36 +00:00
|
|
|
int method;
|
|
|
|
int path;
|
2017-09-22 02:27:33 +00:00
|
|
|
int request;
|
|
|
|
int query;
|
2017-07-28 03:43:36 +00:00
|
|
|
int http_ver;
|
|
|
|
int header;
|
|
|
|
int body;
|
2017-07-24 01:24:14 +00:00
|
|
|
size_t body_size;
|
2017-09-08 02:59:57 +00:00
|
|
|
int boundary;
|
|
|
|
size_t boundary_size;
|
2017-07-24 01:24:14 +00:00
|
|
|
};
|
|
|
|
|
2017-09-22 02:27:33 +00:00
|
|
|
#define API_V0_START "/api/v0/"
|
|
|
|
|
2017-09-21 14:50:15 +00:00
|
|
|
#define WEBUI_ADDR "/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/"
|
|
|
|
|
|
|
|
#define HTTP_301 "HTTP/1.1 301 Moved Permanently\r\n" \
|
|
|
|
"Location: %s\r\n" \
|
|
|
|
"Content-Type: text/html\r\n\r\n" \
|
|
|
|
"<a href=\"%s\">Moved Permanently</a>.\r\n\r\n"
|
|
|
|
|
|
|
|
#define HTTP_302 "HTTP/1.1 302 Found\r\n" \
|
|
|
|
"Content-Type: text/html\r\n" \
|
|
|
|
"Connection: close\r\n" \
|
|
|
|
"Location: %s\r\n" \
|
|
|
|
"X-Ipfs-Path: %s\r\n\r\n" \
|
|
|
|
"<a href=\"%s\">Found</a>.\r\n\r\n"
|
|
|
|
|
2017-07-24 01:24:14 +00:00
|
|
|
#define HTTP_400 "HTTP/1.1 400 Bad Request\r\n" \
|
|
|
|
"Content-Type: text/plain\r\n" \
|
|
|
|
"Connection: close\r\n\r\n" \
|
|
|
|
"400 Bad Request"
|
|
|
|
|
|
|
|
#define HTTP_404 "HTTP/1.1 404 Not Found\r\n" \
|
2017-07-28 03:43:36 +00:00
|
|
|
"Content-Type: text/plain\r\n" \
|
|
|
|
"Connection: close\r\n\r\n" \
|
|
|
|
"404 page not found"
|
2017-07-24 01:24:14 +00:00
|
|
|
|
|
|
|
#define HTTP_500 "HTTP/1.1 500 Internal server error\r\n" \
|
|
|
|
"Content-Type: text/plain\r\n" \
|
|
|
|
"Connection: close\r\n\r\n" \
|
|
|
|
"500 Internal server error"
|
|
|
|
|
2017-07-28 03:43:36 +00:00
|
|
|
#define HTTP_501 "HTTP/1.1 501 Not Implemented\r\n" \
|
|
|
|
"Content-Type: text/plain\r\n" \
|
|
|
|
"Connection: close\r\n\r\n" \
|
|
|
|
"501 Not Implemented"
|
|
|
|
|
2017-07-21 03:40:43 +00:00
|
|
|
#define write_cstr(f,s) write(f,s,sizeof(s)-1)
|
|
|
|
#define write_str(f,s) write(f,s,strlen(s))
|
|
|
|
|
|
|
|
#define cstrstart(a,b) (memcmp(a,b,sizeof(b)-1)==0)
|
|
|
|
#define strstart(a,b) (memcmp(a,b,strlen(b))==0)
|
|
|
|
|
|
|
|
void *api_connection_thread (void *ptr);
|
2017-09-25 13:55:42 +00:00
|
|
|
void api_connections_cleanup (struct IpfsNode* node);
|
2017-07-21 03:40:43 +00:00
|
|
|
void *api_listen_thread (void *ptr);
|
2017-09-25 13:55:42 +00:00
|
|
|
int api_start (struct IpfsNode* local_node, int max_conns, int timeout);
|
|
|
|
int api_stop (struct IpfsNode* local_node);
|