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