2010-11-05 14:07:38 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2012-04-06 23:35:15 +02:00
|
|
|
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2010-11-05 14:07:38 +01:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
|
|
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2012-04-06 23:35:15 +02:00
|
|
|
#include "tool_setup.h"
|
2010-11-05 12:39:46 +01:00
|
|
|
|
2010-11-07 16:54:49 +01:00
|
|
|
#ifdef HAVE_FSETXATTR
|
2011-10-06 17:39:00 +02:00
|
|
|
# include <sys/xattr.h> /* header from libc, not from libattr */
|
2011-09-14 11:27:12 +02:00
|
|
|
#endif
|
|
|
|
|
2011-10-06 17:39:00 +02:00
|
|
|
#include "tool_xattr.h"
|
2011-09-14 11:27:12 +02:00
|
|
|
|
2012-12-28 12:40:20 +01:00
|
|
|
#include "curl_memdebug.h" /* keep this as LAST include */
|
2011-09-14 11:27:12 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_FSETXATTR
|
2010-11-05 14:07:38 +01:00
|
|
|
|
2010-11-05 12:39:46 +01:00
|
|
|
/* mapping table of curl metadata to extended attribute names */
|
2010-11-10 03:47:16 +01:00
|
|
|
static const struct xattr_mapping {
|
2010-11-08 09:10:33 +01:00
|
|
|
const char *attr; /* name of the xattr */
|
2010-11-05 12:39:46 +01:00
|
|
|
CURLINFO info;
|
|
|
|
} mappings[] = {
|
|
|
|
/* mappings proposed by
|
|
|
|
* http://freedesktop.org/wiki/CommonExtendedAttributes
|
|
|
|
*/
|
|
|
|
{ "user.xdg.origin.url", CURLINFO_EFFECTIVE_URL },
|
2011-10-06 17:39:00 +02:00
|
|
|
{ "user.mime_type", CURLINFO_CONTENT_TYPE },
|
|
|
|
{ NULL, CURLINFO_NONE } /* last element, abort loop here */
|
2010-11-05 12:39:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* store metadata from the curl request alongside the downloaded
|
|
|
|
* file using extended attributes
|
|
|
|
*/
|
2010-11-07 16:54:49 +01:00
|
|
|
int fwrite_xattr(CURL *curl, int fd)
|
2010-11-05 12:39:46 +01:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
int err = 0;
|
2010-11-10 03:47:16 +01:00
|
|
|
/* loop through all xattr-curlinfo pairs and abort on a set error */
|
2011-04-25 22:44:39 +02:00
|
|
|
while(err == 0 && mappings[i].attr != NULL) {
|
2010-11-05 12:39:46 +01:00
|
|
|
char *value = NULL;
|
2010-11-10 03:47:16 +01:00
|
|
|
CURLcode rc = curl_easy_getinfo(curl, mappings[i].info, &value);
|
2011-04-25 22:44:39 +02:00
|
|
|
if(rc == CURLE_OK && value) {
|
2010-11-10 18:39:44 +01:00
|
|
|
#ifdef HAVE_FSETXATTR_6
|
2011-10-06 17:39:00 +02:00
|
|
|
err = fsetxattr(fd, mappings[i].attr, value, strlen(value), 0, 0);
|
2010-11-10 18:39:44 +01:00
|
|
|
#elif defined(HAVE_FSETXATTR_5)
|
2011-10-06 17:39:00 +02:00
|
|
|
err = fsetxattr(fd, mappings[i].attr, value, strlen(value), 0);
|
2010-11-10 18:39:44 +01:00
|
|
|
#endif
|
2010-11-05 12:39:46 +01:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
2010-11-05 14:07:38 +01:00
|
|
|
#else
|
2010-11-07 16:54:49 +01:00
|
|
|
int fwrite_xattr(CURL *curl, int fd)
|
2010-11-05 14:07:38 +01:00
|
|
|
{
|
|
|
|
(void)curl;
|
2010-11-07 16:54:49 +01:00
|
|
|
(void)fd;
|
2010-11-05 14:07:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|