/* conversion from UTF8 to the "current" charset */ char *FiconvUtf8ToCharset(Display *dpy, FlocaleCharset *fc, const char *in, unsigned int in_size) { char *out = NULL; FlocaleCharset *my_fc = NULL; if (!FiconvSupport) { return NULL; } my_fc = FiconvSetupConversion(dpy, fc); if (my_fc == NULL) { return NULL; } #if FLOCALE_DEBUG_ICONV fprintf(stderr, "[FiconvUtf8ToCharset] conversion from %s to %s\n", FLC_DEBUG_GET_ICONV_CHARSET(FLCIconvUtf8Charset), FLC_DEBUG_GET_ICONV_CHARSET(my_fc)); #endif if (FLC_ENCODING_TYPE_IS_UTF_8(my_fc)) { /* in can be a none terminate string so do not use CopyString */ out = safemalloc(in_size+1); strncpy(out, in, in_size); out[in_size]=0; } else { char *to_cs; if (do_transliterate_utf8 && FLC_IS_TRANSLIT_SUPPORTED(my_fc)) { to_cs = FLC_GET_ICONV_TRANSLIT_CHARSET(my_fc); } else { to_cs = FLC_GET_ICONV_CHARSET(my_fc); } out = convert_charsets( FLC_GET_ICONV_CHARSET(FLCIconvUtf8Charset), to_cs, in, in_size); } return out; }
int main(int argc, char** argv) { CURL *easy; CURLcode curl_res; char *tmp; int res; struct fuse_args args = FUSE_ARGS_INIT(argc, argv); /* Initialize curl library before we are a multithreaded program */ curl_global_init(CURL_GLOBAL_ALL); memset(&ftpfs, 0, sizeof ftpfs); /* Set some default values */ ftpfs.curl_version = curl_version_info(CURLVERSION_NOW); ftpfs.safe_nobody = ftpfs.curl_version->version_num > CURLFTPFS_BAD_NOBODY; ftpfs.blksize = 4096; ftpfs.disable_epsv = 1; ftpfs.multiconn = 1; ftpfs.attached_to_multi = 0; if (fuse_opt_parse(&args, &ftpfs, ftpfs_opts, ftpfs_opt_proc) == -1) return 1; if (!ftpfs.host) { fprintf(stderr, "missing host\n"); fprintf(stderr, "see `%s -h' for usage\n", argv[0]); return 1; } if (!ftpfs.iocharset) { ftpfs.iocharset = "UTF8"; } if (ftpfs.codepage) { convert_charsets(ftpfs.iocharset, ftpfs.codepage, &ftpfs.host); } easy = curl_easy_init(); if (easy == NULL) { fprintf(stderr, "Error initializing libcurl\n"); return 1; } res = cache_parse_options(&args); if (res == -1) return 1; if (!prompt_passwd("host", &ftpfs.user)) return 1; if (!prompt_passwd("proxy", &ftpfs.proxy_user)) return 1; if (ftpfs.transform_symlinks && !ftpfs.mountpoint) { fprintf(stderr, "cannot transform symlinks: no mountpoint given\n"); return 1; } if (!ftpfs.transform_symlinks) ftpfs.symlink_prefix_len = 0; else if (realpath(ftpfs.mountpoint, ftpfs.symlink_prefix) != NULL) ftpfs.symlink_prefix_len = strlen(ftpfs.symlink_prefix); else { fprintf(stderr, "unable to normalize mount path\n"); return 1; } set_common_curl_stuff(easy); curl_easy_setopt_or_die(easy, CURLOPT_WRITEDATA, NULL); curl_easy_setopt_or_die(easy, CURLOPT_NOBODY, ftpfs.safe_nobody); curl_res = curl_easy_perform(easy); if (curl_res != 0) ftpfs_curl_easy_perform_abort(); curl_easy_setopt_or_die(easy, CURLOPT_NOBODY, 0); ftpfs.multi = curl_multi_init(); if (ftpfs.multi == NULL) { fprintf(stderr, "Error initializing libcurl multi\n"); return 1; } ftpfs.connection = easy; pthread_mutex_init(&ftpfs.lock, NULL); /* Set the filesystem name to show the current server */ tmp = g_strdup_printf("-ofsname=curlftpfs#%s", ftpfs.host); fuse_opt_insert_arg(&args, 1, tmp); g_free(tmp); res = ftpfs_fuse_main(&args); cancel_previous_multi(); curl_multi_cleanup(ftpfs.multi); curl_easy_cleanup(easy); curl_global_cleanup(); fuse_opt_free_args(&args); pthread_mutex_destroy(&ftpfs.lock); cache_deinit(); return res; }