]>
Commit | Line | Data |
---|---|---|
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 | RCSID("$Header$"); | |
18 | ||
19 | /* | |
20 | * | |
21 | * syntax: | |
22 | * >>> (STRING)"xfer_002" filesize checksum pathname | |
23 | * <<< (int)0 | |
24 | * >>> (STRING)data | |
25 | * <<< (int)code | |
26 | * >>> (STRING)data | |
27 | * <<< (int)code | |
28 | * ... | |
29 | * >>> (STRING)data (last data block) | |
30 | * <<< (int)code (from read, write, checksum verify) | |
31 | * | |
32 | * function: | |
33 | * perform initial preparations and receive file as | |
34 | * a single string, storing it into <pathname>.moira_update. | |
35 | * | |
36 | * still to be done: file locking; perform transfers in pieces instead | |
37 | * of all at once; use checksums | |
38 | */ | |
39 | ||
40 | void xfer_002(int conn, char *str) | |
41 | { | |
42 | int file_size, checksum, code; | |
43 | char *pathname, *p; | |
44 | ||
45 | str += 8; | |
46 | while (*str == ' ') | |
47 | str++; | |
48 | if (!*str) | |
49 | { | |
50 | failure: | |
51 | send_int(conn, MR_ARGS); | |
52 | return; | |
53 | } | |
54 | ||
55 | file_size = strtol(str, &p, 10); | |
56 | if (p == str) | |
57 | { | |
58 | send_int(conn, MR_ARGS); | |
59 | return; | |
60 | } | |
61 | else | |
62 | str = p; | |
63 | while (*str == ' ') | |
64 | str++; | |
65 | ||
66 | checksum = strtol(str, &p, 10); | |
67 | if (p == str) | |
68 | { | |
69 | send_int(conn, MR_ARGS); | |
70 | return; | |
71 | } | |
72 | else | |
73 | str = p; | |
74 | while (*str == ' ') | |
75 | str++; | |
76 | ||
77 | if (*str != '/') | |
78 | goto failure; | |
79 | pathname = str; | |
80 | ||
81 | if (!have_authorization) | |
82 | { | |
83 | send_int(conn, MR_PERM); | |
84 | return; | |
85 | } | |
86 | ||
87 | send_ok(conn); | |
88 | code = get_file(conn, pathname, file_size, checksum, 0700, 0); | |
89 | if (!code) | |
90 | com_err(whoami, 0, "Transferred file %s", pathname); | |
91 | ||
92 | return; | |
93 | } |