Removed references to Subversion in the code
[citadel.git] / citadel / modules / bio / serv_bio.c
index 276e7d9811baebb88c87c05b36891335f0b257dd..665873ab50d612f5e81fef8ec975e3c35a07f71a 100644 (file)
@@ -1,50 +1,31 @@
 /*
- * $Id$
- *
  * This module implementsserver commands related to the display and
  * manipulation of user "bio" files.
  *
+ *
+ * Copyright (c) 1987-2009 by the citadel.org team
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <pwd.h>
-#include <errno.h>
-#include <sys/types.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
+#include "ctdl_module.h"
 
-#include <sys/wait.h>
-#include <string.h>
-#include <limits.h>
-#include <libcitadel.h>
-#include "citadel.h"
-#include "server.h"
-#include "citserver.h"
-#include "support.h"
-#include "config.h"
-#include "control.h"
-#include "room_ops.h"
-#include "user_ops.h"
-#include "policy.h"
-#include "database.h"
-#include "msgbase.h"
-#include "citadel_dirs.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
 
-#include "ctdl_module.h"
 
 /*
  * enter user bio
@@ -68,7 +49,7 @@ void cmd_ebio(char *cmdbuf) {
                return;
        }
        cprintf("%d  \n",SEND_LISTING);
-       while(client_getln(buf, sizeof buf), strcmp(buf,"000")) {
+       while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
                if (ftell(fp) < config.c_maxmsglen) {
                        fprintf(fp,"%s\n",buf);
                }
@@ -86,7 +67,7 @@ void cmd_rbio(char *cmdbuf)
        FILE *fp;
 
        extract_token(buf, cmdbuf, 0, '|', sizeof buf);
-       if (getuser(&ruser, buf) != 0) {
+       if (CtdlGetUser(&ruser, buf) != 0) {
                cprintf("%d No such user.\n",ERROR + NO_SUCH_USER);
                return;
        }
@@ -108,27 +89,54 @@ void cmd_rbio(char *cmdbuf)
 /*
  * list of users who have entered bios
  */
-void cmd_lbio(char *cmdbuf) {
-       char buf[256];
-       FILE *ls;
+void cmd_lbio(char *cmdbuf)
+{
+       DIR *filedir = NULL;
+       struct dirent *filedir_entry;
+       struct dirent *d;
+       int dont_resolve_uids;
+       size_t d_namelen;
        struct ctdluser usbuf;
-       char listbios[256];
 
-       snprintf(listbios, sizeof(listbios),"cd %s; ls",ctdl_bio_dir);
-       ls = popen(listbios, "r");
-       if (ls == NULL) {
+       d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 2);
+       if (d == NULL) {
                cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
                return;
        }
 
-       cprintf("%d\n", LISTING_FOLLOWS);
-       while (fgets(buf, sizeof buf, ls)!=NULL)
-               if (getuserbynumber(&usbuf,atol(buf))==0)
+       filedir = opendir (ctdl_bio_dir);
+       if (filedir == NULL) {
+               free(d);
+               cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
+               return;
+       }
+       dont_resolve_uids = *cmdbuf == '1';
+        cprintf("%d\n", LISTING_FOLLOWS);
+       while ((readdir_r(filedir, d, &filedir_entry) == 0) &&
+              (filedir_entry != NULL))
+       {
+#ifdef _DIRENT_HAVE_D_NAMELEN
+               d_namelen = filedir_entry->d_namelen;
+#else
+               d_namelen = strlen(filedir_entry->d_name);
+#endif
+               if (((d_namelen == 1) && (filedir_entry->d_name[0] == '.')) || 
+                   ((d_namelen == 2) && (filedir_entry->d_name[0] == '.') && (filedir_entry->d_name[1] == '.')))
+                       continue;
+                   
+               if (dont_resolve_uids) {
+                       filedir_entry->d_name[d_namelen++] = '\n';
+                       filedir_entry->d_name[d_namelen] = '\0';
+                       client_write(filedir_entry->d_name, d_namelen);
+               }
+               else if (CtdlGetUserByNumber(&usbuf,atol(filedir_entry->d_name))==0)
                        cprintf("%s\n", usbuf.fullname);
-       pclose(ls);
+       }
+       free(d);
+       closedir(filedir);
        cprintf("000\n");
-}
 
+}
 
 
 
@@ -140,8 +148,8 @@ CTDL_MODULE_INIT(bio)
                CtdlRegisterProtoHook(cmd_rbio, "RBIO", "Read a user's bio");
                CtdlRegisterProtoHook(cmd_lbio, "LBIO", "List users with bios");
        }
-       /* return our Subversion id for the Log */
-        return "$Id$";
+       /* return our module name for the log */
+        return "bio";
 }