static int dcc_timeout_func(void) { GSList *tmp, *next; time_t now; now = time(NULL)-settings_get_int("dcc_timeout"); for (tmp = dcc_conns; tmp != NULL; tmp = next) { DCC_REC *rec = tmp->data; next = tmp->next; if (rec->tagread == -1 && now > rec->created) { /* timed out. */ dcc_reject(rec, NULL); } } return 1; }
/* input function: DCC SEND - someone tried to connect to our socket */ static void dcc_send_init(DCC_REC *dcc) { int handle, port; IPADDR addr; g_return_if_fail(dcc != NULL); /* accept connection */ handle = net_accept(dcc->handle, &addr, &port); if (handle == -1) return; /* TODO: some kind of paranoia check would be nice. it would check that the host of the nick who we sent the request matches the address who connected us. */ g_source_remove(dcc->tagconn); close(dcc->handle); dcc->starttime = time(NULL); dcc->fastsend = settings_get_bool("dcc_fast_send"); dcc->handle = handle; memcpy(&dcc->addr, &addr, sizeof(IPADDR)); net_ip2host(&dcc->addr, dcc->addrstr); dcc->port = port; dcc->databufsize = settings_get_int("dcc_block_size"); if (dcc->databufsize <= 0) dcc->databufsize = 2048; dcc->databuf = g_malloc(dcc->databufsize); dcc->tagread = g_input_add(handle, G_INPUT_READ, (GInputFunction) dcc_send_read_size, dcc); dcc->tagwrite = !dcc->fastsend ? -1 : g_input_add(handle, G_INPUT_WRITE, (GInputFunction) dcc_send_data, dcc); signal_emit("dcc connected", 1, dcc); if (!dcc->fastsend) { /* send first block */ dcc->gotalldata = TRUE; dcc_send_data(dcc); } }
static void read_settings(void) { int old_autolog = autolog_level; int log_file_create_mode; g_free_not_null(autolog_path); autolog_path = g_strdup(settings_get_str("autolog_path")); autolog_level = !settings_get_bool("autolog") ? 0 : settings_get_level("autolog_level"); if (old_autolog && !autolog_level) autologs_close_all(); /* write to log files with different theme? */ if (log_theme_name != NULL) signal_remove("print format", (SIGNAL_FUNC) sig_print_format); g_free_not_null(log_theme_name); log_theme_name = g_strdup(settings_get_str("log_theme")); if (*log_theme_name == '\0') { g_free(log_theme_name); log_theme_name = NULL; } else signal_add("print format", (SIGNAL_FUNC) sig_print_format); log_theme = log_theme_name == NULL ? NULL : theme_load(log_theme_name); log_file_create_mode = octal2dec(settings_get_int("log_create_mode")); log_dir_create_mode = log_file_create_mode; if (log_file_create_mode & 0400) log_dir_create_mode |= 0100; if (log_file_create_mode & 0040) log_dir_create_mode |= 0010; if (log_file_create_mode & 0004) log_dir_create_mode |= 0001; if (autolog_ignore_targets != NULL) g_strfreev(autolog_ignore_targets); autolog_ignore_targets = g_strsplit(settings_get_str("autolog_ignore_targets"), " ", -1); }
void gui_windows_reset_settings(void) { GSList *tmp; for (tmp = windows; tmp != NULL; tmp = tmp->next) { WINDOW_REC *rec = tmp->data; GUI_WINDOW_REC *gui = WINDOW_GUI(rec); textbuffer_view_set_break_wide(gui->view, settings_get_bool("break_wide")); textbuffer_view_set_default_indent(gui->view, settings_get_int("indent"), !settings_get_bool("indent_always"), get_default_indent_func()); textbuffer_view_set_scroll(gui->view, gui->use_scroll ? gui->scroll : settings_get_bool("scroll")); } }
static void set_print(SETTINGS_REC *rec) { const char *value; char value_int[MAX_INT_STRLEN]; switch (rec->type) { case SETTING_TYPE_BOOLEAN: value = settings_get_bool(rec->key) ? "ON" : "OFF"; break; case SETTING_TYPE_INT: ltoa(value_int, settings_get_int(rec->key)); value = value_int; break; case SETTING_TYPE_STRING: value = settings_get_str(rec->key); break; default: value = ""; } printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%s = %s", rec->key, value); }
static void sig_complete_topic_plus(GList **list, WINDOW_REC *window, const char *word, const char *line, int *want_space) { char *p; char *topic; int topic_len; const char *mark; int mark_len; g_return_if_fail(list != NULL); g_return_if_fail(word != NULL); if (*word == '\0' && IS_CHANNEL(window->active)) { topic = g_strdup(CHANNEL(window->active)->topic); if (topic != NULL) { mark = settings_get_str("mark_encrypted"); if (!IsNULLorEmpty(mark)) { topic_len = strlen(topic); mark_len = strlen(mark); if (settings_get_int("mark_position") == 0) { // suffix p = topic + (topic_len - mark_len); if (strncmp(p, mark, mark_len) == 0) { *p = '\0'; // Remove mark } } else { // prefix if (strncmp(topic, mark, mark_len) == 0) { g_memmove(topic, topic + mark_len, topic_len - mark_len); } } } *list = g_list_append(NULL, topic); signal_stop(); } } }
/* command: DCC CHAT */ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server) { DCC_REC *dcc; IPADDR own_ip; char *str, host[MAX_IP_LEN]; int port, handle; g_return_if_fail(data != NULL); if (*data == '\0') cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS); dcc = dcc_find_item(DCC_TYPE_CHAT, data, NULL); if (dcc != NULL) { /* found from dcc list - so we're the connecting side.. */ dcc_chat_connect(dcc); return; } /* send dcc chat request */ if (server == NULL || !server->connected) cmd_return_error(CMDERR_NOT_CONNECTED); if (net_getsockname(server->handle, &own_ip, NULL) == -1) cmd_return_error(CMDERR_ERRNO); port = settings_get_int("dcc_port"); handle = net_listen(&own_ip, &port); if (handle == -1) cmd_return_error(CMDERR_ERRNO); dcc = dcc_create(DCC_TYPE_CHAT, handle, data, "chat", server, NULL); dcc->tagread = g_input_add(dcc->handle, G_INPUT_READ, (GInputFunction) dcc_chat_listen, dcc); /* send the request */ dcc_make_address(&own_ip, host); str = g_strdup_printf("PRIVMSG %s :\001DCC CHAT CHAT %s %d\001", data, host, port); irc_send_cmd(server, str); g_free(str); }
static void server_setup_fill(SERVER_CONNECT_REC *conn, const char *address, int port) { g_return_if_fail(conn != NULL); g_return_if_fail(address != NULL); conn->type = module_get_uniq_id("SERVER CONNECT", 0); conn->address = g_strdup(address); if (port > 0) conn->port = port; if (strchr(address, '/') != NULL) conn->unix_socket = TRUE; if (!conn->nick) conn->nick = g_strdup(settings_get_str("nick")); conn->username = g_strdup(settings_get_str("user_name")); conn->realname = g_strdup(settings_get_str("real_name")); /* proxy settings */ if (settings_get_bool("use_proxy")) { conn->proxy = g_strdup(settings_get_str("proxy_address")); conn->proxy_port = settings_get_int("proxy_port"); conn->proxy_string = g_strdup(settings_get_str("proxy_string")); conn->proxy_string_after = g_strdup(settings_get_str("proxy_string_after")); conn->proxy_password = g_strdup(settings_get_str("proxy_password")); } /* source IP */ if (source_host_ip4 != NULL) { conn->own_ip4 = g_new(IPADDR, 1); memcpy(conn->own_ip4, source_host_ip4, sizeof(IPADDR)); } if (source_host_ip6 != NULL) { conn->own_ip6 = g_new(IPADDR, 1); memcpy(conn->own_ip6, source_host_ip6, sizeof(IPADDR)); } signal_emit("server setup fill connect", 1, conn); }
static GUI_WINDOW_REC *gui_window_init(WINDOW_REC *window, MAIN_WINDOW_REC *parent) { GUI_WINDOW_REC *gui; window->width = parent->width; window->height = MAIN_WINDOW_TEXT_HEIGHT(parent); gui = g_new0(GUI_WINDOW_REC, 1); gui->parent = parent; gui->view = textbuffer_view_create(textbuffer_create(), window->width, window->height, settings_get_bool("scroll"), term_type == TERM_TYPE_UTF8); textbuffer_view_set_default_indent(gui->view, settings_get_int("indent"), !settings_get_bool("indent_always"), get_default_indent_func()); if (parent->active == window) textbuffer_view_set_window(gui->view, parent->screen_win); return gui; }
char *settings_get_print(SETTINGS_REC *rec) { char *value = NULL; switch(rec->type) { case SETTING_TYPE_CHOICE: value = g_strdup(rec->choices[settings_get_choice(rec->key)]); break; case SETTING_TYPE_BOOLEAN: value = g_strdup(settings_get_bool(rec->key) ? "ON" : "OFF"); break; case SETTING_TYPE_INT: value = g_strdup_printf("%d", settings_get_int(rec->key)); break; case SETTING_TYPE_STRING: case SETTING_TYPE_TIME: case SETTING_TYPE_LEVEL: case SETTING_TYPE_SIZE: case SETTING_TYPE_ANY: value = g_strdup(settings_get_str(rec->key)); break; } return value; }
static void read_settings(void) { use_colors = settings_get_bool("colors"); if (settings_get_bool("topicbar")) topicbar_create(); else if (!settings_get_bool("topicbar")) topicbar_destroy(); lag_min_show = settings_get_int("lag_min_show")*10; sbar_color_background = settings_get_int("statusbar_background") << 4; sbar_color_dim = sbar_color_background | settings_get_int("statusbar_dim"); sbar_color_normal = sbar_color_background | settings_get_int("statusbar_normal"); sbar_color_bold = sbar_color_background | settings_get_int("statusbar_bold"); sbar_color_away = sbar_color_background | settings_get_int("statusbar_away"); sbar_color_act_highlight = sbar_color_background | settings_get_int("statusbar_act_highlight"); statusbar_redraw(NULL); }
/* * Decrypt a base64 cipher text (using key for target) */ int FiSH_decrypt(const SERVER_REC * serverRec, char *msg_ptr, const char *target, GString* decrypted_msg) { char contactName[CONTACT_SIZE] = ""; char theKey[KEYBUF_SIZE] = ""; char bf_dest[1000] = ""; char myMark[20] = ""; char *recoded; int msg_len, i, mark_broken_block = 0, action_found = 0, markPos; if (IsNULLorEmpty(msg_ptr) || decrypted_msg == NULL || IsNULLorEmpty(target)) return 0; if (settings_get_bool("process_incoming") == 0) return 0; if (strncmp(msg_ptr, "+OK ", 4) == 0) msg_ptr += 4; // TODO: Maybe remove this? else if (strncmp(msg_ptr, "mcps ", 5) == 0) msg_ptr += 5; else return 0; // don't process, blowcrypt-prefix not found // Verify base64 string msg_len = strlen(msg_ptr); if ((strspn(msg_ptr, B64) != (size_t) msg_len) || (msg_len < 12)) return 0; if (getIniSectionForContact(serverRec, target, contactName) == FALSE) return 0; if (getContactKey(contactName, theKey) == FALSE) return 0; // usually a received message does not exceed 512 chars, but we want to prevent evil buffer overflow if (msg_len >= (int)(sizeof(bf_dest) * 1.5)) msg_ptr[(int)(sizeof(bf_dest) * 1.5) - 20] = '\0'; // block-align blowcrypt strings if truncated by IRC server (each block is 12 chars long) // such a truncated block is destroyed and not needed anymore if (msg_len != (msg_len / 12) * 12) { msg_len = (msg_len / 12) * 12; msg_ptr[msg_len] = '\0'; strncpy(myMark, settings_get_str("mark_broken_block"), sizeof(myMark)); if (*myMark == '\0' || isNoChar(*myMark)) mark_broken_block = 0; else mark_broken_block = 1; } decrypt_string(theKey, msg_ptr, bf_dest, msg_len); ZeroMemory(theKey, KEYBUF_SIZE); if (*bf_dest == '\0') return 0; // don't process, decrypted msg is bad // recode message again, last time it was the encrypted message... if (settings_get_bool("recode") && serverRec != NULL) { recoded = recode_in(serverRec, bf_dest, target); if (recoded) { strncpy(bf_dest, recoded, sizeof(bf_dest)); ZeroMemory(recoded, strlen(recoded)); g_free(recoded); } } i = 0; while (bf_dest[i] != 0x0A && bf_dest[i] != 0x0D && bf_dest[i] != '\0') i++; bf_dest[i] = '\0'; // in case of wrong key, decrypted message might have control characters -> cut message if (strncmp(bf_dest, "\001ACTION ", 8) == 0) { // ACTION message found if (bf_dest[i - 1] == '\001') bf_dest[i - 1] = '\0'; // remove 0x01 control character action_found = 1; } // append broken-block-mark? if (mark_broken_block) strcat(bf_dest, myMark); // append crypt-mark? strncpy(myMark, settings_get_str("mark_encrypted"), sizeof(myMark)); if (*myMark != '\0') { markPos = settings_get_int("mark_position"); if (markPos == 0 || action_found) strcat(bf_dest, myMark); // append mark at the end (default for ACTION messages) else { // prefix mark i = strlen(myMark); memmove(bf_dest + i, bf_dest, strlen(bf_dest) + 1); strncpy(bf_dest, myMark, i); } } g_string_assign(decrypted_msg, bf_dest); ZeroMemory(bf_dest, sizeof(bf_dest)); return 1; }
gboolean proxy_init(void) { gchar ipaddr[MAX_IP_LEN]; const char *password; const char *addr; int port; proxy_settings_init(); proxy_data = g_new0(PLUGIN_DATA, 1); password = settings_get_str("proxy_listen_password"); addr = settings_get_str("proxy_listen_addr"); port = settings_get_int("proxy_listen_port"); plug = module_find("proxy"); proxy_data->plugin = plug; if (*password != '\0') { /* args = password */ proxy_data->password = g_strdup(password); } if (*addr != '\0') { /* specify ip address to listen */ net_host2ip(addr, &proxy_data->ip); } if (port != 0) { /* specify port to use */ proxy_data->port = port; } if (proxy_data->password == NULL) { /* no password - bad idea! */ printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, "Warning!! Password not specified, everyone can use this proxy! Use /set proxy_listen_password <password> to set it"); } if (servers == NULL) { /* FIXME: not good */ printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "You need to specify IP address to listen with /set proxy_listen_addr <address>"); deinit(); return FALSE; } else { SERVER_REC *server; server = servers->data; if (net_getsockname(net_sendbuffer_handle(server->handle), &proxy_data->ip, NULL)) { deinit(); return FALSE; } } net_ip2host(&proxy_data->ip, ipaddr); printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, "Proxy plugin loaded - listening in interface %s port %d", ipaddr, proxy_data->port); plugin_proxy_listen_init(proxy_data); proxy_data->loaded = TRUE; return TRUE; }
/* Handle incoming DCC CTCP messages */ static void dcc_ctcp_msg(char *data, IRC_SERVER_REC *server, char *sender, char *sendaddr, char *target, DCC_REC *chat) { char *params, *type, *arg, *addrstr, *portstr, *sizestr, *str; const char *cstr; DCC_REC *dcc; gulong size; int port; g_return_if_fail(data != NULL); g_return_if_fail(sender != NULL); params = cmd_get_params(data, 5 | PARAM_FLAG_NOQUOTES, &type, &arg, &addrstr, &portstr, &sizestr); if (sscanf(portstr, "%d", &port) != 1) port = 0; if (sscanf(sizestr, "%lu", &size) != 1) size = 0; dcc = dcc_create(SWAP_SENDGET(dcc_str2type(type)), -1, sender, arg, server, chat); dcc_get_address(addrstr, &dcc->addr); net_ip2host(&dcc->addr, dcc->addrstr); dcc->port = port; dcc->size = size; switch (dcc->type) { case DCC_TYPE_GET: cstr = settings_get_str("dcc_autoget_masks"); /* check that autoget masks match */ if (settings_get_bool("dcc_autoget") && (*cstr == '\0' || irc_masks_match(cstr, sender, sendaddr)) && /* check file size limit, FIXME: it's possible to send a bogus file size and then just send what ever sized file.. */ (settings_get_int("dcc_max_autoget_size") <= 0 || (settings_get_int("dcc_max_autoget_size") > 0 && size <= settings_get_int("dcc_max_autoget_size")*1024))) { /* automatically get */ str = g_strdup_printf("GET %s %s", dcc->nick, dcc->arg); signal_emit("command dcc", 2, str, server); g_free(str); } else { /* send request */ signal_emit("dcc request", 1, dcc); } break; case DCC_TYPE_CHAT: cstr = settings_get_str("dcc_autochat_masks"); if (*cstr != '\0' && irc_masks_match(cstr, sender, sendaddr)) { /* automatically accept chat */ str = g_strdup_printf("CHAT %s", dcc->nick); signal_emit("command dcc", 2, str, server); g_free(str); } else { /* send request */ signal_emit("dcc request", 1, dcc); } break; case DCC_TYPE_RESUME: case DCC_TYPE_ACCEPT: /* handle this in dcc-files.c */ dcc_destroy(dcc); break; default: /* unknown DCC command */ signal_emit("dcc unknown ctcp", 3, data, sender, sendaddr); dcc_destroy(dcc); break; } g_free(params); }
static void read_settings(void) { dcc_file_create_mode = octal2dec(settings_get_int("dcc_file_create_mode")); }
/* SYNTAX: KNOCKOUT [<seconds>] <nicks> <reason> */ static void cmd_knockout(const char *data, IRC_SERVER_REC *server, IRC_CHANNEL_REC *channel) { KNOCKOUT_REC *rec; char *nicks, *reason, *timeoutstr, *kickcmd, *bancmd; char **nicklist, *spacenicks, *banmasks; void *free_arg; int timeleft; CMD_IRC_SERVER(server); if (!IS_IRC_CHANNEL(channel)) cmd_return_error(CMDERR_NOT_JOINED); if (!channel->wholist) cmd_return_error(CMDERR_CHAN_NOT_SYNCED); if (is_numeric(data, ' ')) { /* first argument is the timeout */ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &timeoutstr, &nicks, &reason)) return; timeleft = atoi(timeoutstr); } else { if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &nicks, &reason)) return; timeleft = 0; } if (timeleft == 0) timeleft = settings_get_int("knockout_time"); if (*nicks == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); nicklist = g_strsplit(nicks, ",", -1); spacenicks = g_strjoinv(" ", nicklist); g_strfreev(nicklist); banmasks = ban_get_masks(channel, spacenicks, 0); g_free(spacenicks); kickcmd = g_strdup_printf("%s %s %s", channel->name, nicks, reason); bancmd = *banmasks == '\0'? NULL : g_strdup_printf("%s %s", channel->name, banmasks); if (settings_get_bool("kick_first_on_kickban")) { signal_emit("command kick", 3, kickcmd, server, channel); if (bancmd != NULL) signal_emit("command ban", 3, bancmd, server, channel); } else { if (bancmd != NULL) signal_emit("command ban", 3, bancmd, server, channel); signal_emit("command kick", 3, kickcmd, server, channel); } g_free(kickcmd); g_free_not_null(bancmd); if (*banmasks == '\0') g_free(banmasks); else { /* create knockout record */ rec = g_new(KNOCKOUT_REC, 1); rec->timeleft = timeleft; rec->channel = channel; rec->ban = banmasks; server->knockoutlist = g_slist_append(server->knockoutlist, rec); } cmd_params_free(free_arg); }
/* callback: net_connect() finished for DCC GET */ void sig_dccget_connected(GET_DCC_REC *dcc) { struct stat statbuf; char *fname, *tempfname, *str; int ret, ret_errno, temphandle, old_umask; if (!dcc->from_dccserver) { if (net_geterror(dcc->handle) != 0) { /* error connecting */ signal_emit("dcc error connect", 1, dcc); dcc_destroy(DCC(dcc)); return; } g_source_remove(dcc->tagconn); dcc->tagconn = -1; } g_free_not_null(dcc->file); dcc->file = dcc_get_download_path(dcc->arg); /* if some plugin wants to change the file name/path here.. */ signal_emit("dcc get receive", 1, dcc); if (stat(dcc->file, &statbuf) == 0 && dcc->get_type == DCC_GET_RENAME) { /* file exists, rename.. */ fname = dcc_get_rename_file(dcc->file); g_free(dcc->file); dcc->file = fname; } if (dcc->get_type != DCC_GET_RESUME) { int dcc_file_create_mode = octal2dec(settings_get_int("dcc_file_create_mode")); /* we want to overwrite the file, remove it here. if it gets created after this, we'll fail. */ unlink(dcc->file); /* just to make sure we won't run into race conditions if download_path is in some global temp directory */ tempfname = g_strconcat(dcc->file, ".XXXXXX", NULL); old_umask = umask(0077); temphandle = mkstemp(tempfname); umask(old_umask); if (temphandle == -1) ret = -1; else ret = fchmod(temphandle, dcc_file_create_mode); close(temphandle); if (ret != -1) { ret = link(tempfname, dcc->file); if (ret == -1 && /* Linux */ (errno == EPERM || /* FUSE */ errno == ENOSYS || /* BSD */ errno == EOPNOTSUPP)) { /* hard links aren't supported - some people want to download stuff to FAT/NTFS/etc partitions, so fallback to rename() */ ret = rename(tempfname, dcc->file); } } /* if ret = 0, we're the file owner now */ dcc->fhandle = ret == -1 ? -1 : open(dcc->file, O_WRONLY | O_TRUNC); /* close/remove the temp file */ ret_errno = errno; unlink(tempfname); g_free(tempfname); if (dcc->fhandle == -1) { signal_emit("dcc error file create", 3, dcc, dcc->file, g_strerror(ret_errno)); dcc_destroy(DCC(dcc)); return; } } dcc->starttime = time(NULL); if (dcc->size == 0) { dcc_close(DCC(dcc)); return; } dcc->tagread = g_input_add(dcc->handle, G_INPUT_READ, (GInputFunction) sig_dccget_receive, dcc); signal_emit("dcc connected", 1, dcc); if (dcc->from_dccserver) { str = g_strdup_printf("121 %s %d\n", dcc->server ? dcc->server->nick : "??", 0); net_transmit(dcc->handle, str, strlen(str)); } }
static void read_settings(void) { reconnect_time = settings_get_int("server_reconnect_time"); }
static void display_sorted_nicks(CHANNEL_REC *channel, GSList *nicklist) { WINDOW_REC *window; TEXT_DEST_REC dest; GString *str; GSList *tmp; char *format, *stripped, *prefix_format; char *linebuf, nickmode[2] = { 0, 0 }; int *columns, cols, rows, last_col_rows, col, row, max_width; int item_extra, linebuf_size, formatnum; window = window_find_closest(channel->server, channel->visible_name, MSGLEVEL_CLIENTCRAP); max_width = window->width; /* get the length of item extra stuff ("[ ] ") */ format = format_get_text(MODULE_NAME, NULL, channel->server, channel->visible_name, TXT_NAMES_NICK, " ", ""); stripped = strip_codes(format); item_extra = strlen(stripped); g_free(stripped); g_free(format); if (settings_get_int("names_max_width") > 0 && settings_get_int("names_max_width") < max_width) max_width = settings_get_int("names_max_width"); /* remove width of the timestamp from max_width */ format_create_dest(&dest, channel->server, channel->visible_name, MSGLEVEL_CLIENTCRAP, NULL); format = format_get_line_start(current_theme, &dest, time(NULL)); if (format != NULL) { stripped = strip_codes(format); max_width -= strlen(stripped); g_free(stripped); g_free(format); } /* remove width of the prefix from max_width */ prefix_format = format_get_text(MODULE_NAME, NULL, channel->server, channel->visible_name, TXT_NAMES_PREFIX, channel->visible_name); if (prefix_format != NULL) { stripped = strip_codes(prefix_format); max_width -= strlen(stripped); g_free(stripped); } if (max_width <= 0) { /* we should always have at least some space .. if we really don't, it won't show properly anyway. */ max_width = 10; } /* calculate columns */ cols = get_max_column_count(nicklist, get_nick_length, max_width, settings_get_int("names_max_columns"), item_extra, 3, &columns, &rows); nicklist = columns_sort_list(nicklist, rows); /* rows in last column */ last_col_rows = rows-(cols*rows-g_slist_length(nicklist)); if (last_col_rows == 0) last_col_rows = rows; str = g_string_new(prefix_format); linebuf_size = max_width+1; linebuf = g_malloc(linebuf_size); col = 0; row = 0; for (tmp = nicklist; tmp != NULL; tmp = tmp->next) { NICK_REC *rec = tmp->data; if (rec->other) nickmode[0] = rec->other; else if (rec->op) nickmode[0] = '@'; else if (rec->halfop) nickmode[0] = '%'; else if (rec->voice) nickmode[0] = '+'; else nickmode[0] = ' '; if (linebuf_size < columns[col]-item_extra+1) { linebuf_size = (columns[col]-item_extra+1)*2; linebuf = g_realloc(linebuf, linebuf_size); } memset(linebuf, ' ', columns[col]-item_extra); linebuf[columns[col]-item_extra] = '\0'; memcpy(linebuf, rec->nick, strlen(rec->nick)); formatnum = rec->op ? TXT_NAMES_NICK_OP : rec->halfop ? TXT_NAMES_NICK_HALFOP : rec->voice ? TXT_NAMES_NICK_VOICE : TXT_NAMES_NICK; format = format_get_text(MODULE_NAME, NULL, channel->server, channel->visible_name, formatnum, nickmode, linebuf); g_string_append(str, format); g_free(format); if (++col == cols) { printtext(channel->server, channel->visible_name, MSGLEVEL_CLIENTCRAP, "%s", str->str); g_string_truncate(str, 0); if (prefix_format != NULL) g_string_assign(str, prefix_format); col = 0; row++; if (row == last_col_rows) cols--; } } if (str->len > strlen(prefix_format)) { printtext(channel->server, channel->visible_name, MSGLEVEL_CLIENTCRAP, "%s", str->str); } g_slist_free(nicklist); g_string_free(str, TRUE); g_free_not_null(columns); g_free_not_null(prefix_format); g_free(linebuf); }
static void read_settings(void) { rawlog_set_size(settings_get_int("rawlog_lines")); }
SERVER_REC * xmpp_server_init_connect(SERVER_CONNECT_REC *connrec) { XMPP_SERVER_REC *server; XMPP_SERVER_CONNECT_REC *conn = (XMPP_SERVER_CONNECT_REC *)connrec; char *recoded; if (conn->address == NULL || conn->address[0] == '\0') return NULL; if (conn->nick == NULL || conn->nick[0] == '\0') return NULL; g_return_val_if_fail(IS_XMPP_SERVER_CONNECT(conn), NULL); server = g_new0(XMPP_SERVER_REC, 1); server->chat_type = XMPP_PROTOCOL; server->user = xmpp_extract_user(conn->nick); server->domain = xmpp_have_domain(conn->nick) ? xmpp_extract_domain(conn->nick) : g_strdup(conn->address); server->jid = xmpp_have_domain(conn->nick) ? xmpp_strip_resource(conn->nick) : g_strconcat(server->user, "@", server->domain, (void *)NULL); server->resource = xmpp_extract_resource(conn->nick); if (server->resource == NULL) server->resource = g_strdup("irssi-xmpp"); server->priority = settings_get_int("xmpp_priority"); if (xmpp_priority_out_of_bound(server->priority)) server->priority = 0; server->ping_id = NULL; server->server_features = NULL; server->my_resources = NULL; server->roster = NULL; server->msg_handlers = NULL; server->channels_join = channels_join; server->isnickflag = isnickflag_func; server->ischannel = ischannel_func; server->get_nick_flags = get_nick_flags; server->send_message = send_message; server->connrec = (XMPP_SERVER_CONNECT_REC *)conn; server_connect_ref(connrec); /* don't use irssi's sockets */ server->connrec->no_connect = TRUE; server->connect_pid = -1; if (server->connrec->port <= 0) server->connrec->port = (server->connrec->use_ssl) ? LM_CONNECTION_DEFAULT_PORT_SSL : LM_CONNECTION_DEFAULT_PORT; if (conn->real_jid == NULL) conn->real_jid = conn->nick; else g_free(conn->nick); conn->nick = g_strdup(settings_get_bool("xmpp_set_nick_as_username") ? server->user : server->jid); /* init loudmouth connection structure */ server->lmconn = lm_connection_new(NULL); lm_connection_set_server(server->lmconn, server->connrec->address); lm_connection_set_port(server->lmconn, server->connrec->port); recoded = xmpp_recode_out(server->jid); lm_connection_set_jid(server->lmconn, recoded); g_free(recoded); lm_connection_set_keep_alive_rate(server->lmconn, 30); server->timeout_tag = 0; server_connect_init((SERVER_REC *)server); server->connect_tag = 1; return (SERVER_REC *)server; }
/* command: DCC SEND */ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item) { char *params, *target, *fname, *str, *ptr; char host[MAX_IP_LEN]; int hfile, hlisten, port; long fsize; DCC_REC *dcc, *chat; IPADDR own_ip; g_return_if_fail(data != NULL); params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &fname); if (*target == '\0' || *fname == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); /* if we're in dcc chat, send the request via it. */ chat = item_get_dcc(item); if (chat != NULL && (chat->mirc_ctcp || g_strcasecmp(target, chat->nick) != 0)) chat = NULL; if ((server == NULL || !server->connected) && chat == NULL) cmd_param_error(CMDERR_NOT_CONNECTED); if (dcc_find_item(DCC_TYPE_SEND, target, fname)) { signal_emit("dcc error send exists", 2, target, fname); g_free(params); return; } str = convert_home(fname); if (!g_path_is_absolute(str)) { char *path; g_free(str); path = convert_home(settings_get_str("dcc_upload_path")); str = g_strconcat(path, G_DIR_SEPARATOR_S, fname, NULL); g_free(path); } hfile = open(str, O_RDONLY); g_free(str); if (hfile == -1) { signal_emit("dcc error file not found", 2, target, fname); g_free(params); return; } fsize = lseek(hfile, 0, SEEK_END); lseek(hfile, 0, SEEK_SET); /* get the IP address we use with IRC server */ if (net_getsockname(chat != NULL ? chat->handle : server->handle, &own_ip, NULL) == -1) { close(hfile); cmd_param_error(CMDERR_ERRNO); } /* start listening */ port = settings_get_int("dcc_port"); hlisten = net_listen(&own_ip, &port); if (hlisten == -1) { close(hfile); cmd_param_error(CMDERR_ERRNO); } /* skip path, change all spaces to _ */ fname = g_strdup(g_basename(fname)); for (ptr = fname; *ptr != '\0'; ptr++) if (*ptr == ' ') *ptr = '_'; dcc = dcc_create(DCC_TYPE_SEND, hlisten, target, fname, server, chat); dcc->port = port; dcc->size = fsize; dcc->fhandle = hfile; dcc->tagread = g_input_add(hlisten, G_INPUT_READ, (GInputFunction) dcc_send_init, dcc); /* send DCC request */ dcc_make_address(&own_ip, host); str = g_strdup_printf("DCC SEND %s %s %d %lu", fname, host, port, fsize); dcc_ctcp_message(target, server, chat, FALSE, str); g_free(str); g_free(fname); g_free(params); }
static void read_settings(void) { scrollback_lines = settings_get_int("scrollback_lines"); scrollback_hours = settings_get_int("scrollback_hours"); scrollback_save_formats = settings_get_bool("scrollback_save_formats"); }
/* Handle incoming DCC CTCP messages */ static void dcc_ctcp_msg(char *data, IRC_SERVER_REC *server, char *sender, char *sendaddr, char *target, DCC_REC *chat) { char *type, *arg, *addrstr, *portstr, *sizestr, *str; void *free_arg; const char *cstr; DCC_REC *dcc, *olddcc; long size; int dcctype, port; g_return_if_fail(data != NULL); g_return_if_fail(sender != NULL); if (!cmd_get_params(data, &free_arg, 5 | PARAM_FLAG_NOQUOTES, &type, &arg, &addrstr, &portstr, &sizestr)) return; if (sscanf(portstr, "%d", &port) != 1) port = 0; if (sscanf(sizestr, "%ld", &size) != 1) size = 0; dcctype = SWAP_SENDGET(dcc_str2type(type)); olddcc = dcc_find_item(dcctype, sender, dcctype == DCC_TYPE_CHAT ? NULL : arg); if (olddcc != NULL) { /* same DCC request offered again */ if (olddcc->type == DCC_TYPE_CHAT && olddcc->handle != -1 && olddcc->starttime == 0) { /* we requested dcc chat, they requested dcc chat from us .. allow it. */ dcc_destroy(olddcc); } else { /* if the connection isn't open, update the port, otherwise just ignore */ if (olddcc->handle == -1) olddcc->port = port; cmd_params_free(free_arg); return; } } dcc = dcc_create(dcctype, -1, sender, arg, server, chat); dcc_get_address(addrstr, &dcc->addr); net_ip2host(&dcc->addr, dcc->addrstr); dcc->port = port; dcc->size = size; switch (dcc->type) { case DCC_TYPE_GET: cstr = settings_get_str("dcc_autoget_masks"); /* check that autoget masks match */ if (settings_get_bool("dcc_autoget") && (*cstr == '\0' || masks_match(SERVER(server), cstr, sender, sendaddr)) && /* check file size limit, FIXME: it's possible to send a bogus file size and then just send what ever sized file.. */ (settings_get_int("dcc_max_autoget_size") <= 0 || (settings_get_int("dcc_max_autoget_size") > 0 && size <= settings_get_int("dcc_max_autoget_size")*1024))) { /* automatically get */ str = g_strdup_printf("GET %s %s", dcc->nick, dcc->arg); signal_emit("command dcc", 2, str, server); g_free(str); } else { /* send request */ signal_emit("dcc request", 1, dcc); } break; case DCC_TYPE_CHAT: cstr = settings_get_str("dcc_autochat_masks"); if (olddcc != NULL || (*cstr != '\0' && masks_match(SERVER(server), cstr, sender, sendaddr))) { /* automatically accept chat */ str = g_strdup_printf("CHAT %s", dcc->nick); signal_emit("command dcc", 2, str, server); g_free(str); } else { /* send request */ signal_emit("dcc request", 1, dcc); } break; case DCC_TYPE_RESUME: case DCC_TYPE_ACCEPT: /* handle this in dcc-files.c */ dcc_destroy(dcc); break; default: /* unknown DCC command */ signal_emit("dcc unknown ctcp", 3, data, sender, sendaddr); dcc_destroy(dcc); break; } cmd_params_free(free_arg); }
static void read_settings(void) { scrollback_lines = settings_get_int("scrollback_lines"); scrollback_time = settings_get_time("scrollback_time")/1000; scrollback_burst_remove = settings_get_int("scrollback_burst_remove"); }
static void init_settings(void) { settings_init(); settings_load(); hotkey_t hk; settings_get(TRIGGER_KEY, &hk); INIT_KEY_SETTING(trigger); settings_get(ENG_KEY, &hk); INIT_KEY_SETTING(english); varchar colorstr; settings_get(PREEDIT_COLOR, colorstr); INIT_COLOR_SETTING(background_color_btn); settings_get(PREEDIT_FONT_COLOR, colorstr); INIT_COLOR_SETTING(font_color_btn); varchar fontstr; settings_get(PREEDIT_FONT, fontstr); gtk_font_button_set_font_name(font_btn, fontstr); gtk_adjustment_set_value(opacity_value, settings_get_double(PREEDIT_OPACITY)); gtk_adjustment_set_value(ncandidates, settings_get_int(CANDIDATES_SIZE)); gtk_toggle_button_set_active(minus_plus_check, settings_get_int(PAGE_MINUS_PLUS)); gtk_toggle_button_set_active(comma_period_check, settings_get_int(PAGE_COMMA_PERIOD)); gtk_toggle_button_set_active(paren_check, settings_get_int(PAGE_PAREN)); gtk_toggle_button_set_active(fuzzy_seg_check, settings_get_int(FUZZY_SEGMENTATION)); gtk_toggle_button_set_active(fuzzy_inner_seg_check, settings_get_int(FUZZY_INNER_SEGMENTATION)); gtk_toggle_button_set_active(cancel_on_backspace_check, settings_get_int(CANCEL_ON_BACKSPACE)); gtk_toggle_button_set_active(smart_punct_check, settings_get_int(SMART_PUNCT)); gtk_toggle_button_set_active(shuangpin_check, settings_get_int(SHUANGPIN)); varchar scheme; int i; settings_get(SHUANGPIN_SCHEME, scheme); for (i = 0; i < UI_SHUANGPIN_SCHEMES_NUM; i++) { if (strcmp(ui_shuangpin_schemes[i], scheme) == 0) { gtk_combo_box_set_active(shuangpin_combo, i); break; } } /* init status */ settings_get_int(INIT_PUNC_TYPE)? gtk_toggle_button_set_active(punc_english_radio, TRUE): gtk_toggle_button_set_active(punc_chinese_radio, TRUE); settings_get_int(INIT_WIDTH)? gtk_toggle_button_set_active(half_width_radio, TRUE): gtk_toggle_button_set_active(full_width_radio, TRUE); settings_get_int(INIT_LANGUAGE)? gtk_toggle_button_set_active(lang_english_radio, TRUE): gtk_toggle_button_set_active(lang_chinese_radio, TRUE); /* skin */ varchar skin_name; settings_get(SKIN_NAME, skin_name); int idx = list_skins(skin_name); gtk_combo_box_set_active(skin_combo, idx); gtk_toggle_button_set_active(hide_icbar_check, settings_get_int(HIDE_ICBAR)); }
static void read_settings(void) { scrollback_lines = settings_get_int("scrollback_lines"); scrollback_hours = settings_get_int("scrollback_hours"); scrollback_burst_remove = settings_get_int("scrollback_burst_remove"); }
/* Create server connection record. `address' is required, rest can be NULL */ static IRC_SERVER_CONNECT_REC * create_addr_conn(const char *address, int port, const char *password, const char *nick) { IRC_SERVER_CONNECT_REC *conn; SETUP_SERVER_REC *sserver; IRCNET_REC *ircnet; g_return_val_if_fail(address != NULL, NULL); conn = g_new0(IRC_SERVER_CONNECT_REC, 1); conn->address = g_strdup(address); conn->port = port > 0 ? port : 6667; if (password && *password) conn->password = g_strdup(password); if (nick && *nick) conn->nick = g_strdup(nick); if (!conn->nick) conn->nick = g_strdup(settings_get_str("default_nick")); conn->alternate_nick = g_strdup(settings_get_str("alternate_nick")); conn->username = g_strdup(settings_get_str("user_name")); conn->realname = g_strdup(settings_get_str("real_name")); /* proxy settings */ if (settings_get_bool("use_ircproxy")) { conn->proxy = g_strdup(settings_get_str("proxy_address")); conn->proxy_port = settings_get_int("proxy_port"); conn->proxy_string = g_strdup(settings_get_str("proxy_string")); } /* source IP */ get_source_host_ip(); if (source_host_ok) { conn->own_ip = g_new(IPADDR, 1); memcpy(conn->own_ip, source_host_ip, sizeof(IPADDR)); } /* fill the information from setup */ sserver = server_setup_find(address, -1); if (sserver == NULL) return conn; server_setup_fill_conn(conn, sserver); /* fill the rest from IRC network settings */ ircnet = sserver->ircnet == NULL ? NULL : ircnet_find(sserver->ircnet); if (ircnet == NULL) return conn; if (ircnet->nick && !(nick && *nick)) { g_free(conn->nick); conn->nick = g_strdup(ircnet->nick);; } if (ircnet->username) { g_free(conn->username); conn->username = g_strdup(ircnet->username);; } if (ircnet->realname) { g_free(conn->realname); conn->realname = g_strdup(ircnet->realname);; } if (ircnet->max_kicks > 0) conn->max_kicks = ircnet->max_kicks; if (ircnet->max_msgs > 0) conn->max_msgs = ircnet->max_msgs; if (ircnet->max_modes > 0) conn->max_modes = ircnet->max_modes; if (ircnet->max_whois > 0) conn->max_whois = ircnet->max_whois; if (ircnet->max_cmds_at_once > 0 && sserver->max_cmds_at_once <= 0) conn->max_cmds_at_once = ircnet->max_cmds_at_once; if (ircnet->cmd_queue_speed > 0 && sserver->cmd_queue_speed <= 0) conn->cmd_queue_speed = ircnet->cmd_queue_speed; if (sserver->own_host == NULL && ircnet->own_host != NULL) conn_set_ip(conn, &ircnet->own_ip, ircnet->own_host); return conn; }
static void read_settings(void) { rawlog_set_size(settings_get_int("rawlog_lines")); log_file_create_mode = octal2dec(settings_get_int("log_create_mode")); }
static void read_settings(void) { massjoin_max_joins = settings_get_int("massjoin_max_joins"); }