X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fcitserver.c;h=bc7e493e09c1976d6356d1ebf7b9002145ce3ea8;hb=3a1a804554cb9764783a8021f95978e5a0bb58bf;hp=868f2daab498b6d80e50f4e13317a9bdbeae3cfd;hpb=ca4dbb6ab63f27ebff1e5aa9247c9c031d7fae8c;p=citadel.git diff --git a/citadel/citserver.c b/citadel/citserver.c index 868f2daab..bc7e493e0 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -32,6 +32,7 @@ #include #include +#include #include #include /* #include */ @@ -452,6 +453,8 @@ void cmd_mesg(char *mname) char buf[256]; char buf2[256]; char *dirs[2]; + DIR *dp; + struct dirent *d; extract_token(buf, mname, 0, '|', sizeof buf); @@ -465,15 +468,39 @@ void cmd_mesg(char *mname) DATA_DIR"/" #endif "help"); - snprintf(buf2, sizeof buf2, "%s.%d.%d", buf, CC->cs_clientdev, CC->cs_clienttyp); - mesg_locate(targ, sizeof targ, buf2, 2, (const char **)dirs); - if (strlen(targ) == 0) { - snprintf(buf2, sizeof buf2, "%s.%d", buf, CC->cs_clientdev); + snprintf(buf2, sizeof buf2, "%s.%d.%d", + buf, CC->cs_clientdev, CC->cs_clienttyp); + + /* If the client requested "?" then produce a listing */ + if (!strcmp(buf, "?")) { + cprintf("%d %s\n",LISTING_FOLLOWS,buf); + dp = opendir(dirs[1]); + if (dp != NULL) { + while (d = readdir(dp), d != NULL) { + if (d->d_name[0] != '.') { + cprintf(" %s\n", d->d_name); + } + } + closedir(dp); + } + cprintf("000\n"); + } + + /* Otherwise, look for the requested file by name. */ + else { mesg_locate(targ, sizeof targ, buf2, 2, (const char **)dirs); if (strlen(targ) == 0) { - mesg_locate(targ, sizeof targ, buf, 2, (const char **)dirs); - } + snprintf(buf2, sizeof buf2, "%s.%d", + buf, CC->cs_clientdev); + mesg_locate(targ, sizeof targ, buf2, 2, + (const char **)dirs); + if (strlen(targ) == 0) { + mesg_locate(targ, sizeof targ, buf, 2, + (const char **)dirs); + } + } } + free(dirs[0]); free(dirs[1]);