Added clencode and cldecode to safe escape messages to mbtask

This commit is contained in:
Michiel Broek 2005-10-17 13:08:43 +00:00
parent 09574dcaca
commit 6cf5ac3431
3 changed files with 128 additions and 49 deletions

View File

@ -9,6 +9,9 @@ v0.81.2 14-Oct-2005.
the outbound are 12 bytes log. If not, stop the whole bbs and the outbound are 12 bytes log. If not, stop the whole bbs and
remove all these files. Then start the bbs again. remove all these files. Then start the bbs again.
libmbse.a:
Added clencode and cldecode to safe escape messages to mbtask.
mbcico: mbcico:
Some time_t/int conversions. Some time_t/int conversions.

View File

@ -102,6 +102,8 @@ char *xstrcat(char *src, char *add)
void InitClient(char *user, char *myname, char *where, char *logfname, int loggr, char *err, char *mgr, char *debug) void InitClient(char *user, char *myname, char *where, char *logfname, int loggr, char *err, char *mgr, char *debug)
{ {
char *u, *w;
if ((getenv("MBSE_ROOT")) == NULL) { if ((getenv("MBSE_ROOT")) == NULL) {
printf("Could not get the MBSE_ROOT environment variable\n"); printf("Could not get the MBSE_ROOT environment variable\n");
printf("Please set the environment variable ie:\n"); printf("Please set the environment variable ie:\n");
@ -124,10 +126,14 @@ void InitClient(char *user, char *myname, char *where, char *logfname, int loggr
* some communications with the mbsed server. * some communications with the mbsed server.
*/ */
mypid = getpid(); mypid = getpid();
if (socket_connect(user, myname, where) == -1) { u = xstrcpy(clencode(user));
w = xstrcpy(clencode(where));
if (socket_connect(u, myname, w) == -1) {
printf("PANIC: cannot access socket\n"); printf("PANIC: cannot access socket\n");
exit(MBERR_INIT_ERROR); exit(MBERR_INIT_ERROR);
} }
free(w);
free(u);
} }
@ -400,7 +406,13 @@ void SetTTY(char *tty)
void UserCity(pid_t pid, char *user, char *city) void UserCity(pid_t pid, char *user, char *city)
{ {
SockS("AUSR:3,%d,%s,%s;", pid, user, city); char *u, *c;
u = xstrcpy(clencode(user));
c = xstrcpy(clencode(city));
SockS("AUSR:3,%d,%s,%s;", pid, u, c);
free(u);
free(c);
} }
@ -412,7 +424,7 @@ void DoNop()
static int32_t nop = 0; static time_t nop = 0;
/* /*
* This function can be called very often but will only send once a minute * This function can be called very often but will only send once a minute
@ -423,7 +435,7 @@ void Nopper(void)
time_t now; time_t now;
now = time(NULL); now = time(NULL);
if (((time_t)now - (time_t)nop) > 60) { if ((now - nop) > 60) {
nop = now; nop = now;
SockS("GNOP:1,%d;", mypid); SockS("GNOP:1,%d;", mypid);
} }
@ -501,6 +513,68 @@ int enoughspace(unsigned int needed)
char *clencode(char *s)
{
char Base16Code[]="0123456789ABCDEF";
static char *buf;
char *p, *q;
if (buf)
free(buf);
buf = NULL;
if (s == NULL)
return NULL;
if ((buf = malloc(2 * strlen(s) + 1 * sizeof(char))) == NULL) {
Syslog('+', "clencode: out of memory:string too long:\"%s\"", s);
return s;
}
for (p = s, q = buf; *p != '\0';) {
if ((! isascii(*p)) || (*p == ',')) {
*q++ = '\\';
*q++ = Base16Code[(*p >> 4) & 0x0f];
*q++ = Base16Code[*p & 0x0f];
p++;
} else if (*p == '\\') {
*q++ = '\\';
*q++ = *p++;
} else {
*q++ = *p++;
}
}
*q = '\0';
return buf;
}
char *cldecode(char *s)
{
char *p, *q;
int i;
if (s == NULL) {
return NULL;
}
for (p = s, q = s; *p; p++) {
if (*p == '\\') {
if (*(p + 1) == '\\') {
*q++ = *p++;
} else {
sscanf(p + 1, "%02x", &i);
*q++ = i;
p += 2;
}
} else {
*q++ = *p;
}
}
return s;
}
char *printable(char *s, int l) char *printable(char *s, int l)
{ {
int len; int len;

View File

@ -2088,6 +2088,8 @@ void Nopper(void);
void Altime(int); void Altime(int);
int enoughspace(unsigned int); int enoughspace(unsigned int);
unsigned int sequencer(void); unsigned int sequencer(void);
char *clencode(char *);
char *cldecode(char *);
char *printable(char *, int); char *printable(char *, int);
char *printablec(char); char *printablec(char);