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; }
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; }
irc_t *irc_new(int fd) { irc_t *irc; struct sockaddr_storage sock; socklen_t socklen = sizeof(sock); char *host = NULL, *myhost = NULL; irc_user_t *iu; GSList *l; set_t *s; bee_t *b; irc = g_new0(irc_t, 1); irc->fd = fd; sock_make_nonblocking(irc->fd); irc->r_watch_source_id = b_input_add(irc->fd, B_EV_IO_READ, bitlbee_io_current_client_read, irc); irc->status = USTATUS_OFFLINE; irc->last_pong = gettime(); irc->nick_user_hash = g_hash_table_new(g_str_hash, g_str_equal); irc->watches = g_hash_table_new(g_str_hash, g_str_equal); irc->iconv = (GIConv) - 1; irc->oconv = (GIConv) - 1; if (global.conf->hostname) { myhost = g_strdup(global.conf->hostname); } else if (getsockname(irc->fd, (struct sockaddr*) &sock, &socklen) == 0) { char buf[NI_MAXHOST + 1]; if (getnameinfo((struct sockaddr *) &sock, socklen, buf, NI_MAXHOST, NULL, 0, 0) == 0) { myhost = g_strdup(ipv6_unwrap(buf)); } } if (getpeername(irc->fd, (struct sockaddr*) &sock, &socklen) == 0) { char buf[NI_MAXHOST + 1]; if (getnameinfo((struct sockaddr *) &sock, socklen, buf, NI_MAXHOST, NULL, 0, 0) == 0) { host = g_strdup(ipv6_unwrap(buf)); } } if (host == NULL) { host = g_strdup("localhost.localdomain"); } if (myhost == NULL) { myhost = g_strdup("localhost.localdomain"); } if (global.conf->ping_interval > 0 && global.conf->ping_timeout > 0) { irc->ping_source_id = b_timeout_add(global.conf->ping_interval * 1000, irc_userping, irc); } irc_connection_list = g_slist_append(irc_connection_list, irc); b = irc->b = bee_new(); b->ui_data = irc; b->ui = &irc_ui_funcs; s = set_add(&b->set, "allow_takeover", "true", set_eval_bool, irc); s = set_add(&b->set, "away_devoice", "true", set_eval_bw_compat, irc); s->flags |= SET_HIDDEN; s = set_add(&b->set, "away_reply_timeout", "3600", set_eval_int, irc); s = set_add(&b->set, "charset", "utf-8", set_eval_charset, irc); s = set_add(&b->set, "default_target", "root", NULL, irc); s = set_add(&b->set, "display_namechanges", "false", set_eval_bool, irc); s = set_add(&b->set, "display_timestamps", "true", set_eval_bool, irc); s = set_add(&b->set, "handle_unknown", "add_channel", NULL, irc); s = set_add(&b->set, "last_version", "0", NULL, irc); s->flags |= SET_HIDDEN; s = set_add(&b->set, "nick_format", "%-@nick", NULL, irc); s = set_add(&b->set, "nick_lowercase", "false", set_eval_bool, irc); s = set_add(&b->set, "nick_underscores", "false", set_eval_bool, irc); s = set_add(&b->set, "offline_user_quits", "true", set_eval_bool, irc); s = set_add(&b->set, "ops", "both", set_eval_irc_channel_ops, irc); s = set_add(&b->set, "paste_buffer", "false", set_eval_bool, irc); s->old_key = g_strdup("buddy_sendbuffer"); s = set_add(&b->set, "paste_buffer_delay", "200", set_eval_int, irc); s->old_key = g_strdup("buddy_sendbuffer_delay"); s = set_add(&b->set, "password", NULL, set_eval_password, irc); s->flags |= SET_NULL_OK | SET_PASSWORD; s = set_add(&b->set, "private", "true", set_eval_bool, irc); s = set_add(&b->set, "query_order", "lifo", NULL, irc); s = set_add(&b->set, "root_nick", ROOT_NICK, set_eval_root_nick, irc); s->flags |= SET_HIDDEN; s = set_add(&b->set, "show_offline", "false", set_eval_bw_compat, irc); s->flags |= SET_HIDDEN; s = set_add(&b->set, "self_messages", "true", set_eval_self_messages, irc); s = set_add(&b->set, "simulate_netsplit", "true", set_eval_bool, irc); s = set_add(&b->set, "timezone", "local", set_eval_timezone, irc); s = set_add(&b->set, "to_char", ": ", set_eval_to_char, irc); s = set_add(&b->set, "typing_notice", "false", set_eval_bool, irc); s = set_add(&b->set, "utf8_nicks", "false", set_eval_utf8_nicks, irc); irc->root = iu = irc_user_new(irc, ROOT_NICK); iu->host = g_strdup(myhost); iu->fullname = g_strdup(ROOT_FN); iu->f = &irc_user_root_funcs; iu = irc_user_new(irc, NS_NICK); iu->host = g_strdup(myhost); iu->fullname = g_strdup(ROOT_FN); iu->f = &irc_user_root_funcs; irc->user = g_new0(irc_user_t, 1); irc->user->host = g_strdup(host); conf_loaddefaults(irc); /* Evaluator sets the iconv/oconv structures. */ set_eval_charset(set_find(&b->set, "charset"), set_getstr(&b->set, "charset")); irc_write(irc, ":%s NOTICE * :%s", irc->root->host, "BitlBee-IRCd initialized, please go on"); if (isatty(irc->fd)) { irc_write(irc, ":%s NOTICE * :%s", irc->root->host, "If you read this, you most likely accidentally " "started BitlBee in inetd mode on the command line. " "You probably want to run it in (Fork)Daemon mode. " "See doc/README for more information."); } g_free(myhost); g_free(host); /* libpurple doesn't like fork()s after initializing itself, so this is the right moment to initialize it. */ #ifdef WITH_PURPLE nogaim_init(); #endif /* SSL library initialization also should be done after the fork, to avoid shared CSPRNG state. This is required by NSS, which refuses to work if a fork is detected */ ssl_init(); for (l = irc_plugins; l; l = l->next) { irc_plugin_t *p = l->data; if (p->irc_new) { p->irc_new(irc); } } return irc; }