aboutsummaryrefslogtreecommitdiff
path: root/easy-tg.c
diff options
context:
space:
mode:
authorTrumeet <yuuta@yuuta.moe>2021-10-12 14:12:27 -0700
committerTrumeet <yuuta@yuuta.moe>2021-10-12 14:12:27 -0700
commit612fa53409ae24bf4b17e87a0c52e63658b59014 (patch)
treef05554fb57ea2162333d8918b0a3498550707fb7 /easy-tg.c
parent5eb340686e89c77411dc9c2b301db02b69739676 (diff)
downloadeasy-tg-612fa53409ae24bf4b17e87a0c52e63658b59014.tar
easy-tg-612fa53409ae24bf4b17e87a0c52e63658b59014.tar.gz
easy-tg-612fa53409ae24bf4b17e87a0c52e63658b59014.tar.bz2
easy-tg-612fa53409ae24bf4b17e87a0c52e63658b59014.zip
handle updateConnectionState
Diffstat (limited to 'easy-tg.c')
-rw-r--r--easy-tg.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/easy-tg.c b/easy-tg.c
index baac4a8..ff2dd00 100644
--- a/easy-tg.c
+++ b/easy-tg.c
@@ -237,6 +237,33 @@ int tg_destroy()
return 0;
}
+static int handle_update_connection_state(const json_object *json)
+{
+ int r = TG_IGNORE;
+ json_object *obj = NULL;
+ if(!json_object_object_get_ex(json, "state", &obj) ||
+ !json_object_object_get_ex(obj, "@type", &obj))
+ goto cleanup;
+ r = TG_CONNECTION;
+ tg_reg1 = json_object_get_string(obj);
+ if(!strcmp(tg_reg1, "connectionStateConnecting"))
+ tg_errno = TG_CONNECTION_CONNECTING;
+ else if(!strcmp(tg_reg1, "connectionStateConnectingToProxy"))
+ tg_errno = TG_CONNECTION_CONNECTING_PROXY;
+ else if(!strcmp(tg_reg1, "connectionStateReady"))
+ tg_errno = TG_CONNECTION_READY;
+ else if(!strcmp(tg_reg1, "connectionStateUpdating"))
+ tg_errno = TG_CONNECTION_UPDATING;
+ else if(!strcmp(tg_reg1, "connectionStateWaitingForNetwork"))
+ tg_errno = TG_CONNECTION_WAITING_NETWORK;
+ else
+ r = TG_RUN;
+
+ goto cleanup;
+cleanup:
+ return r;
+}
+
int tg_loop()
{
if(tg_update != NULL)
@@ -267,6 +294,8 @@ int tg_loop()
r = handle_update_authorization_state(tg_update);
else if(!strcmp(tg_update_type, "error"))
r = handle_update_error(tg_update);
+ else if(!strcmp(tg_update_type, "updateConnectionState"))
+ r = handle_update_connection_state(tg_update);
else
r = TG_RUN;
goto cleanup;