Exemplo n.º 1
0
static char* ConvertFromUtf8Filename(const char* fName){
#if _WIN32
	char* convertedFilename;
	int nChar, nb_byte;
	LPWSTR wideFilename;
	
	nChar = MultiByteToWideChar(CP_UTF8, 0, fName, -1, NULL, 0);
	if (nChar == 0) return NULL;
	wideFilename = bctbx_malloc(nChar*sizeof(wideFilename[0]));
	if (wideFilename == NULL) return NULL;
	nChar = MultiByteToWideChar(CP_UTF8, 0, fName, -1, wideFilename, nChar);
	if (nChar == 0) {
		bctbx_free(wideFilename);
		wideFilename = 0;
	}
	
	nb_byte = WideCharToMultiByte(CP_ACP, 0, wideFilename, -1, 0, 0, 0, 0);
	if (nb_byte == 0) return NULL;
	convertedFilename = bctbx_malloc(nb_byte);
	if (convertedFilename == NULL) return NULL;
	nb_byte = WideCharToMultiByte(CP_ACP, 0, wideFilename, -1, convertedFilename, nb_byte, 0, 0);
	if (nb_byte == 0) {
		bctbx_free(convertedFilename);
		convertedFilename = 0;
	}
	bctbx_free(wideFilename);
	return convertedFilename;
#elif defined(__QNXNTO__)
	return bctbx_strdup(fName);
#else
	#define MAX_PATH_SIZE 1024
	char db_file_utf8[MAX_PATH_SIZE] = {'\0'};
	char db_file_locale[MAX_PATH_SIZE] = "";
	char *outbuf=db_file_locale, *inbuf=db_file_utf8;
	size_t inbyteleft = MAX_PATH_SIZE, outbyteleft = MAX_PATH_SIZE;
	iconv_t cb;
	
	if (strcasecmp("UTF-8", nl_langinfo(CODESET)) == 0) {
		strncpy(db_file_locale, fName, MAX_PATH_SIZE - 1);
	} else {
		strncpy(db_file_utf8, fName, MAX_PATH_SIZE-1);
		cb = iconv_open(nl_langinfo(CODESET), "UTF-8");
		if (cb != (iconv_t)-1) {
			int ret;
			ret = iconv(cb, &inbuf, &inbyteleft, &outbuf, &outbyteleft);
			if(ret == -1) db_file_locale[0] = '\0';
			iconv_close(cb);
		}
	}
	return bctbx_strdup(db_file_locale);
#endif
}
int32_t bctbx_ssl_set_hostname(bctbx_ssl_context_t *ssl_ctx, const char *hostname){
	if (ssl_ctx->cn) bctbx_free(ssl_ctx->cn);
	if (hostname) ssl_ctx->cn = bctbx_strdup(hostname);
	else ssl_ctx->cn = NULL;
	ssl_ctx->ssl_ctx.peer_cn = ssl_ctx->cn;
	return 0;
}