Mercurial
annotate postdog/main.c @ 114:e2a73e64e8e6
[Postdog] Got history working.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Tue, 06 Jan 2026 08:15:37 -0800 |
| parents | d6d578b49a19 |
| children | 96db6c3f38d6 |
| rev | line source |
|---|---|
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
1 #include <stdio.h> |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
2 #include <stdlib.h> |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
3 #include <string.h> |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
4 #include <time.h> |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
5 #include <sys/stat.h> |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
6 #include "dowa/dowa.h" |
|
58
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
57
diff
changeset
|
7 |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
8 #include <curl/curl.h> |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
9 #include "third_party/raylib/include/raylib.h" |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
10 #define RAYGUI_IMPLEMENTATION |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
11 #include "third_party/raylib/include/raygui.h" |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
12 |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
13 #ifndef POSTDOG_PATHS |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
14 #define POSTDOG_PATHS "/Users/mrjunejune/zenbu/postdog/history" |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
15 #endif |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
16 |
|
54
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 TEXT_SIZE 10 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
20 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
21 #define JSON_INPUT_BUFFER_LEN 8192 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
22 #define HEADER_INPUT_BUFFER_LEN 4096 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
23 #define PARAM_INPUT_BUFFER_LEN 4096 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
24 #define MAX_HISTORY_ITEMS 100 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
25 |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
26 #define HEADER_BUFFER_LENGTH 1024 * 4 |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
27 #define DEFAULT_TEXT_BUFFER_LENGTH 1024 * 4 |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
28 #define URL_TEXT_BUFFER 1024 * 10 |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
29 #define BODY_BUFFER_LENGTH 1024 * 1025 * 5 |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
30 #define RESULT_BUFFER_LENGTH 1024 * 1025 * 5 |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
31 #define AREANA_BUFFER_LENGTH 1024 * 1025 * 15 |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
32 |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
33 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
34 #ifdef _WIN32 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
35 #include <direct.h> |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
36 #include <io.h> |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
37 #define mkdir(path, mode) _mkdir(path) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
38 #define access _access |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
39 #define F_OK 0 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
40 #else |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
41 #include <sys/stat.h> |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
42 #include <dirent.h> |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
43 #include <unistd.h> |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
44 #endif |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
45 |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
46 typedef Dowa_KV(char*, char*) INPUT_HASHMAP; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
47 |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
48 typedef struct { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
49 char *data; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
50 size_t size; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
51 } ResponseBuffer; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
52 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
53 typedef struct { |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
54 char *filename; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
55 Rectangle rect; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
56 long time_modified; |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
57 } HistoryItem; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
58 |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
59 typedef struct { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
60 Rectangle rectangle; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
61 char *label; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
62 bool active; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
63 } TabItem; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
64 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
65 typedef enum { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
66 TAB_HEADER = 0, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
67 TAB_BODY, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
68 TAB_GET_PARAMS, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
69 TAB_BAR, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
70 TAB_LENGTH |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
71 } PostDog_Tab_Enum; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
72 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
73 static uint32 counter = 0; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
74 HistoryItem *history_items = NULL; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
75 HistoryItem *new_history_items = NULL; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
76 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
77 int CompareHistoryItemsByDate(const void *a, const void *b) { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
78 HistoryItem *itemA = (HistoryItem *)a; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
79 HistoryItem *itemB = (HistoryItem *)b; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
80 return (itemB->time_modified - itemA->time_modified); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
81 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
82 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
83 // TODO: Make this into generic fucntion so I can use it across different thing. |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
84 void PostDog_List_Directory(const char *path, HistoryItem **p_file_arr) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
85 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
86 HistoryItem *file_arr = *p_file_arr; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
87 #ifdef _WIN32 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
88 struct _finddata_t fileinfo; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
89 intptr_t handle; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
90 char search_path[256]; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
91 sprintf(search_path, "%s\\*", path); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
92 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
93 if ((handle = _findfirst(search_path, &fileinfo)) == -1L) { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
94 printf("Directory is empty or cannot be read.\n"); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
95 } else { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
96 do { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
97 HistoryItem item = {0}; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
98 item.filename = strdup(fileinfo.name); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
99 item.rect = (Rectangle){0}; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
100 item.time_modified = fileinfo.time_write; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
101 Dowa_Array_Push(file_arr, item); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
102 } while (_findnext(handle, &fileinfo) == 0); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
103 _findclose(handle); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
104 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
105 #else |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
106 struct dirent *entry; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
107 struct stat file_stat; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
108 DIR *dp = opendir(path); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
109 if (dp == NULL) return; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
110 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
111 char full_path[256]; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
112 while ((entry = readdir(dp))) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
113 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
114 if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
115 continue; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
116 snprintf(full_path, sizeof(full_path), "%s/%s", path, entry->d_name); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
117 if (stat(full_path, &file_stat) == 0) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
118 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
119 HistoryItem item = {0}; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
120 item.filename = strdup(entry->d_name); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
121 item.time_modified = file_stat.st_mtime; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
122 Dowa_Array_Push(file_arr, item); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
123 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
124 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
125 closedir(dp); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
126 #endif |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
127 int count = Dowa_Array_Length(file_arr); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
128 if (count > 1) { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
129 qsort(file_arr, count, sizeof(HistoryItem), CompareHistoryItemsByDate); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
130 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
131 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
132 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
133 int PostDog_History_Load(HistoryItem **p_history_files) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
134 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
135 if (access(POSTDOG_PATHS, F_OK) == -1) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
136 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
137 printf("Directory '%s' not found. Creating it...\n", POSTDOG_PATHS); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
138 if (mkdir(POSTDOG_PATHS, 0777) != 0) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
139 return -1; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
140 return 0; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
141 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
142 printf("Directory '%s' already exists.\n", POSTDOG_PATHS); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
143 PostDog_List_Directory(POSTDOG_PATHS, p_history_files); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
144 return 0; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
145 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
146 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
147 bool InArea(Vector2 mouse_position, Rectangle area) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
148 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
149 return ( |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
150 mouse_position.x >= area.x && |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
151 mouse_position.x < area.x + area.width && |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
152 mouse_position.y >= area.y && |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
153 mouse_position.y < area.y + area.height |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
154 ); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
155 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
156 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
157 bool Clicked(Vector2 mouse_position, Rectangle area) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
158 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
159 return (InArea(mouse_position, area) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
160 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
161 |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
162 char *PostDog_Enum_To_String(int active_enum) |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
163 { |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
164 switch(active_enum) |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
165 { |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
166 case 0: return "GET"; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
167 case 1: return "POST"; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
168 case 2: return "PUT"; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
169 case 3: return "DELETE"; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
170 } |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
171 return 0; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
172 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
173 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
174 void PostDog_History_CreateFile(char *filename, char* values) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
175 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
176 char full_file_path[512] = {0}; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
177 snprintf(full_file_path, 512, "%s/%s", POSTDOG_PATHS, filename); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
178 FILE *file = fopen(full_file_path, "w"); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
179 if (!file) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
180 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
181 printf("Failed to create a file: %s\n", full_file_path); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
182 return; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
183 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
184 fwrite(values, 1, strlen(values), file); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
185 fclose(file); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
186 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
187 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
188 void PostDog_Request_SaveFile( |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
189 const char *url, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
190 const char *method, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
191 const char *headers, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
192 const char *body, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
193 const char *response) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
194 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
195 size_t new_file_size = 1024 * 1024; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
196 Dowa_Arena *arena = Dowa_Arena_Create(1024 * 1024 * 2); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
197 char *new_file = Dowa_Arena_Allocate(arena, 1024 * 1024); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
198 snprintf( |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
199 new_file, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
200 new_file_size, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
201 "%s\n" |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
202 "---\n" |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
203 "%s\n" |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
204 "---\n" |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
205 "%s\n" |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
206 "---\n" |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
207 "%s\n" |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
208 "---\n" |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
209 "%s\n", |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
210 url, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
211 method, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
212 headers, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
213 body, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
214 response |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
215 ); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
216 char *filename = Dowa_Arena_Allocate(arena, 1024); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
217 if (!filename) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
218 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
219 perror("Error opening file"); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
220 exit(EXIT_FAILURE); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
221 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
222 char *uuid4 = (char *)Dowa_Arena_Allocate(arena, 37); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
223 if (!uuid4) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
224 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
225 perror("Error uuid"); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
226 exit(EXIT_FAILURE); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
227 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
228 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
229 int32 seed = (uint32)time(NULL) ^ counter++; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
230 Dowa_String_UUID(seed, uuid4); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
231 snprintf(filename, 1024, "%s.txt", uuid4); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
232 PostDog_History_CreateFile(filename, new_file); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
233 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
234 HistoryItem item = (HistoryItem){ .filename = malloc(sizeof(char) * strlen(filename) + 1), .rect = (Rectangle){0} }; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
235 memcpy(item.filename, filename, strlen(filename) + 1); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
236 Dowa_Array_Push(new_history_items, item); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
237 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
238 Dowa_Arena_Free(arena); |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
239 } |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
240 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
241 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
|
242 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
243 size_t real_size = size * nmemb; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
244 ResponseBuffer *buf = (ResponseBuffer *)userp; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
245 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
246 char *ptr = realloc(buf->data, buf->size + real_size + 1); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
247 if (ptr == NULL) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
248 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
249 printf("Not enough memory for response\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
250 return 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
251 } |
|
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 buf->data = ptr; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
254 memcpy(&(buf->data[buf->size]), contents, real_size); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
255 buf->size += real_size; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
256 buf->data[buf->size] = 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
257 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
258 return real_size; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
259 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
260 |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
261 int PostDog_Http_Request( |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
262 const char *url, |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
263 const char *method, |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
264 const char *headers, |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
265 const char *body, |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
266 char *response, size_t responseSize) |
|
54
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 CURL *curl; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
269 CURLcode res; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
270 ResponseBuffer buffer = { .data = malloc(1), .size = 0 }; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
271 |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
272 response[0] = '\n'; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
273 |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
274 if (buffer.data == NULL) |
|
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 snprintf(response, responseSize, "Error: Failed to allocate memory"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
277 return -1; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
278 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
279 buffer.data[0] = '\0'; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
280 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
281 curl_global_init(CURL_GLOBAL_DEFAULT); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
282 curl = curl_easy_init(); |
|
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 if (curl) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
285 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
286 struct curl_slist *headerList = NULL; |
|
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 // Set URL |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
289 curl_easy_setopt(curl, CURLOPT_URL, url); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
290 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
291 // Set HTTP method |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
292 if (strcmp(method, "POST") == 0) |
|
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 curl_easy_setopt(curl, CURLOPT_POST, 1L); |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
295 if (body && strlen(body) > 0) |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
296 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
297 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
298 else if (strcmp(method, "PUT") == 0) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
299 { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
300 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
301 if (body && strlen(body) > 0) |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
302 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
303 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
304 else if (strcmp(method, "DELETE") == 0) |
|
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 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
307 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
308 // Default is GET |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
309 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
310 // Parse and add headers |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
311 if (headers && strlen(headers) > 0) |
|
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 char *headersCopy = strdup(headers); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
314 char *line = strtok(headersCopy, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
315 while (line != NULL) { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
316 // Trim whitespace |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
317 while (*line == ' ' || *line == '\t') line++; |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
318 if (strlen(line) > 0) |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
319 headerList = curl_slist_append(headerList, line); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
320 line = strtok(NULL, "\n"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
321 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
322 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerList); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
323 free(headersCopy); |
|
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 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
326 // Set write callback |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
327 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Postdog_Curl_Callback); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
328 curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&buffer); |
|
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 // Follow redirects |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
331 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
332 // Set timeout |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
333 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30L); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
334 // Perform request |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
335 res = curl_easy_perform(curl); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
336 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
337 if (res != CURLE_OK) |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
338 snprintf(response, responseSize, "Error: %s\n", curl_easy_strerror(res)); |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
339 else |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
340 { |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
341 long response_code; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
342 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); |
|
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 snprintf(response, responseSize, "HTTP Status: %ld\n\n%s", |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
345 response_code, buffer.data ? buffer.data : ""); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
346 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
347 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
348 // Cleanup |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
349 if (headerList) curl_slist_free_all(headerList); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
350 curl_easy_cleanup(curl); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
351 } else { |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
352 snprintf(response, responseSize, "Error: Failed to initialize curl"); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
353 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
354 |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
355 free(buffer.data); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
356 curl_global_cleanup(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
357 |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
358 PostDog_Request_SaveFile( |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
359 url, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
360 method, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
361 headers, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
362 body, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
363 response); |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
364 return 0; |
|
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 |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
367 void PostDog_Update_URL(char **p_url_input_text, char* get_params) |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
368 { |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
369 char *url_input_text = *p_url_input_text; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
370 |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
371 // Reset |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
372 char *question_mark = strchr(url_input_text, '?'); |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
373 if (question_mark) |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
374 *question_mark = '\0'; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
375 |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
376 int get_params_length = (int)strlen(get_params) ; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
377 if (get_params_length == 0) |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
378 return; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
379 |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
380 char *separator = "?"; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
381 |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
382 Dowa_Arena *arena = Dowa_Arena_Create(1024*1024); |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
383 char **lines = Dowa_String_Split(get_params, "\n", get_params_length, 1, arena); |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
384 for (int i = 0; i < Dowa_Array_Length(lines); i++) |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
385 { |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
386 char *line = lines[i]; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
387 char **key_value = Dowa_String_Split(line, " ", (int)strlen(line), 1, arena); |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
388 |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
389 if (Dowa_Array_Length(key_value) < 2) |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
390 break; |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
391 |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
392 strcat(url_input_text, separator); |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
393 strcat(url_input_text, key_value[0]); |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
394 strcat(url_input_text, "="); |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
395 for (int i = 1; i < Dowa_Array_Length(key_value); i++) |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
396 { |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
397 if (!key_value[i] || key_value[i][0] == '\0') |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
398 break; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
399 if (i > 1) strcat(url_input_text, "%20"); |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
400 strcat(url_input_text, key_value[i]); |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
401 } |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
402 separator = "&"; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
403 } |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
404 |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
405 Dowa_Arena_Free(arena); |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
406 } |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
407 |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
408 int PostDog_String_To_MethodEnum(char *value) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
409 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
410 if (strstr(value, "GET")) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
411 return 0; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
412 if (strstr(value, "POST")) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
413 return 1; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
414 if (strstr(value, "PUT")) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
415 return 2; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
416 if (strstr(value, "DELETE")) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
417 return 3; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
418 return 0; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
419 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
420 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
421 void PostDog_Params_Reset( |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
422 char **p_url_input_text, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
423 int *p_active_method_dropdown, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
424 char **url_body_map, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
425 char **p_url_result_text |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
426 ) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
427 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
428 char *url_input_text = *p_url_input_text; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
429 char *url_result_text = *p_url_result_text; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
430 int active_method_dropdown = *p_active_method_dropdown; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
431 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
432 url_input_text = ""; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
433 url_result_text = ""; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
434 active_method_dropdown = 0; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
435 for (int i = 0; i < Dowa_Array_Length(url_body_map); i++) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
436 url_body_map[i] = ""; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
437 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
438 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
439 void PostDog_Load_File( |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
440 const char *filename, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
441 char **p_url_input_text, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
442 int *p_active_method_dropdown, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
443 char **url_body_map, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
444 char **p_url_result_text |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
445 ) { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
446 char *url_input_text = *p_url_input_text; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
447 char *url_result_text = *p_url_result_text; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
448 int active_method_dropdown = *p_active_method_dropdown; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
449 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
450 char full_file_path[512] = {0}; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
451 snprintf(full_file_path, 512, "%s/%s", POSTDOG_PATHS, filename); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
452 FILE *file = fopen(full_file_path, "r"); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
453 if (!file) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
454 return; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
455 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
456 fseek(file, 0, SEEK_END); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
457 size_t file_size = ftell(file); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
458 fseek(file, 0, SEEK_SET); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
459 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
460 Dowa_Arena *init_arena = Dowa_Arena_Create(file_size + 2); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
461 Dowa_Arena *split_arena = Dowa_Arena_Create(file_size * 2); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
462 char *file_buffer = Dowa_Arena_Allocate(init_arena, file_size+1); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
463 fread(file_buffer, 1, file_size, file); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
464 char **values = Dowa_String_Split(file_buffer, "---\n", file_size, 4, split_arena); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
465 Dowa_Arena_Free(init_arena); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
466 for (int i = 0; i < Dowa_Array_Length(values); i++) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
467 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
468 if (i == 0) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
469 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
470 snprintf(url_input_text, strlen(values[i]) + 1, "%s", values[i]); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
471 url_input_text[strcspn(url_input_text, "\n")] = '\0'; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
472 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
473 else if (i == 1) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
474 active_method_dropdown = PostDog_String_To_MethodEnum(values[i]); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
475 else if (i <= 3) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
476 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
477 snprintf(url_body_map[i-2], strlen(values[i]) + 1, "%s", values[i]); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
478 for (int j = strlen(values[i]); j > 0; j--) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
479 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
480 if (url_body_map[i-2][j] == '\n') |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
481 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
482 url_body_map[i-2][j] = '\0'; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
483 break; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
484 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
485 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
486 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
487 else |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
488 snprintf(url_result_text, strlen(values[i]) + 1, "%s", values[i]); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
489 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
490 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
491 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
492 Rectangle AddPadding(Rectangle rect, float padding) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
493 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
494 return (Rectangle){ |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
495 rect.x + padding, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
496 rect.y + padding, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
497 rect.width - (2 * padding), |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
498 rect.height - (2 * padding) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
499 }; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
500 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
501 |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
502 int main() |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
503 { |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
504 // -- initizlied --// |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
505 InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "PostDog"); |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
506 SetWindowState(FLAG_WINDOW_RESIZABLE); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
507 SetTargetFPS(60); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
508 |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
509 Dowa_Arena *arena = Dowa_Arena_Create(AREANA_BUFFER_LENGTH); |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
510 |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
511 Font customFont = LoadFontEx("postdog/Roboto-Regular.ttf", 20, 0, 0); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
512 GuiSetFont(customFont); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
513 GuiSetStyle(DEFAULT, TEXT_SIZE, 20); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
514 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
515 // -- Starting pos ---// |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
516 // Everyhting is relative to sidebar at this point lol |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
517 float side_bar_x = 10; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
518 float side_bar_y = 10; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
519 Rectangle history_sidebar = { .x = side_bar_x, .y = side_bar_y, .width = 0, .height = 0 }; |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
520 Dowa_Array_Reserve(history_items, 10); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
521 Dowa_Array_Reserve(new_history_items, 10); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
522 PostDog_History_Load(&history_items); |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
523 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
524 Rectangle url_area = { 0 }; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
525 Rectangle textBounds = { 0 }; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
526 Rectangle url_input_bounds = { 0 }; |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
527 bool url_input_edit = false; |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
528 Rectangle url_text_bounds = { 0 }; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
529 Rectangle url_enter_button = { 0 }; |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
530 Rectangle method_dropdown = { 0 }; |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
531 |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
532 |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
533 char *url_input_text = (char *)Dowa_Arena_Allocate(arena, URL_TEXT_BUFFER); |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
534 snprintf(url_input_text, URL_TEXT_BUFFER, "https://httpbin.org/get"); |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
535 |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
536 char **url_body_map = NULL; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
537 Dowa_Array_Push_Arena(url_body_map, (char *)Dowa_Arena_Allocate(arena, HEADER_BUFFER_LENGTH), arena); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
538 Dowa_Array_Push_Arena(url_body_map, (char *)Dowa_Arena_Allocate(arena, BODY_BUFFER_LENGTH), arena); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
539 Dowa_Array_Push_Arena(url_body_map, (char *)Dowa_Arena_Allocate(arena, DEFAULT_TEXT_BUFFER_LENGTH), arena); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
540 Dowa_Array_Push_Arena(url_body_map, (char *)Dowa_Arena_Allocate(arena, DEFAULT_TEXT_BUFFER_LENGTH), arena); |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
541 |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
542 snprintf(url_body_map[TAB_HEADER], HEADER_BUFFER_LENGTH, "Content-Type: application/json"); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
543 snprintf(url_body_map[TAB_BODY], HEADER_BUFFER_LENGTH, ""); |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
544 |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
545 char *url_result_text = (char *)Dowa_Arena_Allocate(arena, RESULT_BUFFER_LENGTH); |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
546 |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
547 int active_method_dropdown = 0; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
548 bool method_edit = false; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
549 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
550 int sendRequest; |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
551 |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
552 // -- input --// |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
553 Rectangle input_area = { 0 }; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
554 Rectangle input_tab = { 0 }; |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
555 Rectangle input_tab_item = { 0 }; |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
556 Rectangle input_body = { 0 }; |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
557 bool input_body_bool = false; |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
558 |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
559 // -- result --// |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
560 Rectangle result_area = { 0 }; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
561 Rectangle result_body = { 0 }; |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
562 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
563 // General styling. |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
564 float padding = 10; // TODO make it % based? |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
565 int active_input_tab = 0; |
|
54
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 while (!WindowShouldClose()) |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
568 { |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
569 int screen_width = GetScreenWidth(); |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
570 int screen_height = GetScreenHeight(); |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
571 |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
572 history_sidebar.width = screen_width * 0.15; |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
573 history_sidebar.height = screen_width - 10; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
574 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
575 int32 new_history_items_length = Dowa_Array_Length(new_history_items); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
576 int32 history_item_length = Dowa_Array_Length(history_items); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
577 int32 total = new_history_items_length + history_item_length; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
578 for (int i = 0; i < total; i++) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
579 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
580 HistoryItem *curr_history_items = i < new_history_items_length ? &new_history_items[i] : &history_items[i - new_history_items_length]; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
581 curr_history_items->rect.x = history_sidebar.x + padding; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
582 curr_history_items->rect.y = history_sidebar.y + (padding * 2 * (i+1)) + (i * history_sidebar.height * 0.05); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
583 curr_history_items->rect.width = history_sidebar.width - (padding * 2); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
584 curr_history_items->rect.height = history_sidebar.height * 0.05; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
585 } |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
586 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
587 // -- URL Area --// |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
588 url_area.x = (side_bar_x + history_sidebar.width); |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
589 url_area.y = (side_bar_y); |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
590 url_area.width = (screen_width - history_sidebar.width) * 0.9; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
591 url_area.height = (screen_height) * 0.1; |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
592 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
593 url_text_bounds.x = url_area.x + padding; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
594 url_text_bounds.y = (url_area.height) / 2; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
595 url_text_bounds.width = 7 * (TEXT_SIZE / 2); |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
596 url_text_bounds.height = TEXT_SIZE * 2; |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
597 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
598 url_input_bounds.x = url_text_bounds.x + url_text_bounds.width + padding; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
599 url_input_bounds.y = (url_area.height) / 2; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
600 url_input_bounds.width = (url_area.width - padding) * 0.7; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
601 url_input_bounds.height = TEXT_SIZE * 2; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
602 |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
603 url_enter_button.x = url_input_bounds.x + url_input_bounds.width + padding; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
604 url_enter_button.y = (url_area.height) / 2; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
605 url_enter_button.width = (url_area.width - padding) * 0.1; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
606 url_enter_button.height = TEXT_SIZE * 2; |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
607 |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
608 method_dropdown.x = url_enter_button.x + url_enter_button.width + padding; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
609 method_dropdown.y = (url_area.height) / 2; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
610 method_dropdown.width = (url_area.width - padding) * 0.1; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
611 method_dropdown.height = TEXT_SIZE * 2; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
612 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
613 // -- Input Area --// |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
614 input_area.x = (side_bar_x + history_sidebar.width); |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
615 input_area.y = (side_bar_y + url_area.height); |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
616 input_area.width = url_area.width * 0.5; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
617 input_area.height = screen_height - url_area.height; |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
618 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
619 input_tab.x = (side_bar_x + history_sidebar.width) + padding; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
620 input_tab.y = (side_bar_y + url_area.height) + padding; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
621 input_tab.width = url_area.width * 0.49 - padding; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
622 input_tab.height = input_area.height * 0.1; |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
623 input_tab_item = input_tab; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
624 input_tab_item.width = input_tab.width / 4; |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
625 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
626 input_body.x = input_tab.x; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
627 input_body.y = input_tab.y + input_tab.height; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
628 input_body.width = url_area.width * 0.49 - padding; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
629 input_body.height = input_area.height - input_tab.height - padding; |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
630 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
631 // -- Result Area --// |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
632 result_area.x = (input_area.x + input_area.width); |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
633 result_area.y = (side_bar_y + url_area.height); |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
634 result_area.width = url_area.width * 0.49; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
635 result_area.height = screen_height - url_area.height; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
636 |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
637 result_body.x = result_area.x + padding; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
638 result_body.y = result_area.y + input_tab.height + padding; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
639 result_body.width = url_area.width * 0.49 - padding; |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
640 result_body.height = result_area.height - input_tab.height - padding; |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
641 |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
642 Vector2 mouse_position = GetMousePosition(); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
643 |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
644 BeginDrawing(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
645 ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR))); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
646 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
647 DrawRectangleRec(history_sidebar, Fade(GRAY, 0.1f)); |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
648 for (int i = 0; i < total; i++) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
649 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
650 HistoryItem *curr_history_items = i < new_history_items_length ? &new_history_items[i] : &history_items[i - new_history_items_length]; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
651 DrawRectangleRec(curr_history_items->rect, Fade(RED, 0.1f)); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
652 GuiDrawText(curr_history_items->filename, AddPadding(curr_history_items->rect, padding), TEXT_ALIGN_CENTER, RED); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
653 } |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
654 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
655 // URL area Rect |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
656 GuiDrawText("URL: ", url_text_bounds, TEXT_ALIGN_CENTER, RED); |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
657 DrawRectangleRec(url_area, Fade(RED, 0.1f)); |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
658 if (GuiTextBox(url_input_bounds, url_input_text, DEFAULT_TEXT_BUFFER_LENGTH, url_input_edit)) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
659 url_input_edit = !url_input_edit; |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
660 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
661 sendRequest = GuiButton(url_enter_button, "ENTER"); |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
662 if (sendRequest) |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
663 PostDog_Http_Request( |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
664 url_input_text, |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
665 PostDog_Enum_To_String(active_method_dropdown), |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
666 url_body_map[TAB_HEADER], |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
667 url_body_map[TAB_BODY], |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
668 url_result_text, |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
669 RESULT_BUFFER_LENGTH |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
670 ); |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
671 if (GuiDropdownBox(method_dropdown, "GET;POST;PUT;DELETE", &active_method_dropdown, method_edit)) |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
672 method_edit = !method_edit; |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
673 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
674 // Input Tabs Rect |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
675 DrawRectangleRec(input_area, Fade(BLUE, 0.1f)); |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
676 DrawRectangleRec(input_tab, Fade(DARKBLUE, 0.1f)); |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
677 GuiSetStyle(TOGGLE, GROUP_PADDING, 0); |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
678 if (JUNE_GuiTextBox(input_body, url_body_map[active_input_tab], DEFAULT_TEXT_BUFFER_LENGTH, input_body_bool)) |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
679 input_body_bool = !input_body_bool; |
|
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
680 GuiToggleGroup(input_tab_item, "Header;Body;Get Param;Bar", &active_input_tab); |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
681 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
682 PostDog_Update_URL(&url_input_text, url_body_map[TAB_GET_PARAMS]); |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
683 |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
684 // Result Rect |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
685 DrawRectangleRec(result_area, Fade(GREEN, 0.1f)); |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
63
diff
changeset
|
686 DrawRectangleRec(result_body, Fade(DARKGREEN, 0.1f)); |
|
112
d6d578b49a19
[PostDog] Got CRUD working.
June Park <parkjune1995@gmail.com>
parents:
111
diff
changeset
|
687 GuiTextBoxMulti(result_body, url_result_text, RESULT_BUFFER_LENGTH, false); |
|
114
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
688 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
689 if (url_input_edit && (IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C)) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
690 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
691 SetClipboardText(url_input_text); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
692 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
693 else if (input_body_bool && (IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C)) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
694 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
695 SetClipboardText(url_body_map[active_input_tab]); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
696 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
697 else if (InArea(mouse_position, result_body)) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
698 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
699 DrawRectangleRec(result_body, Fade(GREEN, 0.3f)); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
700 if ((IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C)) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
701 SetClipboardText(url_result_text); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
702 } |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
703 |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
704 for (int i = 0; i < Dowa_Array_Length(history_items); i++) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
705 { |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
706 if (Clicked(mouse_position, history_items[i].rect)) |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
707 PostDog_Load_File( |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
708 history_items[i].filename, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
709 &url_input_text, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
710 &active_method_dropdown, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
711 url_body_map, |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
712 &url_result_text |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
713 ); |
|
e2a73e64e8e6
[Postdog] Got history working.
June Park <parkjune1995@gmail.com>
parents:
112
diff
changeset
|
714 } |
|
54
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
715 EndDrawing(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
716 } |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
717 CloseWindow(); |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
718 return 0; |
|
b3e82d22f961
[PostDog] Initial commit BROKEN
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
719 } |