formdata.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef HEADER_CURL_FORMDATA_H
  2. #define HEADER_CURL_FORMDATA_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, 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 http://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_DATA, /* form metadata (convert to network encoding if necessary) */
  26. FORM_CONTENT, /* form content (never convert) */
  27. FORM_CALLBACK, /* 'line' points to the custom pointer we pass to the callback
  28. */
  29. FORM_FILE /* 'line' points to a file name we should read from
  30. to create the form data (never convert) */
  31. };
  32. /* plain and simple linked list with lines to send */
  33. struct FormData {
  34. struct FormData *next;
  35. enum formtype type;
  36. char *line;
  37. size_t length;
  38. };
  39. struct Form {
  40. struct FormData *data; /* current form line to send */
  41. size_t sent; /* number of bytes of the current line that has
  42. already been sent in a previous invoke */
  43. FILE *fp; /* file to read from */
  44. curl_read_callback fread_func; /* fread callback pointer */
  45. };
  46. /* used by FormAdd for temporary storage */
  47. typedef struct FormInfo {
  48. char *name;
  49. bool name_alloc;
  50. size_t namelength;
  51. char *value;
  52. bool value_alloc;
  53. size_t contentslength;
  54. char *contenttype;
  55. bool contenttype_alloc;
  56. long flags;
  57. char *buffer; /* pointer to existing buffer used for file upload */
  58. size_t bufferlength;
  59. char *showfilename; /* The file name to show. If not set, the actual
  60. file name will be used */
  61. bool showfilename_alloc;
  62. char *userp; /* pointer for the read callback */
  63. struct curl_slist* contentheader;
  64. struct FormInfo *more;
  65. } FormInfo;
  66. int Curl_FormInit(struct Form *form, struct FormData *formdata );
  67. CURLcode Curl_getformdata(struct SessionHandle *data,
  68. struct FormData **,
  69. struct curl_httppost *post,
  70. const char *custom_contenttype,
  71. curl_off_t *size);
  72. /* fread() emulation */
  73. size_t Curl_FormReader(char *buffer,
  74. size_t size,
  75. size_t nitems,
  76. FILE *mydata);
  77. /*
  78. * Curl_formpostheader() returns the first line of the formpost, the
  79. * request-header part (which is not part of the request-body like the rest of
  80. * the post).
  81. */
  82. char *Curl_formpostheader(void *formp, size_t *len);
  83. char *Curl_FormBoundary(void);
  84. void Curl_formclean(struct FormData **);
  85. CURLcode Curl_formconvert(struct SessionHandle *, struct FormData *);
  86. #endif /* HEADER_CURL_FORMDATA_H */