o_len=destlen;
while (i_len > 0) {
- if ((option & CONV_UNESCAPEHEX)) {
- for (j = 0; j < i_len; ++j) {
- if (inbuf[j] == ':') break;
- }
- j = i_len - j;
- i_len -= j;
- }
+ for (j = 0; j < i_len; ++j)
+ if (inbuf[j] == ':')
+ break;
+ j = i_len - j;
+ i_len -= j;
if (i_len > 0 &&
atalk_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len) == (size_t)-1) {
}
if (j) {
- /* we're at the start on an hex encoded ucs2 char */
- char h[MAXPATHLEN];
- size_t hlen = 0;
-
+ /* we have a ':' */
i_len = j, j = 0;
- while (i_len >= 3 && inbuf[0] == ':' &&
- isxdigit(inbuf[1]) && isxdigit(inbuf[2])) {
- h[hlen++] = (hextoint(inbuf[1]) << 4) | hextoint(inbuf[2]);
- inbuf += 3;
- i_len -= 3;
- }
- if (hlen) {
- const char *h_buf = h;
- if (atalk_iconv(descriptor_cap, &h_buf, &hlen, &outbuf, &o_len) == (size_t)-1) {
- i_len += hlen * 3;
- inbuf -= hlen * 3;
- if (errno == EILSEQ && (option & CONV_IGNORE)) {
+
+ if ((option & CONV_UNESCAPEHEX)) {
+ /* treat it as a CAP hex encoded char */
+ char h[MAXPATHLEN];
+ size_t hlen = 0;
+
+ while (i_len >= 3 && inbuf[0] == ':' &&
+ isxdigit(inbuf[1]) && isxdigit(inbuf[2])) {
+ h[hlen++] = (hextoint(inbuf[1]) << 4) | hextoint(inbuf[2]);
+ inbuf += 3;
+ i_len -= 3;
+ }
+ if (hlen) {
+ const char *h_buf = h;
+ if (atalk_iconv(descriptor_cap, &h_buf, &hlen, &outbuf, &o_len) == (size_t)-1) {
+ i_len += hlen * 3;
+ inbuf -= hlen * 3;
+ if (errno == EILSEQ && (option & CONV_IGNORE)) {
+ *flags |= CONV_REQMANGLE;
+ return destlen - o_len;
+ }
+ goto end;
+ }
+ } else {
+ /* We have an invalid :xx sequence */
+ errno = EILSEQ;
+ if ((option & CONV_IGNORE)) {
*flags |= CONV_REQMANGLE;
return destlen - o_len;
}
goto end;
}
} else {
- /* We have an invalid :xx sequence */
- errno = EILSEQ;
- if ((option & CONV_IGNORE)) {
- *flags |= CONV_REQMANGLE;
- return destlen - o_len;
- }
- goto end;
+ /* a ':' that we just convert to a '/' */
+ ucs2_t slash = 0x002f;
+ memcpy(outbuf, &slash, sizeof(ucs2_t));
+ outbuf += 2;
+ o_len -= 2;
+ inbuf++;
+ i_len--;
}
}
}
}
while (i_len >= 2) {
- if ((option & CONV_ESCAPEHEX)) {
- for (i = 0; i < i_len; i += 2) {
- ucs2_t c = SVAL(inbuf, i);
- switch (c) {
- case 0x003a: /* 0x003a = ':' */
- if ( ! (option & CONV_ALLOW_COLON)) {
- errno = EILSEQ;
- goto end;
- }
- escch = c;
- j = i_len - i;
- i_len = i;
- break;
- case 0x002f: /* 0x002f = '/' */
- escch = c;
- j = i_len - i;
- i_len = i;
- break;
+ for (i = 0; i < i_len; i += 2) {
+ ucs2_t c = SVAL(inbuf, i);
+ switch (c) {
+ case 0x003a: /* 0x003a = ':' */
+ if ( ! (option & CONV_ALLOW_COLON)) {
+ errno = EILSEQ;
+ goto end;
}
+ escch = c;
+ j = i_len - i;
+ i_len = i;
+ break;
+ case 0x002f: /* 0x002f = '/' */
+ escch = c;
+ j = i_len - i;
+ i_len = i;
+ break;
}
}
while (i_len > 0 &&
}
if (j) {
+ /* we have a ':' or '/' */
i_len = j, j = 0;
- if (o_len < 3) {
- errno = E2BIG;
- goto end;
- }
- switch (escch) {
- case '/':
- *outbuf++ = ':';
- *outbuf++ = '2';
- *outbuf++ = 'f';
- break;
- case ':':
- *outbuf++ = ':';
- *outbuf++ = '3';
- *outbuf++ = 'a';
- break;
- default:
- /*
- * THIS SHOULD NEVER BE REACHED !!!
- * As a safety net I put in a ' ' here
- */
- *outbuf++ = ':';
- *outbuf++ = '2';
- *outbuf++ = '0';
- break;
+
+ if ((option & CONV_ESCAPEHEX)) {
+ /* CAP hex encode it */
+ if (o_len < 3) {
+ errno = E2BIG;
+ goto end;
+ }
+ switch (escch) {
+ case '/':
+ *outbuf++ = ':';
+ *outbuf++ = '2';
+ *outbuf++ = 'f';
+ break;
+ case ':':
+ *outbuf++ = ':';
+ *outbuf++ = '3';
+ *outbuf++ = 'a';
+ break;
+ default:
+ /*
+ * THIS SHOULD NEVER BE REACHED !!!
+ * As a safety net I put in a ' ' here
+ */
+ *outbuf++ = ':';
+ *outbuf++ = '2';
+ *outbuf++ = '0';
+ break;
+ }
+ o_len -= 3;
+ inbuf += 2;
+ i_len -= 2;
+ } else {
+ switch (escch) {
+ case '/':
+ case ':':
+ *outbuf++ = ':';
+ break;
+ default: /* should never be reached */
+ *outbuf++ = ' ';
+ break;
+ }
+ o_len--;
+ inbuf += 2;
+ i_len -= 2;
}
- o_len -= 3;
- inbuf += 2;
- i_len -= 2;
}
}
if (i_len > 0) errno = EINVAL;
if (getoption_bool(obj->iniconfig, section, "read only", preset, 0))
volume->v_flags |= AFPVOL_RO;
- if (!getoption_bool(obj->iniconfig, section, "hex encoding", preset, 1))
+ if (!getoption_bool(obj->iniconfig, section, "hex encoding", preset, 0))
volume->v_flags |= AFPVOL_NOHEX;
if (getoption_bool(obj->iniconfig, section, "use dots", preset, 1))
volume->v_flags |= AFPVOL_USEDOTS;
volume->v_ad_options |= ADVOL_INVDOTS;
/* Mac to Unix conversion flags*/
- if (!(volume->v_flags & AFPVOL_NOHEX))
+ if (!(volume->v_flags & AFPVOL_NOHEX)) {
volume->v_mtou_flags |= CONV_ESCAPEHEX;
+ volume->v_utom_flags |= CONV_UNESCAPEHEX;
+ }
if (!(volume->v_flags & AFPVOL_USEDOTS))
volume->v_mtou_flags |= CONV_ESCAPEDOTS;
if ((volume->v_flags & AFPVOL_EILSEQ))
volume->v_mtou_flags |= CONV_TOLOWER;
/* Unix to Mac conversion flags*/
- volume->v_utom_flags = CONV_IGNORE | CONV_UNESCAPEHEX;
+ volume->v_utom_flags = CONV_IGNORE;
if ((volume->v_casefold & AFPVOL_UTOMUPPER))
volume->v_utom_flags |= CONV_TOUPPER;
else if ((volume->v_casefold & AFPVOL_UTOMLOWER))