]> andersk Git - moira.git/blob - update/xfer_002.c
added copyright message
[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  lint
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 <strings.h>
20 #include <sms.h>
21 #include "kludge.h"
22
23 extern CONNECTION conn;
24 char buf[BUFSIZ];
25
26 extern int code, errno;
27
28 extern int have_authorization, have_file, done;
29
30 /*
31  *
32  * syntax:
33  * >>> (STRING)"xfer_002" filesize checksum pathname
34  * <<< (int)0
35  * >>> (STRING)data
36  * <<< (int)code
37  * >>> (STRING)data
38  * <<< (int)code
39  * ...
40  * >>> (STRING)data     (last data block)
41  * <<< (int)code        (from read, write, checksum verify)
42  *
43  * function:
44  *      perform initial preparations and receive file as
45  * a single string, storing it into <pathname>.sms_update.
46  *
47  * still to be done: file locking; perform transfers in pieces instead
48  * of all at once; use checksums
49  */
50
51 int
52 xfer_002(str)
53     char *str;
54 {
55     int file_size;
56     int checksum;
57     char *pathname;
58     
59     str += 8;
60     while (*str == ' ')
61         str++;
62     if (!*str) {
63     failure:
64         reject_call(SMS_ARGS);
65         return;
66     }
67     file_size = atoi(str);
68     while (isdigit(*str))
69         str++;
70     while (*str == ' ')
71         str++;
72     checksum = atoi(str);
73     while (isdigit(*str))
74         str++;
75     while (*str == ' ')
76         str++;
77     if (*str != '/')
78         goto failure;
79     pathname = str;
80     if (!have_authorization) {
81         reject_call(SMS_PERM);
82         return;
83     }
84     if (done)                   /* re-initialize data */
85         initialize();
86     code = send_ok();
87     if (code)
88         lose("sending ok for file xfer (2)");
89     code = get_file(pathname, file_size, checksum);
90     if (!code) {
91         char buf[BUFSIZ];
92         have_file = 1;
93         strcpy(buf, "transferred file ");
94         strcat(buf, pathname);
95         sms_log_info(buf);
96     }
97     return;
98 }
This page took 0.055623 seconds and 5 git commands to generate.