SOAPHelpers.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #include "SOAPHelpers.h"
  18. namespace KC {
  19. void *mime_file_read_open(struct soap *soap, void *handle, const char *id, const char *type, const char *description)
  20. {
  21. return handle;
  22. }
  23. void mime_file_read_close(struct soap *soap, void *handle)
  24. {
  25. if (handle)
  26. fclose((FILE*)handle);
  27. }
  28. size_t mime_file_read(struct soap *soap, void *handle, char *buf, size_t len)
  29. {
  30. return fread(buf, 1, len, (FILE*)handle);
  31. }
  32. void *mime_file_write_open(struct soap *soap, void *handle, const char *id, const char *type, const char *description, enum soap_mime_encoding encoding)
  33. {
  34. auto lpFilename = static_cast<const char *>(handle);
  35. if (!lpFilename) {
  36. soap->error = SOAP_EOF;
  37. soap->errnum = errno;
  38. return NULL;
  39. }
  40. FILE *fHandle = fopen(lpFilename, "wb");
  41. if (!fHandle) {
  42. soap->error = SOAP_EOF;
  43. soap->errnum = errno;
  44. }
  45. return (void*)fHandle;
  46. }
  47. void mime_file_write_close(struct soap *soap, void *handle)
  48. {
  49. fclose((FILE*)handle);
  50. }
  51. int mime_file_write(struct soap *soap, void *handle, const char *buf, size_t len)
  52. {
  53. size_t nwritten;
  54. while (len)
  55. {
  56. nwritten = fwrite(buf, 1, len, (FILE*)handle);
  57. if (!nwritten)
  58. {
  59. soap->errnum = errno;
  60. return SOAP_EOF;
  61. }
  62. len -= nwritten;
  63. buf += nwritten;
  64. }
  65. return SOAP_OK;
  66. }
  67. } /* namespace */