char * script_config_get_xml_filename () { char *path, *filename; int length; path = weechat_string_eval_path_home ( weechat_config_string (script_config_scripts_path), NULL, NULL, NULL); length = strlen (path) + 64; filename = malloc (length); if (filename) snprintf (filename, length, "%s/plugins.xml.gz", path); free (path); return filename; }
void relay_server_update_path (struct t_relay_server *server, const char *path) { char *new_path; new_path = weechat_string_eval_path_home (path, NULL, NULL, NULL); if (!new_path) return; if (strcmp (new_path, server->path) != 0) { relay_server_close_socket (server); free (server->path); server->path = strdup (new_path); server->port = -1; relay_server_create_socket (server); } free (new_path); }
char * logger_get_file_path () { char *path, *path2; int length; time_t seconds; struct tm *date_tmp; path = NULL; path2 = NULL; /* replace %h and "~", evaluate path */ path = weechat_string_eval_path_home ( weechat_config_string (logger_config_file_path), NULL, NULL, NULL); if (!path) goto end; /* replace date/time specifiers in path */ length = strlen (path) + 256 + 1; path2 = malloc (length); if (!path2) goto end; seconds = time (NULL); date_tmp = localtime (&seconds); path2[0] = '\0'; strftime (path2, length - 1, path, date_tmp); if (weechat_logger_plugin->debug) { weechat_printf_tags (NULL, "no_log", "%s: file path = \"%s\"", LOGGER_PLUGIN_NAME, path2); } end: if (path) free (path); return path2; }
char * script_config_get_script_download_filename (struct t_script_repo *script, const char *suffix) { char *path, *filename; int length; path = weechat_string_eval_path_home ( weechat_config_string (script_config_scripts_path), NULL, NULL, NULL); length = strlen (path) + 1 + strlen (script->name_with_extension) + ((suffix) ? strlen (suffix) : 0) + 1; filename = malloc (length); if (filename) { snprintf (filename, length, "%s/%s%s", path, script->name_with_extension, (suffix) ? suffix : ""); } free (path); return filename; }
void xfer_file_find_filename (struct t_xfer *xfer) { const char *dir_separator; char *path, *filename2; int length; if (!XFER_IS_FILE(xfer->type)) return; path = weechat_string_eval_path_home ( weechat_config_string (xfer_config_file_download_path), NULL, NULL, NULL); if (!path) return; xfer->local_filename = malloc (strlen (path) + strlen (xfer->remote_nick) + strlen (xfer->filename) + 4); if (!xfer->local_filename) { free (path); return; } strcpy (xfer->local_filename, path); dir_separator = weechat_info_get("dir_separator", ""); if (dir_separator && (xfer->local_filename[strlen (xfer->local_filename) - 1] != dir_separator[0])) strcat (xfer->local_filename, dir_separator); if (weechat_config_boolean (xfer_config_file_use_nick_in_filename)) { strcat (xfer->local_filename, xfer->remote_nick); strcat (xfer->local_filename, "."); } strcat (xfer->local_filename, xfer->filename); free (path); /* file already exists? */ if (access (xfer->local_filename, F_OK) == 0) { if (xfer_file_resume (xfer, xfer->local_filename)) return; /* if auto rename is not set, then abort xfer */ if (!xfer_config_file_auto_rename) { xfer_close (xfer, XFER_STATUS_FAILED); xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE); return; } length = strlen (xfer->local_filename) + 16; filename2 = malloc (length); if (!filename2) { xfer_close (xfer, XFER_STATUS_FAILED); xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE); return; } xfer->filename_suffix = 0; do { xfer->filename_suffix++; snprintf (filename2, length, "%s.%d", xfer->local_filename, xfer->filename_suffix); if (access (filename2, F_OK) == 0) { if (xfer_file_resume (xfer, filename2)) break; } else break; } while (1); free (xfer->local_filename); xfer->local_filename = strdup (filename2); free (filename2); } }
struct t_relay_server * relay_server_new (const char *protocol_string, enum t_relay_protocol protocol, const char *protocol_args, int port, const char *path, int ipv4, int ipv6, int ssl, int unix_socket) { struct t_relay_server *new_server, *dup_server; if (!protocol_string) return NULL; /* look for duplicate ports/paths */ dup_server = (unix_socket) ? relay_server_search_path (path) : relay_server_search_port (port); if (dup_server) { if (unix_socket) { weechat_printf (NULL, _("%s%s: error: path \"%s\" is already used"), weechat_prefix ("error"), RELAY_PLUGIN_NAME, path); } else { weechat_printf (NULL, _("%s%s: error: port \"%d\" is already used"), weechat_prefix ("error"), RELAY_PLUGIN_NAME, port); } return NULL; } new_server = malloc (sizeof (*new_server)); if (new_server) { new_server->protocol_string = strdup (protocol_string); new_server->protocol = protocol; new_server->protocol_args = (protocol_args) ? strdup (protocol_args) : NULL; new_server->port = port; new_server->path = weechat_string_eval_path_home (path, NULL, NULL, NULL); new_server->ipv4 = ipv4; new_server->ipv6 = ipv6; new_server->ssl = ssl; new_server->unix_socket = unix_socket; new_server->sock = -1; new_server->hook_fd = NULL; new_server->start_time = 0; new_server->last_client_disconnect = 0; relay_server_create_socket (new_server); new_server->prev_server = NULL; new_server->next_server = relay_servers; if (relay_servers) relay_servers->prev_server = new_server; else last_relay_server = new_server; relay_servers = new_server; } else { weechat_printf (NULL, _("%s%s: not enough memory for listening on new port"), weechat_prefix ("error"), RELAY_PLUGIN_NAME); } return new_server; }