This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository minilauncher-for-slippi.

View the commit online.

commit ce3a319f4fabe91edc95921080fe292e4289ed3b
Author: Nekobit <m...@ow.nekobit.net>
AuthorDate: Sun Sep 17 17:37:22 2023 -0400

    Cleaner HTTP handling, print some real datagit add .
---
 Makefile                  |  4 +--
 gg.c                      | 92 +++++++++++++++++++++++++++++++++++++++--------
 home.c                    |  9 +++--
 http.c                    | 21 ++++++++++-
 http.h                    | 12 ++++++-
 static/tourney_query.json | 27 ++------------
 6 files changed, 117 insertions(+), 48 deletions(-)

diff --git a/Makefile b/Makefile
index d370cc0..5934c44 100644
--- a/Makefile
+++ b/Makefile
@@ -11,10 +11,10 @@ filec: file-to-c/main.o
 	$(CC) -o filec file-to-c/main.o
 	
 $(CHEAD_C): $(CHEAD)
-	./filec static/tourney_query.json data_tourney_query_tt > $@
+	./filec static/tourney_query.json data_tourney_query > $@
 
 minilauncher4slippi: $(OBJS)
 	$(CC) -o minilauncher4slippi $(OBJS) $(LDFLAGS)
 
 clean:
-	rm minilauncher4slippi filec *.o static/*.h
+	rm -f minilauncher4slippi filec *.o static/*.h
diff --git a/gg.c b/gg.c
index 02fe076..deebe62 100644
--- a/gg.c
+++ b/gg.c
@@ -9,6 +9,7 @@ Evas_Object* tab_gg = NULL;
 static Evas_Object* tab_gg_sidebar;
 static Evas_Object* tab_gg_content;
 extern char* start_gg_api;
+//extern char* start_gg_token;
 
 static int player_id;
 
@@ -21,21 +22,68 @@ _gg_sidebar_cb(void *_data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_
 	//update_tab(*data);
 }
 
+static void
+_gg_set_token(Ecore_Con_Url* ec_url, char* token)
+{
+	Eina_Strbuf* sesh = eina_strbuf_new();
+	eina_strbuf_append_printf(sesh, "gg_session=%s;", token);
+	//Eina_Strbuf* bearer = eina_strbuf_new();
+	//eina_strbuf_append_printf(bearer, "Bearer %s", start_gg_token);
+	ecore_con_url_additional_header_add(ec_url, "Cookie", eina_strbuf_string_get(sesh));
+	ecore_con_url_additional_header_add(ec_url, "x-web-source", "gg-web-gql-client, gg-web-rest");
+	//ecore_con_url_additional_header_add(ec_url, "Authorization", eina_strbuf_string_get(bearer));
+	free(eina_strbuf_release(sesh));
+	//free(eina_strbuf_release(bearer));
+}
+
 static Eina_Bool
-_gg_scrape_result(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
+_gg_tourneys_result(struct memory_chunk* dd, void *deta EINA_UNUSED, int type EINA_UNUSED, void *event_info)
 {
 	Ecore_Con_Event_Url_Complete* ev = event_info;
-	struct memory_chunk* dd = ecore_con_url_data_get(ev->url_con);
+
+	cJSON* json = cJSON_Parse(dd->data);
+	if (!json)
+	{
+		fprintf(stderr, "Something happened.\n");
+		return EINA_FALSE;
+	}
+	
+	cJSON* data = "" "data");
+	cJSON* user = cJSON_GetObjectItemCaseSensitive(data, "user");
+	cJSON* player = cJSON_GetObjectItemCaseSensitive(user, "player");
+	cJSON* events = cJSON_GetObjectItemCaseSensitive(player, "events");
+	cJSON* nodes = cJSON_GetObjectItemCaseSensitive(events, "nodes");
 	
+	//int i = 0;
+	//for (cJSON* c = nodes->child; c->next != NULL; (++i, c = c->next))
+	cJSON* c;
+	cJSON_ArrayForEach(c, nodes)
+	{
+		cJSON* entity = cJSON_GetObjectItemCaseSensitive(c, "entity");
+		printf("name: %s\n", cJSON_GetObjectItemCaseSensitive(entity, "name")->valuestring);
+	}
+	
+	return EINA_TRUE;
+}
+
+static Eina_Bool
+_gg_scrape_result(struct memory_chunk* dd, void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
+{
 #define magiccode "script id=\"__NEXT_DATA__\" type=\"application/json\">"
 	char* start_json = strstr(dd->data, magiccode);
 	if (!start_json)
+	{
+		fprintf(stderr, "Something happened with start_json.\n");
 		return EINA_FALSE; // Some error
+	}
 	start_json += sizeof(magiccode) - 1;
 	
 	char* end_json = strstr(start_json, "</script><script>");
 	if (!end_json)
+	{
+		fprintf(stderr, "Something happened with end_json.\n");
 		return EINA_FALSE;
+	}
 	*end_json = '\0';
 #undef magiccode
 	// Data required is scraped now!
@@ -56,9 +104,33 @@ _gg_scrape_result(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info
 	cJSON* jplayer_id = cJSON_GetObjectItemCaseSensitive(users, "id");
 	if (jplayer_id)
 		player_id = jplayer_id->valueint;
+	else
+	{
+		printf("Token expired. Create a new one.\n");
+		return EINA_FALSE;
+	}
+	
+	free(dd);
 	
 	// Now attempt another request
+	// RANT: There are two endpoints. api.start.gg/gql/alpha is the official, and it SUCKS
+	Ecore_Con_Url* ec_url = ecore_con_url_custom_new("https://www.start.gg/api/-/gql", "POST");
+	ecore_con_url_data_set(ec_url, memory_chunk_alloc(_gg_tourneys_result));
+	ecore_con_url_verbose_set(ec_url, EINA_TRUE);
+	//ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, memory_chunk_data, NULL);
+	//ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, memory_chunk_result, NULL);
+	ecore_con_url_additional_header_add(ec_url, "User-Agent", ":^)'); DROP TABLE users; --");
 	
+	_gg_set_token(ec_url, (char*)data);
+	// Fill info
+	Eina_Strbuf* req = eina_strbuf_new();
+	eina_strbuf_append_printf(req, data_tourney_query, player_id);
+	// Need to remove real newlines
+	eina_strbuf_replace_all(req, "\n", "\\n");
+	// Need to remove the newline at the end or it's not valid.
+	ecore_con_url_post(ec_url, eina_strbuf_string_get(req), eina_strbuf_length_get(req)-2, "application/json, application/json");
+	free(eina_strbuf_release(req));
+	return EINA_FALSE;
 #if 0
 	int i = 0;
 	for (cJSON* c = tournament->child; c->next != NULL; (++i, c = c->next))
@@ -68,25 +140,17 @@ _gg_scrape_result(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info
 #endif
 }
 
-static void
-_gg_set_token(Ecore_Con_Url* ec_url, char* token)
-{
-	Eina_Strbuf* sesh = eina_strbuf_new();
-	eina_strbuf_append_printf(sesh, "gg_session=%s;", token);
-	ecore_con_url_additional_header_add(ec_url, "Cookie", eina_strbuf_string_get(sesh));
-	free(eina_strbuf_release(sesh));
-}
-
 static void
 _gg_scrape_homepage(char* token)
 {
+	if (!ecore_con_url_pipeline_get())
+    	ecore_con_url_pipeline_set(EINA_TRUE);
 	Ecore_Con_Url* ec_url = ecore_con_url_custom_new("https://www.start.gg/", "GET");
-	ecore_con_url_data_set(ec_url, memory_chunk_alloc());
+	ecore_con_url_data_set(ec_url, memory_chunk_alloc(_gg_scrape_result));
 	ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, memory_chunk_data, NULL);
-	ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _gg_scrape_result, NULL);
+	ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, memory_chunk_result, token);
 	ecore_con_url_additional_header_add(ec_url, "User-Agent", ":^)'); DROP TABLE users; --");
 	_gg_set_token(ec_url, token);
-
 	ecore_con_url_get(ec_url);
 }
 
diff --git a/home.c b/home.c
index 83c64cb..1900118 100644
--- a/home.c
+++ b/home.c
@@ -10,11 +10,10 @@ char const* home_url = "https://api.github.com/repos/project-slippi/Ishiiruka/re
 
 	
 static Eina_Bool
-releases_result(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
+releases_result(struct memory_chunk* dd, void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
 {
 	Evas_Object* parent = data;
 	Ecore_Con_Event_Url_Complete* ev = event_info;
-	struct memory_chunk* dd = ecore_con_url_data_get(ev->url_con);
 	cJSON* json = cJSON_ParseWithLength(dd->data, dd->size);
 	if (!json)
 	{
@@ -94,9 +93,9 @@ _tab_home_make_da_damn_request(Evas_Object* parent)
 	//ecore_con_init();
 	//ecore_con_url_init();
 	Ecore_Con_Url* ec_url = ecore_con_url_custom_new(home_url, "GET");
-	ecore_con_url_data_set(ec_url, memory_chunk_alloc());
+	ecore_con_url_data_set(ec_url, memory_chunk_alloc(releases_result));
 	ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, memory_chunk_data, NULL);
-	ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, releases_result, parent);
+	ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, memory_chunk_result, parent);
 	ecore_con_url_additional_header_add(ec_url, "User-Agent", ":^)'); DROP TABLE issues; --");
 	ecore_con_url_additional_header_add(ec_url, "Accept", "application/vnd.github.html");
 	ecore_con_url_get(ec_url);
@@ -124,7 +123,7 @@ tab_home_setup(Evas_Object* parent)
 	evas_object_show(tab_home_scr);
 	evas_object_show(tab_home);
 	
-//   	_tab_home_make_da_damn_request(tab_home_content);
+   	//_tab_home_make_da_damn_request(tab_home_content);
 	
 	// Add progress bar for noa
 	Evas_Object* speen = elm_progressbar_add(tab_home_content);
diff --git a/http.c b/http.c
index a1213e4..2e95dca 100644
--- a/http.c
+++ b/http.c
@@ -5,7 +5,10 @@
 #include "http.h"
 
 struct memory_chunk*
-memory_chunk_alloc(void)
+memory_chunk_alloc(Eina_Bool (*callback)(struct memory_chunk* meta,
+	                      void *data EINA_UNUSED,
+	                      int type EINA_UNUSED,
+	                      void *event_info))
 {
 	struct memory_chunk* data = "" sizeof(struct memory_chunk));
 	if (!data)
@@ -13,6 +16,7 @@ memory_chunk_alloc(void)
 		perror("memory_chunk_alloc");
 		exit(1);
 	}
+	data->callback = callback;
 	
 	return data;
 }
@@ -25,8 +29,23 @@ memory_chunk_data(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info
 
 	dd->data = "" dd->size + ev->size + 1);
 	
+#ifndef NDEBUG
+	printf("---------------DEBUG---------------\n");
+	printf("%.*s\n", ev->size, ev->data);
+	printf("-----------------------------------\n\n");
+#endif
+	
 	memcpy(dd->data + dd->size, ev->data, ev->size);
 	dd->size += ev->size;
 	dd->data[dd->size] = 0;
 	return EINA_TRUE;
 }
+
+Eina_Bool
+memory_chunk_result(void *data, int type, void *event_info)
+{
+	Ecore_Con_Event_Url_Complete* ev = event_info;
+	struct memory_chunk* dd = ecore_con_url_data_get(ev->url_con);
+	
+	return dd->callback(dd, data, type, event_info);
+}
diff --git a/http.h b/http.h
index ec2a55c..4d00ed4 100644
--- a/http.h
+++ b/http.h
@@ -5,12 +5,22 @@
 struct memory_chunk {
 	char* data;
 	size_t size;
+	Eina_Bool (*callback)(struct memory_chunk* meta,
+	                      void *data EINA_UNUSED,
+	                      int type EINA_UNUSED,
+	                      void *event_info);
 };
 
 struct memory_chunk*
-memory_chunk_alloc(void);
+memory_chunk_alloc(Eina_Bool (*callback)(struct memory_chunk* meta,
+	                      void *data EINA_UNUSED,
+	                      int type EINA_UNUSED,
+	                      void *event_info));
 
 Eina_Bool
 memory_chunk_data(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info);
 
+Eina_Bool
+memory_chunk_result(void *data, int type, void *event_info);
+
 #endif /* HTTP_H */
