From: Christian Grothoff Date: Tue, 8 Oct 2013 09:06:47 +0000 (+0000) Subject: implement #3035: add mimetype:type category keywords, also doxygen fixes X-Git-Tag: initial-import-from-subversion-38251~6734 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e90117e2fb7fb84976e1961ee11a0619d1d28f2b;p=oweals%2Fgnunet.git implement #3035: add mimetype:type category keywords, also doxygen fixes --- 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 }; - /** * Abort the scan. Must not be called from within the progress_callback * function. @@ -197,7 +196,7 @@ expand_tree (struct GNUNET_FS_ShareTreeItem *parent, struct GNUNET_FS_ShareTreeItem *chld; size_t slen; - chld = GNUNET_malloc (sizeof (struct GNUNET_FS_ShareTreeItem)); + chld = GNUNET_new (struct GNUNET_FS_ShareTreeItem); chld->parent = parent; chld->filename = GNUNET_strdup (filename); 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, * * @param sc our search context * @param ub the ublock with the keyword search result - * @param size size of nb + * @param size size of @a ub */ static void process_kblock (struct GNUNET_FS_SearchContext *sc, @@ -834,7 +834,7 @@ process_sblock (struct GNUNET_FS_SearchContext *sc, * @param type type of the result * @param expiration when it will expire * @param data the (encrypted) response - * @param size size of data + * @param size size of @a data */ static void 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 insert_non_mandatory_keyword (const char *s, char **array, int index) { char *nkword; - GNUNET_asprintf (&nkword, " %s", /* space to mark as 'non mandatory' */ s); + + GNUNET_asprintf (&nkword, + " %s", /* space to mark as 'non mandatory' */ + s); array[index] = nkword; } /** - * Test if the given keyword 's' is already present in the + * Test if the given keyword @a s is already present in the * given array, ignoring the '+'-mandatory prefix in the array. * * @param s keyword to test * @param array keywords to test against, with ' ' or '+' prefix to ignore - * @param array_length length of the array - * @return GNUNET_YES if the keyword exists, GNUNET_NO if not + * @param array_length length of the @a array + * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not */ static int 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) * FIXME: comment */ static char * -normalize_metadata (enum EXTRACTOR_MetaFormat format, const char *data, - size_t data_len) +normalize_metadata (enum EXTRACTOR_MetaFormat format, + const char *data, + size_t data_len) { uint8_t *free_str = NULL; uint8_t *str_to_normalize = (uint8_t *) data; @@ -1682,6 +1686,7 @@ get_keywords_from_tokens (const char *s, char **array, int index) } #undef TOKENS + /** * Function called on each value in the meta data. * Adds it to the URI. @@ -1696,16 +1701,20 @@ get_keywords_from_tokens (const char *s, char **array, int index) * @param data_mime_type mime-type of data (not of the original file); * can be NULL (if mime-type is not known) * @param data actual meta-data found - * @param data_len number of bytes in data + * @param data_len number of bytes in @a data * @return 0 (always) */ static int gather_uri_data (void *cls, const char *plugin_name, - enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, - const char *data_mime_type, const char *data, size_t data_len) + enum EXTRACTOR_MetaType type, + enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, + const char *data, + size_t data_len) { struct GNUNET_FS_Uri *uri = cls; char *normalized_data; + const char *sep; if ((format != EXTRACTOR_METAFORMAT_UTF8) && (format != EXTRACTOR_METAFORMAT_C_STRING)) @@ -1716,19 +1725,43 @@ gather_uri_data (void *cls, const char *plugin_name, * If it does - fix the extractor, not this check! */ if (u8_strcount ((const uint8_t *) data) <= 2) - { return 0; + if ( (EXTRACTOR_METATYPE_MIMETYPE == type) && + (NULL != (sep = memchr (data, '/', data_len))) && + (sep != data) ) + { + char *xtra; + + GNUNET_asprintf (&xtra, + "mimetype:%.*s", + (int) (sep - data), + data); + if (! find_duplicate (xtra, + (const char **) uri->data.ksk.keywords, + uri->data.ksk.keywordCount)) + { + insert_non_mandatory_keyword (xtra, + uri->data.ksk.keywords, + uri->data.ksk.keywordCount); + uri->data.ksk.keywordCount++; + } + GNUNET_free (xtra); } + normalized_data = normalize_metadata (format, data, data_len); - if (!find_duplicate (data, (const char **) uri->data.ksk.keywords, uri->data.ksk.keywordCount)) + if (! find_duplicate (data, + (const char **) uri->data.ksk.keywords, + uri->data.ksk.keywordCount)) { insert_non_mandatory_keyword (data, uri->data.ksk.keywords, uri->data.ksk.keywordCount); uri->data.ksk.keywordCount++; } - if (normalized_data != NULL) - { - if (!find_duplicate (normalized_data, (const char **) uri->data.ksk.keywords, uri->data.ksk.keywordCount)) + if (NULL != normalized_data) + { + if (! find_duplicate (normalized_data, + (const char **) uri->data.ksk.keywords, + uri->data.ksk.keywordCount)) { insert_non_mandatory_keyword (normalized_data, uri->data.ksk.keywords, uri->data.ksk.keywordCount); @@ -1749,8 +1782,7 @@ gather_uri_data (void *cls, const char *plugin_name, * @return NULL on error, otherwise a KSK URI */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData - *md) +GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md) { struct GNUNET_FS_Uri *ret; char *filename; @@ -1760,7 +1792,7 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData int tok_keywords = 0; int paren_keywords = 0; - if (md == NULL) + if (NULL == md) return NULL; ret = GNUNET_new (struct GNUNET_FS_Uri); ret->type = GNUNET_FS_URI_KSK; @@ -1777,19 +1809,20 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData tok_keywords = get_keywords_from_tokens (filename, NULL, 0); paren_keywords = get_keywords_from_parens (filename, NULL, 0); } - /* x2 because there might be a normalized variant of every keyword */ - ret->data.ksk.keywords = GNUNET_malloc (sizeof (char *) * (ent - + tok_keywords + paren_keywords) * 2); + /* x3 because there might be a normalized variant of every keyword, + plus theoretically one more for mime... */ + ret->data.ksk.keywords = GNUNET_malloc + (sizeof (char *) * (ent + tok_keywords + paren_keywords) * 3); GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); } if (tok_keywords > 0) ret->data.ksk.keywordCount += get_keywords_from_tokens (filename, - ret->data.ksk.keywords, - ret->data.ksk.keywordCount); + ret->data.ksk.keywords, + ret->data.ksk.keywordCount); if (paren_keywords > 0) ret->data.ksk.keywordCount += get_keywords_from_parens (filename, - ret->data.ksk.keywords, - ret->data.ksk.keywordCount); + ret->data.ksk.keywords, + ret->data.ksk.keywordCount); if (ent > 0) GNUNET_free_non_null (full_name); return ret;