char * script_config_get_dir () { const char *weechat_home; char *path, *path2; weechat_home = weechat_info_get ("weechat_dir", NULL); path = weechat_string_expand_home (weechat_config_string (script_config_scripts_dir)); path2 = weechat_string_replace ((path) ? path : weechat_config_string (script_config_scripts_dir), "%h", weechat_home); if (path && path2) { free (path); path = NULL; } if (path2) return path2; if (path) return path; return strdup (weechat_config_string (script_config_scripts_dir)); }
void relay_network_set_ssl_cert_key (int verbose) { #ifdef HAVE_GNUTLS char *certkey_path, *certkey_path2; int ret; gnutls_certificate_free_credentials (relay_gnutls_x509_cred); gnutls_certificate_allocate_credentials (&relay_gnutls_x509_cred); relay_network_init_ssl_cert_key_ok = 0; certkey_path = weechat_string_expand_home (weechat_config_string (relay_config_network_ssl_cert_key)); if (certkey_path) { certkey_path2 = weechat_string_replace (certkey_path, "%h", weechat_info_get ("weechat_dir", NULL)); if (certkey_path2) { ret = gnutls_certificate_set_x509_key_file (relay_gnutls_x509_cred, certkey_path2, certkey_path2, GNUTLS_X509_FMT_PEM); if (ret >= 0) { relay_network_init_ssl_cert_key_ok = 1; if (verbose) { weechat_printf (NULL, _("%s: SSL certificate and key have been " "set"), RELAY_PLUGIN_NAME); } } else { if (verbose) { weechat_printf (NULL, _("%s%s: warning: no SSL certificate/key " "found (option relay.network.ssl_cert_key)"), weechat_prefix ("error"), RELAY_PLUGIN_NAME); } } free (certkey_path2); } free (certkey_path); } #else /* make C compiler happy */ (void) verbose; #endif }
char * irc_sasl_get_key_content (struct t_irc_server *server, const char *sasl_key) { const char *weechat_dir; char *key_path1, *key_path2, *content; if (!sasl_key) return NULL; content = NULL; weechat_dir = weechat_info_get ("weechat_dir", ""); key_path1 = weechat_string_replace (sasl_key, "%h", weechat_dir); key_path2 = (key_path1) ? weechat_string_expand_home (key_path1) : NULL; if (key_path2) content = weechat_file_get_content (key_path2); if (!content) { weechat_printf ( server->buffer, _("%s%s: unable to read private key in file \"%s\""), weechat_prefix ("error"), IRC_PLUGIN_NAME, (key_path2) ? key_path2 : ((key_path1) ? key_path1 : sasl_key)); } if (key_path1) free (key_path1); if (key_path2) free (key_path2); return content; }
void xfer_file_find_filename (struct t_xfer *xfer) { const char *weechat_home, *dir_separator; char *dir1, *dir2, *filename2; if (!XFER_IS_FILE(xfer->type)) return; dir1 = weechat_string_expand_home (weechat_config_string (xfer_config_file_download_path)); if (!dir1) return; weechat_home = weechat_info_get ("weechat_dir", ""); if (!weechat_home) { free (dir1); return; } dir2 = weechat_string_replace (dir1, "%h", weechat_home); if (!dir2) { free (dir1); return; } xfer->local_filename = malloc (strlen (dir2) + strlen (xfer->remote_nick) + strlen (xfer->filename) + 4); if (!xfer->local_filename) return; strcpy (xfer->local_filename, dir2); 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); if (dir1) free (dir1); if (dir2 ) free (dir2); /* 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; } filename2 = malloc (strlen (xfer->local_filename) + 16); if (!filename2) { xfer_close (xfer, XFER_STATUS_FAILED); xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE); return; } xfer->filename_suffix = 0; do { xfer->filename_suffix++; sprintf (filename2, "%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); } }
char * logger_get_file_path () { char *file_path, *file_path2, *file_path3; const char *weechat_dir; int length; time_t seconds; struct tm *date_tmp; file_path = NULL; file_path2 = NULL; file_path3 = NULL; weechat_dir = weechat_info_get ("weechat_dir", ""); if (!weechat_dir) goto end; /* replace "~" with user home */ file_path = weechat_string_expand_home (weechat_config_string (logger_config_file_path)); if (!file_path) goto end; /* replace "%h" with WeeChat home (at beginning of string only) */ if (strncmp (file_path, "%h", 2) == 0) { length = strlen (weechat_dir) + strlen (file_path + 2) + 1; file_path2 = malloc (length); if (file_path2) snprintf (file_path2, length, "%s%s", weechat_dir, file_path + 2); } else file_path2 = strdup (file_path); if (!file_path2) goto end; /* replace date/time specifiers in path */ length = strlen (file_path2) + 256 + 1; file_path3 = malloc (length); if (!file_path3) goto end; seconds = time (NULL); date_tmp = localtime (&seconds); file_path3[0] = '\0'; strftime (file_path3, length - 1, file_path2, date_tmp); if (weechat_logger_plugin->debug) { weechat_printf_tags (NULL, "no_log", "%s: file path = \"%s\"", LOGGER_PLUGIN_NAME, file_path3); } end: if (file_path) free (file_path); if (file_path2) free (file_path2); return file_path3; }