Mercurial
annotate seobeo/s_http_client.c @ 192:b818a4561a3c hg-web
Added AI genreated README.md. Needed to be read.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Sat, 24 Jan 2026 21:52:14 -0800 |
| parents | 71ad34a8bc9a |
| children |
| rev | line source |
|---|---|
|
119
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
1 #include "seobeo/seobeo.h" |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
2 #include <ctype.h> |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
3 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
4 static void Seobeo_Client_Parse_Url(const char *url, char **p_host, |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
5 char **p_port, char **p_path, boolean *p_use_tls, Dowa_Arena *p_arena) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
6 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
7 if (!url) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
8 return; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
9 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
10 const char *start = url; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
11 *p_use_tls = FALSE; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
12 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
13 if (strncmp(url, "https://", 8) == 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
14 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
15 *p_use_tls = TRUE; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
16 start = url + 8; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
17 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
18 else if (strncmp(url, "http://", 7) == 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
19 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
20 *p_use_tls = FALSE; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
21 start = url + 7; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
22 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
23 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
24 const char *slash = strchr(start, '/'); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
25 const char *colon = strchr(start, ':'); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
26 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
27 if (colon && (!slash || colon < slash)) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
28 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
29 size_t host_len = colon - start; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
30 *p_host = Dowa_Arena_Allocate(p_arena, host_len + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
31 memcpy(*p_host, start, host_len); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
32 (*p_host)[host_len] = '\0'; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
33 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
34 const char *port_start = colon + 1; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
35 size_t port_len = slash ? (slash - port_start) : strlen(port_start); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
36 *p_port = Dowa_Arena_Allocate(p_arena, port_len + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
37 memcpy(*p_port, port_start, port_len); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
38 (*p_port)[port_len] = '\0'; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
39 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
40 else |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
41 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
42 size_t host_len = slash ? (slash - start) : strlen(start); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
43 *p_host = Dowa_Arena_Allocate(p_arena, host_len + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
44 memcpy(*p_host, start, host_len); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
45 (*p_host)[host_len] = '\0'; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
46 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
47 *p_port = Dowa_Arena_Allocate(p_arena, 8); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
48 strcpy(*p_port, *p_use_tls ? "443" : "80"); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
49 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
50 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
51 if (slash) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
52 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
53 size_t path_len = strlen(slash); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
54 *p_path = Dowa_Arena_Allocate(p_arena, path_len + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
55 strcpy(*p_path, slash); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
56 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
57 else |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
58 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
59 *p_path = Dowa_Arena_Allocate(p_arena, 2); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
60 strcpy(*p_path, "/"); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
61 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
62 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
63 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
64 Seobeo_Client_Request *Seobeo_Client_Request_Create(const char *url) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
65 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
66 Seobeo_Client_Request *p_req = malloc(sizeof(Seobeo_Client_Request)); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
67 if (!p_req) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
68 return NULL; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
69 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
70 memset(p_req, 0, sizeof(Seobeo_Client_Request)); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
71 |
|
175
71ad34a8bc9a
[HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents:
168
diff
changeset
|
72 p_req->p_arena = Dowa_Arena_Create(1024 * 1024 * 5); |
|
119
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
73 if (!p_req->p_arena) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
74 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
75 free(p_req); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
76 return NULL; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
77 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
78 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
79 size_t url_len = strlen(url); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
80 p_req->url = Dowa_Arena_Allocate(p_req->p_arena, url_len + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
81 strcpy(p_req->url, url); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
82 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
83 Seobeo_Client_Parse_Url(url, &p_req->host, &p_req->port, &p_req->path, &p_req->use_tls, p_req->p_arena); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
84 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
85 p_req->method = Dowa_Arena_Allocate(p_req->p_arena, 4); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
86 strcpy(p_req->method, "GET"); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
87 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
88 p_req->follow_redirects = FALSE; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
89 p_req->max_redirects = 10; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
90 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
91 return p_req; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
92 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
93 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
94 void Seobeo_Client_Request_Set_Method(Seobeo_Client_Request *p_req, const char *method) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
95 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
96 if (!p_req || !method) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
97 return; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
98 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
99 size_t len = strlen(method); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
100 p_req->method = Dowa_Arena_Allocate(p_req->p_arena, len + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
101 strcpy(p_req->method, method); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
102 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
103 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
104 void Seobeo_Client_Request_Add_Header_Map(Seobeo_Client_Request *p_req, const char *key, const char *value) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
105 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
106 if (!p_req || !key || !value) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
107 return; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
108 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
109 char *key_copy = Dowa_Arena_Allocate(p_req->p_arena, strlen(key) + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
110 strcpy(key_copy, key); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
111 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
112 char *value_copy = Dowa_Arena_Allocate(p_req->p_arena, strlen(value) + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
113 strcpy(value_copy, value); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
114 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
115 Dowa_HashMap_Push_Arena(p_req->headers_map, key_copy, value_copy, p_req->p_arena); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
116 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
117 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
118 void Seobeo_Client_Request_Add_Header_Array(Seobeo_Client_Request *p_req, const char *header) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
119 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
120 if (!p_req || !header) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
121 return; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
122 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
123 char *header_copy = Dowa_Arena_Allocate(p_req->p_arena, strlen(header) + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
124 strcpy(header_copy, header); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
125 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
126 Dowa_Array_Push_Arena(p_req->headers_array, header_copy, p_req->p_arena); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
127 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
128 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
129 void Seobeo_Client_Request_Set_Body(Seobeo_Client_Request *p_req, const char *body, size_t length) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
130 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
131 if (!p_req || !body) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
132 return; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
133 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
134 if (length == 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
135 length = strlen(body); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
136 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
137 p_req->body = Dowa_Arena_Allocate(p_req->p_arena, length + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
138 memcpy(p_req->body, body, length); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
139 p_req->body[length] = '\0'; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
140 p_req->body_length = length; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
141 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
142 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
143 void Seobeo_Client_Request_Set_Follow_Redirects(Seobeo_Client_Request *p_req, boolean follow, int32 max_redirects) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
144 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
145 if (!p_req) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
146 return; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
147 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
148 p_req->follow_redirects = follow; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
149 p_req->max_redirects = max_redirects > 0 ? max_redirects : 10; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
150 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
151 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
152 void Seobeo_Client_Request_Set_Download_Path(Seobeo_Client_Request *p_req, const char *path) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
153 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
154 if (!p_req || !path) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
155 return; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
156 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
157 size_t len = strlen(path); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
158 p_req->download_path = Dowa_Arena_Allocate(p_req->p_arena, len + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
159 strcpy(p_req->download_path, path); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
160 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
161 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
162 static int Seobeo_Client_Build_Request_Header(Seobeo_Client_Request *p_req, char *buffer, size_t buffer_size) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
163 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
164 int offset = 0; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
165 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
166 offset += snprintf(buffer + offset, buffer_size - offset, |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
167 "%s %s HTTP/1.1\r\n" |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
168 "Host: %s\r\n", |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
169 p_req->method, p_req->path, p_req->host); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
170 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
171 boolean has_content_length = FALSE; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
172 boolean has_connection = FALSE; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
173 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
174 if (p_req->headers_map) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
175 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
176 size_t count = Dowa_Array_Length(p_req->headers_map); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
177 for (size_t i = 0; i < count; i++) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
178 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
179 const char *key = p_req->headers_map[i].key; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
180 const char *value = p_req->headers_map[i].value; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
181 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
182 if (strcasecmp(key, "content-length") == 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
183 has_content_length = TRUE; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
184 if (strcasecmp(key, "connection") == 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
185 has_connection = TRUE; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
186 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
187 offset += snprintf(buffer + offset, buffer_size - offset, |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
188 "%s: %s\r\n", key, value); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
189 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
190 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
191 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
192 if (p_req->headers_array) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
193 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
194 size_t count = Dowa_Array_Length(p_req->headers_array); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
195 for (size_t i = 0; i < count; i++) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
196 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
197 const char *header = p_req->headers_array[i]; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
198 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
199 if (strncasecmp(header, "content-length:", 15) == 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
200 has_content_length = TRUE; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
201 if (strncasecmp(header, "connection:", 11) == 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
202 has_connection = TRUE; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
203 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
204 offset += snprintf(buffer + offset, buffer_size - offset, |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
205 "%s\r\n", header); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
206 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
207 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
208 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
209 if (p_req->body && !has_content_length) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
210 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
211 offset += snprintf(buffer + offset, buffer_size - offset, |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
212 "Content-Length: %zu\r\n", p_req->body_length); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
213 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
214 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
215 if (!has_connection) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
216 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
217 offset += snprintf(buffer + offset, buffer_size - offset, |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
218 "Connection: close\r\n"); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
219 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
220 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
221 offset += snprintf(buffer + offset, buffer_size - offset, "\r\n"); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
222 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
223 return offset; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
224 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
225 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
226 static Seobeo_Client_Response *Seobeo_Client_Parse_Response(Seobeo_Handle *p_handle, const char *download_path) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
227 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
228 Seobeo_Client_Response *p_resp = malloc(sizeof(Seobeo_Client_Response)); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
229 if (!p_resp) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
230 return NULL; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
231 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
232 memset(p_resp, 0, sizeof(Seobeo_Client_Response)); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
233 |
|
175
71ad34a8bc9a
[HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents:
168
diff
changeset
|
234 p_resp->p_arena = Dowa_Arena_Create(1024 * 1024 * 10); // 10 MB |
|
119
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
235 if (!p_resp->p_arena) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
236 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
237 free(p_resp); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
238 return NULL; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
239 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
240 |
|
163
058de208e640
[Config] Adding os ignore files.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
241 while (TRUE) |
|
119
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
242 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
243 int r = Seobeo_Handle_Read(p_handle); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
244 if (r < 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
245 return p_resp; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
246 if (r == -2) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
247 break; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
248 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
249 if (p_handle->read_buffer_len >= 4 && strstr((char*)p_handle->read_buffer, "\r\n\r\n") != NULL) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
250 break; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
251 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
252 if (r == 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
253 continue; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
254 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
255 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
256 char *buf = (char*)p_handle->read_buffer; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
257 char *hdr_end = strstr(buf, "\r\n\r\n"); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
258 if (!hdr_end) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
259 return p_resp; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
260 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
261 size_t hdr_len = hdr_end - buf + 4; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
262 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
263 char version[16]; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
264 int status_code; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
265 char status_text[256]; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
266 int scan_result = sscanf(buf, "%15s %d %255[^\r\n]", version, &status_code, status_text); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
267 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
268 if (scan_result >= 2) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
269 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
270 p_resp->status_code = status_code; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
271 if (scan_result >= 3) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
272 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
273 size_t len = strlen(status_text); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
274 p_resp->status_text = Dowa_Arena_Allocate(p_resp->p_arena, len + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
275 strcpy(p_resp->status_text, status_text); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
276 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
277 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
278 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
279 char *line = buf + strlen(version) + 1; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
280 while (*line && !isdigit(*line)) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
281 line++; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
282 while (*line && isdigit(*line)) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
283 line++; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
284 while (*line && *line == ' ') |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
285 line++; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
286 while (*line && *line != '\r') |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
287 line++; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
288 line += 2; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
289 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
290 while (line < hdr_end) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
291 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
292 char *next = strstr(line, "\r\n"); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
293 if (!next) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
294 break; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
295 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
296 char *colon = memchr(line, ':', next - line); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
297 if (colon) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
298 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
299 size_t key_len = colon - line; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
300 size_t value_len = next - colon - 1; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
301 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
302 char *val_start = colon + 1; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
303 if (*val_start == ' ') |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
304 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
305 val_start++; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
306 value_len--; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
307 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
308 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
309 char *key = Dowa_Arena_Allocate(p_resp->p_arena, key_len + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
310 memcpy(key, line, key_len); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
311 key[key_len] = '\0'; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
312 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
313 char *val = Dowa_Arena_Allocate(p_resp->p_arena, value_len + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
314 memcpy(val, val_start, value_len); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
315 val[value_len] = '\0'; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
316 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
317 Dowa_HashMap_Push_Arena(p_resp->headers, key, val, p_resp->p_arena); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
318 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
319 if (strcasecmp(key, "Location") == 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
320 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
321 p_resp->redirect_url = Dowa_Arena_Allocate(p_resp->p_arena, value_len + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
322 strcpy(p_resp->redirect_url, val); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
323 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
324 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
325 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
326 line = next + 2; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
327 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
328 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
329 Seobeo_Handle_Consume(p_handle, (uint32)hdr_len); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
330 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
331 void *p_cl_kv = Dowa_HashMap_Get_Ptr(p_resp->headers, "Content-Length"); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
332 size_t body_len = 0; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
333 if (p_cl_kv) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
334 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
335 const char *content_length_str = ((Seobeo_Request_Entry*)p_cl_kv)->value; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
336 body_len = atoi(content_length_str); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
337 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
338 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
339 FILE *p_file = NULL; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
340 if (download_path) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
341 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
342 p_file = fopen(download_path, "wb"); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
343 if (!p_file) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
344 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
345 Seobeo_Log(SEOBEO_ERROR, "Failed to open file for writing: %s\n", download_path); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
346 return p_resp; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
347 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
348 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
349 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
350 if (body_len > 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
351 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
352 char *body = download_path ? NULL : Dowa_Arena_Allocate(p_resp->p_arena, body_len + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
353 size_t total_read = 0; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
354 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
355 while (total_read < body_len) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
356 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
357 size_t available = p_handle->read_buffer_len; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
358 size_t to_copy = (body_len - total_read) < available ? (body_len - total_read) : available; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
359 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
360 if (to_copy > 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
361 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
362 if (download_path) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
363 fwrite(p_handle->read_buffer, 1, to_copy, p_file); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
364 else |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
365 memcpy(body + total_read, p_handle->read_buffer, to_copy); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
366 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
367 total_read += to_copy; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
368 Seobeo_Handle_Consume(p_handle, (uint32)to_copy); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
369 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
370 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
371 if (total_read < body_len) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
372 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
373 int r = Seobeo_Handle_Read(p_handle); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
374 if (r < 0 || r == -2) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
375 break; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
376 if (r == 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
377 continue; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
378 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
379 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
380 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
381 if (!download_path) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
382 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
383 body[body_len] = '\0'; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
384 p_resp->body = body; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
385 p_resp->body_length = body_len; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
386 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
387 else |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
388 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
389 p_resp->body_length = total_read; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
390 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
391 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
392 else |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
393 { |
|
175
71ad34a8bc9a
[HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents:
168
diff
changeset
|
394 size_t cap = 1024 * 1024 * 5; |
|
119
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
395 size_t used = 0; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
396 char *body = download_path ? NULL : Dowa_Arena_Allocate(p_resp->p_arena, cap); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
397 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
398 while (1) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
399 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
400 int n = Seobeo_Handle_Read(p_handle); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
401 if (n > 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
402 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
403 if (download_path) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
404 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
405 fwrite(p_handle->read_buffer, 1, p_handle->read_buffer_len, p_file); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
406 used += p_handle->read_buffer_len; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
407 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
408 else |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
409 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
410 if (used + p_handle->read_buffer_len >= cap) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
411 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
412 Seobeo_Log(SEOBEO_WARNING, "Response body too large, truncating...\n"); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
413 break; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
414 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
415 memcpy(body + used, p_handle->read_buffer, p_handle->read_buffer_len); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
416 used += p_handle->read_buffer_len; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
417 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
418 Seobeo_Handle_Consume(p_handle, (uint32)p_handle->read_buffer_len); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
419 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
420 else if (n == -2) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
421 break; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
422 else if (n == 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
423 continue; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
424 else |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
425 break; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
426 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
427 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
428 if (!download_path) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
429 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
430 p_resp->body = body; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
431 p_resp->body_length = used; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
432 if (used < cap) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
433 body[used] = '\0'; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
434 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
435 else |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
436 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
437 p_resp->body_length = used; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
438 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
439 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
440 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
441 if (p_file) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
442 fclose(p_file); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
443 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
444 return p_resp; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
445 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
446 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
447 static Seobeo_Client_Response *Seobeo_Client_Execute_Single(Seobeo_Client_Request *p_req) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
448 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
449 Seobeo_Handle *p_handle = Seobeo_Stream_Handle_Client_Create(p_req->host, p_req->port, p_req->use_tls); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
450 if (!p_handle || p_handle->socket < 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
451 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
452 if (p_handle) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
453 Seobeo_Handle_Destroy(p_handle); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
454 return NULL; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
455 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
456 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
457 char request_buffer[8192]; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
458 int request_len = Seobeo_Client_Build_Request_Header(p_req, request_buffer, sizeof(request_buffer)); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
459 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
460 Seobeo_Handle_Queue(p_handle, (uint8*)request_buffer, (uint32)request_len); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
461 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
462 if (p_req->body && p_req->body_length > 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
463 Seobeo_Handle_Queue(p_handle, (uint8*)p_req->body, (uint32)p_req->body_length); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
464 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
465 if (Seobeo_Handle_Flush(p_handle) < 0) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
466 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
467 Seobeo_Handle_Destroy(p_handle); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
468 return NULL; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
469 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
470 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
471 Seobeo_Client_Response *p_resp = Seobeo_Client_Parse_Response(p_handle, p_req->download_path); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
472 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
473 Seobeo_Handle_Destroy(p_handle); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
474 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
475 return p_resp; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
476 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
477 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
478 Seobeo_Client_Response *Seobeo_Client_Request_Execute(Seobeo_Client_Request *p_req) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
479 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
480 if (!p_req) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
481 return NULL; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
482 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
483 Seobeo_Client_Response *p_resp = Seobeo_Client_Execute_Single(p_req); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
484 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
485 if (!p_resp) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
486 return NULL; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
487 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
488 int redirect_count = 0; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
489 while (p_req->follow_redirects && |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
490 p_resp->redirect_url && |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
491 (p_resp->status_code == 301 || p_resp->status_code == 302 || |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
492 p_resp->status_code == 303 || p_resp->status_code == 307 || |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
493 p_resp->status_code == 308) && |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
494 redirect_count < p_req->max_redirects) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
495 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
496 char *redirect_url = malloc(strlen(p_resp->redirect_url) + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
497 strcpy(redirect_url, p_resp->redirect_url); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
498 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
499 Seobeo_Client_Response_Destroy(p_resp); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
500 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
501 // Relative redirect |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
502 if (redirect_url[0] == '/') |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
503 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
504 size_t path_len = strlen(redirect_url); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
505 p_req->path = Dowa_Arena_Allocate(p_req->p_arena, path_len + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
506 strcpy(p_req->path, redirect_url); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
507 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
508 size_t url_len = strlen(p_req->host) + strlen(p_req->port) + path_len + 16; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
509 p_req->url = Dowa_Arena_Allocate(p_req->p_arena, url_len); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
510 snprintf(p_req->url, url_len, "%s://%s:%s%s", |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
511 p_req->use_tls ? "https" : "http", |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
512 p_req->host, p_req->port, p_req->path); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
513 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
514 else |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
515 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
516 size_t url_len = strlen(redirect_url); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
517 p_req->url = Dowa_Arena_Allocate(p_req->p_arena, url_len + 1); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
518 strcpy(p_req->url, redirect_url); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
519 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
520 Seobeo_Client_Parse_Url(redirect_url, &p_req->host, &p_req->port, &p_req->path, &p_req->use_tls, p_req->p_arena); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
521 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
522 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
523 free(redirect_url); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
524 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
525 p_resp = Seobeo_Client_Execute_Single(p_req); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
526 if (!p_resp) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
527 return NULL; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
528 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
529 redirect_count++; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
530 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
531 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
532 return p_resp; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
533 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
534 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
535 void Seobeo_Client_Request_Destroy(Seobeo_Client_Request *p_req) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
536 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
537 if (!p_req) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
538 return; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
539 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
540 if (p_req->p_arena) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
541 Dowa_Arena_Free(p_req->p_arena); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
542 |
|
168
f3084bca7317
[Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents:
163
diff
changeset
|
543 // Note: headers_map and headers_array are allocated using arena functions |
|
f3084bca7317
[Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents:
163
diff
changeset
|
544 // (Dowa_HashMap_Push_Arena, Dowa_Array_Push_Arena), so they are freed |
|
f3084bca7317
[Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents:
163
diff
changeset
|
545 // when the arena is freed above. Do not call Dowa_HashMap_Free or |
|
f3084bca7317
[Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents:
163
diff
changeset
|
546 // Dowa_Array_Free on them. |
|
119
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
547 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
548 free(p_req); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
549 } |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
550 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
551 void Seobeo_Client_Response_Destroy(Seobeo_Client_Response *p_resp) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
552 { |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
553 if (!p_resp) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
554 return; |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
555 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
556 if (p_resp->p_arena) |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
557 Dowa_Arena_Free(p_resp->p_arena); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
558 |
|
168
f3084bca7317
[Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents:
163
diff
changeset
|
559 // Note: headers are allocated using Dowa_HashMap_Push_Arena, so they are |
|
f3084bca7317
[Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents:
163
diff
changeset
|
560 // freed when the arena is freed above. Do not call Dowa_HashMap_Free. |
|
119
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
561 |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
562 free(p_resp); |
|
c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
563 } |