]>
Commit | Line | Data |
---|---|---|
7ac48069 | 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>. | |
de56407f | 6 | */ |
de56407f | 7 | |
546bc43b | 8 | #include <mit-copyright.h> |
7ac48069 | 9 | #include <moira.h> |
10 | #include "update_server.h" | |
11 | ||
de56407f | 12 | #include <ctype.h> |
7ac48069 | 13 | #include <stdio.h> |
14 | #include <stdlib.h> | |
7b48c9f9 | 15 | #include <string.h> |
7ac48069 | 16 | |
17 | #include <gdb.h> | |
18 | ||
19 | RCSID("$Header$"); | |
de56407f | 20 | |
21 | extern CONNECTION conn; | |
7da203a3 | 22 | extern char buf[BUFSIZ]; |
de56407f | 23 | |
7ac48069 | 24 | extern int code; |
de56407f | 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 | |
2ad0a777 | 43 | * a single string, storing it into <pathname>.moira_update. |
de56407f | 44 | * |
45 | * still to be done: file locking; perform transfers in pieces instead | |
46 | * of all at once; use checksums | |
47 | */ | |
48 | ||
5eaef520 | 49 | int xfer_002(char *str) |
de56407f | 50 | { |
5eaef520 | 51 | int file_size; |
52 | int checksum; | |
53 | char *pathname; | |
54 | ||
55 | str += 8; | |
56 | while (*str == ' ') | |
57 | str++; | |
58 | if (!*str) | |
59 | { | |
de56407f | 60 | failure: |
5eaef520 | 61 | reject_call(MR_ARGS); |
62 | return 0; | |
de56407f | 63 | } |
5eaef520 | 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; | |
de56407f | 81 | } |
5eaef520 | 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); | |
de56407f | 95 | } |
5eaef520 | 96 | return 0; |
de56407f | 97 | } |