summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2011-09-15 17:05:56 +0000
committerCedric BAIL <cedric.bail@free.fr>2011-09-15 17:05:56 +0000
commitdd56854e990d99c707b0baae2720c9ac6a9497a2 (patch)
tree9420d5127f26cb4e5bb3ceac9956b3e7ac003aab
parent5a3e77cf96da5e1560afc973bcd31844e578f62d (diff)
downloadeet-dd56854e990d99c707b0baae2720c9ac6a9497a2.tar.gz
eet: add eet_data_xattr helper.
SVN revision: 63413
-rw-r--r--ChangeLog4
-rw-r--r--src/lib/Eet.h58
-rw-r--r--src/lib/eet_data.c40
3 files changed, 99 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index b108bff..a786ee4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -526,3 +526,7 @@
2011-07-29 Mike Blumenkrantz
* Add eet_alias_get to return the destination name of an alias
+
+2011-09-15 Cedric Bail
+
+ * Add eet_data_xattr_cipher_get and eet_data_xattr_cipher_set.
diff --git a/src/lib/Eet.h b/src/lib/Eet.h
index d7f0fc3..1d01af3 100644
--- a/src/lib/Eet.h
+++ b/src/lib/Eet.h
@@ -3326,6 +3326,35 @@ eet_data_read_cipher(Eet_File *ef,
const char *cipher_key);
/**
+ * Read a data structure from an eet extended attribute and decodes it using a cipher.
+ * @param filename The file to extract the extended attribute from.
+ * @param attribute The attribute to get the data from.
+ * @param edd The data descriptor handle to use when decoding.
+ * @param cipher_key The key to use as cipher.
+ * @return A pointer to the decoded data structure.
+ *
+ * This function decodes a data structure stored in an eet extended attribute,
+ * returning a pointer to it if it decoded successfully, or NULL on failure.
+ * Eet can handle members being added or deleted from the data in
+ * storage and safely zero-fills unfilled members if they were not found
+ * in the data. It checks sizes and headers whenever it reads data, allowing
+ * the programmer to not worry about corrupt data.
+ *
+ * Once a data structure has been described by the programmer with the
+ * fields they wish to save or load, storing or retrieving a data structure
+ * from an eet file, from a chunk of memory or from an extended attribute
+ * is as simple as a single function call.
+ *
+ * @since 1.5.0
+ * @ingroup Eet_Data_Cipher_Group
+ */
+EAPI void *
+eet_data_xattr_cipher_get(const char *filename,
+ const char *attribute,
+ Eet_Data_Descriptor *edd,
+ const char *cipher_key);
+
+/**
* Write a data structure from memory and store in an eet file
* using a cipher.
* @param ef The eet file handle to write to.
@@ -3336,11 +3365,9 @@ eet_data_read_cipher(Eet_File *ef,
* @param compress Compression flags for storage.
* @return bytes written on successful write, 0 on failure.
*
- * This function is the reverse of eet_data_read(), saving a data structure
+ * This function is the reverse of eet_data_read_cipher(), saving a data structure
* to an eet file.
*
- * @see eet_data_write_cipher()
- *
* @since 1.0.0
* @ingroup Eet_Data_Cipher_Group
*/
@@ -3353,6 +3380,31 @@ eet_data_write_cipher(Eet_File *ef,
int compress);
/**
+ * Write a data structure from memory and store in an eet extended attribute
+ * using a cipher.
+ * @param filename The file to write the extended attribute to.
+ * @param attribute The attribute to store the data to.
+ * @param edd The data descriptor to use when encoding.
+ * @param cipher_key The key to use as cipher.
+ * @param data A pointer to the data structure to ssave and encode.
+ * @param flags The policy to use when setting the data.
+ * @return EINA_TRUE on success, EINA_FALSE on failure.
+ *
+ * This function is the reverse of eet_data_xattr_cipher_get(), saving a data structure
+ * to an eet extended attribute.
+ *
+ * @since 1.5.0
+ * @ingroup Eet_Data_Cipher_Group
+ */
+EAPI Eina_Bool
+eet_data_xattr_cipher_set(const char *filename,
+ const char *attribute,
+ Eet_Data_Descriptor *edd,
+ const char *cipher_key,
+ const void *data,
+ Eina_Xattr_Flags flags);
+
+/**
* Dump an eet encoded data structure into ascii text using a cipher.
* @param data_in The pointer to the data to decode into a struct.
* @param cipher_key The key to use as cipher.
diff --git a/src/lib/eet_data.c b/src/lib/eet_data.c
index 5ae1256..7b2d394 100644
--- a/src/lib/eet_data.c
+++ b/src/lib/eet_data.c
@@ -4884,3 +4884,43 @@ eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
return eet_data_descriptor_encode_cipher(edd, data_in, NULL, size_ret);
} /* eet_data_descriptor_encode */
+EAPI void *
+eet_data_xattr_cipher_get(const char *filename,
+ const char *attribute,
+ Eet_Data_Descriptor *edd,
+ const char *cipher_key)
+{
+ void *blob;
+ void *ret;
+ int size;
+
+ blob = eina_xattr_get(filename, attribute, &size);
+ if (!blob) return NULL;
+
+ ret = eet_data_descriptor_decode_cipher(edd, blob, cipher_key, size);
+ free(blob);
+
+ return ret;
+}
+
+EAPI Eina_Bool
+eet_data_xattr_cipher_set(const char *filename,
+ const char *attribute,
+ Eet_Data_Descriptor *edd,
+ const char *cipher_key,
+ const void *data,
+ Eina_Xattr_Flags flags)
+{
+ void *blob;
+ int size;
+ Eina_Bool ret;
+
+ blob = eet_data_descriptor_encode_cipher(edd, data, cipher_key, &size);
+ if (!blob) return EINA_FALSE;
+
+ ret = eina_xattr_set(filename, attribute, blob, size, flags);
+ free(blob);
+
+ return ret;
+}
+