Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/nad/nad_cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ static int copy(const char *path,
ad_setid(&ad, st.st_dev, st.st_ino, did, pdid, dvolume.db_stamp);

if (dvolume.vol->v_adouble == AD_VERSION2) {
ad_setname(&ad, utompath(dvolume.vol, basename(to.p_path)));
ad_setname(&ad, convert_utf8_to_mac(dvolume.vol, basename(to.p_path)));
}

ad_setdate(&ad, AD_DATE_CREATE | AD_DATE_UNIX, (uint32_t) st.st_mtime);
Expand Down Expand Up @@ -667,7 +667,7 @@ static int copy(const char *path,
ad_setid(&ad, st.st_dev, st.st_ino, cnid, did, dvolume.db_stamp);

if (dvolume.vol->v_adouble == AD_VERSION2) {
ad_setname(&ad, utompath(dvolume.vol, basename(to.p_path)));
ad_setname(&ad, convert_utf8_to_mac(dvolume.vol, basename(to.p_path)));
}

ad_setdate(&ad, AD_DATE_CREATE | AD_DATE_UNIX, (uint32_t) st.st_mtime);
Expand Down
44 changes: 0 additions & 44 deletions bin/nad/nad_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,50 +147,6 @@ void closevol(afpvol_t *vol)
memset(vol, 0, sizeof(afpvol_t));
}

/*
Taken from afpd/desktop.c
*/
char *utompath(const struct vol *vol, const char *upath)
{
/* for convert_charset dest_len parameter +2 */
static char mpath[MAXPATHLEN + 2];
char *m;
const char *u;
uint16_t flags = CONV_IGNORE | CONV_UNESCAPEHEX;
size_t outlen;

if (!upath) {
return NULL;
}

m = mpath;
u = upath;
outlen = strlen(upath);

if (vol->v_casefold & AFPVOL_UTOMUPPER) {
flags |= CONV_TOUPPER;
} else if (vol->v_casefold & AFPVOL_UTOMLOWER) {
flags |= CONV_TOLOWER;
}

if (vol->v_flags & AFPVOL_EILSEQ) {
flags |= CONV__EILSEQ;
}

/* convert charsets */
if ((size_t) -1 == convert_charset(vol->v_volcharset,
CH_UTF8_MAC,
vol->v_maccharset,
u, outlen, mpath, MAXPATHLEN, &flags)) {
SLOG("Conversion from %s to %s for %s failed.",
vol->v_volcodepage, vol->v_maccodepage, u);
return NULL;
}

return m;
}


/*!
* @brief Convert dot encoding of basename _in place_
*
Expand Down
46 changes: 2 additions & 44 deletions etc/cnid_dbd/cmd_dbd_scanvol.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,48 +65,6 @@ static struct cnid_dbd_rply rply _U_;
static jmp_buf jmp;
static char pname[MAXPATHLEN] = "../";

/*
Taken form afpd/desktop.c
*/
static char *utompath(char *upath)
{
/* for convert_charset dest_len parameter +2 */
static char mpath[MAXPATHLEN + 2];
char *m, *u;
uint16_t flags = CONV_IGNORE | CONV_UNESCAPEHEX;
size_t outlen;

if (!upath) {
return NULL;
}

m = mpath;
u = upath;
outlen = strlen(upath);

if (vol->v_casefold & AFPVOL_UTOMUPPER) {
flags |= CONV_TOUPPER;
} else if (vol->v_casefold & AFPVOL_UTOMLOWER) {
flags |= CONV_TOLOWER;
}

if (vol->v_flags & AFPVOL_EILSEQ) {
flags |= CONV__EILSEQ;
}

/* convert charsets */
if ((size_t) -1 == (outlen = convert_charset(vol->v_volcharset,
CH_UTF8_MAC,
vol->v_maccharset,
u, outlen, mpath, MAXPATHLEN, &flags))) {
dbd_log(LOGSTD, "Conversion from %s to %s for %s failed.",
vol->v_volcodepage, vol->v_maccodepage, u);
return NULL;
}

return m;
}

/*!
* @brief Check for netatalk special folders e.g. ".AppleDB" or ".AppleDesktop"
* @returns pointer to name or NULL.
Expand Down Expand Up @@ -233,7 +191,7 @@ static int check_adfile(const char *fname, const struct stat *st,
}

/* Set name in ad-file */
ad_setname(&ad, utompath((char *)fname));
ad_setname(&ad, convert_utf8_to_mac(vol, fname));
ad_flush(&ad);
ad_close(&ad, ADFLAGS_HF);
fd = open(adname, O_RDWR | O_NOFOLLOW);
Expand Down Expand Up @@ -461,7 +419,7 @@ static int check_addir(int volroot _U_)
}

/* Get basename of cwd from cwdbuf */
mname = utompath(strrchr(cwdbuf, '/') + 1);
mname = convert_utf8_to_mac(vol, strrchr(cwdbuf, '/') + 1);
/* Update name in ad file */
ad_setname(&ad, mname);
ad_flush(&ad);
Expand Down
8 changes: 7 additions & 1 deletion include/atalk/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,16 @@ extern cnid_t cnid_for_path(struct _cnid_db *cdb, const char *volpath,
const char *path, cnid_t *did);

/******************************************************************
* cnid.c
* gettok.c
*****************************************************************/

extern void initline(int, char *);
extern int parseline(int, char *);

/******************************************************************
* pathconv.c
*****************************************************************/

extern char *convert_utf8_to_mac(const struct vol *vol, const char *upath);

#endif /* _ATALK_UTIL_H */
1 change: 1 addition & 0 deletions libatalk/util/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ util_sources = [
'locking.c',
'logger.c',
'netatalk_conf.c',
'pathconv.c',
'queue.c',
'server_child.c',
'server_ipc.c',
Expand Down
63 changes: 63 additions & 0 deletions libatalk/util/pathconv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */

#include <atalk/globals.h>
#include <atalk/logger.h>
#include <atalk/util.h>
#include <atalk/volume.h>

/*!
* @brief Convert a UTF-8 filename to a mangled Mac filename
*
* @param vol volume structure
* @param upath input path in UTF-8
*
* @return pointer to static buffer containing mangled Mac filename
*
* @sa utompath() in etc/afpd/desktop.c
*/
char *convert_utf8_to_mac(const struct vol *vol, const char *upath)
{
/* for convert_charset dest_len parameter +2 */
static char mpath[MAXPATHLEN + 2];
char *m;
const char *u;
uint16_t flags = CONV_IGNORE | CONV_UNESCAPEHEX;
size_t outlen;

if (!upath) {
return NULL;
}

m = mpath;
u = upath;
outlen = strnlen(upath, MAXPATHLEN);

if (vol->v_casefold & AFPVOL_UTOMUPPER) {
flags |= CONV_TOUPPER;
} else if (vol->v_casefold & AFPVOL_UTOMLOWER) {
flags |= CONV_TOLOWER;
}

if (vol->v_flags & AFPVOL_EILSEQ) {
flags |= CONV__EILSEQ;
}

/* convert charsets */
if ((size_t) -1 == convert_charset(vol->v_volcharset,
CH_UTF8_MAC,
vol->v_maccharset,
u, outlen, mpath, MAXPATHLEN, &flags)) {
LOG(log_error, logtype_default, "Conversion from %s to %s for %s failed.",
vol->v_volcodepage, vol->v_maccodepage, u);
return NULL;
}

return m;
}