diff options
Diffstat (limited to 'src/fs/fs_getopt.c')
-rw-r--r-- | src/fs/fs_getopt.c | 204 |
1 files changed, 99 insertions, 105 deletions
diff --git a/src/fs/fs_getopt.c b/src/fs/fs_getopt.c index 0db7237f73..6c54fd69b8 100644 --- a/src/fs/fs_getopt.c +++ b/src/fs/fs_getopt.c @@ -42,10 +42,9 @@ * @return GNUNET_OK on success */ int -GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx, - void *scls, - const char *option, - const char *value) +GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext + *ctx, void *scls, const char *option, + const char *value) { struct GNUNET_FS_Uri **uri = scls; struct GNUNET_FS_Uri *u = *uri; @@ -53,60 +52,58 @@ GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* size_t slen; if (u == NULL) - { - u = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); - *uri = u; - u->type = ksk; - u->data.ksk.keywordCount = 0; - u->data.ksk.keywords = NULL; - } + { + u = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); + *uri = u; + u->type = ksk; + u->data.ksk.keywordCount = 0; + u->data.ksk.keywords = NULL; + } else - { - GNUNET_assert (u->type == ksk); - } + { + GNUNET_assert (u->type == ksk); + } slen = strlen (value); if (slen == 0) return GNUNET_SYSERR; /* cannot be empty */ if (value[0] == '+') + { + /* simply preserve the "mandatory" flag */ + if (slen < 2) + return GNUNET_SYSERR; /* empty keywords not allowed */ + if ((value[1] == '"') && (slen > 3) && (value[slen - 1] == '"')) { - /* simply preserve the "mandatory" flag */ - if (slen < 2) - return GNUNET_SYSERR; /* empty keywords not allowed */ - if ((value[1] == '"') && (slen > 3) && (value[slen - 1] == '"')) - { - /* remove the quotes, keep the '+' */ - val = GNUNET_malloc (slen - 1); - val[0] = '+'; - memcpy (&val[1], &value[2], slen - 3); - val[slen - 2] = '\0'; - } - else - { - /* no quotes, just keep the '+' */ - val = GNUNET_strdup (value); - } + /* remove the quotes, keep the '+' */ + val = GNUNET_malloc (slen - 1); + val[0] = '+'; + memcpy (&val[1], &value[2], slen - 3); + val[slen - 2] = '\0'; } + else + { + /* no quotes, just keep the '+' */ + val = GNUNET_strdup (value); + } + } else + { + if ((value[0] == '"') && (slen > 2) && (value[slen - 1] == '"')) + { + /* remove the quotes, add a space */ + val = GNUNET_malloc (slen); + val[0] = ' '; + memcpy (&val[1], &value[1], slen - 2); + val[slen - 1] = '\0'; + } + else { - if ((value[0] == '"') && (slen > 2) && (value[slen - 1] == '"')) - { - /* remove the quotes, add a space */ - val = GNUNET_malloc (slen); - val[0] = ' '; - memcpy (&val[1], &value[1], slen - 2); - val[slen - 1] = '\0'; - } - else - { - /* add a space to indicate "not mandatory" */ - val = GNUNET_malloc (slen + 2); - strcpy (val, " "); - strcat (val, value); - } + /* add a space to indicate "not mandatory" */ + val = GNUNET_malloc (slen + 2); + strcpy (val, " "); + strcat (val, value); } - GNUNET_array_append (u->data.ksk.keywords, - u->data.ksk.keywordCount, - val); + } + GNUNET_array_append (u->data.ksk.keywords, u->data.ksk.keywordCount, val); return GNUNET_OK; } @@ -124,11 +121,9 @@ GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* * @return GNUNET_OK on success */ int -GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx, - void *scls, - const char *option, - const char *value) - +GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext + *ctx, void *scls, const char *option, + const char *value) { struct GNUNET_CONTAINER_MetaData **mm = scls; enum EXTRACTOR_MetaType type; @@ -139,69 +134,68 @@ GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext* meta = *mm; if (meta == NULL) - { - meta = GNUNET_CONTAINER_meta_data_create (); - *mm = meta; - } + { + meta = GNUNET_CONTAINER_meta_data_create (); + *mm = meta; + } #if ENABLE_NLS - tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), - nl_langinfo (CODESET)); + tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), nl_langinfo (CODESET)); #else - tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), - "utf-8"); + tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), "utf-8"); #endif type = EXTRACTOR_metatype_get_max (); while (type > 0) + { + type--; + typename = EXTRACTOR_metatype_to_string (type); + typename_i18n = dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, typename); + if ((strlen (tmp) >= strlen (typename) + 1) && + (tmp[strlen (typename)] == ':') && + (0 == strncmp (typename, tmp, strlen (typename)))) { - type--; - typename = EXTRACTOR_metatype_to_string (type); - typename_i18n = dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, typename); - if ((strlen (tmp) >= strlen (typename) + 1) && - (tmp[strlen (typename)] == ':') && - (0 == strncmp (typename, tmp, strlen (typename)))) - { - GNUNET_CONTAINER_meta_data_insert (meta, - "<gnunet>", - type, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", - &tmp[strlen (typename) + 1], - strlen (&tmp[strlen (typename) + 1])+1); - GNUNET_free (tmp); - tmp = NULL; - break; - } - if ((strlen (tmp) >= strlen (typename_i18n) + 1) && - (tmp[strlen (typename_i18n)] == ':') && - (0 == strncmp (typename_i18n, tmp, strlen (typename_i18n)))) - { - GNUNET_CONTAINER_meta_data_insert (meta, - "<gnunet>", - type, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", - &tmp[strlen (typename_i18n) + 1], - strlen (&tmp[strlen (typename_i18n) + 1]) + 1); - GNUNET_free (tmp); - tmp = NULL; - break; - } + GNUNET_CONTAINER_meta_data_insert (meta, + "<gnunet>", + type, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", + &tmp[strlen (typename) + 1], + strlen (&tmp[strlen (typename) + 1]) + + 1); + GNUNET_free (tmp); + tmp = NULL; + break; } - if (tmp != NULL) + if ((strlen (tmp) >= strlen (typename_i18n) + 1) && + (tmp[strlen (typename_i18n)] == ':') && + (0 == strncmp (typename_i18n, tmp, strlen (typename_i18n)))) { - GNUNET_CONTAINER_meta_data_insert (meta, - "<gnunet>", - EXTRACTOR_METATYPE_UNKNOWN, - EXTRACTOR_METAFORMAT_UTF8, - "text/plain", - tmp, - strlen(tmp) + 1); + GNUNET_CONTAINER_meta_data_insert (meta, + "<gnunet>", + type, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", + &tmp[strlen (typename_i18n) + 1], + strlen (&tmp + [strlen (typename_i18n) + 1]) + + 1); GNUNET_free (tmp); - printf (_ - ("Unknown metadata type in metadata option `%s'. Using metadata type `unknown' instead.\n"), - value); + tmp = NULL; + break; } + } + if (tmp != NULL) + { + GNUNET_CONTAINER_meta_data_insert (meta, + "<gnunet>", + EXTRACTOR_METATYPE_UNKNOWN, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", tmp, strlen (tmp) + 1); + GNUNET_free (tmp); + printf (_ + ("Unknown metadata type in metadata option `%s'. Using metadata type `unknown' instead.\n"), + value); + } return GNUNET_OK; } |