diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-08 09:06:47 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-08 09:06:47 +0000 |
commit | e90117e2fb7fb84976e1961ee11a0619d1d28f2b (patch) | |
tree | 941c42b04ac878688703e8b6da0757a4e38e1e9a /src/fs | |
parent | 31cc9c3182ef5ac01edcdd4c4e4dc9c312fc8c9c (diff) | |
download | gnunet-e90117e2fb7fb84976e1961ee11a0619d1d28f2b.tar.gz gnunet-e90117e2fb7fb84976e1961ee11a0619d1d28f2b.zip |
implement #3035: add mimetype:type category keywords, also doxygen fixes
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/fs_dirmetascan.c | 3 | ||||
-rw-r--r-- | src/fs/fs_search.c | 4 | ||||
-rw-r--r-- | src/fs/fs_uri.c | 81 |
3 files changed, 60 insertions, 28 deletions
diff --git a/src/fs/fs_dirmetascan.c b/src/fs/fs_dirmetascan.c index 1df07a01c..3b3615f65 100644 --- a/src/fs/fs_dirmetascan.c +++ b/src/fs/fs_dirmetascan.c | |||
@@ -90,7 +90,6 @@ struct GNUNET_FS_DirScanner | |||
90 | }; | 90 | }; |
91 | 91 | ||
92 | 92 | ||
93 | |||
94 | /** | 93 | /** |
95 | * Abort the scan. Must not be called from within the progress_callback | 94 | * Abort the scan. Must not be called from within the progress_callback |
96 | * function. | 95 | * function. |
@@ -197,7 +196,7 @@ expand_tree (struct GNUNET_FS_ShareTreeItem *parent, | |||
197 | struct GNUNET_FS_ShareTreeItem *chld; | 196 | struct GNUNET_FS_ShareTreeItem *chld; |
198 | size_t slen; | 197 | size_t slen; |
199 | 198 | ||
200 | chld = GNUNET_malloc (sizeof (struct GNUNET_FS_ShareTreeItem)); | 199 | chld = GNUNET_new (struct GNUNET_FS_ShareTreeItem); |
201 | chld->parent = parent; | 200 | chld->parent = parent; |
202 | chld->filename = GNUNET_strdup (filename); | 201 | chld->filename = GNUNET_strdup (filename); |
203 | GNUNET_asprintf (&chld->short_filename, | 202 | GNUNET_asprintf (&chld->short_filename, |
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index 7a869b4c5..11af03646 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c | |||
@@ -718,7 +718,7 @@ decrypt_block_with_keyword (const struct GNUNET_FS_SearchContext *sc, | |||
718 | * | 718 | * |
719 | * @param sc our search context | 719 | * @param sc our search context |
720 | * @param ub the ublock with the keyword search result | 720 | * @param ub the ublock with the keyword search result |
721 | * @param size size of nb | 721 | * @param size size of @a ub |
722 | */ | 722 | */ |
723 | static void | 723 | static void |
724 | process_kblock (struct GNUNET_FS_SearchContext *sc, | 724 | process_kblock (struct GNUNET_FS_SearchContext *sc, |
@@ -834,7 +834,7 @@ process_sblock (struct GNUNET_FS_SearchContext *sc, | |||
834 | * @param type type of the result | 834 | * @param type type of the result |
835 | * @param expiration when it will expire | 835 | * @param expiration when it will expire |
836 | * @param data the (encrypted) response | 836 | * @param data the (encrypted) response |
837 | * @param size size of data | 837 | * @param size size of @a data |
838 | */ | 838 | */ |
839 | static void | 839 | static void |
840 | process_result (struct GNUNET_FS_SearchContext *sc, | 840 | process_result (struct GNUNET_FS_SearchContext *sc, |
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index 90c211415..e64fabeba 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c | |||
@@ -1433,19 +1433,22 @@ static void | |||
1433 | insert_non_mandatory_keyword (const char *s, char **array, int index) | 1433 | insert_non_mandatory_keyword (const char *s, char **array, int index) |
1434 | { | 1434 | { |
1435 | char *nkword; | 1435 | char *nkword; |
1436 | GNUNET_asprintf (&nkword, " %s", /* space to mark as 'non mandatory' */ s); | 1436 | |
1437 | GNUNET_asprintf (&nkword, | ||
1438 | " %s", /* space to mark as 'non mandatory' */ | ||
1439 | s); | ||
1437 | array[index] = nkword; | 1440 | array[index] = nkword; |
1438 | } | 1441 | } |
1439 | 1442 | ||
1440 | 1443 | ||
1441 | /** | 1444 | /** |
1442 | * Test if the given keyword 's' is already present in the | 1445 | * Test if the given keyword @a s is already present in the |
1443 | * given array, ignoring the '+'-mandatory prefix in the array. | 1446 | * given array, ignoring the '+'-mandatory prefix in the array. |
1444 | * | 1447 | * |
1445 | * @param s keyword to test | 1448 | * @param s keyword to test |
1446 | * @param array keywords to test against, with ' ' or '+' prefix to ignore | 1449 | * @param array keywords to test against, with ' ' or '+' prefix to ignore |
1447 | * @param array_length length of the array | 1450 | * @param array_length length of the @a array |
1448 | * @return GNUNET_YES if the keyword exists, GNUNET_NO if not | 1451 | * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not |
1449 | */ | 1452 | */ |
1450 | static int | 1453 | static int |
1451 | find_duplicate (const char *s, const char **array, int array_length) | 1454 | find_duplicate (const char *s, const char **array, int array_length) |
@@ -1463,8 +1466,9 @@ find_duplicate (const char *s, const char **array, int array_length) | |||
1463 | * FIXME: comment | 1466 | * FIXME: comment |
1464 | */ | 1467 | */ |
1465 | static char * | 1468 | static char * |
1466 | normalize_metadata (enum EXTRACTOR_MetaFormat format, const char *data, | 1469 | normalize_metadata (enum EXTRACTOR_MetaFormat format, |
1467 | size_t data_len) | 1470 | const char *data, |
1471 | size_t data_len) | ||
1468 | { | 1472 | { |
1469 | uint8_t *free_str = NULL; | 1473 | uint8_t *free_str = NULL; |
1470 | uint8_t *str_to_normalize = (uint8_t *) data; | 1474 | uint8_t *str_to_normalize = (uint8_t *) data; |
@@ -1682,6 +1686,7 @@ get_keywords_from_tokens (const char *s, char **array, int index) | |||
1682 | } | 1686 | } |
1683 | #undef TOKENS | 1687 | #undef TOKENS |
1684 | 1688 | ||
1689 | |||
1685 | /** | 1690 | /** |
1686 | * Function called on each value in the meta data. | 1691 | * Function called on each value in the meta data. |
1687 | * Adds it to the URI. | 1692 | * Adds it to the URI. |
@@ -1696,16 +1701,20 @@ get_keywords_from_tokens (const char *s, char **array, int index) | |||
1696 | * @param data_mime_type mime-type of data (not of the original file); | 1701 | * @param data_mime_type mime-type of data (not of the original file); |
1697 | * can be NULL (if mime-type is not known) | 1702 | * can be NULL (if mime-type is not known) |
1698 | * @param data actual meta-data found | 1703 | * @param data actual meta-data found |
1699 | * @param data_len number of bytes in data | 1704 | * @param data_len number of bytes in @a data |
1700 | * @return 0 (always) | 1705 | * @return 0 (always) |
1701 | */ | 1706 | */ |
1702 | static int | 1707 | static int |
1703 | gather_uri_data (void *cls, const char *plugin_name, | 1708 | gather_uri_data (void *cls, const char *plugin_name, |
1704 | enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, | 1709 | enum EXTRACTOR_MetaType type, |
1705 | const char *data_mime_type, const char *data, size_t data_len) | 1710 | enum EXTRACTOR_MetaFormat format, |
1711 | const char *data_mime_type, | ||
1712 | const char *data, | ||
1713 | size_t data_len) | ||
1706 | { | 1714 | { |
1707 | struct GNUNET_FS_Uri *uri = cls; | 1715 | struct GNUNET_FS_Uri *uri = cls; |
1708 | char *normalized_data; | 1716 | char *normalized_data; |
1717 | const char *sep; | ||
1709 | 1718 | ||
1710 | if ((format != EXTRACTOR_METAFORMAT_UTF8) && | 1719 | if ((format != EXTRACTOR_METAFORMAT_UTF8) && |
1711 | (format != EXTRACTOR_METAFORMAT_C_STRING)) | 1720 | (format != EXTRACTOR_METAFORMAT_C_STRING)) |
@@ -1716,19 +1725,43 @@ gather_uri_data (void *cls, const char *plugin_name, | |||
1716 | * If it does - fix the extractor, not this check! | 1725 | * If it does - fix the extractor, not this check! |
1717 | */ | 1726 | */ |
1718 | if (u8_strcount ((const uint8_t *) data) <= 2) | 1727 | if (u8_strcount ((const uint8_t *) data) <= 2) |
1719 | { | ||
1720 | return 0; | 1728 | return 0; |
1729 | if ( (EXTRACTOR_METATYPE_MIMETYPE == type) && | ||
1730 | (NULL != (sep = memchr (data, '/', data_len))) && | ||
1731 | (sep != data) ) | ||
1732 | { | ||
1733 | char *xtra; | ||
1734 | |||
1735 | GNUNET_asprintf (&xtra, | ||
1736 | "mimetype:%.*s", | ||
1737 | (int) (sep - data), | ||
1738 | data); | ||
1739 | if (! find_duplicate (xtra, | ||
1740 | (const char **) uri->data.ksk.keywords, | ||
1741 | uri->data.ksk.keywordCount)) | ||
1742 | { | ||
1743 | insert_non_mandatory_keyword (xtra, | ||
1744 | uri->data.ksk.keywords, | ||
1745 | uri->data.ksk.keywordCount); | ||
1746 | uri->data.ksk.keywordCount++; | ||
1747 | } | ||
1748 | GNUNET_free (xtra); | ||
1721 | } | 1749 | } |
1750 | |||
1722 | normalized_data = normalize_metadata (format, data, data_len); | 1751 | normalized_data = normalize_metadata (format, data, data_len); |
1723 | if (!find_duplicate (data, (const char **) uri->data.ksk.keywords, uri->data.ksk.keywordCount)) | 1752 | if (! find_duplicate (data, |
1753 | (const char **) uri->data.ksk.keywords, | ||
1754 | uri->data.ksk.keywordCount)) | ||
1724 | { | 1755 | { |
1725 | insert_non_mandatory_keyword (data, | 1756 | insert_non_mandatory_keyword (data, |
1726 | uri->data.ksk.keywords, uri->data.ksk.keywordCount); | 1757 | uri->data.ksk.keywords, uri->data.ksk.keywordCount); |
1727 | uri->data.ksk.keywordCount++; | 1758 | uri->data.ksk.keywordCount++; |
1728 | } | 1759 | } |
1729 | if (normalized_data != NULL) | 1760 | if (NULL != normalized_data) |
1730 | { | 1761 | { |
1731 | if (!find_duplicate (normalized_data, (const char **) uri->data.ksk.keywords, uri->data.ksk.keywordCount)) | 1762 | if (! find_duplicate (normalized_data, |
1763 | (const char **) uri->data.ksk.keywords, | ||
1764 | uri->data.ksk.keywordCount)) | ||
1732 | { | 1765 | { |
1733 | insert_non_mandatory_keyword (normalized_data, | 1766 | insert_non_mandatory_keyword (normalized_data, |
1734 | uri->data.ksk.keywords, uri->data.ksk.keywordCount); | 1767 | uri->data.ksk.keywords, uri->data.ksk.keywordCount); |
@@ -1749,8 +1782,7 @@ gather_uri_data (void *cls, const char *plugin_name, | |||
1749 | * @return NULL on error, otherwise a KSK URI | 1782 | * @return NULL on error, otherwise a KSK URI |
1750 | */ | 1783 | */ |
1751 | struct GNUNET_FS_Uri * | 1784 | struct GNUNET_FS_Uri * |
1752 | GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData | 1785 | GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md) |
1753 | *md) | ||
1754 | { | 1786 | { |
1755 | struct GNUNET_FS_Uri *ret; | 1787 | struct GNUNET_FS_Uri *ret; |
1756 | char *filename; | 1788 | char *filename; |
@@ -1760,7 +1792,7 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData | |||
1760 | int tok_keywords = 0; | 1792 | int tok_keywords = 0; |
1761 | int paren_keywords = 0; | 1793 | int paren_keywords = 0; |
1762 | 1794 | ||
1763 | if (md == NULL) | 1795 | if (NULL == md) |
1764 | return NULL; | 1796 | return NULL; |
1765 | ret = GNUNET_new (struct GNUNET_FS_Uri); | 1797 | ret = GNUNET_new (struct GNUNET_FS_Uri); |
1766 | ret->type = GNUNET_FS_URI_KSK; | 1798 | ret->type = GNUNET_FS_URI_KSK; |
@@ -1777,19 +1809,20 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData | |||
1777 | tok_keywords = get_keywords_from_tokens (filename, NULL, 0); | 1809 | tok_keywords = get_keywords_from_tokens (filename, NULL, 0); |
1778 | paren_keywords = get_keywords_from_parens (filename, NULL, 0); | 1810 | paren_keywords = get_keywords_from_parens (filename, NULL, 0); |
1779 | } | 1811 | } |
1780 | /* x2 because there might be a normalized variant of every keyword */ | 1812 | /* x3 because there might be a normalized variant of every keyword, |
1781 | ret->data.ksk.keywords = GNUNET_malloc (sizeof (char *) * (ent | 1813 | plus theoretically one more for mime... */ |
1782 | + tok_keywords + paren_keywords) * 2); | 1814 | ret->data.ksk.keywords = GNUNET_malloc |
1815 | (sizeof (char *) * (ent + tok_keywords + paren_keywords) * 3); | ||
1783 | GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); | 1816 | GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); |
1784 | } | 1817 | } |
1785 | if (tok_keywords > 0) | 1818 | if (tok_keywords > 0) |
1786 | ret->data.ksk.keywordCount += get_keywords_from_tokens (filename, | 1819 | ret->data.ksk.keywordCount += get_keywords_from_tokens (filename, |
1787 | ret->data.ksk.keywords, | 1820 | ret->data.ksk.keywords, |
1788 | ret->data.ksk.keywordCount); | 1821 | ret->data.ksk.keywordCount); |
1789 | if (paren_keywords > 0) | 1822 | if (paren_keywords > 0) |
1790 | ret->data.ksk.keywordCount += get_keywords_from_parens (filename, | 1823 | ret->data.ksk.keywordCount += get_keywords_from_parens (filename, |
1791 | ret->data.ksk.keywords, | 1824 | ret->data.ksk.keywords, |
1792 | ret->data.ksk.keywordCount); | 1825 | ret->data.ksk.keywordCount); |
1793 | if (ent > 0) | 1826 | if (ent > 0) |
1794 | GNUNET_free_non_null (full_name); | 1827 | GNUNET_free_non_null (full_name); |
1795 | return ret; | 1828 | return ret; |