api to add keyword
authorChristian Grothoff <christian@grothoff.org>
Tue, 26 Oct 2010 22:20:20 +0000 (22:20 +0000)
committerChristian Grothoff <christian@grothoff.org>
Tue, 26 Oct 2010 22:20:20 +0000 (22:20 +0000)
src/fs/fs_uri.c
src/include/gnunet_fs_service.h

index 9a4f72201b0cc4b5b48739c04e21935552ce92a6..78187182465064137a88409f167909c933389892 100644 (file)
@@ -765,6 +765,39 @@ GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
 }
 
 
+/**
+ * Add the given keyword to the set of keywords represented by the URI.
+ * Does nothing if the keyword is already present.
+ *
+ * @param uri ksk uri to modify
+ * @param keyword keyword to add
+ * @param is_mandatory is this keyword mandatory?
+ */
+void
+GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
+                              const char *keyword,
+                              int is_mandatory)
+{
+  unsigned int i;
+  const char *old;
+  char *n;
+
+  GNUNET_assert (uri->type == ksk);
+  for (i = 0; i < uri->data.ksk.keywordCount; i++)
+    {
+      old = uri->data.ksk.keywords[i];
+      if (0 == strcmp (&old[1], keyword))
+       return;
+    }
+  GNUNET_asprintf (&n,
+                  is_mandatory ? "+%s" : " %s",
+                  keyword);
+  GNUNET_array_append (uri->data.ksk.keywords,
+                      uri->data.ksk.keywordCount,
+                      n);
+}
+
+
 /**
  * Obtain the identity of the peer offering the data
  *
index 8e71308ba3263d89a608cadf211e08ff2e73376e..8477c534d691cec06d6d0156bf32b0acdfe32460 100644 (file)
@@ -114,6 +114,20 @@ char *
 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
 
 
+/**
+ * Add the given keyword to the set of keywords represented by the URI.
+ * Does nothing if the keyword is already present.
+ *
+ * @param uri ksk uri to modify
+ * @param keyword keyword to add
+ * @param is_mandatory is this keyword mandatory?
+ */
+void
+GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri,
+                              const char *keyword,
+                              int is_mandatory);
+
+
 /**
  * Convert a UTF-8 String to a URI.
  *