Beispiel #1
0
static void purple_set_away( struct im_connection *ic, char *state_txt, char *message )
{
	PurpleAccount *pa = ic->proto_data;
	GList *status_types = purple_account_get_status_types( pa ), *st;
	PurpleStatusType *pst = NULL;
	GList *args = NULL;
	
	for( st = status_types; st; st = st->next )
	{
		pst = st->data;
		
		if( state_txt == NULL &&
		    purple_status_type_get_primitive( pst ) == PURPLE_STATUS_AVAILABLE )
			break;

		if( state_txt != NULL &&
		    g_strcasecmp( state_txt, purple_status_type_get_name( pst ) ) == 0 )
			break;
	}
	
	if( message && purple_status_type_get_attr( pst, "message" ) )
	{
		args = g_list_append( args, "message" );
		args = g_list_append( args, message );
	}
	
	purple_account_set_status_list( pa, st ? purple_status_type_get_id( pst ) : "away",
		                        TRUE, args );

	g_list_free( args );
}
Beispiel #2
0
static void pipe_handle_publish(struct purple_publish *publish) {
	PurpleAccount *account = NULL;
	extern_account_t *accounts = NULL;
	int naccounts = 0;
	int i;

	LM_DBG("calling find_accounts(\"%s\", &naccoutns)\n", publish->from);
	accounts = find_accounts(publish->from, &naccounts);
	LM_DBG("found %d extra account(s) for <%s>", naccounts, publish->from);

	for (i = 0; i < naccounts; i++) {
		LM_DBG("calling client_find_account(\"%s\")\n", accounts[i].username);
		account = client_find_account(&accounts[i]);
		if (account) {
		
			if (publish->basic == PURPLE_BASIC_OPEN) {
				client_enable_account(account);
				LM_DBG("basic = open, setting up new status... %s,%d,%s\n", account[i].username, publish->primitive, publish->note);
				PurpleStatusType *type = purple_account_get_status_type_with_primitive(account, publish->primitive);
				if (purple_status_type_get_attr(type, "message")) {
					purple_account_set_status(account, purple_status_type_get_id(type), TRUE, "message", publish->note, NULL);
				} else {
					purple_account_set_status(account, purple_status_type_get_id(type), TRUE, NULL);
				}
			}

			else if (publish->basic == PURPLE_BASIC_CLOSED){
				LM_DBG("basic = closed, setting up new status to offline... %s\n", account[i].username);
				PurpleStatusType *type = purple_account_get_status_type_with_primitive(account, PURPLE_STATUS_OFFLINE);
				purple_account_set_status(account, purple_status_type_get_id(type), TRUE, NULL);
			}
			
		}
	}

	if (accounts)
		extern_account_free(accounts, naccounts);

}
static void received_im_msg_cb(PurpleAccount *account, char *who, char *buffer,
    PurpleConversation *conv, PurpleMessageFlags flags, void *data) {
    // A workaround to avoid skipping of the first message as a result on NULL-conv:
    if (conv == NULL) conv = purple_conversation_new(PURPLE_CONV_TYPE_IM,
        account, who); 
    PurpleBuddy *buddy = purple_find_buddy(account, who);
    PurplePresence *presence = purple_buddy_get_presence(buddy);
    msg_metadata_t msg;

    //Get message
    msg.text = purple_markup_strip_html(buffer);
    msg.remote_username = who;

    //LOCAL USER:
    msg.local_alias = purple_account_get_alias(account);
    msg.local_username = (char *) purple_account_get_name_for_display(account);

    //REMOTE USER (Buddy):
    //Get buddy alias
    msg.remote_alias = purple_buddy_get_alias(buddy);
    if(msg.remote_alias == NULL) msg.remote_alias = "";

    //Get buddy group
    PurpleGroup *group = purple_buddy_get_group(buddy);
    //return empty string if not in group
    msg.remote_from_group = group != NULL ? purple_group_get_name(group) : ""; 

    //Get protocol ID
    msg.protocol_id = purple_account_get_protocol_id(account);
    //trim out PROTOCOL_PREFIX (eg.: "prpl-irc" => "irc")
    if(!strncmp(msg.protocol_id,PROTOCOL_PREFIX,strlen(PROTOCOL_PREFIX))) 
        msg.protocol_id += strlen(PROTOCOL_PREFIX); 

    //Get status
    PurpleStatus *status = purple_account_get_active_status(account);
    PurpleStatusType *type = purple_status_get_type(status);
    //remote
    PurpleStatus *r_status = purple_presence_get_active_status(presence);
    PurpleStatusType *r_status_type =	purple_status_get_type(r_status);

    //Get status id
    msg.local_status_id = NULL;
    msg.local_status_id = purple_primitive_get_id_from_type(
        purple_status_type_get_primitive(type));
    //remote
    msg.remote_status_id = NULL;
    msg.remote_status_id = purple_primitive_get_id_from_type(
        purple_status_type_get_primitive(r_status_type));

    //Get status message
    msg.local_status_msg = NULL;
    if (purple_status_type_get_attr(type, "message") != NULL) {
        msg.local_status_msg = purple_status_get_attr_string(status, "message");
    } else {
        PurpleSavedStatus *savedstatus = purple_savedstatus_get_current();
        if(savedstatus)
            msg.local_status_msg = purple_savedstatus_get_message(savedstatus);
    }
    //remote
    msg.remote_status_msg = NULL;
    if (purple_status_type_get_attr(r_status_type, "message") != NULL) {
        msg.remote_status_msg = purple_status_get_attr_string(r_status, "message");
    } else {
        msg.remote_status_msg = "";
    }

    run_lua(conv, msg);
}
Beispiel #4
0
static void purple_init( account_t *acc )
{
	PurplePlugin *prpl = purple_plugins_find_with_id( (char*) acc->prpl->data );
	PurplePluginProtocolInfo *pi = prpl->info->extra_info;
	PurpleAccount *pa;
	GList *i, *st;
	set_t *s;
	char help_title[64];
	GString *help;
	static gboolean dir_fixed = FALSE;
	
	/* Layer violation coming up: Making an exception for libpurple here.
	   Dig in the IRC state a bit to get a username. Ideally we should
	   check if s/he identified but this info doesn't seem *that* important.
	   It's just that fecking libpurple can't *not* store this shit.
	   
	   Remember that libpurple is not really meant to be used on public
	   servers anyway! */
	if( !dir_fixed )
	{
		irc_t *irc = acc->bee->ui_data;
		char *dir;
		
		dir = g_strdup_printf( "%s/purple/%s", global.conf->configdir, irc->user->nick );
		purple_util_set_user_dir( dir );
		g_free( dir );
		
		purple_blist_load();
		purple_prefs_load();
		dir_fixed = TRUE;
	}
	
	help = g_string_new( "" );
	g_string_printf( help, "BitlBee libpurple module %s (%s).\n\nSupported settings:",
	                        (char*) acc->prpl->name, prpl->info->name );
	
	if( pi->user_splits )
	{
		GList *l;
		g_string_append_printf( help, "\n* username: Username" );
		for( l = pi->user_splits; l; l = l->next )
			g_string_append_printf( help, "%c%s",
			                        purple_account_user_split_get_separator( l->data ),
			                        purple_account_user_split_get_text( l->data ) );
	}
	
	/* Convert all protocol_options into per-account setting variables. */
	for( i = pi->protocol_options; i; i = i->next )
	{
		PurpleAccountOption *o = i->data;
		const char *name;
		char *def = NULL;
		set_eval eval = NULL;
		void *eval_data = NULL;
		GList *io = NULL;
		GSList *opts = NULL;
		
		name = purple_account_option_get_setting( o );
		
		switch( purple_account_option_get_type( o ) )
		{
		case PURPLE_PREF_STRING:
			def = g_strdup( purple_account_option_get_default_string( o ) );
			
			g_string_append_printf( help, "\n* %s (%s), %s, default: %s",
			                        name, purple_account_option_get_text( o ),
			                        "string", def );
			
			break;
		
		case PURPLE_PREF_INT:
			def = g_strdup_printf( "%d", purple_account_option_get_default_int( o ) );
			eval = set_eval_int;
			
			g_string_append_printf( help, "\n* %s (%s), %s, default: %s",
			                        name, purple_account_option_get_text( o ),
			                        "integer", def );
			
			break;
		
		case PURPLE_PREF_BOOLEAN:
			if( purple_account_option_get_default_bool( o ) )
				def = g_strdup( "true" );
			else
				def = g_strdup( "false" );
			eval = set_eval_bool;
			
			g_string_append_printf( help, "\n* %s (%s), %s, default: %s",
			                        name, purple_account_option_get_text( o ),
			                        "boolean", def );
			
			break;
		
		case PURPLE_PREF_STRING_LIST:
			def = g_strdup( purple_account_option_get_default_list_value( o ) );
			
			g_string_append_printf( help, "\n* %s (%s), %s, default: %s",
			                        name, purple_account_option_get_text( o ),
			                        "list", def );
			g_string_append( help, "\n  Possible values: " );
			
			for( io = purple_account_option_get_list( o ); io; io = io->next )
			{
				PurpleKeyValuePair *kv = io->data;
				opts = g_slist_append( opts, kv->value );
				/* TODO: kv->value is not a char*, WTF? */
				if( strcmp( kv->value, kv->key ) != 0 )
					g_string_append_printf( help, "%s (%s), ", (char*) kv->value, kv->key );
				else
					g_string_append_printf( help, "%s, ", (char*) kv->value );
			}
			g_string_truncate( help, help->len - 2 );
			eval = set_eval_list;
			eval_data = opts;
			
			break;
			
		default:
			/** No way to talk to the user right now, invent one when
			this becomes important.
			irc_rootmsg( acc->irc, "Setting with unknown type: %s (%d) Expect stuff to break..\n",
			             name, purple_account_option_get_type( o ) );
			*/
			g_string_append_printf( help, "\n* [%s] UNSUPPORTED (type %d)",
			                        name, purple_account_option_get_type( o ) );
			name = NULL;
		}
		
		if( name != NULL )
		{
			s = set_add( &acc->set, name, def, eval, acc );
			s->flags |= ACC_SET_OFFLINE_ONLY;
			s->eval_data = eval_data;
			g_free( def );
		}
	}
	
	g_snprintf( help_title, sizeof( help_title ), "purple %s", (char*) acc->prpl->name );
	help_add_mem( &global.help, help_title, help->str );
	g_string_free( help, TRUE );
	
	s = set_add( &acc->set, "display_name", NULL, set_eval_display_name, acc );
	s->flags |= ACC_SET_ONLINE_ONLY;
	
	if( pi->options & OPT_PROTO_MAIL_CHECK )
	{
		s = set_add( &acc->set, "mail_notifications", "false", set_eval_bool, acc );
		s->flags |= ACC_SET_OFFLINE_ONLY;
	}
	
	if( strcmp( prpl->info->name, "Gadu-Gadu" ) == 0 )
		s = set_add( &acc->set, "gg_sync_contacts", "true", set_eval_bool, acc );
	
	/* Go through all away states to figure out if away/status messages
	   are possible. */
	pa = purple_account_new( acc->user, (char*) acc->prpl->data );
	for( st = purple_account_get_status_types( pa ); st; st = st->next )
	{
		PurpleStatusPrimitive prim = purple_status_type_get_primitive( st->data );
		
		if( prim == PURPLE_STATUS_AVAILABLE )
		{
			if( purple_status_type_get_attr( st->data, "message" ) )
				acc->flags |= ACC_FLAG_STATUS_MESSAGE;
		}
		else if( prim != PURPLE_STATUS_OFFLINE )
		{
			if( purple_status_type_get_attr( st->data, "message" ) )
				acc->flags |= ACC_FLAG_AWAY_MESSAGE;
		}
	}
	purple_accounts_remove( pa );
}