c-ipfs/include/ipfs/core/http_request.h

90 lines
2.5 KiB
C
Raw Normal View History

2017-09-21 20:27:16 +00:00
#pragma once
2017-09-21 22:10:41 +00:00
#include "ipfs/core/ipfs_node.h"
2017-09-21 20:27:16 +00:00
/***
* A name/value pair of http parameters
*/
struct HttpParam {
char* name; // the name of the parameter
char* value; // the value of the parameter
};
/**
* A struct to help with incoming http requests
*/
struct HttpRequest {
char* command; // the command
char* sub_command; // the sub command
struct Libp2pVector* params; // a collection of HttpParam structs
struct Libp2pVector* arguments; // a collection of chars that are arguments
};
/***
* A struct to hold the response to be sent via http
*/
struct HttpResponse {
char* content_type; // a const char, not dynamically allocated
uint8_t* bytes; // dynamically allocated
size_t bytes_size;
};
2017-09-21 20:27:16 +00:00
/***
* Build a new HttpRequest
* @returns the newly allocated HttpRequest struct
*/
struct HttpRequest* ipfs_core_http_request_new();
/***
* Clean up resources of a HttpRequest struct
* @param request the struct to destroy
*/
void ipfs_core_http_request_free(struct HttpRequest* request);
struct HttpResponse* ipfs_core_http_response_new();
void ipfs_core_http_response_free(struct HttpResponse* response);
2017-09-21 20:27:16 +00:00
/***
* Build a new HttpParam
* @returns a newly allocated HttpParam struct
*/
struct HttpParam* ipfs_core_http_param_new();
/***
* Clean up resources allocated by a HttpParam struct
* @param param the struct to destroy
*/
void ipfs_core_http_param_free(struct HttpParam* param);
/***
* Process the parameters passed in from an http request
2017-09-21 22:10:41 +00:00
* @param local_node the context
2017-09-21 20:27:16 +00:00
* @param request the request
* @param response the response
* @returns true(1) on success, false(0) otherwise.
*/
int ipfs_core_http_request_process(struct IpfsNode* local_node, struct HttpRequest* request, struct HttpResponse** response);
2017-09-21 22:10:41 +00:00
/**
* Do an HTTP Get to the local API
* @param local_node the context
* @param request the request
* @param result the results
* @param result_size the size of the results
2017-09-21 22:10:41 +00:00
* @returns true(1) on success, false(0) on error
*/
int ipfs_core_http_request_get(struct IpfsNode* local_node, struct HttpRequest* request, char** result, size_t* result_size);
2017-10-03 15:33:30 +00:00
/**
* Do an HTTP Post to the local API
* @param local_node the context
* @param request the request
* @param result the results
2017-10-04 14:36:38 +00:00
* @param result_size the size of the results
2017-10-03 15:33:30 +00:00
* @param data the array with post data
2017-10-04 14:36:38 +00:00
* @param data_size the data length
2017-10-03 15:33:30 +00:00
* @returns true(1) on success, false(0) on error
*/
2017-10-04 14:36:38 +00:00
int ipfs_core_http_request_post(struct IpfsNode* local_node, struct HttpRequest* request, char** result, size_t* result_size, char *data, size_t data_size);