+
+static char hex[17] = "0123456789abcdef";
+
+static char * srvloc_encode(const struct afp_options *options, const char *name)
+{
+ static char buf[512];
+ char *conv_name;
+ unsigned char *p;
+ unsigned int i = 0;
+#ifndef NO_DDP
+ char *Obj, *Type = "", *Zone = "";
+#endif
+
+ /* Convert name to maccharset */
+ if ((size_t)-1 ==(convert_string_allocate( options->unixcharset, options->maccharset,
+ name, -1, &conv_name)) )
+ return (char*)name;
+
+ /* Escape characters */
+ p = conv_name;
+ while (*p && i<(sizeof(buf)-4)) {
+ if (*p == '@')
+ break;
+ else if (isspace(*p)) {
+ buf[i++] = '%';
+ buf[i++] = '2';
+ buf[i++] = '0';
+ p++;
+ }
+ else if ((!isascii(*p)) || *p <= 0x2f || *p == 0x3f ) {
+ buf[i++] = '%';
+ buf[i++] = hex[*p >> 4];
+ buf[i++] = hex[*p++ & 15];
+ }
+ else {
+ buf[i++] = *p++;
+ }
+ }
+ buf[i] = '\0';
+
+#ifndef NO_DDP
+ /* Add ZONE, */
+ if (nbp_name(options->server, &Obj, &Type, &Zone )) {
+ LOG(log_error, logtype_afpd, "srvloc_encode: can't parse %s", options->server );
+ }
+ else {
+ snprintf( buf+i, sizeof(buf)-i-1 ,"&ZONE=%s", Zone);
+ }
+#endif
+ free (conv_name);
+
+ return buf;
+}