clientaccount.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <string.h>
00021 #include <libpurple/account.h>
00022
00023 #include "../../dprint.h"
00024
00025 #include "defines.h"
00026 #include "clientaccount.h"
00027 #include "mapping.h"
00028
00029 extern PurpleProxyInfo *proxy;
00030
00031 PurpleAccount *client_find_account(extern_account_t *account) {
00032 PurpleAccount *r;
00033
00034 char* plugin;
00035 char username[255];
00036 memset(username, 0, 255);
00037
00038 if (strcmp(account->protocol, "gtalk") == 0) {
00039 sprintf(username, "%s%s", account->username, "/sip");
00040 plugin = "prpl-jabber";
00041 }
00042 else {
00043 sprintf(username, "%s", account->username);
00044 plugin = account->protocol;
00045 }
00046
00047
00048 LM_DBG("searching purple account for %s with plugin %s \n", username, plugin);
00049 r = purple_accounts_find(username, plugin);
00050 if (r) {
00051 LM_DBG("account %s found\n", username);
00052 return r;
00053 }
00054
00055 LM_DBG("account %s not found, creating.\n", username);
00056 r = purple_account_new(username, plugin);
00057 purple_account_set_password(r, account->password);
00058 purple_account_set_remember_password(r, TRUE);
00059
00060 if (proxy != NULL)
00061 purple_account_set_proxy_info(r, proxy);
00062
00063 if (strcmp(account->protocol, "gtalk") == 0)
00064 purple_account_set_string(r, "connect_server", "talk.google.com");
00065
00066 purple_accounts_add(r);
00067
00068 return r;
00069 }
00070
00071 void client_enable_account(PurpleAccount *account) {
00072
00073 if ((account) && !purple_account_get_enabled(account, UI_ID)) {
00074 LM_DBG("account %s disabled, enabling...\n", account->username);
00075 purple_account_set_enabled(account, UI_ID, TRUE);
00076 }
00077
00078 if ((account) && purple_account_is_disconnected(account)) {
00079 LM_DBG("account %s disconnected, reconnecting...\n", account->username);
00080 purple_account_connect(account);
00081 LM_DBG("account %s connection called\n", account->username);
00082 }
00083 }
00084
00085