clientaccount.c

Go to the documentation of this file.
00001 /* OpenSER PURPLE MODULE
00002  * 
00003  * Copyright (C) 2008 Atos Worldline
00004  * Contact: Eric PTAK <eric.ptak@atosorigin.com>
00005  *
00006  * This program is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
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 

Generated on Mon May 21 16:00:24 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6