EMSI quoting

Pablo Saratxaga (srtxg@linux.chanae.stben.be)
Fri, 24 Jan 1997 12:56:43 +0100 (MET)

Hello !

There is a little patch to add EMSI escaping, as defined in fsc-0056, so
characaters [ ] { } \ can be used in fields "name", "sysop", "location".
The EMSI packets are correctly created whith the escaping, however when
testing I remarked that incoming packets aren't properly handled, it seems
that only the first escaping is handled the rest trashed...

I defined the system name "== Bad WaZOO BBS ][ ==" in config file.

prepared: "EMSI_DAT0113{EMSI}....{[== Bad WaZOO BBS \5D\5B ==][Liege]...

got data packet: "{EMSI}...{[== Bad WaZOO BBS \5D\5B ==][Liege]...

So the escaping is correctly done, however:

remote system: == Bad WaZOO BBS
remote location: ==
remote operator: Liege
remote phone: Pablo Saratxaga
remote baud: 32-4-3445020
remote flags: 14400

...

This affect _incoming_ packets and so can be a problematic bug.
It seems that the dequoting is done before the parsing to find the closing
"]". Same problem for "\". So I changed sel_brace to double those two
chars before calling sel_bracket.
There is allways the case of a "]" or "\" inside of a pure brace, whithout
brackets inside. But I think it is really not a common think :) and
anyway the annoyance of having those two characters redoubled is less than
having the fileds switched like before, whith phone numbers like
"Pablo Saratxaga" :)

Well, now you can delete the line

# For now, escaping of '}' and ']' unimplemented, try to avoid these
# characters please!

in sample config file ;-)

--- work/ifmail-2.9/ifcico/emsidat.c Sun Sep 8 19:13:33 1996
+++ ifmail/ifcico/emsidat.c Fri Jan 24 12:46:42 1997
@@ -15,6 +15,38 @@
extern time_t sl2mtime(time_t);
extern int nodelock(faddr*);

+char *emsiencode(s)
+char *s;
+{
+ char Base16Code[]="0123456789ABCDEF";
+ static char *buf;
+ char *p, *q;
+
+ if (buf)
+ free(buf);
+ if ((buf = malloc(2 * strlen(s) + 1 * sizeof(char))) == NULL) {
+ loginf("emsiencode:out of memory:string too long:\"%s\"", s);
+ return s;
+ }
+ for (p = s, q = buf; *p != '\0';) {
+ switch (*p)
+ {
+ case '\\': *q++ = '\\'; *q++ = *p++; break;
+ case '[':
+ case ']':
+ case '{':
+ case '}': *q++ = '\\';
+ *q++ = Base16Code[(*p >> 4) & 0x0f];
+ *q++ = Base16Code[*p & 0x0f];
+ p++; break;
+ default: *q++ = *p++; break;
+ }
+ }
+ *q = '\0';
+
+ return buf;
+}
+
char *mkemsidat(caller)
int caller;
{
@@ -85,19 +117,19 @@
sprintf(cbuf,"%08lX",mtime2sl(tt));
p=xstrcat(p,cbuf);
p=xstrcat(p,"]}{IDENT}{[");
- p=xstrcat(p,name?name:"Unknown");
+ p=xstrcat(p,name?emsiencode(name):"Unknown");
p=xstrcat(p,"][");
- p=xstrcat(p,location?location:"Unknown");
+ p=xstrcat(p,location?emsiencode(location):"Unknown");
p=xstrcat(p,"][");
- p=xstrcat(p,sysop?sysop:"Unknown");
+ p=xstrcat(p,sysop?emsiencode(sysop):"Unknown");
p=xstrcat(p,"][");
- p=xstrcat(p,phone?phone:"-Unpublished-");
+ p=xstrcat(p,phone?emsiencode(phone):"-Unpublished-");
p=xstrcat(p,"][");
if (speed) sprintf(cbuf,"%ld",speed);
else strcpy(cbuf,"9600");
p=xstrcat(p,cbuf);
p=xstrcat(p,"][");
- p=xstrcat(p,flags?flags:"");
+ p=xstrcat(p,flags?emsiencode(flags):"");
p=xstrcat(p,"]}");

sprintf(cbuf,"%04X",strlen(p+12));
@@ -132,10 +164,11 @@
goto exit;
}
break;
- case '\\': if (*(p+1) == '\\') *q++=*p++;
+ case '\\': if (*(p+1) == '\\') { *q++=*p++; *q++=*p; }
else
{
sscanf(p+1,"%02x",&i);
+ if ((i == '\\') || (i == ']')) *q++=i;
*q++=i;
p+=2;
}
@@ -307,7 +340,7 @@
else
{
q=sel_brace(NULL);
- loginf("remote tag: \"%s\" value: \"%s\"",p,q);
+ loginf("remote tag: \"%s\" value: \"%s\"",p,q);
}

return 0;

--

A bientôt, Pablo Saratxaga

~ ~ :wq ;-) PGP Key available, key ID: 0x8F0E4975