bug-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] move socket-related client parts into separate file


From: Alexey Mahotkin
Subject: Re: [PATCH] move socket-related client parts into separate file
Date: Wed, 07 May 2003 21:41:19 +0400
User-agent: Gnus/5.090006 (Oort Gnus v0.06) XEmacs/21.4 (Common Lisp, i386-debian-linux)

>>>>> "DRP" == Derek Robert Price <derek@ximbiot.com> writes:

 DRP> I just committed your rsh-client patch as well.  Does this mean you
 DRP> want me to wait before committing your other six patches?

Go ahead with three from_/to_buffer patches.  First one will give several
rejects in start_rsh_server() in server.c.  Ignore them.

Then apply log-buffer patch:

2003-04-24  Alexey Mahotkin <alexm@hsys.msk.ru>

Move logging buffer code to separate log-buffer.[ch]


 src/Makefile.am  |    1 
 src/client.c     |  198 -------------------------------------------------
 src/log-buffer.c |  222 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/log-buffer.h |   19 ++++
 4 files changed, 244 insertions(+), 196 deletions(-)

--- ccvs/src/client.c~log-buffer        Wed May  7 21:28:08 2003
+++ ccvs-alexm/src/client.c     Wed May  7 21:28:42 2003
@@ -21,6 +21,7 @@
 #include "getline.h"
 #include "edit.h"
 #include "buffer.h"
+#include "log-buffer.h"
 
 #ifdef CLIENT_SUPPORT
 
@@ -413,161 +414,6 @@ static struct buffer *global_to_server;
 static struct buffer *global_from_server;
 
 
-/* We want to be able to log data sent between us and the server.  We
-   do it using log buffers.  Each log buffer has another buffer which
-   handles the actual I/O, and a file to log information to.
-
-   This structure is the closure field of a log buffer.  */
-
-struct log_buffer
-{
-    /* The underlying buffer.  */
-    struct buffer *buf;
-    /* The file to log information to.  */
-    FILE *log;
-};
-
-static struct buffer *log_buffer_initialize
-  PROTO((struct buffer *, FILE *, int, void (*) (struct buffer *)));
-static int log_buffer_input PROTO((void *, char *, int, int, int *));
-static int log_buffer_output PROTO((void *, const char *, int, int *));
-static int log_buffer_flush PROTO((void *));
-static int log_buffer_block PROTO((void *, int));
-static int log_buffer_shutdown PROTO((struct buffer *));
-
-/* Create a log buffer.  */
-
-static struct buffer *
-log_buffer_initialize (buf, fp, input, memory)
-     struct buffer *buf;
-     FILE *fp;
-     int input;
-     void (*memory) PROTO((struct buffer *));
-{
-    struct log_buffer *n;
-
-    n = (struct log_buffer *) xmalloc (sizeof *n);
-    n->buf = buf;
-    n->log = fp;
-    return buf_initialize (input ? log_buffer_input : NULL,
-                          input ? NULL : log_buffer_output,
-                          input ? NULL : log_buffer_flush,
-                          log_buffer_block,
-                          log_buffer_shutdown,
-                          memory,
-                          n);
-}
-
-/* The input function for a log buffer.  */
-
-static int
-log_buffer_input (closure, data, need, size, got)
-     void *closure;
-     char *data;
-     int need;
-     int size;
-     int *got;
-{
-    struct log_buffer *lb = (struct log_buffer *) closure;
-    int status;
-    size_t n_to_write;
-
-    if (lb->buf->input == NULL)
-       abort ();
-
-    status = (*lb->buf->input) (lb->buf->closure, data, need, size, got);
-    if (status != 0)
-       return status;
-
-    if (*got > 0)
-    {
-       n_to_write = *got;
-       if (fwrite (data, 1, n_to_write, lb->log) != n_to_write)
-           error (0, errno, "writing to log file");
-    }
-
-    return 0;
-}
-
-/* The output function for a log buffer.  */
-
-static int
-log_buffer_output (closure, data, have, wrote)
-     void *closure;
-     const char *data;
-     int have;
-     int *wrote;
-{
-    struct log_buffer *lb = (struct log_buffer *) closure;
-    int status;
-    size_t n_to_write;
-
-    if (lb->buf->output == NULL)
-       abort ();
-
-    status = (*lb->buf->output) (lb->buf->closure, data, have, wrote);
-    if (status != 0)
-       return status;
-
-    if (*wrote > 0)
-    {
-       n_to_write = *wrote;
-       if (fwrite (data, 1, n_to_write, lb->log) != n_to_write)
-           error (0, errno, "writing to log file");
-    }
-
-    return 0;
-}
-
-/* The flush function for a log buffer.  */
-
-static int
-log_buffer_flush (closure)
-     void *closure;
-{
-    struct log_buffer *lb = (struct log_buffer *) closure;
-
-    if (lb->buf->flush == NULL)
-       abort ();
-
-    /* We don't really have to flush the log file here, but doing it
-       will let tail -f on the log file show what is sent to the
-       network as it is sent.  */
-    if (fflush (lb->log) != 0)
-        error (0, errno, "flushing log file");
-
-    return (*lb->buf->flush) (lb->buf->closure);
-}
-
-/* The block function for a log buffer.  */
-
-static int
-log_buffer_block (closure, block)
-     void *closure;
-     int block;
-{
-    struct log_buffer *lb = (struct log_buffer *) closure;
-
-    if (block)
-       return set_block (lb->buf);
-    else
-       return set_nonblock (lb->buf);
-}
-
-/* The shutdown function for a log buffer.  */
-
-static int
-log_buffer_shutdown (buf)
-     struct buffer *buf;
-{
-    struct log_buffer *lb = (struct log_buffer *) buf->closure;
-    int retval;
-
-    retval = buf_shutdown (lb->buf);
-    if (fclose (lb->log) < 0)
-       error (0, errno, "closing log file");
-    return retval;
-}
 
 /*
  * Read a line from the server.  Result does not include the terminating \n.
@@ -3972,7 +3818,6 @@ void
 start_server ()
 {
     int rootless;
-    char *log = getenv ("CVS_CLIENT_LOG");
 
     /* Clear our static variables for this invocation. */
     if (toplevel_repos != NULL)
