]> andersk Git - moira.git/blob - update/xfer_002.c
eliminate use of the `register' keyword: let the compiler decide
[moira.git] / update / xfer_002.c
1 /*
2  *      $Source$
3  *      $Header$
4  */
5 /*  (c) Copyright 1988 by the Massachusetts Institute of Technology. */
6 /*  For copying and distribution information, please see the file */
7 /*  <mit-copyright.h>. */
8
9 #ifndef lint
10 static char *rcsid_xfer_002_c = "$Header$";
11 #endif
12
13 #include <mit-copyright.h>
14 #include <stdio.h>
15 #include <gdb.h>
16 #include <ctype.h>
17 #include <sys/param.h>
18 #include <sys/file.h>
19 #include <string.h>
20 #include <moira.h>
21
22 extern CONNECTION conn;
23 extern char buf[BUFSIZ];
24
25 extern int code, errno;
26
27 extern int have_authorization, have_file, done;
28
29 /*
30  *
31  * syntax:
32  * >>> (STRING)"xfer_002" filesize checksum pathname
33  * <<< (int)0
34  * >>> (STRING)data
35  * <<< (int)code
36  * >>> (STRING)data
37  * <<< (int)code
38  * ...
39  * >>> (STRING)data     (last data block)
40  * <<< (int)code        (from read, write, checksum verify)
41  *
42  * function:
43  *      perform initial preparations and receive file as
44  * a single string, storing it into <pathname>.moira_update.
45  *
46  * still to be done: file locking; perform transfers in pieces instead
47  * of all at once; use checksums
48  */
49
50 int xfer_002(char *str)
51 {
52   int file_size;
53   int checksum;
54   char *pathname;
55
56   str += 8;
57   while (*str == ' ')
58     str++;
59   if (!*str)
60     {
61     failure:
62       reject_call(MR_ARGS);
63       return 0;
64     }
65   file_size = atoi(str);
66   while (isdigit(*str))
67     str++;
68   while (*str == ' ')
69     str++;
70   checksum = atoi(str);
71   while (isdigit(*str))
72     str++;
73   while (*str == ' ')
74     str++;
75   if (*str != '/')
76     goto failure;
77   pathname = str;
78   if (!have_authorization)
79     {
80       reject_call(MR_PERM);
81       return 0;
82     }
83   if (done)                     /* re-initialize data */
84     initialize();
85   code = send_ok();
86   if (code)
87     lose("sending ok for file xfer (2)");
88   code = get_file(pathname, file_size, checksum, 0700, 0);
89   if (!code)
90     {
91       char buf[BUFSIZ];
92       have_file = 1;
93       strcpy(buf, "transferred file ");
94       strcat(buf, pathname);
95       mr_log_info(buf);
96     }
97   return 0;
98 }
This page took 0.447659 seconds and 5 git commands to generate.