示例#1
0
文件: irc_im.c 项目: wingo/bitlbee
static gboolean bee_irc_user_new(bee_t *bee, bee_user_t *bu)
{
	irc_user_t *iu;
	irc_t *irc = (irc_t *) bee->ui_data;
	char nick[MAX_NICK_LENGTH + 1], *s;

	memset(nick, 0, MAX_NICK_LENGTH + 1);
	strncpy(nick, nick_get(bu), MAX_NICK_LENGTH);

	bu->ui_data = iu = irc_user_new(irc, nick);
	iu->bu = bu;

	if (set_getbool(&irc->b->set, "private")) {
		iu->last_channel = NULL;
	} else {
		iu->last_channel = irc_channel_with_user(irc, iu);
	}

	if ((s = strchr(bu->handle, '@'))) {
		iu->host = g_strdup(s + 1);
		iu->user = g_strndup(bu->handle, s - bu->handle);
	} else {
		iu->user = g_strdup(bu->handle);
		if (bu->ic->acc->server) {
			iu->host = g_strdup(bu->ic->acc->server);
		} else {
			char *s;
			for (s = bu->ic->acc->tag; g_ascii_isalnum(*s); s++) {
				;
			}
			/* Only use the tag if we got to the end of the string.
			   (So allow alphanumerics only. Hopefully not too
			   restrictive.) */
			if (*s) {
				iu->host = g_strdup(bu->ic->acc->prpl->name);
			} else {
				iu->host = g_strdup(bu->ic->acc->tag);
			}
		}
	}

	while ((s = strchr(iu->user, ' '))) {
		*s = '_';
	}

	if (bu->flags & BEE_USER_LOCAL) {
		char *s = set_getstr(&bee->set, "handle_unknown");

		if (strcmp(s, "add_private") == 0) {
			iu->last_channel = NULL;
		} else if (strcmp(s, "add_channel") == 0) {
			iu->last_channel = irc->default_channel;
		}
	}

	iu->f = &irc_user_im_funcs;

	return TRUE;
}
示例#2
0
文件: irc_im.c 项目: AlD/bitlbee
static gboolean bee_irc_user_new( bee_t *bee, bee_user_t *bu )
{
	irc_user_t *iu;
	irc_t *irc = (irc_t*) bee->ui_data;
	char nick[MAX_NICK_LENGTH+1], *s;
	
	memset( nick, 0, MAX_NICK_LENGTH + 1 );
	strcpy( nick, nick_get( bu ) );
	
	bu->ui_data = iu = irc_user_new( irc, nick );
	iu->bu = bu;
	
	if( set_getbool( &irc->b->set, "private" ) )
		iu->last_channel = NULL;
	else
		iu->last_channel = irc_channel_with_user( irc, iu );
	
	if( ( s = strchr( bu->handle, '@' ) ) )
	{
		iu->host = g_strdup( s + 1 );
		iu->user = g_strndup( bu->handle, s - bu->handle );
	}
	else
	{
		iu->user = g_strdup( bu->handle );
		if( bu->ic->acc->server )
			iu->host = g_strdup( bu->ic->acc->server );
		else
			iu->host = g_strdup( bu->ic->acc->prpl->name );
	}
	
	while( ( s = strchr( iu->user, ' ' ) ) )
		*s = '_';
	
	if( bu->flags & BEE_USER_LOCAL )
	{
		char *s = set_getstr( &bee->set, "handle_unknown" );
		
		if( strcmp( s, "add_private" ) == 0 )
			iu->last_channel = NULL;
		else if( strcmp( s, "add_channel" ) == 0 )
			iu->last_channel = irc->default_channel;
	}
	
	iu->f = &irc_user_im_funcs;
	
	return TRUE;
}