C Request Library
C library similar to Python requests library
Loading...
Searching...
No Matches
crequests.h
Go to the documentation of this file.
1
2#include <curl/curl.h>
3
4#ifndef C_REQUESTS_H
5
6#define C_REQUESTS_H
8#define CREQ_ERROR_SUCCESS 0
9
11#define CREQ_ERROR_MEMORY_ALLOCATION 1
12
14#define CREQ_ERROR_CURL 2
15
17#define CREQ_ERROR_SETTING_GET_PARAMS 3
18
22#define CREQ_ERROR_PARAMS_TOO_LONG 4
23
24typedef struct CREQ_GET_PARAMS CREQ_GET_PARAMS;
25
37 char * key;
38 char * value;
40};
41
42typedef struct CREQ_HEADER CREQ_HEADER;
43
44
46 char * key;
47 char * value;
49};
50
51
53
54
59
60
61
62typedef struct {
64 int verify;
65 char * ua;
67 char * url;
69 struct curl_slist * headers;
70 char method[5];
71 char * proxy;
73
82
91
92
93
94char * creq_error(CREQ_CTX *);
95CREQ_CTX * creq_init(void);
96void creq_get(CREQ_CTX * ctx, char * url);
97void creq_close(CREQ_CTX * ctx);
100void creq_set_useragent(CREQ_CTX * ctx, char * ua);
101void creq_add_param(CREQ_CTX * ctx, char * key, char * value);
102void creq_set_timeout(CREQ_CTX * ctx, long timesec);
103void creq_add_header(CREQ_CTX * ctx, char * header);
104void creq_post(CREQ_CTX * ctx, char * url);
105void creq_head(CREQ_CTX * ctx, char * url);
106void creq_set_proxy(CREQ_CTX *ctx, char * proxy);
107void creq_set_verify(CREQ_CTX * ctx, int val);
108char * creq_get_response_header(CREQ_CTX * ctx, char * header);
109/*******************utility function*******************/
110
111
112#endif
void creq_set_timeout(CREQ_CTX *ctx, long timesec)
Sets timeout for both connection and data transfer.
Definition crequests.c:337
void creq_set_proxy(CREQ_CTX *ctx, char *proxy)
Sets a proxy for sending requests.
Definition crequests.c:151
void creq_add_param(CREQ_CTX *ctx, char *key, char *value)
Sets a GET/POST param.
Definition crequests.c:953
char * creq_get_content(CREQ_CTX *)
Returns the content of the request.
Definition crequests.c:1024
char * creq_get_response_header(CREQ_CTX *ctx, char *header)
Returns the value for a given header name.
Definition crequests.c:1118
void creq_close(CREQ_CTX *ctx)
Cleans up the library and memory after using it.
Definition crequests.c:234
void creq_head(CREQ_CTX *ctx, char *url)
Sends a head request.
Definition crequests.c:758
char * creq_error(CREQ_CTX *)
Returns the possible error message.
Definition crequests.c:894
void creq_set_allow_redirects(CREQ_CTX *, int)
Tells the library if it should follow redirection.
Definition crequests.c:275
CREQ_CTX * creq_init(void)
Initialize the creq library for a new request.
Definition crequests.c:52
void creq_add_header(CREQ_CTX *ctx, char *header)
Adds a header to the header list for sending.
Definition crequests.c:111
void creq_post(CREQ_CTX *ctx, char *url)
Sends a post request.
Definition crequests.c:722
void creq_get(CREQ_CTX *ctx, char *url)
Sends a GET request to the specified URL.
Definition crequests.c:651
void creq_set_useragent(CREQ_CTX *ctx, char *ua)
Add user-agent to the request header.
Definition crequests.c:585
void creq_set_verify(CREQ_CTX *ctx, int val)
Enables/disables SSL/TLS verification.
Definition crequests.c:291
Definition crequests.h:83
CREQ_REQUEST_DATA * request
request structure
Definition crequests.h:87
CURLcode curl_code
possible curl error code
Definition crequests.h:88
CURL * handle
Internal curl handle.
Definition crequests.h:85
CREQ_RESPONSE_DATA * response
response structure
Definition crequests.h:86
int err_code
Any possible error code (0 means success)
Definition crequests.h:84
short int _is_redirection
Internal member.
Definition crequests.h:89
Structure to hold the GET/POST parameters.
Definition crequests.h:36
char * value
value of the get parameter
Definition crequests.h:38
CREQ_GET_PARAMS * next
Pointer to the next node.
Definition crequests.h:39
char * key
key of the get parameter
Definition crequests.h:37
Definition crequests.h:45
char * value
value of the hader
Definition crequests.h:47
char * key
key of the header
Definition crequests.h:46
CREQ_HEADER * next
pointer to the next node
Definition crequests.h:48
Definition crequests.h:55
char * url
URL found in 'Location' header.
Definition crequests.h:56
CREQ_REDIRECTION_CHAIN * next
pointer to the next node
Definition crequests.h:57
Definition crequests.h:62
CREQ_GET_PARAMS * params
parameters of POST & GET requests
Definition crequests.h:66
char * ua
User-Agent (will be freed by library)
Definition crequests.h:65
char * proxy
String for proxy to use.
Definition crequests.h:71
char * url
URL to get (will be freed by library)
Definition crequests.h:67
struct curl_slist * headers
curl will free this option for you
Definition crequests.h:69
int allow_redirects
Should we follow redirections?
Definition crequests.h:63
int verify
should we verify TLS/SSL connection?
Definition crequests.h:64
long request_timeout
Maximum time (in seconds) before timeout.
Definition crequests.h:68
Definition crequests.h:74
char * url
final destination URL
Definition crequests.h:76
long status_code
returned HTTP status code
Definition crequests.h:75
size_t len
Length of the body of the request.
Definition crequests.h:78
CREQ_HEADER * headers
linked-list of response headers
Definition crequests.h:79
CREQ_REDIRECTION_CHAIN * follow_chain
Linked-list of redirections.
Definition crequests.h:80
char * mem
pointer to memory we keep the body of the request
Definition crequests.h:77