PurplePlugin * purple_find_prpl(const char *id) { GList *l; PurplePlugin *plugin; g_return_val_if_fail(id != NULL, NULL); /* libpurple3 compatibility. * prpl-xmpp isn't used yet (it's prpl-jabber), * but may be used in the future. */ if (g_strcmp0(id, "prpl-xmpp") == 0 || g_strcmp0(id, "prpl-gtalk") == 0 || g_strcmp0(id, "prpl-facebook-xmpp") == 0) { id = "prpl-jabber"; } for (l = purple_plugins_get_protocols(); l != NULL; l = l->next) { plugin = (PurplePlugin *)l->data; if (purple_strequal(plugin->info->id, id)) return plugin; } return NULL; }
void ProtoManager::PluginsAvailable () { purple_debug_set_enabled (true); const auto& dir = Util::CreateIfNotExists ("azoth/velvetbird/purple"); purple_util_set_user_dir (dir.absolutePath ().toUtf8 ().constData ()); purple_core_set_ui_ops (&UiOps); purple_eventloop_set_ui_ops (&EvLoopOps); purple_idle_set_ui_ops (&IdleOps); purple_connections_set_ui_ops (&ConnUiOps); purple_set_blist (purple_blist_new ()); purple_blist_set_ui_data (this); purple_blist_set_ui_ops (&BListUiOps); purple_conversations_set_ui_ops (&ConvUiOps); purple_accounts_set_ui_ops (&AccUiOps); purple_notify_set_ui_ops (&NotifyUiOps); purple_imgstore_init (); purple_buddy_icons_init (); if (!purple_core_init ("leechcraft.azoth")) { qWarning () << Q_FUNC_INFO << "failed initializing libpurple"; return; } QMap<QByteArray, Protocol_ptr> id2proto; auto protos = purple_plugins_get_protocols (); while (protos) { auto item = static_cast<PurplePlugin*> (protos->data); protos = protos->next; const auto& proto = std::make_shared<Protocol> (item, Proxy_); const auto& purpleId = proto->GetPurpleID (); if (purpleId == "prpl-jabber" || purpleId == "prpl-irc") continue; Protocols_ << proto; id2proto [purpleId] = proto; } auto accs = purple_accounts_get_all (); while (accs) { auto acc = static_cast<PurpleAccount*> (accs->data); accs = accs->next; id2proto [purple_account_get_protocol_id (acc)]->PushAccount (acc); } purple_blist_load (); purple_savedstatus_activate (purple_savedstatus_get_startup ()); }
static VALUE list_protocols(VALUE self) { VALUE array = rb_ary_new(); GList *iter = purple_plugins_get_protocols(); for (; iter; iter = iter->next) { VALUE protocol = Data_Wrap_Struct(cProtocol, NULL, NULL, iter->data); rb_ary_push(array, protocol); } return array; }
void AccountWindow::addAccount(CppConsUI::Button& /*activator*/) { GList *i = purple_plugins_get_protocols(); PurpleAccount *account = purple_account_new(_("Username"), purple_plugin_get_id(reinterpret_cast<PurplePlugin*>(i->data))); /* Stop here if libpurple returned an already created account. This happens * when user pressed Add button twice in a row. In that case there is * already one "empty" account that user can edit. */ if (account_entries.find(account) == account_entries.end()) { purple_accounts_add(account); populateAccount(account); } account_entries[account].parent->grabFocus(); }
PurplePlugin * purple_find_prpl(const char *id) { GList *l; PurplePlugin *plugin; g_return_val_if_fail(id != NULL, NULL); for (l = purple_plugins_get_protocols(); l != NULL; l = l->next) { plugin = (PurplePlugin *)l->data; if (!strcmp(plugin->info->id, id)) return plugin; } return NULL; }
static VALUE list_protocols(VALUE self) { VALUE array = rb_ary_new(); GList *iter = purple_plugins_get_protocols(); int i; for (i = 0; iter; iter = iter->next) { PurplePlugin *plugin = iter->data; PurplePluginInfo *info = plugin->info; if (info && info->name) { char s[256]; snprintf(s, sizeof(s) -1, "%s %s", info->id, info->name); rb_ary_push(array, rb_str_new2(s)); } } return array; }
AccountWindow::ProtocolOption::ProtocolOption(PurpleAccount *account_, AccountWindow &account_window_) : account_window(&account_window_), account(account_) { g_assert(account); setText(_("Protocol")); for (GList *i = purple_plugins_get_protocols(); i; i = i->next) addOptionPtr(purple_plugin_get_name( reinterpret_cast<PurplePlugin*>(i->data)), i->data); const char *proto_id = purple_account_get_protocol_id(account); PurplePlugin *plugin = purple_plugins_find_with_id(proto_id); setSelectedByDataPtr(plugin); signal_selection_changed.connect(sigc::mem_fun(this, &ProtocolOption::onProtocolChanged)); }
void purple_initmodule() { struct prpl funcs; GList *prots; GString *help; char *dir; if( B_EV_IO_READ != PURPLE_INPUT_READ || B_EV_IO_WRITE != PURPLE_INPUT_WRITE ) { /* FIXME FIXME FIXME FIXME FIXME :-) */ exit( 1 ); } dir = g_strdup_printf( "%s/purple", global.conf->configdir ); purple_util_set_user_dir( dir ); g_free( dir ); purple_debug_set_enabled( FALSE ); purple_core_set_ui_ops( &bee_core_uiops ); purple_eventloop_set_ui_ops( &glib_eventloops ); if( !purple_core_init( "BitlBee") ) { /* Initializing the core failed. Terminate. */ fprintf( stderr, "libpurple initialization failed.\n" ); abort(); } if( proxytype != PROXY_NONE ) { PurpleProxyInfo *pi = purple_global_proxy_get_info(); switch( proxytype ) { case PROXY_SOCKS4: purple_proxy_info_set_type( pi, PURPLE_PROXY_SOCKS4 ); break; case PROXY_SOCKS5: purple_proxy_info_set_type( pi, PURPLE_PROXY_SOCKS5 ); break; case PROXY_HTTP: purple_proxy_info_set_type( pi, PURPLE_PROXY_HTTP ); break; } purple_proxy_info_set_host( pi, proxyhost ); purple_proxy_info_set_port( pi, proxyport ); purple_proxy_info_set_username( pi, proxyuser ); purple_proxy_info_set_password( pi, proxypass ); } purple_set_blist( purple_blist_new() ); /* No, really. So far there were ui_ops for everything, but now suddenly one needs to use signals for typing notification stuff. :-( */ purple_signal_connect( purple_conversations_get_handle(), "buddy-typing", &funcs, PURPLE_CALLBACK(prplcb_buddy_typing), NULL ); purple_signal_connect( purple_conversations_get_handle(), "buddy-typed", &funcs, PURPLE_CALLBACK(prplcb_buddy_typing), NULL ); purple_signal_connect( purple_conversations_get_handle(), "buddy-typing-stopped", &funcs, PURPLE_CALLBACK(prplcb_buddy_typing), NULL ); memset( &funcs, 0, sizeof( funcs ) ); funcs.login = purple_login; funcs.init = purple_init; funcs.logout = purple_logout; funcs.buddy_msg = purple_buddy_msg; funcs.away_states = purple_away_states; funcs.set_away = purple_set_away; funcs.add_buddy = purple_add_buddy; funcs.remove_buddy = purple_remove_buddy; funcs.add_permit = purple_add_permit; funcs.add_deny = purple_add_deny; funcs.rem_permit = purple_rem_permit; funcs.rem_deny = purple_rem_deny; funcs.get_info = purple_get_info; funcs.keepalive = purple_keepalive; funcs.send_typing = purple_send_typing; funcs.handle_cmp = g_strcasecmp; /* TODO(wilmer): Set these only for protocols that support them? */ funcs.chat_msg = purple_chat_msg; funcs.chat_with = purple_chat_with; funcs.chat_invite = purple_chat_invite; funcs.chat_leave = purple_chat_leave; funcs.chat_join = purple_chat_join; funcs.transfer_request = purple_transfer_request; help = g_string_new( "BitlBee libpurple module supports the following IM protocols:\n" ); /* Add a protocol entry to BitlBee's structures for every protocol supported by this libpurple instance. */ for( prots = purple_plugins_get_protocols(); prots; prots = prots->next ) { PurplePlugin *prot = prots->data; struct prpl *ret; /* If we already have this one (as a native module), don't add a libpurple duplicate. */ if( find_protocol( prot->info->id ) ) continue; ret = g_memdup( &funcs, sizeof( funcs ) ); ret->name = ret->data = prot->info->id; if( strncmp( ret->name, "prpl-", 5 ) == 0 ) ret->name += 5; register_protocol( ret ); g_string_append_printf( help, "\n* %s (%s)", ret->name, prot->info->name ); /* libpurple doesn't define a protocol called OSCAR, but we need it to be compatible with normal BitlBee. */ if( g_strcasecmp( prot->info->id, "prpl-aim" ) == 0 ) { ret = g_memdup( &funcs, sizeof( funcs ) ); ret->name = "oscar"; ret->data = prot->info->id; register_protocol( ret ); } } g_string_append( help, "\n\nFor used protocols, more information about available " "settings can be found using \x02help purple <protocol name>\x02 " "(create an account using that protocol first!)" ); /* Add a simple dynamically-generated help item listing all the supported protocols. */ help_add_mem( &global.help, "purple", help->str ); g_string_free( help, TRUE ); }
int main(int argc, char *argv[]) { GList *iter; int i, num; GList *names = NULL; const char *prpl; char name[128]; char *password; GMainLoop *loop = g_main_loop_new(NULL, FALSE); PurpleAccount *account; PurpleSavedStatus *status; char *res; #ifndef _WIN32 /* libpurple's built-in DNS resolution forks processes to perform * blocking lookups without blocking the main process. It does not * handle SIGCHLD itself, so if the UI does not you quickly get an army * of zombie subprocesses marching around. */ signal(SIGCHLD, SIG_IGN); #endif init_libpurple(); printf("libpurple initialized.\n"); iter = purple_plugins_get_protocols(); for (i = 0; iter; iter = iter->next) { PurplePlugin *plugin = iter->data; PurplePluginInfo *info = plugin->info; if (info && info->name) { printf("\t%d: %s\n", i++, info->name); names = g_list_append(names, info->id); } } printf("Select the protocol [0-%d]: ", i-1); res = fgets(name, sizeof(name), stdin); if (!res) { fprintf(stderr, "Failed to gets protocol selection."); abort(); } sscanf(name, "%d", &num); prpl = g_list_nth_data(names, num); printf("Username: "******"Failed to read user name."); abort(); } name[strlen(name) - 1] = 0; /* strip the \n at the end */ /* Create the account */ account = purple_account_new(name, prpl); /* Get the password for the account */ password = getpass("Password: "); purple_account_set_password(account, password); /* It's necessary to enable the account first. */ purple_account_set_enabled(account, UI_ID, TRUE); /* Now, to connect the account(s), create a status and activate it. */ status = purple_savedstatus_new(NULL, PURPLE_STATUS_AVAILABLE); purple_savedstatus_activate(status); connect_to_signals_for_demonstration_purposes_only(); g_main_loop_run(loop); return 0; }
int parse(char*toParse, char*ret_buffer, char**uid) { char command = -1, *pCur, *pPrev; int ix, Bound = TK__LAST; taim_session *ses; pCur = toParse; for(ix = 0; ix < Bound; ix++) { if(!strncmp(pCur, g_commands[ix], strlen(g_commands[ix]))) { command = ix; pCur += strlen(g_commands[ix]); break; } } switch(command) { case TK_UID: if(*pCur == ' ') { pCur++; pPrev = pCur; while(*pCur > 32) { pCur ++; } *uid = (char*) malloc(pCur - pPrev); memcpy(*uid, pPrev, pCur - pPrev); (*uid)[pCur - pPrev] = 0; } else { *uid = 0; do { if(*uid != 0) { free(*uid); } *uid = (char*) malloc(KEY_LENGTH + 1); memcpy(*uid, generate_uid(), KEY_LENGTH); } while(uid_addsession(*uid) == 0); } memcpy(ret_buffer, *uid, strlen(*uid)); sprintf(ret_buffer + strlen(*uid) + 1, "\n"); return RET_NODATA; break; case TK_USER: pCur++; pPrev = pCur; while(*pCur > 32 ) { pCur++; } *uid = (char*)malloc(pCur - pPrev + 1); memcpy(*uid, pPrev, pCur - pPrev); (*uid)[pCur - pPrev] = 0; ses = uid_find(*uid); pCur ++; { char *username = pCur; for( ix = 0; username[ix] > ' '; ix++); username[ix] = 0; GList *iter = purple_plugins_get_protocols(); PurplePlugin *plugin = iter->data; PurplePluginInfo *info = plugin->info; printf("<%x>", (unsigned int)ses); fflush(0); if(ses->pses->account == 0) { taim_new_account(ses); } d(username); ses->pses->account->account = purple_account_new(username, info->id); } return RET_NODATA; break; case TK_PASS: pCur++; pPrev = pCur; while(*pCur > 32 ) { pCur++; } *uid = (char*)malloc(pCur - pPrev + 1); memcpy(*uid, pPrev, pCur - pPrev); (*uid)[pCur - pPrev] = 0; pCur ++; ses = uid_find(*uid); { PurpleSavedStatus *status; char *password = pCur, hash[20]; for(ix = 0; password[ix] > ' '; ix++); password[ix] = 0; if(ses->pses->account->hash_have == 1) { // See if the hashes match if(!memcmp(SHA1(password, strlen(password), hash), ses->pses->account->hash, 20)) { // If so, then bond the stuff } else // Otherwise, try to auth anyway { strcpy(ses->pses->account->password_try, password); } purple_account_set_password(ses->pses->account->account, password); purple_account_set_enabled(ses->pses->account->account, UI_ID, TRUE); // Either way, this password is replaced with the new one } else { strcpy(ses->pses->account->password_try, password); purple_account_set_password(ses->pses->account->account, password); purple_account_set_enabled(ses->pses->account->account, UI_ID, TRUE); } // Now, to connect the account(s), create a status and activate it. status = purple_savedstatus_new(NULL, PURPLE_STATUS_AVAILABLE); purple_savedstatus_activate(status); pthread_mutex_unlock(&g_mutex_init); } return RET_NODATA; break; case TK_GET: pCur++; pPrev = pCur; while(*pCur > 32 ) { pCur++; } *uid = (char*)malloc(pCur - pPrev + 1); memcpy(*uid, pPrev, pCur - pPrev); (*uid)[pCur - pPrev] = 0; pCur ++; if((*uid)[0]) { d(*uid); drecurse(g_blist->root, *uid); return RET_DATA; } else { return RET_NODATA; } break; case TK_SEND: pCur++; pPrev = pCur; while(*pCur > 32 ) { pCur++; } *uid = (char*)malloc(pCur - pPrev + 1); memcpy(*uid, pPrev, pCur - pPrev); (*uid)[pCur - pPrev] = 0; pCur ++; pCur[strlen(pCur) - 1] = 0; taim_send(pCur, *uid, ret_buffer); return RET_NODATA; break; case TK_QUIT: do_exit(); break; default: return RET_ERROR; // unknown command break; } return RET_ERROR; }