diff --git a/static/tourney_query.json b/static/tourney_query.json
index f2e4fe1..f84f067 100644
--- a/static/tourney_query.json
+++ b/static/tourney_query.json
@@ -1,7 +1,6 @@
-[{"operationName":"UserTournaments","variables":{"userId":%d,"upcomingQuery":{"perPage":3,"filter":{"upcoming":true},"sortBy":"startDate ASC"},"pastQuery":{"perPage":3,"filter":{"past":true},"sortBy":"startDate DESC"}},"query":"query UserTournaments($userId: ID!, $upcomingQuery: PlayerScheduleQuery, $pastQuery: PlayerScheduleQuery) {
+[{"operationName":"UserTournaments","variables":{"userId":%d},"query":"query UserTournaments($userId: ID!) {
   user(id: $userId) {
     ...userTournaments
-    __typename
   }
 }
 
@@ -9,32 +8,16 @@ fragment userTournaments on User {
   id
   player {
     id
-    upcomingAdminSchedule: adminSchedule(query: $upcomingQuery) {
+    events: adminSchedule {
       nodes {
         id
         entity {
           ...tournamentInfo
-          __typename
         }
-        __typename
       }
-      __typename
     }
-    pastAdminSchedule: adminSchedule(query: $pastQuery) {
-      nodes {
-        id
-        entity {
-          ...tournamentInfo
-          __typename
-        }
-        __typename
-      }
-      __typename
-    }
-    __typename
   }
   discriminator
-  __typename
 }
 
 fragment tournamentInfo on Tournament {
@@ -45,7 +28,6 @@ fragment tournamentInfo on Tournament {
     id
     type
     url
-    __typename
   }
   startAt
   endAt
@@ -60,16 +42,11 @@ fragment tournamentInfo on Tournament {
       videogame {
         id
         name
-        __typename
       }
-      __typename
     }
     entrants {
       id
-      __typename
     }
-    __typename
   }
-  __typename
 }
 "}]

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to