formdata.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef HEADER_CURL_FORMDATA_H
  2. #define HEADER_CURL_FORMDATA_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2016, Daniel Stenberg, <[email protected]>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.haxx.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. ***************************************************************************/
  24. enum formtype {
  25. FORM_DATAMEM, /* already allocated FORM_DATA memory */
  26. FORM_DATA, /* form metadata (convert to network encoding if necessary) */
  27. FORM_CONTENT, /* form content (never convert) */
  28. FORM_CALLBACK, /* 'line' points to the custom pointer we pass to the callback
  29. */
  30. FORM_FILE /* 'line' points to a file name we should read from
  31. to create the form data (never convert) */
  32. };
  33. /* plain and simple linked list with lines to send */
  34. struct FormData {
  35. struct FormData *next;
  36. enum formtype type;
  37. char *line;
  38. size_t length;
  39. };
  40. struct Form {
  41. struct FormData *data; /* current form line to send */
  42. size_t sent; /* number of bytes of the current line that has
  43. already been sent in a previous invoke */
  44. FILE *fp; /* file to read from */
  45. curl_read_callback fread_func; /* fread callback pointer */
  46. };
  47. /* used by FormAdd for temporary storage */
  48. typedef struct FormInfo {
  49. char *name;
  50. bool name_alloc;
  51. size_t namelength;
  52. char *value;
  53. bool value_alloc;
  54. curl_off_t contentslength;
  55. char *contenttype;
  56. bool contenttype_alloc;
  57. long flags;
  58. char *buffer; /* pointer to existing buffer used for file upload */
  59. size_t bufferlength;
  60. char *showfilename; /* The file name to show. If not set, the actual
  61. file name will be used */
  62. bool showfilename_alloc;
  63. char *userp; /* pointer for the read callback */
  64. struct curl_slist *contentheader;
  65. struct FormInfo *more;
  66. } FormInfo;
  67. int Curl_FormInit(struct Form *form, struct FormData *formdata);
  68. CURLcode Curl_getformdata(struct Curl_easy *data,
  69. struct FormData **,
  70. struct curl_httppost *post,
  71. const char *custom_contenttype,
  72. curl_off_t *size);
  73. /* fread() emulation */
  74. size_t Curl_FormReader(char *buffer,
  75. size_t size,
  76. size_t nitems,
  77. FILE *mydata);
  78. /*
  79. * Curl_formpostheader() returns the first line of the formpost, the
  80. * request-header part (which is not part of the request-body like the rest of
  81. * the post).
  82. */
  83. char *Curl_formpostheader(void *formp, size_t *len);
  84. char *Curl_FormBoundary(void);
  85. void Curl_formclean(struct FormData **);
  86. CURLcode Curl_formconvert(struct Curl_easy *, struct FormData *);
  87. #endif /* HEADER_CURL_FORMDATA_H */