@@ -4053,46 +3898,7 @@ start_server ()
     /* "Hi, I'm Darlene and I'll be your server tonight..." */
     server_started = 1;
 
-    /* Set up logfiles, if any.
-     *
-     * We do this _after_ authentication on purpose.  Wouldn't really like to
-     * worry about logging passwords...
-     */
-    if (log)
-    {
-       int len = strlen (log);
-       char *buf = xmalloc (len + 5);
-       char *p;
-       FILE *fp;
-
-       strcpy (buf, log);
-       p = buf + len;
-
-       /* Open logfiles in binary mode so that they reflect
-          exactly what was transmitted and received (that is
-          more important than that they be maximally
-          convenient to view).  */
-       /* Note that if we create several connections in a single CVS client
-          (currently used by update.c), then the last set of logfiles will
-          overwrite the others.  There is currently no way around this.  */
-       strcpy (p, ".in");
-       fp = open_file (buf, "wb");
-        if (fp == NULL)
-           error (0, errno, "opening to-server logfile %s", buf);
-       else
-           global_to_server = log_buffer_initialize (global_to_server, fp, 0,
-                                                     (BUFMEMERRPROC) NULL);
-
-       strcpy (p, ".out");
-       fp = open_file (buf, "wb");
-        if (fp == NULL)
-           error (0, errno, "opening from-server logfile %s", buf);
-       else
-           global_from_server = log_buffer_initialize (global_from_server, fp, 
1,
-                                                       (BUFMEMERRPROC) NULL);
-
-       free (buf);
-    }
+    setup_logfiles(&global_to_server, &global_from_server);
 
     /* Clear static variables.  */
     if (toplevel_repos != NULL)
