~ubuntu-branches/ubuntu/edgy/lynx/edgy

« back to all changes in this revision

Viewing changes to src/LYUpload.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-16 12:14:10 UTC
  • Revision ID: james.westby@ubuntu.com-20040916121410-cz1gu92c4nqfeyrg
Tags: upstream-2.8.5
ImportĀ upstreamĀ versionĀ 2.8.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
**  Routines to upload files to the local filesystem.
 
3
**  Created by: Rick Mallett, Carleton University
 
4
**  Report problems to rmallett@ccs.carleton.ca
 
5
**  Modified 15-Dec-95 George Lindholm (lindholm@ucs.ubc.ca):
 
6
**      Reread the upload menu page every time, in case the "upload" directory
 
7
**        has changed (make the current directory that for the upload process).
 
8
**      Prompt for the upload file name if there is no "%s" in the command
 
9
**        string.  Most protocols allow the user to specify the file name
 
10
**        from the client side.  Xmodem appears to be the only that can't
 
11
**        figure out the filename from the transfer data so it needs the
 
12
**        information from lynx (or an upload script which prompts for it).
 
13
**        On the other hand, zmodem aborts when you give it a filename on
 
14
**        the command line (great way of bypassing the nodotfile code :=( ).
 
15
*/
 
16
 
 
17
#include <HTUtils.h>
 
18
#include <HTFile.h>
 
19
#include <HTParse.h>
 
20
#include <HTAlert.h>
 
21
#include <LYCurses.h>
 
22
#include <LYUtils.h>
 
23
#include <LYGlobalDefs.h>
 
24
#include <LYStrings.h>
 
25
#include <LYClean.h>
 
26
#include <LYGetFile.h>
 
27
#include <LYUpload.h>
 
28
#include <LYLocal.h>
 
29
 
 
30
#include <LYexit.h>
 
31
#include <LYLeaks.h>
 
32
 
 
33
#define SUBDIR_COMMAND "cd %s ; "
 
34
 
 
35
/*
 
36
 *  LYUpload uploads a file to a given location using a
 
37
 *  specified upload method.  It parses an incoming link
 
38
 *  that looks like:
 
39
 *      LYNXDIRED://UPLOAD=<#>/TO=<STRING>
 
40
 */
 
41
PUBLIC int LYUpload ARGS1(
 
42
        char *,         line)
 
43
{
 
44
    char *method, *directory;
 
45
    int method_number;
 
46
    int count;
 
47
    char *the_upload = 0;
 
48
    char tmpbuf[LY_MAXPATH];
 
49
    char *filename = NULL;
 
50
    lynx_list_item_type *upload_command = 0;
 
51
    char *the_command = 0;
 
52
 
 
53
    /*
 
54
     *  Use configured upload commands.
 
55
     */
 
56
    if((directory = strstr(line, "TO=")) == NULL)
 
57
        goto failed;
 
58
    *(directory - 1) = '\0';
 
59
    /* go past "Directory=" */
 
60
    directory += 3;
 
61
 
 
62
    if((method = strstr(line, "UPLOAD=")) == NULL)
 
63
        goto failed;
 
64
    /*
 
65
     *  Go past "Method=".
 
66
     */
 
67
    method += 7;
 
68
    method_number = atoi(method);
 
69
 
 
70
    for (count = 0, upload_command = uploaders; count < method_number;
 
71
        count++, upload_command = upload_command->next)
 
72
      ; /* null body */
 
73
 
 
74
    /*
 
75
     *  Parsed out the Method and the Location?
 
76
     */
 
77
    if (upload_command->command == NULL) {
 
78
        HTAlert(gettext("ERROR! - upload command is misconfigured"));
 
79
        goto failed;
 
80
    }
 
81
 
 
82
    /*
 
83
     *  Care about the local name?
 
84
     */
 
85
    if (HTCountCommandArgs (upload_command->command)) {
 
86
        /*
 
87
         *  Commands have the form "command %s [etc]"
 
88
         *  where %s is the filename.
 
89
         */
 
90
        _statusline(FILENAME_PROMPT);
 
91
retry:
 
92
        *tmpbuf = '\0';
 
93
        if (LYgetstr(tmpbuf, VISIBLE, sizeof(tmpbuf), NORECALL) < 0)
 
94
            goto cancelled;
 
95
 
 
96
        if (*tmpbuf == '\0')
 
97
            goto cancelled;
 
98
 
 
99
        if (strstr(tmpbuf, "../") != NULL) {
 
100
            HTAlert(gettext("Illegal redirection \"../\" found! Request ignored."));
 
101
            goto cancelled;
 
102
        } else if (strchr(tmpbuf, '/') != NULL) {
 
103
            HTAlert(gettext("Illegal character \"/\" found! Request ignored."));
 
104
            goto cancelled;
 
105
        } else if (tmpbuf[0] == '~') {
 
106
            HTAlert(gettext("Illegal redirection using \"~\" found! Request ignored."));
 
107
            goto cancelled;
 
108
        }
 
109
        HTSprintf0(&filename, "%s/%s", directory, tmpbuf);
 
110
 
 
111
#ifdef HAVE_POPEN
 
112
        if (LYIsPipeCommand(filename)) {
 
113
            HTAlert(CANNOT_WRITE_TO_FILE);
 
114
            _statusline(NEW_FILENAME_PROMPT);
 
115
            goto retry;
 
116
        }
 
117
#endif
 
118
        switch (LYValidateOutput(filename)) {
 
119
        case 'Y':
 
120
            break;
 
121
        case 'N':
 
122
            goto retry;
 
123
        default:
 
124
            goto cancelled;
 
125
        }
 
126
 
 
127
        /*
 
128
         *  See if we can write to it.
 
129
         */
 
130
        CTRACE((tfp, "LYUpload: filename is %s", filename));
 
131
 
 
132
        if (! LYCanWriteFile(filename)) {
 
133
            goto retry;
 
134
        }
 
135
 
 
136
        HTAddParam(&the_upload, upload_command->command, 1, filename);
 
137
        HTEndParam(&the_upload, upload_command->command, 1);
 
138
    } else {                    /* No substitution, no changes */
 
139
        StrAllocCopy(the_upload, upload_command->command);
 
140
    }
 
141
 
 
142
    HTAddParam(&the_command, SUBDIR_COMMAND, 1, directory);
 
143
    HTEndParam(&the_command, SUBDIR_COMMAND, 1);
 
144
    StrAllocCat(the_command, the_upload);
 
145
 
 
146
    CTRACE((tfp, "command: %s\n", the_command));
 
147
 
 
148
    stop_curses();
 
149
    LYSystem(the_command);
 
150
    start_curses();
 
151
 
 
152
    FREE(the_command);
 
153
    FREE(the_upload);
 
154
#if defined(MULTI_USER_UNIX)
 
155
    if (filename != 0)
 
156
        chmod(filename, HIDE_CHMOD);
 
157
#endif /* UNIX */
 
158
    FREE(filename);
 
159
 
 
160
    return 1;
 
161
 
 
162
failed:
 
163
    HTAlert(gettext("Unable to upload file."));
 
164
    return 0;
 
165
 
 
166
cancelled:
 
167
    HTInfoMsg(CANCELLING);
 
168
    return 0;
 
169
}
 
170
 
 
171
/*
 
172
 *  LYUpload_options writes out the current upload choices to a
 
173
 *  file so that the user can select printers in the same way that
 
174
 *  they select all other links.  Upload links look like:
 
175
 *      LYNXDIRED://UPLOAD=<#>/TO=<STRING>
 
176
 */
 
177
PUBLIC int LYUpload_options ARGS2(
 
178
        char **,        newfile,
 
179
        char *,         directory)
 
180
{
 
181
    static char tempfile[LY_MAXPATH];
 
182
    FILE *fp0;
 
183
    lynx_list_item_type *cur_upload;
 
184
    int count;
 
185
    static char curloc[LY_MAXPATH];
 
186
    char *cp;
 
187
 
 
188
    if ((fp0 = InternalPageFP(tempfile, TRUE)) == 0)
 
189
        return(-1);
 
190
 
 
191
#ifdef VMS
 
192
    strcpy(curloc, "/sys$login");
 
193
#else
 
194
    cp = HTfullURL_toFile(directory);
 
195
    strcpy(curloc,cp);
 
196
    LYTrimPathSep(curloc);
 
197
    FREE(cp);
 
198
#endif /* VMS */
 
199
 
 
200
    LYLocalFileToURL(newfile, tempfile);
 
201
    LYRegisterUIPage(*newfile, UIP_UPLOAD_OPTIONS);
 
202
 
 
203
    BeginInternalPage(fp0, UPLOAD_OPTIONS_TITLE, UPLOAD_OPTIONS_HELP);
 
204
 
 
205
    fprintf(fp0, "<pre>\n");
 
206
    fprintf(fp0, "   <em>%s</em> %s\n", gettext("Upload To:"), curloc);
 
207
    fprintf(fp0, "\n%s\n", gettext("Upload options:"));
 
208
 
 
209
    if (uploaders != NULL) {
 
210
        for (count = 0, cur_upload = uploaders;
 
211
             cur_upload != NULL;
 
212
             cur_upload = cur_upload->next, count++) {
 
213
            fprintf(fp0, "   <a href=\"LYNXDIRED://UPLOAD=%d/TO=%s\">",
 
214
                         count, curloc);
 
215
            fprintf(fp0, (cur_upload->name ?
 
216
                          cur_upload->name : gettext("No Name Given")));
 
217
            fprintf(fp0, "</a>\n");
 
218
        }
 
219
    } else {
 
220
        fprintf(fp0, "   &lt;NONE&gt;\n");
 
221
    }
 
222
 
 
223
    fprintf(fp0, "</pre>\n");
 
224
    EndInternalPage(fp0);
 
225
    LYCloseTempFP(fp0);
 
226
 
 
227
    LYforce_no_cache = TRUE;
 
228
 
 
229
    return(0);
 
230
}