2 * This file is part of sharing-plugin-template
4 * Copyright (C) 2008-2009 Nokia Corporation. All rights reserved.
6 * This maemo code example is licensed under a MIT-style license,
7 * that can be found in the file called "COPYING" in the root
15 #include "libsharing/sharing-account.h"
16 #include "libsharing/sharing-service-option.h"
18 #include <conicconnection.h>
24 * @account: #SharingAccount to be tested
25 * @con: Connection used
26 * @dead_mans_switch: Turn to %FALSE at least every 30 seconds.
28 * Test if #SharingAccount is valid.
30 * Returns: #SharingPluginInterfaceTestAccountResult
32 SharingPluginInterfaceAccountValidateResult validate (SharingAccount* account,
33 ConIcConnection* con, gboolean *cont, gboolean* dead_mans_switch)
35 SharingPluginInterfaceAccountValidateResult ret = SHARING_ACCOUNT_VALIDATE_FAILED;
37 char* sessionKey = NULL;
38 char* sessionRequestId = NULL;
41 *dead_mans_switch = FALSE;
42 if (yandexGetSessionKey(&sessionKey, &sessionRequestId) == YANDEX_GET_SESSION_KEY_SUCCESS) {
43 *dead_mans_switch = FALSE;
44 yandexGetAuthTokenResult res =
45 yandexGetAuthToken(sessionRequestId, sessionKey,
46 sharing_account_get_username(account), sharing_account_get_password(account),
49 case YANDEX_GET_AUTH_TOKEN_SUCCESS:
50 ret = SHARING_ACCOUNT_VALIDATE_SUCCESS;
51 GSList* albumsList = NULL;
52 if (YANDEX_GET_ALBUM_LIST_SUCCESS == yandexGetAlbumsList(token,sharing_account_get_username(account),&albumsList) && albumsList)
53 sharing_account_set_option_values(account,"album",albumsList);
54 if (albumsList) sharing_service_option_values_free(albumsList);
56 case YANDEX_GET_AUTH_TOKEN_FAILED:
57 ret = SHARING_ACCOUNT_VALIDATE_ERROR_UNKNOWN;
59 case YANDEX_GET_AUTH_TOKEN_INVALID_USER:
60 ret = SHARING_ACCOUNT_VALIDATE_FAILED;
64 *dead_mans_switch = FALSE;
66 if (token) free(token);
67 if (sessionKey) free(sessionKey);
68 if (sessionRequestId) free(sessionRequestId);