store json information in account
This commit is contained in:
parent
42183539d3
commit
aed7dacf29
@ -19,6 +19,12 @@ char const *dc_account_password(dc_account_t a);
|
|||||||
void dc_account_set_id(dc_account_t a, char const *id);
|
void dc_account_set_id(dc_account_t a, char const *id);
|
||||||
char const *dc_account_id(dc_account_t a);
|
char const *dc_account_id(dc_account_t a);
|
||||||
|
|
||||||
|
void dc_account_set_username(dc_account_t a, char const *id);
|
||||||
|
char const *dc_account_username(dc_account_t a);
|
||||||
|
|
||||||
|
void dc_account_set_discriminator(dc_account_t a, char const *id);
|
||||||
|
char const *dc_account_discriminator(dc_account_t a);
|
||||||
|
|
||||||
void dc_account_set_token(dc_account_t a, char const *token);
|
void dc_account_set_token(dc_account_t a, char const *token);
|
||||||
char const *dc_account_token(dc_account_t a);
|
char const *dc_account_token(dc_account_t a);
|
||||||
bool dc_account_has_token(dc_account_t a);
|
bool dc_account_has_token(dc_account_t a);
|
||||||
|
@ -17,6 +17,15 @@ struct dc_account_
|
|||||||
/* internal ID
|
/* internal ID
|
||||||
*/
|
*/
|
||||||
char *id;
|
char *id;
|
||||||
|
/* username
|
||||||
|
*/
|
||||||
|
char *username;
|
||||||
|
/* discriminator
|
||||||
|
*/
|
||||||
|
char *discriminator;
|
||||||
|
/* full username username#discriminator
|
||||||
|
*/
|
||||||
|
char *full;
|
||||||
|
|
||||||
/* authentication token
|
/* authentication token
|
||||||
*/
|
*/
|
||||||
@ -121,3 +130,50 @@ char const *dc_account_id(dc_account_t a)
|
|||||||
return_if_true(a == NULL,NULL);
|
return_if_true(a == NULL,NULL);
|
||||||
return a->id;
|
return a->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dc_account_update_full(dc_account_t a)
|
||||||
|
{
|
||||||
|
free(a->full);
|
||||||
|
a->full = NULL;
|
||||||
|
|
||||||
|
asprintf(&a->full, "%s/%s",
|
||||||
|
(a->username != NULL ? a->username : ""),
|
||||||
|
(a->discriminator != NULL ? a->discriminator : "")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dc_account_set_username(dc_account_t a, char const *id)
|
||||||
|
{
|
||||||
|
return_if_true(a == NULL,);
|
||||||
|
|
||||||
|
free(a->username);
|
||||||
|
a->username = strdup(id);
|
||||||
|
dc_account_update_full(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
char const *dc_account_username(dc_account_t a)
|
||||||
|
{
|
||||||
|
return_if_true(a == NULL, NULL);
|
||||||
|
return a->username;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dc_account_set_discriminator(dc_account_t a, char const *id)
|
||||||
|
{
|
||||||
|
return_if_true(a == NULL,);
|
||||||
|
|
||||||
|
free(a->discriminator);
|
||||||
|
a->discriminator = strdup(id);
|
||||||
|
dc_account_update_full(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
char const *dc_account_discriminator(dc_account_t a)
|
||||||
|
{
|
||||||
|
return_if_true(a == NULL, NULL);
|
||||||
|
return a->discriminator;
|
||||||
|
}
|
||||||
|
|
||||||
|
char const *dc_account_full_username(dc_account_t a)
|
||||||
|
{
|
||||||
|
return_if_true(a == NULL, NULL);
|
||||||
|
return a->full;
|
||||||
|
}
|
||||||
|
@ -336,7 +336,7 @@ bool dc_api_userinfo(dc_api_t api, dc_account_t login,
|
|||||||
dc_account_t user)
|
dc_account_t user)
|
||||||
{
|
{
|
||||||
char *url = NULL;
|
char *url = NULL;
|
||||||
json_t *reply = NULL;
|
json_t *reply = NULL, *val = NULL;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
return_if_true(api == NULL, false);
|
return_if_true(api == NULL, false);
|
||||||
@ -348,9 +348,17 @@ bool dc_api_userinfo(dc_api_t api, dc_account_t login,
|
|||||||
reply = dc_api_call_sync(api, dc_account_token(login), url, NULL);
|
reply = dc_api_call_sync(api, dc_account_token(login), url, NULL);
|
||||||
goto_if_true(reply == NULL, cleanup);
|
goto_if_true(reply == NULL, cleanup);
|
||||||
|
|
||||||
/* TODO: parse json and store info in user
|
val = json_object_get(reply, "username");
|
||||||
*/
|
goto_if_true(val == NULL || !json_is_string(val), cleanup);
|
||||||
dc_util_dump_json(reply);
|
dc_account_set_username(user, json_string_value(val));
|
||||||
|
|
||||||
|
val = json_object_get(reply, "discriminator");
|
||||||
|
goto_if_true(val == NULL || !json_is_string(val), cleanup);
|
||||||
|
dc_account_set_discriminator(user, json_string_value(val));
|
||||||
|
|
||||||
|
val = json_object_get(reply, "id");
|
||||||
|
goto_if_true(val == NULL || !json_is_string(val), cleanup);
|
||||||
|
dc_account_set_id(user, json_string_value(val));
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user