PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/curl-7.28.0/src/tool_xattr.c

https://bitbucket.org/vlaznev/curl
C | 76 lines | 41 code | 6 blank | 29 comment | 6 complexity | b7403e15f68d9826b6af6f2cfa390879 MD5 | raw file
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "tool_setup.h"
  23. #ifdef HAVE_FSETXATTR
  24. # include <sys/xattr.h> /* header from libc, not from libattr */
  25. #endif
  26. #include "tool_xattr.h"
  27. #include "memdebug.h" /* keep this as LAST include */
  28. #ifdef HAVE_FSETXATTR
  29. /* mapping table of curl metadata to extended attribute names */
  30. static const struct xattr_mapping {
  31. const char *attr; /* name of the xattr */
  32. CURLINFO info;
  33. } mappings[] = {
  34. /* mappings proposed by
  35. * http://freedesktop.org/wiki/CommonExtendedAttributes
  36. */
  37. { "user.xdg.origin.url", CURLINFO_EFFECTIVE_URL },
  38. { "user.mime_type", CURLINFO_CONTENT_TYPE },
  39. { NULL, CURLINFO_NONE } /* last element, abort loop here */
  40. };
  41. /* store metadata from the curl request alongside the downloaded
  42. * file using extended attributes
  43. */
  44. int fwrite_xattr(CURL *curl, int fd)
  45. {
  46. int i = 0;
  47. int err = 0;
  48. /* loop through all xattr-curlinfo pairs and abort on a set error */
  49. while(err == 0 && mappings[i].attr != NULL) {
  50. char *value = NULL;
  51. CURLcode rc = curl_easy_getinfo(curl, mappings[i].info, &value);
  52. if(rc == CURLE_OK && value) {
  53. #ifdef HAVE_FSETXATTR_6
  54. err = fsetxattr(fd, mappings[i].attr, value, strlen(value), 0, 0);
  55. #elif defined(HAVE_FSETXATTR_5)
  56. err = fsetxattr(fd, mappings[i].attr, value, strlen(value), 0);
  57. #endif
  58. }
  59. i++;
  60. }
  61. return err;
  62. }
  63. #else
  64. int fwrite_xattr(CURL *curl, int fd)
  65. {
  66. (void)curl;
  67. (void)fd;
  68. return 0;
  69. }
  70. #endif