mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
ce0881edee
Available in HTTP, SMTP and IMAP. Deprecates the FORM API. See CURLOPT_MIMEPOST. Lib code and associated documentation.
120 lines
5.1 KiB
C
120 lines
5.1 KiB
C
#ifndef HEADER_CURL_MIME_H
|
|
#define HEADER_CURL_MIME_H
|
|
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
*
|
|
* This software is licensed as described in the file COPYING, which
|
|
* you should have received as part of this distribution. The terms
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
|
*
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
*
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
* KIND, either express or implied.
|
|
*
|
|
***************************************************************************/
|
|
|
|
#define MIME_RAND_BOUNDARY_CHARS 16 /* Nb. of random boundary chars. */
|
|
|
|
/* Part flags. */
|
|
#define MIME_USERHEADERS_OWNER (1 << 0)
|
|
#define MIME_BODY_ONLY (1 << 1)
|
|
|
|
/* Part source kinds. */
|
|
enum mimekind {
|
|
MIMEKIND_NONE = 0, /* Part not set. */
|
|
MIMEKIND_DATA, /* Allocated mime data. */
|
|
MIMEKIND_NAMEDFILE, /* Data from named file. */
|
|
MIMEKIND_FILE, /* Data from file pointer. */
|
|
MIMEKIND_CALLBACK, /* Data from `read' callback. */
|
|
MIMEKIND_MULTIPART, /* Data is a mime subpart. */
|
|
MIMEKIND_LAST
|
|
};
|
|
|
|
/* Readback state tokens. */
|
|
enum mimestate {
|
|
MIMESTATE_BEGIN, /* Readback has not yet started. */
|
|
MIMESTATE_CURLHEADERS, /* In curl-generated headers. */
|
|
MIMESTATE_USERHEADERS, /* In caller's supplied headers. */
|
|
MIMESTATE_EOH, /* End of headers. */
|
|
MIMESTATE_BODY, /* Placeholder. */
|
|
MIMESTATE_BOUNDARY1, /* In boundary prefix. */
|
|
MIMESTATE_BOUNDARY2, /* In boundary. */
|
|
MIMESTATE_CONTENT, /* In content. */
|
|
MIMESTATE_END, /* End of part reached. */
|
|
MIMESTATE_LAST
|
|
};
|
|
|
|
/* Mime headers strategies. */
|
|
enum mimestrategy {
|
|
MIMESTRATEGY_MAIL, /* Mime mail. */
|
|
MIMESTRATEGY_FORM, /* HTTP post form. */
|
|
MIMESTRATEGY_LAST
|
|
};
|
|
|
|
/* Mime readback state. */
|
|
struct mime_state {
|
|
enum mimestate state; /* Current state token. */
|
|
void * ptr; /* State-dependent pointer. */
|
|
size_t offset; /* State-dependent offset. */
|
|
};
|
|
|
|
/* A mime context. */
|
|
struct Curl_mime {
|
|
struct Curl_easy * easy; /* The associated easy handle. */
|
|
struct Curl_mimepart * parent; /* Parent part. */
|
|
struct Curl_mimepart * firstpart; /* First part. */
|
|
struct Curl_mimepart * lastpart; /* Last part. */
|
|
char * boundary; /* The part boundary. */
|
|
struct mime_state state; /* Current readback state. */
|
|
};
|
|
|
|
/* A mime part. */
|
|
struct Curl_mimepart {
|
|
struct Curl_easy * easy; /* The associated easy handle. */
|
|
struct Curl_mime * parent; /* Parent mime structure. */
|
|
struct Curl_mimepart * nextpart; /* Forward linked list. */
|
|
enum mimekind kind; /* The part kind. */
|
|
char * data; /* Memory data or file name. */
|
|
curl_read_callback readfunc; /* Read function. */
|
|
curl_seek_callback seekfunc; /* Seek function. */
|
|
curl_free_callback freefunc; /* Argument free function. */
|
|
void * arg; /* Argument to callback functions. */
|
|
FILE * namedfp; /* Named file pointer. */
|
|
struct curl_slist * curlheaders; /* Part headers. */
|
|
struct curl_slist * userheaders; /* Part headers. */
|
|
char * mimetype; /* Part mime type. */
|
|
char * filename; /* Remote file name. */
|
|
char * name; /* Data name. */
|
|
size_t namesize; /* Data name size. */
|
|
curl_off_t origin; /* Origin file offset. */
|
|
curl_off_t datasize; /* Expected data size. */
|
|
unsigned int flags; /* Flags. */
|
|
struct mime_state state; /* Current readback state. */
|
|
};
|
|
|
|
|
|
/* Prototypes. */
|
|
void Curl_mime_initpart(struct Curl_mimepart *part, struct Curl_easy *easy);
|
|
void Curl_mime_cleanpart(struct Curl_mimepart *part);
|
|
CURLcode Curl_mime_prepare_headers(struct Curl_mimepart *part,
|
|
const char *contenttype,
|
|
const char *disposition,
|
|
enum mimestrategy strategy);
|
|
curl_off_t Curl_mime_size(struct Curl_mimepart *part);
|
|
size_t Curl_mime_read(char *buffer, size_t size, size_t nitems,
|
|
void *instream);
|
|
CURLcode Curl_mime_rewind(struct Curl_mimepart *part);
|
|
CURLcode Curl_mime_add_header(struct curl_slist **slp, const char *fmt, ...);
|
|
CURLcode Curl_mime_file(curl_mimepart *part, FILE *fp, int closewhendone);
|
|
|
|
#endif /* HEADER_CURL_MIME_H */
|