--- /dev/null   Wed Jan  1 02:48:46 2003
+++ ccvs-alexm/src/log-buffer.c Wed May  7 21:28:08 2003
@@ -0,0 +1,222 @@
+/* CVS client logging buffer.
+
+   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 2, 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.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include "cvs.h"
+#include "buffer.h"
+
+/* We want to be able to log data sent between us and the server.  We
+   do it using log buffers.  Each log buffer has another buffer which
+   handles the actual I/O, and a file to log information to.
+
+   This structure is the closure field of a log buffer.  */
+
+struct log_buffer
+{
+    /* The underlying buffer.  */
+    struct buffer *buf;
+    /* The file to log information to.  */
+    FILE *log;
+};
+
+static int log_buffer_input PROTO((void *, char *, int, int, int *));
+static int log_buffer_output PROTO((void *, const char *, int, int *));
+static int log_buffer_flush PROTO((void *));
+static int log_buffer_block PROTO((void *, int));
+static int log_buffer_shutdown PROTO((struct buffer *));
+
+/* Create a log buffer.  */
+
+static struct buffer *
+log_buffer_initialize (buf, fp, input, memory)
+     struct buffer *buf;
+     FILE *fp;
+     int input;
+     void (*memory) PROTO((struct buffer *));
+{
+    struct log_buffer *n;
+
+    n = (struct log_buffer *) xmalloc (sizeof *n);
+    n->buf = buf;
+    n->log = fp;
+    return buf_initialize (input ? log_buffer_input : NULL,
+                          input ? NULL : log_buffer_output,
+                          input ? NULL : log_buffer_flush,
+                          log_buffer_block,
+                          log_buffer_shutdown,
+                          memory,
+                          n);
+}
+
+/* The input function for a log buffer.  */
+
+static int
+log_buffer_input (closure, data, need, size, got)
+     void *closure;
+     char *data;
+     int need;
+     int size;
+     int *got;
+{
+    struct log_buffer *lb = (struct log_buffer *) closure;
+    int status;
+    size_t n_to_write;
+
+    if (lb->buf->input == NULL)
+       abort ();
+
+    status = (*lb->buf->input) (lb->buf->closure, data, need, size, got);
+    if (status != 0)
+       return status;
+
+    if (*got > 0)
+    {
+       n_to_write = *got;
+       if (fwrite (data, 1, n_to_write, lb->log) != n_to_write)
+           error (0, errno, "writing to log file");
+    }
+
+    return 0;
+}
+
+/* The output function for a log buffer.  */
+
+static int
+log_buffer_output (closure, data, have, wrote)
+     void *closure;
+     const char *data;
+     int have;
+     int *wrote;
+{
+    struct log_buffer *lb = (struct log_buffer *) closure;
+    int status;
+    size_t n_to_write;
+
+    if (lb->buf->output == NULL)
+       abort ();
+
+    status = (*lb->buf->output) (lb->buf->closure, data, have, wrote);
+    if (status != 0)
+       return status;
+
+    if (*wrote > 0)
+    {
+       n_to_write = *wrote;
+       if (fwrite (data, 1, n_to_write, lb->log) != n_to_write)
+           error (0, errno, "writing to log file");
+    }
+
+    return 0;
+}
+
+/* The flush function for a log buffer.  */
+
+static int
+log_buffer_flush (closure)
+     void *closure;
+{
+    struct log_buffer *lb = (struct log_buffer *) closure;
+
+    if (lb->buf->flush == NULL)
+       abort ();
+
+    /* We don't really have to flush the log file here, but doing it
+       will let tail -f on the log file show what is sent to the
+       network as it is sent.  */
+    if (fflush (lb->log) != 0)
+        error (0, errno, "flushing log file");
+
+    return (*lb->buf->flush) (lb->buf->closure);
+}
+
+/* The block function for a log buffer.  */
+
+static int
+log_buffer_block (closure, block)
+     void *closure;
+     int block;
+{
+    struct log_buffer *lb = (struct log_buffer *) closure;
+
+    if (block)
+       return set_block (lb->buf);
+    else
+       return set_nonblock (lb->buf);
+}
+
+/* The shutdown function for a log buffer.  */
+
+static int
+log_buffer_shutdown (buf)
+     struct buffer *buf;
+{
+    struct log_buffer *lb = (struct log_buffer *) buf->closure;
+    int retval;
+
+    retval = buf_shutdown (lb->buf);
+    if (fclose (lb->log) < 0)
+       error (0, errno, "closing log file");
+    return retval;
+}
+
+
+void
+setup_logfiles (to_server_p, from_server_p)
+     struct buffer** to_server_p;
+     struct buffer** from_server_p;
+{
+  char *log = getenv ("CVS_CLIENT_LOG");
+
+  /* Set up logfiles, if any.
+   *
+   * We do this _after_ authentication on purpose.  Wouldn't really like to
+   * worry about logging passwords...
+   */
+  if (log)
+    {
+      int len = strlen (log);
+      char *buf = xmalloc (len + 5);
+      char *p;
+      FILE *fp;
+
+      strcpy (buf, log);
+      p = buf + len;
+
+      /* Open logfiles in binary mode so that they reflect
+        exactly what was transmitted and received (that is
+        more important than that they be maximally
+        convenient to view).  */
+      /* Note that if we create several connections in a single CVS client
+        (currently used by update.c), then the last set of logfiles will
+        overwrite the others.  There is currently no way around this.  */
+      strcpy (p, ".in");
+      fp = open_file (buf, "wb");
+      if (fp == NULL)
+       error (0, errno, "opening to-server logfile %s", buf);
+      else
+       *to_server_p = log_buffer_initialize (*to_server_p, fp, 0,
+                                             (BUFMEMERRPROC) NULL);
+
+      strcpy (p, ".out");
+      fp = open_file (buf, "wb");
+      if (fp == NULL)
+       error (0, errno, "opening from-server logfile %s", buf);
+      else
+       *from_server_p = log_buffer_initialize (*from_server_p, fp, 1,
+                                               (BUFMEMERRPROC) NULL);
+
+      free (buf);
+    }
+}
--- /dev/null   Wed Jan  1 02:48:46 2003
+++ ccvs-alexm/src/log-buffer.h Wed May  7 21:28:08 2003
@@ -0,0 +1,19 @@
+/* CVS client logging buffer.
+
+   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 2, 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.  */
+
+
+#ifndef LOG_BUFFER_H__
+#define LOG_BUFFER_H__
+
+void setup_logfiles PROTO ((struct buffer** to_server_p, struct buffer** 
from_server_p));
+
+#endif LOG_BUFFER_H__
--- ccvs/src/Makefile.am~log-buffer     Wed May  7 21:28:08 2003
+++ ccvs-alexm/src/Makefile.am  Wed May  7 21:28:08 2003
@@ -48,6 +48,7 @@ cvs_SOURCES = \
        import.c \
        lock.c \
        log.c \
+       log-buffer.c log-buffer.h \
        login.c \
        logmsg.c \
        main.c \

_

--alexm




reply via email to

[Prev in Thread] Current Thread [Next in Thread]