Mercurial
annotate postdog/main.c @ 55:0dcfbf5ba997
Remvoing unneeded bzl rules.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Fri, 19 Dec 2025 13:59:11 -0800 |
| parents | b3e82d22f961 |
| children | d4cdb87212fb |
| rev | line source |
|---|---|
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
1 /** |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
2 * Entirely written by Claude AI. |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
3 */ |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
4 #include <stdio.h> |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
5 #include <stdlib.h> |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
6 #include <string.h> |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
7 #include <time.h> |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
8 #include <sys/stat.h> |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
9 #include <dirent.h> |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
10 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
11 // third party |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
12 #include <curl/curl.h> |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
13 #include "third_party/raylib/include/raylib.h" |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
14 #define RAYGUI_IMPLEMENTATION |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
15 #include "third_party/raylib/include/raygui.h" |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
16 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
17 #define SCREEN_WIDTH 1280 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
18 #define SCREEN_HEIGHT 780 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
19 #define SIDEBAR_WIDTH 200 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
20 #define URL_INPUT_HEIGHT 40 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
21 #define PADDING 15 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
22 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
23 #define TEXT_SIZE 10 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
24 #define LINE_HEIGHT 15 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
25 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
26 #define METHOD_BUTTON_WIDTH 100 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
27 #define METHOD_BUTTON_HEIGHT 40 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
28 #define SEND_BUTTON_WIDTH 100 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
29 #define SEND_BUTTON_HEIGHT 40 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
30 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
31 #define JSON_INPUT_BUFFER_LEN 8192 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
32 #define HEADER_INPUT_BUFFER_LEN 4096 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
33 #define PARAM_INPUT_BUFFER_LEN 4096 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
34 #define MAX_HISTORY_ITEMS 100 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
35 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
36 // Structure to hold response data |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
37 typedef struct { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
38 char *data; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
39 size_t size; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
40 } ResponseBuffer; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
41 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
42 // Structure to hold history item |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
43 typedef struct { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
44 char filename[256]; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
45 char displayName[128]; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
46 char method[16]; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
47 time_t timestamp; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
48 } HistoryItem; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
49 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
50 typedef enum { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
51 ActiveTab_JSON = 0 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
52 ActiveTab_Headers, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
53 ActiveTab_Params, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
54 } ActiveTab |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
55 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
56 // Callback function for curl to write response data |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
57 static size_t Postdog_Curl_Callback(void *contents, size_t size, size_t nmemb, void *userp) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
58 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
59 size_t real_size = size * nmemb; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
60 ResponseBuffer *buf = (ResponseBuffer *)userp; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
61 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
62 char *ptr = realloc(buf->data, buf->size + real_size + 1); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
63 if (ptr == NULL) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
64 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
65 printf("Not enough memory for response\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
66 return 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
67 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
68 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
69 buf->data = ptr; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
70 memcpy(&(buf->data[buf->size]), contents, real_size); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
71 buf->size += real_size; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
72 buf->data[buf->size] = 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
73 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
74 return real_size; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
75 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
76 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
77 // Function to make HTTP request using curl |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
78 int PostDog_Make_HttpRequest(const char *url, const char *method, const char *headers, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
79 const char *body, char *response, size_t responseSize) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
80 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
81 CURL *curl; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
82 CURLcode res; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
83 ResponseBuffer buffer = { .data = malloc(1), .size = 0 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
84 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
85 if (buffer.data == NULL) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
86 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
87 snprintf(response, responseSize, "Error: Failed to allocate memory"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
88 return -1; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
89 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
90 buffer.data[0] = '\0'; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
91 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
92 curl_global_init(CURL_GLOBAL_DEFAULT); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
93 curl = curl_easy_init(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
94 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
95 if (curl) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
96 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
97 struct curl_slist *headerList = NULL; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
98 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
99 // Set URL |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
100 curl_easy_setopt(curl, CURLOPT_URL, url); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
101 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
102 // Set HTTP method |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
103 if (strcmp(method, "POST") == 0) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
104 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
105 curl_easy_setopt(curl, CURLOPT_POST, 1L); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
106 if (body && strlen(body) > 0) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
107 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
108 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
109 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
110 else if (strcmp(method, "PUT") == 0) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
111 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
112 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
113 if (body && strlen(body) > 0) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
114 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
115 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
116 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
117 else if (strcmp(method, "DELETE") == 0) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
118 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
119 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
120 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
121 // Default is GET |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
122 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
123 // Parse and add headers |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
124 if (headers && strlen(headers) > 0) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
125 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
126 char *headersCopy = strdup(headers); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
127 char *line = strtok(headersCopy, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
128 while (line != NULL) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
129 // Trim whitespace |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
130 while (*line == ' ' || *line == '\t') line++; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
131 if (strlen(line) > 0) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
132 headerList = curl_slist_append(headerList, line); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
133 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
134 line = strtok(NULL, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
135 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
136 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerList); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
137 free(headersCopy); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
138 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
139 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
140 // Set write callback |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
141 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Postdog_Curl_Callback); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
142 curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&buffer); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
143 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
144 // Follow redirects |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
145 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
146 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
147 // Set timeout |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
148 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30L); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
149 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
150 // Perform request |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
151 res = curl_easy_perform(curl); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
152 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
153 if (res != CURLE_OK) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
154 snprintf(response, responseSize, "Error: %s\n", curl_easy_strerror(res)); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
155 } else { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
156 long response_code; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
157 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
158 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
159 snprintf(response, responseSize, "HTTP Status: %ld\n\n%s", |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
160 response_code, buffer.data ? buffer.data : ""); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
161 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
162 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
163 // Cleanup |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
164 if (headerList) curl_slist_free_all(headerList); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
165 curl_easy_cleanup(curl); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
166 } else { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
167 snprintf(response, responseSize, "Error: Failed to initialize curl"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
168 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
169 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
170 free(buffer.data); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
171 curl_global_cleanup(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
172 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
173 return 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
174 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
175 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
176 void PostDog_HistoryDirectory_Exists() |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
177 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
178 struct stat st = {0}; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
179 if (stat("history", &st) == -1) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
180 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
181 mkdir("history", 0700); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
182 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
183 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
184 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
185 int PostDog_HistoryDistory_ItemsLoad(HistoryItem *items, int maxItems) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
186 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
187 DIR *dir = opendir("history"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
188 if (!dir) return 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
189 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
190 struct dirent *entry; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
191 int count = 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
192 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
193 while ((entry = readdir(dir)) != NULL && count < maxItems) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
194 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
195 if (entry->d_name[0] == '.') continue; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
196 if (strstr(entry->d_name, ".txt") == NULL) continue; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
197 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
198 // Parse filename: YYYYMMDD_HHMMSS_METHOD.txt |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
199 strncpy(items[count].filename, entry->d_name, sizeof(items[count].filename) - 1); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
200 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
201 // Extract method from filename |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
202 char *methodStart = strrchr(entry->d_name, '_'); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
203 if (methodStart) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
204 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
205 methodStart++; // Skip underscore |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
206 char *dotPos = strchr(methodStart, '.'); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
207 if (dotPos) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
208 int len = dotPos - methodStart; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
209 if (len < 16) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
210 strncpy(items[count].method, methodStart, len); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
211 items[count].method[len] = '\0'; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
212 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
213 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
214 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
215 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
216 // Create display name: METHOD - YYYYMMDD HHMMSS |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
217 char dateTime[32] = ""; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
218 if (strlen(entry->d_name) >= 15) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
219 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
220 snprintf(dateTime, sizeof(dateTime), "%.8s %.6s", |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
221 entry->d_name, entry->d_name + 9); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
222 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
223 snprintf(items[count].displayName, sizeof(items[count].displayName), |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
224 "%s - %s", items[count].method, dateTime); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
225 count++; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
226 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
227 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
228 closedir(dir); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
229 return count; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
230 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
231 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
232 int PostDog_HistoryDirectory_LoadRequest(const char *filename, char *url, char *method, char *headers, char *body) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
233 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
234 char filepath[512]; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
235 snprintf(filepath, sizeof(filepath), "history/%s", filename); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
236 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
237 FILE *f = fopen(filepath, "r"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
238 if (!f) return -1; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
239 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
240 char line[2048]; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
241 int section = 0; // 0=url, 1=method, 2=headers, 3=body |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
242 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
243 url[0] = '\0'; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
244 method[0] = '\0'; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
245 headers[0] = '\0'; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
246 body[0] = '\0'; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
247 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
248 while (fgets(line, sizeof(line), f)) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
249 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
250 // Remove newline |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
251 line[strcspn(line, "\n")] = 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
252 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
253 if (section == 0) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
254 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
255 // First line is URL |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
256 strncpy(url, line, 1024 - 1); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
257 section = 1; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
258 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
259 else if (strncmp(line, "Method: ", 8) == 0) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
260 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
261 strncpy(method, line + 8, 15); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
262 section = 2; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
263 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
264 else if (strncmp(line, "Headers:", 8) == 0) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
265 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
266 section = 2; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
267 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
268 else if (strcmp(line, "---") == 0) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
269 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
270 section = 3; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
271 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
272 else if (strncmp(line, "Body:", 5) == 0) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
273 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
274 section = 3; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
275 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
276 else if (section == 2 && strcmp(line, "None") != 0) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
277 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
278 // Add header line |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
279 if (strlen(headers) > 0) strcat(headers, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
280 strncat(headers, line, HEADER_INPUT_BUFFER_LEN - strlen(headers) - 1); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
281 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
282 else if (section == 3 && strcmp(line, "None") != 0) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
283 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
284 // Add body line |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
285 if (strlen(body) > 0) strcat(body, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
286 strncat(body, line, JSON_INPUT_BUFFER_LEN - strlen(body) - 1); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
287 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
288 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
289 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
290 fclose(f); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
291 return 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
292 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
293 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
294 void updateUrlWithParams(char *url, size_t urlSize, const char *baseUrl, const char *params) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
295 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
296 // Find if there's already a ? in the URL |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
297 char *questionMark = strchr(baseUrl, '?'); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
298 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
299 if (questionMark != NULL) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
300 // URL already has params, just copy the base |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
301 strncpy(url, baseUrl, urlSize - 1); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
302 } else { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
303 // No params yet, add them |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
304 snprintf(url, urlSize, "%s", baseUrl); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
305 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
306 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
307 // Parse and append params |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
308 if (params && strlen(params) > 0) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
309 char *paramsCopy = strdup(params); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
310 char *line = strtok(paramsCopy, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
311 bool firstParam = (questionMark == NULL); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
312 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
313 while (line != NULL) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
314 // Trim whitespace |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
315 while (*line == ' ' || *line == '\t') line++; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
316 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
317 if (strlen(line) > 0 && strchr(line, '=')) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
318 size_t currentLen = strlen(url); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
319 if (currentLen + 2 < urlSize) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
320 strcat(url, firstParam ? "?" : "&"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
321 firstParam = false; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
322 strncat(url, line, urlSize - strlen(url) - 1); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
323 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
324 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
325 line = strtok(NULL, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
326 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
327 free(paramsCopy); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
328 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
329 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
330 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
331 // Save request to history file |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
332 void saveRequestToHistory(const char *url, const char *method, const char *headers, const char *body) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
333 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
334 PostDog_HistoryDirectory_Exists(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
335 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
336 // Generate filename with timestamp |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
337 time_t now = time(NULL); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
338 struct tm *t = localtime(&now); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
339 char filename[256]; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
340 snprintf(filename, sizeof(filename), "history/%04d%02d%02d_%02d%02d%02d_%s.txt", |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
341 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
342 t->tm_hour, t->tm_min, t->tm_sec, method); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
343 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
344 FILE *f = fopen(filename, "w"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
345 if (f == NULL) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
346 printf("Failed to create history file\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
347 return; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
348 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
349 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
350 // Write URL |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
351 fprintf(f, "%s\n", url); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
352 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
353 // Write method |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
354 fprintf(f, "Method: %s\n", method); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
355 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
356 // Write headers |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
357 fprintf(f, "Headers:\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
358 if (headers && strlen(headers) > 0) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
359 fprintf(f, "%s\n", headers); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
360 } else { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
361 fprintf(f, "None\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
362 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
363 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
364 fprintf(f, "---\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
365 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
366 // Write body |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
367 fprintf(f, "Body:\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
368 if (body && strlen(body) > 0) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
369 fprintf(f, "%s\n", body); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
370 } else { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
371 fprintf(f, "None\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
372 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
373 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
374 fclose(f); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
375 printf("Request saved to %s\n", filename); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
376 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
377 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
378 void PostDog_Render_TextWithScroll(Rectangle textArea, Vector2 scroll, char * input) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
379 BeginScissorMode(textArea.x, textArea.y, textArea.width, textArea.height); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
380 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
381 int yPos = textArea.y + 5 - (int)scroll.y; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
382 char *textCopy = strdup(input); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
383 char *line = strtok(textCopy, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
384 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
385 while (line != NULL && yPos < textArea.y + textArea.height) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
386 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
387 if (yPos + LINE_HEIGHT > textArea.y) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
388 DrawText(line, textArea.x + 5, yPos, TEXT_SIZE, DARKGRAY); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
389 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
390 yPos += LINE_HEIGHT; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
391 line = strtok(NULL, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
392 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
393 free(textCopy); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
394 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
395 EndScissorMode(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
396 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
397 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
398 int main() |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
399 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
400 InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "PostDog - HTTP Client"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
401 SetWindowState(FLAG_WINDOW_RESIZABLE); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
402 SetTargetFPS(60); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
403 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
404 PostDog_HistoryDirectory_Exists(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
405 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
406 // UI State |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
407 char urlInput[1024] = "https://httpbin.org/get"; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
408 bool urlEditMode = false; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
409 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
410 char jsonInput[JSON_INPUT_BUFFER_LEN] = "{\"key\":\"value\"}"; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
411 bool jsonEditMode = false; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
412 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
413 char headersInput[HEADER_INPUT_BUFFER_LEN] = "Content-Type: application/json"; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
414 bool headersEditMode = false; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
415 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
416 char responseText[16384] = "Response will appear here...\n\nTry the default URL or enter your own!"; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
417 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
418 char paramsInput[PARAM_INPUT_BUFFER_LEN] = "key1=value1\nkey2=value2"; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
419 bool paramsEditMode = false; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
420 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
421 ActiveTab activeTab = ActiveTab_JSON; // 0 = JSON, 1 = Headers, 2 = Params |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
422 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
423 // HTTP method selection |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
424 int methodActive = 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
425 bool methodDropdown = false; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
426 const char *methods[] = { "GET", "POST", "PUT", "DELETE" }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
427 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
428 // Scroll support |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
429 Vector2 jsonScroll = { 0, 0 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
430 Vector2 headersScroll = { 0, 0 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
431 Vector2 paramsScroll = { 0, 0 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
432 Vector2 responseScroll = { 0, 0 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
433 Vector2 historyScroll = { 0, 0 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
434 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
435 // History |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
436 HistoryItem historyItems[MAX_HISTORY_ITEMS]; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
437 int historyCount = 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
438 int selectedHistoryIndex = -1; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
439 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
440 // Load initial history |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
441 historyCount = PostDog_HistoryDistory_ItemsLoad(historyItems, MAX_HISTORY_ITEMS); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
442 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
443 while (!WindowShouldClose()) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
444 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
445 // Get current window dimensions for responsive layout |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
446 int screenWidth = GetScreenWidth(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
447 int screenHeight = GetScreenHeight(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
448 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
449 // Layout calculations |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
450 Rectangle sidebar = { 0, 10, SIDEBAR_WIDTH, screenHeight }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
451 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
452 float mainX = SIDEBAR_WIDTH + PADDING; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
453 float mainWidth = screenWidth - SIDEBAR_WIDTH - PADDING * 2; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
454 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
455 // URL input box - leave space for SEND button on the right |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
456 Rectangle urlBox = { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
457 mainX, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
458 PADDING, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
459 mainWidth - SEND_BUTTON_WIDTH - PADDING, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
460 URL_INPUT_HEIGHT |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
461 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
462 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
463 // SEND button positioned beside URL input |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
464 Rectangle sendButton = { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
465 urlBox.x + urlBox.width + PADDING, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
466 PADDING, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
467 SEND_BUTTON_WIDTH, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
468 SEND_BUTTON_HEIGHT |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
469 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
470 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
471 // Method dropdown below URL |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
472 Rectangle methodButton = { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
473 mainX, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
474 urlBox.y + urlBox.height + PADDING, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
475 METHOD_BUTTON_WIDTH, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
476 METHOD_BUTTON_HEIGHT |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
477 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
478 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
479 float tabHeight = 30; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
480 float contentY = methodButton.y + methodButton.height + PADDING + tabHeight; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
481 float contentHeight = screenHeight - contentY - PADDING; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
482 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
483 float panelWidth = (mainWidth - PADDING) / 2; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
484 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
485 Rectangle tabBar = { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
486 mainX, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
487 methodButton.y + methodButton.height + PADDING, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
488 panelWidth, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
489 tabHeight |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
490 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
491 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
492 Rectangle requestPanel = { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
493 mainX, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
494 contentY, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
495 panelWidth, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
496 contentHeight |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
497 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
498 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
499 Rectangle responsePanel = { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
500 mainX + panelWidth + PADDING, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
501 contentY, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
502 panelWidth, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
503 contentHeight |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
504 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
505 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
506 BeginDrawing(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
507 ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR))); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
508 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
509 // Sidebar with history |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
510 DrawRectangleRec(sidebar, Fade(GRAY, 0.1f)); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
511 GuiGroupBox(sidebar, "HISTORY"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
512 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
513 // Refresh history button |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
514 Rectangle refreshBtn = { sidebar.x + 5, sidebar.y + 5, 90, 20 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
515 if (GuiButton(refreshBtn, "Refresh")) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
516 historyCount = PostDog_HistoryDistory_ItemsLoad(historyItems, MAX_HISTORY_ITEMS); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
517 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
518 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
519 // Scroll area for history |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
520 Rectangle historyArea = { sidebar.x + 5, sidebar.y + 30, sidebar.width - 10, sidebar.height - 40 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
521 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
522 // Handle scroll |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
523 if (CheckCollisionPointRec(GetMousePosition(), historyArea)) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
524 float wheel = GetMouseWheelMove(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
525 historyScroll.y += wheel * 20; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
526 if (historyScroll.y < 0) historyScroll.y = 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
527 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
528 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
529 BeginScissorMode(historyArea.x, historyArea.y, historyArea.width, historyArea.height); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
530 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
531 if (historyCount == 0) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
532 DrawText("No requests yet", historyArea.x + 5, historyArea.y + 5, 10, DARKGRAY); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
533 } else { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
534 int yPos = historyArea.y + 5 - (int)historyScroll.y; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
535 int itemHeight = 45; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
536 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
537 for (int i = 0; i < historyCount; i++) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
538 if (yPos > historyArea.y - itemHeight && yPos < historyArea.y + historyArea.height) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
539 Rectangle itemRect = { historyArea.x, yPos, historyArea.width, itemHeight - 2 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
540 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
541 // Draw button for history item |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
542 Color bgColor = (selectedHistoryIndex == i) ? Fade(BLUE, 0.3f) : Fade(LIGHTGRAY, 0.5f); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
543 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
544 if (CheckCollisionPointRec(GetMousePosition(), itemRect) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
545 // Load this request |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
546 char tempUrl[1024], tempMethod[16], tempHeaders[HEADER_INPUT_BUFFER_LEN], tempBody[JSON_INPUT_BUFFER_LEN]; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
547 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
548 if (PostDog_HistoryDirectory_LoadRequest( |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
549 historyItems[i].filename, tempUrl, tempMethod, tempHeaders, tempBody) == 0) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
550 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
551 strncpy(urlInput, tempUrl, sizeof(urlInput) - 1); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
552 strncpy(headersInput, tempHeaders, sizeof(headersInput) - 1); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
553 strncpy(jsonInput, tempBody, sizeof(jsonInput) - 1); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
554 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
555 // Set method |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
556 for (int m = 0; m < 4; m++) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
557 if (strcmp(methods[m], tempMethod) == 0) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
558 methodActive = m; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
559 break; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
560 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
561 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
562 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
563 selectedHistoryIndex = i; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
564 strcpy(responseText, "Request loaded from history. Click SEND to execute."); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
565 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
566 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
567 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
568 DrawRectangleRec(itemRect, bgColor); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
569 DrawRectangleLinesEx(itemRect, 1, GRAY); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
570 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
571 // Draw method badge |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
572 DrawText(historyItems[i].method, itemRect.x + 5, yPos + 5, 10, BLACK); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
573 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
574 // Draw timestamp (date only) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
575 char dateStr[16] = ""; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
576 if (strlen(historyItems[i].filename) >= 8) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
577 snprintf(dateStr, sizeof(dateStr), "%.4s-%.2s-%.2s", |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
578 historyItems[i].filename, historyItems[i].filename + 4, historyItems[i].filename + 6); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
579 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
580 DrawText(dateStr, itemRect.x + 5, yPos + 18, 8, DARKGRAY); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
581 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
582 // Draw time |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
583 char timeStr[16] = ""; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
584 if (strlen(historyItems[i].filename) >= 15) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
585 snprintf(timeStr, sizeof(timeStr), "%.2s:%.2s:%.2s", |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
586 historyItems[i].filename + 9, historyItems[i].filename + 11, historyItems[i].filename + 13); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
587 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
588 DrawText(timeStr, itemRect.x + 5, yPos + 28, 8, DARKGRAY); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
589 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
590 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
591 yPos += itemHeight; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
592 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
593 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
594 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
595 EndScissorMode(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
596 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
597 // URL Input |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
598 GuiLabel((Rectangle){ mainX, PADDING - 15, 100, 20 }, "URL:"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
599 if (GuiTextBox(urlBox, urlInput, 1024, urlEditMode)) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
600 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
601 urlEditMode = !urlEditMode; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
602 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
603 // Copy support for URL |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
604 if (urlEditMode && (IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C)) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
605 SetClipboardText(urlInput); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
606 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
607 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
608 // Send button (beside URL) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
609 if (GuiButton(sendButton, "SEND")) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
610 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
611 strcpy(responseText, "Sending request...\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
612 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
613 // Make the actual HTTP request |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
614 char tempResponse[16384]; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
615 const char *selectedMethod = methods[methodActive]; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
616 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
617 // Use JSON body for POST/PUT, otherwise use empty body |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
618 const char *requestBody = (methodActive == 1 || methodActive == 2) ? jsonInput : NULL; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
619 const char *requestHeaders = headersInput; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
620 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
621 // Save request to history |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
622 saveRequestToHistory(urlInput, selectedMethod, requestHeaders, requestBody); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
623 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
624 // Reload history to show the new request |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
625 historyCount = PostDog_HistoryDistory_ItemsLoad(historyItems, MAX_HISTORY_ITEMS); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
626 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
627 PostDog_Make_HttpRequest(urlInput, selectedMethod, requestHeaders, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
628 requestBody, tempResponse, sizeof(tempResponse)); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
629 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
630 strncpy(responseText, tempResponse, sizeof(responseText) - 1); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
631 responseText[sizeof(responseText) - 1] = '\0'; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
632 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
633 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
634 // Tab toggle (3 tabs now) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
635 float tabWidth = tabBar.width / 3; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
636 Rectangle jsonTab = { tabBar.x, tabBar.y - 10, tabWidth, tabBar.height }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
637 Rectangle headersTab = { tabBar.x + tabWidth, tabBar.y - 10, tabWidth, tabBar.height }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
638 Rectangle paramsTab = { tabBar.x + tabWidth * 2, tabBar.y - 10, tabWidth, tabBar.height }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
639 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
640 if (GuiButton(jsonTab, activeTab == ActiveTab_JSON ? "#191#Body" : "Body")) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
641 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
642 activeTab = ActiveTab_JSON; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
643 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
644 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
645 if (GuiButton(headersTab, activeTab == ActiveTab_Headers ? "#191#Headers" : "Headers")) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
646 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
647 activeTab = ActiveTab_Headers; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
648 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
649 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
650 if (GuiButton(paramsTab, activeTab == ActiveTab_Params ? "#191#Params" : "Params")) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
651 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
652 activeTab = ActiveTab_Headers; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
653 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
654 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
655 const char *panelTitle; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
656 switch(activeTab) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
657 case ActiveTab_JSON: |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
658 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
659 panelTitle = "Request Body (JSON)" |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
660 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
661 case ActiveTab_Headers: |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
662 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
663 panelTitle = "Request Headers" |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
664 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
665 case ActiveTab_Params: |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
666 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
667 panelTitle = "Query Parameters" |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
668 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
669 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
670 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
671 // Panel title |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
672 GuiGroupBox(requestPanel, panelTitle); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
673 Rectangle textArea = { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
674 requestPanel.x + 10, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
675 requestPanel.y + 30, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
676 requestPanel.width - 20, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
677 requestPanel.height - 40 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
678 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
679 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
680 // Handle click outside to disable edit mode |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
681 if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
682 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
683 if (!CheckCollisionPointRec(GetMousePosition(), textArea)) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
684 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
685 jsonEditMode = false; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
686 headersEditMode = false; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
687 paramsEditMode = false; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
688 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
689 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
690 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
691 // Draw border for text area |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
692 DrawRectangleLinesEx(textArea, 1, GRAY); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
693 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
694 // Manual scroll handling with mouse wheel |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
695 if (CheckCollisionPointRec(GetMousePosition(), textArea)) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
696 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
697 float wheel = GetMouseWheelMove(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
698 switch(activeTab) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
699 case ActiveTab_JSON: |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
700 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
701 jsonScroll.y += wheel * 20; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
702 if (jsonScroll.y < 0) jsonScroll.y = 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
703 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
704 case ActiveTab_Headers: |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
705 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
706 headersScroll.y += wheel * 20; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
707 if (headersScroll.y < 0) headersScroll.y = 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
708 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
709 case ActiveTab_Params: |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
710 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
711 paramsScroll.y += wheel * 20; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
712 if (paramsScroll.y < 0) paramsScroll.y = 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
713 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
714 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
715 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
716 if (activeTab == 0) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
717 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
718 BeginScissorMode(textArea.x, textArea.y, textArea.width, textArea.height); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
719 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
720 int yPos = textArea.y + 5 - (int)jsonScroll.y; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
721 char *textCopy = strdup(jsonInput); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
722 char *line = strtok(textCopy, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
723 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
724 while (line != NULL && yPos < textArea.y + textArea.height) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
725 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
726 if (yPos + LINE_HEIGHT > textArea.y) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
727 DrawText(line, textArea.x + 5, yPos, TEXT_SIZE, DARKGRAY); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
728 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
729 yPos += LINE_HEIGHT; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
730 line = strtok(NULL, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
731 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
732 free(textCopy); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
733 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
734 EndScissorMode(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
735 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
736 if ((IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C)) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
737 SetClipboardText(jsonInput); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
738 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
739 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
740 // Edit button |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
741 Rectangle editBtn = { textArea.x + textArea.width - 60, textArea.y + textArea.height - 10, 50, 20 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
742 if (GuiButton(editBtn, "Edit")) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
743 jsonEditMode = !jsonEditMode; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
744 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
745 } else if (activeTab == 1) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
746 BeginScissorMode(textArea.x, textArea.y, textArea.width, textArea.height); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
747 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
748 int yPos = textArea.y + 5 - (int)headersScroll.y; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
749 char *textCopy = strdup(headersInput); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
750 char *line = strtok(textCopy, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
751 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
752 while (line != NULL && yPos < textArea.y + textArea.height) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
753 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
754 if (yPos + LINE_HEIGHT > textArea.y) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
755 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
756 DrawText(line, textArea.x + 5, yPos, TEXT_SIZE, DARKGRAY); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
757 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
758 yPos += LINE_HEIGHT; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
759 line = strtok(NULL, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
760 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
761 free(textCopy); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
762 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
763 EndScissorMode(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
764 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
765 if ((IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C)) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
766 SetClipboardText(headersInput); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
767 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
768 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
769 // Edit button |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
770 Rectangle editBtn = { textArea.x + textArea.width - 60, textArea.y + textArea.height + 5, 50, 20 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
771 if (GuiButton(editBtn, "Edit")) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
772 headersEditMode = !headersEditMode; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
773 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
774 } else { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
775 // Params input with manual scroll |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
776 BeginScissorMode(textArea.x, textArea.y, textArea.width, textArea.height); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
777 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
778 int yPos = textArea.y + 5 - (int)paramsScroll.y; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
779 char *textCopy = strdup(paramsInput); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
780 char *line = strtok(textCopy, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
781 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
782 while (line != NULL && yPos < textArea.y + textArea.height) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
783 if (yPos + LINE_HEIGHT > textArea.y) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
784 DrawText(line, textArea.x + 5, yPos, TEXT_SIZE, DARKGRAY); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
785 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
786 yPos += LINE_HEIGHT; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
787 line = strtok(NULL, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
788 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
789 free(textCopy); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
790 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
791 EndScissorMode(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
792 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
793 if ((IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C)) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
794 SetClipboardText(paramsInput); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
795 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
796 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
797 // Buttons |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
798 Rectangle editBtn = { textArea.x + textArea.width - 60, textArea.y + textArea.height + 5, 50, 20 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
799 if (GuiButton(editBtn, "Edit")) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
800 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
801 paramsEditMode = !paramsEditMode; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
802 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
803 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
804 Rectangle updateUrlBtn = { textArea.x, textArea.y + textArea.height + 5, 120, 20 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
805 if (GuiButton(updateUrlBtn, "Update URL")) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
806 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
807 char tempUrl[1024]; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
808 strncpy(tempUrl, urlInput, sizeof(tempUrl) - 1); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
809 // Remove existing params if any |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
810 char *questionMark = strchr(tempUrl, '?'); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
811 if (questionMark) *questionMark = '\0'; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
812 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
813 updateUrlWithParams(urlInput, sizeof(urlInput), tempUrl, paramsInput); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
814 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
815 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
816 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
817 // Response Panel with scroll |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
818 GuiGroupBox(responsePanel, "Response"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
819 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
820 Rectangle responseArea = { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
821 responsePanel.x + 10, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
822 responsePanel.y + 30, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
823 responsePanel.width - 20, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
824 responsePanel.height - 40 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
825 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
826 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
827 // Manual scroll for response |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
828 if (CheckCollisionPointRec(GetMousePosition(), responseArea)) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
829 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
830 float wheel = GetMouseWheelMove(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
831 responseScroll.y += wheel * 20; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
832 if (responseScroll.y < 0) responseScroll.y = 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
833 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
834 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
835 // Draw border |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
836 DrawRectangleLinesEx(responseArea, 1, GRAY); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
837 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
838 // Draw response text with scroll |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
839 BeginScissorMode(responseArea.x, responseArea.y, responseArea.width, responseArea.height); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
840 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
841 int yPos = responseArea.y + 5 - (int)responseScroll.y; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
842 char *textCopy = strdup(responseText); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
843 char *line = strtok(textCopy, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
844 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
845 while (line != NULL && yPos < responseArea.y + responseArea.height) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
846 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
847 if (yPos + LINE_HEIGHT > responseArea.y) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
848 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
849 DrawText(line, responseArea.x + 5, yPos, TEXT_SIZE, DARKGRAY); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
850 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
851 yPos += LINE_HEIGHT; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
852 line = strtok(NULL, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
853 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
854 free(textCopy); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
855 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
856 EndScissorMode(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
857 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
858 if ((IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C)) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
859 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
860 if (CheckCollisionPointRec(GetMousePosition(), responseArea)) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
861 SetClipboardText(responseText); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
862 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
863 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
864 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
865 // --- Edit modal ---- |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
866 if (jsonEditMode) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
867 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
868 GuiTextBox( |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
869 (Rectangle){ screenWidth/2 - 300, screenHeight/2 - 200, 600, 400 }, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
870 jsonInput, JSON_INPUT_BUFFER_LEN, true); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
871 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
872 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
873 if (headersEditMode) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
874 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
875 GuiTextBox( |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
876 (Rectangle){ screenWidth/2 - 300, screenHeight/2 - 200, 600, 400 }, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
877 headersInput, HEADER_INPUT_BUFFER_LEN, true); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
878 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
879 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
880 if (paramsEditMode) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
881 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
882 GuiTextBox( |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
883 (Rectangle){ screenWidth/2 - 300, screenHeight/2 - 200, 600, 400 }, |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
884 paramsInput, PARAM_INPUT_BUFFER_LEN, true); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
885 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
886 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
887 if (GuiDropdownBox(methodButton, "GET;POST;PUT;DELETE", &methodActive, methodDropdown)) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
888 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
889 methodDropdown = !methodDropdown; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
890 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
891 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
892 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
893 EndDrawing(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
894 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
895 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
896 CloseWindow(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
897 return 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
898 } |