Commit 1a3f4c19 authored by Patrick Monnerat's avatar Patrick Monnerat
Browse files

mime: remove support "-" stdin pseudo-file name in curl_mime_filedata().

This feature is badly supported in Windows: as a replacement, a caller has
to use curl_mime_data_cb() with fread, fseek and possibly fclose
callbacks to process opened files.

The cli tool and documentation are updated accordingly.

The feature is however kept internally for form API compatibility, with
the known caveats it always had.

As a side effect, stdin size is not determined by the cli tool even if
possible and this results in a chunked transfer encoding. Test 173 is
updated accordingly.
parent 045b076a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -153,6 +153,9 @@ int main(void)
     * clean up in the end.
     */
    curl_easy_cleanup(curl);

    /* Free multipart message. */
    curl_mime_free(mime);
  }

  return (int)res;
+0 −1
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ contents.
\fIpart\fP is the part's to assign contents to.
\fIfilename\fP points to the nul-terminated file's path name. The pointer can
be NULL to detach previous part contents settings.
If \fIfilename\fP is "-", part contents data will be read from stdin.
Filename storage can be safely be reused after this call.

As a side effect, the part's remote file name is set to the base name of the
+4 −1
Original line number Diff line number Diff line
@@ -897,6 +897,9 @@ CURLcode Curl_getformdata(struct Curl_easy *data,
          clen = -1;

        if(post->flags & (HTTPPOST_FILENAME | HTTPPOST_READFILE)) {
          if(!strcmp(file->contents, "-"))
            result = Curl_mime_file(part, stdin, 0);
          else
            result = curl_mime_filedata(part, file->contents);
          if(!result && (post->flags & HTTPPOST_READFILE))
            result = curl_mime_filename(part, NULL);
+11 −4
Original line number Diff line number Diff line
@@ -634,8 +634,18 @@ static int mime_part_rewind(struct Curl_mimepart *part)
    targetstate = MIMESTATE_BODY;
  if(part->state.state > targetstate) {
    res = CURL_SEEKFUNC_CANTSEEK;
    if(part->seekfunc)
    if(part->seekfunc) {
      res = part->seekfunc(part->arg, part->origin, SEEK_SET);
      switch(res) {
      case CURL_SEEKFUNC_OK:
      case CURL_SEEKFUNC_FAIL:
      case CURL_SEEKFUNC_CANTSEEK:
        break;
      default:
        res = CURL_SEEKFUNC_FAIL;
        break;
      }
    }
  }

  if(res == CURL_SEEKFUNC_OK)
@@ -907,9 +917,6 @@ CURLcode curl_mime_filedata(struct Curl_mimepart *part, const char *filename)
  if(!part || !filename)
    return CURLE_BAD_FUNCTION_ARGUMENT;

  if(!strcmp(filename, "-"))
    return Curl_mime_file(part, stdin, 0);

  if(stat(filename, &sbuf) || access(filename, R_OK))
    result = CURLE_READ_ERROR;

+19 −4
Original line number Diff line number Diff line
@@ -347,6 +347,21 @@ static int get_param_part(struct OperationConfig *config, char **str,
  return sep & 0xFF;
}

/* Check if file is "-". If so, use a callback to read OUR stdin (to
 * workaround Windows DLL file handle caveat).
 * Else use curl_mime_filedata(). */
static CURLcode file_or_stdin(curl_mimepart *part, const char *file)
{
  CURLcode ret = CURLE_OK;

  if(strcmp(file, "-"))
    return curl_mime_filedata(part, file);

  return curl_mime_data_cb(part, -1, (curl_read_callback) fread,
                           (curl_seek_callback) fseek, NULL, stdin);
}


/***************************************************************************
 *
 * formparse()
@@ -547,9 +562,9 @@ int formparse(struct OperationConfig *config,
        }

        /* Setup file in part. */
        res = curl_mime_filedata(part, data);
        res = file_or_stdin(part, data);
        if(res) {
          warnf(config->global, "curl_mime_filedata failed!\n");
          warnf(config->global, "setting file %s  failed!\n", data);
          if(res != CURLE_READ_ERROR) {
            if(subparts != *mimecurrent)
              curl_mime_free(subparts);
@@ -619,9 +634,9 @@ int formparse(struct OperationConfig *config,
        }

        /* Setup file in part. */
        res = curl_mime_filedata(part, data);
        res = file_or_stdin(part, data);
        if(res) {
          warnf(config->global, "curl_mime_filedata failed!\n");
          warnf(config->global, "setting file %s failed!\n", data);
          if(res != CURLE_READ_ERROR) {
            Curl_safefree(contents);
            return 22;
Loading