1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#include <stdlib.h>
#include "rtclient/request.h"
#include "rtclient/client.h"
CURL *curl = NULL;
char *server_url = NULL;
bool rtclient_init(const char *url)
{
curl_global_init(CURL_GLOBAL_SSL);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
curl_easy_setopt(curl, CURLOPT_REFERER, url);
#ifdef DEBUG
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#endif
server_url = malloc(strlen(url) + 1);
strcpy(server_url, url);
}
return (bool)curl;
}
void rtclient_login(const char *name, const char *password)
{
struct curl_httppost *post, *last = NULL;
curl_formadd(&post, &last
, CURLFORM_COPYNAME, "user"
, CURLFORM_PTRCONTENTS, name
, CURLFORM_END);
curl_formadd(&post, &last
, CURLFORM_COPYNAME, "pass"
, CURLFORM_PTRCONTENTS, password
, CURLFORM_END);
last = NULL;
request("", "", NULL, NULL, post);
curl_formfree(post);
post = NULL;
}
void rtclient_cleanup()
{
if (curl) {
free(server_url);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
}
|