123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- #ifndef HEADER_CURL_MIME_H
- #define HEADER_CURL_MIME_H
- #include "curl_setup.h"
- #define MIME_BOUNDARY_DASHES 24
- #define MIME_RAND_BOUNDARY_CHARS 22
- #define MAX_ENCODED_LINE_LENGTH 76
- #define ENCODING_BUFFER_SIZE 256
- #define MIME_USERHEADERS_OWNER (1 << 0)
- #define MIME_BODY_ONLY (1 << 1)
- #define MIME_FAST_READ (1 << 2)
- #define FILE_CONTENTTYPE_DEFAULT "application/octet-stream"
- #define MULTIPART_CONTENTTYPE_DEFAULT "multipart/mixed"
- #define DISPOSITION_DEFAULT "attachment"
- enum mimekind {
- MIMEKIND_NONE = 0,
- MIMEKIND_DATA,
- MIMEKIND_FILE,
- MIMEKIND_CALLBACK,
- MIMEKIND_MULTIPART,
- MIMEKIND_LAST
- };
- enum mimestate {
- MIMESTATE_BEGIN,
- MIMESTATE_CURLHEADERS,
- MIMESTATE_USERHEADERS,
- MIMESTATE_EOH,
- MIMESTATE_BODY,
- MIMESTATE_BOUNDARY1,
- MIMESTATE_BOUNDARY2,
- MIMESTATE_CONTENT,
- MIMESTATE_END,
- MIMESTATE_LAST
- };
- enum mimestrategy {
- MIMESTRATEGY_MAIL,
- MIMESTRATEGY_FORM,
- MIMESTRATEGY_LAST
- };
- struct mime_encoder {
- const char * name;
- size_t (*encodefunc)(char *buffer, size_t size, bool ateof,
- curl_mimepart *part);
- curl_off_t (*sizefunc)(curl_mimepart *part);
- };
- struct mime_encoder_state {
- size_t pos;
- size_t bufbeg;
- size_t bufend;
- char buf[ENCODING_BUFFER_SIZE];
- };
- struct mime_state {
- enum mimestate state;
- void *ptr;
- curl_off_t offset;
- };
- #define MIME_BOUNDARY_LEN (MIME_BOUNDARY_DASHES + MIME_RAND_BOUNDARY_CHARS)
- struct curl_mime {
- curl_mimepart *parent;
- curl_mimepart *firstpart;
- curl_mimepart *lastpart;
- char boundary[MIME_BOUNDARY_LEN + 1];
- struct mime_state state;
- };
- struct curl_mimepart {
- curl_mime *parent;
- curl_mimepart *nextpart;
- enum mimekind kind;
- unsigned int flags;
- char *data;
- curl_read_callback readfunc;
- curl_seek_callback seekfunc;
- curl_free_callback freefunc;
- void *arg;
- FILE *fp;
- struct curl_slist *curlheaders;
- struct curl_slist *userheaders;
- char *mimetype;
- char *filename;
- char *name;
- curl_off_t datasize;
- struct mime_state state;
- const struct mime_encoder *encoder;
- struct mime_encoder_state encstate;
- size_t lastreadstatus;
- };
- CURLcode Curl_mime_add_header(struct curl_slist **slp, const char *fmt, ...)
- CURL_PRINTF(2, 3);
- #if !defined(CURL_DISABLE_MIME) && (!defined(CURL_DISABLE_HTTP) || \
- !defined(CURL_DISABLE_SMTP) || \
- !defined(CURL_DISABLE_IMAP))
- void Curl_mime_initpart(struct curl_mimepart *part);
- void Curl_mime_cleanpart(struct curl_mimepart *part);
- CURLcode Curl_mime_duppart(struct Curl_easy *data,
- struct curl_mimepart *dst,
- const curl_mimepart *src);
- CURLcode Curl_mime_set_subparts(struct curl_mimepart *part,
- struct curl_mime *subparts,
- int take_ownership);
- CURLcode Curl_mime_prepare_headers(struct Curl_easy *data,
- struct curl_mimepart *part,
- const char *contenttype,
- const char *disposition,
- enum mimestrategy strategy);
- size_t Curl_mime_read(char *buffer, size_t size, size_t nitems,
- void *instream);
- const char *Curl_mime_contenttype(const char *filename);
- CURLcode Curl_creader_set_mime(struct Curl_easy *data, curl_mimepart *part);
- #else
- #define Curl_mime_initpart(x)
- #define Curl_mime_cleanpart(x)
- #define Curl_mime_duppart(x,y,z) CURLE_OK
- #define Curl_mime_set_subparts(a,b,c) CURLE_NOT_BUILT_IN
- #define Curl_mime_prepare_headers(a,b,c,d,e) CURLE_NOT_BUILT_IN
- #define Curl_mime_read NULL
- #define Curl_creader_set_mime(x,y) ((void)x, CURLE_NOT_BUILT_IN)
- #endif
- #endif
|